summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjosh.macdonald <jmacd@users.noreply.github.com>2012-09-24 04:10:10 +0000
committerjosh.macdonald <jmacd@users.noreply.github.com>2012-09-24 04:10:10 +0000
commita9e8d2f03a29f81ecb490980d64431f25296085d (patch)
treed0f0ca928351bd1c1a4c8ac87cc2c292a09a24d2
parent04295a524612410a206f86e9103dc4dcf7df5eca (diff)
Fix UNALIGNED_OK logic, add autoconf rule to detect for non-Windows builds and default to UNALIGNED_OK=1
-rw-r--r--xdelta3/config.h.in3
-rw-r--r--xdelta3/configure.ac1
-rw-r--r--xdelta3/m4/ax_check_aligned_access_required.m484
-rw-r--r--xdelta3/xdelta3-hash.h33
-rw-r--r--xdelta3/xdelta3.h9
5 files changed, 100 insertions, 30 deletions
diff --git a/xdelta3/config.h.in b/xdelta3/config.h.in
index 220915d..f01f64a 100644
--- a/xdelta3/config.h.in
+++ b/xdelta3/config.h.in
@@ -1,5 +1,8 @@
1/* config.h.in. Generated from configure.ac by autoheader. */ 1/* config.h.in. Generated from configure.ac by autoheader. */
2 2
3/* Define if pointers to integers require aligned access */
4#undef HAVE_ALIGNED_ACCESS_REQUIRED
5
3/* Define to 1 if you have the <inttypes.h> header file. */ 6/* Define to 1 if you have the <inttypes.h> header file. */
4#undef HAVE_INTTYPES_H 7#undef HAVE_INTTYPES_H
5 8
diff --git a/xdelta3/configure.ac b/xdelta3/configure.ac
index 869f3c2..394e2ae 100644
--- a/xdelta3/configure.ac
+++ b/xdelta3/configure.ac
@@ -5,6 +5,7 @@ AC_CONFIG_MACRO_DIR([m4])
5#LT_INIT 5#LT_INIT
6AM_INIT_AUTOMAKE([1.9 no-define foreign tar-ustar]) 6AM_INIT_AUTOMAKE([1.9 no-define foreign tar-ustar])
7#AC_DISABLE_STATIC 7#AC_DISABLE_STATIC
8AX_CHECK_ALIGNED_ACCESS_REQUIRED
8AC_PROG_CC 9AC_PROG_CC
9AC_PROG_CXX 10AC_PROG_CXX
10AC_CHECK_HEADERS([lzma.h]) 11AC_CHECK_HEADERS([lzma.h])
diff --git a/xdelta3/m4/ax_check_aligned_access_required.m4 b/xdelta3/m4/ax_check_aligned_access_required.m4
new file mode 100644
index 0000000..b078275
--- /dev/null
+++ b/xdelta3/m4/ax_check_aligned_access_required.m4
@@ -0,0 +1,84 @@
1# ====================================================================================
2# http://www.gnu.org/software/autoconf-archive/ax_check_aligned_access_required.html
3# ====================================================================================
4#
5# SYNOPSIS
6#
7# AC_CHECK_ALIGNED_ACCESS_REQUIRED
8#
9# DESCRIPTION
10#
11# While the x86 CPUs allow access to memory objects to be unaligned it
12# happens that most of the modern designs require objects to be aligned -
13# or they will fail with a buserror. That mode is quite known by
14# big-endian machines (sparc, etc) however the alpha cpu is little-
15# endian.
16#
17# The following function will test for aligned access to be required and
18# set a config.h define HAVE_ALIGNED_ACCESS_REQUIRED (name derived by
19# standard usage). Structures loaded from a file (or mmapped to memory)
20# should be accessed per-byte in that case to avoid segfault type errors.
21#
22# LICENSE
23#
24# Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
25#
26# This program is free software; you can redistribute it and/or modify it
27# under the terms of the GNU General Public License as published by the
28# Free Software Foundation; either version 3 of the License, or (at your
29# option) any later version.
30#
31# This program is distributed in the hope that it will be useful, but
32# WITHOUT ANY WARRANTY; without even the implied warranty of
33# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
34# Public License for more details.
35#
36# You should have received a copy of the GNU General Public License along
37# with this program. If not, see <http://www.gnu.org/licenses/>.
38#
39# As a special exception, the respective Autoconf Macro's copyright owner
40# gives unlimited permission to copy, distribute and modify the configure
41# scripts that are the output of Autoconf when processing the Macro. You
42# need not follow the terms of the GNU General Public License when using
43# or distributing such scripts, even though portions of the text of the
44# Macro appear in them. The GNU General Public License (GPL) does govern
45# all other use of the material that constitutes the Autoconf Macro.
46#
47# This special exception to the GPL applies to versions of the Autoconf
48# Macro released by the Autoconf Archive. When you make and distribute a
49# modified version of the Autoconf Macro, you may extend this special
50# exception to the GPL to apply to your modified version as well.
51
52#serial 7
53
54AC_DEFUN([AX_CHECK_ALIGNED_ACCESS_REQUIRED],
55[AC_CACHE_CHECK([if pointers to integers require aligned access],
56 [ax_cv_have_aligned_access_required],
57 [AC_TRY_RUN([
58#include <stdio.h>
59#include <stdlib.h>
60
61int main()
62{
63 char* string = malloc(40);
64 int i;
65 for (i=0; i < 40; i++) string[[i]] = i;
66 {
67 void* s = string;
68 int* p = s+1;
69 int* q = s+2;
70
71 if (*p == *q) { return 1; }
72 }
73 return 0;
74}
75 ],
76 [ax_cv_have_aligned_access_required=yes],
77 [ax_cv_have_aligned_access_required=no],
78 [ax_cv_have_aligned_access_required=no])
79 ])
80if test "$ax_cv_have_aligned_access_required" = yes ; then
81 AC_DEFINE([HAVE_ALIGNED_ACCESS_REQUIRED], [1],
82 [Define if pointers to integers require aligned access])
83fi
84])
diff --git a/xdelta3/xdelta3-hash.h b/xdelta3/xdelta3-hash.h
index e546d59..08d8136 100644
--- a/xdelta3/xdelta3-hash.h
+++ b/xdelta3/xdelta3-hash.h
@@ -65,46 +65,29 @@ xd3_large_cksum_update (uint32_t cksum,
65/* TODO: revisit this topic */ 65/* TODO: revisit this topic */
66#endif 66#endif
67 67
68/* Note: small cksum is hard-coded for 4 bytes */
69#if UNALIGNED_OK 68#if UNALIGNED_OK
70static inline uint32_t 69#define UNALIGNED_READ32(dest,src) (*(dest)) = (*(uint32_t*)(src))
71xd3_scksum (uint32_t *state,
72 const uint8_t *base,
73 const usize_t look)
74{
75 (*state) = *(uint32_t*)base;
76 return (*state) * hash_multiplier;
77}
78static inline uint32_t
79xd3_small_cksum_update (uint32_t *state,
80 const uint8_t *base,
81 usize_t look)
82{
83 (*state) = *(uint32_t*)(base+1);
84 return (*state) * hash_multiplier;
85}
86#else 70#else
71#define UNALIGNED_READ32(dest,src) memcpy((dest), (src), 4);
72#endif
73
74/* TODO: small cksum is hard-coded for 4 bytes (i.e., "look" is unused) */
87static inline uint32_t 75static inline uint32_t
88xd3_scksum (uint32_t *state, 76xd3_scksum (uint32_t *state,
89 const uint8_t *base, 77 const uint8_t *base,
90 const usize_t look) 78 const usize_t look)
91{ 79{
92 (*state) = (base[0] << 24 | 80 UNALIGNED_READ32(state, base);
93 base[1] << 16 |
94 base[2] << 8 |
95 base[3]);
96 return (*state) * hash_multiplier; 81 return (*state) * hash_multiplier;
97} 82}
98static inline uint32_t 83static inline uint32_t
99xd3_small_cksum_update (uint32_t *state, 84xd3_small_cksum_update (uint32_t *state,
100 const uint8_t *base, 85 const uint8_t *base,
101 const usize_t look) 86 usize_t look)
102{ 87{
103 (*state) <<= 8; 88 UNALIGNED_READ32(state, base+1);
104 (*state) |= base[4];
105 return (*state) * hash_multiplier; 89 return (*state) * hash_multiplier;
106} 90}
107#endif
108 91
109/*********************************************************************** 92/***********************************************************************
110 Ctable stuff 93 Ctable stuff
diff --git a/xdelta3/xdelta3.h b/xdelta3/xdelta3.h
index 6256961..0710f08 100644
--- a/xdelta3/xdelta3.h
+++ b/xdelta3/xdelta3.h
@@ -171,13 +171,12 @@ typedef uint32_t xoff_t;
171#define USE_UINT64 (SIZEOF_USIZE_T == 8 || \ 171#define USE_UINT64 (SIZEOF_USIZE_T == 8 || \
172 SIZEOF_XOFF_T == 8 || REGRESSION_TEST) 172 SIZEOF_XOFF_T == 8 || REGRESSION_TEST)
173 173
174/* TODO: probably should do something better here. */
175#ifndef UNALIGNED_OK 174#ifndef UNALIGNED_OK
176#if defined(__i386__) || defined(__i486__) || defined(__i586__) || \ 175#ifdef HAVE_ALIGNED_ACCESS_REQUIRED
177 defined(__i686__) || defined(_X86_) || defined(__x86_64__)
178#define UNALIGNED_OK 1
179#else
180#define UNALIGNED_OK 0 176#define UNALIGNED_OK 0
177#else
178/* This generally includes all Windows builds. */
179#define UNALIGNED_OK 1
181#endif 180#endif
182#endif 181#endif
183 182