kusano 7d535a
/* lzo_ptr.h -- low-level pointer constructs
kusano 7d535a
kusano 7d535a
   This file is part of the LZO real-time data compression library.
kusano 7d535a
kusano 7d535a
   Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   All Rights Reserved.
kusano 7d535a
kusano 7d535a
   The LZO library is free software; you can redistribute it and/or
kusano 7d535a
   modify it under the terms of the GNU General Public License as
kusano 7d535a
   published by the Free Software Foundation; either version 2 of
kusano 7d535a
   the License, or (at your option) any later version.
kusano 7d535a
kusano 7d535a
   The LZO library is distributed in the hope that it will be useful,
kusano 7d535a
   but WITHOUT ANY WARRANTY; without even the implied warranty of
kusano 7d535a
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
kusano 7d535a
   GNU General Public License for more details.
kusano 7d535a
kusano 7d535a
   You should have received a copy of the GNU General Public License
kusano 7d535a
   along with the LZO library; see the file COPYING.
kusano 7d535a
   If not, write to the Free Software Foundation, Inc.,
kusano 7d535a
   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
kusano 7d535a
kusano 7d535a
   Markus F.X.J. Oberhumer
kusano 7d535a
   <markus@oberhumer.com></markus@oberhumer.com>
kusano 7d535a
   http://www.oberhumer.com/opensource/lzo/
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
kusano 7d535a
/* WARNING: this file should *not* be used by applications. It is
kusano 7d535a
   part of the implementation of the library and is subject
kusano 7d535a
   to change.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
kusano 7d535a
#ifndef __LZO_PTR_H
kusano 7d535a
#define __LZO_PTR_H
kusano 7d535a
kusano 7d535a
#ifdef __cplusplus
kusano 7d535a
extern "C" {
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
kusano 7d535a
/***********************************************************************
kusano 7d535a
// Integral types
kusano 7d535a
************************************************************************/
kusano 7d535a
kusano 7d535a
#if !defined(lzo_uintptr_t)
kusano 7d535a
#  if defined(__LZO_MMODEL_HUGE)
kusano 7d535a
#    define lzo_uintptr_t   unsigned long
kusano 7d535a
#  else
kusano 7d535a
#    define lzo_uintptr_t   acc_uintptr_t
kusano 7d535a
#    ifdef __ACC_INTPTR_T_IS_POINTER
kusano 7d535a
#      define __LZO_UINTPTR_T_IS_POINTER 1
kusano 7d535a
#    endif
kusano 7d535a
#  endif
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
kusano 7d535a
/***********************************************************************
kusano 7d535a
//
kusano 7d535a
************************************************************************/
kusano 7d535a
kusano 7d535a
/* Always use the safe (=integral) version for pointer-comparisions.
kusano 7d535a
 * The compiler should optimize away the additional casts anyway.
kusano 7d535a
 *
kusano 7d535a
 * Note that this only works if the representation and ordering
kusano 7d535a
 * of the pointer and the integral is the same (at bit level).
kusano 7d535a
 *
kusano 7d535a
 * Most 16-bit compilers have their own view about pointers -
kusano 7d535a
 * fortunately they don't care about comparing pointers
kusano 7d535a
 * that are pointing to Nirvana.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
#if (LZO_ARCH_I086)
kusano 7d535a
#define PTR(a)              ((lzo_bytep) (a))
kusano 7d535a
/* only need the low bits of the pointer -> offset is ok */
kusano 7d535a
#define PTR_ALIGNED_4(a)    ((ACC_PTR_FP_OFF(a) & 3) == 0)
kusano 7d535a
#define PTR_ALIGNED2_4(a,b) (((ACC_PTR_FP_OFF(a) | ACC_PTR_FP_OFF(b)) & 3) == 0)
kusano 7d535a
#elif (LZO_MM_PVP)
kusano 7d535a
#define PTR(a)              ((lzo_bytep) (a))
kusano 7d535a
#define PTR_ALIGNED_8(a)    ((((lzo_uintptr_t)(a)) >> 61) == 0)
kusano 7d535a
#define PTR_ALIGNED2_8(a,b) ((((lzo_uintptr_t)(a)|(lzo_uintptr_t)(b)) >> 61) == 0)
kusano 7d535a
#else
kusano 7d535a
#define PTR(a)              ((lzo_uintptr_t) (a))
kusano 7d535a
#define PTR_LINEAR(a)       PTR(a)
kusano 7d535a
#define PTR_ALIGNED_4(a)    ((PTR_LINEAR(a) & 3) == 0)
kusano 7d535a
#define PTR_ALIGNED_8(a)    ((PTR_LINEAR(a) & 7) == 0)
kusano 7d535a
#define PTR_ALIGNED2_4(a,b) (((PTR_LINEAR(a) | PTR_LINEAR(b)) & 3) == 0)
kusano 7d535a
#define PTR_ALIGNED2_8(a,b) (((PTR_LINEAR(a) | PTR_LINEAR(b)) & 7) == 0)
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
#define PTR_LT(a,b)         (PTR(a) < PTR(b))
kusano 7d535a
#define PTR_GE(a,b)         (PTR(a) >= PTR(b))
kusano 7d535a
#define PTR_DIFF(a,b)       (PTR(a) - PTR(b))
kusano 7d535a
#define pd(a,b)             ((lzo_uint) ((a)-(b)))
kusano 7d535a
kusano 7d535a
kusano 7d535a
LZO_EXTERN(lzo_uintptr_t)
kusano 7d535a
__lzo_ptr_linear(const lzo_voidp ptr);
kusano 7d535a
kusano 7d535a
kusano 7d535a
typedef union
kusano 7d535a
{
kusano 7d535a
    char            a_char;
kusano 7d535a
    unsigned char   a_uchar;
kusano 7d535a
    short           a_short;
kusano 7d535a
    unsigned short  a_ushort;
kusano 7d535a
    int             a_int;
kusano 7d535a
    unsigned int    a_uint;
kusano 7d535a
    long            a_long;
kusano 7d535a
    unsigned long   a_ulong;
kusano 7d535a
    lzo_int         a_lzo_int;
kusano 7d535a
    lzo_uint        a_lzo_uint;
kusano 7d535a
    lzo_int32       a_lzo_int32;
kusano 7d535a
    lzo_uint32      a_lzo_uint32;
kusano 7d535a
    ptrdiff_t       a_ptrdiff_t;
kusano 7d535a
    lzo_uintptr_t   a_lzo_uintptr_t;
kusano 7d535a
    lzo_voidp       a_lzo_voidp;
kusano 7d535a
    void *          a_void_p;
kusano 7d535a
    lzo_bytep       a_lzo_bytep;
kusano 7d535a
    lzo_bytepp      a_lzo_bytepp;
kusano 7d535a
    lzo_uintp       a_lzo_uintp;
kusano 7d535a
    lzo_uint *      a_lzo_uint_p;
kusano 7d535a
    lzo_uint32p     a_lzo_uint32p;
kusano 7d535a
    lzo_uint32 *    a_lzo_uint32_p;
kusano 7d535a
    unsigned char * a_uchar_p;
kusano 7d535a
    char *          a_char_p;
kusano 7d535a
}
kusano 7d535a
lzo_full_align_t;
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
#ifdef __cplusplus
kusano 7d535a
} /* extern "C" */
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
#endif /* already included */
kusano 7d535a
kusano 7d535a
/*
kusano 7d535a
vi:ts=4:et
kusano 7d535a
*/
kusano 7d535a