This is an archive of the discontinued LLVM Phabricator instance.

Add generic __bswap[ds]i2 implementations
ClosedPublic

Authored by dim on May 24 2017, 1:33 PM.

Details

Summary

In FreeBSD we needed to add generic implementations for __bswapdi2 and
__bswapsi2, since gcc 6.x for mips is emitting calls to these. See:

https://reviews.freebsd.org/D10838 and https://reviews.freebsd.org/rS318601

The actual mips code generated for these generic C versions is pretty
OK, as can be seen in the (FreeBSD) review.

I checked over gcc sources, and it seems that it can emit these calls on
more architectures, so maybe it's best to simply always add them to the
compiler-rt builtins library.

Event Timeline

dim created this revision.May 24 2017, 1:33 PM
emaste accepted this revision.May 24 2017, 5:25 PM

LGTM from my perspective.

lib/builtins/bswapdi2.c
20–27

Does clang-format agree with this style?

This revision is now accepted and ready to land.May 24 2017, 5:25 PM
compnerd accepted this revision.May 24 2017, 7:20 PM

Please clang-format before committing this.

dim added a comment.May 25 2017, 7:36 AM

Hmm, it's a bit weird that lib/builtins doesn't have its own .clang-format file. Is this supposed to have LLVM or Google style? The style across various files seems to be wildly different.

Both the LLVM and Google style reformat the body of the function to the following, which I find very ugly:

return (
    (((u)&0xff00000000000000ULL) >> 56) |
    (((u)&0x00ff000000000000ULL) >> 40) |
    (((u)&0x0000ff0000000000ULL) >> 24) | (((u)&0x000000ff00000000ULL) >> 8) |
    (((u)&0x00000000ff000000ULL) << 8) | (((u)&0x0000000000ff0000ULL) << 24) |
    (((u)&0x000000000000ff00ULL) << 40) |
    (((u)&0x00000000000000ffULL) << 56));

I am going to ignore clang-format's suggestion here, and just have one | expression per line instead.

dim closed this revision.May 25 2017, 7:52 AM