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
37
38 #ifndef _IH264_PLATFORM_MACROS_H_
39 #define _IH264_PLATFORM_MACROS_H_
40
41 #include <stdint.h>
42 #include <immintrin.h>
43
44 #ifndef __ANDROID__
45 static __inline__ __m128i
loadu_32(void const * __a)46 loadu_32(void const *__a)
47 {
48 struct __loadu_si32 {
49 int __v;
50 } __attribute__((__packed__, __may_alias__));
51 int __u = ((struct __loadu_si32*)__a)->__v;
52 return __extension__ (__m128i)(__v4si){__u, 0, 0, 0};
53 }
54 #else
loadu_32(void const * __a)55 static __inline__ __m128i loadu_32(void const *__a) { return _mm_loadu_si32(__a); };
56 #endif
57
58 #define CLIP_U8(x) CLIP3(0, UINT8_MAX, (x))
59 #define CLIP_S8(x) CLIP3(INT8_MIN, INT8_MAX, (x))
60
61 #define CLIP_U10(x) CLIP3(0, 1023, (x))
62 #define CLIP_S10(x) CLIP3(-512, 511, (x))
63
64 #define CLIP_U11(x) CLIP3(0, 2047, (x))
65 #define CLIP_S11(x) CLIP3(-1024, 1023, (x))
66
67 #define CLIP_U12(x) CLIP3(0, 4095, (x))
68 #define CLIP_S12(x) CLIP3(-2048, 2047, (x))
69
70 #define CLIP_U16(x) CLIP3(0, UINT16_MAX, (x))
71 #define CLIP_S16(x) CLIP3(INT16_MIN, INT16_MAX, (x))
72
73 #define CLIP_U32(x) CLIP3(0, UINT32_MAX, (x))
74 #define CLIP_S32(x) CLIP3(INT32_MIN, INT32_MAX, (x))
75
76 #define MEM_ALIGN16 __attribute__ ((aligned (16)))
77
78 #define SHL(x,y) (((y) < 32) ? ((x) << (y)) : 0)
79 #define SHR(x,y) (((y) < 32) ? ((x) >> (y)) : 0)
80
81 #define SHR_NEG(val,shift) ((shift>0)?(val>>shift):(val<<(-shift)))
82 #define SHL_NEG(val,shift) ((shift<0)?(val>>(-shift)):(val<<shift))
83
84
85 #define ITT_BIG_ENDIAN(x) __builtin_bswap32(x);
86
87 #define NOP(nop_cnt) {UWORD32 nop_i; for (nop_i = 0; nop_i < nop_cnt; nop_i++) asm("nop");}
88
89 #define PLD(a)
90
91 /* In normal cases, 0 will not be passed as an argument to CLZ and CTZ.
92 As CLZ and CTZ outputs are used as a shift value in few places, these return
93 31 for u4_word == 0 case, just to handle error cases gracefully without any
94 undefined behaviour */
95
CLZ(UWORD32 u4_word)96 static __inline UWORD32 CLZ(UWORD32 u4_word)
97 {
98 if(u4_word)
99 return(__builtin_clz(u4_word));
100 else
101 return 31;
102 }
103
CTZ(UWORD32 u4_word)104 static __inline UWORD32 CTZ(UWORD32 u4_word)
105 {
106 if(0 == u4_word)
107 return 31;
108 else
109 {
110 unsigned int index;
111 index = __builtin_ctz(u4_word);
112 return (UWORD32)index;
113 }
114 }
115
116 #define DATA_SYNC() __sync_synchronize()
117
118
119
120 //#define INLINE __inline
121 #define INLINE inline
122
123 #define PREFETCH_ENABLE 1
124
125 #if PREFETCH_ENABLE
126 #define PREFETCH(ptr, type) _mm_prefetch(ptr, type);
127 #else
128 #define PREFETCH(ptr, type)
129 #endif
130
131 #define MEM_ALIGN8 __attribute__ ((aligned (8)))
132 #define MEM_ALIGN16 __attribute__ ((aligned (16)))
133 #define MEM_ALIGN32 __attribute__ ((aligned (32)))
134
135 #endif /* _IH264_PLATFORM_MACROS_H_ */
136