@samitouri / QOSamiQemu / commits / ead4d3a8d8

tests/tcg/hexagon: add HVX test for V6_vsubwsat saturation

Reviewed-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com> Link: https://lore.kernel.org/qemu-devel/20260807152241.1576334-7-brian.cain@oss.qualcomm.com Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>

Brian Cain committed Aug 7, 2026 at 08:22 UTC ead4d3a8d874f7f59fec909ea17a66b056b39ea5
1 file changed +44
tests/tcg/hexagon/hvx_misc.c
+44
@@ -20,6 +20,8 @@
20 #include <stdbool.h>
21 #include <string.h>
22 #include <limits.h>
23 +#include <hexagon_types.h>
24 +#include <hvx_hexagon_protos.h>
25
26 int err;
27
@@ -386,6 +388,47 @@ static void test_vsubuwsat_dv(void)
388 check_output_w(__LINE__, 2);
389 }
390
391 +static void test_vsubwsat(void)
392 +{
393 + const int32_t x0 = INT32_MIN;
394 + const int32_t y0 = 1;
395 + const int32_t x1 = INT32_MAX;
396 + const int32_t y1 = -1;
397 + HVX_Vector v0;
398 + HVX_Vector v1;
399 + HVX_Vector vres;
400 +
401 + /* INT32_MIN - 1 underflows and must saturate to INT32_MIN */
402 + memset(expect, 0x12, sizeof(MMVector));
403 + memset(output, 0x34, sizeof(MMVector));
404 +
405 + v0 = Q6_V_vsplat_R(x0);
406 + v1 = Q6_V_vsplat_R(y0);
407 + vres = Q6_Vw_vsub_VwVw_sat(v0, v1);
408 + memcpy(&output[0], &vres, sizeof(MMVector));
409 +
410 + for (int j = 0; j < MAX_VEC_SIZE_BYTES / 4; j++) {
411 + expect[0].w[j] = INT32_MIN;
412 + }
413 +
414 + check_output_w(__LINE__, 1);
415 +
416 + /* INT32_MAX - (-1) overflows and must saturate to INT32_MAX */
417 + memset(expect, 0x12, sizeof(MMVector));
418 + memset(output, 0x34, sizeof(MMVector));
419 +
420 + v0 = Q6_V_vsplat_R(x1);
421 + v1 = Q6_V_vsplat_R(y1);
422 + vres = Q6_Vw_vsub_VwVw_sat(v0, v1);
423 + memcpy(&output[0], &vres, sizeof(MMVector));
424 +
425 + for (int j = 0; j < MAX_VEC_SIZE_BYTES / 4; j++) {
426 + expect[0].w[j] = INT32_MAX;
427 + }
428 +
429 + check_output_w(__LINE__, 1);
430 +}
431 +
432 static void test_load_tmp_predicated(void)
433 {
434 void *p0 = buffer0;
@@ -530,6 +573,7 @@ int main()
573
574 test_vadduwsat();
575 test_vsubuwsat_dv();
576 + test_vsubwsat();
577
578 test_load_tmp_predicated();
579 test_load_cur_predicated();