Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type-relative overloads for vreinterpret, vlmul_ext, vlmul_trunc, etc. #303

Open
sh1boot opened this issue Dec 22, 2023 · 1 comment
Open

Comments

@sh1boot
Copy link

sh1boot commented Dec 22, 2023

Consider overloads like:

vuint8m1_t __riscv_vreinterpret_u(vuint8m1_t v) { return v; }
vuint16m1_t __riscv_vreinterpret_u(vuint16m1_t) /* ... */
vuint32m1_t __riscv_vreinterpret_u(vuint32m1_t);
vuint64m1_t __riscv_vreinterpret_u(vuint64m1_t);
vuint8m1_t __riscv_vreinterpret_u(vint8m1_t v) { return __riscv_vreinterpret_u8m1(v); }
vuint16m1_t __riscv_vreinterpret_u(vint16m1_t); /* ... */
vuint32m1_t __riscv_vreinterpret_u(vint32m1_t);
vuint64m1_t __riscv_vreinterpret_u(vint64m1_t);
vuint32m1_t __riscv_vreinterpret_u(vfloat32m1_t);
vuint64m1_t __riscv_vreinterpret_u(vfloat64m1_t);
// etc., across all LMUL and versions which set signed, unsigned, 8-bit, 16-bit, 32-bit, 64-bit

To make it possible for template code and code receiving typedef versions of vector types to change what they need to change without getting entagled with the rest of the data type.

Also:

vuint8mf4_t __riscv_vlmul_widen(vuint8mf8_t v) { return __riscv_vlmul_ext_u8mf4(v); }
vuint8mf2_t __riscv_vlmul_widen(vuint8mf4_t); /* ... */
vuint8m1_t __riscv_vlmul_widen(vuint8mf2_t);
vuint8m2_t __riscv_vlmul_widen(vuint8m1_t);
vuint8m4_t __riscv_vlmul_widen(vuint8m2_t);
vuint8m8_t __riscv_vlmul_widen(vuint8m4_t);
// etc., across all element types

vuint8mf8_t __riscv_vlmul_narrow(vuint8mf4_t v) { return __riscv_vlmul_trunc_u8mf8(v); }
vuint8mf4_t __riscv_vlmul_narrow(vuint8mf2_t); /* ... */
vuint8mf2_t __riscv_vlmul_narrow(vuint8m1_t);
vuint8m1_t __riscv_vlmul_narrow(vuint8m2_t);
vuint8m2_t __riscv_vlmul_narrow(vuint8m4_t);
vuint8m4_t __riscv_vlmul_narrow(vuint8m8_t);
// etc., across all element types

#if 1  // debatable
vuint8mf8_t __riscv_vget_upper(vuint8mf4_t v ) { return __riscv_vslidedown(v, __riscv_vsetvlmax_e8mf8(), __riscv_vsetvlmax_e8mf8()); }
vuint8mf4_t __riscv_vget_upper(vuint8mf2_t); /* ... */
vuint8mf2_t __riscv_vget_upper(vuint8m1_t);
#endif
vuint8m1_t __riscv_vget_upper(vuint8m2_t v) { return __riscv_vget_u8m1(v, 1); }
vuint8m2_t __riscv_vget_upper(vuint8m4_t); /* ... */
vuint8m4_t __riscv_vget_upper(vuint8m8_t);
// etc., across all element types

#define __riscv_vset_upper(d, v) __riscv_vset(d, 1, v)  /* shouldn't accept some variants, but whatever */
#define __riscv_vget_lower __riscv_vlmul_narrow  /* same operation, but with a consistent name based on intent */
#define __riscv_vjoin(a, b) __riscv_vset_upper(__riscv_vlmul_widen(a), b)

Allowing code to cope with the relative widening and narrowing of data types by factors of two under the same conditions as above.

@sh1boot
Copy link
Author

sh1boot commented Dec 22, 2023

I guess there's also the element-wise widen (a form of vreinterpret), and the vlmul widen with element-wise widen at the same time; though you can cobble the latter together with the other two.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant