authorgravatar for hi@mihaelm.commihael <hi@mihaelm.com> 2026-03-20 22:16:01+01:00
committergravatar for hi@mihaelm.commihael <hi@mihaelm.com> 2026-04-02 23:54:20+02:00
log19334f95c1797af2ead725baf3a67070d90c8586
treebdfb9791b5ce90f702025db2f8593de8f78eae01
parentbd1dc8948f6093a13f1ac887b71fb71466b24f9e
signaturebadge-check Signed by SSH key SHA256:aoFoShdYLdrqMichqKXSSieTKUfACUIDJHsKc4V2tQg

`libzigc/math`: Implement `lrintf`

This was checked 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=lrintf -fqemu -fwasmtime --summary line Build Summary: 369/369 steps succeeded ```

9 files changed, 5 insertions(+), 62 deletions(-)

lib/c/math.zig+5
......@@ -72,6 +72,7 @@ comptime {
7272 symbol(&frexp, "frexp");
7373 symbol(&hypot, "hypot");
7474 symbol(&lrint, "lrint");
75 symbol(&lrintf, "lrintf");
7576 symbol(&modf, "modf");
7677 symbol(&pow, "pow");
7778 symbol(&pow10, "pow10");
......@@ -238,6 +239,10 @@ fn lrint(x: f64) callconv(.c) c_long {
238239 return @intFromFloat(rint(x));
239240}
240241
242fn lrintf(x: f32) callconv(.c) c_long {
243 return @intFromFloat(rintf(x));
244}
245
241246fn modfGeneric(comptime T: type, x: T, iptr: *T) T {
242247 if (math.isNegativeInf(x)) {
243248 iptr.* = -math.inf(T);
lib/libc/musl/src/math/aarch64/lrintf.c deleted-10
......@@ -1,10 +0,0 @@
1#include <math.h>
2
3long lrintf(float x)
4{
5 long n;
6 __asm__ (
7 "frintx %s1, %s1\n"
8 "fcvtzs %x0, %s1\n" : "=r"(n), "+w"(x));
9 return n;
10}
lib/libc/musl/src/math/i386/lrintf.c deleted-8
......@@ -1,8 +0,0 @@
1#include <math.h>
2
3long lrintf(float x)
4{
5 long r;
6 __asm__ ("fistpl %0" : "=m"(r) : "t"(x) : "st");
7 return r;
8}
lib/libc/musl/src/math/lrintf.c deleted-8
......@@ -1,8 +0,0 @@
1#include <math.h>
2
3/* uses LONG_MAX > 2^24, see comments in lrint.c */
4
5long lrintf(float x)
6{
7 return rintf(x);
8}
lib/libc/musl/src/math/powerpc64/lrintf.c deleted-16
......@@ -1,16 +0,0 @@
1#include <math.h>
2
3#ifdef _ARCH_PWR5X
4
5long lrintf(float x)
6{
7 long n;
8 __asm__ ("fctid %0, %1" : "=d"(n) : "f"(x));
9 return n;
10}
11
12#else
13
14#include "../lrintf.c"
15
16#endif
lib/libc/musl/src/math/x32/lrintf.s deleted-5
......@@ -1,5 +0,0 @@
1.global lrintf
2.type lrintf,@function
3lrintf:
4 cvtss2si %xmm0,%rax
5 ret
lib/libc/musl/src/math/x86_64/lrintf.c deleted-8
......@@ -1,8 +0,0 @@
1#include <math.h>
2
3long lrintf(float x)
4{
5 long r;
6 __asm__ ("cvtss2si %1, %0" : "=r"(r) : "x"(x));
7 return r;
8}
src/libs/musl.zig-6
......@@ -787,7 +787,6 @@ const src_files = [_][]const u8{
787787 "musl/src/math/aarch64/llrintf.c",
788788 "musl/src/math/aarch64/llround.c",
789789 "musl/src/math/aarch64/llroundf.c",
790 "musl/src/math/aarch64/lrintf.c",
791790 "musl/src/math/aarch64/lround.c",
792791 "musl/src/math/aarch64/lroundf.c",
793792 "musl/src/math/aarch64/nearbyint.c",
......@@ -858,7 +857,6 @@ const src_files = [_][]const u8{
858857 "musl/src/math/i386/log1p.s",
859858 "musl/src/math/i386/log2l.s",
860859 "musl/src/math/i386/logl.s",
861 "musl/src/math/i386/lrintf.c",
862860 "musl/src/math/i386/lrintl.c",
863861 "musl/src/math/i386/remainder.c",
864862 "musl/src/math/i386/remainderf.c",
......@@ -906,7 +904,6 @@ const src_files = [_][]const u8{
906904 "musl/src/math/logbf.c",
907905 "musl/src/math/logbl.c",
908906 "musl/src/math/logl.c",
909 "musl/src/math/lrintf.c",
910907 "musl/src/math/lrintl.c",
911908 "musl/src/math/lround.c",
912909 "musl/src/math/lroundf.c",
......@@ -935,7 +932,6 @@ const src_files = [_][]const u8{
935932 "musl/src/math/pow_data.c",
936933 "musl/src/math/powerpc64/fma.c",
937934 "musl/src/math/powerpc64/fmaf.c",
938 "musl/src/math/powerpc64/lrintf.c",
939935 "musl/src/math/powerpc64/lround.c",
940936 "musl/src/math/powerpc64/lroundf.c",
941937 "musl/src/math/powerpc/fma.c",
......@@ -1007,7 +1003,6 @@ const src_files = [_][]const u8{
10071003 "musl/src/math/x32/log1pl.s",
10081004 "musl/src/math/x32/log2l.s",
10091005 "musl/src/math/x32/logl.s",
1010 "musl/src/math/x32/lrintf.s",
10111006 "musl/src/math/x32/lrintl.s",
10121007 "musl/src/math/x32/remainderl.s",
10131008 "musl/src/math/x32/rintl.s",
......@@ -1027,7 +1022,6 @@ const src_files = [_][]const u8{
10271022 "musl/src/math/x86_64/log1pl.s",
10281023 "musl/src/math/x86_64/log2l.s",
10291024 "musl/src/math/x86_64/logl.s",
1030 "musl/src/math/x86_64/lrintf.c",
10311025 "musl/src/math/x86_64/lrintl.c",
10321026 "musl/src/math/x86_64/remainderl.c",
10331027 "musl/src/math/x86_64/remquol.c",
src/libs/wasi_libc.zig-1
......@@ -732,7 +732,6 @@ const libc_top_half_src_files = [_][]const u8{
732732 "musl/src/math/logbf.c",
733733 "musl/src/math/logbl.c",
734734 "musl/src/math/logl.c",
735 "musl/src/math/lrintf.c",
736735 "musl/src/math/lrintl.c",
737736 "musl/src/math/lround.c",
738737 "musl/src/math/lroundf.c",