Brian Waters | 13d9601 | 2017-12-08 16:53:31 -0600 | [diff] [blame] | 1 | /***************************************************************************************************** |
| 2 | * Software License Agreement (BSD License) |
| 3 | * Author : Souheil Ben Ayed <souheil@tera.ics.keio.ac.jp> |
| 4 | * |
| 5 | * Copyright (c) 2009-2010, Souheil Ben Ayed, Teraoka Laboratory of Keio University, and the WIDE Project |
| 6 | * All rights reserved. |
| 7 | * |
| 8 | * Redistribution and use of this software in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions are met: |
| 10 | * |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * |
| 14 | * 2. Redistributions in binary form must reproduce the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer in the |
| 16 | * documentation and/or other materials provided with the distribution. |
| 17 | * |
| 18 | * 3. All advertising materials mentioning features or use of this software |
| 19 | * must display the following acknowledgement: |
| 20 | * This product includes software developed by Souheil Ben Ayed <souheil@tera.ics.keio.ac.jp>. |
| 21 | * |
| 22 | * 4. Neither the name of Souheil Ben Ayed, Teraoka Laboratory of Keio University or the WIDE Project nor the |
| 23 | * names of its contributors may be used to endorse or promote products |
| 24 | * derived from this software without specific prior written permission. |
| 25 | * |
| 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' AND ANY |
| 27 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 28 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY |
| 30 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 31 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 32 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 33 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | *****************************************************************************************************/ |
| 37 | |
| 38 | |
| 39 | #ifndef DIAMEAP_DEFS_H_ |
| 40 | #define DIAMEAP_DEFS_H_ |
| 41 | |
| 42 | #include <stdio.h> |
| 43 | #include <stdlib.h> |
| 44 | #include <stdint.h> |
| 45 | |
| 46 | |
| 47 | /************************************************/ |
| 48 | /* Data Type Definition */ |
| 49 | /************************************************/ |
| 50 | |
| 51 | /* boolean Type */ |
| 52 | typedef enum |
| 53 | { |
| 54 | FALSE = 0, TRUE = 1 |
| 55 | } boolean; |
| 56 | |
| 57 | /* Exact-width integer types */ |
| 58 | typedef int8_t s8; /* signed char */ |
| 59 | typedef uint8_t u8; /* unsigned char */ |
| 60 | typedef int16_t s16; /* signed int */ |
| 61 | typedef uint16_t u16; /* unsigned int */ |
| 62 | typedef int32_t s32; /* signed long int */ |
| 63 | typedef uint32_t u32; /* unsigned long int */ |
| 64 | typedef int64_t s64; /* signed long long int */ |
| 65 | typedef uint64_t u64; /* unsigned long long int */ |
| 66 | |
| 67 | /************************************************/ |
| 68 | /* Macros */ |
| 69 | /************************************************/ |
| 70 | |
| 71 | /* Macros for manipulating data*/ |
| 72 | |
| 73 | /* Retrieve signed/unsigned exact-width integer types */ |
| 74 | #define G8(v) (u8) (* (v) ) |
| 75 | |
| 76 | #define G16BIGE(v) ( ( (u16) (* (v) ) << 8 ) ^ \ |
| 77 | ( (u16) (*((v)+1)) ) ) |
| 78 | #define G16LITE(v) ( ( (u16) (*((v)+1)) << 8 ) ^ \ |
| 79 | ( (u16) (* (v) ) ) ) |
| 80 | |
| 81 | #define G24BIGE(v) ( ( (u32) (* (v) ) << 16 ) ^ \ |
| 82 | ( (u32) (*((v)+1)) << 8 ) ^ \ |
| 83 | ( (u32) (*((v)+2)) ) ) |
| 84 | #define G24LITE(v) ( ( (u32) (*((v)+2)) << 16 ) ^ \ |
| 85 | ( (u32) (*((v)+1)) << 8 ) ^ \ |
| 86 | ( (u32) (* (v) ) ) ) |
| 87 | |
| 88 | #define G32BIGE(v) ( ( (u32) (* (v) ) << 24 ) ^ \ |
| 89 | ( (u32) (*((v)+1)) << 16 ) ^ \ |
| 90 | ( (u32) (*((v)+2)) << 8 ) ^ \ |
| 91 | ( (u32) (*((v)+3)) ) ) |
| 92 | #define G32LITE(v) ( ( (u32) (*((v)+3)) << 24 ) ^ \ |
| 93 | ( (u32) (*((v)+2)) << 16 ) ^ \ |
| 94 | ( (u32) (*((v)+1)) << 8 ) ^ \ |
| 95 | ( (u32) (* (v) ) ) ) |
| 96 | |
| 97 | #define G64BIGE(v) ( ( (u64) (* (v) ) << 56 ) ^ \ |
| 98 | ( (u64) (*((v)+1)) << 48 ) ^ \ |
| 99 | ( (u64) (*((v)+2)) << 40 ) ^ \ |
| 100 | ( (u64) (*((v)+3)) << 32 ) ^ \ |
| 101 | ( (u64) (*((v)+4)) << 24 ) ^ \ |
| 102 | ( (u64) (*((v)+5)) << 16 ) ^ \ |
| 103 | ( (u64) (*((v)+6)) << 8 ) ^ \ |
| 104 | ( (u64) (*((v)+7)) ) ) |
| 105 | #define G64LITE(v) ( ( (u64) (*((v)+7)) << 56 ) ^ \ |
| 106 | ( (u64) (*((v)+6)) << 48 ) ^ \ |
| 107 | ( (u64) (*((v)+5)) << 40 ) ^ \ |
| 108 | ( (u64) (*((v)+4)) << 32 ) ^ \ |
| 109 | ( (u64) (*((v)+3)) << 24 ) ^ \ |
| 110 | ( (u64) (*((v)+2)) << 16 ) ^ \ |
| 111 | ( (u64) (*((v)+1)) << 8 ) ^ \ |
| 112 | ( (u64) (* (v) ) ) ) |
| 113 | |
| 114 | /* Insert signed/unsigned exact-width integer types */ |
| 115 | /* v : pointer where to insert the data |
| 116 | * b : pointer of data to be inserted |
| 117 | */ |
| 118 | /* Insertion format |
| 119 | * BIGE : BIG ENDIAN |
| 120 | * LITE : LITTLE ENDIAN |
| 121 | */ |
| 122 | |
| 123 | #define P8(v,b) do { \ |
| 124 | u8 x = (b); \ |
| 125 | u8 *d = (v); \ |
| 126 | d[0] = (x&0xffU); \ |
| 127 | } while (0) |
| 128 | |
| 129 | #define P16BIGE(v,b) do { \ |
| 130 | u16 x = (b); \ |
| 131 | u8 *d = (v); \ |
| 132 | d[0] = ((x >> 8)&0xffU); \ |
| 133 | d[1] = (x&0xffU); \ |
| 134 | } while (0) |
| 135 | |
| 136 | #define P16LITE(v,b) do { \ |
| 137 | u16 x = (b); \ |
| 138 | u8 *d = (v); \ |
| 139 | d[0] = (x&0xffU); \ |
| 140 | d[1] = ((x >> 8)&0xffU); \ |
| 141 | } while (0) |
| 142 | |
| 143 | #define P24BIGE(v, b) do { \ |
| 144 | u32 x = (b); \ |
| 145 | u8 *d = (v); \ |
| 146 | d[0] = ((x >> 16)&0xffU); \ |
| 147 | d[1] = ((x >> 8)&0xffU); \ |
| 148 | d[2] = ((x)&0xffU); \ |
| 149 | } while (0) |
| 150 | |
| 151 | #define P24LITE(v, b) do { \ |
| 152 | u32 x = (b); \ |
| 153 | u8 *d = (v); \ |
| 154 | d[0] = ((x)&0xffU); \ |
| 155 | d[1] = ((x >> 8)&0xffU); \ |
| 156 | d[2] = ((x >> 16)&0xffU); \ |
| 157 | } while (0) |
| 158 | |
| 159 | #define P32BIGE(v, b) do { \ |
| 160 | u32 x = (b); \ |
| 161 | u8 *d = (v); \ |
| 162 | d[0] = ((x >> 24)&0xffU); \ |
| 163 | d[1] = ((x >> 16)&0xffU); \ |
| 164 | d[2] = ((x >> 8)&0xffU); \ |
| 165 | d[3] = ((x)&0xffU); \ |
| 166 | } while (0) |
| 167 | |
| 168 | #define P32LITE(v, b) do { \ |
| 169 | u32 x = (b); \ |
| 170 | u8 *d = (v); \ |
| 171 | d[0] = ((x)&0xffU); \ |
| 172 | d[1] = ((x >> 8)&0xffU); \ |
| 173 | d[2] = ((x >> 16)&0xffU); \ |
| 174 | d[3] = ((x >> 24)&0xffU); \ |
| 175 | } while (0) |
| 176 | |
| 177 | #define P64BIGE(v, b) do { \ |
| 178 | u64 x = (b); \ |
| 179 | u8 *d = (v); \ |
| 180 | d[0] = ((x >> 56)&0xffU); \ |
| 181 | d[1] = ((x >> 48)&0xffU); \ |
| 182 | d[2] = ((x >> 40)&0xffU); \ |
| 183 | d[3] = ((x >> 32)&0xffU); \ |
| 184 | d[4] = ((x >> 24)&0xffU); \ |
| 185 | d[5] = ((x >> 16)&0xffU); \ |
| 186 | d[6] = ((x >> 8)&0xffU); \ |
| 187 | d[7] = ((x)&0xffU); \ |
| 188 | } while (0) |
| 189 | |
| 190 | #define P64LITE(v, b) do { \ |
| 191 | u64 x = (b); \ |
| 192 | u8 *d = (v); \ |
| 193 | d[0] = ((x)&0xffU); \ |
| 194 | d[1] = ((x >> 8)&0xffU); \ |
| 195 | d[2] = ((x >> 16)&0xffU); \ |
| 196 | d[3] = ((x >> 24)&0xffU); \ |
| 197 | d[4] = ((x >> 32)&0xffU); \ |
| 198 | d[5] = ((x >> 40)&0xffU); \ |
| 199 | d[6] = ((x >> 48)&0xffU); \ |
| 200 | d[7] = ((x >> 56)&0xffU); \ |
| 201 | } while (0) |
| 202 | |
| 203 | /* |
| 204 | * Insert data in a specified position |
| 205 | * a : (u8*) pointer where to insert the data |
| 206 | * f : (int) insert from this position |
| 207 | * l : (int) length of the data in byte to insert |
| 208 | * b : (u8*) pointer of data to be inserted |
| 209 | */ |
| 210 | |
| 211 | #define U8COPY(a,f,l,b) do{ \ |
| 212 | u8 * x = (a); \ |
| 213 | u8 * y = (b); \ |
| 214 | int i; \ |
| 215 | for(i=0;i<l;i++) \ |
| 216 | x[i+f]= y[i]; \ |
| 217 | } while (0) |
| 218 | |
| 219 | |
| 220 | #endif /*DIAMEAP_DEFS_H_*/ |