~ubuntu-branches/ubuntu/wily/libsereal-encoder-perl/wily

« back to all changes in this revision

Viewing changes to srl_common.h

  • Committer: Package Import Robot
  • Author(s): gregor herrmann
  • Date: 2014-07-27 22:25:25 UTC
  • mfrom: (1.1.12)
  • Revision ID: package-import@ubuntu.com-20140727222525-12re0k54e36px9g1
Tags: 3.001.004-1
* Team upload.
* New upstream release.
  Further improvements for non-x86 architectures.
* Bump versioned build dependency on libsereal-decoder-perl.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
/* these defines are somewhat borrowed from miniz.c */
17
17
 
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
21
21
#endif
22
22
 
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
 
24
 
 
25
#ifdef __hpux
 
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
26
 
#endif
27
 
 
28
 
/* HP-UX runs on Itanium but has strict alignment. */
29
 
#ifdef __hpux
30
 
#undef SRL_USE_ALIGNED_LOADS_AND_STORES
 
31
#else
 
32
/* When in doubt use aligned loads and stores */
31
33
#define SRL_USE_ALIGNED_LOADS_AND_STORES 1
32
34
#endif
33
35
 
34
36
#endif
 
37
 
 
38
 
 
39
/* In x86 one can try to enforce strict alignment in runtime.
 
40
 *
 
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.
 
47
 *
 
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.
 
50
 *
 
51
 * http://en.wikipedia.org/wiki/Control_register
 
52
 * http://en.wikipedia.org/wiki/FLAGS_register_(computing)
 
53
 */
 
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")
 
59
#  endif
 
60
#else
 
61
#  define SRL_TRY_ENABLE_STRICT_ALIGN() (void)0
 
62
#endif
 
63
 
 
64
#endif