Repository navigation
Conversation
adriadam10
left a comment
There was a problem hiding this comment.
Thanks. Build and guest_math pass here, and the new check fails without the change. Points before this can merge:
conventionsis red: the checklist item "Unimplemented paths throw (NotImplemented_nid_no_patch)…" is unchecked. Tick it (nothing here is unimplemented).- Scope: FreeBSD msun never sets errno, so the same reasoning applies to
acosh,asinh,atanhand the otherstd::wrappers inMath.cpp, which still set errno on the host for domain/range errors. Either cover the family in one place (one PR, with a test row per function) or say why onlyacoshfdiffers. GuestMath.cpp:499:CheckAcoshfErrno()is called between theabs_nid_postfixchecks inmain; move it next to the otherCheck*calls.
One question on scope: |
b0898ff to
3fb3e2e
Compare
adriadam10
left a comment
There was a problem hiding this comment.
main moved and Math.cpp conflicted with __powisf2 (adjacent lines). Rebased onto current main, keeping both sides; no logic change. Build and guest_math pass after the rebase, and it fails with Math.cpp reverted. Merging.
Note: #3599, #3600, #3688, #3693 and #3602 edit lines next to these ones in Math.cpp, so they will need a rebase after this lands.
3fb3e2e to
7956caa
Compare
7956caa to
26d14e8
Compare
|
|
acoshf returned 0xffc00000 (errno 33) for -1.0 (0xbf800000), where FreeBSD lib/msun/src/math.h returns 0xffc00000 (errno 0). It now returns the FreeBSD result for that case. A guest test covers it and fails on main. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
The libm exports forwarded straight to the host, so a domain or range error set the host errno (33 or 34) where FreeBSD lib/msun/src/math.h (math_errhandling is MATH_ERREXCEPT) leaves the caller's errno alone. PreserveErrno runs the host call between an errno read and an errno write. The empty asm statements on the arguments and the result keep the compiler from dropping or reordering them: GCC treats sin, cos and tan as never setting errno and removed a plain save and restore. It wraps the 39 libm exports whose results already match msun on the error inputs. Results are unchanged. One guest test row per function pins the result bits and the caller's errno for an error input and an in-range input. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
26d14e8 to
7496683
Compare
|
Rebased onto Tested locally, Release, gcc, the same configure options as the Linux job:
I could not reproduce the abort from run 38220387093 on the newer |
|
Three things before the next build:
|
|
Closing this. To answer the last question: none of the 39 functions were checked against the console's own libc, only against FreeBSD msun source, and #3725 shows that is not enough for at least |
What
A guest that calls a libm function on a domain or range error and then reads
errnosees a host errno that FreeBSDnever sets:
The libm exports in
Math.cppforward to the hoststd::functions, and glibc sets errno for those errors. FreeBSDmsunnever does:math_errhandlingisMATH_ERREXCEPT(https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/msun/src/math.h#L67-L69).PreserveErrnoreads errno, runs the host call and writes errno back. Results and floating point exception flags donot change. It wraps 39 exports, each one a one-line change:
sin cos tan sinh cosh asinh acosh atanh exp expm1 log log2 log10 log1p sqrt pow atan2 hypot ldexp scalbn sincossinf cosf tanf coshf expf exp2f logf log2f log10f log1pf sqrtf acoshf atan2f fmodf scalbnf ldexpf remainderf sincosfThe two empty
asmstatements in the helper keep the read, the call and the write in order. Without them GCC treatssin,cosandtanas functions that never touch errno and removes a plain save and restore.Not in this PR:
exp2(fix(libc): exp2 leaves errno unchanged #3599),fmod(fix(libc): fmod leaves errno unchanged #3600),acosf(fix(libc): keep the acosf result and leave errno unchanged #3688),asinf(fix(libc): match FreeBSD asinf errno #3693): the same errno fix, already open.powf: fix(libc): powf(1, y) returns 1 for any y #3602 changes the same line.asin,acos, andlog10with a negative input: the result is also a different NaN sign than msun, which is avalue difference, not an errno one.
log10is wrapped and tested on the pole caselog10(0.0)only.nextafterf: left alone; its difference from msun is in the result for a signalling NaN, not in errno._FSinh,_FCosh, the long double functions: no msun counterpart, or covered by feat(libc): implement the remaining long double math functions RetroArch imports #3598.tanh,tanhf,atan,atanf,cbrt,cbrtf,asinhf,hypotf,logbf,modf,modff,fma,round,roundf,trunc: the host did not set errno for any input tried, so they stay as they are.Tested
Linux (CachyOS), GCC 16 and clang 23.1.1; RTX 4070 Ti (NVIDIA), Radeon 610M (RADV) and lavapipe (Mesa 26.2.4).
guest_mathhas one row per wrapped function: an error input and an in-range input, each pinning the result bitsand that the caller's errno (set to
EINTRbefore the call) is unchanged.sincosandsincosfcheck bothoutputs.
guest_mathpasses on NVIDIA, RADV and lavapipe;tools/check_conventions.py --base origin/mainandgit diff --checkare clean.main'sMath.cppthe same test aborts at the first row (errno 33).mainon 239,332 inputs over 65 ops (special values, random bit patterns, int exponents), built withGCC and with clang: result bits, exception flags and out-arguments are identical (0 differences), errno stays 0 for
every wrapped op. OpenLibm 0.8.8 (msun-derived), built offline, leaves errno at 0 on all of them and returns the
same bits as
mainon every error input the tests use.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repositoryAI-assisted: yes