This is an archive of the discontinued LLVM Phabricator instance.

[COMPILER-RT] Implement __fixtfsi, __fixunstfsi
ClosedPublic

Authored by joerg on Feb 13 2014, 9:56 PM.

Diff Detail

Event Timeline

koviankevin updated this revision to Unknown Object (????).Feb 19 2014, 6:15 PM

add test

koviankevin updated this revision to Unknown Object (????).Feb 24 2014, 7:54 PM

Use CRT_HAS_128BIT and modify the codes according to gribozavr's comments

koviankevin updated this revision to Unknown Object (????).Feb 27 2014, 8:46 PM

introduce CRT_LDBL_128BIT

koviankevin updated this revision to Unknown Object (????).Mar 10 2014, 1:15 AM

modify by gribozavr's comment and use COMPILER_RT_ABI

joerg added a subscriber: joerg.May 15 2014, 8:23 AM
joerg added inline comments.
lib/builtins/fixtfsi.c
31

Typos, see comments below for return value.

48

Typo. Doesn't agree with the comment above in that it provides a deterministic value?

50

Shouldn't this be sign == 1 ? INT_MAX : INT_MIN, otherwise it would return INT_MIN + 1?

lib/builtins/fixunstfsi.c
26

Code does range check?

42

Typo in comment, please spell the constant as UINT_MAX too.

koviankevin updated this revision to Diff 9741.May 23 2014, 1:15 AM

use UINT64_C and drop le64

joerg accepted this revision.May 23 2014, 5:02 AM
joerg added a reviewer: joerg.

With the comment fix.

lib/builtins/fixunstfsi.c
40

Still typo

This revision is now accepted and ready to land.May 23 2014, 5:02 AM
koviankevin updated this revision to Diff 9792.May 25 2014, 7:57 PM
koviankevin edited edge metadata.

fix typo

This patch blocks quad math stuff on aarch64 from using compiler-rt instead of gnu libgcc
Can this patch be commited, now? Thanks

joerg commandeered this revision.Sep 16 2014, 1:38 PM
joerg edited reviewers, added: koviankevin; removed: joerg.
joerg added inline comments.
lib/builtins/fixtfsi.c
34

See initial comment, no need for range check.

This revision now requires review to proceed.Sep 16 2014, 1:38 PM
joerg updated this revision to Diff 13761.Sep 16 2014, 1:39 PM

Refactor existing fixXfsi functions and use common code for fixtfsi. Drop range checks as they are UB.

koviankevin edited edge metadata.Sep 17 2014, 12:05 AM

Since these functions are implemented for using compiler-rt instead of libgcc, and __fixtfsi returns INT_MAX/INT_MIN when the input is out of range in libgcc, I think range check is still needed to avoid inconsistent results.

Steve -- you wrote the original version. Can you comment on the overflow handling please?

scanon edited edge metadata.Sep 17 2014, 5:48 PM

I think it makes sense to clamp out-of-range values. Even though the C language cast is UB, there’s a fairly clear “right” thing to do, and we can do it without excessive performance penalty. Let’s follow libgcc here and saturate.

joerg updated this revision to Diff 13847.Sep 18 2014, 1:54 PM
joerg edited edge metadata.

Implement saturation logic for all __fix*si variants.

__fixunstfsi should have range check, too.

Saturation logic for _fixunstfsi is also needed but it has been removed in previous revision. (i.e, range check part in fixuntfsi.cpp)

emaste added a subscriber: emaste.Jan 9 2015, 5:57 AM

Saturation logic for _fixunstfsi is also needed but it has been removed in previous revision. (i.e, range check part in fixuntfsi.cpp)

Is this the only outstanding issue here?

Yes, it's not resonable to implement saturation logic for fixtfsi but not for fixuntfsi.

Yes, it's not resonable to implement saturation logic for fixtfsi but not for fixuntfsi.

That's reasonable -- I'm not asking if it can be committed in the current state, but rather if it's ready to commit once this is addressed.

OK, but the following two cases in the test will fail if there's no saturation logic in fixunstfsi. I think it's better to remove them, thanks.

if (test__fixunstfsi(0x1.23456789abcdefp+40, UINT32_C(0xffffffff)))
    return 1;
if (test__fixunstfsi(0x1.23456789abcdefp+256, UINT32_C(0xffffffff)))
    return 1;
joerg updated this revision to Diff 21459.Mar 8 2015, 2:16 PM

Refactor fix* and fixuns* to use common logic and consistent behavior w.r.t. saturation. XF format is still excluded for now.

joerg updated this revision to Diff 21460.Mar 8 2015, 2:19 PM

Fix glitches for XF support.

scanon accepted this revision.Mar 9 2015, 6:08 AM
scanon edited edge metadata.

Thanks for keeping after this. Looks good to me.

This revision is now accepted and ready to land.Mar 9 2015, 6:08 AM
This revision was automatically updated to reflect the committed changes.