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

Enable Floating Point Exceptions #1619

Merged
merged 7 commits into from
Aug 22, 2024
Merged

Enable Floating Point Exceptions #1619

merged 7 commits into from
Aug 22, 2024

Conversation

yitzchak
Copy link
Member

No description provided.

@yitzchak yitzchak force-pushed the fpe branch 3 times, most recently from cdbed81 to 600e795 Compare August 21, 2024 17:28
@yitzchak yitzchak marked this pull request as ready for review August 21, 2024 20:37
repos.sexp Show resolved Hide resolved
@@ -515,7 +515,8 @@ void HashTable_O::sxhash_eql(HashGenerator& hg, T_sp obj) {
return;
}
case gctools::single_float_tag: {
hg.addValue0(std::abs(::floor(obj.unsafe_single_float())));
float value = obj.unsafe_single_float();
hg.addValue0((std::fpclassify(value) == FP_ZERO) ? 0u : float_convert<float>::to_bits(value));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does float_convert not work on zeroes somehow? If it doesn't, this should probably be mentioned in a comment in float_convert.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No the issue is that standard requires that -0.0 and 0.0 behave the same in hashes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, that makes sense for the others, but for an eql hash they should be distinct, right? Since they're not eql? Unless there's a hash table specific rule I'm missing here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to the tests in sxhash.lsp it is tested by gethash in all varieties.

https://gitlab.common-lisp.net/ansi-test/ansi-test/-/blob/master/hash-tables/gethash.lsp?ref_type=heads#L84-148

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I'm wrong. The only gethash test that requires that is equalp. Apologies, I'll fix it.

// printf("Enter handle_fpe Signo: %d Errno:%d Code:%d\n", (info->si_signo), (info->si_errno), (info->si_code));
// init_float_traps(); // WHY
if (_lisp) {
feenableexcept(_lisp->getTrapFpeBits());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handle_fpe is a signal handler and should be as reentrant as possible. It would be possible for an interrupt to occur between enable and disable here - true elsewhere as well of course. Is there any way we can do this atomically? I imagine not, but it would be nice.

Also, why is this code restoring the floating point traps necessary? Does receiving an FPE warp the traps somehow? An explanation in a comment would be appreciated. Also an explanation for why the if (_lisp) check - because this can happen extremely early, maybe?

Copy link
Member Author

@yitzchak yitzchak Aug 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The interrupts should get queued. On amd64 the traps are all reset on SIGFPE so you have to restore them. This is not true on Aarch64.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The if (_lisp) check is just there because I am paranoid.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, could you mention the reset in a comment? Also, do you have a doc reference for this or is it just what you've observed.

Copy link
Member Author

@yitzchak yitzchak Aug 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just what I have observed, but I'll look for a reference. I think it might originate with how FPE is enabled/disabled. On amd64 FPE is always on until you mask it to off and then the mask is reset. Whereas on aarch64 the FPE is off until you explicitly enable it. Aarch64 doesn't have the concept of "masking."

src/lisp/regression-tests/framework.lisp Show resolved Hide resolved
include/clasp/core/lisp.h Outdated Show resolved Hide resolved
@Bike Bike merged commit dc008b5 into main Aug 22, 2024
9 checks passed
@yitzchak yitzchak deleted the fpe branch August 22, 2024 14:27
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.

2 participants