Skip to content

Commit 463e3ee

Browse files
committed
Update gemmini_params.h
1 parent 623ab6e commit 463e3ee

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

include/gemmini_params.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ typedef uint32_t acc_scale_t_bits;
5959
i % 2 == 0 ? i : next)); \
6060
result; })
6161

62+
// Rounding right shift equation: https://riscv.github.io/documents/riscv-v-spec/#_vector_fixed_point_rounding_mode_register_vxrm
63+
#define ROUNDING_RIGHT_SHIFT_BITS(x, shift) \
64+
((shift) > 0 ? (((x) >> (shift)) + \
65+
(((shift) == 0 ? 0 : (((x) >> ((shift)-1)) & 1)) & \
66+
((((shift) <= 1 ? 0 : ((x) & ((1 << ((shift)-1)) - 1))) != 0) | (((x) >> (shift)) & 1)))) : ((x) << (-(shift))))
67+
6268
#define ACC_SCALE(x, scale) \
6369
({float y = ROUND_NEAR_EVEN((x) * (scale)); y > INT8_MAX ? INT8_MAX : (y < INT8_MIN ? INT8_MIN : (acc_t)y);})
6470

0 commit comments

Comments
 (0)