3 ms·
This is a reasonably good example (except it's binary to hex, not just BCD to hex), but it's from the start of the year and based on the already out of date ver
by brucehoult 6y ago
This is a reasonably good example (except it's binary to hex, not just BCD to hex), but it's from the start of the year and based on the already out of date version 0.8 draft spec.
A couple of things need to be changed to bring it up to date:
-vlbu.v v16, (a1)
+vle8.v v16, (a1)
+vzext.vf2 v16, v16
-vsb.v v24, (a0)
+vse8.v v24, (a0)
I'd also probably make (or at least compare the speed of) one more change:
-vrgather.vv v24, v8, v16
+vmsgtu.vi v0, v16, 9 # set mask-bit if >9
+vadd.vi v16, v16, '0' # add '0' to each element
+vadd.vi v16, v16, 'a'-0xA-'0', v0.t # masked add to correct A..F
That's basically the same code as he used to create the lookup table in v8 for the vrgather. I think it might run faster on many machines, and also the vrgather would fail on the smallest machines (with only 32 bits in each vector register) if anyone modified the code to not use m8 (LMUL=8).
For more explanation see my post at https://www.reddit.com/r/RISCV/comments/i5alno/programming_with_riscv_vector_instructions/g0p6rz0/ https://www.reddit.com/r/RISCV/comments/i5alno/programming_w...
[NB slight cheat -- those vadd.vi immediates are too big to fit .. you'd actually need to put them in integer registers and use vadd.vx, which can be set up outside the loop]