@@ -3,6 +3,15 @@
#include <stdint-gcc.h>
#include <stdbool.h>
+#include <stdio.h>
+
+#define VALIDATE_RESULT(out, expect, N) \
+ do \
+ { \
+ for (unsigned i = 0; i < N; i++) \
+ if (out[i] != expect[i]) __builtin_abort (); \
+ } \
+ while (false)
/******************************************************************************/
/* Saturation Add (unsigned and signed) */
@@ -139,6 +148,23 @@ vec_sat_u_add_##T##_fmt_8 (T *out, T *op_1, T *op_2, unsigned limit) \
#define RUN_VEC_SAT_U_ADD_FMT_8(T, out, op_1, op_2, N) \
vec_sat_u_add_##T##_fmt_8(out, op_1, op_2, N)
+#define DEF_VEC_SAT_U_ADD_IMM_FMT_1(T, IMM) \
+T __attribute__((noinline)) \
+vec_sat_u_add_imm##IMM##_##T##_fmt_1 (T *out, T *in, unsigned limit) \
+{ \
+ unsigned i; \
+ for (i = 0; i < limit; i++) \
+ out[i] = (T)(in[i] + IMM) >= in[i] ? (in[i] + IMM) : -1; \
+}
+#define DEF_VEC_SAT_U_ADD_IMM_FMT_1_WRAP(T, IMM) \
+ DEF_VEC_SAT_U_ADD_IMM_FMT_1(T, IMM)
+
+#define RUN_VEC_SAT_U_ADD_IMM_FMT_1(T, out, op_1, expect, IMM, N) \
+ vec_sat_u_add_imm##IMM##_##T##_fmt_1(out, op_1, N); \
+ VALIDATE_RESULT (out, expect, N)
+#define RUN_VEC_SAT_U_ADD_IMM_FMT_1_WRAP(T, out, op_1, expect, IMM, N) \
+ RUN_VEC_SAT_U_ADD_IMM_FMT_1(T, out, op_1, expect, IMM, N)
+
/******************************************************************************/
/* Saturation Sub (Unsigned and Signed) */
/******************************************************************************/
new file mode 100644
@@ -0,0 +1,256 @@
+#ifndef HAVE_DEFINE_VEC_SAT_DATA_H
+#define HAVE_DEFINE_VEC_SAT_DATA_H
+
+#define N 16
+#define TEST_UNARY_DATA(T, NAME) test_##T##_##NAME##_data
+#define TEST_UNARY_DATA_WRAP(T, NAME) TEST_UNARY_DATA(T, NAME)
+
+uint8_t TEST_UNARY_DATA(uint8_t, sat_u_add_imm)[][2][N] =
+{
+ { /* For add imm 0 */
+ {
+ 0, 1, 5, 255,
+ 0, 1, 5, 255,
+ 0, 1, 5, 255,
+ 0, 1, 5, 255,
+ },
+ {
+ 0, 1, 5, 255,
+ 0, 1, 5, 255,
+ 0, 1, 5, 255,
+ 0, 1, 5, 255,
+ },
+ },
+ { /* For add imm 1 */
+ {
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ },
+ {
+ 1, 2, 1, 9,
+ 1, 2, 1, 9,
+ 1, 2, 1, 9,
+ 1, 2, 1, 9,
+ },
+ },
+ { /* For add imm 254 */
+ {
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ },
+ {
+ 254, 255, 254, 255,
+ 254, 255, 254, 255,
+ 254, 255, 254, 255,
+ 254, 255, 254, 255,
+ },
+ },
+ { /* For add imm 255 */
+ {
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ },
+ {
+ 255, 255, 255, 255,
+ 255, 255, 255, 255,
+ 255, 255, 255, 255,
+ 255, 255, 255, 255,
+ },
+ },
+};
+
+uint16_t TEST_UNARY_DATA(uint16_t, sat_u_add_imm)[][2][N] =
+{
+ { /* For add imm 0 */
+ {
+ 0, 1, 5, 65535,
+ 0, 1, 5, 65535,
+ 0, 1, 5, 65535,
+ 0, 1, 5, 65535,
+ },
+ {
+ 0, 1, 5, 65535,
+ 0, 1, 5, 65535,
+ 0, 1, 5, 65535,
+ 0, 1, 5, 65535,
+ },
+ },
+ { /* For add imm 1 */
+ {
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ },
+ {
+ 1, 2, 1, 9,
+ 1, 2, 1, 9,
+ 1, 2, 1, 9,
+ 1, 2, 1, 9,
+ },
+ },
+ { /* For add imm 65534 */
+ {
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ },
+ {
+ 65534, 65535, 65534, 65535,
+ 65534, 65535, 65534, 65535,
+ 65534, 65535, 65534, 65535,
+ 65534, 65535, 65534, 65535,
+ },
+ },
+ { /* For add imm 65535 */
+ {
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ },
+ {
+ 65535, 65535, 65535, 65535,
+ 65535, 65535, 65535, 65535,
+ 65535, 65535, 65535, 65535,
+ 65535, 65535, 65535, 65535,
+ },
+ },
+};
+
+uint32_t TEST_UNARY_DATA(uint32_t, sat_u_add_imm)[][2][N] =
+{
+ { /* For add imm 0 */
+ {
+ 0, 1, 5, 4294967295,
+ 0, 1, 5, 4294967295,
+ 0, 1, 5, 4294967295,
+ 0, 1, 5, 4294967295,
+ },
+ {
+ 0, 1, 5, 4294967295,
+ 0, 1, 5, 4294967295,
+ 0, 1, 5, 4294967295,
+ 0, 1, 5, 4294967295,
+ },
+ },
+ { /* For add imm 1 */
+ {
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ },
+ {
+ 1, 2, 1, 9,
+ 1, 2, 1, 9,
+ 1, 2, 1, 9,
+ 1, 2, 1, 9,
+ },
+ },
+ { /* For add imm 4294967294 */
+ {
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ },
+ {
+ 4294967294, 4294967295, 4294967294, 4294967295,
+ 4294967294, 4294967295, 4294967294, 4294967295,
+ 4294967294, 4294967295, 4294967294, 4294967295,
+ 4294967294, 4294967295, 4294967294, 4294967295,
+ },
+ },
+ { /* For add imm 4294967295 */
+ {
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ },
+ {
+ 4294967295, 4294967295, 4294967295, 4294967295,
+ 4294967295, 4294967295, 4294967295, 4294967295,
+ 4294967295, 4294967295, 4294967295, 4294967295,
+ 4294967295, 4294967295, 4294967295, 4294967295,
+ },
+ },
+};
+
+uint64_t TEST_UNARY_DATA(uint64_t, sat_u_add_imm)[][2][N] =
+{
+ { /* For add imm 0 */
+ {
+ 0, 1, 5, 18446744073709551615u,
+ 0, 1, 5, 18446744073709551615u,
+ 0, 1, 5, 18446744073709551615u,
+ 0, 1, 5, 18446744073709551615u,
+ },
+ {
+ 0, 1, 5, 18446744073709551615u,
+ 0, 1, 5, 18446744073709551615u,
+ 0, 1, 5, 18446744073709551615u,
+ 0, 1, 5, 18446744073709551615u,
+ },
+ },
+ { /* For add imm 1 */
+ {
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ },
+ {
+ 1, 2, 1, 9,
+ 1, 2, 1, 9,
+ 1, 2, 1, 9,
+ 1, 2, 1, 9,
+ },
+ },
+ { /* For add imm 18446744073709551614 */
+ {
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ },
+ {
+ 18446744073709551614u, 18446744073709551615u,
+ 18446744073709551614u, 18446744073709551615u,
+ 18446744073709551614u, 18446744073709551615u,
+ 18446744073709551614u, 18446744073709551615u,
+ 18446744073709551614u, 18446744073709551615u,
+ 18446744073709551614u, 18446744073709551615u,
+ 18446744073709551614u, 18446744073709551615u,
+ 18446744073709551614u, 18446744073709551615u,
+ },
+ },
+ { /* For add imm 18446744073709551615 */
+ {
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ 0, 1, 0, 8,
+ },
+ {
+ 18446744073709551615u, 18446744073709551615u,
+ 18446744073709551615u, 18446744073709551615u,
+ 18446744073709551615u, 18446744073709551615u,
+ 18446744073709551615u, 18446744073709551615u,
+ 18446744073709551615u, 18446744073709551615u,
+ 18446744073709551615u, 18446744073709551615u,
+ 18446744073709551615u, 18446744073709551615u,
+ 18446744073709551615u, 18446744073709551615u,
+ },
+ },
+};
+
+#endif
new file mode 100644
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -O3 -ftree-vectorize -fdump-rtl-expand-details -fno-schedule-insns -fno-schedule-insns2" } */
+/* { dg-skip-if "" { *-*-* } { "-flto" } } */
+/* { dg-final { check-function-bodies "**" "" } } */
+
+#include "vec_sat_arith.h"
+
+/*
+** vec_sat_u_add_imm9_uint8_t_fmt_1:
+** ...
+** vsaddu\.vi\s+v[0-9]+,\s*v[0-9]+,\s*9
+** ...
+*/
+DEF_VEC_SAT_U_ADD_IMM_FMT_1(uint8_t, 9)
new file mode 100644
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -O3 -ftree-vectorize -fdump-rtl-expand-details -fno-schedule-insns -fno-schedule-insns2" } */
+/* { dg-skip-if "" { *-*-* } { "-flto" } } */
+/* { dg-final { check-function-bodies "**" "" } } */
+
+#include "vec_sat_arith.h"
+
+/*
+** vec_sat_u_add_imm15_uint16_t_fmt_1:
+** ...
+** vsaddu\.vi\s+v[0-9]+,\s*v[0-9]+,\s*15
+** ...
+*/
+DEF_VEC_SAT_U_ADD_IMM_FMT_1(uint16_t, 15)
new file mode 100644
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -O3 -ftree-vectorize -fdump-rtl-expand-details -fno-schedule-insns -fno-schedule-insns2" } */
+/* { dg-skip-if "" { *-*-* } { "-flto" } } */
+/* { dg-final { check-function-bodies "**" "" } } */
+
+#include "vec_sat_arith.h"
+
+/*
+** vec_sat_u_add_imm33_uint32_t_fmt_1:
+** ...
+** vsaddu\.vv\s+v[0-9]+,\s*v[0-9]+,\s*v[0-9]+
+** ...
+*/
+DEF_VEC_SAT_U_ADD_IMM_FMT_1(uint32_t, 33)
new file mode 100644
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -O3 -ftree-vectorize -fdump-rtl-expand-details -fno-schedule-insns -fno-schedule-insns2" } */
+/* { dg-skip-if "" { *-*-* } { "-flto" } } */
+/* { dg-final { check-function-bodies "**" "" } } */
+
+#include "vec_sat_arith.h"
+
+/*
+** vec_sat_u_add_imm129_uint64_t_fmt_1:
+** ...
+** vsaddu\.vv\s+v[0-9]+,\s*v[0-9]+,\s*v[0-9]+
+** ...
+*/
+DEF_VEC_SAT_U_ADD_IMM_FMT_1(uint64_t, 129)
new file mode 100644
@@ -0,0 +1,28 @@
+/* { dg-do run { target { riscv_v } } } */
+/* { dg-additional-options "-std=c99" } */
+
+#include "vec_sat_arith.h"
+#include "vec_sat_data.h"
+
+#define T uint8_t
+#define RUN(T, out, in, expect, IMM, N) \
+ RUN_VEC_SAT_U_ADD_IMM_FMT_1_WRAP (T, out, in, expect, IMM, N)
+
+DEF_VEC_SAT_U_ADD_IMM_FMT_1_WRAP (T, 0)
+DEF_VEC_SAT_U_ADD_IMM_FMT_1_WRAP (T, 1)
+DEF_VEC_SAT_U_ADD_IMM_FMT_1_WRAP (T, 254)
+DEF_VEC_SAT_U_ADD_IMM_FMT_1_WRAP (T, 255)
+
+int
+main ()
+{
+ T out[N];
+ T (*d)[2][N] = TEST_UNARY_DATA_WRAP (T, sat_u_add_imm);
+
+ RUN (T, out, d[0][0], d[0][1], 0, N);
+ RUN (T, out, d[1][0], d[1][1], 1, N);
+ RUN (T, out, d[2][0], d[2][1], 254, N);
+ RUN (T, out, d[3][0], d[3][1], 255, N);
+
+ return 0;
+}
new file mode 100644
@@ -0,0 +1,28 @@
+/* { dg-do run { target { riscv_v } } } */
+/* { dg-additional-options "-std=c99" } */
+
+#include "vec_sat_arith.h"
+#include "vec_sat_data.h"
+
+#define T uint16_t
+#define RUN(T, out, in, expect, IMM, N) \
+ RUN_VEC_SAT_U_ADD_IMM_FMT_1_WRAP (T, out, in, expect, IMM, N)
+
+DEF_VEC_SAT_U_ADD_IMM_FMT_1_WRAP (T, 0)
+DEF_VEC_SAT_U_ADD_IMM_FMT_1_WRAP (T, 1)
+DEF_VEC_SAT_U_ADD_IMM_FMT_1_WRAP (T, 65534)
+DEF_VEC_SAT_U_ADD_IMM_FMT_1_WRAP (T, 65535)
+
+int
+main ()
+{
+ T out[N];
+ T (*d)[2][N] = TEST_UNARY_DATA_WRAP (T, sat_u_add_imm);
+
+ RUN (T, out, d[0][0], d[0][1], 0, N);
+ RUN (T, out, d[1][0], d[1][1], 1, N);
+ RUN (T, out, d[2][0], d[2][1], 65534, N);
+ RUN (T, out, d[3][0], d[3][1], 65535, N);
+
+ return 0;
+}
new file mode 100644
@@ -0,0 +1,28 @@
+/* { dg-do run { target { riscv_v } } } */
+/* { dg-additional-options "-std=c99" } */
+
+#include "vec_sat_arith.h"
+#include "vec_sat_data.h"
+
+#define T uint32_t
+#define RUN(T, out, in, expect, IMM, N) \
+ RUN_VEC_SAT_U_ADD_IMM_FMT_1_WRAP (T, out, in, expect, IMM, N)
+
+DEF_VEC_SAT_U_ADD_IMM_FMT_1_WRAP (T, 0)
+DEF_VEC_SAT_U_ADD_IMM_FMT_1_WRAP (T, 1)
+DEF_VEC_SAT_U_ADD_IMM_FMT_1_WRAP (T, 4294967295)
+DEF_VEC_SAT_U_ADD_IMM_FMT_1_WRAP (T, 4294967294)
+
+int
+main ()
+{
+ T out[N];
+ T (*d)[2][N] = TEST_UNARY_DATA_WRAP (T, sat_u_add_imm);
+
+ RUN (T, out, d[0][0], d[0][1], 0, N);
+ RUN (T, out, d[1][0], d[1][1], 1, N);
+ RUN (T, out, d[2][0], d[2][1], 4294967294, N);
+ RUN (T, out, d[3][0], d[3][1], 4294967295, N);
+
+ return 0;
+}
new file mode 100644
@@ -0,0 +1,28 @@
+/* { dg-do run { target { riscv_v } } } */
+/* { dg-additional-options "-std=c99" } */
+
+#include "vec_sat_arith.h"
+#include "vec_sat_data.h"
+
+#define T uint64_t
+#define RUN(T, out, in, expect, IMM, N) \
+ RUN_VEC_SAT_U_ADD_IMM_FMT_1_WRAP (T, out, in, expect, IMM, N)
+
+DEF_VEC_SAT_U_ADD_IMM_FMT_1_WRAP (T, 0)
+DEF_VEC_SAT_U_ADD_IMM_FMT_1_WRAP (T, 1)
+DEF_VEC_SAT_U_ADD_IMM_FMT_1_WRAP (T, 18446744073709551614u)
+DEF_VEC_SAT_U_ADD_IMM_FMT_1_WRAP (T, 18446744073709551615u)
+
+int
+main ()
+{
+ T out[N];
+ T (*d)[2][N] = TEST_UNARY_DATA_WRAP (T, sat_u_add_imm);
+
+ RUN (T, out, d[0][0], d[0][1], 0, N);
+ RUN (T, out, d[1][0], d[1][1], 1, N);
+ RUN (T, out, d[2][0], d[2][1], 18446744073709551614u, N);
+ RUN (T, out, d[3][0], d[3][1], 18446744073709551615u, N);
+
+ return 0;
+}