1 /****************************************************************************** 2 * 3 * Copyright (C) 2012 Ittiam Systems Pvt Ltd, Bangalore 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 /** 19 ******************************************************************************* 20 * @file 21 * ihevc_platform_macros.h 22 * 23 * @brief 24 * Platform specific Macro definitions used in the codec 25 * 26 * @author 27 * Ittiam 28 * 29 * @remarks 30 * None 31 * 32 ******************************************************************************* 33 */ 34 #ifndef _IHEVC_PLATFORM_MACROS_H_ 35 #define _IHEVC_PLATFORM_MACROS_H_ 36 37 #ifndef ARMV8 38 static __inline WORD32 CLIP_U8(WORD32 x) 39 { 40 asm("usat %0, #8, %1" : "=r"(x) : "r"(x)); 41 return x; 42 } 43 44 static __inline WORD32 CLIP_S8(WORD32 x) 45 { 46 asm("ssat %0, #8, %1" : "=r"(x) : "r"(x)); 47 return x; 48 } 49 50 static __inline WORD32 CLIP_U10(WORD32 x) 51 { 52 asm("usat %0, #10, %1" : "=r"(x) : "r"(x)); 53 return x; 54 } 55 56 static __inline WORD32 CLIP_S10(WORD32 x) 57 { 58 asm("ssat %0, #10, %1" : "=r"(x) : "r"(x)); 59 return x; 60 } 61 62 static __inline WORD32 CLIP_U12(WORD32 x) 63 { 64 asm("usat %0, #12, %1" : "=r"(x) : "r"(x)); 65 return x; 66 } 67 68 static __inline WORD32 CLIP_S12(WORD32 x) 69 { 70 asm("ssat %0, #12, %1" : "=r"(x) : "r"(x)); 71 return x; 72 } 73 74 static __inline WORD32 CLIP_U14(WORD32 x) 75 { 76 asm("usat %0, #14, %1" : "=r"(x) : "r"(x)); 77 return x; 78 } 79 80 static __inline WORD32 CLIP_S14(WORD32 x) 81 { 82 asm("ssat %0, #14, %1" : "=r"(x) : "r"(x)); 83 return x; 84 } 85 86 static __inline WORD32 CLIP_U16(WORD32 x) 87 { 88 asm("usat %0, #16, %1" : "=r"(x) : "r"(x)); 89 return x; 90 } 91 static __inline WORD32 CLIP_S16(WORD32 x) 92 { 93 asm("ssat %0, #16, %1" : "=r"(x) : "r"(x)); 94 return x; 95 } 96 97 98 static __inline UWORD32 ITT_BIG_ENDIAN(UWORD32 x) 99 { 100 asm("rev %0, %1" : "=r"(x) : "r"(x)); 101 return x; 102 } 103 #else 104 105 #define CLIP_U8(x) CLIP3((x), 0, 255) 106 #define CLIP_S8(x) CLIP3((x), -128, 127) 107 108 #define CLIP_U10(x) CLIP3((x), 0, 1023); 109 #define CLIP_S10(x) CLIP3((x), -512, 511); 110 111 #define CLIP_U12(x) CLIP3((x), 0, 4095); 112 #define CLIP_S12(x) CLIP3((x), -2048, 2047); 113 114 #define CLIP_U14(x) CLIP3((x), 0, 16383); 115 #define CLIP_S14(x) CLIP3((x), -8192, 8191); 116 117 #define CLIP_U16(x) CLIP3((x), 0, 65535) 118 #define CLIP_S16(x) CLIP3((x), -32768, 32767) 119 120 #define ITT_BIG_ENDIAN(x) ((x & 0x000000ff) << 24) | \ 121 ((x & 0x0000ff00) << 8) | \ 122 ((x & 0x00ff0000) >> 8) | \ 123 ((UWORD32)x >> 24); 124 #endif 125 126 #define SHL(x,y) (((y) < 32) ? ((x) << (y)) : 0) 127 #define SHR(x,y) (((y) < 32) ? ((x) >> (y)) : 0) 128 129 #define SHR_NEG(val,shift) ((shift>0)?(val>>shift):(val<<(-shift))) 130 #define SHL_NEG(val,shift) ((shift<0)?(val>>(-shift)):(val<<shift)) 131 132 #define INLINE inline 133 134 #define POPCNT_U32(x) __builtin_popcount(x) 135 136 static INLINE UWORD32 CLZ(UWORD32 u4_word) 137 { 138 if(u4_word) 139 return (__builtin_clz(u4_word)); 140 else 141 return 31; 142 } 143 144 static INLINE UWORD32 CLZNZ(UWORD32 u4_word) 145 { 146 return (__builtin_clz(u4_word)); 147 } 148 149 static INLINE UWORD32 CTZ(UWORD32 u4_word) 150 { 151 if(0 == u4_word) 152 return 31; 153 else 154 { 155 unsigned int index; 156 index = __builtin_ctz(u4_word); 157 return (UWORD32)index; 158 } 159 } 160 161 #define DATA_SYNC() __sync_synchronize() 162 163 /** 164 ****************************************************************************** 165 * @brief returns postion of msb bit for 32bit input 166 ****************************************************************************** 167 */ 168 #define GET_POS_MSB_32(r,word) \ 169 { \ 170 if(word) \ 171 { \ 172 r = 31 - __builtin_clz(word); \ 173 } \ 174 else \ 175 { \ 176 r = -1; \ 177 } \ 178 } 179 180 /** 181 ****************************************************************************** 182 * @brief returns postion of msb bit for 64bit input 183 ****************************************************************************** 184 */ 185 #define GET_POS_MSB_64(r,word) \ 186 { \ 187 if(word) \ 188 { \ 189 r = 63 - __builtin_clzll(word); \ 190 } \ 191 else \ 192 { \ 193 r = -1; \ 194 } \ 195 } 196 197 198 /** 199 ****************************************************************************** 200 * @brief returns max number of bits required to represent input word (max 32bits) 201 ****************************************************************************** 202 */ 203 #define GETRANGE(r,word) \ 204 { \ 205 if(word) \ 206 { \ 207 r = 32 - __builtin_clz(word); \ 208 } \ 209 else \ 210 { \ 211 r = 1; \ 212 } \ 213 } 214 215 216 /** 217 ***************************************************************************************************** 218 * @brief returns max number of bits required to represent input unsigned long long word (max 64bits) 219 ***************************************************************************************************** 220 */ 221 #define GETRANGE64(r,llword) \ 222 { \ 223 if(llword) \ 224 { \ 225 r = 64 - __builtin_clzll(llword); \ 226 } \ 227 else \ 228 { \ 229 r = 1; \ 230 } \ 231 } 232 233 234 235 #define NOP(nop_cnt) {UWORD32 nop_i; for (nop_i = 0; nop_i < nop_cnt; nop_i++) asm("nop");} 236 237 238 239 #define MEM_ALIGN8 __attribute__ ((aligned (8))) 240 #define MEM_ALIGN16 __attribute__ ((aligned (16))) 241 #define MEM_ALIGN32 __attribute__ ((aligned (32))) 242 243 #endif /* _IHEVC_PLATFORM_MACROS_H_ */ 244