[compiler-rt] r303866 - Add generic __bswap[ds]i2 implementations
Dimitry Andric via llvm-commits
llvm-commits at lists.llvm.org
Thu May 25 07:52:15 PDT 2017
Author: dim
Date: Thu May 25 09:52:14 2017
New Revision: 303866
URL: http://llvm.org/viewvc/llvm-project?rev=303866&view=rev
Log:
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
Added:
compiler-rt/trunk/lib/builtins/bswapdi2.c
compiler-rt/trunk/lib/builtins/bswapsi2.c
Modified:
compiler-rt/trunk/lib/builtins/CMakeLists.txt
compiler-rt/trunk/lib/builtins/README.txt
compiler-rt/trunk/test/builtins/Unit/bswapdi2_test.c
compiler-rt/trunk/test/builtins/Unit/bswapsi2_test.c
Modified: compiler-rt/trunk/lib/builtins/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/CMakeLists.txt?rev=303866&r1=303865&r2=303866&view=diff
==============================================================================
--- compiler-rt/trunk/lib/builtins/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/builtins/CMakeLists.txt Thu May 25 09:52:14 2017
@@ -42,6 +42,8 @@ set(GENERIC_SOURCES
ashlti3.c
ashrdi3.c
ashrti3.c
+ bswapdi2.c
+ bswapsi2.c
clear_cache.c
clzdi2.c
clzsi2.c
Modified: compiler-rt/trunk/lib/builtins/README.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/README.txt?rev=303866&r1=303865&r2=303866&view=diff
==============================================================================
--- compiler-rt/trunk/lib/builtins/README.txt (original)
+++ compiler-rt/trunk/lib/builtins/README.txt Thu May 25 09:52:14 2017
@@ -57,8 +57,8 @@ si_int __popcountsi2(si_int a); // bit
si_int __popcountdi2(di_int a); // bit population
si_int __popcountti2(ti_int a); // bit population
-uint32_t __bswapsi2(uint32_t a); // a byteswapped, arm only
-uint64_t __bswapdi2(uint64_t a); // a byteswapped, arm only
+uint32_t __bswapsi2(uint32_t a); // a byteswapped
+uint64_t __bswapdi2(uint64_t a); // a byteswapped
// Integral arithmetic
Added: compiler-rt/trunk/lib/builtins/bswapdi2.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/bswapdi2.c?rev=303866&view=auto
==============================================================================
--- compiler-rt/trunk/lib/builtins/bswapdi2.c (added)
+++ compiler-rt/trunk/lib/builtins/bswapdi2.c Thu May 25 09:52:14 2017
@@ -0,0 +1,27 @@
+/* ===-- bswapdi2.c - Implement __bswapdi2 ---------------------------------===
+ *
+ * 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 __bswapdi2 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+COMPILER_RT_ABI uint64_t __bswapdi2(uint64_t u) {
+ 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));
+}
Added: compiler-rt/trunk/lib/builtins/bswapsi2.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/bswapsi2.c?rev=303866&view=auto
==============================================================================
--- compiler-rt/trunk/lib/builtins/bswapsi2.c (added)
+++ compiler-rt/trunk/lib/builtins/bswapsi2.c Thu May 25 09:52:14 2017
@@ -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));
+}
Modified: compiler-rt/trunk/test/builtins/Unit/bswapdi2_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/bswapdi2_test.c?rev=303866&r1=303865&r2=303866&view=diff
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/bswapdi2_test.c (original)
+++ compiler-rt/trunk/test/builtins/Unit/bswapdi2_test.c Thu May 25 09:52:14 2017
@@ -13,34 +13,25 @@
//
//===----------------------------------------------------------------------===//
-#include <stdlib.h>
+#include <math.h>
#include <stdint.h>
#include <stdio.h>
-#include <math.h>
-
+#include <stdlib.h>
extern uint64_t __bswapdi2(uint64_t);
-#if __arm__
-int test__bswapdi2(uint64_t a, uint64_t expected)
-{
- uint64_t actual = __bswapdi2(a);
- if (actual != expected)
- printf("error in test__bswapsi2(0x%0llX) = 0x%0llX, expected 0x%0llX\n",
- a, actual, expected);
- return actual != expected;
+int test__bswapdi2(uint64_t a, uint64_t expected) {
+ uint64_t actual = __bswapdi2(a);
+ if (actual != expected)
+ printf("error in test__bswapsi2(0x%0llX) = 0x%0llX, expected 0x%0llX\n", a,
+ actual, expected);
+ return actual != expected;
}
-#endif
-int main()
-{
-#if __arm__
- if (test__bswapdi2(0x123456789ABCDEF0LL, 0xF0DEBC9A78563412LL))
- return 1;
- if (test__bswapdi2(0x0000000100000002LL, 0x0200000001000000LL))
- return 1;
-#else
- printf("skipped\n");
-#endif
- return 0;
+int main() {
+ if (test__bswapdi2(0x123456789ABCDEF0LL, 0xF0DEBC9A78563412LL))
+ return 1;
+ if (test__bswapdi2(0x0000000100000002LL, 0x0200000001000000LL))
+ return 1;
+ return 0;
}
Modified: compiler-rt/trunk/test/builtins/Unit/bswapsi2_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/bswapsi2_test.c?rev=303866&r1=303865&r2=303866&view=diff
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/bswapsi2_test.c (original)
+++ compiler-rt/trunk/test/builtins/Unit/bswapsi2_test.c Thu May 25 09:52:14 2017
@@ -13,34 +13,25 @@
//
//===----------------------------------------------------------------------===//
-#include <stdlib.h>
+#include <math.h>
#include <stdint.h>
#include <stdio.h>
-#include <math.h>
-
+#include <stdlib.h>
extern uint32_t __bswapsi2(uint32_t);
-#if __arm__
-int test__bswapsi2(uint32_t a, uint32_t expected)
-{
- uint32_t actual = __bswapsi2(a);
- if (actual != expected)
- printf("error in test__bswapsi2(0x%0X) = 0x%0X, expected 0x%0X\n",
- a, actual, expected);
- return actual != expected;
+int test__bswapsi2(uint32_t a, uint32_t expected) {
+ uint32_t actual = __bswapsi2(a);
+ if (actual != expected)
+ printf("error in test__bswapsi2(0x%0X) = 0x%0X, expected 0x%0X\n", a,
+ actual, expected);
+ return actual != expected;
}
-#endif
-int main()
-{
-#if __arm__
- if (test__bswapsi2(0x12345678, 0x78563412))
- return 1;
- if (test__bswapsi2(0x00000001, 0x01000000))
- return 1;
-#else
- printf("skipped\n");
-#endif
- return 0;
+int main() {
+ if (test__bswapsi2(0x12345678, 0x78563412))
+ return 1;
+ if (test__bswapsi2(0x00000001, 0x01000000))
+ return 1;
+ return 0;
}
More information about the llvm-commits
mailing list