u_pointer.h

Go to the documentation of this file.
00001 /**************************************************************************
00002  * 
00003  * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  * 
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  * 
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  * 
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  * 
00026  **************************************************************************/
00027 
00028 #ifndef U_POINTER_H
00029 #define U_POINTER_H
00030 
00031 #include "pipe/p_compiler.h"
00032 
00033 #ifdef __cplusplus
00034 extern "C" {
00035 #endif
00036 
00037 static INLINE intptr_t
00038 pointer_to_intptr( const void *p )
00039 {
00040    union {
00041       const void *p;
00042       intptr_t i;
00043    } pi;
00044    pi.p = p;
00045    return pi.i;
00046 }
00047 
00048 static INLINE void *
00049 intptr_to_pointer( intptr_t i )
00050 {
00051    union {
00052       void *p;
00053       intptr_t i;
00054    } pi;
00055    pi.i = i;
00056    return pi.p;
00057 }
00058 
00059 static INLINE uintptr_t
00060 pointer_to_uintptr( const void *ptr )
00061 {
00062    union {
00063       const void *p;
00064       uintptr_t u;
00065    } pu;
00066    pu.p = ptr;
00067    return pu.u;
00068 }
00069 
00070 static INLINE void *
00071 uintptr_to_pointer( uintptr_t u )
00072 {
00073    union {
00074       void *p;
00075       uintptr_t u;
00076    } pu;
00077    pu.u = u;
00078    return pu.p;
00079 }
00080 
00084 static INLINE void *
00085 align_pointer( const void *unaligned, uintptr_t alignment )
00086 {
00087    uintptr_t aligned = (pointer_to_uintptr( unaligned ) + alignment - 1) & ~(alignment - 1);
00088    return uintptr_to_pointer( aligned );
00089 }
00090 
00091 
00095 static INLINE void *
00096 align16( void *unaligned )
00097 {
00098    return align_pointer( unaligned, 16 );
00099 }
00100 
00101 
00102 
00103 #ifdef __cplusplus
00104 }
00105 #endif
00106 
00107 #endif /* U_POINTER_H */

Generated on Tue Sep 29 06:25:15 2009 for Gallium3D by  doxygen 1.5.4