Skip to content

Commit 1ff9361

Browse files
committed
[PowerPC] Add missing overloads of vec_promote to altivec.h
The VSX-only overloads (for 8-byte element vectors) are missing. Add the missing overloads and convert element numbering to modulo arithmetic to match GCC and XLC.
1 parent 93c5e6b commit 1ff9361

File tree

2 files changed

+48
-7
lines changed

2 files changed

+48
-7
lines changed

clang/lib/Headers/altivec.h

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14024,49 +14024,71 @@ static __inline__ void __ATTRS_o_ai vec_stvrxl(vector float __a, int __b,
1402414024
static __inline__ vector signed char __ATTRS_o_ai vec_promote(signed char __a,
1402514025
int __b) {
1402614026
vector signed char __res = (vector signed char)(0);
14027-
__res[__b] = __a;
14027+
__res[__b & 0x7] = __a;
1402814028
return __res;
1402914029
}
1403014030

1403114031
static __inline__ vector unsigned char __ATTRS_o_ai
1403214032
vec_promote(unsigned char __a, int __b) {
1403314033
vector unsigned char __res = (vector unsigned char)(0);
14034-
__res[__b] = __a;
14034+
__res[__b & 0x7] = __a;
1403514035
return __res;
1403614036
}
1403714037

1403814038
static __inline__ vector short __ATTRS_o_ai vec_promote(short __a, int __b) {
1403914039
vector short __res = (vector short)(0);
14040-
__res[__b] = __a;
14040+
__res[__b & 0x7] = __a;
1404114041
return __res;
1404214042
}
1404314043

1404414044
static __inline__ vector unsigned short __ATTRS_o_ai
1404514045
vec_promote(unsigned short __a, int __b) {
1404614046
vector unsigned short __res = (vector unsigned short)(0);
14047-
__res[__b] = __a;
14047+
__res[__b & 0x7] = __a;
1404814048
return __res;
1404914049
}
1405014050

1405114051
static __inline__ vector int __ATTRS_o_ai vec_promote(int __a, int __b) {
1405214052
vector int __res = (vector int)(0);
14053-
__res[__b] = __a;
14053+
__res[__b & 0x3] = __a;
1405414054
return __res;
1405514055
}
1405614056

1405714057
static __inline__ vector unsigned int __ATTRS_o_ai vec_promote(unsigned int __a,
1405814058
int __b) {
1405914059
vector unsigned int __res = (vector unsigned int)(0);
14060-
__res[__b] = __a;
14060+
__res[__b & 0x3] = __a;
1406114061
return __res;
1406214062
}
1406314063

1406414064
static __inline__ vector float __ATTRS_o_ai vec_promote(float __a, int __b) {
1406514065
vector float __res = (vector float)(0);
14066-
__res[__b] = __a;
14066+
__res[__b & 0x3] = __a;
1406714067
return __res;
1406814068
}
1406914069

14070+
#ifdef __VSX__
14071+
static __inline__ vector double __ATTRS_o_ai vec_promote(double __a, int __b) {
14072+
vector double __res = (vector double)(0);
14073+
__res[__b & 0x1] = __a;
14074+
return __res;
14075+
}
14076+
14077+
static __inline__ vector signed long long __ATTRS_o_ai
14078+
vec_promote(signed long long __a, int __b) {
14079+
vector signed long long __res = (vector signed long long)(0);
14080+
__res[__b & 0x1] = __a;
14081+
return __res;
14082+
}
14083+
14084+
static __inline__ vector unsigned long long __ATTRS_o_ai
14085+
vec_promote(unsigned long long __a, int __b) {
14086+
vector unsigned long long __res = (vector unsigned long long)(0);
14087+
__res[__b & 0x1] = __a;
14088+
return __res;
14089+
}
14090+
#endif
14091+
1407014092
/* vec_splats */
1407114093

1407214094
static __inline__ vector signed char __ATTRS_o_ai vec_splats(signed char __a) {

clang/test/CodeGen/builtins-ppc-vsx.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ vector signed long long vsll = { 255LL, -937LL };
2222
vector unsigned long long vull = { 1447LL, 2894LL };
2323
double d = 23.4;
2424
signed long long sll = 618LL;
25+
unsigned long long ull = 618ULL;
2526
float af[4] = {23.4f, 56.7f, 89.0f, 12.3f};
2627
double ad[2] = {23.4, 56.7};
2728
signed char asc[16] = { -8, 9, -10, 11, -12, 13, -14, 15,
@@ -1851,6 +1852,24 @@ res_vsc = vec_xxsldwi(vsc, vsc, 0);
18511852
res_vuc = vec_xxsldwi(vuc, vuc, 1);
18521853
// CHECK: shufflevector <4 x i32> %{{[0-9]+}}, <4 x i32> %{{[0-9]+}}, <4 x i32> <i32 1, i32 2, i32 3, i32 4>
18531854
// CHECK-LE: shufflevector <4 x i32> %{{[0-9]+}}, <4 x i32> %{{[0-9]+}}, <4 x i32> <i32 7, i32 0, i32 1, i32 2>
1855+
1856+
res_vd = vec_promote(d, 0);
1857+
// CHECK: store <2 x double> zeroinitializer
1858+
// CHECK: insertelement <2 x double>
1859+
// CHECK-LE: store <2 x double> zeroinitializer
1860+
// CHECK-LE: insertelement <2 x double>
1861+
1862+
res_vsll = vec_promote(sll, 0);
1863+
// CHECK: store <2 x i64> zeroinitializer
1864+
// CHECK: insertelement <2 x i64>
1865+
// CHECK-LE: store <2 x i64> zeroinitializer
1866+
// CHECK-LE: insertelement <2 x i64>
1867+
1868+
res_vull = vec_promote(ull, 0);
1869+
// CHECK: store <2 x i64> zeroinitializer
1870+
// CHECK: insertelement <2 x i64>
1871+
// CHECK-LE: store <2 x i64> zeroinitializer
1872+
// CHECK-LE: insertelement <2 x i64>
18541873
}
18551874

18561875
// The return type of the call expression may be different from the return type of the shufflevector.

0 commit comments

Comments
 (0)