treewide: use SWAP macro

Via Coccinelle patch + manual clean up:

    @@
    identifier temporary, a, b;
    type T;
    @@

    -T temporary = a;
    -a = b;
    -b = temporary;
    +SWAP(a, b);

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36297>
This commit is contained in:
Alyssa Rosenzweig 2025-07-22 16:13:48 -04:00 committed by Marge Bot
parent d51b411f56
commit 8a1a410389
13 changed files with 16 additions and 53 deletions

View file

@ -169,9 +169,7 @@ apply_nuw_to_ssa(isel_context* ctx, nir_def* ssa)
nir_scalar src1 = nir_scalar_chase_alu_src(scalar, 1);
if (nir_scalar_is_const(src0)) {
nir_scalar tmp = src0;
src0 = src1;
src1 = tmp;
std::swap(src0, src1);
}
uint32_t src1_ub = nir_unsigned_upper_bound(ctx->shader, ctx->range_ht, src1, &ctx->ub_config);

View file

@ -562,9 +562,7 @@ radv_nir_lower_cooperative_matrix(nir_shader *shader, enum amd_gfx_level gfx_lev
row_offset = nir_iadd_imm(&b, base_row, row_iter);
if (layout == GLSL_MATRIX_LAYOUT_ROW_MAJOR) {
nir_def *tmp = col_offset;
col_offset = row_offset;
row_offset = tmp;
SWAP(col_offset, row_offset);
}
col_offset = nir_imul(&b, col_offset, stride);

View file

@ -31,9 +31,7 @@ cmpsel_for_break_if(agx_builder *b, agx_instr *I)
agx_index f = r0l;
if (I->invert_cond) {
agx_index temp = t;
t = f;
f = temp;
SWAP(t, f);
}
if (I->op == AGX_OPCODE_BREAK_IF_FCMP)

View file

@ -64,9 +64,7 @@ phi_web_union(struct phi_web_node *web, unsigned x, unsigned y)
/* Union-by-rank: ensure x.rank >= y.rank */
if (web[x].rank < web[y].rank) {
unsigned temp = x;
x = y;
y = temp;
SWAP(x, y);
}
web[y].parent = x;

View file

@ -1020,9 +1020,7 @@ try_find_trip_count_vars_in_logical_op(nir_scalar *cond,
if (!nir_scalar_is_alu(logical_op) || !nir_scalar_is_const(zero)) {
/* Maybe we had it the wrong way, flip things around */
nir_scalar tmp = zero;
zero = logical_op;
logical_op = tmp;
SWAP(zero, logical_op);
/* If we still didn't find what we need then return */
if (!nir_scalar_is_const(zero))

View file

@ -517,18 +517,9 @@ do_clip_tri(struct draw_stage *stage,
}
/* swap in/out lists */
{
struct vertex_header **tmp = inlist;
inlist = outlist;
outlist = tmp;
n = outcount;
}
{
bool *tmp = inEdges;
inEdges = outEdges;
outEdges = tmp;
}
SWAP(inlist, outlist);
SWAP(inEdges, outEdges);
n = outcount;
}
/* If constant interpolated, copy provoking vertex attrib to polygon vertex[0]

View file

@ -807,11 +807,7 @@ translate_attr_convert(struct translate_sse *p,
sse2_por(p->func, tmpXMM, dataXMM);
sse2_psrlw_imm(p->func, dataXMM, 7);
sse2_por(p->func, tmpXMM, dataXMM);
{
struct x86_reg t = dataXMM;
dataXMM = tmpXMM;
tmpXMM = t;
}
SWAP(dataXMM, tmpXMM);
}
else {
sse2_punpcklbw(p->func, dataXMM, dataXMM);

View file

@ -1319,9 +1319,7 @@ d3d12_set_viewport_states(struct pipe_context *pctx,
bool reverse_depth_range = near_depth > far_depth;
if (reverse_depth_range) {
float tmp = near_depth;
near_depth = far_depth;
far_depth = tmp;
std::swap(near_depth, far_depth);
ctx->reverse_depth_range |= (1 << (start_slot + i));
} else
ctx->reverse_depth_range &= ~(1 << (start_slot + i));

View file

@ -418,9 +418,7 @@ try_setup_line(struct lp_setup_context *setup,
if (dx < 0.0f) {
/* if v2 is to the right of v1, swap pointers */
const float (*temp)[4] = v1;
v1 = v2;
v2 = temp;
SWAP(v1, v2);
/* Otherwise shift planes appropriately */
/* left edge */
@ -517,9 +515,7 @@ try_setup_line(struct lp_setup_context *setup,
if (dy > 0.0f) {
/* if v2 is on top of v1, swap pointers */
const float (*temp)[4] = v1;
v1 = v2;
v2 = temp;
SWAP(v1, v2);
if (setup->bottom_edge_rule) {
will_draw_start = y1diff >= 0.f;

View file

@ -91,9 +91,7 @@ add_dep(enum direction dir,
assert(before != after);
if (dir == R) {
struct schedule_node *t = before;
before = after;
after = t;
SWAP(before, after);
}
dag_add_edge(&after->dag, &before->dag, 0);

View file

@ -1054,9 +1054,7 @@ generate_mipmap_compressed(struct gl_context *ctx, GLenum target,
/* swap src and dest pointers */
{
GLubyte *temp = temp_src;
temp_src = temp_dst;
temp_dst = temp;
SWAP(temp_src, temp_dst);
temp_src_row_stride = temp_dst_row_stride;
temp_src_img_stride = temp_dst_img_stride;
}

View file

@ -622,9 +622,7 @@ _mesa_set_intersects(struct set *a, struct set *b)
/* iterate over the set with less entries */
if (b->entries < a->entries) {
struct set *tmp = a;
a = b;
b = tmp;
SWAP(a, b);
}
set_foreach(a, entry) {

View file

@ -98,9 +98,7 @@ compute_off_scale(uint32_t src_level_size,
*dst1_out = dst0;
/* Flip the source region */
uint32_t tmp = src0;
src0 = src1;
src1 = tmp;
SWAP(src0, src1);
}
double src_region_size = (double)src1 - (double)src0;