ih264_platform_macros.h revision 8ef4c3f6142028732a155cbfc1febd6ef5da72fd
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#ifndef  ARMV8
40
41static __inline WORD32 CLIP_U8(WORD32 x)
42{
43    asm("usat %0, #8, %1" : "=r"(x) : "r"(x));
44    return x;
45}
46
47static __inline WORD32 CLIP_S8(WORD32 x)
48{
49    asm("ssat %0, #8, %1" : "=r"(x) : "r"(x));
50    return x;
51}
52
53static __inline WORD32 CLIP_U10(WORD32 x)
54{
55    asm("usat %0, #10, %1" : "=r"(x) : "r"(x));
56    return x;
57}
58
59static __inline WORD32 CLIP_S10(WORD32 x)
60{
61    asm("ssat %0, #10, %1" : "=r"(x) : "r"(x));
62    return x;
63}
64
65static __inline WORD32 CLIP_U12(WORD32 x)
66{
67    asm("usat %0, #12, %1" : "=r"(x) : "r"(x));
68    return x;
69}
70
71static __inline WORD32 CLIP_S12(WORD32 x)
72{
73    asm("ssat %0, #12, %1" : "=r"(x) : "r"(x));
74    return x;
75}
76
77static __inline WORD32 CLIP_U16(WORD32 x)
78{
79    asm("usat %0, #16, %1" : "=r"(x) : "r"(x));
80    return x;
81}
82static __inline WORD32 CLIP_S16(WORD32 x)
83{
84    asm("ssat %0, #16, %1" : "=r"(x) : "r"(x));
85    return x;
86}
87
88
89static __inline UWORD32 ITT_BIG_ENDIAN(UWORD32 x)
90{
91    asm("rev %0, %1" : "=r"(x) : "r"(x));
92    return x;
93}
94#define NOP(nop_cnt)    {UWORD32 nop_i; for (nop_i = 0; nop_i < nop_cnt; nop_i++) asm("nop");}
95
96#else
97
98#define CLIP_U8(x) CLIP3(0, 255, (x))
99#define CLIP_S8(x) CLIP3(-128, 127, (x))
100
101#define CLIP_U10(x) CLIP3(0, 1023, (x))
102#define CLIP_S10(x) CLIP3(-512, 511, (x))
103
104#define CLIP_U12(x) CLIP3(0, 4095, (x))
105#define CLIP_S12(x) CLIP3(-2048, 2047, (x))
106
107#define CLIP_U16(x) CLIP3(0, 65535, (x))
108#define CLIP_S16(x) CLIP3(-32768, 32767, (x))
109
110#define ITT_BIG_ENDIAN(x)       __asm__("rev %0, %1" : "=r"(x) : "r"(x));
111
112#define NOP(nop_cnt)                                \
113{                                                   \
114    UWORD32 nop_i;                                  \
115    for (nop_i = 0; nop_i < nop_cnt; nop_i++)       \
116        __asm__ __volatile__("mov x0, x0");         \
117}
118
119#endif
120
121#define DATA_SYNC() __sync_synchronize()
122
123#define SHL(x,y) (((y) < 32) ? ((x) << (y)) : 0)
124#define SHR(x,y) (((y) < 32) ? ((x) >> (y)) : 0)
125
126#define SHR_NEG(val,shift)  ((shift>0)?(val>>shift):(val<<(-shift)))
127#define SHL_NEG(val,shift)  ((shift<0)?(val>>(-shift)):(val<<shift))
128
129#define INLINE inline
130
131static INLINE UWORD32 CLZ(UWORD32 u4_word)
132{
133    if(u4_word)
134        return (__builtin_clz(u4_word));
135    else
136        return 32;
137}
138static INLINE UWORD32 CTZ(UWORD32 u4_word)
139{
140    if(0 == u4_word)
141        return 31;
142    else
143    {
144        unsigned int index;
145        index = __builtin_ctz(u4_word);
146        return (UWORD32)index;
147    }
148}
149
150#define MEM_ALIGN8 __attribute__ ((aligned (8)))
151#define MEM_ALIGN16 __attribute__ ((aligned (16)))
152#define MEM_ALIGN32 __attribute__ ((aligned (32)))
153
154#endif /* _IH264_PLATFORM_MACROS_H_ */
155