Open Inventor Reference
|
00001 /* 00002 * 00003 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * Further, this software is distributed without any warranty that it is 00016 * free of the rightful claim of any third person regarding infringement 00017 * or the like. Any license provided herein, whether implied or 00018 * otherwise, applies only to this software file. Patent licenses, if 00019 * any, provided herein do not apply to combinations of this program with 00020 * other software, or any other product whatsoever. 00021 * 00022 * You should have received a copy of the GNU Lesser General Public 00023 * License along with this library; if not, write to the Free Software 00024 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00025 * 00026 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, 00027 * Mountain View, CA 94043, or: 00028 * 00029 * http://www.sgi.com 00030 * 00031 * For further information regarding this notice, see: 00032 * 00033 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ 00034 * 00035 */ 00036 00037 #ifndef __MACHINE_H__ 00038 #define __MACHINE_H__ 00039 00040 /* 00041 * Copyright (C) 1990,91,92,93 Silicon Graphics, Inc. 00042 * 00043 _______________________________________________________________________ 00044 ______________ S I L I C O N G R A P H I C S I N C . ____________ 00045 | 00046 | $Revision: 1.5 $ 00047 | 00048 | Description: 00049 | This include file contains the machine-dependent macros 00050 | and defines for converting basic datatypes across machines. 00051 | This is only used by the SoInput and SoOutput classes defined 00052 | in the Inventor lib/database source. 00053 | TO ADD A NEW MACHINE: 00054 | 00055 | 1. Add a machine independent setup section 00056 | (define MACHINE_WORD_FORMAT and MACHINE_FLOAT_FORMAT) 00057 | 00058 | 2. Define DGL_HTON_*, DGL_NTOH_*, and SHORT/INT32/FLOAT/DOUBLE 00059 | 00060 | IMPORTANT NOTE: The only complete examples found in this 00061 | file is the SGI implementation. Note that the other 00062 | implementations are incomplete! 00063 | 00064 | Author(s) : Dave Immel 00065 | 00066 ______________ S I L I C O N G R A P H I C S I N C . ____________ 00067 _______________________________________________________________________ 00068 */ 00069 00070 00071 /* 00072 * SGI machine dependent setup 00073 */ 00074 00075 #if sgi 00076 00077 #define MACHINE_WORD_FORMAT DGL_BIG_ENDIAN 00078 #define MACHINE_FLOAT_FORMAT DGL_BIG_IEEE 00079 #if m68000 /* on 3K, times() returns 60'ths regardless */ 00080 #undef HZ 00081 #define HZ 60 00082 #define double long float /* System long, 00083 make m68020 behave like everyone */ 00084 #endif /* m68000 */ 00085 00086 #endif /* sgi */ 00087 00088 00089 /* 00090 * SUN/BSD machine dependent setup 00091 */ 00092 00093 #if sun 00094 00095 #define MACHINE_WORD_FORMAT DGL_BIG_ENDIAN 00096 #define MACHINE_FLOAT_FORMAT DGL_BIG_IEEE 00097 #define signed /* SUN default is signed chars */ 00098 #define h_errno errno /* BSD has these merged??? */ 00099 typedef unsigned long ulong; /* System long missing from types.h */ 00100 00101 #endif /* sun */ 00102 00103 00104 /* 00105 * VAX VMS/BSD machine dependent setup 00106 */ 00107 00108 #if vax 00109 00110 #define MACHINE_WORD_FORMAT DGL_LITTLE_ENDIAN 00111 #define MACHINE_FLOAT_FORMAT DGL_NON_IEEE 00112 #define signed /* VAX default is signed chars */ 00113 #if vms /* VMS only statements */ 00114 #define HZ 100 /* missing from param.h */ 00115 #define dn_perror dgl_perror /* use normal error handler */ 00116 #define fork vfork /* just for now - doesn't really work */ 00117 #else /* VAX/BSD only statements */ 00118 #define HZ 60 /* missing from param.h */ 00119 typedef unsigned long ulong; /* System long missing from types.h */ 00120 extern int errno; /* missing from errno.h */ 00121 #endif /* vms */ 00122 00123 #endif /* vax */ 00124 00125 00126 /* 00127 * Win32 machine dependent setup 00128 */ 00129 00130 #if defined(WIN32) 00131 #if !defined(__i386__) 00132 #define __i386__ 1 00133 #endif /* not __i386__ */ 00134 00135 #define MACHINE_WORD_FORMAT DGL_LITTLE_ENDIAN 00136 #define MACHINE_FLOAT_FORMAT DGL_NON_IEEE 00137 00138 #endif /* WIN32 */ 00139 00140 00141 /* 00142 * Linux i386/ia64 machine dependent setup 00143 */ 00144 00145 #if defined(__linux__) && (__i386__ || __ia64__) 00146 00147 #define MACHINE_WORD_FORMAT DGL_LITTLE_ENDIAN 00148 #define MACHINE_FLOAT_FORMAT DGL_NON_IEEE 00149 00150 #endif /* __linux__ && (__i386__ || __ia64__) */ 00151 00152 00153 /* 00154 * Apple Darwin (Mac OS X) machine dependent setup 00155 */ 00156 00157 #if defined(__APPLE__) 00158 #if defined(__i386__) || defined(__x86_64__) 00159 00160 #define MACHINE_WORD_FORMAT DGL_LITTLE_ENDIAN 00161 #define MACHINE_FLOAT_FORMAT DGL_NON_IEEE 00162 00163 #else /* __APPLE__ and not (__i386__ or __x86_64__) */ 00164 00165 #define MACHINE_WORD_FORMAT DGL_BIG_ENDIAN 00166 #define MACHINE_FLOAT_FORMAT DGL_BIG_IEEE 00167 00168 #endif /* __i386__ || __x86_64__ */ 00169 #endif /* __APPLE__ */ 00170 00171 00172 /* 00173 * IBM RS/6000 series machine dependent setup 00174 */ 00175 00176 #ifdef _IBMR2 00177 00178 #define MACHINE_WORD_FORMAT DGL_BIG_ENDIAN 00179 #define MACHINE_FLOAT_FORMAT DGL_BIG_IEEE 00180 #undef DOUBLE /* bogusly defined in <gai/g3dm2types.h> */ 00181 00182 #endif 00183 00184 00185 00186 /* 00187 * 32/64-bit architecture dependent statements 00188 */ 00189 00190 #define M_SIZEOF(x) sizeof(x) 00191 00192 /* 00193 * Defines for the various data formats 00194 */ 00195 00196 #define DGL_LITTLE_ENDIAN 1 /* integer formats */ 00197 #define DGL_BIG_ENDIAN 2 00198 00199 #define DGL_BIG_IEEE 1 /* floating point formats */ 00200 #define DGL_NON_IEEE 3 00201 00202 00203 /* 00204 * Data conversion (byte swapping) algorithms: 00205 * HTON - client host to network (server) 00206 * NTOH - network (server) to client host 00207 */ 00208 00209 #if MACHINE_WORD_FORMAT == DGL_BIG_ENDIAN 00210 #define DGL_HTON_SHORT(t,f) t = f 00211 #define DGL_NTOH_SHORT DGL_HTON_SHORT 00212 #define DGL_HTON_INT32(t,f) t = f 00213 #define DGL_NTOH_INT32 DGL_HTON_INT32 00214 #endif /* MACHINE_WORD_FORMAT */ 00215 00216 /* 00217 * DGL_BIG_IEEE: no conversion necessary (FLOAT) 00218 */ 00219 00220 #if MACHINE_FLOAT_FORMAT == DGL_BIG_IEEE 00221 #define DGL_HTON_FLOAT(t,f) t = f 00222 #define DGL_NTOH_FLOAT DGL_HTON_FLOAT 00223 #define DGL_HTON_DOUBLE(t,f) t = f 00224 #define DGL_NTOH_DOUBLE DGL_HTON_DOUBLE 00225 #endif 00226 00227 /* 00228 * DGL_LITTLE_ENDIAN: conversion necessary (INTEGER) 00229 * NOTE: non-floating point conversions are the same for both 00230 * directions and thus one macro suffices 00231 */ 00232 00233 #if MACHINE_WORD_FORMAT == DGL_LITTLE_ENDIAN 00234 00235 /* like DGL_HTON_INT32, but more efficient if f is a constant */ 00236 #define DGL_HTON_SHORT(t,f) \ 00237 { \ 00238 short _from = f,_to; \ 00239 ((char *)&_to)[0] = ((char *)&_from)[1]; \ 00240 ((char *)&_to)[1] = ((char *)&_from)[0]; \ 00241 t = _to; \ 00242 } 00243 #define DGL_NTOH_SHORT DGL_HTON_SHORT 00244 #define DGL_HTON_INT32(t,f) \ 00245 { \ 00246 int32_t _from = f,_to; \ 00247 ((char *)&_to)[0] = ((char *)&_from)[3]; \ 00248 ((char *)&_to)[1] = ((char *)&_from)[2]; \ 00249 ((char *)&_to)[2] = ((char *)&_from)[1]; \ 00250 ((char *)&_to)[3] = ((char *)&_from)[0]; \ 00251 t = _to; \ 00252 } 00253 #define DGL_NTOH_INT32 DGL_HTON_INT32 00254 00255 #endif /* LITTLE_ENDIAN */ 00256 00257 00258 /* 00259 * DGL_NON_IEEE: conversion necessary (FLOAT) 00260 * conversion is done within procedure calls for simplicity 00261 */ 00262 00263 #if MACHINE_FLOAT_FORMAT == DGL_NON_IEEE 00264 #if __i386__ || __x86_64__ || __ia64__ 00265 void mem_hton_float(float *t, float *f); 00266 void mem_ntoh_float(float *t, float *f); 00267 void mem_hton_double(double *t, double *f); 00268 void mem_ntoh_double(double *t, double *f); 00269 #endif /* __i386__ || __x86_64__ || __ia64__ */ 00270 #define DGL_HTON_FLOAT(t,f) mem_hton_float(&t,&f) 00271 #define DGL_NTOH_FLOAT(t,f) mem_ntoh_float(&t,&f) 00272 #define DGL_HTON_DOUBLE(t,f) mem_hton_double(&t,&f) 00273 #define DGL_NTOH_DOUBLE(t,f) mem_ntoh_double(&t,&f) 00274 #endif 00275 00276 00277 /* 00278 * get/set a data item located at address p regardless what it really is 00279 */ 00280 00281 #define INT32(p) (*(int32_t *)(p)) 00282 #define FLOAT(p) (*(float *)(p)) 00283 #define DOUBLE(p) (*(double *)(p)) 00284 #define SHORT(p) (*(short *)(p)) 00285 00286 #endif /* __MACHINE_H__ */