]> granicus.if.org Git - clang/commitdiff
Expose __builtin_bswap16.
authorBenjamin Kramer <benny.kra@googlemail.com>
Sat, 6 Oct 2012 14:42:22 +0000 (14:42 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sat, 6 Oct 2012 14:42:22 +0000 (14:42 +0000)
GCC has always supported this on PowerPC and 4.8 supports it on all platforms,
so it's a good idea to expose it in clang too. LLVM supports this on all targets.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165362 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/Builtins.def
lib/AST/ExprConstant.cpp
lib/CodeGen/CGBuiltin.cpp
test/CodeGen/builtins.c
test/Sema/constant-builtins-2.c
test/Sema/constant-builtins.c

index 13205e9f91f183c83120dbb50241c628bc3bfb3f..7a1b4aabc1f71aeaff4cc51f18e8cc0c1cea2da1 100644 (file)
@@ -388,6 +388,7 @@ BUILTIN(__builtin_popcountll, "iULLi", "nc")
 
 // FIXME: These type signatures are not correct for targets with int != 32-bits
 // or with ULL != 64-bits.
+BUILTIN(__builtin_bswap16, "UsUs", "nc")
 BUILTIN(__builtin_bswap32, "UiUi", "nc")
 BUILTIN(__builtin_bswap64, "ULLiULLi", "nc")
 
index e21c83b64f67b6166b9b6e01100aaa5678cf682c..323a1746bfbe18a168d50ff355670388ce3a9b4c 100644 (file)
@@ -4296,6 +4296,7 @@ bool IntExprEvaluator::VisitCallExpr(const CallExpr *E) {
     return Error(E);
   }
 
+  case Builtin::BI__builtin_bswap16:
   case Builtin::BI__builtin_bswap32:
   case Builtin::BI__builtin_bswap64: {
     APSInt Val;
index a084be1f71e54dd3129076e38e4f863023233892..b83e75ad23842f3cbb5faac178a327d59dfddd5c 100644 (file)
@@ -356,6 +356,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
                                         "expval");
     return RValue::get(Result);
   }
+  case Builtin::BI__builtin_bswap16:
   case Builtin::BI__builtin_bswap32:
   case Builtin::BI__builtin_bswap64: {
     Value *ArgValue = EmitScalarExpr(E->getArg(0));
index 65b9ad111fd85843cf2bf0e05adf4572c53f069d..9ba12bbf2fec9627fe2d0ebf298d53a9ff199b91 100644 (file)
@@ -113,6 +113,7 @@ int main() {
 
   // Whatever
 
+  P(bswap16, (N));
   P(bswap32, (N));
   P(bswap64, (N));
   // FIXME
index d78a176ef4964df702b4f879bc8773b0d079202d..13d81fe13cbf2e30dfcbcddd5f5c9f3c6fcd71d7 100644 (file)
@@ -48,8 +48,9 @@ extern int f();
 int h0 = __builtin_types_compatible_p(int, float);
 //int h1 = __builtin_choose_expr(1, 10, f());
 //int h2 = __builtin_expect(0, 0);
-int h3 = __builtin_bswap32(0x1234) == 0x34120000 ? 1 : f();
-int h4 = __builtin_bswap64(0x1234) == 0x3412000000000000 ? 1 : f();
+int h3 = __builtin_bswap16(0x1234) == 0x3412 ? 1 : f();
+int h4 = __builtin_bswap32(0x1234) == 0x34120000 ? 1 : f();
+int h5 = __builtin_bswap64(0x1234) == 0x3412000000000000 ? 1 : f();
 extern long int bi0;
 extern __typeof__(__builtin_expect(0, 0)) bi0;
 
index 1562623c0affcba67d5086f5e11cdfd1f9019124..0045ea03d49d5ec3b7d8c52d62b0067fed4f33de 100644 (file)
@@ -16,8 +16,9 @@ extern int f();
 int h0 = __builtin_types_compatible_p(int,float);
 //int h1 = __builtin_choose_expr(1, 10, f());
 //int h2 = __builtin_expect(0, 0);
-int h3 = __builtin_bswap32(0x1234) == 0x34120000 ? 1 : f();
-int h4 = __builtin_bswap64(0x1234) == 0x3412000000000000 ? 1 : f();
+int h3 = __builtin_bswap16(0x1234) == 0x3412 ? 1 : f();
+int h4 = __builtin_bswap32(0x1234) == 0x34120000 ? 1 : f();
+int h5 = __builtin_bswap64(0x1234) == 0x3412000000000000 ? 1 : f();
 
 short somefunc();