mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-20 12:44:59 -07:00
Add intrinsics.count_zeros
This commit is contained in:
@@ -9113,6 +9113,8 @@ lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv,
|
||||
|
||||
case BuiltinProc_count_ones:
|
||||
return lb_emit_count_ones(p, lb_build_expr(p, ce->args[0]), tv.type);
|
||||
case BuiltinProc_count_zeros:
|
||||
return lb_emit_count_zeros(p, lb_build_expr(p, ce->args[0]), tv.type);
|
||||
|
||||
case BuiltinProc_reverse_bits:
|
||||
return lb_emit_reverse_bits(p, lb_build_expr(p, ce->args[0]), tv.type);
|
||||
@@ -9971,6 +9973,14 @@ lbValue lb_emit_count_ones(lbProcedure *p, lbValue x, Type *type) {
|
||||
return res;
|
||||
}
|
||||
|
||||
lbValue lb_emit_count_zeros(lbProcedure *p, lbValue x, Type *type) {
|
||||
i64 sz = 8*type_size_of(type);
|
||||
lbValue size = lb_const_int(p->module, type, cast(u64)sz);
|
||||
lbValue count = lb_emit_count_ones(p, x, type);
|
||||
return lb_emit_arith(p, Token_Sub, size, count, type);
|
||||
}
|
||||
|
||||
|
||||
|
||||
lbValue lb_emit_count_trailing_zeros(lbProcedure *p, lbValue x, Type *type) {
|
||||
x = lb_emit_conv(p, x, type);
|
||||
|
||||
Reference in New Issue
Block a user