1 // RUN: %clang_cc1 -x c -ffreestanding -triple i686--linux -emit-llvm %s -o - | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG
2 // RUN: %clang_cc1 -x c -ffreestanding -triple x86_64--linux -emit-llvm %s -o - | FileCheck %s --check-prefixes CHECK,CHECK-64BIT-LONG
3 // RUN: %clang_cc1 -x c -fms-extensions -fms-compatibility -ffreestanding %s -triple=i686-windows-msvc -target-feature +sse2 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG
4 // RUN: %clang_cc1 -x c -fms-extensions -fms-compatibility -ffreestanding %s -triple=x86_64-windows-msvc -target-feature +sse2 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG
5 // RUN: %clang_cc1 -x c -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 -ffreestanding %s -triple=i686-windows-msvc -target-feature +sse2 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG
6 // RUN: %clang_cc1 -x c -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 -ffreestanding %s -triple=x86_64-windows-msvc -target-feature +sse2 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG
7
8 // RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding -triple i686--linux -emit-llvm %s -o - | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG
9 // RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding -triple x86_64--linux -emit-llvm %s -o - | FileCheck %s --check-prefixes CHECK,CHECK-64BIT-LONG
10 // RUN: %clang_cc1 -x c++ -std=c++11 -fms-extensions -fms-compatibility -ffreestanding %s -triple=i686-windows-msvc -target-feature +sse2 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG
11 // RUN: %clang_cc1 -x c++ -std=c++11 -fms-extensions -fms-compatibility -ffreestanding %s -triple=x86_64-windows-msvc -target-feature +sse2 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG
12 // RUN: %clang_cc1 -x c++ -std=c++11 -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 -ffreestanding %s -triple=i686-windows-msvc -target-feature +sse2 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG
13 // RUN: %clang_cc1 -x c++ -std=c++11 -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 -ffreestanding %s -triple=x86_64-windows-msvc -target-feature +sse2 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG
14
15 #include <x86intrin.h>
16
test__rolb(unsigned char value,int shift)17 unsigned char test__rolb(unsigned char value, int shift) {
18 // CHECK-LABEL: test__rolb
19 // CHECK: [[R:%.*]] = call i8 @llvm.fshl.i8(i8 [[X:%.*]], i8 [[X]], i8 [[Y:%.*]])
20 // CHECK: ret i8 [[R]]
21 return __rolb(value, shift);
22 }
23
test__rolw(unsigned short value,int shift)24 unsigned short test__rolw(unsigned short value, int shift) {
25 // CHECK-LABEL: test__rolw
26 // CHECK: [[R:%.*]] = call i16 @llvm.fshl.i16(i16 [[X:%.*]], i16 [[X]], i16 [[Y:%.*]])
27 // CHECK: ret i16 [[R]]
28 return __rolw(value, shift);
29 }
30
test__rold(unsigned int value,int shift)31 unsigned int test__rold(unsigned int value, int shift) {
32 // CHECK-LABEL: test__rold
33 // CHECK: [[R:%.*]] = call i32 @llvm.fshl.i32(i32 [[X:%.*]], i32 [[X]], i32 [[Y:%.*]])
34 // CHECK: ret i32 [[R]]
35 return __rold(value, shift);
36 }
37
38 #if defined(__x86_64__)
test__rolq(unsigned long value,int shift)39 unsigned long test__rolq(unsigned long value, int shift) {
40 // CHECK-LONG-LABEL: test__rolq
41 // CHECK-LONG: [[R:%.*]] = call i64 @llvm.fshl.i64(i64 [[X:%.*]], i64 [[X]], i64 [[Y:%.*]])
42 // CHECK-LONG: ret i64 [[R]]
43 return __rolq(value, shift);
44 }
45 #endif
46
test__rorb(unsigned char value,int shift)47 unsigned char test__rorb(unsigned char value, int shift) {
48 // CHECK-LABEL: test__rorb
49 // CHECK: [[R:%.*]] = call i8 @llvm.fshr.i8(i8 [[X:%.*]], i8 [[X]], i8 [[Y:%.*]])
50 // CHECK: ret i8 [[R]]
51 return __rorb(value, shift);
52 }
53
test__rorw(unsigned short value,int shift)54 unsigned short test__rorw(unsigned short value, int shift) {
55 // CHECK-LABEL: test__rorw
56 // CHECK: [[R:%.*]] = call i16 @llvm.fshr.i16(i16 [[X:%.*]], i16 [[X]], i16 [[Y:%.*]])
57 // CHECK: ret i16 [[R]]
58 return __rorw(value, shift);
59 }
60
test__rord(unsigned int value,int shift)61 unsigned int test__rord(unsigned int value, int shift) {
62 // CHECK-LABEL: test__rord
63 // CHECK: [[R:%.*]] = call i32 @llvm.fshr.i32(i32 [[X:%.*]], i32 [[X]], i32 [[Y:%.*]])
64 // CHECK: ret i32 [[R]]
65 return __rord(value, shift);
66 }
67
68 #if defined(__x86_64__)
test__rorq(unsigned long value,int shift)69 unsigned long test__rorq(unsigned long value, int shift) {
70 // CHECK-LONG-LABEL: test__rorq
71 // CHECK-LONG: [[R:%.*]] = call i64 @llvm.fshr.i64(i64 [[X:%.*]], i64 [[X]], i64 [[Y:%.*]])
72 // CHECK-LONG: ret i64 [[R]]
73 return __rorq(value, shift);
74 }
75 #endif
76
test_rotwl(unsigned short value,int shift)77 unsigned short test_rotwl(unsigned short value, int shift) {
78 // CHECK-LABEL: test_rotwl
79 // CHECK: [[R:%.*]] = call i16 @llvm.fshl.i16(i16 [[X:%.*]], i16 [[X]], i16 [[Y:%.*]])
80 // CHECK: ret i16 [[R]]
81 return _rotwl(value, shift);
82 }
83
test_rotl(unsigned int value,int shift)84 unsigned int test_rotl(unsigned int value, int shift) {
85 // CHECK-LABEL: test_rotl
86 // CHECK: [[R:%.*]] = call i32 @llvm.fshl.i32(i32 [[X:%.*]], i32 [[X]], i32 [[Y:%.*]])
87 // CHECK: ret i32 [[R]]
88 return _rotl(value, shift);
89 }
90
test_lrotl(unsigned long value,int shift)91 unsigned long test_lrotl(unsigned long value, int shift) {
92 // CHECK-32BIT-LONG-LABEL: test_lrotl
93 // CHECK-32BIT-LONG: [[R:%.*]] = call i32 @llvm.fshl.i32(i32 [[X:%.*]], i32 [[X]], i32 [[Y:%.*]])
94 // CHECK-32BIT-LONG: ret i32 [[R]]
95 //
96 // CHECK-64BIT-LONG-LABEL: test_lrotl
97 // CHECK-64BIT-LONG: [[R:%.*]] = call i64 @llvm.fshl.i64(i64 [[X:%.*]], i64 [[X]], i64 [[Y:%.*]])
98 // CHECK-64BIT-LONG: ret i64 [[R]]
99 return _lrotl(value, shift);
100 }
101
102
test_rotwr(unsigned short value,int shift)103 unsigned short test_rotwr(unsigned short value, int shift) {
104 // CHECK-LABEL: test_rotwr
105 // CHECK: [[R:%.*]] = call i16 @llvm.fshr.i16(i16 [[X:%.*]], i16 [[X]], i16 [[Y:%.*]])
106 // CHECK: ret i16 [[R]]
107 return _rotwr(value, shift);
108 }
109
test_rotr(unsigned int value,int shift)110 unsigned int test_rotr(unsigned int value, int shift) {
111 // CHECK-LABEL: test_rotr
112 // CHECK: [[R:%.*]] = call i32 @llvm.fshr.i32(i32 [[X:%.*]], i32 [[X]], i32 [[Y:%.*]])
113 // CHECK: ret i32 [[R]]
114 return _rotr(value, shift);
115 }
116
test_lrotr(unsigned long value,int shift)117 unsigned long test_lrotr(unsigned long value, int shift) {
118 // CHECK-32BIT-LONG-LABEL: test_lrotr
119 // CHECK-32BIT-LONG: [[R:%.*]] = call i32 @llvm.fshr.i32(i32 [[X:%.*]], i32 [[X]], i32 [[Y:%.*]])
120 // CHECK-32BIT-LONG: ret i32 [[R]]
121 //
122 // CHECK-64BIT-LONG-LABEL: test_lrotr
123 // CHECK-64BIT-LONG: [[R:%.*]] = call i64 @llvm.fshr.i64(i64 [[X:%.*]], i64 [[X]], i64 [[Y:%.*]])
124 // CHECK-64BIT-LONG: ret i64 [[R]]
125 return _lrotr(value, shift);
126 }
127
128 // Test constexpr handling.
129 #if defined(__cplusplus) && (__cplusplus >= 201103L)
130
131 char rolb_0[__rolb(0x01, 5) == 0x20 ? 1 : -1];
132 char rolw_0[__rolw(0x3210, 11) == 0x8190 ? 1 : -1];
133 char rold_0[__rold(0x76543210, 22) == 0x841D950C ? 1 : -1];
134
135 char rorb_0[__rorb(0x01, 5) == 0x08 ? 1 : -1];
136 char rorw_0[__rorw(0x3210, 11) == 0x4206 ? 1 : -1];
137 char rord_0[__rord(0x76543210, 22) == 0x50C841D9 ? 1 : -1];
138
139 #if defined(__x86_64__)
140 char rolq_0[__rolq(0xFEDCBA9876543210ULL, 55) == 0x087F6E5D4C3B2A19ULL ? 1 : -1];
141 char rorq_0[__rorq(0xFEDCBA9876543210ULL, 55) == 0xB97530ECA86421FDULL ? 1 : -1];
142 #endif
143
144 char rotwl_0[_rotwl(0x3210, 4) == 0x2103 ? 1 : -1];
145 char rotwr_0[_rotwr(0x3210, 4) == 0x0321 ? 1 : -1];
146 char rotl_0[_rotl(0x76543210, 8) == 0x54321076 ? 1 : -1];
147 char rotr_0[_rotr(0x76543210, 8) == 0x10765432 ? 1 : -1];
148
149 #if defined(__LP64__) && !defined(_MSC_VER)
150 char lrotl_0[_lrotl(0xFEDCBA9876543210ULL, 55) == 0x087F6E5D4C3B2A19ULL ? 1 : -1];
151 char lrotr_0[_lrotr(0xFEDCBA9876543210ULL, 55) == 0xB97530ECA86421FDULL ? 1 : -1];
152 #else
153 char lrotl_0[_lrotl(0x76543210, 22) == 0x841D950C ? 1 : -1];
154 char lrotr_0[_lrotr(0x76543210, 22) == 0x50C841D9 ? 1 : -1];
155 #endif
156
157 #endif
158