blob: 86d6f96fb69b72efbd73ac36b70003ab1a20d2bf [file] [log] [blame]
Stephen Hines5a470202013-05-29 15:36:18 -07001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jean-Luc Brouilletbe216382015-03-22 12:44:27 -070017#include "rs_core.rsh"
Stephen Hines5a470202013-05-29 15:36:18 -070018
Jason Samsd8b8f8a2014-08-19 17:53:08 -070019typedef unsigned long long ull;
20typedef unsigned long long ull2 __attribute__((ext_vector_type(2)));
21typedef unsigned long long ull3 __attribute__((ext_vector_type(3)));
22typedef unsigned long long ull4 __attribute__((ext_vector_type(4)));
23
Stephen Hines5a470202013-05-29 15:36:18 -070024#define S_CLAMP(T) \
25extern T __attribute__((overloadable)) clamp(T amount, T low, T high) { \
26 return amount < low ? low : (amount > high ? high : amount); \
27}
28
29//_CLAMP(float); implemented in .ll
30S_CLAMP(double);
31S_CLAMP(char);
32S_CLAMP(uchar);
33S_CLAMP(short);
34S_CLAMP(ushort);
35S_CLAMP(int);
36S_CLAMP(uint);
37S_CLAMP(long);
38S_CLAMP(ulong);
39
40#undef S_CLAMP
41
42
43 \
44#define V_CLAMP(T) \
45extern T##2 __attribute__((overloadable)) clamp(T##2 amount, T##2 low, T##2 high) { \
46 T##2 r; \
47 r.x = amount.x < low.x ? low.x : (amount.x > high.x ? high.x : amount.x); \
48 r.y = amount.y < low.y ? low.y : (amount.y > high.y ? high.y : amount.y); \
49 return r; \
50} \
51 \
52extern T##3 __attribute__((overloadable)) clamp(T##3 amount, T##3 low, T##3 high) { \
53 T##3 r; \
54 r.x = amount.x < low.x ? low.x : (amount.x > high.x ? high.x : amount.x); \
55 r.y = amount.y < low.y ? low.y : (amount.y > high.y ? high.y : amount.y); \
56 r.z = amount.z < low.z ? low.z : (amount.z > high.z ? high.z : amount.z); \
57 return r; \
58} \
59 \
60extern T##4 __attribute__((overloadable)) clamp(T##4 amount, T##4 low, T##4 high) { \
61 T##4 r; \
62 r.x = amount.x < low.x ? low.x : (amount.x > high.x ? high.x : amount.x); \
63 r.y = amount.y < low.y ? low.y : (amount.y > high.y ? high.y : amount.y); \
64 r.z = amount.z < low.z ? low.z : (amount.z > high.z ? high.z : amount.z); \
65 r.w = amount.w < low.w ? low.w : (amount.w > high.w ? high.w : amount.w); \
66 return r; \
67} \
68 \
69extern T##2 __attribute__((overloadable)) clamp(T##2 amount, T low, T high) { \
70 T##2 r; \
71 r.x = amount.x < low ? low : (amount.x > high ? high : amount.x); \
72 r.y = amount.y < low ? low : (amount.y > high ? high : amount.y); \
73 return r; \
74} \
75 \
76extern T##3 __attribute__((overloadable)) clamp(T##3 amount, T low, T high) { \
77 T##3 r; \
78 r.x = amount.x < low ? low : (amount.x > high ? high : amount.x); \
79 r.y = amount.y < low ? low : (amount.y > high ? high : amount.y); \
80 r.z = amount.z < low ? low : (amount.z > high ? high : amount.z); \
81 return r; \
82} \
83 \
84extern T##4 __attribute__((overloadable)) clamp(T##4 amount, T low, T high) { \
85 T##4 r; \
86 r.x = amount.x < low ? low : (amount.x > high ? high : amount.x); \
87 r.y = amount.y < low ? low : (amount.y > high ? high : amount.y); \
88 r.z = amount.z < low ? low : (amount.z > high ? high : amount.z); \
89 r.w = amount.w < low ? low : (amount.w > high ? high : amount.w); \
90 return r; \
91}
92
93//V_CLAMP(float); implemented in .ll
94V_CLAMP(double);
95V_CLAMP(char);
96V_CLAMP(uchar);
97V_CLAMP(short);
98V_CLAMP(ushort);
Tim Murray97446772014-08-26 12:59:17 -070099#if !defined(ARCH_ARM_HAVE_NEON) && !defined (ARCH_ARM64_HAVE_NEON)
Stephen Hines5a470202013-05-29 15:36:18 -0700100 V_CLAMP(int); //implemented in .ll
101 V_CLAMP(uint); //implemented in .ll
102#endif
Tim Murray97446772014-08-26 12:59:17 -0700103
Stephen Hines5a470202013-05-29 15:36:18 -0700104V_CLAMP(long);
105V_CLAMP(ulong);
Jason Samsd8b8f8a2014-08-19 17:53:08 -0700106V_CLAMP(ull);
Stephen Hines5a470202013-05-29 15:36:18 -0700107
108#undef _CLAMP