aboutsummaryrefslogtreecommitdiff
path: root/src/check_builtin.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2022-05-25 20:27:14 +0100
committergingerBill <bill@gingerbill.org>2022-05-25 20:27:14 +0100
commit4c4480104de9d6ba520215afb6330c95b0e56b93 (patch)
tree8e413cbc0df4cdcec9baeb83226e269112340a85 /src/check_builtin.cpp
parent5c72974167405a37bd397788e3224d773efd9c46 (diff)
Add `simd_extract` and `simd_insert`
Diffstat (limited to 'src/check_builtin.cpp')
-rw-r--r--src/check_builtin.cpp120
1 files changed, 88 insertions, 32 deletions
diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp
index 13eb9f47d..ab4cc210c 100644
--- a/src/check_builtin.cpp
+++ b/src/check_builtin.cpp
@@ -425,14 +425,9 @@ bool check_builtin_simd_operation(CheckerContext *c, Operand *operand, Ast *call
{
Operand x = {};
Operand y = {};
- check_expr(c, &x, ce->args[0]);
- check_expr(c, &y, ce->args[1]);
- if (x.mode == Addressing_Invalid) {
- return false;
- }
- if (y.mode == Addressing_Invalid) {
- return false;
- }
+ 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; }
+ convert_to_typed(c, &y, x.type);
if (!is_type_simd_vector(x.type)) {
error(x.expr, "'%.*s' expected a simd vector type", LIT(builtin_name));
return false;
@@ -470,14 +465,9 @@ bool check_builtin_simd_operation(CheckerContext *c, Operand *operand, Ast *call
{
Operand x = {};
Operand y = {};
- check_expr(c, &x, ce->args[0]);
- check_expr(c, &y, ce->args[1]);
- if (x.mode == Addressing_Invalid) {
- return false;
- }
- if (y.mode == Addressing_Invalid) {
- return false;
- }
+ 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; }
+ convert_to_typed(c, &y, x.type);
if (!is_type_simd_vector(x.type)) {
error(x.expr, "'%.*s' expected a simd vector type", LIT(builtin_name));
return false;
@@ -514,14 +504,9 @@ bool check_builtin_simd_operation(CheckerContext *c, Operand *operand, Ast *call
{
Operand x = {};
Operand y = {};
- check_expr(c, &x, ce->args[0]);
- check_expr(c, &y, ce->args[1]);
- if (x.mode == Addressing_Invalid) {
- return false;
- }
- if (y.mode == Addressing_Invalid) {
- return false;
- }
+ 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; }
+ convert_to_typed(c, &y, x.type);
if (!is_type_simd_vector(x.type)) {
error(x.expr, "'%.*s' expected a simd vector type", LIT(builtin_name));
return false;
@@ -599,14 +584,9 @@ bool check_builtin_simd_operation(CheckerContext *c, Operand *operand, Ast *call
Operand x = {};
Operand y = {};
- check_expr(c, &x, ce->args[0]);
- check_expr(c, &y, ce->args[1]);
- if (x.mode == Addressing_Invalid) {
- return false;
- }
- if (y.mode == Addressing_Invalid) {
- return false;
- }
+ 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; }
+ convert_to_typed(c, &y, x.type);
if (!is_type_simd_vector(x.type)) {
error(x.expr, "'%.*s' expected a simd vector type", LIT(builtin_name));
return false;
@@ -639,6 +619,81 @@ bool check_builtin_simd_operation(CheckerContext *c, Operand *operand, Ast *call
operand->type = alloc_type_simd_vector(count, new_elem);
return true;
}
+
+ case BuiltinProc_simd_extract:
+ {
+ 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;
+ }
+ i64 max_count = x.type->SimdVector.count;
+ i64 value = -1;
+ if (!check_index_value(c, x.type, false, ce->args[1], max_count, &value)) {
+ return false;
+ }
+ if (max_count < 0) {
+ error(ce->args[1], "'%.*s' expected a constant integer index, got '%lld'", LIT(builtin_name), cast(long long)value);
+ return false;
+ }
+
+ operand->mode = Addressing_Value;
+ operand->type = elem;
+ return true;
+ }
+ break;
+ case BuiltinProc_simd_insert:
+ {
+ 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;
+ }
+ i64 max_count = x.type->SimdVector.count;
+ i64 value = -1;
+ if (!check_index_value(c, x.type, false, ce->args[1], max_count, &value)) {
+ return false;
+ }
+ if (max_count < 0) {
+ error(ce->args[1], "'%.*s' expected a constant integer index, got '%lld'", LIT(builtin_name), cast(long long)value);
+ return false;
+ }
+
+ Operand y = {};
+ check_expr_with_type_hint(c, &y, ce->args[2], elem); if (y.mode == Addressing_Invalid) { return false; }
+ convert_to_typed(c, &y, elem);
+ if (!are_types_identical(y.type, elem)) {
+ gbString et = type_to_string(elem);
+ gbString yt = type_to_string(y.type);
+ error(y.expr, "'%.*s' expected a type of '%s' to insert, got '%s'", LIT(builtin_name), et, yt);
+ gb_string_free(yt);
+ gb_string_free(et);
+ return false;
+ }
+
+ operand->mode = Addressing_Value;
+ operand->type = x.type;
+ return true;
+ }
+ break;
default:
GB_PANIC("Unhandled simd intrinsic: %.*s", LIT(builtin_name));
}
@@ -736,6 +791,7 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32
}
operand->mode = Addressing_Value;
operand->value = {};
+ operand->expr = call;
return ok;
}