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:
Brendan Hansknecht 2023-09-16 21:27:51 -07:00
parent 7986d6cdba
commit 108d9a54e3
No known key found for this signature in database
GPG key ID: 0EA784685083E75B
11 changed files with 25 additions and 4 deletions

View file

@ -163,6 +163,7 @@ comptime {
num.exportSin(T, ROC_BUILTINS ++ "." ++ NUM ++ ".sin.");
num.exportCos(T, ROC_BUILTINS ++ "." ++ NUM ++ ".cos.");
num.exportTan(T, ROC_BUILTINS ++ "." ++ NUM ++ ".tan.");
num.exportPow(T, ROC_BUILTINS ++ "." ++ NUM ++ ".pow.");
num.exportLog(T, ROC_BUILTINS ++ "." ++ NUM ++ ".log.");

View file

@ -168,6 +168,15 @@ pub fn exportCos(comptime T: type, comptime name: []const u8) void {
@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 {
comptime var f = struct {
fn func(input: T) callconv(.C) T {

View file

@ -825,11 +825,7 @@ max = \a, b ->
sin : Frac a -> Frac a
cos : 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
acos : Frac a -> Frac a

View file

@ -272,6 +272,7 @@ macro_rules! int_intrinsic {
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_TAN: IntrinsicName = float_intrinsic!("roc_builtins.num.tan");
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_ATAN: IntrinsicName = float_intrinsic!("roc_builtins.num.atan");