mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Rename $$fabs to $$abs
This commit is contained in:
committed by
Christoffer Lerno
parent
fffb8a1d0c
commit
5d15ec23bb
@@ -81,6 +81,11 @@ macro min(x, y) @builtin
|
||||
return x < y ? x : y;
|
||||
}
|
||||
|
||||
macro abs(x) @builtin
|
||||
{
|
||||
return $$abs(x);
|
||||
}
|
||||
|
||||
fn double log10(double x) @inline
|
||||
{
|
||||
return $$log10(x);
|
||||
@@ -126,11 +131,6 @@ fn double pow(double x, double y) @inline
|
||||
return $$pow(x, y);
|
||||
}
|
||||
|
||||
fn double fabs(double x) @inline
|
||||
{
|
||||
return $$fabs(x);
|
||||
}
|
||||
|
||||
fn double trunc(double x) @inline
|
||||
{
|
||||
return $$trunc(x);
|
||||
|
||||
@@ -767,7 +767,7 @@ typedef enum
|
||||
BUILTIN_MIN,
|
||||
BUILTIN_POW,
|
||||
BUILTIN_EXP,
|
||||
BUILTIN_FABS,
|
||||
BUILTIN_ABS,
|
||||
BUILTIN_FMA,
|
||||
BUILTIN_FSHR,
|
||||
BUILTIN_FSHL,
|
||||
|
||||
@@ -654,7 +654,7 @@ void llvm_codegen_setup()
|
||||
intrinsic_id.lrint = lookup_intrinsic("llvm.lrint");
|
||||
intrinsic_id.llrint = lookup_intrinsic("llvm.llrint");
|
||||
|
||||
//intrinsic_id.abs = lookup_intrinsic("llvm.abs");
|
||||
intrinsic_id.abs = lookup_intrinsic("llvm.abs");
|
||||
intrinsic_id.smax = lookup_intrinsic("llvm.smax");
|
||||
intrinsic_id.smin = lookup_intrinsic("llvm.smin");
|
||||
intrinsic_id.umax = lookup_intrinsic("llvm.umax");
|
||||
|
||||
@@ -4126,7 +4126,7 @@ static void llvm_emit_intrinsic_expr(GenContext *c, unsigned intrinsic, BEValue
|
||||
llvm_value_rvalue(c, be_value);
|
||||
arg_results[i] = be_value->value;
|
||||
}
|
||||
if (intrinsic == intrinsic_id.ctlz || intrinsic == intrinsic_id.cttz)
|
||||
if (intrinsic == intrinsic_id.ctlz || intrinsic == intrinsic_id.cttz || intrinsic == intrinsic_id.abs)
|
||||
{
|
||||
arg_results[1] = llvm_get_zero_raw(c->bool_type);
|
||||
arguments++;
|
||||
@@ -4326,6 +4326,7 @@ unsigned llvm_get_intrinsic(BuiltinFunction func)
|
||||
case BUILTIN_NONE:
|
||||
case BUILTIN_UNREACHABLE:
|
||||
case BUILTIN_STACKTRACE:
|
||||
case BUILTIN_ABS:
|
||||
UNREACHABLE
|
||||
case BUILTIN_SYSCLOCK:
|
||||
return intrinsic_id.readcyclecounter;
|
||||
@@ -4349,8 +4350,6 @@ unsigned llvm_get_intrinsic(BuiltinFunction func)
|
||||
return intrinsic_id.maxnum;
|
||||
case BUILTIN_MIN:
|
||||
return intrinsic_id.minnum;
|
||||
case BUILTIN_FABS:
|
||||
return intrinsic_id.fabs;
|
||||
case BUILTIN_FMA:
|
||||
return intrinsic_id.fma;
|
||||
case BUILTIN_FSHL:
|
||||
@@ -4587,6 +4586,26 @@ void llvm_emit_builtin_call(GenContext *c, BEValue *result_value, Expr *expr)
|
||||
UNREACHABLE
|
||||
}
|
||||
}
|
||||
else if (func == BUILTIN_ABS)
|
||||
{
|
||||
Type *type = type_flatten(expr->call_expr.arguments[0]->type);
|
||||
RETRY3:
|
||||
switch (type->type_kind)
|
||||
{
|
||||
case TYPE_BOOL:
|
||||
case ALL_INTS:
|
||||
intrinsic = intrinsic_id.abs;
|
||||
break;
|
||||
case ALL_FLOATS:
|
||||
intrinsic = intrinsic_id.fabs;
|
||||
break;
|
||||
case TYPE_VECTOR:
|
||||
type = type->array.base;
|
||||
goto RETRY3;
|
||||
default:
|
||||
UNREACHABLE
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
intrinsic = llvm_get_intrinsic(func);
|
||||
|
||||
@@ -2469,7 +2469,7 @@ static inline unsigned builtin_expected_args(BuiltinFunction func)
|
||||
case BUILTIN_LOG:
|
||||
case BUILTIN_LOG2:
|
||||
case BUILTIN_LOG10:
|
||||
case BUILTIN_FABS:
|
||||
case BUILTIN_ABS:
|
||||
case BUILTIN_VOLATILE_LOAD:
|
||||
case BUILTIN_CTPOP:
|
||||
case BUILTIN_CTTZ:
|
||||
@@ -2700,7 +2700,6 @@ static inline bool sema_expr_analyse_builtin_call(SemaContext *context, Expr *ex
|
||||
case BUILTIN_COS:
|
||||
case BUILTIN_SIN:
|
||||
case BUILTIN_EXP:
|
||||
case BUILTIN_FABS:
|
||||
case BUILTIN_LOG:
|
||||
case BUILTIN_LOG2:
|
||||
case BUILTIN_LOG10:
|
||||
@@ -2717,6 +2716,11 @@ static inline bool sema_expr_analyse_builtin_call(SemaContext *context, Expr *ex
|
||||
if (!sema_check_builtin_args_match(args, arg_count)) return false;
|
||||
rtype = args[0]->type;
|
||||
break;
|
||||
case BUILTIN_ABS:
|
||||
if (!sema_check_builtin_args(args, (BuiltinArg[]) { BA_NUMLIKE }, arg_count)) return false;
|
||||
if (!sema_check_builtin_args_match(args, arg_count)) return false;
|
||||
rtype = args[0]->type;
|
||||
break;
|
||||
case BUILTIN_MAX:
|
||||
case BUILTIN_MIN:
|
||||
if (!sema_check_builtin_args(args, (BuiltinArg[]) { BA_NUMLIKE, BA_NUMLIKE }, arg_count)) return false;
|
||||
|
||||
@@ -198,7 +198,7 @@ void symtab_init(uint32_t capacity)
|
||||
builtin_list[BUILTIN_MAX] = KW_DEF("max");
|
||||
builtin_list[BUILTIN_MIN] = KW_DEF("min");
|
||||
builtin_list[BUILTIN_FMA] = KW_DEF("fma");
|
||||
builtin_list[BUILTIN_FABS] = KW_DEF("fabs");
|
||||
builtin_list[BUILTIN_ABS] = KW_DEF("abs");
|
||||
builtin_list[BUILTIN_FSHL] = KW_DEF("fshl");
|
||||
builtin_list[BUILTIN_FSHR] = KW_DEF("fshr");
|
||||
builtin_list[BUILTIN_VOLATILE_STORE] = KW_DEF("volatile_store");
|
||||
|
||||
18
test/test_suite/builtins/builtin_vector_abs.c3t
Normal file
18
test/test_suite/builtins/builtin_vector_abs.c3t
Normal file
@@ -0,0 +1,18 @@
|
||||
// #target: macos-x64
|
||||
module test;
|
||||
fn void main()
|
||||
{
|
||||
{
|
||||
float[<2>] vf1 = { 1, -1 };
|
||||
float[<2>] absf = $$abs(vf1);
|
||||
}
|
||||
{
|
||||
int[<2>] v1 = { 1, -1 };
|
||||
int[<2>] absi = $$abs(v1);
|
||||
}
|
||||
}
|
||||
|
||||
/* #expect: test.ll
|
||||
|
||||
%1 = call <2 x float> @llvm.fabs.v2f32(<2 x float> %0)
|
||||
%3 = call <2 x i32> @llvm.abs.v2i32(<2 x i32> %2, i1 false)
|
||||
18
test/test_suite2/builtins/builtin_vector_abs.c3t
Normal file
18
test/test_suite2/builtins/builtin_vector_abs.c3t
Normal file
@@ -0,0 +1,18 @@
|
||||
// #target: macos-x64
|
||||
module test;
|
||||
fn void main()
|
||||
{
|
||||
{
|
||||
float[<2>] vf1 = { 1, -1 };
|
||||
float[<2>] absf = $$abs(vf1);
|
||||
}
|
||||
{
|
||||
int[<2>] v1 = { 1, -1 };
|
||||
int[<2>] absi = $$abs(v1);
|
||||
}
|
||||
}
|
||||
|
||||
/* #expect: test.ll
|
||||
|
||||
%1 = call <2 x float> @llvm.fabs.v2f32(<2 x float> %0)
|
||||
%3 = call <2 x i32> @llvm.abs.v2i32(<2 x i32> %2, i1 false)
|
||||
Reference in New Issue
Block a user