Skip to content

Commit c89db9d

Browse files
authored
Revert "platform: fix unaligned 64-bit accesses on AArch32 (#699)"
This reverts commit 6d027d1.
1 parent 6d027d1 commit c89db9d

File tree

1 file changed

+10
-35
lines changed

1 file changed

+10
-35
lines changed

c/common/platform.h

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,7 @@ To apply compiler hint, enclose the branching condition into macros, like this:
187187

188188
#if (defined(__ARM_ARCH) && (__ARM_ARCH == 8)) || \
189189
defined(__aarch64__) || defined(__ARM64_ARCH_8__)
190-
#define BROTLI_TARGET_ARMV8_ANY
191-
192-
#if defined(__ARM_32BIT_STATE)
193-
#define BROTLI_TARGET_ARMV8_32
194-
#elif defined(__ARM_64BIT_STATE)
195-
#define BROTLI_TARGET_ARMV8_64
196-
#endif
197-
190+
#define BROTLI_TARGET_ARMV8
198191
#endif /* ARMv8 */
199192

200193
#if defined(__i386) || defined(_M_IX86)
@@ -217,7 +210,7 @@ To apply compiler hint, enclose the branching condition into macros, like this:
217210
#define BROTLI_64_BITS 1
218211
#elif defined(BROTLI_BUILD_32_BIT)
219212
#define BROTLI_64_BITS 0
220-
#elif defined(BROTLI_TARGET_X64) || defined(BROTLI_TARGET_ARMV8_64) || \
213+
#elif defined(BROTLI_TARGET_X64) || defined(BROTLI_TARGET_ARMV8) || \
221214
defined(BROTLI_TARGET_POWERPC64) || defined(BROTLI_TARGET_RISCV64)
222215
#define BROTLI_64_BITS 1
223216
#else
@@ -268,7 +261,7 @@ To apply compiler hint, enclose the branching condition into macros, like this:
268261
#if defined(BROTLI_BUILD_PORTABLE)
269262
#define BROTLI_ALIGNED_READ (!!1)
270263
#elif defined(BROTLI_TARGET_X86) || defined(BROTLI_TARGET_X64) || \
271-
defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8_ANY) || \
264+
defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8) || \
272265
defined(BROTLI_TARGET_RISCV64)
273266
/* Allow unaligned read only for white-listed CPUs. */
274267
#define BROTLI_ALIGNED_READ (!!0)
@@ -313,33 +306,15 @@ static BROTLI_INLINE void BrotliUnalignedWrite64(void* p, uint64_t v) {
313306
}
314307
#else /* BROTLI_64_BITS */
315308
/* Avoid emitting LDRD / STRD, which require properly aligned address. */
316-
317-
#if BROTLI_GNUC_HAS_ATTRIBUTE(aligned, 2, 7, 0)
318-
typedef __attribute__((aligned(1))) uint64_t unaligned_uint64_t;
319-
320-
static BROTLI_INLINE uint64_t BrotliUnalignedRead64(const void* p) {
321-
return (uint64_t) ((unaligned_uint64_t*) p)[0];
322-
}
323-
static BROTLI_INLINE void BrotliUnalignedWrite64(void* p, uint64_t v) {
324-
unaligned_uint64_t* dwords = (unaligned_uint64_t*) p;
325-
dwords[0] = (unaligned_uint64_t) v;
326-
}
327-
#else /* BROTLI_GNUC_HAS_ATTRIBUTE(aligned, 2, 7, 0) */
328-
329-
/* Alternative way to avoid LDRD/STRD is use volatile pointers. See:
330-
* http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka16346.html
331-
*/
332309
static BROTLI_INLINE uint64_t BrotliUnalignedRead64(const void* p) {
333-
return (uint64_t) *((volatile uint32_t*) p)
334-
| ((uint64_t) *((volatile uint32_t*) p+1) << 32);
310+
const uint32_t* dwords = (const uint32_t*)p;
311+
return dwords[0] | ((uint64_t)dwords[1] << 32);
335312
}
336-
337313
static BROTLI_INLINE void BrotliUnalignedWrite64(void* p, uint64_t v) {
338-
*((volatile uint32_t*) p) = (uint32_t) v;
339-
*((volatile uint32_t*) p+1) = (uint32_t) (v >> 32);
314+
uint32_t* dwords = (uint32_t *)p;
315+
dwords[0] = (uint32_t)v;
316+
dwords[1] = (uint32_t)(v >> 32);
340317
}
341-
342-
#endif /* BROTLI_GNUC_HAS_ATTRIBUTE(aligned, 2, 7, 0) */
343318
#endif /* BROTLI_64_BITS */
344319
#endif /* BROTLI_ALIGNED_READ */
345320

@@ -425,7 +400,7 @@ static BROTLI_INLINE void BROTLI_UNALIGNED_STORE64LE(void* p, uint64_t v) {
425400
#define BROTLI_IS_CONSTANT(x) (!!0)
426401
#endif
427402

428-
#if defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8_ANY)
403+
#if defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8)
429404
#define BROTLI_HAS_UBFX (!!1)
430405
#else
431406
#define BROTLI_HAS_UBFX (!!0)
@@ -452,7 +427,7 @@ static BROTLI_INLINE void BrotliDump(const char* f, int l, const char* fn) {
452427
/* TODO: add appropriate icc/sunpro/arm/ibm/ti checks. */
453428
#if (BROTLI_GNUC_VERSION_CHECK(3, 0, 0) || defined(__llvm__)) && \
454429
!defined(BROTLI_BUILD_NO_RBIT)
455-
#if defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8_ANY)
430+
#if defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8)
456431
/* TODO: detect ARMv6T2 and enable this code for it. */
457432
static BROTLI_INLINE brotli_reg_t BrotliRBit(brotli_reg_t input) {
458433
brotli_reg_t output;

0 commit comments

Comments
 (0)