Skip to content
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

Simplify softfloat interface #289

Closed
wants to merge 2 commits into from
Closed

Conversation

Timmmm
Copy link
Collaborator

@Timmmm Timmmm commented Aug 4, 2023

Currently the softfloat interface relies on two global registers defined in Sail to return values, one of which is a mirror of fflags. Unfortunately this doesn't work if the model is compiled with -static or wrapped in an anonymous namespace (I am doing the latter in a similar way to @arichardson's method here).

This commit changes the design so that there is only a one-way dependency - the softfloat implementation does not depend on the model. This is done by returning the result of the floating point operation as a normal function return value, and then the model retrieves the new flags by simply calling another platform function (extern_float_flags()).

This is a bit cleaner, works with -static and also removes the need for write_fflags() and update_softfloat_fflags().

Tested with run_fp_tests.sh - all 82 tests pass.

Note, I have not updated the OCaml or Lem parts yet because I wanted to get agreement before doing all that work.

@ptomsich ptomsich self-requested a review August 4, 2023 13:46
@ptomsich
Copy link
Collaborator

ptomsich commented Aug 4, 2023

@Timmmm The clang-format pre-commit check is failing. Could you make sure that your PR follows the style (i.e., that you run clang-format)? Thx.

@Timmmm
Copy link
Collaborator Author

Timmmm commented Aug 4, 2023

Ooops, fixed now.

@github-actions
Copy link

github-actions bot commented Aug 4, 2023

Unit Test Results

712 tests  ±0   396 ✔️  - 316   0s ⏱️ ±0s
    6 suites ±0       0 💤 ±    0 
    1 files   ±0   316 +316 

For more details on these failures, see this check.

Results for commit 979d6f2. ± Comparison against base commit 58cac61.

♻️ This comment has been updated with latest results.

@Timmmm
Copy link
Collaborator Author

Timmmm commented Aug 4, 2023

The test failures are due to the OCaml emulator not building and are expected, as noted in the PR message.

@jrtc27
Copy link
Collaborator

jrtc27 commented Aug 4, 2023

I don't understand what's wrong with static linking, and wrapping random external code in an anonymous namespace is a "you pick up the pieces when it breaks" scenario, but using the return value directly is indeed cleaner if it works.

However, you seem to be doing three different things in the one commit, which makes it harder to review. Please separate out the return value change, the flags accrual change (to avoid the callback) and the flags getter change.

Currently the softfloat interface relies on two global registers defined in Sail to return values, one of which is a mirror of `fflags`. Unfortunately this doesn't work if the model is compiled with `-static` or wrapped in an anonymous namespace (I am doing the latter in a similar way to [@arichardson's method here](https://github.com/CTSRD-CHERI/cheri-compressed-cap/blob/89d21384c0183e5c422e23e1e5b37e127ad14e96/test/sail_wrapper_common.c#L50)).

This commit changes the design so that there is only a one-way dependency - the softfloat implementation does not depend on the model. This is done by returning the result of the floating point operation as a normal function return value, and then the model retrieves the new flags by simply calling another platform function (`extern_float_flags()`).

This is a bit cleaner, works with `-static` and also removes the need for `write_fflags()` and `update_softfloat_fflags()`.

Tested with `run_fp_tests.sh` - all 82 tests pass.

This commit only applies the changes to f16add/sub/mul/div to make review easier.
Copy/paste the changes in the previous commit to all softfloat methods.
@Timmmm
Copy link
Collaborator Author

Timmmm commented Aug 5, 2023

I don't understand what's wrong with static linking

Not static linking; static linkage. The Sail -static flag turns mach_bits zfloat_result; into static mach_bits zfloat_result;, so riscv_sail.h's extern mach_bits zfloat_result; no longer works.

and wrapping random external code in an anonymous namespace is a "you pick up the pieces when it breaks" scenario

This is me picking up the pieces! :-)

However, you seem to be doing three different things in the one commit, which makes it harder to review. Please separate out the return value change, the flags accrual change (to avoid the callback) and the flags getter change.

Fair point. It's actually a very small change but there are so many softfloat methods it's difficult to review like this. I've split it into two commits - the first has all the actual changes and updates the f16add/sub/div/mul methods. The second is just copy & pasting to all the other methods.

@jrtc27
Copy link
Collaborator

jrtc27 commented Aug 5, 2023

However, you seem to be doing three different things in the one commit, which makes it harder to review. Please separate out the return value change, the flags accrual change (to avoid the callback) and the flags getter change.

Fair point. It's actually a very small change but there are so many softfloat methods it's difficult to review like this. I've split it into two commits - the first has all the actual changes and updates the f16add/sub/div/mul methods. The second is just copy & pasting to all the other methods.

I appreciate the reasoning behind it, but having intermediate commits in the history that don't work is a no-no.

@Timmmm
Copy link
Collaborator Author

Timmmm commented Aug 5, 2023

Ok I can squash it before merging. The three changes you mentioned are tightly linked and the changes to the code are quite minimal and easy to review. I would rather not spend a lot of time making intermediate commits that only fix 1/3 of the issue!

@Timmmm
Copy link
Collaborator Author

Timmmm commented Aug 5, 2023

Actually the removal of write_fflags can probably be separated out fairly easily and it shouldn't require changes to OCaml. I'll make a separate PR for that.

@Timmmm
Copy link
Collaborator Author

Timmmm commented Aug 5, 2023

Ok the first part is #290

@Timmmm
Copy link
Collaborator Author

Timmmm commented Nov 7, 2023

Part 2 here: #340

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants