Fid host-utils sat; Add GVec overrides for HVX ops
cover Fid host-utils sat; Add GVec overrides for HVX ops
I was going to just send the host-utils change on its own but figured it might be useful to have the motivating commits that encountered the issue, so I've included those here too.
Brian Cain (6):
host-utils: fix ssub32/64_saturate return type and clamp direction target/hexagon: add GVec overrides for HVX saturating add/sub target/hexagon: add GVec override for HVX vmpyih multiply target/hexagon: add GVec overrides for HVX absolute difference target/hexagon: add GVec overrides for HVX vector average tests/tcg/hexagon: add HVX test for V6_vsubwsat saturation
include/qemu/host-utils.h | 20 ++-- target/hexagon/gen_tcg_hvx.h | 183 +++++++++++++++++++++++++++++++++++ tests/tcg/hexagon/hvx_misc.c | 44 +++++++++ 3 files changed, 237 insertions(+), 10 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/6 host-utils: fix ssub32/64_saturate return type and clamp direction
ssub32_saturate() and ssub64_saturate() were declared to return bool instead of int32_t/int64_t, and clamped to the wrong bound on overflow.
--- include/qemu/host-utils.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
include/qemu/host-utils.h +10 -10
@@ -610,7 +610,7 @@ static inline bool umul64_overflow(uint64_t x, uint64_t y, uint64_t *ret)* sadd32_saturate - addition with saturation * @x, @y: addends * -* Computes @x + @y, and saturates rathern than truncating the result. +* Computes @x + @y, and saturates rather than truncating the result. */ static inline int32_t sadd32_saturate (int32_t x,int32_t y) {
@@ -625,7 +625,7 @@ static inline int32_t sadd32_saturate(int32_t x, int32_t y)* sadd64_saturate - addition with saturation * @x, @y: addends * -* Computes @x + @y, and saturates rathern than truncating the result. +* Computes @x + @y, and saturates rather than truncating the result. */ static inline int64_t sadd64_saturate (int64_t x,int64_t y) {
@@ -638,30 +638,30 @@ static inline int64_t sadd64_saturate(int64_t x, int64_t y)/** * ssub32_saturate - subtraction with saturation -* @x, @y: addends +* @x, @y: minuend and subtrahend * -* Computes @x + @y, and saturates rathern than truncating the result. +* Computes @x - @y, and saturates rather than truncating the result. */ -static inline bool ssub32_saturate (int32_t x,int32_t y) +static inline int32_t ssub32_saturate (int32_t x,int32_t y) {int32_t ret;if (ssub32_overflow (x, y, &ret)) { - ret = x <0 ?INT32_MAX :INT32_MIN ; + ret = x <0 ?INT32_MIN :INT32_MAX ; }return ret; }/** * ssub64_saturate - subtraction with saturation -* @x, @y: addends +* @x, @y: minuend and subtrahend * -* Computes @x + @y, and saturates rathern than truncating the result. +* Computes @x - @y, and saturates rather than truncating the result. */ -static inline bool ssub64_saturate (int64_t x,int64_t y) +static inline int64_t ssub64_saturate (int64_t x,int64_t y) {int64_t ret;if (ssub64_overflow (x, y, &ret)) { - ret = x <0 ?INT64_MAX :INT64_MIN ; + ret = x <0 ?INT64_MIN :INT64_MAX ; }return ret; }
Signature · 1 line
2.34.1
Re: [PATCH 1/6] host-utils: fix ssub32/64_saturate return type and clamp direction
Quoted 8 lines · Brian Cain
ssub32_saturate()andssub64_saturate()were declared to return bool instead of int32_t/int64_t, and clamped to the wrong bound on overflow.Signed-off-by Brian Cain <[email protected]>--- include/qemu/host-utils.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
PATCH 2/6 target/hexagon: add GVec overrides for HVX saturating add/sub
In reply to Brian Cain--- target/hexagon/gen_tcg_hvx.h | 93 ++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+)
target/hexagon/gen_tcg_hvx.h +93 -0
@@ -234,6 +234,99 @@ static inline void assert_vhist_tmp(DisasContext *ctx)tcg_gen_gvec_sub (MO_32 , VddV_off, VuuV_off, VvvV_off, \ sizeof(MMVector) * 2, sizeof(MMVector) * 2) +#define fGEN_TCG_V6_vaddbsat (SHORTCODE ) \ + tcg_gen_gvec_ssadd(MO_8, VdV_off, VuV_off, VvV_off, \ + VECTOR_SIZE_BYTE, VECTOR_SIZE_BYTE) + +#define fGEN_TCG_V6_vaddhsat (SHORTCODE ) \ + tcg_gen_gvec_ssadd(MO_16, VdV_off, VuV_off, VvV_off, \ + VECTOR_SIZE_BYTE, VECTOR_SIZE_BYTE) + +#define fGEN_TCG_V6_vaddwsat (SHORTCODE ) \ + tcg_gen_gvec_ssadd(MO_32, VdV_off, VuV_off, VvV_off, \ + VECTOR_SIZE_BYTE, VECTOR_SIZE_BYTE) + +#define fGEN_TCG_V6_vaddubsat (SHORTCODE ) \ + tcg_gen_gvec_usadd(MO_8, VdV_off, VuV_off, VvV_off, \ + VECTOR_SIZE_BYTE, VECTOR_SIZE_BYTE) + +#define fGEN_TCG_V6_vadduhsat (SHORTCODE ) \ + tcg_gen_gvec_usadd(MO_16, VdV_off, VuV_off, VvV_off, \ + VECTOR_SIZE_BYTE, VECTOR_SIZE_BYTE) + +#define fGEN_TCG_V6_vadduwsat (SHORTCODE ) \ + tcg_gen_gvec_usadd(MO_32, VdV_off, VuV_off, VvV_off, \ + VECTOR_SIZE_BYTE, VECTOR_SIZE_BYTE) + +#define fGEN_TCG_PAIR_ADDSUB (OP ,VECE ,DST ,SRC_A ,SRC_B ) \ + do { \ + tcg_gen_gvec_##OP(VECE, DST, SRC_A, SRC_B, \ + VECTOR_SIZE_BYTE, VECTOR_SIZE_BYTE); \ + tcg_gen_gvec_##OP(VECE, DST + sizeof(MMVector), \ + SRC_A + sizeof(MMVector), \ + SRC_B + sizeof(MMVector), \ + VECTOR_SIZE_BYTE, VECTOR_SIZE_BYTE); \ + } while (0) + +#define fGEN_TCG_V6_vaddbsat_dv (SHORTCODE ) \ + fGEN_TCG_PAIR_ADDSUB(ssadd, MO_8, VddV_off, VuuV_off, VvvV_off) + +#define fGEN_TCG_V6_vaddhsat_dv (SHORTCODE ) \ + fGEN_TCG_PAIR_ADDSUB(ssadd, MO_16, VddV_off, VuuV_off, VvvV_off) + +#define fGEN_TCG_V6_vaddwsat_dv (SHORTCODE ) \ + fGEN_TCG_PAIR_ADDSUB(ssadd, MO_32, VddV_off, VuuV_off, VvvV_off) + +#define fGEN_TCG_V6_vaddubsat_dv (SHORTCODE ) \ + fGEN_TCG_PAIR_ADDSUB(usadd, MO_8, VddV_off, VuuV_off, VvvV_off) + +#define fGEN_TCG_V6_vadduhsat_dv (SHORTCODE ) \ + fGEN_TCG_PAIR_ADDSUB(usadd, MO_16, VddV_off, VuuV_off, VvvV_off) + +#define fGEN_TCG_V6_vadduwsat_dv (SHORTCODE ) \ + fGEN_TCG_PAIR_ADDSUB(usadd, MO_32, VddV_off, VuuV_off, VvvV_off) + +#define fGEN_TCG_V6_vsubbsat (SHORTCODE ) \ + tcg_gen_gvec_sssub(MO_8, VdV_off, VuV_off, VvV_off, \ + VECTOR_SIZE_BYTE, VECTOR_SIZE_BYTE) + +#define fGEN_TCG_V6_vsubhsat (SHORTCODE ) \ + tcg_gen_gvec_sssub(MO_16, VdV_off, VuV_off, VvV_off, \ + VECTOR_SIZE_BYTE, VECTOR_SIZE_BYTE) + +#define fGEN_TCG_V6_vsubwsat (SHORTCODE ) \ + tcg_gen_gvec_sssub(MO_32, VdV_off, VuV_off, VvV_off, \ + VECTOR_SIZE_BYTE, VECTOR_SIZE_BYTE) + +#define fGEN_TCG_V6_vsububsat (SHORTCODE ) \ + tcg_gen_gvec_ussub(MO_8, VdV_off, VuV_off, VvV_off, \ + VECTOR_SIZE_BYTE, VECTOR_SIZE_BYTE) + +#define fGEN_TCG_V6_vsubuhsat (SHORTCODE ) \ + tcg_gen_gvec_ussub(MO_16, VdV_off, VuV_off, VvV_off, \ + VECTOR_SIZE_BYTE, VECTOR_SIZE_BYTE) + +#define fGEN_TCG_V6_vsubuwsat (SHORTCODE ) \ + tcg_gen_gvec_ussub(MO_32, VdV_off, VuV_off, VvV_off, \ + VECTOR_SIZE_BYTE, VECTOR_SIZE_BYTE) + +#define fGEN_TCG_V6_vsubbsat_dv (SHORTCODE ) \ + fGEN_TCG_PAIR_ADDSUB(sssub, MO_8, VddV_off, VuuV_off, VvvV_off) + +#define fGEN_TCG_V6_vsubhsat_dv (SHORTCODE ) \ + fGEN_TCG_PAIR_ADDSUB(sssub, MO_16, VddV_off, VuuV_off, VvvV_off) + +#define fGEN_TCG_V6_vsubwsat_dv (SHORTCODE ) \ + fGEN_TCG_PAIR_ADDSUB(sssub, MO_32, VddV_off, VuuV_off, VvvV_off) + +#define fGEN_TCG_V6_vsububsat_dv (SHORTCODE ) \ + fGEN_TCG_PAIR_ADDSUB(ussub, MO_8, VddV_off, VuuV_off, VvvV_off) + +#define fGEN_TCG_V6_vsubuhsat_dv (SHORTCODE ) \ + fGEN_TCG_PAIR_ADDSUB(ussub, MO_16, VddV_off, VuuV_off, VvvV_off) + +#define fGEN_TCG_V6_vsubuwsat_dv (SHORTCODE ) \ + fGEN_TCG_PAIR_ADDSUB(ussub, MO_32, VddV_off, VuuV_off, VvvV_off)/* Vector shift right - various forms */ #define fGEN_TCG_V6_vasrh (SHORTCODE ) \ do { \
Signature · 1 line
2.34.1
Re: [PATCH 2/6] target/hexagon: add GVec overrides for HVX saturating add/sub
Quoted 5 lines · Brian Cain
Signed-off-by Brian Cain <[email protected]>--- target/hexagon/gen_tcg_hvx.h | 93 ++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+)
PATCH 3/6 target/hexagon: add GVec override for HVX vmpyih multiply
In reply to Brian Cain--- target/hexagon/gen_tcg_hvx.h | 5 +++++ 1 file changed, 5 insertions(+)
target/hexagon/gen_tcg_hvx.h +5 -0
@@ -327,6 +327,11 @@ static inline void assert_vhist_tmp(DisasContext *ctx)#define fGEN_TCG_V6_vsubuwsat_dv (SHORTCODE ) \ fGEN_TCG_PAIR_ADDSUB(ussub, MO_32, VddV_off, VuuV_off, VvvV_off) + +#define fGEN_TCG_V6_vmpyih (SHORTCODE ) \ + tcg_gen_gvec_mul(MO_16, VdV_off, VuV_off, VvV_off, \ + VECTOR_SIZE_BYTE, VECTOR_SIZE_BYTE) +/* Vector shift right - various forms */ #define fGEN_TCG_V6_vasrh (SHORTCODE ) \ do { \
Signature · 1 line
2.34.1
Re: [PATCH 3/6] target/hexagon: add GVec override for HVX vmpyih multiply
Quoted 5 lines · Brian Cain
Signed-off-by Brian Cain <[email protected]>--- target/hexagon/gen_tcg_hvx.h | 5 +++++ 1 file changed, 5 insertions(+)
PATCH 4/6 target/hexagon: add GVec overrides for HVX absolute difference
In reply to Brian Cain--- target/hexagon/gen_tcg_hvx.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
target/hexagon/gen_tcg_hvx.h +23 -0
@@ -332,6 +332,29 @@ static inline void assert_vhist_tmp(DisasContext *ctx)tcg_gen_gvec_mul (MO_16 , VdV_off, VuV_off, VvV_off, \ VECTOR_SIZE_BYTE, VECTOR_SIZE_BYTE) +#define fGEN_TCG_VEC_ABSDIFF (VECE ,MAX_FN ,MIN_FN ) \ + do { \ + intptr_t tmpoff = offsetof(CPUHexagonState, vtmp); \ + MAX_FN(VECE, tmpoff, VuV_off, VvV_off, \ + VECTOR_SIZE_BYTE, VECTOR_SIZE_BYTE); \ + MIN_FN(VECE, VdV_off, VuV_off, VvV_off, \ + VECTOR_SIZE_BYTE, VECTOR_SIZE_BYTE); \ + tcg_gen_gvec_sub(VECE, VdV_off, tmpoff, VdV_off, \ + VECTOR_SIZE_BYTE, VECTOR_SIZE_BYTE); \ + } while (0) + +#define fGEN_TCG_V6_vabsdiffub (SHORTCODE ) \ + fGEN_TCG_VEC_ABSDIFF(MO_8, tcg_gen_gvec_umax, tcg_gen_gvec_umin) + +#define fGEN_TCG_V6_vabsdiffuh (SHORTCODE ) \ + fGEN_TCG_VEC_ABSDIFF(MO_16, tcg_gen_gvec_umax, tcg_gen_gvec_umin) + +#define fGEN_TCG_V6_vabsdiffh (SHORTCODE ) \ + fGEN_TCG_VEC_ABSDIFF(MO_16, tcg_gen_gvec_smax, tcg_gen_gvec_smin) + +#define fGEN_TCG_V6_vabsdiffw (SHORTCODE ) \ + fGEN_TCG_VEC_ABSDIFF(MO_32, tcg_gen_gvec_smax, tcg_gen_gvec_smin) +/* Vector shift right - various forms */ #define fGEN_TCG_V6_vasrh (SHORTCODE ) \ do { \
Signature · 1 line
2.34.1
Re: [PATCH 4/6] target/hexagon: add GVec overrides for HVX absolute difference
Quoted 5 lines · Brian Cain
Signed-off-by Brian Cain <[email protected]>--- target/hexagon/gen_tcg_hvx.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
PATCH 5/6 target/hexagon: add GVec overrides for HVX vector average
In reply to Brian Cain--- target/hexagon/gen_tcg_hvx.h | 62 ++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+)
target/hexagon/gen_tcg_hvx.h +62 -0
@@ -355,6 +355,68 @@ static inline void assert_vhist_tmp(DisasContext *ctx)#define fGEN_TCG_V6_vabsdiffw (SHORTCODE ) \ fGEN_TCG_VEC_ABSDIFF(MO_32, tcg_gen_gvec_smax, tcg_gen_gvec_smin) +#define fGEN_TCG_VEC_AVG (VECE ,SHIFT_FN ) \ + do { \ + intptr_t tmpoff = offsetof(CPUHexagonState, vtmp); \ + tcg_gen_gvec_and(MO_64, tmpoff, VuV_off, VvV_off, \ + VECTOR_SIZE_BYTE, VECTOR_SIZE_BYTE); \ + tcg_gen_gvec_xor(MO_64, VdV_off, VuV_off, VvV_off, \ + VECTOR_SIZE_BYTE, VECTOR_SIZE_BYTE); \ + SHIFT_FN(VECE, VdV_off, VdV_off, 1, \ + VECTOR_SIZE_BYTE, VECTOR_SIZE_BYTE); \ + tcg_gen_gvec_add(VECE, VdV_off, tmpoff, VdV_off, \ + VECTOR_SIZE_BYTE, VECTOR_SIZE_BYTE); \ + } while (0) + +#define fGEN_TCG_V6_vavgub (SHORTCODE ) \ + fGEN_TCG_VEC_AVG(MO_8, tcg_gen_gvec_shri) + +#define fGEN_TCG_V6_vavguh (SHORTCODE ) \ + fGEN_TCG_VEC_AVG(MO_16, tcg_gen_gvec_shri) + +#define fGEN_TCG_V6_vavguw (SHORTCODE ) \ + fGEN_TCG_VEC_AVG(MO_32, tcg_gen_gvec_shri) + +#define fGEN_TCG_V6_vavgb (SHORTCODE ) \ + fGEN_TCG_VEC_AVG(MO_8, tcg_gen_gvec_sari) + +#define fGEN_TCG_V6_vavgh (SHORTCODE ) \ + fGEN_TCG_VEC_AVG(MO_16, tcg_gen_gvec_sari) + +#define fGEN_TCG_V6_vavgw (SHORTCODE ) \ + fGEN_TCG_VEC_AVG(MO_32, tcg_gen_gvec_sari) + +#define fGEN_TCG_VEC_AVGRND (VECE ,SHIFT_FN ) \ + do { \ + intptr_t tmpoff = offsetof(CPUHexagonState, vtmp); \ + tcg_gen_gvec_or(MO_64, tmpoff, VuV_off, VvV_off, \ + VECTOR_SIZE_BYTE, VECTOR_SIZE_BYTE); \ + tcg_gen_gvec_xor(MO_64, VdV_off, VuV_off, VvV_off, \ + VECTOR_SIZE_BYTE, VECTOR_SIZE_BYTE); \ + SHIFT_FN(VECE, VdV_off, VdV_off, 1, \ + VECTOR_SIZE_BYTE, VECTOR_SIZE_BYTE); \ + tcg_gen_gvec_sub(VECE, VdV_off, tmpoff, VdV_off, \ + VECTOR_SIZE_BYTE, VECTOR_SIZE_BYTE); \ + } while (0) + +#define fGEN_TCG_V6_vavgubrnd (SHORTCODE ) \ + fGEN_TCG_VEC_AVGRND(MO_8, tcg_gen_gvec_shri) + +#define fGEN_TCG_V6_vavguhrnd (SHORTCODE ) \ + fGEN_TCG_VEC_AVGRND(MO_16, tcg_gen_gvec_shri) + +#define fGEN_TCG_V6_vavguwrnd (SHORTCODE ) \ + fGEN_TCG_VEC_AVGRND(MO_32, tcg_gen_gvec_shri) + +#define fGEN_TCG_V6_vavgbrnd (SHORTCODE ) \ + fGEN_TCG_VEC_AVGRND(MO_8, tcg_gen_gvec_sari) + +#define fGEN_TCG_V6_vavghrnd (SHORTCODE ) \ + fGEN_TCG_VEC_AVGRND(MO_16, tcg_gen_gvec_sari) + +#define fGEN_TCG_V6_vavgwrnd (SHORTCODE ) \ + fGEN_TCG_VEC_AVGRND(MO_32, tcg_gen_gvec_sari) +/* Vector shift right - various forms */ #define fGEN_TCG_V6_vasrh (SHORTCODE ) \ do { \
Signature · 1 line
2.34.1
Re: [PATCH 5/6] target/hexagon: add GVec overrides for HVX vector average
Quoted 5 lines · Brian Cain
Signed-off-by Brian Cain <[email protected]>--- target/hexagon/gen_tcg_hvx.h | 62 ++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+)
PATCH 6/6 tests/tcg/hexagon: add HVX test for V6_vsubwsat saturation
In reply to Brian Cain--- tests/tcg/hexagon/hvx_misc.c | 44 ++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)
tests/tcg/hexagon/hvx_misc.c +44 -0
@@ -20,6 +20,8 @@#include <stdbool.h> #include <string.h> #include <limits.h> +#include <hexagon_types.h> +#include <hvx_hexagon_protos.h> int err;
@@ -386,6 +388,47 @@ static void test_vsubuwsat_dv(void)check_output_w (__LINE__,2 ); } +static void test_vsubwsat (void ) +{ +const int32_t x0 =INT32_MIN ; +const int32_t y0 =1 ; +const int32_t x1 =INT32_MAX ; +const int32_t y1 =-1 ; +HVX_Vector v0; +HVX_Vector v1; +HVX_Vector vres; + +/* INT32_MIN - 1 underflows and must saturate to INT32_MIN */ +memset (expect,0x12 ,sizeof (MMVector)); +memset (output,0x34 ,sizeof (MMVector)); + + v0 =Q6_V_vsplat_R (x0); + v1 =Q6_V_vsplat_R (y0); + vres =Q6_Vw_vsub_VwVw_sat (v0, v1); +memcpy (&output[0 ], &vres,sizeof (MMVector)); + +for (int j =0 ; j <MAX_VEC_SIZE_BYTES /4 ; j++) { + expect[0 ].w[j] =INT32_MIN ; + } + +check_output_w (__LINE__,1 ); + +/* INT32_MAX - (-1) overflows and must saturate to INT32_MAX */ +memset (expect,0x12 ,sizeof (MMVector)); +memset (output,0x34 ,sizeof (MMVector)); + + v0 =Q6_V_vsplat_R (x1); + v1 =Q6_V_vsplat_R (y1); + vres =Q6_Vw_vsub_VwVw_sat (v0, v1); +memcpy (&output[0 ], &vres,sizeof (MMVector)); + +for (int j =0 ; j <MAX_VEC_SIZE_BYTES /4 ; j++) { + expect[0 ].w[j] =INT32_MAX ; + } + +check_output_w (__LINE__,1 ); +} +static void test_load_tmp_predicated (void ) {void *p0 = buffer0;
@@ -530,6 +573,7 @@ int main()test_vadduwsat ();test_vsubuwsat_dv (); +test_vsubwsat ();test_load_tmp_predicated ();test_load_cur_predicated ();
Signature · 1 line
2.34.1
Re: [PATCH 6/6] tests/tcg/hexagon: add HVX test for V6_vsubwsat saturation
Quoted 5 lines · Brian Cain
Signed-off-by Brian Cain <[email protected]>--- tests/tcg/hexagon/hvx_misc.c | 44 ++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)
Quoted 3 lines · Brian Cain
I was going to just send the host-utils change on its own but figured it might be useful to have the motivating commits that encountered the issue, so I've included those here too.
Ugh - careless review - don't "Fid" host-utils sat -- Fix... :/
Quoted 13 lines
Brian Cain (6):
host-utils: fix ssub32/64_saturate return type and clamp direction target/hexagon: add GVec overrides for HVX saturating add/sub target/hexagon: add GVec override for HVX vmpyih multiply target/hexagon: add GVec overrides for HVX absolute difference target/hexagon: add GVec overrides for HVX vector average tests/tcg/hexagon: add HVX test forV6_vsubwsatsaturationinclude/qemu/host-utils.h | 20 ++-- target/hexagon/gen_tcg_hvx.h | 183 +++++++++++++++++++++++++++++++++++ tests/tcg/hexagon/hvx_misc.c | 44 +++++++++ 3 files changed, 237 insertions(+), 10 deletions(-)