#include <stdint-gcc.h>
#include <stdbool.h>
+typedef __uint128_t uint128_t;
+
/******************************************************************************/
/* Saturation Add (unsigned and signed) */
/******************************************************************************/
#define RUN_SAT_S_TRUNC_FMT_8(NT, WT, x) sat_s_trunc_##WT##_to_##NT##_fmt_8 (x)
#define RUN_SAT_S_TRUNC_FMT_8_WRAP(NT, WT, x) RUN_SAT_S_TRUNC_FMT_8(NT, WT, x)
+/******************************************************************************/
+/* Saturation Mult (unsigned and signed) */
+/******************************************************************************/
+
+#define DEF_SAT_U_MUL_FMT_1(NT, WT) \
+NT __attribute__((noinline)) \
+sat_u_mul_##NT##_from_##WT##_fmt_1 (NT a, NT b) \
+{ \
+ WT x = (WT)a * (WT)b; \
+ NT max = -1; \
+ if (x > (WT)(max)) \
+ return max; \
+ else \
+ return (NT)x; \
+}
+
+#define DEF_SAT_U_MUL_FMT_1_WRAP(NT, WT) DEF_SAT_U_MUL_FMT_1(NT, WT)
+#define RUN_SAT_U_MUL_FMT_1(NT, WT, a, b) \
+ sat_u_mul_##NT##_from_##WT##_fmt_1 (a, b)
+#define RUN_SAT_U_MUL_FMT_1_WRAP(NT, WT, a, b) RUN_SAT_U_MUL_FMT_1(NT, WT, a, b)
+
#endif
#define TEST_BINARY_STRUCT_NAME(T, NAME) test_##T##_##NAME##_s
#define TEST_BINARY_STRUCT_DECL(T, NAME) struct TEST_BINARY_STRUCT_NAME(T, NAME)
+#define TEST_BINARY_STRUCT_DECL_WRAP(T, NAME) TEST_BINARY_STRUCT_DECL(T, NAME)
#define TEST_BINARY_STRUCT(T, NAME) \
struct TEST_BINARY_STRUCT_NAME(T, NAME) \
{ \
TEST_BINARY_STRUCT (uint32_t, usadd)
TEST_BINARY_STRUCT (uint64_t, usadd)
+TEST_BINARY_STRUCT (uint8_t, usmul)
+TEST_BINARY_STRUCT (uint16_t, usmul)
+TEST_BINARY_STRUCT (uint32_t, usmul)
+TEST_BINARY_STRUCT (uint64_t, usmul)
+
TEST_BINARY_STRUCT (int8_t, ssadd)
TEST_BINARY_STRUCT (int16_t, ssadd)
TEST_BINARY_STRUCT (int32_t, ssadd)
{ 9223372036854775806ll, 9223372036854775800ll, 6},
};
+TEST_BINARY_STRUCT_DECL(uint8_t, usmul) TEST_BINARY_DATA(uint8_t, usmul)[] =
+{
+ { 0, 0, 0, },
+ { 0, 1, 0, },
+ { 1, 1, 1, },
+ { 1, 127, 127, },
+ { 2, 127, 254, },
+ { 3, 127, 255, },
+ { 127, 127, 255, },
+ { 1, 255, 255, },
+ { 127, 255, 255, },
+ { 255, 255, 255, },
+};
+
+TEST_BINARY_STRUCT_DECL(uint16_t, usmul) TEST_BINARY_DATA(uint16_t, usmul)[] =
+{
+ { 0, 0, 0, },
+ { 0, 1, 0, },
+ { 1, 1, 1, },
+ { 1, 32767, 32767, },
+ { 2, 32767, 65534, },
+ { 3, 32767, 65535, },
+ { 32767, 32767, 65535, },
+ { 1, 65535, 65535, },
+ { 32767, 65535, 65535, },
+ { 65535, 65535, 65535, },
+};
+
+TEST_BINARY_STRUCT_DECL(uint32_t, usmul) TEST_BINARY_DATA(uint32_t, usmul)[] =
+{
+ { 0, 0, 0, },
+ { 0, 1, 0, },
+ { 1, 1, 1, },
+ { 1, 2147483647, 2147483647, },
+ { 2, 2147483647, 4294967294, },
+ { 3, 2147483647, 4294967295, },
+ { 2147483647, 2147483647, 4294967295, },
+ { 1, 4294967295, 4294967295, },
+ { 2147483647, 4294967295, 4294967295, },
+ { 4294967295, 4294967295, 4294967295, },
+};
+
+TEST_BINARY_STRUCT_DECL(uint64_t, usmul) TEST_BINARY_DATA(uint64_t, usmul)[] =
+{
+ { 0, 0, 0, },
+ { 0, 1, 0, },
+ { 1, 1, 1, },
+ { 1, 9223372036854775807ull, 9223372036854775807ull, },
+ { 2, 9223372036854775807ull, 18446744073709551614ull, },
+ { 3, 9223372036854775807ull, 18446744073709551615ull, },
+ { 9223372036854775807ull, 9223372036854775807ull, 18446744073709551615ull, },
+ { 1, 18446744073709551615ull, 18446744073709551615ull, },
+ { 9223372036854775807ull, 18446744073709551615ull, 18446744073709551615ull, },
+ { 18446744073709551615ull, 18446744073709551615ull, 18446744073709551615ull, },
+};
+
#endif