1/* lzo_ptr.h -- low-level pointer constructs 2 3 This file is part of the LZO real-time data compression library. 4 5 Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer 6 Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer 7 Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer 8 Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer 9 Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer 10 Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer 11 Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer 12 Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer 13 Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer 14 Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer 15 Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer 16 Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer 17 Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer 18 Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer 19 Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer 20 Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer 21 All Rights Reserved. 22 23 The LZO library is free software; you can redistribute it and/or 24 modify it under the terms of the GNU General Public License as 25 published by the Free Software Foundation; either version 2 of 26 the License, or (at your option) any later version. 27 28 The LZO library is distributed in the hope that it will be useful, 29 but WITHOUT ANY WARRANTY; without even the implied warranty of 30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 31 GNU General Public License for more details. 32 33 You should have received a copy of the GNU General Public License 34 along with the LZO library; see the file COPYING. 35 If not, write to the Free Software Foundation, Inc., 36 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 37 38 Markus F.X.J. Oberhumer 39 <markus@oberhumer.com> 40 http://www.oberhumer.com/opensource/lzo/ 41 */ 42 43 44/* WARNING: this file should *not* be used by applications. It is 45 part of the implementation of the library and is subject 46 to change. 47 */ 48 49 50#ifndef __LZO_PTR_H 51#define __LZO_PTR_H 1 52 53#ifdef __cplusplus 54extern "C" { 55#endif 56 57 58/*********************************************************************** 59// Integral types 60************************************************************************/ 61 62#if !defined(lzo_uintptr_t) 63# if (__LZO_MMODEL_HUGE) 64# define lzo_uintptr_t unsigned long 65# else 66# define lzo_uintptr_t acc_uintptr_t 67# ifdef __ACC_INTPTR_T_IS_POINTER 68# define __LZO_UINTPTR_T_IS_POINTER 1 69# endif 70# endif 71#endif 72 73 74/*********************************************************************** 75// 76************************************************************************/ 77 78/* Always use the safe (=integral) version for pointer-comparisons. 79 * The compiler should optimize away the additional casts anyway. 80 * 81 * Note that this only works if the representation and ordering 82 * of the pointer and the integral is the same (at bit level). 83 * 84 * Most 16-bit compilers have their own view about pointers - 85 * fortunately they don't care about comparing pointers 86 * that are pointing to Nirvana. 87 */ 88 89#if (LZO_ARCH_I086) 90#define PTR(a) ((lzo_bytep) (a)) 91/* only need the low bits of the pointer -> offset is ok */ 92#define PTR_ALIGNED_4(a) ((ACC_PTR_FP_OFF(a) & 3) == 0) 93#define PTR_ALIGNED2_4(a,b) (((ACC_PTR_FP_OFF(a) | ACC_PTR_FP_OFF(b)) & 3) == 0) 94#elif (LZO_MM_PVP) 95#define PTR(a) ((lzo_bytep) (a)) 96#define PTR_ALIGNED_8(a) ((((lzo_uintptr_t)(a)) >> 61) == 0) 97#define PTR_ALIGNED2_8(a,b) ((((lzo_uintptr_t)(a)|(lzo_uintptr_t)(b)) >> 61) == 0) 98#else 99#define PTR(a) ((lzo_uintptr_t) (a)) 100#define PTR_LINEAR(a) PTR(a) 101#define PTR_ALIGNED_4(a) ((PTR_LINEAR(a) & 3) == 0) 102#define PTR_ALIGNED_8(a) ((PTR_LINEAR(a) & 7) == 0) 103#define PTR_ALIGNED2_4(a,b) (((PTR_LINEAR(a) | PTR_LINEAR(b)) & 3) == 0) 104#define PTR_ALIGNED2_8(a,b) (((PTR_LINEAR(a) | PTR_LINEAR(b)) & 7) == 0) 105#endif 106 107#define PTR_LT(a,b) (PTR(a) < PTR(b)) 108#define PTR_GE(a,b) (PTR(a) >= PTR(b)) 109#define PTR_DIFF(a,b) (PTR(a) - PTR(b)) 110#define pd(a,b) ((lzo_uint) ((a)-(b))) 111 112 113LZO_EXTERN(lzo_uintptr_t) 114__lzo_ptr_linear(const lzo_voidp ptr); 115 116 117typedef union 118{ 119 char a_char; 120 unsigned char a_uchar; 121 short a_short; 122 unsigned short a_ushort; 123 int a_int; 124 unsigned int a_uint; 125 long a_long; 126 unsigned long a_ulong; 127 lzo_int a_lzo_int; 128 lzo_uint a_lzo_uint; 129 lzo_int32 a_lzo_int32; 130 lzo_uint32 a_lzo_uint32; 131#if defined(LZO_UINT64_MAX) 132 lzo_int64 a_lzo_int64; 133 lzo_uint64 a_lzo_uint64; 134#endif 135 ptrdiff_t a_ptrdiff_t; 136 lzo_uintptr_t a_lzo_uintptr_t; 137 lzo_voidp a_lzo_voidp; 138 void * a_void_p; 139 lzo_bytep a_lzo_bytep; 140 lzo_bytepp a_lzo_bytepp; 141 lzo_uintp a_lzo_uintp; 142 lzo_uint * a_lzo_uint_p; 143 lzo_uint32p a_lzo_uint32p; 144 lzo_uint32 * a_lzo_uint32_p; 145 unsigned char * a_uchar_p; 146 char * a_char_p; 147} 148lzo_full_align_t; 149 150 151 152#ifdef __cplusplus 153} /* extern "C" */ 154#endif 155 156#endif /* already included */ 157 158/* 159vi:ts=4:et 160*/ 161 162