| author | |
| committer | |
| log | 811bada06d4d88d786119bab752c0e0cff345154 |
| tree | 0a494fbfc628cd5936032028f9ed70fad111a648 |
| parent | e15d8dd3d27047043a371421e59bc11c83a7a1b5 |
| signature |
The changes were tested by running:
```
$ ./build/stage3/bin/zig build -p stage4 -Denable-llvm -Dno-lib
$ stage4/bin/zig build test-libc -Dlibc-test-path=<LIBC-TEST-PATH> -Dtest-filter=lrint -fqemu -fwasmtime --summary line
Build Summary: 737/737 steps succeeded
```9 files changed, 5 insertions(+), 126 deletions(-)
lib/c/math.zig+5| ... | ... | @@ -66,6 +66,7 @@ comptime { |
| 66 | 66 | symbol(&finitef, "finitef"); |
| 67 | 67 | symbol(&frexp, "frexp"); |
| 68 | 68 | symbol(&hypot, "hypot"); |
| 69 | symbol(&lrint, "lrint"); | |
| 69 | 70 | symbol(&modf, "modf"); |
| 70 | 71 | symbol(&pow, "pow"); |
| 71 | 72 | symbol(&pow10, "pow10"); |
| ... | ... | @@ -229,6 +230,10 @@ fn isnanl(x: c_longdouble) callconv(.c) c_int { |
| 229 | 230 | return if (math.isNan(x)) 1 else 0; |
| 230 | 231 | } |
| 231 | 232 | |
| 233 | fn lrint(x: f64) callconv(.c) c_long { | |
| 234 | return @intFromFloat(rint(x)); | |
| 235 | } | |
| 236 | ||
| 232 | 237 | fn modfGeneric(comptime T: type, x: T, iptr: *T) T { |
| 233 | 238 | if (math.isNegativeInf(x)) { |
| 234 | 239 | iptr.* = -math.inf(T); |
lib/libc/musl/src/math/aarch64/lrint.c deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | #include <math.h> | |
| 2 | ||
| 3 | long lrint(double x) | |
| 4 | { | |
| 5 | 	long n; | |
| 6 | 	__asm__ ( | |
| 7 | 		"frintx %d1, %d1\n" | |
| 8 | 		"fcvtzs %x0, %d1\n" : "=r"(n), "+w"(x)); | |
| 9 | 	return n; | |
| 10 | } |
lib/libc/musl/src/math/i386/lrint.c deleted-8| ... | ... | @@ -1,8 +0,0 @@ |
| 1 | #include <math.h> | |
| 2 | ||
| 3 | long lrint(double x) | |
| 4 | { | |
| 5 | 	long r; | |
| 6 | 	__asm__ ("fistpl %0" : "=m"(r) : "t"(x) : "st"); | |
| 7 | 	return r; | |
| 8 | } |
lib/libc/musl/src/math/lrint.c deleted-72| ... | ... | @@ -1,72 +0,0 @@ |
| 1 | #include <limits.h> | |
| 2 | #include <fenv.h> | |
| 3 | #include <math.h> | |
| 4 | #include "libm.h" | |
| 5 | ||
| 6 | /* | |
| 7 | If the result cannot be represented (overflow, nan), then | |
| 8 | lrint raises the invalid exception. | |
| 9 | ||
| 10 | Otherwise if the input was not an integer then the inexact | |
| 11 | exception is raised. | |
| 12 | ||
| 13 | C99 is a bit vague about whether inexact exception is | |
| 14 | allowed to be raised when invalid is raised. | |
| 15 | (F.9 explicitly allows spurious inexact exceptions, F.9.6.5 | |
| 16 | does not make it clear if that rule applies to lrint, but | |
| 17 | IEEE 754r 7.8 seems to forbid spurious inexact exception in | |
| 18 | the ineger conversion functions) | |
| 19 | ||
| 20 | So we try to make sure that no spurious inexact exception is | |
| 21 | raised in case of an overflow. | |
| 22 | ||
| 23 | If the bit size of long > precision of double, then there | |
| 24 | cannot be inexact rounding in case the result overflows, | |
| 25 | otherwise LONG_MAX and LONG_MIN can be represented exactly | |
| 26 | as a double. | |
| 27 | */ | |
| 28 | ||
| 29 | #if LONG_MAX < 1U<<53 && defined(FE_INEXACT) | |
| 30 | #include <float.h> | |
| 31 | #include <stdint.h> | |
| 32 | #if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1 | |
| 33 | #define EPS DBL_EPSILON | |
| 34 | #elif FLT_EVAL_METHOD==2 | |
| 35 | #define EPS LDBL_EPSILON | |
| 36 | #endif | |
| 37 | #ifdef __GNUC__ | |
| 38 | /* avoid stack frame in lrint */ | |
| 39 | __attribute__((noinline)) | |
| 40 | #endif | |
| 41 | static long lrint_slow(double x) | |
| 42 | { | |
| 43 | 	#pragma STDC FENV_ACCESS ON | |
| 44 | 	int e; | |
| 45 | ||
| 46 | 	e = fetestexcept(FE_INEXACT); | |
| 47 | 	x = rint(x); | |
| 48 | 	if (!e && (x > LONG_MAX || x < LONG_MIN)) | |
| 49 | 		feclearexcept(FE_INEXACT); | |
| 50 | 	/* conversion */ | |
| 51 | 	return x; | |
| 52 | } | |
| 53 | ||
| 54 | long lrint(double x) | |
| 55 | { | |
| 56 | 	uint32_t abstop = asuint64(x)>>32 & 0x7fffffff; | |
| 57 | 	uint64_t sign = asuint64(x) & (1ULL << 63); | |
| 58 | ||
| 59 | 	if (abstop < 0x41dfffff) { | |
| 60 | 		/* |x| < 0x7ffffc00, no overflow */ | |
| 61 | 		double_t toint = asdouble(asuint64(1/EPS) | sign); | |
| 62 | 		double_t y = x + toint - toint; | |
| 63 | 		return (long)y; | |
| 64 | 	} | |
| 65 | 	return lrint_slow(x); | |
| 66 | } | |
| 67 | #else | |
| 68 | long lrint(double x) | |
| 69 | { | |
| 70 | 	return rint(x); | |
| 71 | } | |
| 72 | #endif |
lib/libc/musl/src/math/powerpc64/lrint.c deleted-16| ... | ... | @@ -1,16 +0,0 @@ |
| 1 | #include <math.h> | |
| 2 | ||
| 3 | #ifdef _ARCH_PWR5X | |
| 4 | ||
| 5 | long lrint(double x) | |
| 6 | { | |
| 7 | 	long n; | |
| 8 | 	__asm__ ("fctid %0, %1" : "=d"(n) : "d"(x)); | |
| 9 | 	return n; | |
| 10 | } | |
| 11 | ||
| 12 | #else | |
| 13 | ||
| 14 | #include "../lrint.c" | |
| 15 | ||
| 16 | #endif |
lib/libc/musl/src/math/x32/lrint.s deleted-5| ... | ... | @@ -1,5 +0,0 @@ |
| 1 | .global lrint | |
| 2 | .type lrint,@function | |
| 3 | lrint: | |
| 4 | 	cvtsd2si %xmm0,%rax | |
| 5 | 	ret |
lib/libc/musl/src/math/x86_64/lrint.c deleted-8| ... | ... | @@ -1,8 +0,0 @@ |
| 1 | #include <math.h> | |
| 2 | ||
| 3 | long lrint(double x) | |
| 4 | { | |
| 5 | 	long r; | |
| 6 | 	__asm__ ("cvtsd2si %1, %0" : "=r"(r) : "x"(x)); | |
| 7 | 	return r; | |
| 8 | } |
src/libs/musl.zig-6| ... | ... | @@ -787,7 +787,6 @@ const src_files = [_][]const u8{ |
| 787 | 787 | "musl/src/math/aarch64/llrintf.c", |
| 788 | 788 | "musl/src/math/aarch64/llround.c", |
| 789 | 789 | "musl/src/math/aarch64/llroundf.c", |
| 790 | "musl/src/math/aarch64/lrint.c", | |
| 791 | 790 | "musl/src/math/aarch64/lrintf.c", |
| 792 | 791 | "musl/src/math/aarch64/lround.c", |
| 793 | 792 | "musl/src/math/aarch64/lroundf.c", |
| ... | ... | @@ -860,7 +859,6 @@ const src_files = [_][]const u8{ |
| 860 | 859 | "musl/src/math/i386/log1p.s", |
| 861 | 860 | "musl/src/math/i386/log2l.s", |
| 862 | 861 | "musl/src/math/i386/logl.s", |
| 863 | "musl/src/math/i386/lrint.c", | |
| 864 | 862 | "musl/src/math/i386/lrintf.c", |
| 865 | 863 | "musl/src/math/i386/lrintl.c", |
| 866 | 864 | "musl/src/math/i386/remainder.c", |
| ... | ... | @@ -910,7 +908,6 @@ const src_files = [_][]const u8{ |
| 910 | 908 | "musl/src/math/logbf.c", |
| 911 | 909 | "musl/src/math/logbl.c", |
| 912 | 910 | "musl/src/math/logl.c", |
| 913 | "musl/src/math/lrint.c", | |
| 914 | 911 | "musl/src/math/lrintf.c", |
| 915 | 912 | "musl/src/math/lrintl.c", |
| 916 | 913 | "musl/src/math/lround.c", |
| ... | ... | @@ -940,7 +937,6 @@ const src_files = [_][]const u8{ |
| 940 | 937 | "musl/src/math/pow_data.c", |
| 941 | 938 | "musl/src/math/powerpc64/fma.c", |
| 942 | 939 | "musl/src/math/powerpc64/fmaf.c", |
| 943 | "musl/src/math/powerpc64/lrint.c", | |
| 944 | 940 | "musl/src/math/powerpc64/lrintf.c", |
| 945 | 941 | "musl/src/math/powerpc64/lround.c", |
| 946 | 942 | "musl/src/math/powerpc64/lroundf.c", |
| ... | ... | @@ -1017,7 +1013,6 @@ const src_files = [_][]const u8{ |
| 1017 | 1013 | "musl/src/math/x32/logl.s", |
| 1018 | 1014 | "musl/src/math/x32/lrintf.s", |
| 1019 | 1015 | "musl/src/math/x32/lrintl.s", |
| 1020 | "musl/src/math/x32/lrint.s", | |
| 1021 | 1016 | "musl/src/math/x32/remainderl.s", |
| 1022 | 1017 | "musl/src/math/x32/rintl.s", |
| 1023 | 1018 | "musl/src/math/x86_64/acosl.s", |
| ... | ... | @@ -1036,7 +1031,6 @@ const src_files = [_][]const u8{ |
| 1036 | 1031 | "musl/src/math/x86_64/log1pl.s", |
| 1037 | 1032 | "musl/src/math/x86_64/log2l.s", |
| 1038 | 1033 | "musl/src/math/x86_64/logl.s", |
| 1039 | "musl/src/math/x86_64/lrint.c", | |
| 1040 | 1034 | "musl/src/math/x86_64/lrintf.c", |
| 1041 | 1035 | "musl/src/math/x86_64/lrintl.c", |
| 1042 | 1036 | "musl/src/math/x86_64/remainderl.c", |
src/libs/wasi_libc.zig-1| ... | ... | @@ -732,7 +732,6 @@ const libc_top_half_src_files = [_][]const u8{ |
| 732 | 732 | "musl/src/math/logbf.c", |
| 733 | 733 | "musl/src/math/logbl.c", |
| 734 | 734 | "musl/src/math/logl.c", |
| 735 | "musl/src/math/lrint.c", | |
| 736 | 735 | "musl/src/math/lrintf.c", |
| 737 | 736 | "musl/src/math/lrintl.c", |
| 738 | 737 | "musl/src/math/lround.c", |