| author | |
| committer | |
| log | 891c93c118a85ce16225ed2e97676cdae2abe657 |
| tree | 8fb47079465fbcd5d58f7d477678987ade56c032 |
| parent | d4f791cf6c560da25a0b84b4eb2ad68f8e7d27fd |
| parent | 24cd99160c2eeea34088ef3e3d631233d8913dc1 |
| signature |
Add hw sqrt for x86_643 files changed, 30 insertions(+), 4 deletions(-)
CMakeLists.txt+1| ... | @@ -425,6 +425,7 @@ set(ZIG_STD_FILES | ... | @@ -425,6 +425,7 @@ set(ZIG_STD_FILES |
| 425 | "math/tan.zig" | 425 | "math/tan.zig" |
| 426 | "math/tanh.zig" | 426 | "math/tanh.zig" |
| 427 | "math/trunc.zig" | 427 | "math/trunc.zig" |
| 428 | "math/x86_64/sqrt.zig" | ||
| 428 | "mem.zig" | 429 | "mem.zig" |
| 429 | "net.zig" | 430 | "net.zig" |
| 430 | "os/child_process.zig" | 431 | "os/child_process.zig" |
std/math/sqrt.zig+14-4| ... | @@ -18,11 +18,21 @@ pub fn sqrt(x: var) -> (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @ | ... | @@ -18,11 +18,21 @@ pub fn sqrt(x: var) -> (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @ |
| 18 | return T(sqrt64(x)); | 18 | return T(sqrt64(x)); |
| 19 | }, | 19 | }, |
| 20 | TypeId.Float => { | 20 | TypeId.Float => { |
| 21 | return switch (T) { | 21 | switch (T) { |
| 22 | f32 => sqrt32(x), | 22 | f32 => { |
| 23 | f64 => sqrt64(x), | 23 | switch (builtin.arch) { |
| 24 | builtin.Arch.x86_64 => return @import("x86_64/sqrt.zig").sqrt32(x), | ||
| 25 | else => return sqrt32(x), | ||
| 26 | } | ||
| 27 | }, | ||
| 28 | f64 => { | ||
| 29 | switch (builtin.arch) { | ||
| 30 | builtin.Arch.x86_64 => return @import("x86_64/sqrt.zig").sqrt64(x), | ||
| 31 | else => return sqrt64(x), | ||
| 32 | } | ||
| 33 | }, | ||
| 24 | else => @compileError("sqrt not implemented for " ++ @typeName(T)), | 34 | else => @compileError("sqrt not implemented for " ++ @typeName(T)), |
| 25 | }; | 35 | } |
| 26 | }, | 36 | }, |
| 27 | TypeId.IntLiteral => comptime { | 37 | TypeId.IntLiteral => comptime { |
| 28 | if (x > @maxValue(u128)) { | 38 | if (x > @maxValue(u128)) { |
std/math/x86_64/sqrt.zig created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | pub fn sqrt32(x: f32) -> f32 { | ||
| 2 | return asm ( | ||
| 3 | \\sqrtss %%xmm0, %%xmm0 | ||
| 4 | : [ret] "={xmm0}" (-> f32) | ||
| 5 | : [x] "{xmm0}" (x) | ||
| 6 | ); | ||
| 7 | } | ||
| 8 | |||
| 9 | pub fn sqrt64(x: f64) -> f64 { | ||
| 10 | return asm ( | ||
| 11 | \\sqrtsd %%xmm0, %%xmm0 | ||
| 12 | : [ret] "={xmm0}" (-> f64) | ||
| 13 | : [x] "{xmm0}" (x) | ||
| 14 | ); | ||
| 15 | } | ||