| author | |
| committer | |
| log | 24cd99160c2eeea34088ef3e3d631233d8913dc1 |
| tree | 0f646f8f6ec7b83b0d36b4e94f311419c724f415 |
| parent | 3c094116aae459b651934663a31981cf09cdb3e4 |
3 files changed, 30 insertions(+), 4 deletions(-)
CMakeLists.txt+1| ... | ... | @@ -425,6 +425,7 @@ set(ZIG_STD_FILES |
| 425 | 425 | "math/tan.zig" |
| 426 | 426 | "math/tanh.zig" |
| 427 | 427 | "math/trunc.zig" |
| 428 | "math/x86_64/sqrt.zig" | |
| 428 | 429 | "mem.zig" |
| 429 | 430 | "net.zig" |
| 430 | 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 | 18 | return T(sqrt64(x)); |
| 19 | 19 | }, |
| 20 | 20 | TypeId.Float => { |
| 21 | return switch (T) { | |
| 22 | f32 => sqrt32(x), | |
| 23 | f64 => sqrt64(x), | |
| 21 | switch (T) { | |
| 22 | f32 => { | |
| 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 | 34 | else => @compileError("sqrt not implemented for " ++ @typeName(T)), |
| 25 | }; | |
| 35 | } | |
| 26 | 36 | }, |
| 27 | 37 | TypeId.IntLiteral => comptime { |
| 28 | 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 | } |