[VSX] correct lshiftbyte_m128/rshiftbyte_m128, variable_byte_shift

This commit is contained in:
Konstantinos Margaritis 2022-09-06 23:39:44 +03:00
parent 17467ff21b
commit 94fe406f0c
2 changed files with 56 additions and 8 deletions

View File

@ -285,7 +285,6 @@ m128 loadbytes128(const void *ptr, unsigned int n) {
return a;
}
#define CASE_ALIGN_VECTORS(a, b, offset) case offset: return (m128)vec_sld((int8x16_t)(b), (int8x16_t)(a), (16 - offset)); break;
static really_really_inline
@ -326,21 +325,21 @@ m128 palignr(m128 r, m128 l, int offset) {
static really_really_inline
m128 rshiftbyte_m128(m128 a, unsigned b) {
return rshift_m128(a,b);
return palignr_imm(zeroes128(), a, b);
}
static really_really_inline
m128 lshiftbyte_m128(m128 a, unsigned b) {
return lshift_m128(a,b);
return palignr_imm(a, zeroes128(), 16 - b);
}
static really_inline
m128 variable_byte_shift_m128(m128 in, s32 amount) {
assert(amount >= -16 && amount <= 16);
if (amount < 0){
return palignr_imm(zeroes128(), in, -amount);
} else{
return palignr_imm(in, zeroes128(), 16 - amount);
if (amount < 0) {
return rshiftbyte_m128(in, -amount);
} else {
return lshiftbyte_m128(in, amount);
}
}

View File

@ -723,10 +723,59 @@ TEST(SimdUtilsTest, set2x128) {
}
#endif
#define TEST_LSHIFTBYTE128(v1, buf, l) { \
m128 v_shifted = lshiftbyte_m128(v1, l); \
storeu128(res, v_shifted); \
int i; \
for (i=0; i < l; i++) { \
assert(res[i] == 0); \
} \
for (; i < 16; i++) { \
assert(res[i] == vec[i - l]); \
} \
}
TEST(SimdUtilsTest, lshiftbyte128){
u8 vec[16];
u8 res[16];
for (int i=0; i<16; i++) {
vec[i]=i;
}
m128 v1 = loadu128(vec);
for (int j = 0; j<16; j++){
TEST_LSHIFTBYTE128(v1, vec, j);
}
}
#define TEST_RSHIFTBYTE128(v1, buf, l) { \
m128 v_shifted = rshiftbyte_m128(v1, l); \
storeu128(res, v_shifted); \
int i; \
for (i=15; i >= 16 - l; i--) { \
assert(res[i] == 0); \
} \
for (; i >= 0; i--) { \
assert(res[i] == vec[i + l]); \
} \
}
TEST(SimdUtilsTest, rshiftbyte128){
u8 vec[16];
u8 res[16];
for (int i=0; i<16; i++) {
vec[i]=i;
}
m128 v1 = loadu128(vec);
for (int j = 0; j<16; j++){
TEST_RSHIFTBYTE128(v1, vec, j);
}
}
TEST(SimdUtilsTest, variableByteShift128) {
char base[] = "0123456789ABCDEF";
m128 in = loadu128(base);
EXPECT_TRUE(!diff128(rshiftbyte_m128(in, 0),
variable_byte_shift_m128(in, 0)));
EXPECT_TRUE(!diff128(rshiftbyte_m128(in, 1),
@ -773,7 +822,7 @@ TEST(SimdUtilsTest, variableByteShift128) {
EXPECT_TRUE(!diff128(lshiftbyte_m128(in, 10),
variable_byte_shift_m128(in, 10)));
EXPECT_TRUE(!diff128(zeroes128(), variable_byte_shift_m128(in, 16)));
EXPECT_TRUE(!diff128(lshiftbyte_m128(in, 15), variable_byte_shift_m128(in, 15)));
EXPECT_TRUE(!diff128(zeroes128(), variable_byte_shift_m128(in, -16)));
}