16
16
/* these defines are somewhat borrowed from miniz.c */
18
#if defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__i386) || defined(__i486__) || defined(__i486) || defined(i386) || defined(__ia64__) || defined(__x86_64__)
19
// SRL_X86_OR_X64_CPU is only used to help set the below macros.
20
#define SRL_X86_OR_X64_CPU 1
18
#if defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__i386) || defined(__i486__) || defined(__i486) || defined(i386) || defined(__ia64__) || defined(__x86_64__) || defined(__x86_64)
19
/* SRL_X86_OR_X64_CPU is only used to help set the below macros. */
20
#define SRL_X86_OR_X64_CPU
23
#if SRL_X86_OR_X64_CPU && !defined(SRL_USE_ALIGNED_LOADS_AND_STORES)
24
// Set SRL_USE_ALIGNED_LOADS_AND_STORES to 0 on CPU's that permit efficient integer loads and stores from unaligned addresses.
23
#ifndef SRL_USE_ALIGNED_LOADS_AND_STORES
26
/* HP-UX runs on Itanium but has strict alignment so we check it first. */
27
#define SRL_USE_ALIGNED_LOADS_AND_STORES 1
28
#elif defined(SRL_X86_OR_X64_CPU)
29
/* Set SRL_USE_ALIGNED_LOADS_AND_STORES to 0 on CPU's that permit efficient integer loads and stores from unaligned addresses. */
25
30
#define SRL_USE_ALIGNED_LOADS_AND_STORES 0
28
/* HP-UX runs on Itanium but has strict alignment. */
30
#undef SRL_USE_ALIGNED_LOADS_AND_STORES
32
/* When in doubt use aligned loads and stores */
31
33
#define SRL_USE_ALIGNED_LOADS_AND_STORES 1
39
/* In x86 one can try to enforce strict alignment in runtime.
41
* Setting the CPU flag bit 18 (called "AC", aligment check) in
42
* the "EFLAGS" (user-settable) causes unaligned access traps but
43
* only iff the system register CR0 (only system-settable, usually done
44
* (or not) during kernel boot) has the same bit set (there called "AM",
45
* alignment mask). If both flags are not set, the strict alignment
46
* traps (silently) do not happen.
48
* The Linux kernel and the Solarix x86 set the "AM". The Windows and
49
* OX X do not. The *BSD behavior is unknown, though suspecting they do.
51
* http://en.wikipedia.org/wiki/Control_register
52
* http://en.wikipedia.org/wiki/FLAGS_register_(computing)
54
#ifdef SRL_X86_OR_X64_CPU
55
# if __x86_64__ || __x86_64
56
# define SRL_TRY_ENABLE_STRICT_ALIGN() asm("pushf\norl $0x40000, (%rsp)\npopf")
57
# elif __i386__ || __i386
58
# define SRL_TRY_ENABLE_STRICT_ALIGN() asm("pushf\norl $0x40000, (%esp)\npopf")
61
# define SRL_TRY_ENABLE_STRICT_ALIGN() (void)0