Add intrinsics.constant_(floor|truncate|ceil|round)

This commit is contained in:
gingerBill
2025-10-30 08:52:21 +00:00
parent 13ddf66cc9
commit 99520d82fd
4 changed files with 60 additions and 1 deletions

View File

@@ -4768,6 +4768,42 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
break;
}
case BuiltinProc_constant_floor:
case BuiltinProc_constant_truncate:
case BuiltinProc_constant_ceil:
case BuiltinProc_constant_round:
{
Operand o = {};
check_expr(c, &o, ce->args[0]);
if (!is_type_integer_or_float(o.type) && (o.mode != Addressing_Constant)) {
error(ce->args[0], "Expected a constant number for '%.*s'", LIT(builtin_name));
return false;
}
operand->mode = Addressing_Constant;
operand->type = o.type;
ExactValue value = o.value;
if (value.kind == ExactValue_Integer) {
// do nothing
} else if (value.kind == ExactValue_Float) {
f64 f = value.value_float;
switch (id) {
case BuiltinProc_constant_floor: f = floor(f); break;
case BuiltinProc_constant_truncate: f = trunc(f); break;
case BuiltinProc_constant_ceil: f = ceil(f); break;
case BuiltinProc_constant_round: f = round(f); break;
default:
GB_PANIC("Unhandled built-in: %.*s", LIT(builtin_name));
break;
}
value = exact_value_float(f);
}
operand->value = value;
break;
}
case BuiltinProc_soa_struct: {
Operand x = {};
Operand y = {};