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_U16(WORD32 x) 75 { 76 asm("usat %0, #16, %1" : "=r"(x) : "r"(x)); 77 return x; 78 } 79 static __inline WORD32 CLIP_S16(WORD32 x) 80 { 81 asm("ssat %0, #16, %1" : "=r"(x) : "r"(x)); 82 return x; 83 } 84 85 86 static __inline UWORD32 ITT_BIG_ENDIAN(UWORD32 x) 87 { 88 asm("rev %0, %1" : "=r"(x) : "r"(x)); 89 return x; 90 } 91 #else 92 93 #define CLIP_U8(x) CLIP3((x), 0, 255) 94 #define CLIP_S8(x) CLIP3((x), -128, 127) 95 96 #define CLIP_U10(x) CLIP3((x), 0, 1023); 97 #define CLIP_S10(x) CLIP3((x), -512, 511); 98 99 #define CLIP_U12(x) CLIP3((x), 0, 4095); 100 #define CLIP_S12(x) CLIP3((x), -2048, 2047); 101 102 #define CLIP_U16(x) CLIP3((x), 0, 65535) 103 #define CLIP_S16(x) CLIP3((x), -32768, 32767) 104 105 #define ITT_BIG_ENDIAN(x) ((x & 0x000000ff) << 24) | \ 106 ((x & 0x0000ff00) << 8) | \ 107 ((x & 0x00ff0000) >> 8) | \ 108 ((UWORD32)x >> 24); 109 #endif 110 111 #define SHL(x,y) (((y) < 32) ? ((x) << (y)) : 0) 112 #define SHR(x,y) (((y) < 32) ? ((x) >> (y)) : 0) 113 114 #define SHR_NEG(val,shift) ((shift>0)?(val>>shift):(val<<(-shift))) 115 #define SHL_NEG(val,shift) ((shift<0)?(val>>(-shift)):(val<<shift)) 116 117 #define INLINE inline 118 119 #define POPCNT_U32(x) __builtin_popcount(x) 120 121 static INLINE UWORD32 CLZ(UWORD32 u4_word) 122 { 123 if(u4_word) 124 return (__builtin_clz(u4_word)); 125 else 126 return 32; 127 } 128 129 static INLINE UWORD32 CLZNZ(UWORD32 u4_word) 130 { 131 return (__builtin_clz(u4_word)); 132 } 133 134 static INLINE UWORD32 CTZ(UWORD32 u4_word) 135 { 136 if(0 == u4_word) 137 return 31; 138 else 139 { 140 unsigned int index; 141 index = __builtin_ctz(u4_word); 142 return (UWORD32)index; 143 } 144 } 145 146 #define DATA_SYNC() __sync_synchronize() 147 148 /** 149 ****************************************************************************** 150 * @brief returns postion of msb bit for 32bit input 151 ****************************************************************************** 152 */ 153 #define GET_POS_MSB_32(r,word) \ 154 { \ 155 if(word) \ 156 { \ 157 r = 31 - __builtin_clz(word); \ 158 } \ 159 else \ 160 { \ 161 r = -1; \ 162 } \ 163 } 164 165 /** 166 ****************************************************************************** 167 * @brief returns postion of msb bit for 64bit input 168 ****************************************************************************** 169 */ 170 #define GET_POS_MSB_64(r,word) \ 171 { \ 172 if(word) \ 173 { \ 174 r = 63 - __builtin_clzll(word); \ 175 } \ 176 else \ 177 { \ 178 r = -1; \ 179 } \ 180 } 181 182 183 /** 184 ****************************************************************************** 185 * @brief returns max number of bits required to represent input word (max 32bits) 186 ****************************************************************************** 187 */ 188 #define GETRANGE(r,word) \ 189 { \ 190 if(word) \ 191 { \ 192 r = 32 - __builtin_clz(word); \ 193 } \ 194 else \ 195 { \ 196 r = 1; \ 197 } \ 198 } 199 200 #if 0 /* Equivalent C code for GETRANGE */ 201 #define GETRANGE(r,word) \ 202 { \ 203 UWORD32 temp; \ 204 r = 0; \ 205 temp = (UWORD32)word; \ 206 if(0 == word) \ 207 r = 1; \ 208 else \ 209 { \ 210 while(temp) \ 211 { \ 212 temp >>= 1; \ 213 r++; \ 214 } \ 215 }\ 216 } 217 #endif 218 219 220 221 #define NOP(nop_cnt) {UWORD32 nop_i; for (nop_i = (nop_cnt) ; nop_i > 0 ; nop_i--) asm("nop");} 222 223 224 225 #define MEM_ALIGN8 __attribute__ ((aligned (8))) 226 #define MEM_ALIGN16 __attribute__ ((aligned (16))) 227 #define MEM_ALIGN32 __attribute__ ((aligned (32))) 228 229 #endif /* _IHEVC_PLATFORM_MACROS_H_ */ 230