float types: move copysign, abs, signum to libcore#131304
Conversation
This comment has been minimized.
This comment has been minimized.
|
I was working on PRing such with some tests to validate that no calls to |
|
That said, we can always read the source. It does not generate libcalls for fabs, but it does for fcopysign. EDIT: There's also this .td file which describes all the runtime libcalls LLVM might lower: |
Then either things changed since @Urgau made their experiments or there are some other factors involved... FWIW we could also implement let sign_bit = mem::size_of::<Self>()*8 - 1;
Self::from_bits(self.abs().to_bits() | (sign.to_bits() & (1 << sign_bit)) |
@RalfJung Architecture and size of the float, the latter of which has become particularly relevant for f128... I believe a lot of things that "shouldn't" generate libcalls nonetheless do for f128. |
|
my implementation of copysign was let sign = sign.abs().to_bits() ^ sign.to_bits();
Self::from_bits(self.to_bits() | sign) |
|
Judging from the f16/f128 comments, we do already have things in libcore that generate calls -- I see comments about missing Cc @tgross35 |
|
We "just" need to make sure that compiler_builtins supports the relevant libcall. |
If |
|
Oh, you're right, I meant |
I don't see any |
|
@RalfJung If you cut this down to fabs then I'll go pick up the copysign work. While I was planning on being extra-pedantic, I expect a compiler should never emit a libcall for fabs. Ever. |
|
+1 to what Jubilee is saying, if we can be reasonably certain that the compiler won't emit a libcall for at least
|
|
As-mentioned, I am absolutely pro-landing-as-is for fabs, because it won't have any trouble with that. If your compiler backend can't lower that without a libcall, throw it out! Maybe if it legalizes the bitops to |
|
Apologies for holding up the works. I believe I was mislead by the dead rising again in a hollow mockery of the living, and will pursue turning them away upstream: |
That's odd, why would |
Ah, so these libcalls are likely not actually used?
Maybe we should have that first before moving these things to libcore. So if you have a good idea for how to write such a test, I'll happily wait for that. :) |
It just mirrors how things are split in the C world - Looking at |
Yes, my understanding is that the codepath that does "libcall legalization" of intrinsics happens "last" (speaking very, very loosely) during lowering to the machine level, and thus has several possible upstream chances to "get missed". For instance, maybe LLVM notices a call to copysign can use one of the FSGNJ* instructions on RISCV (a somewhat odd set of instructions that compose two floats with one of three bitops). I couldn't find something in SelectionDAG that guarantees we never hit the switch into |
|
r? libs-api |
|
I don't believe this needs libs-api review since FCP completed #131304 (comment). The new use of @bors r+ |
|
Hey folks, I recently was making changes to a no std crate and wanted to use I would definitely have appreciated some caveats in the primitive docs for functions that have conditional availability in no std crates based on Rust version! |
|
Sadly we don't have infrastructure for that. Feel free to open an issue so we can discuss possible ways of handling this. There might even already be one; the keyword here is "path stability" vs "item stability" -- rustdoc can only communicate the latter currently. |
|
Even free form text in the prose of the doc comment would have solved this for me. |
|
Filed #139066 to discuss. |
These operations are explicitly specified to act "bitwise", i.e. they just act on the sign bit and do not even quiet signaling NaNs. We also list them as "non-arithmetic operations", and all the other non-arithmetic operations are in libcore. There's no reason to expect them to require any sort of runtime support, and from these experiments it seems like LLVM indeed compiles them in a way that does not require any sort of runtime support.
Nominating for @rust-lang/libs-api since this change takes immediate effect on stable.
Part of #50145.