blob: 969012fbdc887d6046ab31fe0acdfb216c799a89 [file] [log] [blame]
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301/******************************************************************************
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_macros.h
24*
25* @brief
26* Macro definitions used in the codec
27*
28* @author
29* Ittiam
30*
31* @remarks
32* None
33*
34*******************************************************************************
35*/
36#ifndef _IH264_MACROS_H_
37#define _IH264_MACROS_H_
38
39/*****************************************************************************/
40/* Function Macros */
41/*****************************************************************************/
42#define RETURN_IF(cond, retval) if(cond) {return (retval);}
43#define UNUSED(x) ((void)(x))
44
45#define ALIGN128(x) ((((x) + 127) >> 7) << 7)
46#define ALIGN64(x) ((((x) + 63) >> 6) << 6)
47#define ALIGN32(x) ((((x) + 31) >> 5) << 5)
48#define ALIGN16(x) ((((x) + 15) >> 4) << 4)
49#define ALIGN8(x) ((((x) + 7) >> 3) << 3)
50#define ALIGN4(x) ((((x) + 3) >> 2) << 2)
Harish Mahendrakar3a52efd2015-04-28 19:07:40 +053051#define ALIGN2(x) ((((x) + 1) >> 1) << 1)
Hamsalekha S8d3d3032015-03-13 21:24:58 +053052
53/**
54******************************************************************************
55 * @brief Min, Max
56******************************************************************************
57 */
58#define MAX(a,b) ((a > b)?(a):(b))
59#define MIN(a,b) ((a < b)?(a):(b))
60#define MIN3(a,b,c) ((a) < (b)) ? (((a) < (c)) ? (a) : (c)) : (((b) < (c)) ? (b) : (c))
61#define MAX3(a,b,c) ((a) > (b)) ? (((a) > (c)) ? (a) : (c)) : (((b) > (c)) ? (b) : (c))
62/**
63******************************************************************************
64 * @brief Div, Mod
65******************************************************************************
66 */
67#define MOD(x,y) ((x)%(y))
68#define DIV(x,y) ((x)/(y))
69
70/**
71******************************************************************************
72 * @brief Clip
73******************************************************************************
74 */
75#define CLIP3(miny, maxy, y) (((y) < (miny))?(miny):(((y) > (maxy))?(maxy):(y)))
76
77/**
78******************************************************************************
79 * @brief True, False
80******************************************************************************
81 */
82#define BOOLEAN(x) (!!(x))
83
84/**
85******************************************************************************
86 * @brief Frequently used multiplications x2. x3, and x4
87******************************************************************************
88 */
89#define X2(a) ((a) << 1)
90#define X3(a) (((a) << 1) + (a))
91#define X4(a) ((a) << 2)
92
93/**
94******************************************************************************
95 * @brief Misc
96******************************************************************************
97 */
98#define ABS(x) ((x) < 0 ? (-(x)) : (x))
99#define SIGNXY(x,y) (((y) < 0) ? (-1 * (x)) : (x))
100
101#define SIGN(x) (((x) >= 0) ? (((x) > 0) ? 1 : 0) : -1)
102
103#define RESET_BIT(x, pos) (x) = (x) & ~(1 << pos);
104#define SET_BIT(x, pos) (x) = (x) | (1 << pos);
105#define GET_BIT(x, pos) ((x) >> (pos)) & 0x1
106
107#define INSERT_BIT(x, pos, bit) { RESET_BIT(x, pos); (x) = (x) | (bit << pos); }
108#endif /*_IH264_MACROS_H_*/
109
110