--- code/trunk/sljit/sljitConfigInternal.h 2011/09/21 12:35:36 704 +++ code/trunk/sljit/sljitConfigInternal.h 2012/04/03 15:32:36 955 @@ -1,7 +1,7 @@ /* * Stack-less Just-In-Time compiler * - * Copyright 2009-2010 Zoltan Herczeg (hzmester@freemail.hu). All rights reserved. + * Copyright 2009-2012 Zoltan Herczeg (hzmester@freemail.hu). All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: @@ -28,21 +28,25 @@ #define _SLJIT_CONFIG_INTERNAL_H_ /* - SLJIT defines the following variables itself depending on the configuration: - sljit_b, sljit_ub : signed and unsigned 8 bit byte - sljit_h, sljit_uh : signed and unsigned 16 bit half-word (short) type - sljit_i, sljit_ui : signed and unsigned 32 bit integer type - sljit_w, sljit_uw : signed and unsigned machine word, enough to store a pointer (same as intptr_t) - SLJIT_CALL : C calling convention for both calling JIT and C callbacks from JIT + SLJIT defines the following macros depending on the target architecture: + + Feature detection (boolean) macros: SLJIT_32BIT_ARCHITECTURE : 32 bit architecture SLJIT_64BIT_ARCHITECTURE : 64 bit architecture SLJIT_WORD_SHIFT : the shift required to apply when accessing a sljit_w/sljit_uw array by index SLJIT_FLOAT_SHIFT : the shift required to apply when accessing a double array by index - SLJIT_BIG_ENDIAN : big endian architecture SLJIT_LITTLE_ENDIAN : little endian architecture - SLJIT_INDIRECT_CALL : see SLJIT_FUNC_OFFSET() - SLJIT_W : for defining 64 bit constants on 64 bit architectures (compiler workaround) - SLJIT_UNALIGNED : allows unaligned memory accesses for integer arithmetic (only!) + SLJIT_BIG_ENDIAN : big endian architecture + SLJIT_UNALIGNED : allows unaligned memory accesses for non-fpu operations (only!) + SLJIT_INDIRECT_CALL : see SLJIT_FUNC_OFFSET() for more information + + Types and useful macros: + sljit_b, sljit_ub : signed and unsigned 8 bit byte + sljit_h, sljit_uh : signed and unsigned 16 bit half-word (short) type + sljit_i, sljit_ui : signed and unsigned 32 bit integer type + sljit_w, sljit_uw : signed and unsigned machine word, enough to store a pointer (same as intptr_t) + SLJIT_CALL : C calling convention define for both calling JIT form C and C callbacks for JIT + SLJIT_W(number) : defining 64 bit constants on 64 bit architectures (compiler independent helper) */ #if !((defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) \ @@ -119,20 +123,33 @@ #if !(defined SLJIT_STD_MACROS_DEFINED && SLJIT_STD_MACROS_DEFINED) +/* These libraries are needed for the macros below. */ #include #include -/* General libraries: +#endif /* STD_MACROS_DEFINED */ + +/* General macros: Note: SLJIT is designed to be independent from them as possible. - In release mode (SLJIT_DEBUG is not defined) only the following macros are needed: */ + In release mode (SLJIT_DEBUG is not defined) only the following macros are needed: +*/ -/* General allocation. */ +#ifndef SLJIT_MALLOC #define SLJIT_MALLOC(size) malloc(size) +#endif + +#ifndef SLJIT_FREE #define SLJIT_FREE(ptr) free(ptr) +#endif + +#ifndef SLJIT_MEMMOVE #define SLJIT_MEMMOVE(dest, src, len) memmove(dest, src, len) +#endif -#endif /* STD_MACROS_DEFINED */ +#ifndef SLJIT_ZEROMEM +#define SLJIT_ZEROMEM(dest, len) memset(dest, 0, len) +#endif #if !defined(SLJIT_LIKELY) && !defined(SLJIT_UNLIKELY) @@ -161,15 +178,39 @@ #define SLJIT_UNUSED_ARG(arg) (void)arg #endif +#if (defined SLJIT_CONFIG_STATIC && SLJIT_CONFIG_STATIC) +/* Static ABI functions. For all-in-one programs. */ + +#if defined(__GNUC__) +/* Disable unused warnings in gcc. */ +#define SLJIT_API_FUNC_ATTRIBUTE static __attribute__((unused)) +#else +#define SLJIT_API_FUNC_ATTRIBUTE static +#endif + +#else +#define SLJIT_API_FUNC_ATTRIBUTE +#endif /* (defined SLJIT_CONFIG_STATIC && SLJIT_CONFIG_STATIC) */ + #ifndef SLJIT_CACHE_FLUSH -#if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) && !(defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) - /* Just call __ARM_NR_cacheflush on Linux. */ +#if (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) + +/* The __clear_cache() implementation of GCC is a dummy function on PowerPC. */ #define SLJIT_CACHE_FLUSH(from, to) \ - __clear_cache((char*)(from), (char*)(to)) -#else - /* Not required to implement on archs with unified caches. */ + ppc_cache_flush((from), (to)) + +#elif (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) + +/* Not required to implement on archs with unified caches. */ #define SLJIT_CACHE_FLUSH(from, to) + +#else + +/* Calls __ARM_NR_cacheflush on ARM-Linux. */ +#define SLJIT_CACHE_FLUSH(from, to) \ + __clear_cache((char*)(from), (char*)(to)) + #endif #endif /* !SLJIT_CACHE_FLUSH */ @@ -189,7 +230,12 @@ /* Machine word type. Can encapsulate a pointer. 32 bit for 32 bit machines. 64 bit for 64 bit machines. */ -#if !(defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) && !(defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) +#if (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) +/* Just to have something. */ +#define SLJIT_WORD_SHIFT 0 +typedef unsigned long int sljit_uw; +typedef long int sljit_w; +#elif !(defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) && !(defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) #define SLJIT_32BIT_ARCHITECTURE 1 #define SLJIT_WORD_SHIFT 2 typedef unsigned int sljit_uw; @@ -289,14 +335,13 @@ #ifndef SLJIT_SSE2 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) -/* Turn on SSE2 support on x86 (operating on doubles). - (Better performance than legacy fpu instructions). */ +/* Turn on SSE2 support on x86. */ #define SLJIT_SSE2 1 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) /* Auto detect SSE2 support using CPUID. On 64 bit x86 cpus, sse2 must be present. */ -#define SLJIT_SSE2_AUTO 1 +#define SLJIT_DETECT_SSE2 1 #endif #endif /* (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) */ @@ -317,8 +362,8 @@ #endif /* !SLJIT_UNALIGNED */ #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR) -void* sljit_malloc_exec(sljit_uw size); -void sljit_free_exec(void* ptr); +SLJIT_API_FUNC_ATTRIBUTE void* sljit_malloc_exec(sljit_uw size); +SLJIT_API_FUNC_ATTRIBUTE void sljit_free_exec(void* ptr); #define SLJIT_MALLOC_EXEC(size) sljit_malloc_exec(size) #define SLJIT_FREE_EXEC(ptr) sljit_free_exec(ptr) #endif @@ -332,11 +377,14 @@ /* Feel free to redefine these two macros. */ #ifndef SLJIT_ASSERT +#define SLJIT_HALT_PROCESS() \ + *((int*)0) = 0 + #define SLJIT_ASSERT(x) \ do { \ if (SLJIT_UNLIKELY(!(x))) { \ printf("Assertion failed at " __FILE__ ":%d\n", __LINE__); \ - *((int*)0) = 0; \ + SLJIT_HALT_PROCESS(); \ } \ } while (0) @@ -347,7 +395,7 @@ #define SLJIT_ASSERT_STOP() \ do { \ printf("Should never been reached " __FILE__ ":%d\n", __LINE__); \ - *((int*)0) = 0; \ + SLJIT_HALT_PROCESS(); \ } while (0) #endif /* !SLJIT_ASSERT_STOP */ @@ -364,4 +412,12 @@ #endif /* (defined SLJIT_DEBUG && SLJIT_DEBUG) */ +#ifndef SLJIT_COMPILE_ASSERT + +/* Should be improved eventually. */ +#define SLJIT_COMPILE_ASSERT(x, description) \ + SLJIT_ASSERT(x) + +#endif /* !SLJIT_COMPILE_ASSERT */ + #endif