Browse Source

Add `intrinsics.simd_x86__MM_SHUFFLE`

gingerBill 3 years ago
parent
commit
432b2b19e9
2 changed files with 34 additions and 0 deletions
  1. 28 0
      src/check_builtin.cpp
  2. 6 0
      src/checker_builtin_procs.hpp

+ 28 - 0
src/check_builtin.cpp

@@ -1033,6 +1033,34 @@ bool check_builtin_simd_operation(CheckerContext *c, Operand *operand, Ast *call
 			return true;
 		}
 
+	case BuiltinProc_simd_x86__MM_SHUFFLE:
+		{
+			Operand x[4] = {};
+			for (unsigned i = 0; i < 4; i++) {
+				check_expr(c, x+i, ce->args[i]); if (x[i].mode == Addressing_Invalid) return false;
+			}
+
+			u32 offsets[4] = {6, 4, 2, 0};
+			u32 result = 0;
+			for (unsigned i = 0; i < 4; i++) {
+				if (!is_type_integer(x[i].type) || x[i].mode != Addressing_Constant) {
+					gbString xs = type_to_string(x[i].type);
+					error(x[i].expr, "'%.*s' expected a constant integer", LIT(builtin_name), xs);
+					gb_string_free(xs);
+					return false;
+				}
+				i64 val = exact_value_to_i64(x[i].value);
+				if (val < 0 || val > 3) {
+					error(x[i].expr, "'%.*s' expected a constant integer in the range 0..<4, got %lld", LIT(builtin_name), cast(long long)val);
+					return false;
+				}
+				result |= cast(u32)(val) << offsets[i];
+			}
+
+			operand->type = t_untyped_integer;
+			operand->mode = Addressing_Constant;
+			operand->value = exact_value_i64(result);
+		}
 
 	default:
 		GB_PANIC("Unhandled simd intrinsic: %.*s", LIT(builtin_name));

+ 6 - 0
src/checker_builtin_procs.hpp

@@ -176,6 +176,10 @@ BuiltinProc__simd_begin,
 	BuiltinProc_simd_reverse,
 	BuiltinProc_simd_rotate_left,
 	BuiltinProc_simd_rotate_right,
+
+
+	// Platform specific SIMD intrinsics
+	BuiltinProc_simd_x86__MM_SHUFFLE,
 BuiltinProc__simd_end,
 	
 	// Platform specific intrinsics
@@ -460,6 +464,8 @@ gb_global BuiltinProc builtin_procs[BuiltinProc_COUNT] = {
 	{STR_LIT("simd_reverse"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
 	{STR_LIT("simd_rotate_left"), 2, false, Expr_Expr, BuiltinProcPkg_intrinsics},
 	{STR_LIT("simd_rotate_right"), 2, false, Expr_Expr, BuiltinProcPkg_intrinsics},
+
+	{STR_LIT("simd_x86__MM_SHUFFLE"), 4, false, Expr_Expr, BuiltinProcPkg_intrinsics},
 	{STR_LIT(""), 0, false, Expr_Stmt, BuiltinProcPkg_intrinsics},