[cfe-dev] Converting float to int with FJCVTZS
Craig Topper via cfe-dev
cfe-dev at lists.llvm.org
Wed Mar 10 09:26:57 PST 2021
I don't think cvttss2si wraps around. Instead it returns 0x80000000 for
large values. "If a converted result is larger than the maximum signed
doubleword integer, the floating-point invalid exception is raised. If this
exception is masked, the indefinite integer value (80000000H or
80000000_00000000H if operand size is 64 bits) is returned."
Also isn't fcvtzu an unsigned conversion while cvttss2si and FJCVTZS are
signed conversions? Am I missing something?
On Wed, Mar 10, 2021 at 9:03 AM Johannes Hoff via cfe-dev <
cfe-dev at lists.llvm.org> wrote:
> I'm working on a code base where a simulation needs to produce the exact
> same result on Aarch64 and x86_64 architectures.
> This is indeed the case for the whole codebase, with one exception:
> Rounding floats to integers. Specifically, when we're in undefined behavior
> territory. In that case, you notice the difference between the emitted
> fcvtzu instruction on aarch64 (saturating cast) and cvttss2si on x86
> Now, I know undefined behavior is not the main business of LLVM, but I
> wonder if it would be possible to ask it to emit FJCVTZS instead, which
> behaves like x86 outside of the integer range. Of course, this would be an
> opt-in flag.
> What do you think? If it's not something that would be valuable for clang,
> do you have any pointers on how to patch it myself?
> Of course, I can just use the compiler intrinsic __builtin_arm_jcvt to
> trigger this behavior, but then I need to be sure to catch all the places,
> and be sure that everyone on the team remembers to do the same in the
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cfe-dev