Home | History | Annotate | Download | only in cpu_ref
      1 /*
      2  * Copyright (C) 2012 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 
     17 
     18 
     19 typedef uint8_t uchar;
     20 typedef uint16_t ushort;
     21 typedef uint32_t uint;
     22 
     23 typedef float float2 __attribute__((ext_vector_type(2)));
     24 typedef float float3 __attribute__((ext_vector_type(3)));
     25 typedef float float4 __attribute__((ext_vector_type(4)));
     26 typedef uchar uchar2 __attribute__((ext_vector_type(2)));
     27 typedef uchar uchar3 __attribute__((ext_vector_type(3)));
     28 typedef uchar uchar4 __attribute__((ext_vector_type(4)));
     29 typedef ushort ushort2 __attribute__((ext_vector_type(2)));
     30 typedef ushort ushort3 __attribute__((ext_vector_type(3)));
     31 typedef ushort ushort4 __attribute__((ext_vector_type(4)));
     32 typedef uint uint2 __attribute__((ext_vector_type(2)));
     33 typedef uint uint3 __attribute__((ext_vector_type(3)));
     34 typedef uint uint4 __attribute__((ext_vector_type(4)));
     35 typedef char char2 __attribute__((ext_vector_type(2)));
     36 typedef char char3 __attribute__((ext_vector_type(3)));
     37 typedef char char4 __attribute__((ext_vector_type(4)));
     38 typedef short short2 __attribute__((ext_vector_type(2)));
     39 typedef short short3 __attribute__((ext_vector_type(3)));
     40 typedef short short4 __attribute__((ext_vector_type(4)));
     41 typedef int int2 __attribute__((ext_vector_type(2)));
     42 typedef int int3 __attribute__((ext_vector_type(3)));
     43 typedef int int4 __attribute__((ext_vector_type(4)));
     44 typedef long long2 __attribute__((ext_vector_type(2)));
     45 typedef long long3 __attribute__((ext_vector_type(3)));
     46 typedef long long4 __attribute__((ext_vector_type(4)));
     47 
     48 enum IntrinsicEnums {
     49     INTRINSIC_UNDEFINED,
     50     INTRINSIC_CONVOLVE_3x3,
     51     INTRINXIC_COLORMATRIX
     52 
     53 };
     54 
     55 #define CVT_FUNC_2(typeout, typein)                             \
     56 static inline typeout##2 __attribute__((const, overloadable))   \
     57     convert_##typeout##2(typein##2 i) {                         \
     58         typeout##2 f = {(typeout)i.x, (typeout)i.y};            \
     59         return f;                                               \
     60     }                                                           \
     61 static inline typeout##3 __attribute__((const, overloadable))   \
     62     convert_##typeout##3(typein##3 i) {                         \
     63         typeout##3 f = {(typeout)i.x, (typeout)i.y, (typeout)i.z}; \
     64         return f;                                               \
     65     }                                                           \
     66 static inline typeout##4 __attribute__((const, overloadable))   \
     67     convert_##typeout##4(typein##4 i) {                         \
     68         typeout##4 f = {(typeout)i.x, (typeout)i.y, (typeout)i.z, (typeout)i.w}; \
     69         return f;                                               \
     70     }
     71 #define CVT_FUNC(type)  CVT_FUNC_2(type, uchar)     \
     72                         CVT_FUNC_2(type, char)      \
     73                         CVT_FUNC_2(type, ushort)    \
     74                         CVT_FUNC_2(type, short)     \
     75                         CVT_FUNC_2(type, uint)      \
     76                         CVT_FUNC_2(type, int)       \
     77                         CVT_FUNC_2(type, float)
     78 CVT_FUNC(char)
     79 CVT_FUNC(uchar)
     80 CVT_FUNC(short)
     81 CVT_FUNC(ushort)
     82 CVT_FUNC(int)
     83 CVT_FUNC(uint)
     84 CVT_FUNC(float)
     85 
     86 
     87 static inline int4 clamp(int4 amount, int low, int high) {
     88     int4 r;
     89     r.x = amount.x < low ? low : (amount.x > high ? high : amount.x);
     90     r.y = amount.y < low ? low : (amount.y > high ? high : amount.y);
     91     r.z = amount.z < low ? low : (amount.z > high ? high : amount.z);
     92     r.w = amount.w < low ? low : (amount.w > high ? high : amount.w);
     93     return r;
     94 }
     95 
     96 static inline float4 clamp(float4 amount, float low, float high) {
     97     float4 r;
     98     r.x = amount.x < low ? low : (amount.x > high ? high : amount.x);
     99     r.y = amount.y < low ? low : (amount.y > high ? high : amount.y);
    100     r.z = amount.z < low ? low : (amount.z > high ? high : amount.z);
    101     r.w = amount.w < low ? low : (amount.w > high ? high : amount.w);
    102     return r;
    103 }
    104 
    105 static inline int2 clamp(int2 amount, int low, int high) {
    106     int2 r;
    107     r.x = amount.x < low ? low : (amount.x > high ? high : amount.x);
    108     r.y = amount.y < low ? low : (amount.y > high ? high : amount.y);
    109     return r;
    110 }
    111 
    112 static inline float2 clamp(float2 amount, float low, float high) {
    113     float2 r;
    114     r.x = amount.x < low ? low : (amount.x > high ? high : amount.x);
    115     r.y = amount.y < low ? low : (amount.y > high ? high : amount.y);
    116     return r;
    117 }
    118 
    119 static inline int clamp(int amount, int low, int high) {
    120     return amount < low ? low : (amount > high ? high : amount);
    121 }
    122 
    123 static inline float clamp(float amount, float low, float high) {
    124     return amount < low ? low : (amount > high ? high : amount);
    125 }
    126 
    127