mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-28 00:01:48 -07:00
Add simd_reverse
This commit is contained in:
@@ -912,6 +912,19 @@ bool check_builtin_simd_operation(CheckerContext *c, Operand *operand, Ast *call
|
||||
return true;
|
||||
}
|
||||
|
||||
case BuiltinProc_simd_reverse:
|
||||
{
|
||||
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;
|
||||
}
|
||||
operand->type = x.type;
|
||||
operand->mode = Addressing_Value;
|
||||
return true;
|
||||
}
|
||||
|
||||
default:
|
||||
GB_PANIC("Unhandled simd intrinsic: %.*s", LIT(builtin_name));
|
||||
|
||||
@@ -165,6 +165,8 @@ BuiltinProc__simd_begin,
|
||||
BuiltinProc_simd_floor,
|
||||
BuiltinProc_simd_trunc,
|
||||
BuiltinProc_simd_nearest,
|
||||
|
||||
BuiltinProc_simd_reverse,
|
||||
BuiltinProc__simd_end,
|
||||
|
||||
// Platform specific intrinsics
|
||||
@@ -433,6 +435,8 @@ gb_global BuiltinProc builtin_procs[BuiltinProc_COUNT] = {
|
||||
{STR_LIT("simd_floor"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("simd_trunc"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("simd_nearest"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
|
||||
{STR_LIT("simd_reverse"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT(""), 0, false, Expr_Stmt, BuiltinProcPkg_intrinsics},
|
||||
|
||||
|
||||
|
||||
@@ -1338,6 +1338,22 @@ lbValue lb_build_builtin_simd_proc(lbProcedure *p, Ast *expr, TypeAndValue const
|
||||
return res;
|
||||
}
|
||||
|
||||
case BuiltinProc_simd_reverse:
|
||||
{
|
||||
i64 count = get_array_type_count(arg0.type);
|
||||
LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, count);
|
||||
LLVMTypeRef llvm_u32 = lb_type(m, t_u32);
|
||||
for (i64 i = 0; i < count; i++) {
|
||||
values[i] = LLVMConstInt(llvm_u32, count-1-i, false);
|
||||
}
|
||||
LLVMValueRef mask = LLVMConstVector(values, cast(unsigned)count);
|
||||
|
||||
LLVMValueRef v = arg0.value;
|
||||
res.value = LLVMBuildShuffleVector(p->builder, v, v, mask, "");
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
GB_PANIC("Unhandled simd intrinsic: '%.*s'", LIT(builtin_procs[builtin_id].name));
|
||||
|
||||
|
||||
@@ -1598,6 +1598,8 @@ i64 get_array_type_count(Type *t) {
|
||||
return bt->Array.count;
|
||||
} else if (bt->kind == Type_EnumeratedArray) {
|
||||
return bt->EnumeratedArray.count;
|
||||
} else if (bt->kind == Type_SimdVector) {
|
||||
return bt->SimdVector.count;
|
||||
}
|
||||
GB_ASSERT(is_type_array_like(t));
|
||||
return -1;
|
||||
|
||||
Reference in New Issue
Block a user