Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add vqshl[b|h|s|d]_n_[s8|s16|s32|s64|u8|u16|u32|u64] #444

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions neon2rvv.h
Original file line number Diff line number Diff line change
Expand Up @@ -6270,21 +6270,38 @@ FORCE_INLINE uint64x2_t vqshlq_n_u64(uint64x2_t a, const int b) {
return __riscv_vmerge_vxm_u64m1(shl, UINT64_MAX, mask_sat_positive, 2);
}

// FORCE_INLINE int8_t vqshlb_n_s8(int8_t a, const int n);
FORCE_INLINE int8_t vqshlb_n_s8(int8_t a, const int n) { return neon2rvv_saturate_int8(a << n); }

// FORCE_INLINE int16_t vqshlh_n_s16(int16_t a, const int n);
FORCE_INLINE int16_t vqshlh_n_s16(int16_t a, const int n) { return neon2rvv_saturate_int16(a << n); }

// FORCE_INLINE int32_t vqshls_n_s32(int32_t a, const int n);
FORCE_INLINE int32_t vqshls_n_s32(int32_t a, const int n) { return neon2rvv_saturate_int32((int64_t)a << n); }

// FORCE_INLINE int64_t vqshld_n_s64(int64_t a, const int n);
FORCE_INLINE int64_t vqshld_n_s64(int64_t a, const int n) {
if (a > 0) {
if (a > (INT64_MAX >> n)) {
return INT64_MAX;
} else {
return a << n;
}
}
if (a < (INT64_MIN >> n)) {
return INT64_MIN;
}
return a << n;
}

// FORCE_INLINE uint8_t vqshlb_n_u8(uint8_t a, const int n);
FORCE_INLINE uint8_t vqshlb_n_u8(uint8_t a, const int n) { return neon2rvv_saturate_uint8(a << n); }

// FORCE_INLINE uint16_t vqshlh_n_u16(uint16_t a, const int n);
FORCE_INLINE uint16_t vqshlh_n_u16(uint16_t a, const int n) { return neon2rvv_saturate_uint16(a << n); }

// FORCE_INLINE uint32_t vqshls_n_u32(uint32_t a, const int n);
FORCE_INLINE uint32_t vqshls_n_u32(uint32_t a, const int n) { return neon2rvv_saturate_uint32((uint64_t)a << n); }

// FORCE_INLINE uint64_t vqshld_n_u64(uint64_t a, const int n);
FORCE_INLINE uint64_t vqshld_n_u64(uint64_t a, const int n) {
if (a > (UINT64_MAX >> n)) {
return UINT64_MAX;
}
return a << n;
}

FORCE_INLINE uint8x8_t vqshlu_n_s8(int8x8_t a, const int b) {
vint8m1_t a_non_neg = __riscv_vmax_vx_i8m1(a, 0, 8);
Expand Down
168 changes: 160 additions & 8 deletions tests/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21890,21 +21890,173 @@ result_t test_vqshlq_n_u64(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) {
#endif // ENABLE_TEST_ALL
}

result_t test_vqshlb_n_s8(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) { return TEST_UNIMPL; }
result_t test_vqshlb_n_s8(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) {
#ifdef ENABLE_TEST_ALL
const int8_t *_a = (const int8_t *)impl.test_cases_int_pointer1;
int8_t _c, c;

#define TEST_IMPL(IDX) \
_c = saturate_int8(_a[0] << IDX); \
c = vqshlb_n_s8(_a[0], IDX); \
CHECK_RESULT(c == _c ? TEST_SUCCESS : TEST_FAIL)

IMM_8_ITER
#undef TEST_IMPL

return TEST_SUCCESS;
#else
return TEST_UNIMPL;
#endif
}

result_t test_vqshlh_n_s16(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) {
#ifdef ENABLE_TEST_ALL
const int16_t *_a = (const int16_t *)impl.test_cases_int_pointer1;
int16_t _c, c;

#define TEST_IMPL(IDX) \
_c = saturate_int16(_a[0] << IDX); \
c = vqshlh_n_s16(_a[0], IDX); \
CHECK_RESULT(c == _c ? TEST_SUCCESS : TEST_FAIL)

IMM_16_ITER
#undef TEST_IMPL

return TEST_SUCCESS;
#else
return TEST_UNIMPL;
#endif // ENABLE_TEST_ALL
}

result_t test_vqshls_n_s32(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) {
#ifdef ENABLE_TEST_ALL
const int32_t *_a = (const int32_t *)impl.test_cases_int_pointer1;
int32_t _c, c;

#define TEST_IMPL(IDX) \
_c = saturate_int32((int64_t)_a[0] << IDX); \
c = vqshls_n_s32(_a[0], IDX); \
CHECK_RESULT(c == _c ? TEST_SUCCESS : TEST_FAIL)

IMM_32_ITER
#undef TEST_IMPL

return TEST_SUCCESS;
#else
return TEST_UNIMPL;
#endif // ENABLE_TEST_ALL
}

result_t test_vqshld_n_s64(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) {
#ifdef ENABLE_TEST_ALL
const int64_t *_a = (const int64_t *)impl.test_cases_int_pointer1;
int64_t _c, c;

#define TEST_IMPL(IDX) \
if (_a[0] > 0) { \
if (_a[0] > (INT64_MAX >> IDX)) { \
_c = INT64_MAX; \
} else { \
_c = _a[0] << IDX; \
} \
} else { \
if (_a[0] < (INT64_MIN >> IDX)) { \
_c = INT64_MIN; \
} else { \
_c = _a[0] << IDX; \
} \
} \
c = vqshld_n_s64(_a[0], IDX); \
CHECK_RESULT(c == _c ? TEST_SUCCESS : TEST_FAIL)

IMM_64_ITER
#undef TEST_IMPL

return TEST_SUCCESS;
#else
return TEST_UNIMPL;
#endif // ENABLE_TEST_ALL
}

result_t test_vqshlb_n_u8(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) {
#ifdef ENABLE_TEST_ALL
const uint8_t *_a = (const uint8_t *)impl.test_cases_int_pointer1;
uint8_t _c, c;

#define TEST_IMPL(IDX) \
_c = saturate_uint8(_a[0] << IDX); \
c = vqshlb_n_u8(_a[0], IDX); \
CHECK_RESULT(c == _c ? TEST_SUCCESS : TEST_FAIL)

result_t test_vqshlh_n_s16(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) { return TEST_UNIMPL; }
IMM_8_ITER
#undef TEST_IMPL

result_t test_vqshls_n_s32(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) { return TEST_UNIMPL; }
return TEST_SUCCESS;
#else
return TEST_UNIMPL;
#endif
}

result_t test_vqshld_n_s64(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) { return TEST_UNIMPL; }
result_t test_vqshlh_n_u16(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) {
#ifdef ENABLE_TEST_ALL
const uint16_t *_a = (const uint16_t *)impl.test_cases_int_pointer1;
uint16_t _c, c;

result_t test_vqshlb_n_u8(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) { return TEST_UNIMPL; }
#define TEST_IMPL(IDX) \
_c = saturate_uint16(_a[0] << IDX); \
c = vqshlh_n_u16(_a[0], IDX); \
CHECK_RESULT(c == _c ? TEST_SUCCESS : TEST_FAIL)

result_t test_vqshlh_n_u16(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) { return TEST_UNIMPL; }
IMM_16_ITER
#undef TEST_IMPL

result_t test_vqshls_n_u32(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) { return TEST_UNIMPL; }
return TEST_SUCCESS;
#else
return TEST_UNIMPL;
#endif // ENABLE_TEST_ALL
}

result_t test_vqshld_n_u64(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) { return TEST_UNIMPL; }
result_t test_vqshls_n_u32(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) {
#ifdef ENABLE_TEST_ALL
const uint32_t *_a = (const uint32_t *)impl.test_cases_int_pointer1;
uint32_t _c, c;

#define TEST_IMPL(IDX) \
_c = saturate_uint32((int64_t)_a[0] << IDX); \
c = vqshls_n_u32(_a[0], IDX); \
CHECK_RESULT(c == _c ? TEST_SUCCESS : TEST_FAIL)

IMM_32_ITER
#undef TEST_IMPL

return TEST_SUCCESS;
#else
return TEST_UNIMPL;
#endif // ENABLE_TEST_ALL
}

result_t test_vqshld_n_u64(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) {
#ifdef ENABLE_TEST_ALL
const uint64_t *_a = (const uint64_t *)impl.test_cases_int_pointer1;
uint64_t _c, c;

#define TEST_IMPL(IDX) \
if (_a[0] > (UINT64_MAX >> IDX)) { \
_c = UINT64_MAX; \
} else { \
_c = _a[0] << IDX; \
} \
c = vqshld_n_u64(_a[0], IDX); \
CHECK_RESULT(c == _c ? TEST_SUCCESS : TEST_FAIL)

IMM_64_ITER
#undef TEST_IMPL

return TEST_SUCCESS;
#else
return TEST_UNIMPL;
#endif // ENABLE_TEST_ALL
}

result_t test_vqshlu_n_s8(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) {
#ifdef ENABLE_TEST_ALL
Expand Down
16 changes: 8 additions & 8 deletions tests/impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1203,14 +1203,14 @@
_(vqshlq_n_u16) \
_(vqshlq_n_u32) \
_(vqshlq_n_u64) \
/*_(vqshlb_n_s8) */ \
/*_(vqshlh_n_s16) */ \
/*_(vqshls_n_s32) */ \
/*_(vqshld_n_s64) */ \
/*_(vqshlb_n_u8) */ \
/*_(vqshlh_n_u16) */ \
/*_(vqshls_n_u32) */ \
/*_(vqshld_n_u64) */ \
_(vqshlb_n_s8) \
_(vqshlh_n_s16) \
_(vqshls_n_s32) \
_(vqshld_n_s64) \
_(vqshlb_n_u8) \
_(vqshlh_n_u16) \
_(vqshls_n_u32) \
_(vqshld_n_u64) \
_(vqshlu_n_s8) \
_(vqshlu_n_s16) \
_(vqshlu_n_s32) \
Expand Down
Loading