riscv-non-isa / rvv-intrinsic-doc

https://jira.riscv.org/browse/RVG-153
BSD 3-Clause "New" or "Revised" License
281 stars 89 forks source link

Question about Reinterpret Cast Conversion Functions #270

Closed rvvstuding closed 11 months ago

rvvstuding commented 12 months ago

Hi everyone, As far as I know about reinterpret Intrinsics, they can reinterpret vector between different type under the same SEW/LMUL, or between different SEW under the same LMUL.

  1. I don't see the reinterpret between float type to different SEW float type, such as vfloat16m1_t to vfloat32m1_t
  2. If I want to reinterpret vint8m1_tto vuint16m1_t, I can be achieved by using __riscv_vreinterpret_v_i16m1_u16m1(__riscv_vreinterpret_v_i8m1_i16m1(a)). If this is right, How do I reinterpret vfloat16m1_tto vint8m1_t? Thanks!
dzaima commented 12 months ago

f16i8 can be __riscv_vreinterpret_v_i16m1_i8m1(__riscv_vreinterpret_v_f16m1_i16m1(x)).

f16f32 is a more unwieldy __riscv_vreinterpret_v_u32m1_f32m1(__riscv_vreinterpret_v_u16m1_u32m1(__riscv_vreinterpret_v_f16m1_u16m1(x))), but given that there's not much use for it, I think it's fine.

fwiw, here's some (auto-generated) code for all int/float LMUL=1 reinterprets:

code ```c // vint8m1_t -> vint16m1_t vint16m1_t dst = __riscv_vreinterpret_v_i8m1_i16m1(src); // vint8m1_t -> vint32m1_t vint32m1_t dst = __riscv_vreinterpret_v_i8m1_i32m1(src); // vint8m1_t -> vint64m1_t vint64m1_t dst = __riscv_vreinterpret_v_i8m1_i64m1(src); // vint8m1_t -> vuint8m1_t vuint8m1_t dst = __riscv_vreinterpret_v_i8m1_u8m1(src); // vint8m1_t -> vuint16m1_t vuint8m1_t v14 = __riscv_vreinterpret_v_i8m1_u8m1(src); vuint16m1_t dst = __riscv_vreinterpret_v_u8m1_u16m1(v14); // vint8m1_t -> vuint32m1_t vuint8m1_t v18 = __riscv_vreinterpret_v_i8m1_u8m1(src); vuint32m1_t dst = __riscv_vreinterpret_v_u8m1_u32m1(v18); // vint8m1_t -> vuint64m1_t vuint8m1_t v22 = __riscv_vreinterpret_v_i8m1_u8m1(src); vuint64m1_t dst = __riscv_vreinterpret_v_u8m1_u64m1(v22); // vint8m1_t -> vfloat16m1_t vint16m1_t v26 = __riscv_vreinterpret_v_i8m1_i16m1(src); vfloat16m1_t dst = __riscv_vreinterpret_v_i16m1_f16m1(v26); // vint8m1_t -> vfloat32m1_t vint32m1_t v30 = __riscv_vreinterpret_v_i8m1_i32m1(src); vfloat32m1_t dst = __riscv_vreinterpret_v_i32m1_f32m1(v30); // vint8m1_t -> vfloat64m1_t vint64m1_t v34 = __riscv_vreinterpret_v_i8m1_i64m1(src); vfloat64m1_t dst = __riscv_vreinterpret_v_i64m1_f64m1(v34); // vint16m1_t -> vint8m1_t vint8m1_t dst = __riscv_vreinterpret_v_i16m1_i8m1(src); // vint16m1_t -> vint32m1_t vint32m1_t dst = __riscv_vreinterpret_v_i16m1_i32m1(src); // vint16m1_t -> vint64m1_t vint64m1_t dst = __riscv_vreinterpret_v_i16m1_i64m1(src); // vint16m1_t -> vuint8m1_t vuint16m1_t v47 = __riscv_vreinterpret_v_i16m1_u16m1(src); vuint8m1_t dst = __riscv_vreinterpret_v_u16m1_u8m1(v47); // vint16m1_t -> vuint16m1_t vuint16m1_t dst = __riscv_vreinterpret_v_i16m1_u16m1(src); // vint16m1_t -> vuint32m1_t vuint16m1_t v54 = __riscv_vreinterpret_v_i16m1_u16m1(src); vuint32m1_t dst = __riscv_vreinterpret_v_u16m1_u32m1(v54); // vint16m1_t -> vuint64m1_t vuint16m1_t v58 = __riscv_vreinterpret_v_i16m1_u16m1(src); vuint64m1_t dst = __riscv_vreinterpret_v_u16m1_u64m1(v58); // vint16m1_t -> vfloat16m1_t vfloat16m1_t dst = __riscv_vreinterpret_v_i16m1_f16m1(src); // vint16m1_t -> vfloat32m1_t vint32m1_t v65 = __riscv_vreinterpret_v_i16m1_i32m1(src); vfloat32m1_t dst = __riscv_vreinterpret_v_i32m1_f32m1(v65); // vint16m1_t -> vfloat64m1_t vint64m1_t v69 = __riscv_vreinterpret_v_i16m1_i64m1(src); vfloat64m1_t dst = __riscv_vreinterpret_v_i64m1_f64m1(v69); // vint32m1_t -> vint8m1_t vint8m1_t dst = __riscv_vreinterpret_v_i32m1_i8m1(src); // vint32m1_t -> vint16m1_t vint16m1_t dst = __riscv_vreinterpret_v_i32m1_i16m1(src); // vint32m1_t -> vint64m1_t vint64m1_t dst = __riscv_vreinterpret_v_i32m1_i64m1(src); // vint32m1_t -> vuint8m1_t vuint32m1_t v82 = __riscv_vreinterpret_v_i32m1_u32m1(src); vuint8m1_t dst = __riscv_vreinterpret_v_u32m1_u8m1(v82); // vint32m1_t -> vuint16m1_t vuint32m1_t v86 = __riscv_vreinterpret_v_i32m1_u32m1(src); vuint16m1_t dst = __riscv_vreinterpret_v_u32m1_u16m1(v86); // vint32m1_t -> vuint32m1_t vuint32m1_t dst = __riscv_vreinterpret_v_i32m1_u32m1(src); // vint32m1_t -> vuint64m1_t vuint32m1_t v93 = __riscv_vreinterpret_v_i32m1_u32m1(src); vuint64m1_t dst = __riscv_vreinterpret_v_u32m1_u64m1(v93); // vint32m1_t -> vfloat16m1_t vint16m1_t v97 = __riscv_vreinterpret_v_i32m1_i16m1(src); vfloat16m1_t dst = __riscv_vreinterpret_v_i16m1_f16m1(v97); // vint32m1_t -> vfloat32m1_t vfloat32m1_t dst = __riscv_vreinterpret_v_i32m1_f32m1(src); // vint32m1_t -> vfloat64m1_t vint64m1_t v104 = __riscv_vreinterpret_v_i32m1_i64m1(src); vfloat64m1_t dst = __riscv_vreinterpret_v_i64m1_f64m1(v104); // vint64m1_t -> vint8m1_t vint8m1_t dst = __riscv_vreinterpret_v_i64m1_i8m1(src); // vint64m1_t -> vint16m1_t vint16m1_t dst = __riscv_vreinterpret_v_i64m1_i16m1(src); // vint64m1_t -> vint32m1_t vint32m1_t dst = __riscv_vreinterpret_v_i64m1_i32m1(src); // vint64m1_t -> vuint8m1_t vuint64m1_t v117 = __riscv_vreinterpret_v_i64m1_u64m1(src); vuint8m1_t dst = __riscv_vreinterpret_v_u64m1_u8m1(v117); // vint64m1_t -> vuint16m1_t vuint64m1_t v121 = __riscv_vreinterpret_v_i64m1_u64m1(src); vuint16m1_t dst = __riscv_vreinterpret_v_u64m1_u16m1(v121); // vint64m1_t -> vuint32m1_t vuint64m1_t v125 = __riscv_vreinterpret_v_i64m1_u64m1(src); vuint32m1_t dst = __riscv_vreinterpret_v_u64m1_u32m1(v125); // vint64m1_t -> vuint64m1_t vuint64m1_t dst = __riscv_vreinterpret_v_i64m1_u64m1(src); // vint64m1_t -> vfloat16m1_t vint16m1_t v132 = __riscv_vreinterpret_v_i64m1_i16m1(src); vfloat16m1_t dst = __riscv_vreinterpret_v_i16m1_f16m1(v132); // vint64m1_t -> vfloat32m1_t vint32m1_t v136 = __riscv_vreinterpret_v_i64m1_i32m1(src); vfloat32m1_t dst = __riscv_vreinterpret_v_i32m1_f32m1(v136); // vint64m1_t -> vfloat64m1_t vfloat64m1_t dst = __riscv_vreinterpret_v_i64m1_f64m1(src); // vuint8m1_t -> vint8m1_t vint8m1_t dst = __riscv_vreinterpret_v_u8m1_i8m1(src); // vuint8m1_t -> vint16m1_t vint8m1_t v146 = __riscv_vreinterpret_v_u8m1_i8m1(src); vint16m1_t dst = __riscv_vreinterpret_v_i8m1_i16m1(v146); // vuint8m1_t -> vint32m1_t vint8m1_t v150 = __riscv_vreinterpret_v_u8m1_i8m1(src); vint32m1_t dst = __riscv_vreinterpret_v_i8m1_i32m1(v150); // vuint8m1_t -> vint64m1_t vint8m1_t v154 = __riscv_vreinterpret_v_u8m1_i8m1(src); vint64m1_t dst = __riscv_vreinterpret_v_i8m1_i64m1(v154); // vuint8m1_t -> vuint16m1_t vuint16m1_t dst = __riscv_vreinterpret_v_u8m1_u16m1(src); // vuint8m1_t -> vuint32m1_t vuint32m1_t dst = __riscv_vreinterpret_v_u8m1_u32m1(src); // vuint8m1_t -> vuint64m1_t vuint64m1_t dst = __riscv_vreinterpret_v_u8m1_u64m1(src); // vuint8m1_t -> vfloat16m1_t vuint16m1_t v167 = __riscv_vreinterpret_v_u8m1_u16m1(src); vfloat16m1_t dst = __riscv_vreinterpret_v_u16m1_f16m1(v167); // vuint8m1_t -> vfloat32m1_t vuint32m1_t v171 = __riscv_vreinterpret_v_u8m1_u32m1(src); vfloat32m1_t dst = __riscv_vreinterpret_v_u32m1_f32m1(v171); // vuint8m1_t -> vfloat64m1_t vuint64m1_t v175 = __riscv_vreinterpret_v_u8m1_u64m1(src); vfloat64m1_t dst = __riscv_vreinterpret_v_u64m1_f64m1(v175); // vuint16m1_t -> vint8m1_t vint16m1_t v179 = __riscv_vreinterpret_v_u16m1_i16m1(src); vint8m1_t dst = __riscv_vreinterpret_v_i16m1_i8m1(v179); // vuint16m1_t -> vint16m1_t vint16m1_t dst = __riscv_vreinterpret_v_u16m1_i16m1(src); // vuint16m1_t -> vint32m1_t vint16m1_t v186 = __riscv_vreinterpret_v_u16m1_i16m1(src); vint32m1_t dst = __riscv_vreinterpret_v_i16m1_i32m1(v186); // vuint16m1_t -> vint64m1_t vint16m1_t v190 = __riscv_vreinterpret_v_u16m1_i16m1(src); vint64m1_t dst = __riscv_vreinterpret_v_i16m1_i64m1(v190); // vuint16m1_t -> vuint8m1_t vuint8m1_t dst = __riscv_vreinterpret_v_u16m1_u8m1(src); // vuint16m1_t -> vuint32m1_t vuint32m1_t dst = __riscv_vreinterpret_v_u16m1_u32m1(src); // vuint16m1_t -> vuint64m1_t vuint64m1_t dst = __riscv_vreinterpret_v_u16m1_u64m1(src); // vuint16m1_t -> vfloat16m1_t vfloat16m1_t dst = __riscv_vreinterpret_v_u16m1_f16m1(src); // vuint16m1_t -> vfloat32m1_t vuint32m1_t v206 = __riscv_vreinterpret_v_u16m1_u32m1(src); vfloat32m1_t dst = __riscv_vreinterpret_v_u32m1_f32m1(v206); // vuint16m1_t -> vfloat64m1_t vuint64m1_t v210 = __riscv_vreinterpret_v_u16m1_u64m1(src); vfloat64m1_t dst = __riscv_vreinterpret_v_u64m1_f64m1(v210); // vuint32m1_t -> vint8m1_t vint32m1_t v214 = __riscv_vreinterpret_v_u32m1_i32m1(src); vint8m1_t dst = __riscv_vreinterpret_v_i32m1_i8m1(v214); // vuint32m1_t -> vint16m1_t vint32m1_t v218 = __riscv_vreinterpret_v_u32m1_i32m1(src); vint16m1_t dst = __riscv_vreinterpret_v_i32m1_i16m1(v218); // vuint32m1_t -> vint32m1_t vint32m1_t dst = __riscv_vreinterpret_v_u32m1_i32m1(src); // vuint32m1_t -> vint64m1_t vint32m1_t v225 = __riscv_vreinterpret_v_u32m1_i32m1(src); vint64m1_t dst = __riscv_vreinterpret_v_i32m1_i64m1(v225); // vuint32m1_t -> vuint8m1_t vuint8m1_t dst = __riscv_vreinterpret_v_u32m1_u8m1(src); // vuint32m1_t -> vuint16m1_t vuint16m1_t dst = __riscv_vreinterpret_v_u32m1_u16m1(src); // vuint32m1_t -> vuint64m1_t vuint64m1_t dst = __riscv_vreinterpret_v_u32m1_u64m1(src); // vuint32m1_t -> vfloat16m1_t vuint16m1_t v238 = __riscv_vreinterpret_v_u32m1_u16m1(src); vfloat16m1_t dst = __riscv_vreinterpret_v_u16m1_f16m1(v238); // vuint32m1_t -> vfloat32m1_t vfloat32m1_t dst = __riscv_vreinterpret_v_u32m1_f32m1(src); // vuint32m1_t -> vfloat64m1_t vuint64m1_t v245 = __riscv_vreinterpret_v_u32m1_u64m1(src); vfloat64m1_t dst = __riscv_vreinterpret_v_u64m1_f64m1(v245); // vuint64m1_t -> vint8m1_t vint64m1_t v249 = __riscv_vreinterpret_v_u64m1_i64m1(src); vint8m1_t dst = __riscv_vreinterpret_v_i64m1_i8m1(v249); // vuint64m1_t -> vint16m1_t vint64m1_t v253 = __riscv_vreinterpret_v_u64m1_i64m1(src); vint16m1_t dst = __riscv_vreinterpret_v_i64m1_i16m1(v253); // vuint64m1_t -> vint32m1_t vint64m1_t v257 = __riscv_vreinterpret_v_u64m1_i64m1(src); vint32m1_t dst = __riscv_vreinterpret_v_i64m1_i32m1(v257); // vuint64m1_t -> vint64m1_t vint64m1_t dst = __riscv_vreinterpret_v_u64m1_i64m1(src); // vuint64m1_t -> vuint8m1_t vuint8m1_t dst = __riscv_vreinterpret_v_u64m1_u8m1(src); // vuint64m1_t -> vuint16m1_t vuint16m1_t dst = __riscv_vreinterpret_v_u64m1_u16m1(src); // vuint64m1_t -> vuint32m1_t vuint32m1_t dst = __riscv_vreinterpret_v_u64m1_u32m1(src); // vuint64m1_t -> vfloat16m1_t vuint16m1_t v273 = __riscv_vreinterpret_v_u64m1_u16m1(src); vfloat16m1_t dst = __riscv_vreinterpret_v_u16m1_f16m1(v273); // vuint64m1_t -> vfloat32m1_t vuint32m1_t v277 = __riscv_vreinterpret_v_u64m1_u32m1(src); vfloat32m1_t dst = __riscv_vreinterpret_v_u32m1_f32m1(v277); // vuint64m1_t -> vfloat64m1_t vfloat64m1_t dst = __riscv_vreinterpret_v_u64m1_f64m1(src); // vfloat16m1_t -> vint8m1_t vint16m1_t v284 = __riscv_vreinterpret_v_f16m1_i16m1(src); vint8m1_t dst = __riscv_vreinterpret_v_i16m1_i8m1(v284); // vfloat16m1_t -> vint16m1_t vint16m1_t dst = __riscv_vreinterpret_v_f16m1_i16m1(src); // vfloat16m1_t -> vint32m1_t vint16m1_t v291 = __riscv_vreinterpret_v_f16m1_i16m1(src); vint32m1_t dst = __riscv_vreinterpret_v_i16m1_i32m1(v291); // vfloat16m1_t -> vint64m1_t vint16m1_t v295 = __riscv_vreinterpret_v_f16m1_i16m1(src); vint64m1_t dst = __riscv_vreinterpret_v_i16m1_i64m1(v295); // vfloat16m1_t -> vuint8m1_t vuint16m1_t v299 = __riscv_vreinterpret_v_f16m1_u16m1(src); vuint8m1_t dst = __riscv_vreinterpret_v_u16m1_u8m1(v299); // vfloat16m1_t -> vuint16m1_t vuint16m1_t dst = __riscv_vreinterpret_v_f16m1_u16m1(src); // vfloat16m1_t -> vuint32m1_t vuint16m1_t v306 = __riscv_vreinterpret_v_f16m1_u16m1(src); vuint32m1_t dst = __riscv_vreinterpret_v_u16m1_u32m1(v306); // vfloat16m1_t -> vuint64m1_t vuint16m1_t v310 = __riscv_vreinterpret_v_f16m1_u16m1(src); vuint64m1_t dst = __riscv_vreinterpret_v_u16m1_u64m1(v310); // vfloat16m1_t -> vfloat32m1_t vuint16m1_t v314 = __riscv_vreinterpret_v_f16m1_u16m1(src); vuint32m1_t v315 = __riscv_vreinterpret_v_u16m1_u32m1(v314); vfloat32m1_t dst = __riscv_vreinterpret_v_u32m1_f32m1(v315); // vfloat16m1_t -> vfloat64m1_t vuint16m1_t v319 = __riscv_vreinterpret_v_f16m1_u16m1(src); vuint64m1_t v320 = __riscv_vreinterpret_v_u16m1_u64m1(v319); vfloat64m1_t dst = __riscv_vreinterpret_v_u64m1_f64m1(v320); // vfloat32m1_t -> vint8m1_t vint32m1_t v324 = __riscv_vreinterpret_v_f32m1_i32m1(src); vint8m1_t dst = __riscv_vreinterpret_v_i32m1_i8m1(v324); // vfloat32m1_t -> vint16m1_t vint32m1_t v328 = __riscv_vreinterpret_v_f32m1_i32m1(src); vint16m1_t dst = __riscv_vreinterpret_v_i32m1_i16m1(v328); // vfloat32m1_t -> vint32m1_t vint32m1_t dst = __riscv_vreinterpret_v_f32m1_i32m1(src); // vfloat32m1_t -> vint64m1_t vint32m1_t v335 = __riscv_vreinterpret_v_f32m1_i32m1(src); vint64m1_t dst = __riscv_vreinterpret_v_i32m1_i64m1(v335); // vfloat32m1_t -> vuint8m1_t vuint32m1_t v339 = __riscv_vreinterpret_v_f32m1_u32m1(src); vuint8m1_t dst = __riscv_vreinterpret_v_u32m1_u8m1(v339); // vfloat32m1_t -> vuint16m1_t vuint32m1_t v343 = __riscv_vreinterpret_v_f32m1_u32m1(src); vuint16m1_t dst = __riscv_vreinterpret_v_u32m1_u16m1(v343); // vfloat32m1_t -> vuint32m1_t vuint32m1_t dst = __riscv_vreinterpret_v_f32m1_u32m1(src); // vfloat32m1_t -> vuint64m1_t vuint32m1_t v350 = __riscv_vreinterpret_v_f32m1_u32m1(src); vuint64m1_t dst = __riscv_vreinterpret_v_u32m1_u64m1(v350); // vfloat32m1_t -> vfloat16m1_t vuint32m1_t v354 = __riscv_vreinterpret_v_f32m1_u32m1(src); vuint16m1_t v355 = __riscv_vreinterpret_v_u32m1_u16m1(v354); vfloat16m1_t dst = __riscv_vreinterpret_v_u16m1_f16m1(v355); // vfloat32m1_t -> vfloat64m1_t vuint32m1_t v359 = __riscv_vreinterpret_v_f32m1_u32m1(src); vuint64m1_t v360 = __riscv_vreinterpret_v_u32m1_u64m1(v359); vfloat64m1_t dst = __riscv_vreinterpret_v_u64m1_f64m1(v360); // vfloat64m1_t -> vint8m1_t vint64m1_t v364 = __riscv_vreinterpret_v_f64m1_i64m1(src); vint8m1_t dst = __riscv_vreinterpret_v_i64m1_i8m1(v364); // vfloat64m1_t -> vint16m1_t vint64m1_t v368 = __riscv_vreinterpret_v_f64m1_i64m1(src); vint16m1_t dst = __riscv_vreinterpret_v_i64m1_i16m1(v368); // vfloat64m1_t -> vint32m1_t vint64m1_t v372 = __riscv_vreinterpret_v_f64m1_i64m1(src); vint32m1_t dst = __riscv_vreinterpret_v_i64m1_i32m1(v372); // vfloat64m1_t -> vint64m1_t vint64m1_t dst = __riscv_vreinterpret_v_f64m1_i64m1(src); // vfloat64m1_t -> vuint8m1_t vuint64m1_t v379 = __riscv_vreinterpret_v_f64m1_u64m1(src); vuint8m1_t dst = __riscv_vreinterpret_v_u64m1_u8m1(v379); // vfloat64m1_t -> vuint16m1_t vuint64m1_t v383 = __riscv_vreinterpret_v_f64m1_u64m1(src); vuint16m1_t dst = __riscv_vreinterpret_v_u64m1_u16m1(v383); // vfloat64m1_t -> vuint32m1_t vuint64m1_t v387 = __riscv_vreinterpret_v_f64m1_u64m1(src); vuint32m1_t dst = __riscv_vreinterpret_v_u64m1_u32m1(v387); // vfloat64m1_t -> vuint64m1_t vuint64m1_t dst = __riscv_vreinterpret_v_f64m1_u64m1(src); // vfloat64m1_t -> vfloat16m1_t vuint64m1_t v394 = __riscv_vreinterpret_v_f64m1_u64m1(src); vuint16m1_t v395 = __riscv_vreinterpret_v_u64m1_u16m1(v394); vfloat16m1_t dst = __riscv_vreinterpret_v_u16m1_f16m1(v395); // vfloat64m1_t -> vfloat32m1_t vuint64m1_t v399 = __riscv_vreinterpret_v_f64m1_u64m1(src); vuint32m1_t v400 = __riscv_vreinterpret_v_u64m1_u32m1(v399); vfloat32m1_t dst = __riscv_vreinterpret_v_u32m1_f32m1(v400); ```
nick-knight commented 12 months ago

Correct: the current API doesn't form the full Cartesian product of conversions, but there should be a path between any pair of types with same EMUL.