• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  * Copyright (C) 2015 The Android Open Source Project
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  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19 */
20 /**
21 *******************************************************************************
22 * @file
23 *  ih264_platform_macros.h
24 *
25 * @brief
26 *  Platform specific Macro definitions used in the codec
27 *
28 * @author
29 *  Ittiam
30 *
31 * @remarks
32 *  None
33 *
34 *******************************************************************************
35 */
36 #ifndef _IH264_PLATFORM_MACROS_H_
37 #define _IH264_PLATFORM_MACROS_H_
38 
39 #include <stdint.h>
40 
41 #ifndef  ARMV8
42 
CLIP_U8(WORD32 x)43 static __inline WORD32 CLIP_U8(WORD32 x)
44 {
45     asm("usat %0, #8, %1" : "=r"(x) : "r"(x));
46     return x;
47 }
48 
CLIP_S8(WORD32 x)49 static __inline WORD32 CLIP_S8(WORD32 x)
50 {
51     asm("ssat %0, #8, %1" : "=r"(x) : "r"(x));
52     return x;
53 }
54 
CLIP_U10(WORD32 x)55 static __inline WORD32 CLIP_U10(WORD32 x)
56 {
57     asm("usat %0, #10, %1" : "=r"(x) : "r"(x));
58     return x;
59 }
60 
CLIP_S10(WORD32 x)61 static __inline WORD32 CLIP_S10(WORD32 x)
62 {
63     asm("ssat %0, #10, %1" : "=r"(x) : "r"(x));
64     return x;
65 }
66 
CLIP_U11(WORD32 x)67 static __inline WORD32 CLIP_U11(WORD32 x)
68 {
69     asm("usat %0, #11, %1" : "=r"(x) : "r"(x));
70     return x;
71 }
72 
CLIP_S11(WORD32 x)73 static __inline WORD32 CLIP_S11(WORD32 x)
74 {
75     asm("ssat %0, #11, %1" : "=r"(x) : "r"(x));
76     return x;
77 }
78 
CLIP_U12(WORD32 x)79 static __inline WORD32 CLIP_U12(WORD32 x)
80 {
81     asm("usat %0, #12, %1" : "=r"(x) : "r"(x));
82     return x;
83 }
84 
CLIP_S12(WORD32 x)85 static __inline WORD32 CLIP_S12(WORD32 x)
86 {
87     asm("ssat %0, #12, %1" : "=r"(x) : "r"(x));
88     return x;
89 }
90 
CLIP_U16(WORD32 x)91 static __inline WORD32 CLIP_U16(WORD32 x)
92 {
93     asm("usat %0, #16, %1" : "=r"(x) : "r"(x));
94     return x;
95 }
CLIP_S16(WORD32 x)96 static __inline WORD32 CLIP_S16(WORD32 x)
97 {
98     asm("ssat %0, #16, %1" : "=r"(x) : "r"(x));
99     return x;
100 }
101 
102 
ITT_BIG_ENDIAN(UWORD32 x)103 static __inline UWORD32 ITT_BIG_ENDIAN(UWORD32 x)
104 {
105     asm("rev %0, %1" : "=r"(x) : "r"(x));
106     return x;
107 }
108 #define NOP(nop_cnt)    {UWORD32 nop_i; for (nop_i = 0; nop_i < nop_cnt; nop_i++) asm("nop");}
109 
110 #else
111 
112 #define CLIP_U8(x) CLIP3(0, UINT8_MAX, (x))
113 #define CLIP_S8(x) CLIP3(INT8_MIN, INT8_MAX, (x))
114 
115 #define CLIP_U10(x) CLIP3(0, 1023, (x))
116 #define CLIP_S10(x) CLIP3(-512, 511, (x))
117 
118 #define CLIP_U11(x) CLIP3(0, 2047, (x))
119 #define CLIP_S11(x) CLIP3(-1024, 1023, (x))
120 
121 #define CLIP_U12(x) CLIP3(0, 4095, (x))
122 #define CLIP_S12(x) CLIP3(-2048, 2047, (x))
123 
124 #define CLIP_U16(x) CLIP3(0, UINT16_MAX, (x))
125 #define CLIP_S16(x) CLIP3(INT16_MIN, INT16_MAX, (x))
126 
127 #define ITT_BIG_ENDIAN(x)       __asm__("rev %0, %1" : "=r"(x) : "r"(x));
128 
129 #define NOP(nop_cnt)                                \
130 {                                                   \
131     UWORD32 nop_i;                                  \
132     for (nop_i = 0; nop_i < nop_cnt; nop_i++)       \
133         __asm__ __volatile__("mov x0, x0");         \
134 }
135 
136 #endif
137 
138 /*saturating instructions are not available for WORD64 in ARMv7, hence we cannot
139  * use inline assembly like other clips*/
140 #define CLIP_U32(x) CLIP3(0, UINT32_MAX, (x))
141 #define CLIP_S32(x) CLIP3(INT32_MIN, INT32_MAX, (x))
142 
143 #define DATA_SYNC() __sync_synchronize()
144 
145 #define SHL(x,y) (((y) < 32) ? ((x) << (y)) : 0)
146 #define SHR(x,y) (((y) < 32) ? ((x) >> (y)) : 0)
147 
148 #define SHR_NEG(val,shift)  ((shift>0)?(val>>shift):(val<<(-shift)))
149 #define SHL_NEG(val,shift)  ((shift<0)?(val>>(-shift)):(val<<shift))
150 
151 #define INLINE inline
152 
153 /* In normal cases, 0 will not be passed as an argument to CLZ and CTZ.
154 As CLZ and CTZ outputs are used as a shift value in few places, these return
155 31 for u4_word == 0 case, just to handle error cases gracefully without any
156 undefined behaviour */
157 
CLZ(UWORD32 u4_word)158 static INLINE UWORD32 CLZ(UWORD32 u4_word)
159 {
160     if(u4_word)
161         return (__builtin_clz(u4_word));
162     else
163         return 31;
164 }
CTZ(UWORD32 u4_word)165 static INLINE UWORD32 CTZ(UWORD32 u4_word)
166 {
167     if(0 == u4_word)
168         return 31;
169     else
170     {
171         unsigned int index;
172         index = __builtin_ctz(u4_word);
173         return (UWORD32)index;
174     }
175 }
176 
177 #define MEM_ALIGN8 __attribute__ ((aligned (8)))
178 #define MEM_ALIGN16 __attribute__ ((aligned (16)))
179 #define MEM_ALIGN32 __attribute__ ((aligned (32)))
180 
181 #endif /* _IH264_PLATFORM_MACROS_H_ */
182