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 <immintrin.h>
42
43
44#define CLIP_U8(x) CLIP3(0, 255, (x))
45#define CLIP_S8(x) CLIP3(-128, 127, (x))
46
47#define CLIP_U10(x) CLIP3(0, 1023, (x))
48#define CLIP_S10(x) CLIP3(-512, 511, (x))
49
50#define CLIP_U12(x) CLIP3(0, 4095, (x))
51#define CLIP_S12(x) CLIP3(-2048, 2047, (x))
52
53#define CLIP_U16(x) CLIP3(0, 65535, (x))
54#define CLIP_S16(x) CLIP3(-32768, 32767, (x))
55
56#define MEM_ALIGN16 __attribute__ ((aligned (16)))
57
58#define SHL(x,y) (((y) < 32) ? ((x) << (y)) : 0)
59#define SHR(x,y) (((y) < 32) ? ((x) >> (y)) : 0)
60
61#define SHR_NEG(val,shift)  ((shift>0)?(val>>shift):(val<<(-shift)))
62#define SHL_NEG(val,shift)  ((shift<0)?(val>>(-shift)):(val<<shift))
63
64
65#define ITT_BIG_ENDIAN(x)   __builtin_bswap32(x);
66
67#define NOP(nop_cnt) {UWORD32 nop_i; for (nop_i = 0; nop_i < nop_cnt; nop_i++) asm("nop");}
68
69#define PLD(a)
70
71static __inline UWORD32 CLZ(UWORD32 u4_word)
72{
73    if(u4_word)
74    return(__builtin_clz(u4_word));
75    else
76        return 32;
77}
78
79static __inline UWORD32 CTZ(UWORD32 u4_word)
80{
81    if(0 == u4_word)
82        return 31;
83    else
84    {
85        unsigned int index;
86        index = __builtin_ctz(u4_word);
87        return (UWORD32)index;
88    }
89}
90
91#define DATA_SYNC()  __sync_synchronize()
92
93
94
95//#define INLINE __inline
96#define INLINE inline
97
98#define PREFETCH_ENABLE 1
99
100#if PREFETCH_ENABLE
101#define PREFETCH(ptr, type) _mm_prefetch(ptr, type);
102#else
103#define PREFETCH(ptr, type)
104#endif
105
106#define MEM_ALIGN8 __attribute__ ((aligned (8)))
107#define MEM_ALIGN16 __attribute__ ((aligned (16)))
108#define MEM_ALIGN32 __attribute__ ((aligned (32)))
109
110#endif /* _IH264_PLATFORM_MACROS_H_ */
111