diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -59,6 +59,8 @@ - Maximum _ExtInt size was decreased from 16,777,215 bits to 8,388,608 bits. Motivation for this was discussed in PR51829. +- The builtin ``__builtin_bswap128`` was added. + New Compiler Flags ------------------ diff --git a/clang/include/clang/Basic/Builtins.def b/clang/include/clang/Basic/Builtins.def --- a/clang/include/clang/Basic/Builtins.def +++ b/clang/include/clang/Basic/Builtins.def @@ -512,6 +512,7 @@ BUILTIN(__builtin_bswap16, "UsUs", "nc") BUILTIN(__builtin_bswap32, "UZiUZi", "nc") BUILTIN(__builtin_bswap64, "UWiUWi", "nc") +BUILTIN(__builtin_bswap128, "ULLLiULLLi", "nc") BUILTIN(__builtin_bitreverse8, "UcUc", "nc") BUILTIN(__builtin_bitreverse16, "UsUs", "nc") diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -11640,7 +11640,8 @@ case Builtin::BI__builtin_bswap16: case Builtin::BI__builtin_bswap32: - case Builtin::BI__builtin_bswap64: { + case Builtin::BI__builtin_bswap64: + case Builtin::BI__builtin_bswap128: { APSInt Val; if (!EvaluateInteger(E->getArg(0), Val, Info)) return false; diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -2905,7 +2905,8 @@ } case Builtin::BI__builtin_bswap16: case Builtin::BI__builtin_bswap32: - case Builtin::BI__builtin_bswap64: { + case Builtin::BI__builtin_bswap64: + case Builtin::BI__builtin_bswap128: { return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::bswap)); } case Builtin::BI__builtin_bitreverse8: diff --git a/clang/test/CodeGen/builtins.cpp b/clang/test/CodeGen/builtins.cpp --- a/clang/test/CodeGen/builtins.cpp +++ b/clang/test/CodeGen/builtins.cpp @@ -20,6 +20,10 @@ decltype(__builtin_bswap32(0)) bswap32 = 42; extern uint64_t bswap64; decltype(__builtin_bswap64(0)) bswap64 = 42; +#ifdef __SIZEOF_INT128__ +extern __uint128_t bswap128; +decltype(__builtin_bswap128(0)) bswap128 = 42; +#endif #ifdef __clang__ extern uint8_t bitrev8; diff --git a/clang/test/Sema/constant-builtins-2.c b/clang/test/Sema/constant-builtins-2.c --- a/clang/test/Sema/constant-builtins-2.c +++ b/clang/test/Sema/constant-builtins-2.c @@ -216,6 +216,7 @@ int h3 = __builtin_bswap16(0x1234) == 0x3412 ? 1 : f(); int h4 = __builtin_bswap32(0x1234) == 0x34120000 ? 1 : f(); int h5 = __builtin_bswap64(0x1234) == 0x3412000000000000 ? 1 : f(); +int h6 = __builtin_bswap128(0x1234) == (((__int128)0x3412) << 112) ? 1 : f(); extern long int bi0; extern __typeof__(__builtin_expect(0, 0)) bi0;