diff options
| author | gingerBill <bill@gingerbill.org> | 2022-05-25 23:34:41 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2022-05-25 23:34:41 +0100 |
| commit | 7002c94a63c58aa0ac5a5d74b1fffd1511aeb699 (patch) | |
| tree | 16e0b4a5d5b41004bf33800da22cc7c02b42be7f /src/check_builtin.cpp | |
| parent | 57e69ea3922ce56b3c959e60aeeaa032ab81ff8d (diff) | |
Add `intrinsics.simd_select`
Diffstat (limited to 'src/check_builtin.cpp')
| -rw-r--r-- | src/check_builtin.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp index 064edd3b7..eaf71fdab 100644 --- a/src/check_builtin.cpp +++ b/src/check_builtin.cpp @@ -815,6 +815,57 @@ bool check_builtin_simd_operation(CheckerContext *c, Operand *operand, Ast *call return true; } + case BuiltinProc_simd_select: + { + Operand cond = {}; + check_expr(c, &cond, ce->args[0]); if (cond.mode == Addressing_Invalid) { return false; } + + if (!is_type_simd_vector(cond.type)) { + error(cond.expr, "'%.*s' expected a simd vector boolean type", LIT(builtin_name)); + return false; + } + if (!is_type_boolean(base_array_type(cond.type))) { + error(cond.expr, "'%.*s' expected a simd vector boolean type", LIT(builtin_name)); + return false; + } + + Operand x = {}; + Operand y = {}; + check_expr(c, &x, ce->args[1]); if (x.mode == Addressing_Invalid) { return false; } + check_expr_with_type_hint(c, &y, ce->args[2], 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; + } + if (!is_type_simd_vector(y.type)) { + error(y.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 results of the same type, got '%s' vs '%s'", LIT(builtin_name), xs, ys); + gb_string_free(ys); + gb_string_free(xs); + return false; + } + + if (cond.type->SimdVector.count != x.type->SimdVector.count) { + error(x.expr, "'%.*s' expected condition vector to match the length of the result lengths, got '%lld' vs '%lld'", + LIT(builtin_name), + cast(long long)cond.type->SimdVector.count, + cast(long long)x.type->SimdVector.count); + return false; + } + + + operand->mode = Addressing_Value; + operand->type = x.type; + return true; + } + + // case BuiltinProc_simd_rotate_left: // { |