xref: /aosp_15_r20/frameworks/rs/cpu_ref/rsCpuIntrinsicInlines.h (revision e1eccf28f96817838ad6867f7f39d2351ec11f56)
1*e1eccf28SAndroid Build Coastguard Worker /*
2*e1eccf28SAndroid Build Coastguard Worker  * Copyright (C) 2012 The Android Open Source Project
3*e1eccf28SAndroid Build Coastguard Worker  *
4*e1eccf28SAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*e1eccf28SAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*e1eccf28SAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*e1eccf28SAndroid Build Coastguard Worker  *
8*e1eccf28SAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*e1eccf28SAndroid Build Coastguard Worker  *
10*e1eccf28SAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*e1eccf28SAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*e1eccf28SAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*e1eccf28SAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*e1eccf28SAndroid Build Coastguard Worker  * limitations under the License.
15*e1eccf28SAndroid Build Coastguard Worker  */
16*e1eccf28SAndroid Build Coastguard Worker 
17*e1eccf28SAndroid Build Coastguard Worker 
18*e1eccf28SAndroid Build Coastguard Worker 
19*e1eccf28SAndroid Build Coastguard Worker typedef uint8_t uchar;
20*e1eccf28SAndroid Build Coastguard Worker typedef uint16_t ushort;
21*e1eccf28SAndroid Build Coastguard Worker typedef uint32_t uint;
22*e1eccf28SAndroid Build Coastguard Worker 
23*e1eccf28SAndroid Build Coastguard Worker typedef float float2 __attribute__((ext_vector_type(2)));
24*e1eccf28SAndroid Build Coastguard Worker typedef float float3 __attribute__((ext_vector_type(3)));
25*e1eccf28SAndroid Build Coastguard Worker typedef float float4 __attribute__((ext_vector_type(4)));
26*e1eccf28SAndroid Build Coastguard Worker typedef uchar uchar2 __attribute__((ext_vector_type(2)));
27*e1eccf28SAndroid Build Coastguard Worker typedef uchar uchar3 __attribute__((ext_vector_type(3)));
28*e1eccf28SAndroid Build Coastguard Worker typedef uchar uchar4 __attribute__((ext_vector_type(4)));
29*e1eccf28SAndroid Build Coastguard Worker typedef ushort ushort2 __attribute__((ext_vector_type(2)));
30*e1eccf28SAndroid Build Coastguard Worker typedef ushort ushort3 __attribute__((ext_vector_type(3)));
31*e1eccf28SAndroid Build Coastguard Worker typedef ushort ushort4 __attribute__((ext_vector_type(4)));
32*e1eccf28SAndroid Build Coastguard Worker typedef uint uint2 __attribute__((ext_vector_type(2)));
33*e1eccf28SAndroid Build Coastguard Worker typedef uint uint3 __attribute__((ext_vector_type(3)));
34*e1eccf28SAndroid Build Coastguard Worker typedef uint uint4 __attribute__((ext_vector_type(4)));
35*e1eccf28SAndroid Build Coastguard Worker typedef char char2 __attribute__((ext_vector_type(2)));
36*e1eccf28SAndroid Build Coastguard Worker typedef char char3 __attribute__((ext_vector_type(3)));
37*e1eccf28SAndroid Build Coastguard Worker typedef char char4 __attribute__((ext_vector_type(4)));
38*e1eccf28SAndroid Build Coastguard Worker typedef short short2 __attribute__((ext_vector_type(2)));
39*e1eccf28SAndroid Build Coastguard Worker typedef short short3 __attribute__((ext_vector_type(3)));
40*e1eccf28SAndroid Build Coastguard Worker typedef short short4 __attribute__((ext_vector_type(4)));
41*e1eccf28SAndroid Build Coastguard Worker typedef int int2 __attribute__((ext_vector_type(2)));
42*e1eccf28SAndroid Build Coastguard Worker typedef int int3 __attribute__((ext_vector_type(3)));
43*e1eccf28SAndroid Build Coastguard Worker typedef int int4 __attribute__((ext_vector_type(4)));
44*e1eccf28SAndroid Build Coastguard Worker typedef long long2 __attribute__((ext_vector_type(2)));
45*e1eccf28SAndroid Build Coastguard Worker typedef long long3 __attribute__((ext_vector_type(3)));
46*e1eccf28SAndroid Build Coastguard Worker typedef long long4 __attribute__((ext_vector_type(4)));
47*e1eccf28SAndroid Build Coastguard Worker 
48*e1eccf28SAndroid Build Coastguard Worker enum IntrinsicEnums {
49*e1eccf28SAndroid Build Coastguard Worker     INTRINSIC_UNDEFINED,
50*e1eccf28SAndroid Build Coastguard Worker     INTRINSIC_CONVOLVE_3x3,
51*e1eccf28SAndroid Build Coastguard Worker     INTRINXIC_COLORMATRIX
52*e1eccf28SAndroid Build Coastguard Worker 
53*e1eccf28SAndroid Build Coastguard Worker };
54*e1eccf28SAndroid Build Coastguard Worker 
55*e1eccf28SAndroid Build Coastguard Worker #define CVT_FUNC_2(typeout, typein)                             \
56*e1eccf28SAndroid Build Coastguard Worker static inline typeout##2 __attribute__((const, overloadable))   \
57*e1eccf28SAndroid Build Coastguard Worker     convert_##typeout##2(typein##2 i) {                         \
58*e1eccf28SAndroid Build Coastguard Worker         return __builtin_convertvector(i, typeout##2);          \
59*e1eccf28SAndroid Build Coastguard Worker     }                                                           \
60*e1eccf28SAndroid Build Coastguard Worker static inline typeout##3 __attribute__((const, overloadable))   \
61*e1eccf28SAndroid Build Coastguard Worker     convert_##typeout##3(typein##3 i) {                         \
62*e1eccf28SAndroid Build Coastguard Worker         return __builtin_convertvector(i, typeout##3);          \
63*e1eccf28SAndroid Build Coastguard Worker     }                                                           \
64*e1eccf28SAndroid Build Coastguard Worker static inline typeout##4 __attribute__((const, overloadable))   \
65*e1eccf28SAndroid Build Coastguard Worker     convert_##typeout##4(typein##4 i) {                         \
66*e1eccf28SAndroid Build Coastguard Worker         return __builtin_convertvector(i, typeout##4);          \
67*e1eccf28SAndroid Build Coastguard Worker     }
68*e1eccf28SAndroid Build Coastguard Worker #define CVT_FUNC(type)  CVT_FUNC_2(type, uchar)     \
69*e1eccf28SAndroid Build Coastguard Worker                         CVT_FUNC_2(type, char)      \
70*e1eccf28SAndroid Build Coastguard Worker                         CVT_FUNC_2(type, ushort)    \
71*e1eccf28SAndroid Build Coastguard Worker                         CVT_FUNC_2(type, short)     \
72*e1eccf28SAndroid Build Coastguard Worker                         CVT_FUNC_2(type, uint)      \
73*e1eccf28SAndroid Build Coastguard Worker                         CVT_FUNC_2(type, int)       \
74*e1eccf28SAndroid Build Coastguard Worker                         CVT_FUNC_2(type, float)
75*e1eccf28SAndroid Build Coastguard Worker 
76*e1eccf28SAndroid Build Coastguard Worker CVT_FUNC(char)
CVT_FUNC(uchar)77*e1eccf28SAndroid Build Coastguard Worker CVT_FUNC(uchar)
78*e1eccf28SAndroid Build Coastguard Worker CVT_FUNC(short)
79*e1eccf28SAndroid Build Coastguard Worker CVT_FUNC(ushort)
80*e1eccf28SAndroid Build Coastguard Worker CVT_FUNC(int)
81*e1eccf28SAndroid Build Coastguard Worker CVT_FUNC(uint)
82*e1eccf28SAndroid Build Coastguard Worker CVT_FUNC(float)
83*e1eccf28SAndroid Build Coastguard Worker 
84*e1eccf28SAndroid Build Coastguard Worker 
85*e1eccf28SAndroid Build Coastguard Worker static inline int4 clamp(int4 amount, int low, int high) {
86*e1eccf28SAndroid Build Coastguard Worker     int4 r;
87*e1eccf28SAndroid Build Coastguard Worker     r.x = amount.x < low ? low : (amount.x > high ? high : amount.x);
88*e1eccf28SAndroid Build Coastguard Worker     r.y = amount.y < low ? low : (amount.y > high ? high : amount.y);
89*e1eccf28SAndroid Build Coastguard Worker     r.z = amount.z < low ? low : (amount.z > high ? high : amount.z);
90*e1eccf28SAndroid Build Coastguard Worker     r.w = amount.w < low ? low : (amount.w > high ? high : amount.w);
91*e1eccf28SAndroid Build Coastguard Worker     return r;
92*e1eccf28SAndroid Build Coastguard Worker }
93*e1eccf28SAndroid Build Coastguard Worker 
clamp(float4 amount,float low,float high)94*e1eccf28SAndroid Build Coastguard Worker static inline float4 clamp(float4 amount, float low, float high) {
95*e1eccf28SAndroid Build Coastguard Worker     float4 r;
96*e1eccf28SAndroid Build Coastguard Worker     r.x = amount.x < low ? low : (amount.x > high ? high : amount.x);
97*e1eccf28SAndroid Build Coastguard Worker     r.y = amount.y < low ? low : (amount.y > high ? high : amount.y);
98*e1eccf28SAndroid Build Coastguard Worker     r.z = amount.z < low ? low : (amount.z > high ? high : amount.z);
99*e1eccf28SAndroid Build Coastguard Worker     r.w = amount.w < low ? low : (amount.w > high ? high : amount.w);
100*e1eccf28SAndroid Build Coastguard Worker     return r;
101*e1eccf28SAndroid Build Coastguard Worker }
102*e1eccf28SAndroid Build Coastguard Worker 
clamp(int2 amount,int low,int high)103*e1eccf28SAndroid Build Coastguard Worker static inline int2 clamp(int2 amount, int low, int high) {
104*e1eccf28SAndroid Build Coastguard Worker     int2 r;
105*e1eccf28SAndroid Build Coastguard Worker     r.x = amount.x < low ? low : (amount.x > high ? high : amount.x);
106*e1eccf28SAndroid Build Coastguard Worker     r.y = amount.y < low ? low : (amount.y > high ? high : amount.y);
107*e1eccf28SAndroid Build Coastguard Worker     return r;
108*e1eccf28SAndroid Build Coastguard Worker }
109*e1eccf28SAndroid Build Coastguard Worker 
clamp(float2 amount,float low,float high)110*e1eccf28SAndroid Build Coastguard Worker static inline float2 clamp(float2 amount, float low, float high) {
111*e1eccf28SAndroid Build Coastguard Worker     float2 r;
112*e1eccf28SAndroid Build Coastguard Worker     r.x = amount.x < low ? low : (amount.x > high ? high : amount.x);
113*e1eccf28SAndroid Build Coastguard Worker     r.y = amount.y < low ? low : (amount.y > high ? high : amount.y);
114*e1eccf28SAndroid Build Coastguard Worker     return r;
115*e1eccf28SAndroid Build Coastguard Worker }
116*e1eccf28SAndroid Build Coastguard Worker 
clamp(int amount,int low,int high)117*e1eccf28SAndroid Build Coastguard Worker static inline int clamp(int amount, int low, int high) {
118*e1eccf28SAndroid Build Coastguard Worker     return amount < low ? low : (amount > high ? high : amount);
119*e1eccf28SAndroid Build Coastguard Worker }
120*e1eccf28SAndroid Build Coastguard Worker 
clamp(float amount,float low,float high)121*e1eccf28SAndroid Build Coastguard Worker static inline float clamp(float amount, float low, float high) {
122*e1eccf28SAndroid Build Coastguard Worker     return amount < low ? low : (amount > high ? high : amount);
123*e1eccf28SAndroid Build Coastguard Worker }
124*e1eccf28SAndroid Build Coastguard Worker 
125