File: sub_sat.cl

package info (click to toggle)
libclc 0.2.0%2Bgit20180917-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,552 kB
  • sloc: lisp: 13,186; ansic: 2,418; python: 647; cpp: 93; sh: 29; makefile: 10; pascal: 7
file content (61 lines) | stat: -rw-r--r-- 1,805 bytes parent folder | download | duplicates (21)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <clc/clc.h>
#include "../clcmacro.h"

_CLC_OVERLOAD _CLC_DEF char sub_sat(char x, char y) {
  short r = x - y;
  return convert_char_sat(r);
}

_CLC_OVERLOAD _CLC_DEF uchar sub_sat(uchar x, uchar y) {
  short r = x - y;
  return convert_uchar_sat(r);
}

_CLC_OVERLOAD _CLC_DEF short sub_sat(short x, short y) {
  int r = x - y;
  return convert_short_sat(r);
}

_CLC_OVERLOAD _CLC_DEF ushort sub_sat(ushort x, ushort y) {
  int r = x - y;
  return convert_ushort_sat(r);
}

_CLC_OVERLOAD _CLC_DEF int sub_sat(int x, int y) {
  int r;
  if (__builtin_ssub_overflow(x, y, &r))
    // The oveflow can only occur in the direction of the first operand
    return x > 0 ? INT_MAX : INT_MIN;
  return r;
}

_CLC_OVERLOAD _CLC_DEF uint sub_sat(uint x, uint y) {
  uint r;
  if (__builtin_usub_overflow(x, y, &r))
	return 0;
  return r;
}

_CLC_OVERLOAD _CLC_DEF long sub_sat(long x, long y) {
  long r;
  if (__builtin_ssubl_overflow(x, y, &r))
    // The oveflow can only occur in the direction of the first operand
    return x > 0 ? LONG_MAX : LONG_MIN;
  return r;
}

_CLC_OVERLOAD _CLC_DEF ulong sub_sat(ulong x, ulong y) {
  ulong r;
  if (__builtin_usubl_overflow(x, y, &r))
	return 0;
  return r;
}

_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, char, sub_sat, char, char)
_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, uchar, sub_sat, uchar, uchar)
_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, short, sub_sat, short, short)
_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, ushort, sub_sat, ushort, ushort)
_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, int, sub_sat, int, int)
_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, uint, sub_sat, uint, uint)
_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, long, sub_sat, long, long)
_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, ulong, sub_sat, ulong, ulong)