[cfe-dev] [llvm-dev] Should isnan be optimized out in fast-math mode?
James Y Knight via cfe-dev
cfe-dev at lists.llvm.org
Mon Sep 13 04:59:45 PDT 2021
On Mon, Sep 13, 2021, 2:02 AM Serge Pavlov via cfe-dev <
cfe-dev at lists.llvm.org> wrote:
> The working construct is `reinterpret_cast<uint32_t&>(x)`. It however
> possesses the same drawback, it requires `x` be in memory.
We're getting rather far afield of the thread topic here, but .. that is
UB, don't do that.
Instead, always memcpy, e.g.
memcpy(&y, &flo, sizeof(uint32_t));
Or use a wrapper like std::bit_cast or absl::bit_cast (
This has effectively no runtime overhead, the compiler is extremely good at
deleting calls to memcpy when it has a constant smallish size. And remember
that *every* local variable started out in memory. Only through
optimizations does the memory location and the loads/stores for every
access get eliminated.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cfe-dev