#ifndef _INCLUDE_TLIB_PRIMITIVES_H #define _INCLUDE_TLIB_PRIMITIVES_H #include "config.h" #include "backend-defines.h" /* Define the ABI for use by the Titanium runtime. This should match the ABI specified by Java. Item Description ---- ----------- jboolean A non-signed 1-bit integer (unsigned 8-bit integer) jubyte An unsigned 8-bit integer (*) jchar An unsigned 16-bit integer juint An unsigned 32-bit integer (*) julong An unsigned 64-bit integer (*) jbyte A signed 8-bit integer jshort A signed 16-bit integer jint A signed 32-bit integer jlong A signed 64-bit integer jIntPointer A signed integer that holds a pointer (*) jUIntPointer An unsigned integer that holds a pointer (*) jfloat A single precision floating point number jdouble A double precision floating point number (*) These are unspecified within the Java language itself. */ /* -------------------- Compiler Information -------------------- */ /* Provide some information about the compiler. Here are some examples that need to be set for certain compilers. Use "long long" as a 64-bit number. This must be defined if the LLP64, ILP32, or LP32 ABI's are used. #define _INCLUDE_TLIB_PRIMITIVES_H_NONSTD_INT64 long long #define _INCLUDE_TLIB_PRIMITIVES_H_NONSTD_UINT64 unsigned long long Use "__int32" as a 32-bit number in the ILP64 ABI. #define _INCLUDE_TLIB_PRIMITIVES_H_NONSTD_INT32 __int32 #define _INCLUDE_TLIB_PRIMITIVES_H_NONSTD_UINT32 unsigned __int32 Force the use of the ILP32 ABI assuming there was not match otherwise. #define _INCLUDE_TLIB_PRIMITIVES_H_ILP32 */ /* Check for any ABI related defines preset by the compiler */ #if defined(_LP64) || defined(__LP64) || defined(__LP64__) # define _INCLUDE_TLIB_PRIMITIVES_H_LP64 # define _INCLUDE_TLIB_PRIMITIVES_H_ABI_SET #endif #if defined(_ILP64) || defined(__ILP64) || defined(__ILP64__) # define _INCLUDE_TLIB_PRIMITIVES_H_ILP64 # define _INCLUDE_TLIB_PRIMITIVES_H_ABI_SET #endif #if defined(_LLP64) || defined(__LLP64) || defined(__LLP64__) # define _INCLUDE_TLIB_PRIMITIVES_H_LLP64 # define _INCLUDE_TLIB_PRIMITIVES_H_ABI_SET #endif #if defined(_ILP32) || defined(__ILP32) || defined(__ILP32__) # define _INCLUDE_TLIB_PRIMITIVES_H_ILP32 # define _INCLUDE_TLIB_PRIMITIVES_H_ABI_SET #endif #if defined(_LP32) || defined(__LP32) || defined(__LP32__) # define _INCLUDE_TLIB_PRIMITIVES_H_LP32 # define _INCLUDE_TLIB_PRIMITIVES_H_ABI_SET #endif /* For now, assume long long, a ILP32 ABI, and __int32 is the default. The configure script should really do a better job of finding the right answers. */ #if !defined(_INCLUDE_TLIB_PRIMITIVES_H_ABI_SET) # define _INCLUDE_TLIB_PRIMITIVES_H_ILP32 #endif #if !defined(_INCLUDE_TLIB_PRIMITIVES_H_NONSTD_INT64) # define _INCLUDE_TLIB_PRIMITIVES_H_NONSTD_INT64 long long #endif #if !defined(_INCLUDE_TLIB_PRIMITIVES_H_NONSTD_UINT64) # define _INCLUDE_TLIB_PRIMITIVES_H_NONSTD_UINT64 unsigned long long #endif #if !defined(_INCLUDE_TLIB_PRIMITIVES_H_NONSTD_INT32) # define _INCLUDE_TLIB_PRIMITIVES_H_NONSTD_INT32 __int32 #endif #if !defined(_INCLUDE_TLIB_PRIMITIVES_H_NONSTD_UINT32) # define _INCLUDE_TLIB_PRIMITIVES_H_NONSTD_UINT32 unsigned __int32 #endif /* ------------------ Special Platforms ------------------ */ /* These platforms are handled specially. If a special platform is handled here, it should declare all of the types specified above. Also, it should set the define: #define _INCLUDE_TLIB_PRIMITIVES_H_SPECIAL_PLATFORM_SET To ensure that the Standard platform portion of this file is skipped. */ /* The Tera */ #if defined(__TERA__) typedef unsigned char jboolean; typedef unsigned char jubyte; typedef unsigned __short16 jchar; typedef unsigned __int32 juint; typedef unsigned __int64 julong; typedef signed char jbyte; typedef __short16 jshort; typedef __int32 jint; typedef __int64 jlong; typedef __int64 jIntPointer; typedef unsigned __int64 jUIntPointer; typedef float jfloat; typedef double jdouble; # define _INCLUDE_TLIB_PRIMITIVES_H_SPECIAL_PLATFORM_SET #endif /* defined(__TERA__) */ /* The Cray T3E */ #if defined(USE_RUNTIME_CRAY_GNU_C) /* Special Gnu C compiler: ILP64 (with 16-bit shorts) */ typedef unsigned char jboolean; typedef unsigned char jubyte; typedef unsigned short jchar; typedef unsigned int juint; /* This is 64-bits, should be 32 !!! */ typedef unsigned long julong; typedef signed char jbyte; typedef short jshort; typedef int jint; /* This is 64-bits, should be 32 !!! */ typedef long jlong; typedef long jIntPointer; typedef unsigned long jUIntPointer; typedef float jfloat; typedef double jdouble; # define _INCLUDE_TLIB_PRIMITIVES_H_SPECIAL_PLATFORM_SET #endif /* defined(USE_RUNTIME_CRAY_GNU_C) */ #if defined(USE_RUNTIME_CRAY_T3E_C) /* The Cray T3E C compiler */ /* ILP64 with 32-bit shorts */ typedef unsigned char jboolean; typedef unsigned char jubyte; typedef unsigned short jchar; /* This is 32-bits, should be 16 !!! */ typedef unsigned short juint; typedef unsigned long julong; typedef signed char jbyte; typedef short jshort; /* This is 32-bits, should be 16 !!! */ typedef short jint; typedef long jlong; typedef long jIntPointer; typedef unsigned long jUIntPointer; typedef float jfloat; typedef double jdouble; # define _INCLUDE_TLIB_PRIMITIVES_H_SPECIAL_PLATFORM_SET #endif /* defined(USE_RUNTIME_CRAY_T3E_C) */ /* ------------------ Standard Platforms ------------------ */ /* The integers and pointers */ #if !defined(_INCLUDE_TLIB_PRIMITIVES_H_SPECIAL_PLATFORM_SET) #if SIZEOF_VOID_P == 8 #define PTR64 #else #define PTR32 #endif # if defined(USE_RUNTIME_INTTYPES_H) /* The standard inttypes.h */ # include typedef uint8_t jboolean; typedef uint8_t jubyte; typedef uint16_t jchar; typedef uint32_t juint; typedef uint64_t julong; typedef int8_t jbyte; typedef int16_t jshort; typedef int32_t jint; typedef int64_t jlong; typedef intptr_t jIntPointer; typedef uintptr_t jUIntPointer; # else /* defined(USE_RUNTIME_INTTYPES_H) */ # if defined(_INCLUDE_TLIB_PRIMITIVES_H_LP64) /* LP64 - long, pointer: 64; int: 32; short: 16; char: 8 */ typedef unsigned char jboolean; typedef unsigned char jubyte; typedef unsigned short jchar; typedef unsigned int juint; typedef unsigned long julong; typedef signed char jbyte; typedef short jshort; typedef int jint; typedef long jlong; typedef long jIntPointer; typedef unsigned long jUIntPointer; # else /* LP64 */ # if defined(_INCLUDE_TLIB_PRIMITIVES_H_ILP64) /* ILP64 - int, long, pointer: 64; short: 16; char: 8 */ typedef unsigned char jboolean; typedef unsigned char jubyte; typedef unsigned short jchar; typedef _INCLUDE_TLIB_PRIMITIVES_H_NONSTD_UINT32 juint; typedef unsigned long julong; typedef signed char jbyte; typedef short jshort; typedef _INCLUDE_TLIB_PRIMITIVES_H_NONSTD_INT32 jint; typedef long jlong; typedef long jIntPointer; typedef unsigned long jUIntPointer; # else /* ILP64 */ # if defined(_INCLUDE_TLIB_PRIMITIVES_H_LLP64) /* LLP64 - long long, pointer: 64; int, long: 32; short: 16; char: 8 */ typedef unsigned char jboolean; typedef unsigned char jubyte; typedef unsigned short jchar; typedef unsigned int juint; typedef _INCLUDE_TLIB_PRIMITIVES_H_NONSTD_UINT64 julong; typedef signed char jbyte; typedef short jshort; typedef int jint; typedef _INCLUDE_TLIB_PRIMITIVES_H_NONSTD_INT64 jlong; typedef _INCLUDE_TLIB_PRIMITIVES_H_NONSTD_INT64 jIntPointer; typedef _INCLUDE_TLIB_PRIMITIVES_H_NONSTD_UINT64 jUIntPointer; # else /* LLP64 */ # if defined(_INCLUDE_TLIB_PRIMITIVES_H_ILP32) /* ILP32 - long long/: 64; int, long, pointer: 32; short: 16; char: 8 */ typedef unsigned char jboolean; typedef unsigned char jubyte; typedef unsigned short jchar; typedef unsigned int juint; typedef _INCLUDE_TLIB_PRIMITIVES_H_NONSTD_UINT64 julong; typedef signed char jbyte; typedef short jshort; typedef int jint; typedef _INCLUDE_TLIB_PRIMITIVES_H_NONSTD_INT64 jlong; typedef int jIntPointer; typedef unsigned int jUIntPointer; # else /* ILP32 */ # if defined(_INCLUDE_TLIB_PRIMITIVES_H_LP32) /* LP32 - : 64; long, pointer: 32; int, short: 16; char: 8 */ typedef unsigned char jboolean; typedef unsigned char jubyte; typedef unsigned short jchar; typedef unsigned long juint; typedef _INCLUDE_TLIB_PRIMITIVES_H_NONSTD_UINT64 julong; typedef signed char jbyte; typedef short jshort; typedef long jint; typedef _INCLUDE_TLIB_PRIMITIVES_H_NONSTD_INT64 jlong; typedef long jIntPointer; typedef unsigned long jUIntPointer; # else /* LP32 */ # error PRIMITIVES_H Error: Unsupported ABI # endif /* LP32 */ # endif /* ILP32 */ # endif /* LLP64 */ # endif /* ILP64 */ # endif /* LP64 */ # endif /* defined(USE_RUNTIME_INTTYPES_H) */ /* The floating point numbers */ typedef float jfloat; typedef double jdouble; #endif /* !defined(_INCLUDE_TLIB_PRIMITIVES_H_SPECIAL_PLATFORM_SET) */ #ifdef PTR64 typedef juint Process; typedef juint Box; #else typedef jchar Process; typedef jchar Box; #endif /* PTR64 */ #ifdef WIDE_POINTERS typedef struct { Box box; /* this is also the proc numner when !MEMORY_SHARED */ void *addr; } jGPointer; #ifdef MEMORY_SHARED #define GET_PROC(x) COMM_GetProxyProcNumberForBoxNumber((x).box) #else #define GET_PROC(x) (x).box #endif #define GET_BOX(x) (x).box #define GET_ADDR(x) (x).addr /* client only needs to set either box or proc, and box is more efficient */ #define SET_BOX(x, val) ((x).box = val) #ifdef MEMORY_SHARED #define SET_PROC(x, val) ((x).box = COMM_GetBoxNumberForProcNumber(val)) #else #define SET_PROC(x, val) ((x).box = val) #endif #define SET_ADDR(x, val) ((x).addr = (void *)(val)) #else typedef void *jGPointer; #define GET_PROC(x) 0 #define GET_BOX(x) 0 #define GET_ADDR(x) ((void *)(x)) #define SET_PROC(x, val) #define SET_BOX(x, val) #define SET_ADDR(x, val) (x = (jGPointer)(val)) #endif /* WIDE_POINTERS */ /* Cast a GP_type pointer to a jGPointer */ #define CAST_GPTR(ptr) (*(jGPointer *)(&(ptr))) #define CAST_GPTR_TO_TYPE(type, ptr) (*(type *)(&(ptr))) /* these macros return the value of the expression given, but pass on a hint that you expect the value to be true or false. Use them to wrap the conditional expression in an if stmt when you have strong reason to believe the branch will frequently go in one direction and the branch is a bottleneck */ #if defined(HAVE_BUILTIN_EXPECT) && defined(__GNUC__) #define PREDICT_TRUE(exp) __builtin_expect( (exp), 1 ) #define PREDICT_FALSE(exp) __builtin_expect( (exp), 0 ) #else #define PREDICT_TRUE(exp) (exp) #define PREDICT_FALSE(exp) (exp) #endif #endif /* _INCLUDE_TLIB_PRIMITIVES_H */