Skip to content

Commit

Permalink
Merge pull request #495 from howjmay/vqneg
Browse files Browse the repository at this point in the history
feat: Add vqneg[b|h|s|d]_[s8|s16|s32|s64]
  • Loading branch information
howjmay authored Jul 31, 2024
2 parents a34f81f + a953e83 commit 519b350
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 12 deletions.
32 changes: 28 additions & 4 deletions neon2rvv.h
Original file line number Diff line number Diff line change
Expand Up @@ -7197,13 +7197,37 @@ FORCE_INLINE int64x2_t vqnegq_s64(int64x2_t a) {
return __riscv_vmerge_vxm_i64m1(a_neg, INT64_MAX, min_mask, 2);
}

// FORCE_INLINE int8_t vqnegb_s8(int8_t a);
FORCE_INLINE int8_t vqnegb_s8(int8_t a) {
if (a == INT8_MIN) {
return INT8_MAX;
} else {
return -a;
}
}

// FORCE_INLINE int16_t vqnegh_s16(int16_t a);
FORCE_INLINE int16_t vqnegh_s16(int16_t a) {
if (a == INT16_MIN) {
return INT16_MAX;
} else {
return -a;
}
}

// FORCE_INLINE int32_t vqnegs_s32(int32_t a);
FORCE_INLINE int32_t vqnegs_s32(int32_t a) {
if (a == INT32_MIN) {
return INT32_MAX;
} else {
return -a;
}
}

// FORCE_INLINE int64_t vqnegd_s64(int64_t a);
FORCE_INLINE int64_t vqnegd_s64(int64_t a) {
if (a == INT64_MIN) {
return INT64_MAX;
} else {
return -a;
}
}

FORCE_INLINE int8x8_t vmvn_s8(int8x8_t a) { return __riscv_vnot_v_i8m1(a, 8); }

Expand Down
64 changes: 60 additions & 4 deletions tests/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25927,13 +25927,69 @@ result_t test_vqnegq_s64(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) {
#endif // ENABLE_TEST_ALL
}

result_t test_vqnegb_s8(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) { return TEST_UNIMPL; }
result_t test_vqnegb_s8(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) {
#ifdef ENABLE_TEST_ALL
int8_t *_a = (int8_t *)impl.test_cases_int_pointer1;
int8_t _c, c;
if (_a[0] == INT8_MIN) {
_c = INT8_MAX;
} else {
_c = -_a[0];
}
c = vqnegb_s8(_a[0]);
return c == _c ? TEST_SUCCESS : TEST_FAIL;
#else
return TEST_UNIMPL;
#endif // ENABLE_TEST_ALL
}

result_t test_vqnegh_s16(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) { return TEST_UNIMPL; }
result_t test_vqnegh_s16(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) {
#ifdef ENABLE_TEST_ALL
int16_t *_a = (int16_t *)impl.test_cases_int_pointer1;
int16_t _c, c;
if (_a[0] == INT16_MIN) {
_c = INT16_MAX;
} else {
_c = -_a[0];
}
c = vqnegh_s16(_a[0]);
return c == _c ? TEST_SUCCESS : TEST_FAIL;
#else
return TEST_UNIMPL;
#endif // ENABLE_TEST_ALL
}

result_t test_vqnegs_s32(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) { return TEST_UNIMPL; }
result_t test_vqnegs_s32(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) {
#ifdef ENABLE_TEST_ALL
int32_t *_a = (int32_t *)impl.test_cases_int_pointer1;
int32_t _c, c;
if (_a[0] == INT32_MIN) {
_c = INT32_MAX;
} else {
_c = -_a[0];
}
c = vqnegs_s32(_a[0]);
return c == _c ? TEST_SUCCESS : TEST_FAIL;
#else
return TEST_UNIMPL;
#endif // ENABLE_TEST_ALL
}

result_t test_vqnegd_s64(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) { return TEST_UNIMPL; }
result_t test_vqnegd_s64(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) {
#ifdef ENABLE_TEST_ALL
int64_t *_a = (int64_t *)impl.test_cases_int_pointer1;
int64_t _c, c;
if (_a[0] == INT64_MIN) {
_c = INT64_MAX;
} else {
_c = -_a[0];
}
c = vqnegd_s64(_a[0]);
return c == _c ? TEST_SUCCESS : TEST_FAIL;
#else
return TEST_UNIMPL;
#endif // ENABLE_TEST_ALL
}

result_t test_vmvn_s8(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) {
#ifdef ENABLE_TEST_ALL
Expand Down
8 changes: 4 additions & 4 deletions tests/impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1340,10 +1340,10 @@
_(vqnegq_s32) \
_(vqneg_s64) \
_(vqnegq_s64) \
/*_(vqnegb_s8) */ \
/*_(vqnegh_s16) */ \
/*_(vqnegs_s32) */ \
/*_(vqnegd_s64) */ \
_(vqnegb_s8) \
_(vqnegh_s16) \
_(vqnegs_s32) \
_(vqnegd_s64) \
_(vmvn_s8) \
_(vmvn_s16) \
_(vmvn_s32) \
Expand Down

0 comments on commit 519b350

Please sign in to comment.