diff options
author | Dimitry Andric <dimitry@andric.com> | 2017-05-25 14:52:14 +0000 |
---|---|---|
committer | Dimitry Andric <dimitry@andric.com> | 2017-05-25 14:52:14 +0000 |
commit | cb42103777b0fa8b8f38a7bfe5592ed8e3e48388 (patch) | |
tree | 01582ecfe0de4bb67ee6b88c6a5aa955e377d36e /lib/builtins/bswapsi2.c | |
parent | 41e921aae202b41ccb0dde05e824bcd6f7f3e0b6 (diff) |
Add generic __bswap[ds]i2 implementations
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.
Reviewers: howard.hinnant, compnerd, petarj, emaste
Reviewed By: compnerd, emaste
Subscribers: mgorny, llvm-commits, arichardson
Differential Revision: https://reviews.llvm.org/D33516
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@303866 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/builtins/bswapsi2.c')
-rw-r--r-- | lib/builtins/bswapsi2.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/builtins/bswapsi2.c b/lib/builtins/bswapsi2.c new file mode 100644 index 000000000..5d941e69f --- /dev/null +++ b/lib/builtins/bswapsi2.c @@ -0,0 +1,23 @@ +/* ===-- bswapsi2.c - Implement __bswapsi2 ---------------------------------=== + * + * The LLVM Compiler Infrastructure + * + * This file is dual licensed under the MIT and the University of Illinois Open + * Source Licenses. See LICENSE.TXT for details. + * + * ===----------------------------------------------------------------------=== + * + * This file implements __bswapsi2 for the compiler_rt library. + * + * ===----------------------------------------------------------------------=== + */ + +#include "int_lib.h" + +COMPILER_RT_ABI uint32_t __bswapsi2(uint32_t u) { + return ( + (((u)&0xff000000) >> 24) | + (((u)&0x00ff0000) >> 8) | + (((u)&0x0000ff00) << 8) | + (((u)&0x000000ff) << 24)); +} |