Repository navigation
Pin softfloat 3.0.0#3: thread-local rounding and exception state #701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /** | ||
| * Berkeley SoftFloat keeps the rounding mode and exception flags in per-thread state (softfloat 3.0.0#3): a | ||
| * worker thread starts from the defaults and leaks nothing back to the thread that spawned it. With the | ||
| * process-global state of 3.0.0#2 every check below fails. | ||
| */ | ||
| extern "C" { | ||
| #include <softfloat/softfloat.h> | ||
| } | ||
| #include <softfloat/softfloat.hpp> | ||
|
|
||
| #include <boost/test/unit_test.hpp> | ||
|
|
||
| #include <cstdint> | ||
| #include <thread> | ||
|
|
||
| namespace { | ||
|
|
||
| const softfloat32_t one = {0x3f800000u}; | ||
| const softfloat32_t zero = {0u}; | ||
| const softfloat32_t minus_one = {0xbf800000u}; | ||
|
|
||
| /// Other suites may leave the calling thread's state behind; start from the defaults and put them back. | ||
| struct softfloat_state_guard { | ||
| softfloat_state_guard() { reset(); } | ||
| ~softfloat_state_guard() { reset(); } | ||
| static void reset() { | ||
| softfloat_roundingMode = softfloat_round_near_even; | ||
| softfloat_exceptionFlags = 0; | ||
| } | ||
| }; | ||
|
|
||
| } // namespace | ||
|
|
||
| BOOST_AUTO_TEST_SUITE(softfloat_thread_local_tests) | ||
|
|
||
| BOOST_AUTO_TEST_CASE(rounding_mode_and_exception_flags_are_per_thread) { | ||
| softfloat_state_guard guard; | ||
|
|
||
| softfloat_roundingMode = softfloat_round_max; | ||
| f32_div(one, zero); | ||
| BOOST_CHECK_EQUAL(unsigned(softfloat_exceptionFlags), unsigned(softfloat_flag_infinite)); | ||
|
|
||
| unsigned worker_mode = ~0u; | ||
| unsigned worker_flags_before = ~0u; | ||
| unsigned worker_flags_after = 0; | ||
| std::thread worker([&] { | ||
| worker_mode = softfloat_roundingMode; | ||
| worker_flags_before = softfloat_exceptionFlags; | ||
| softfloat_roundingMode = softfloat_round_minMag; | ||
| f32_sqrt(minus_one); | ||
| worker_flags_after = softfloat_exceptionFlags; | ||
| }); | ||
| worker.join(); | ||
|
|
||
| BOOST_CHECK_EQUAL(worker_mode, unsigned(softfloat_round_near_even)); | ||
| BOOST_CHECK_EQUAL(worker_flags_before, 0u); | ||
| BOOST_CHECK_EQUAL(worker_flags_after, unsigned(softfloat_flag_invalid)); | ||
| BOOST_CHECK_EQUAL(unsigned(softfloat_roundingMode), unsigned(softfloat_round_max)); | ||
| BOOST_CHECK_EQUAL(unsigned(softfloat_exceptionFlags), unsigned(softfloat_flag_infinite)); | ||
| } | ||
|
|
||
| BOOST_AUTO_TEST_SUITE_END() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -147,7 +147,7 @@ | |
| }, | ||
| { | ||
| "name": "softfloat", | ||
| "version": "3.0.0#2" | ||
| "version": "3.0.0#3" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Medium (test coverage): This version bump changes the four SoftFloat state variables from process-global to thread-local, but the current wire-sysio golden tests are serial and never assert rounding or exception-state isolation. The dependency contains a deterministic TLS test, but the registry port configures it with
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
| }, | ||
| { | ||
| "name": "wire-sys-vm", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Medium: This definition is directory-scoped, so it does not reach consumers of the generated
SysioChain/SysioTesterinterface.SysioTester.cmake.inlinkslibsoftfloatas a raw archive and exports the SoftFloat include paths without this compile definition. On the documented Apple-Silicon wire-cdt integration path,tester.hppincludessoftfloat_types.hbefore Boost.Unordered pulls inarm_neon.h, reproducing typedef redefinitions forfloat16_t,float32_t, andfloat64_t. I reproduced the failure with a Clang 18 AArch64 syntax probe; it passes when this macro is defined. Please export the definition on the generatedSysioChaininterface, while retaining the in-tree definition as needed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exported in 4af9ddb:
SysioChainnow carriesSOFTFLOAT_DISABLE_LEGACY_TYPE_ALIASESand, since it links the archive directly rather than the port's package, alsoTHREAD_LOCAL=__thread, the storage class the archive was built with. Checked with a build-treefind_package(sysio)consumer: both land inINTERFACE_COMPILE_DEFINITIONS. The tree-wide definition stays.