Add intrinsics.simd_reduce_*

This commit is contained in:
gingerBill
2022-05-25 22:04:47 +01:00
parent 8ac12886ed
commit 10e4de3c01
4 changed files with 167 additions and 9 deletions
+50
View File
@@ -695,6 +695,56 @@ bool check_builtin_simd_operation(CheckerContext *c, Operand *operand, Ast *call
}
break;
case BuiltinProc_simd_reduce_add_ordered:
case BuiltinProc_simd_reduce_mul_ordered:
case BuiltinProc_simd_reduce_min:
case BuiltinProc_simd_reduce_max:
{
Operand x = {};
check_expr(c, &x, ce->args[0]); if (x.mode == Addressing_Invalid) { return false; }
if (!is_type_simd_vector(x.type)) {
error(x.expr, "'%.*s' expected a simd vector type", LIT(builtin_name));
return false;
}
Type *elem = base_array_type(x.type);
if (!is_type_integer(elem) && !is_type_float(elem)) {
gbString xs = type_to_string(x.type);
error(x.expr, "'%.*s' expected a #simd type with an integer or floating-point element, got '%s'", LIT(builtin_name), xs);
gb_string_free(xs);
return false;
}
operand->mode = Addressing_Value;
operand->type = base_array_type(x.type);
return true;
}
case BuiltinProc_simd_reduce_and:
case BuiltinProc_simd_reduce_or:
case BuiltinProc_simd_reduce_xor:
{
Operand x = {};
check_expr(c, &x, ce->args[0]); if (x.mode == Addressing_Invalid) { return false; }
if (!is_type_simd_vector(x.type)) {
error(x.expr, "'%.*s' expected a simd vector type", LIT(builtin_name));
return false;
}
Type *elem = base_array_type(x.type);
if (!is_type_integer(elem)) {
gbString xs = type_to_string(x.type);
error(x.expr, "'%.*s' expected a #simd type with an integer element, got '%s'", LIT(builtin_name), xs);
gb_string_free(xs);
return false;
}
operand->mode = Addressing_Value;
operand->type = base_array_type(x.type);
return true;
}
// case BuiltinProc_simd_rotate_left:
// {
// Operand x = {};