mirror of
https://github.com/roc-lang/roc.git
synced 2025-11-03 06:02:54 +00:00
Switch Num.tan to a zig builtin
It should be able to share some work between sine and cosine to run faster.
This commit is contained in:
parent
7986d6cdba
commit
108d9a54e3
11 changed files with 25 additions and 4 deletions
|
|
@ -163,6 +163,7 @@ comptime {
|
||||||
|
|
||||||
num.exportSin(T, ROC_BUILTINS ++ "." ++ NUM ++ ".sin.");
|
num.exportSin(T, ROC_BUILTINS ++ "." ++ NUM ++ ".sin.");
|
||||||
num.exportCos(T, ROC_BUILTINS ++ "." ++ NUM ++ ".cos.");
|
num.exportCos(T, ROC_BUILTINS ++ "." ++ NUM ++ ".cos.");
|
||||||
|
num.exportTan(T, ROC_BUILTINS ++ "." ++ NUM ++ ".tan.");
|
||||||
|
|
||||||
num.exportPow(T, ROC_BUILTINS ++ "." ++ NUM ++ ".pow.");
|
num.exportPow(T, ROC_BUILTINS ++ "." ++ NUM ++ ".pow.");
|
||||||
num.exportLog(T, ROC_BUILTINS ++ "." ++ NUM ++ ".log.");
|
num.exportLog(T, ROC_BUILTINS ++ "." ++ NUM ++ ".log.");
|
||||||
|
|
|
||||||
|
|
@ -168,6 +168,15 @@ pub fn exportCos(comptime T: type, comptime name: []const u8) void {
|
||||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn exportTan(comptime T: type, comptime name: []const u8) void {
|
||||||
|
comptime var f = struct {
|
||||||
|
fn func(input: T) callconv(.C) T {
|
||||||
|
return math.tan(input);
|
||||||
|
}
|
||||||
|
}.func;
|
||||||
|
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
||||||
|
}
|
||||||
|
|
||||||
pub fn exportLog(comptime T: type, comptime name: []const u8) void {
|
pub fn exportLog(comptime T: type, comptime name: []const u8) void {
|
||||||
comptime var f = struct {
|
comptime var f = struct {
|
||||||
fn func(input: T) callconv(.C) T {
|
fn func(input: T) callconv(.C) T {
|
||||||
|
|
|
||||||
|
|
@ -825,11 +825,7 @@ max = \a, b ->
|
||||||
|
|
||||||
sin : Frac a -> Frac a
|
sin : Frac a -> Frac a
|
||||||
cos : Frac a -> Frac a
|
cos : Frac a -> Frac a
|
||||||
|
|
||||||
tan : Frac a -> Frac a
|
tan : Frac a -> Frac a
|
||||||
tan = \x ->
|
|
||||||
# `tan` is not available as an intrinsic in LLVM
|
|
||||||
Num.div (Num.sin x) (Num.cos x)
|
|
||||||
|
|
||||||
asin : Frac a -> Frac a
|
asin : Frac a -> Frac a
|
||||||
acos : Frac a -> Frac a
|
acos : Frac a -> Frac a
|
||||||
|
|
|
||||||
|
|
@ -272,6 +272,7 @@ macro_rules! int_intrinsic {
|
||||||
|
|
||||||
pub const NUM_SIN: IntrinsicName = float_intrinsic!("roc_builtins.num.sin");
|
pub const NUM_SIN: IntrinsicName = float_intrinsic!("roc_builtins.num.sin");
|
||||||
pub const NUM_COS: IntrinsicName = float_intrinsic!("roc_builtins.num.cos");
|
pub const NUM_COS: IntrinsicName = float_intrinsic!("roc_builtins.num.cos");
|
||||||
|
pub const NUM_TAN: IntrinsicName = float_intrinsic!("roc_builtins.num.tan");
|
||||||
pub const NUM_ASIN: IntrinsicName = float_intrinsic!("roc_builtins.num.asin");
|
pub const NUM_ASIN: IntrinsicName = float_intrinsic!("roc_builtins.num.asin");
|
||||||
pub const NUM_ACOS: IntrinsicName = float_intrinsic!("roc_builtins.num.acos");
|
pub const NUM_ACOS: IntrinsicName = float_intrinsic!("roc_builtins.num.acos");
|
||||||
pub const NUM_ATAN: IntrinsicName = float_intrinsic!("roc_builtins.num.atan");
|
pub const NUM_ATAN: IntrinsicName = float_intrinsic!("roc_builtins.num.atan");
|
||||||
|
|
|
||||||
|
|
@ -186,6 +186,7 @@ map_symbol_to_lowlevel_and_arity! {
|
||||||
NumNeg; NUM_NEG; 1,
|
NumNeg; NUM_NEG; 1,
|
||||||
NumSin; NUM_SIN; 1,
|
NumSin; NUM_SIN; 1,
|
||||||
NumCos; NUM_COS; 1,
|
NumCos; NUM_COS; 1,
|
||||||
|
NumTan; NUM_TAN; 1,
|
||||||
NumSqrtUnchecked; NUM_SQRT; 1,
|
NumSqrtUnchecked; NUM_SQRT; 1,
|
||||||
NumLogUnchecked; NUM_LOG; 1,
|
NumLogUnchecked; NUM_LOG; 1,
|
||||||
NumRound; NUM_ROUND; 1,
|
NumRound; NUM_ROUND; 1,
|
||||||
|
|
|
||||||
|
|
@ -935,6 +935,7 @@ pub(crate) fn run_low_level<'a, 'ctx>(
|
||||||
| NumLogUnchecked
|
| NumLogUnchecked
|
||||||
| NumSin
|
| NumSin
|
||||||
| NumCos
|
| NumCos
|
||||||
|
| NumTan
|
||||||
| NumCeiling
|
| NumCeiling
|
||||||
| NumFloor
|
| NumFloor
|
||||||
| NumToFrac
|
| NumToFrac
|
||||||
|
|
@ -2655,6 +2656,7 @@ fn build_float_unary_op<'a, 'ctx>(
|
||||||
// trigonometry
|
// trigonometry
|
||||||
NumSin => call_bitcode_fn(env, &[arg.into()], &bitcode::NUM_SIN[float_width]),
|
NumSin => call_bitcode_fn(env, &[arg.into()], &bitcode::NUM_SIN[float_width]),
|
||||||
NumCos => call_bitcode_fn(env, &[arg.into()], &bitcode::NUM_COS[float_width]),
|
NumCos => call_bitcode_fn(env, &[arg.into()], &bitcode::NUM_COS[float_width]),
|
||||||
|
NumTan => call_bitcode_fn(env, &[arg.into()], &bitcode::NUM_TAN[float_width]),
|
||||||
|
|
||||||
NumAtan => call_bitcode_fn(env, &[arg.into()], &bitcode::NUM_ATAN[float_width]),
|
NumAtan => call_bitcode_fn(env, &[arg.into()], &bitcode::NUM_ATAN[float_width]),
|
||||||
NumAcos => call_bitcode_fn(env, &[arg.into()], &bitcode::NUM_ACOS[float_width]),
|
NumAcos => call_bitcode_fn(env, &[arg.into()], &bitcode::NUM_ACOS[float_width]),
|
||||||
|
|
|
||||||
|
|
@ -1539,6 +1539,12 @@ impl<'a> LowLevelCall<'a> {
|
||||||
}
|
}
|
||||||
_ => panic_ret_type(),
|
_ => panic_ret_type(),
|
||||||
},
|
},
|
||||||
|
NumTan => match self.ret_layout_raw {
|
||||||
|
LayoutRepr::Builtin(Builtin::Float(width)) => {
|
||||||
|
self.load_args_and_call_zig(backend, &bitcode::NUM_TAN[width]);
|
||||||
|
}
|
||||||
|
_ => panic_ret_type(),
|
||||||
|
},
|
||||||
NumSqrtUnchecked => {
|
NumSqrtUnchecked => {
|
||||||
self.load_args(backend);
|
self.load_args(backend);
|
||||||
match self.ret_layout_raw {
|
match self.ret_layout_raw {
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,7 @@ pub enum LowLevel {
|
||||||
NumNeg,
|
NumNeg,
|
||||||
NumSin,
|
NumSin,
|
||||||
NumCos,
|
NumCos,
|
||||||
|
NumTan,
|
||||||
NumSqrtUnchecked,
|
NumSqrtUnchecked,
|
||||||
NumLogUnchecked,
|
NumLogUnchecked,
|
||||||
NumRound,
|
NumRound,
|
||||||
|
|
@ -324,6 +325,7 @@ map_symbol_to_lowlevel! {
|
||||||
NumNeg <= NUM_NEG,
|
NumNeg <= NUM_NEG,
|
||||||
NumSin <= NUM_SIN,
|
NumSin <= NUM_SIN,
|
||||||
NumCos <= NUM_COS,
|
NumCos <= NUM_COS,
|
||||||
|
NumTan <= NUM_TAN,
|
||||||
NumSqrtUnchecked <= NUM_SQRT,
|
NumSqrtUnchecked <= NUM_SQRT,
|
||||||
NumLogUnchecked <= NUM_LOG,
|
NumLogUnchecked <= NUM_LOG,
|
||||||
NumRound <= NUM_ROUND,
|
NumRound <= NUM_ROUND,
|
||||||
|
|
|
||||||
|
|
@ -1571,6 +1571,7 @@ fn low_level_no_rc(lowlevel: &LowLevel) -> RC {
|
||||||
| NumNeg
|
| NumNeg
|
||||||
| NumSin
|
| NumSin
|
||||||
| NumCos
|
| NumCos
|
||||||
|
| NumTan
|
||||||
| NumSqrtUnchecked
|
| NumSqrtUnchecked
|
||||||
| NumLogUnchecked
|
| NumLogUnchecked
|
||||||
| NumRound
|
| NumRound
|
||||||
|
|
|
||||||
|
|
@ -1327,6 +1327,7 @@ fn lowlevel_borrow_signature(arena: &Bump, op: LowLevel) -> &[Ownership] {
|
||||||
| NumNeg
|
| NumNeg
|
||||||
| NumSin
|
| NumSin
|
||||||
| NumCos
|
| NumCos
|
||||||
|
| NumTan
|
||||||
| NumSqrtUnchecked
|
| NumSqrtUnchecked
|
||||||
| NumLogUnchecked
|
| NumLogUnchecked
|
||||||
| NumRound
|
| NumRound
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,7 @@ enum FirstOrder {
|
||||||
NumNeg,
|
NumNeg,
|
||||||
NumSin,
|
NumSin,
|
||||||
NumCos,
|
NumCos,
|
||||||
|
NumTan,
|
||||||
NumSqrtUnchecked,
|
NumSqrtUnchecked,
|
||||||
NumLogUnchecked,
|
NumLogUnchecked,
|
||||||
NumRound,
|
NumRound,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue