Home | History | Annotate | Download | only in common
      1 /******************************************************************************
      2 *
      3 * Copyright (C) 2012 Ittiam Systems Pvt Ltd, Bangalore
      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 /**
     19 *******************************************************************************
     20 * @file
     21 *  ihevc_macros.h
     22 *
     23 * @brief
     24 *  Macro definitions used in the codec
     25 *
     26 * @author
     27 *  Ittiam
     28 *
     29 * @remarks
     30 *  None
     31 *
     32 *******************************************************************************
     33 */
     34 #ifndef _IHEVC_MACROS_H_
     35 #define _IHEVC_MACROS_H_
     36 
     37 #define RETURN_IF(cond, retval) if(cond) {return (retval);}
     38 #define UNUSED(x) ((void)(x))
     39 
     40 #define CLIP3(x, min, max) (((x) > max) ? max :(((x) < min)? min:(x)))
     41 
     42 #define MAX(x,y)    (((x) > (y)) ? (x) :(y))
     43 #define MIN(x,y)    (((x) < (y)) ? (x) :(y))
     44 #define SIGN(x)     ((x) >= 0 ? ((x)>0 ? 1: 0) : -1)
     45 #define ABS(x)      ((((WORD32)(x)) > 0)           ? (x) : -(x))
     46 
     47 #define ALIGN128(x) ((((x) + 127) >> 7) << 7)
     48 #define ALIGN64(x)  ((((x) + 63) >> 6) << 6)
     49 #define ALIGN32(x)  ((((x) + 31) >> 5) << 5)
     50 #define ALIGN16(x)  ((((x) + 15) >> 4) << 4)
     51 #define ALIGN8(x)   ((((x) + 7) >> 3) << 3)
     52 
     53 #define ALIGN_POW2(ptr,align) ((((WORD32)ptr)+align-1)&(~(align-1)))
     54 
     55 /** Sets x bits to '1' starting from MSB */
     56 #define MSB_ONES(x) ((UWORD32)0xFFFFFFFF << (32 - (x)))
     57 
     58 /** Generates a pattern of x number of '01' in binary starting from MSB */
     59 #define DUP_MSB_01(x) ((UWORD32)0x55555555 << (32 - ((x) * 2)))
     60 
     61 /** Generates a pattern of x number of '10' in binary starting from MSB */
     62 #define DUP_MSB_10(x) ((UWORD32)0xAAAAAAAA << (32 - ((x) * 2)))
     63 
     64 /** Generates a pattern of x number of '11' in binary starting from MSB */
     65 #define DUP_MSB_11(x) ((UWORD32)0xFFFFFFFF << (32 - ((x) * 2)))
     66 
     67 /** Sets x bits to '1' starting from LSB */
     68 #define LSB_ONES(x) ((UWORD32)0xFFFFFFFF >> (32 - (x)))
     69 
     70 /** Generates a pattern of x number of '01' in binary starting from LSB */
     71 #define DUP_LSB_01(x) ((UWORD32)0x55555555 >> (32 - ((x) * 2)))
     72 
     73 /** Generates a pattern of x number of '10' in binary starting from LSB */
     74 #define DUP_LSB_10(x) ((UWORD32)0xAAAAAAAA >> (32 - ((x) * 2)))
     75 
     76 /** Generates a pattern of x number of '11' in binary starting from LSB */
     77 #define DUP_LSB_11(x) ((UWORD32)0xFFFFFFFF >> (32 - ((x) * 2)))
     78 
     79 /** Sets the bit in given position to 1 */
     80 #define BITSET(x, pos) ((x) | (1 << (pos)))
     81 
     82 /** Swap two variables */
     83 #define SWAP(X,Y)                   \
     84 {                                   \
     85     (X) = (X) ^ (Y);                \
     86     (Y) = (X) ^ (Y);                \
     87     (X) = (X) ^ (Y);                \
     88 }
     89 #endif /*_IHEVCD_MACROS_H_*/
     90