ROHC compression/decompression library
|
00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 2 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * This program is distributed in the hope that it will be useful, 00008 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00009 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00010 * GNU General Public License for more details. 00011 * 00012 * You should have received a copy of the GNU General Public License 00013 * along with this program; if not, write to the Free Software 00014 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00015 */ 00016 00017 /** 00018 * @file rohc_bit_ops.h 00019 * @brief Bitwised operations for ROHC compression/decompression 00020 * @author Didier Barvaux <didier.barvaux@toulouse.viveris.com> 00021 * @author The hackers from ROHC for Linux 00022 * @author Didier Barvaux <didier@barvaux.org> 00023 */ 00024 00025 #ifndef ROHC_BIT_OPS_H 00026 #define ROHC_BIT_OPS_H 00027 00028 #ifdef __KERNEL__ 00029 # include <endian.h> 00030 #else 00031 # include "config.h" /* for WORDS_BIGENDIAN */ 00032 #endif 00033 00034 00035 /* 00036 * GET_BIT_n(x) macros: extract the (n+1) th bit from byte x starting from 00037 * the right and do not right-shift it 00038 */ 00039 00040 #define GET_BIT_0(x) ((*(x)) & 0x01) 00041 #define GET_BIT_1(x) ((*(x)) & 0x02) 00042 #define GET_BIT_2(x) ((*(x)) & 0x04) 00043 #define GET_BIT_3(x) ((*(x)) & 0x08) 00044 #define GET_BIT_4(x) ((*(x)) & 0x10) 00045 #define GET_BIT_5(x) ((*(x)) & 0x20) 00046 #define GET_BIT_6(x) ((*(x)) & 0x40) 00047 #define GET_BIT_7(x) ((*(x)) & 0x80) 00048 00049 00050 /* 00051 * GET_BIT_0_m(x) macros: extract bits 0 to m included from byte x and do not 00052 * right-shift them 00053 */ 00054 00055 #define GET_BIT_0_2(x) ((*(x)) & 0x07) 00056 #define GET_BIT_0_4(x) ((*(x)) & 0x1f) 00057 #define GET_BIT_0_3(x) ((*(x)) & 0x0f) 00058 #define GET_BIT_0_5(x) ((*(x)) & 0x3f) 00059 #define GET_BIT_0_6(x) ((*(x)) & 0x7f) 00060 #define GET_BIT_0_7(x) ((*(x)) & 0xff) 00061 00062 00063 /* 00064 * GET_BIT_n_m(x) macros: extract bits n to m included from byte x and 00065 * right-shift them 00066 */ 00067 00068 #define GET_BIT_1_7(x) ( ((*(x)) & 0xfe) >> 1 ) 00069 #define GET_BIT_3_4(x) ( ((*(x)) & 0x18) >> 3 ) 00070 #define GET_BIT_3_5(x) ( ((*(x)) & 0x38) >> 3 ) 00071 #define GET_BIT_3_6(x) ( ((*(x)) & 0x78) >> 3 ) 00072 #define GET_BIT_3_7(x) ( ((*(x)) & 0xf8) >> 3 ) 00073 #define GET_BIT_4_7(x) ( ((*(x)) & 0xf0) >> 4 ) 00074 #define GET_BIT_5_7(x) ( ((*(x)) & 0xe0) >> 5 ) 00075 #define GET_BIT_6_7(x) ( ((*(x)) & 0xc0) >> 6 ) 00076 #define GET_BIT_4_6(x) ( ((*(x)) & 0x70) >> 4 ) 00077 00078 00079 /** 00080 * @brief Convert GET_BIT_* values to 0 or 1 00081 * 00082 * example: GET_REAL(GET_BIT_5(data_ptr)); 00083 */ 00084 #define GET_REAL(x) ((x) ? 1 : 0) 00085 00086 00087 /** 00088 * @brief Convert GET_BIT_* values to boolean 00089 * 00090 * example: GET_BOOL(GET_BIT_5(data_ptr)); 00091 */ 00092 #define GET_BOOL(x) ((x) ? true : false) 00093 00094 00095 /** 00096 * @brief Get the next 16 bits at the given memory location 00097 * in Network Byte Order 00098 */ 00099 #if WORDS_BIGENDIAN == 1 00100 #define GET_NEXT_16_BITS(x) \ 00101 ((((*(x)) << 8) & 0xff00) | ((*((x) + 1)) & 0x00ff)) 00102 #else 00103 #define GET_NEXT_16_BITS(x) \ 00104 ((((*((x) + 1)) << 8) & 0xff00) | ((*(x)) & 0x00ff)) 00105 #endif 00106 00107 00108 #endif 00109