blob: 58563cd7e405a2cfaa07ab36561507cc96df6dba [file] [log] [blame]
#ifndef SOFTRVV_VNSRL_H
#define SOFTRVV_VNSRL_H
#include <stddef.h>
#include <type_traits>
namespace softrvv {
template <typename T1, typename T2>
void vnsrl_vx(T1 *dest, T2 *src1, const T1 *src2, int32_t avl) {
// Only low lg2(SEW*2) bits are used for shift
static_assert(sizeof(T1) * 2 == sizeof(T2));
const T1 low_bits_mask = sizeof(T2) * 8 - 1;
const T1 shift = *src2 & low_bits_mask;
for (int32_t idx = 0; idx < avl; idx++) {
dest[idx] = static_cast<T1>(
static_cast<typename std::make_unsigned<T2>::type>(src1[idx]) >> shift);
}
}
template <typename T1, typename T2>
void vnsrl_vv(T1 *dest, T2 *src1, T1 *src2, int32_t avl) {
// // Only low lg2(SEW*2) bits are used for shift
static_assert(sizeof(T1) * 2 == sizeof(T2));
const T1 low_bits_mask = sizeof(T2) * 8 - 1;
for (int32_t idx = 0; idx < avl; idx++) {
dest[idx] = static_cast<T1>(
static_cast<typename std::make_unsigned<T2>::type>(src1[idx])
>> (src2[idx] & low_bits_mask));
}
}
} // namespace softrvv
#endif // SOFTRVV_VNSRL_H