|
@@ -956,6 +956,57 @@ bool check_builtin_simd_operation(CheckerContext *c, Operand *operand, Ast *call
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ case BuiltinProc_simd_clamp:
|
|
|
+ {
|
|
|
+ Operand x = {};
|
|
|
+ Operand y = {};
|
|
|
+ Operand z = {};
|
|
|
+ check_expr(c, &x, ce->args[0]); if (x.mode == Addressing_Invalid) { return false; }
|
|
|
+ check_expr_with_type_hint(c, &y, ce->args[1], x.type); if (y.mode == Addressing_Invalid) { return false; }
|
|
|
+ check_expr_with_type_hint(c, &z, ce->args[2], x.type); if (z.mode == Addressing_Invalid) { return false; }
|
|
|
+ convert_to_typed(c, &y, x.type);
|
|
|
+ convert_to_typed(c, &z, x.type);
|
|
|
+ if (!is_type_simd_vector(x.type)) {
|
|
|
+ error(x.expr, "'%.*s' expected a simd vector type", LIT(builtin_name));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (!is_type_simd_vector(y.type)) {
|
|
|
+ error(y.expr, "'%.*s' expected a simd vector type", LIT(builtin_name));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (!is_type_simd_vector(z.type)) {
|
|
|
+ error(z.expr, "'%.*s' expected a simd vector type", LIT(builtin_name));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (!are_types_identical(x.type, y.type)) {
|
|
|
+ gbString xs = type_to_string(x.type);
|
|
|
+ gbString ys = type_to_string(y.type);
|
|
|
+ error(x.expr, "'%.*s' expected 2 arguments of the same type, got '%s' vs '%s'", LIT(builtin_name), xs, ys);
|
|
|
+ gb_string_free(ys);
|
|
|
+ gb_string_free(xs);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (!are_types_identical(x.type, z.type)) {
|
|
|
+ gbString xs = type_to_string(x.type);
|
|
|
+ gbString zs = type_to_string(z.type);
|
|
|
+ error(x.expr, "'%.*s' expected 2 arguments of the same type, got '%s' vs '%s'", LIT(builtin_name), xs, zs);
|
|
|
+ gb_string_free(zs);
|
|
|
+ gb_string_free(xs);
|
|
|
+ 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 = x.type;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
default:
|
|
|
GB_PANIC("Unhandled simd intrinsic: %.*s", LIT(builtin_name));
|
|
|
}
|