-
Notifications
You must be signed in to change notification settings - Fork 15
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
Add f16
and f128
Rust and C support
#54
Conversation
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.
Wow, awesome work!
PrimitiveTy::F16 => write!( | ||
f, | ||
"(((union {{ uint16_t bits; _Float16 value; }}){{ .bits = {} }}).value)", | ||
val.generate_u16() | ||
)?, |
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.
i hate/love it
I'm extremely confused by why a random macos test is failing for you... |
Oh! I was getting false-flagged by an unrelated test emitting a million warnings. Whatever the default compiler is on arm64 macos does not accept the existence of __float128:
|
You can address this in one of two ways:
|
write!( | ||
f, | ||
"(((union {{ __uint128_t bits; __float128 value; }}){{ .bits = ((__uint128_t){lower:#X}ull) | (((__uint128_t){higher:#X}ull) << 64) }}).value)" | ||
)? |
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.
As funny as this is, technically it's more correct to do char* crimes (cuz accessing the wrong member of a union is technically UB sometimes (might be C++ only but egh))
Someone suggested this wonderful abomination:
*(__float128*)memcpy(&(__float128){}, (char[]){ /* bytes here */ }, sizeof(__float128));
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.
(not a blocker)
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.
Union type punning is fine in C, but not in (standard) C++, so the union implementation should be fine unless this code gets compiled as C++ (which I don't think it does?). This Stack Overflow answer appears to be a good summary.
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.
It doesn't yet, but it seems like a natural evolution of the backend to support both (#31), since 95% of the code would be shared (i think). But we can cross that bridge when we want to do that.
Ok reran some of the tests, and at least with the default github CC's on these platforms:
|
So f16 and f128 support in C is... variable. Latest documentation is: GCC for both types, Clang for _Float16 (I'm not sure if/where Clang's support for __float128 is documented). However the documentation does not always appear to be complete (e.g. on compiler explorer, GCC RISC-V appears to support In terms of the platforms tested in CI:
Further complicating matters:
Given the target and compiler version dependant nature for support for these types, I wonder if it would be better to just check the compiler stderr for |
Checking the compiler output will require deeper changes as currently the compiler output is not captured by |
I've ignored the result of the test that fails due to CI GCC being too old. An alternative would be to increase the GCC version used in CI: according to https://github.com/actions/runner-images/blob/ubuntu22/20240630.1/images/ubuntu/Ubuntu2204-Readme.md, GCC 12 is available. |
Oh, awesome work! I agree we should ideally (in the future) have better info on the compiler we're interacting with, hmm... |
As far as I can tell CI has failed on MacOS due to the compiler being misidentified as being GCC when it is Clang. I believe this will be fixed when |
Works for me! We can refine this logic in followups as desired. Thanks so much!!!! |
Closes #16