mirror of
https://github.com/odin-lang/Odin.git
synced 2026-02-15 15:44:04 +00:00
Add shortcut for unsigned_x/power_of_two -> unsigned_x >> log2(power_of_two)
This commit is contained in:
@@ -1153,6 +1153,17 @@ gb_internal LLVMValueRef lb_integer_division(lbProcedure *p, LLVMValueRef lhs, L
|
||||
return zero;
|
||||
}
|
||||
} else {
|
||||
if (!is_signed && lb_sizeof(type) <= 8) {
|
||||
u64 v = cast(u64)LLVMConstIntGetZExtValue(rhs);
|
||||
if (v == 1) {
|
||||
return lhs;
|
||||
} else if (is_power_of_two_u64(v)) {
|
||||
u64 n = floor_log2(v);
|
||||
LLVMValueRef bits = LLVMConstInt(type, n, false);
|
||||
return LLVMBuildLShr(p->builder, lhs, bits, "");
|
||||
}
|
||||
}
|
||||
|
||||
return call(p->builder, lhs, rhs, "");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user