Browse Source

Allow integer vectors in select

gingerBill 3 years ago
parent
commit
c2f5cbdeb4
3 changed files with 7 additions and 4 deletions
  1. 1 1
      core/intrinsics/intrinsics.odin
  2. 1 1
      core/simd/simd.odin
  3. 5 2
      src/check_builtin.cpp

+ 1 - 1
core/intrinsics/intrinsics.odin

@@ -237,7 +237,7 @@ simd_reduce_or          :: proc(a: #simd[N]T) -> T ---
 simd_reduce_xor         :: proc(a: #simd[N]T) -> T ---
 
 simd_shuffle :: proc(a, b: #simd[N]T, indices: #simd[max 2*N]u32) -> #simd[len(indices)]T ---
-simd_select  :: proc(cond: #simd[N]any_boolean, true, false: #simd[N]T) -> #simd[N]T ---
+simd_select  :: proc(cond: #simd[N]boolean_or_integer, true, false: #simd[N]T) -> #simd[N]T ---
 
 
 // WASM targets only

+ 1 - 1
core/simd/simd.odin

@@ -80,7 +80,7 @@ swizzle :: builtin.swizzle
 // shuffle :: proc(a, b: #simd[N]T, indices: #simd[max 2*N]u32) -> #simd[len(indices)]T
 shuffle :: intrinsics.simd_shuffle
 
-// select :: proc(cond: #simd[N]any_boolean, true, false: #simd[N]T) -> #simd[N]T
+// select :: proc(cond: #simd[N]boolean_or_integer, true, false: #simd[N]T) -> #simd[N]T
 select :: intrinsics.simd_select
 
 splat :: #force_inline proc "contextless" ($T: typeid/#simd[$LANES]$E, value: E) -> T {

+ 5 - 2
src/check_builtin.cpp

@@ -824,8 +824,11 @@ bool check_builtin_simd_operation(CheckerContext *c, Operand *operand, Ast *call
 				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));
+			Type *cond_elem = base_array_type(cond.type);
+			if (!is_type_boolean(cond_elem) && !is_type_integer(cond_elem)) {
+				gbString cond_str = type_to_string(cond.type);
+				error(cond.expr, "'%.*s' expected a simd vector boolean or integer type, got '%s'", LIT(builtin_name), cond_str);
+				gb_string_free(cond_str);
 				return false;
 			}