Add intrinsics.count_zeros

This commit is contained in:
gingerBill
2021-04-25 20:50:25 +01:00
parent 4662bad59c
commit 2691c394e0
5 changed files with 23 additions and 64 deletions
+10
View File
@@ -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);