From 3884972e3f9ae887e0c16ca342851eff3ae67485 Mon Sep 17 00:00:00 2001 From: Pascal Massimino Date: Wed, 17 Aug 2016 12:09:53 -0700 Subject: [PATCH] remove WEBP_FORCE_ALIGNED and use memcpy() instead. BUG=webp:297 Change-Id: I89a08debec7bb1b3f411c897260ab1bb63f77df2 --- CMakeLists.txt | 1 - cmake/config.h.in | 3 --- configure.ac | 13 ------------- src/dsp/dsp.h | 3 +-- src/utils/bit_reader_inl.h | 12 ++++-------- src/utils/utils.h | 11 ----------- 6 files changed, 5 insertions(+), 38 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ab7e1685..25b085eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,6 @@ project(libwebp C) option(WEBP_BUILD_CWEBP "Build the cwebp command line tool." OFF) option(WEBP_BUILD_DWEBP "Build the dwebp command line tool." OFF) option(WEBP_EXPERIMENTAL_FEATURES "Build with experimental features." OFF) -option(WEBP_FORCE_ALIGNED "Force aligned memory operations." OFF) option(WEBP_ENABLE_SWAP_16BIT_CSP "Enable byte swap for 16 bit colorspaces." OFF) set(WEBP_DEP_LIBRARIES) diff --git a/cmake/config.h.in b/cmake/config.h.in index cb3948ea..52ff857c 100644 --- a/cmake/config.h.in +++ b/cmake/config.h.in @@ -103,9 +103,6 @@ /* Enable experimental code */ #cmakedefine WEBP_EXPERIMENTAL_FEATURES 1 -/* Define to 1 to force aligned memory operations */ -#cmakedefine WEBP_FORCE_ALIGNED 1 - /* Set to 1 if AVX2 is supported */ #cmakedefine WEBP_HAVE_AVX2 1 diff --git a/configure.ac b/configure.ac index df31acc1..4c2f929c 100644 --- a/configure.ac +++ b/configure.ac @@ -596,19 +596,6 @@ if test "$enable_wic" = "yes"; then fi esac -dnl === If --enable-aligned is defined, define WEBP_FORCE_ALIGNED - -AC_MSG_CHECKING(if --enable-aligned option is specified) -AC_ARG_ENABLE([aligned], - AS_HELP_STRING([--enable-aligned], - [Force aligned memory operations in non-dsp code - (may be slower)])) -if test "$enable_aligned" = "yes"; then - AC_DEFINE(WEBP_FORCE_ALIGNED, [1], - [Define to 1 to force aligned memory operations]) -fi -AC_MSG_RESULT(${enable_aligned-no}) - dnl === If --enable-swap-16bit-csp is defined, add -DWEBP_SWAP_16BIT_CSP USE_SWAP_16BIT_CSP="" diff --git a/src/dsp/dsp.h b/src/dsp/dsp.h index d2e59ed5..ac0ccd78 100644 --- a/src/dsp/dsp.h +++ b/src/dsp/dsp.h @@ -111,8 +111,7 @@ extern "C" { #define WEBP_UBSAN_IGNORE_UNDEF #define WEBP_UBSAN_IGNORE_UNSIGNED_OVERFLOW -#if !defined(WEBP_FORCE_ALIGNED) && defined(__clang__) && \ - defined(__has_attribute) +#if defined(__clang__) && defined(__has_attribute) #if __has_attribute(no_sanitize) // This macro prevents the undefined behavior sanitizer from reporting // failures. This is only meant to silence unaligned loads on platforms that diff --git a/src/utils/bit_reader_inl.h b/src/utils/bit_reader_inl.h index 36570566..003f6a88 100644 --- a/src/utils/bit_reader_inl.h +++ b/src/utils/bit_reader_inl.h @@ -20,9 +20,7 @@ #include "../webp/config.h" #endif -#ifdef WEBP_FORCE_ALIGNED -#include // memcpy -#endif +#include // for memcpy #include "../dsp/dsp.h" #include "./bit_reader.h" @@ -62,10 +60,7 @@ void VP8LoadNewBytes(VP8BitReader* const br) { if (br->buf_ < br->buf_max_) { // convert memory type to register type (with some zero'ing!) bit_t bits; -#if defined(WEBP_FORCE_ALIGNED) - lbit_t in_bits; - memcpy(&in_bits, br->buf_, sizeof(in_bits)); -#elif defined(WEBP_USE_MIPS32) +#if defined(WEBP_USE_MIPS32) // This is needed because of un-aligned read. lbit_t in_bits; lbit_t* p_buf_ = (lbit_t*)br->buf_; @@ -80,7 +75,8 @@ void VP8LoadNewBytes(VP8BitReader* const br) { : "memory", "at" ); #else - const lbit_t in_bits = *(const lbit_t*)br->buf_; + lbit_t in_bits; + memcpy(&in_bits, br->buf_, sizeof(in_bits)); #endif br->buf_ += BITS >> 3; #if !defined(WORDS_BIGENDIAN) diff --git a/src/utils/utils.h b/src/utils/utils.h index f2066841..6345424c 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -54,7 +54,6 @@ WEBP_EXTERN(void) WebPSafeFree(void* const ptr); #define WEBP_ALIGN_CST 31 #define WEBP_ALIGN(PTR) (((uintptr_t)(PTR) + WEBP_ALIGN_CST) & ~WEBP_ALIGN_CST) -#if defined(WEBP_FORCE_ALIGNED) #include // memcpy() is the safe way of moving potentially unaligned 32b memory. static WEBP_INLINE uint32_t WebPMemToUint32(const uint8_t* const ptr) { @@ -65,16 +64,6 @@ static WEBP_INLINE uint32_t WebPMemToUint32(const uint8_t* const ptr) { static WEBP_INLINE void WebPUint32ToMem(uint8_t* const ptr, uint32_t val) { memcpy(ptr, &val, sizeof(val)); } -#else -static WEBP_UBSAN_IGNORE_UNDEF WEBP_INLINE -uint32_t WebPMemToUint32(const uint8_t* const ptr) { - return *(const uint32_t*)ptr; -} -static WEBP_UBSAN_IGNORE_UNDEF WEBP_INLINE -void WebPUint32ToMem(uint8_t* const ptr, uint32_t val) { - *(uint32_t*)ptr = val; -} -#endif //------------------------------------------------------------------------------ // Reading/writing data.