1207151Smarius/*- 2207151Smarius * Copyright (c) 2010 by Peter Jeremy <peterjeremy@acm.org> 3207151Smarius * All rights reserved. 4207151Smarius * 5207151Smarius * Redistribution and use in source and binary forms, with or without 6207151Smarius * modification, are permitted provided that the following conditions 7207151Smarius * are met: 8207151Smarius * 1. Redistributions of source code must retain the above copyright 9207151Smarius * notice, this list of conditions and the following disclaimer. 10207151Smarius * 2. Redistributions in binary form must reproduce the above copyright 11207151Smarius * notice, this list of conditions and the following disclaimer in the 12207151Smarius * documentation and/or other materials provided with the distribution. 13207151Smarius * 14207151Smarius * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15207151Smarius * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16207151Smarius * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17207151Smarius * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 18207151Smarius * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19207151Smarius * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20207151Smarius * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21207151Smarius * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22207151Smarius * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 23207151Smarius * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24207151Smarius * 25207151Smarius * $FreeBSD$ 26207151Smarius */ 27207151Smarius 28207151Smarius/*---------------------------------------------------------------------------- 29207151Smarius| One of the macros `BIGENDIAN' or `LITTLEENDIAN' must be defined. 30207151Smarius*----------------------------------------------------------------------------*/ 31207151Smarius#define BIGENDIAN 32207151Smarius 33207151Smarius/*---------------------------------------------------------------------------- 34207151Smarius| The macro `BITS64' can be defined to indicate that 64-bit integer types are 35207151Smarius| supported by the compiler. 36207151Smarius*----------------------------------------------------------------------------*/ 37207151Smarius#define BITS64 38207151Smarius 39207151Smarius/*---------------------------------------------------------------------------- 40207151Smarius| Each of the following `typedef's defines the most convenient type that holds 41207151Smarius| integers of at least as many bits as specified. For example, `uint8' should 42207151Smarius| be the most convenient type that can hold unsigned integers of as many as 43207151Smarius| 8 bits. The `flag' type must be able to hold either a 0 or 1. For most 44207151Smarius| implementations of C, `flag', `uint8', and `int8' should all be `typedef'ed 45207151Smarius| to the same as `int'. 46207151Smarius*----------------------------------------------------------------------------*/ 47207151Smariustypedef int flag; 48207151Smariustypedef int uint8; 49207151Smariustypedef int int8; 50207151Smariustypedef int uint16; 51207151Smariustypedef int int16; 52207151Smariustypedef unsigned int uint32; 53207151Smariustypedef signed int int32; 54207151Smarius#ifdef BITS64 55207151Smariustypedef unsigned long int uint64; 56207151Smariustypedef signed long int int64; 57207151Smarius#endif 58207151Smarius 59207151Smarius/*---------------------------------------------------------------------------- 60207151Smarius| Each of the following `typedef's defines a type that holds integers 61207151Smarius| of _exactly_ the number of bits specified. For instance, for most 62207151Smarius| implementation of C, `bits16' and `sbits16' should be `typedef'ed to 63207151Smarius| `unsigned short int' and `signed short int' (or `short int'), respectively. 64207151Smarius*----------------------------------------------------------------------------*/ 65207151Smariustypedef unsigned char bits8; 66207151Smariustypedef signed char sbits8; 67207151Smariustypedef unsigned short int bits16; 68207151Smariustypedef signed short int sbits16; 69207151Smariustypedef unsigned int bits32; 70207151Smariustypedef signed int sbits32; 71207151Smarius#ifdef BITS64 72207151Smariustypedef unsigned long int bits64; 73207151Smariustypedef signed long int sbits64; 74207151Smarius#endif 75207151Smarius 76207151Smarius#ifdef BITS64 77207151Smarius/*---------------------------------------------------------------------------- 78207151Smarius| The `LIT64' macro takes as its argument a textual integer literal and 79207151Smarius| if necessary ``marks'' the literal as having a 64-bit integer type. 80207151Smarius| For example, the GNU C Compiler (`gcc') requires that 64-bit literals be 81207151Smarius| appended with the letters `LL' standing for `long long', which is `gcc's 82207151Smarius| name for the 64-bit integer type. Some compilers may allow `LIT64' to be 83207151Smarius| defined as the identity macro: `#define LIT64( a ) a'. 84207151Smarius*----------------------------------------------------------------------------*/ 85207151Smarius#define LIT64( a ) a##L 86207151Smarius#endif 87207151Smarius 88207151Smarius/*---------------------------------------------------------------------------- 89207151Smarius| The macro `INLINE' can be used before functions that should be inlined. If 90207151Smarius| a compiler does not support explicit inlining, this macro should be defined 91207151Smarius| to be `static'. 92207151Smarius*----------------------------------------------------------------------------*/ 93207151Smarius#define INLINE extern inline 94