Allow endian-aware optimizations only on whitelisted CPUs.
This commit is contained in:
+11
@@ -60,4 +60,15 @@ inline int Log2Floor(uint32 n) {
|
||||
#define PREDICT_TRUE(x) (x)
|
||||
#endif
|
||||
|
||||
#if (defined(__ARM_ARCH) && (__ARM_ARCH == 7)) || \
|
||||
(defined(M_ARM) && (M_ARM == 7)) || \
|
||||
defined(__aarch64__) || defined(__ARM64_ARCH_8__) || defined(__i386) || \
|
||||
defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64)
|
||||
#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
|
||||
#define WOFF_LITTLE_ENDIAN
|
||||
#elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
|
||||
#define WOFF_BIG_ENDIAN
|
||||
#endif /* endianness */
|
||||
#endif /* CPU whitelist */
|
||||
|
||||
#endif // WOFF2_PORT_H_
|
||||
|
||||
+6
-4
@@ -22,6 +22,8 @@
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "./port.h"
|
||||
|
||||
namespace woff2 {
|
||||
|
||||
inline size_t StoreU32(uint8_t* dst, size_t offset, uint32_t x) {
|
||||
@@ -33,10 +35,10 @@ inline size_t StoreU32(uint8_t* dst, size_t offset, uint32_t x) {
|
||||
}
|
||||
|
||||
inline size_t Store16(uint8_t* dst, size_t offset, int x) {
|
||||
#if (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
|
||||
#if defined(WOFF_LITTLE_ENDIAN)
|
||||
*reinterpret_cast<uint16_t*>(dst + offset) =
|
||||
((x & 0xFF) << 8) | ((x & 0xFF00) >> 8);
|
||||
#elif (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
|
||||
#elif defined(WOFF_BIG_ENDIAN)
|
||||
*reinterpret_cast<uint16_t*>(dst + offset) = static_cast<uint16_t>(x);
|
||||
#else
|
||||
dst[offset] = x >> 8;
|
||||
@@ -53,11 +55,11 @@ inline void StoreU32(uint32_t val, size_t* offset, uint8_t* dst) {
|
||||
}
|
||||
|
||||
inline void Store16(int val, size_t* offset, uint8_t* dst) {
|
||||
#if (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
|
||||
#if defined(WOFF_LITTLE_ENDIAN)
|
||||
*reinterpret_cast<uint16_t*>(dst + *offset) =
|
||||
((val & 0xFF) << 8) | ((val & 0xFF00) >> 8);
|
||||
*offset += 2;
|
||||
#elif (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
|
||||
#elif defined(WOFF_BIG_ENDIAN)
|
||||
*reinterpret_cast<uint16_t*>(dst + *offset) = static_cast<uint16_t>(val);
|
||||
*offset += 2;
|
||||
#else
|
||||
|
||||
+4
-2
@@ -18,6 +18,8 @@
|
||||
|
||||
#include "./woff2_common.h"
|
||||
|
||||
#include "./port.h"
|
||||
|
||||
namespace woff2 {
|
||||
|
||||
|
||||
@@ -25,11 +27,11 @@ uint32_t ComputeULongSum(const uint8_t* buf, size_t size) {
|
||||
uint32_t checksum = 0;
|
||||
size_t aligned_size = size & ~3;
|
||||
for (size_t i = 0; i < aligned_size; i += 4) {
|
||||
#if (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
|
||||
#if defined(WOFF_LITTLE_ENDIAN)
|
||||
uint32_t v = *reinterpret_cast<const uint32_t*>(buf + i);
|
||||
checksum += (((v & 0xFF) << 24) | ((v & 0xFF00) << 8) |
|
||||
((v & 0xFF0000) >> 8) | ((v & 0xFF000000) >> 24));
|
||||
#elif (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
|
||||
#elif defined(WOFF_BIG_ENDIAN)
|
||||
checksum += *reinterpret_cast<const uint32_t*>(buf + i);
|
||||
#else
|
||||
checksum += (buf[i] << 24) | (buf[i + 1] << 16) |
|
||||
|
||||
Reference in New Issue
Block a user