2 #include
"../clcmacro.h"
4 _CLC_OVERLOAD _CLC_DEF char sub_sat
(char x
, char y
) {
6 return convert_char_sat
(r);
9 _CLC_OVERLOAD _CLC_DEF uchar sub_sat
(uchar x
, uchar y
) {
11 return convert_uchar_sat
(r);
14 _CLC_OVERLOAD _CLC_DEF short sub_sat
(short x
, short y
) {
16 return convert_short_sat
(r);
19 _CLC_OVERLOAD _CLC_DEF ushort sub_sat
(ushort x
, ushort y
) {
21 return convert_ushort_sat
(r);
24 _CLC_OVERLOAD _CLC_DEF int sub_sat
(int x
, int y
) {
26 if
(__builtin_ssub_overflow(x, y
, &r
))
27 // The oveflow can only occur in the direction of the first operand
28 return x
> 0 ? INT_MAX
: INT_MIN
;
32 _CLC_OVERLOAD _CLC_DEF uint sub_sat
(uint x
, uint y
) {
34 if
(__builtin_usub_overflow(x, y
, &r
))
39 _CLC_OVERLOAD _CLC_DEF long sub_sat
(long x
, long y
) {
41 if
(__builtin_ssubl_overflow(x, y
, &r
))
42 // The oveflow can only occur in the direction of the first operand
43 return x
> 0 ? LONG_MAX
: LONG_MIN
;
47 _CLC_OVERLOAD _CLC_DEF ulong sub_sat
(ulong x
, ulong y
) {
49 if
(__builtin_usubl_overflow(x, y
, &r
))
54 _CLC_BINARY_VECTORIZE
(_CLC_OVERLOAD _CLC_DEF
, char
, sub_sat
, char
, char
)
55 _CLC_BINARY_VECTORIZE
(_CLC_OVERLOAD _CLC_DEF
, uchar
, sub_sat
, uchar
, uchar
)
56 _CLC_BINARY_VECTORIZE
(_CLC_OVERLOAD _CLC_DEF
, short
, sub_sat
, short
, short
)
57 _CLC_BINARY_VECTORIZE
(_CLC_OVERLOAD _CLC_DEF
, ushort
, sub_sat
, ushort
, ushort
)
58 _CLC_BINARY_VECTORIZE
(_CLC_OVERLOAD _CLC_DEF
, int
, sub_sat
, int
, int
)
59 _CLC_BINARY_VECTORIZE
(_CLC_OVERLOAD _CLC_DEF
, uint
, sub_sat
, uint
, uint
)
60 _CLC_BINARY_VECTORIZE
(_CLC_OVERLOAD _CLC_DEF
, long
, sub_sat
, long
, long
)
61 _CLC_BINARY_VECTORIZE
(_CLC_OVERLOAD _CLC_DEF
, ulong
, sub_sat
, ulong
, ulong
)