mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Adding $$reverse. Bump to 0.3.45
This commit is contained in:
committed by
Christoffer Lerno
parent
4d27150952
commit
c8166f6fdb
@@ -4345,6 +4345,7 @@ unsigned llvm_get_intrinsic(BuiltinFunction func)
|
||||
case BUILTIN_STACKTRACE:
|
||||
case BUILTIN_ABS:
|
||||
case BUILTIN_SHUFFLEVECTOR:
|
||||
case BUILTIN_REVERSE:
|
||||
UNREACHABLE
|
||||
case BUILTIN_SYSCLOCK:
|
||||
return intrinsic_id.readcyclecounter;
|
||||
@@ -4382,7 +4383,7 @@ unsigned llvm_get_intrinsic(BuiltinFunction func)
|
||||
return intrinsic_id.ctlz;
|
||||
case BUILTIN_CTTZ:
|
||||
return intrinsic_id.cttz;
|
||||
case BUILTIN_CTPOP:
|
||||
case BUILTIN_POPCOUNT:
|
||||
return intrinsic_id.ctpop;
|
||||
case BUILTIN_LOG2:
|
||||
return intrinsic_id.log2;
|
||||
@@ -4561,6 +4562,26 @@ INLINE void llvm_emit_shufflevector(GenContext *c, BEValue *result_value, Expr *
|
||||
return;
|
||||
}
|
||||
|
||||
INLINE void llvm_emit_reverse(GenContext *c, BEValue *result_value, Expr *expr)
|
||||
{
|
||||
Expr **args = expr->call_expr.arguments;
|
||||
llvm_emit_expr(c, result_value, args[0]);
|
||||
llvm_value_rvalue(c, result_value);
|
||||
Type *rtype = result_value->type;
|
||||
LLVMValueRef arg1 = result_value->value;
|
||||
LLVMValueRef arg2 = LLVMGetPoison(LLVMTypeOf(arg1));
|
||||
LLVMValueRef buff[128];
|
||||
unsigned elements = rtype->array.len;
|
||||
LLVMValueRef *mask_element = elements > 128 ? MALLOC(sizeof(LLVMValueRef)) : buff;
|
||||
LLVMTypeRef mask_element_type = llvm_get_type(c, type_int);
|
||||
for (unsigned i = 0; i < elements; i++)
|
||||
{
|
||||
mask_element[i] = LLVMConstInt(mask_element_type, elements - i - 1, false);
|
||||
}
|
||||
LLVMValueRef mask = LLVMConstVector(mask_element, elements);
|
||||
llvm_value_set(result_value, LLVMBuildShuffleVector(c->builder, arg1, arg2, mask, "reverse"), rtype);
|
||||
}
|
||||
|
||||
void llvm_emit_builtin_call(GenContext *c, BEValue *result_value, Expr *expr)
|
||||
{
|
||||
BuiltinFunction func = exprptr(expr->call_expr.function)->builtin_expr.builtin;
|
||||
@@ -4578,6 +4599,11 @@ void llvm_emit_builtin_call(GenContext *c, BEValue *result_value, Expr *expr)
|
||||
llvm_emit_shufflevector(c, result_value, expr);
|
||||
return;
|
||||
}
|
||||
if (func == BUILTIN_REVERSE)
|
||||
{
|
||||
llvm_emit_reverse(c, result_value, expr);
|
||||
return;
|
||||
}
|
||||
if (func == BUILTIN_STACKTRACE)
|
||||
{
|
||||
if (!c->debug.enable_stacktrace)
|
||||
|
||||
Reference in New Issue
Block a user