Skip to content

Commit

Permalink
Calculate power of 2
Browse files Browse the repository at this point in the history
  • Loading branch information
tyfkda committed Jul 29, 2024
1 parent e045a55 commit afeb1a9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
5 changes: 1 addition & 4 deletions src/cc/backend/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,7 @@ static enum VRegSize get_elem_vtype(const Type *type) {
}

assert(s > 0);
enum VRegSize vsize = VRegSize1;
for (; s >>= 1, s > 0; ++vsize)
;
return vsize;
return most_significant_bit(s);
}

void gen_memcpy(const Type *type, VReg *dst, VReg *src) {
Expand Down
7 changes: 1 addition & 6 deletions src/cc/backend/codegen_expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ enum VRegSize to_vsize(const Type *type) {
int size = type_size(type);
assert(1 <= size && size <= MAX_REG_SIZE && IS_POWER_OF_2(size));
UNUSED(MAX_REG_SIZE);
for (enum VRegSize vsize = VRegSize1; vsize <= VRegSize8; ++vsize) {
if (size == 1 << vsize)
return vsize;
}
assert(!"Must not reached");
return -1;
return most_significant_bit(size);
}

int to_vflag(const Type *type) {
Expand Down

0 comments on commit afeb1a9

Please sign in to comment.