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 #define ALIGN4(x)   ((((x) + 3) >> 2) << 2)
     53 
     54 #define ALIGN_POW2(ptr,align) ((((WORD32)ptr)+align-1)&(~(align-1)))
     55 
     56 /** Sets x bits to '1' starting from MSB */
     57 #define MSB_ONES(x) ((UWORD32)0xFFFFFFFF << (32 - (x)))
     58 
     59 /** Generates a pattern of x number of '01' in binary starting from MSB */
     60 #define DUP_MSB_01(x) ((UWORD32)0x55555555 << (32 - ((x) * 2)))
     61 
     62 /** Generates a pattern of x number of '10' in binary starting from MSB */
     63 #define DUP_MSB_10(x) ((UWORD32)0xAAAAAAAA << (32 - ((x) * 2)))
     64 
     65 /** Generates a pattern of x number of '11' in binary starting from MSB */
     66 #define DUP_MSB_11(x) ((UWORD32)0xFFFFFFFF << (32 - ((x) * 2)))
     67 
     68 /** Sets x bits to '1' starting from LSB */
     69 #define LSB_ONES(x) ((UWORD32)0xFFFFFFFF >> (32 - (x)))
     70 
     71 /** Generates a pattern of x number of '01' in binary starting from LSB */
     72 #define DUP_LSB_01(x) ((UWORD32)0x55555555 >> (32 - ((x) * 2)))
     73 
     74 /** Generates a pattern of x number of '10' in binary starting from LSB */
     75 #define DUP_LSB_10(x) ((UWORD32)0xAAAAAAAA >> (32 - ((x) * 2)))
     76 
     77 /** Generates a pattern of x number of '11' in binary starting from LSB */
     78 #define DUP_LSB_11(x) ((UWORD32)0xFFFFFFFF >> (32 - ((x) * 2)))
     79 
     80 /** Sets the bit in given position to 1 */
     81 #define BITSET(x, pos) ((x) | (1 << (pos)))
     82 
     83 /** Swap two variables */
     84 #define SWAP(X,Y)                   \
     85 {                                   \
     86     (X) = (X) ^ (Y);                \
     87     (Y) = (X) ^ (Y);                \
     88     (X) = (X) ^ (Y);                \
     89 }
     90 #endif /*_IHEVCD_MACROS_H_*/
     91