/src/libwebp/src/utils/endian_inl_utils.h
Line | Count | Source |
1 | | // Copyright 2014 Google Inc. All Rights Reserved. |
2 | | // |
3 | | // Use of this source code is governed by a BSD-style license |
4 | | // that can be found in the COPYING file in the root of the source |
5 | | // tree. An additional intellectual property rights grant can be found |
6 | | // in the file PATENTS. All contributing project authors may |
7 | | // be found in the AUTHORS file in the root of the source tree. |
8 | | // ----------------------------------------------------------------------------- |
9 | | // |
10 | | // Endian related functions. |
11 | | |
12 | | #ifndef WEBP_UTILS_ENDIAN_INL_UTILS_H_ |
13 | | #define WEBP_UTILS_ENDIAN_INL_UTILS_H_ |
14 | | |
15 | | #ifdef HAVE_CONFIG_H |
16 | | #include "src/webp/config.h" |
17 | | #endif |
18 | | |
19 | | #include "src/dsp/dsp.h" |
20 | | #include "src/utils/bounds_safety.h" |
21 | | #include "src/webp/types.h" |
22 | | |
23 | | WEBP_ASSUME_UNSAFE_INDEXABLE_ABI |
24 | | |
25 | | #if defined(WORDS_BIGENDIAN) |
26 | | #define HToLE32 BSwap32 |
27 | | #define HToLE16 BSwap16 |
28 | | #else |
29 | 40.6M | #define HToLE32(x) (x) |
30 | | #define HToLE16(x) (x) |
31 | | #endif |
32 | | |
33 | | #if !defined(HAVE_CONFIG_H) |
34 | | #if LOCAL_GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
35 | | #define HAVE_BUILTIN_BSWAP16 |
36 | | #endif |
37 | | #if LOCAL_GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
38 | | #define HAVE_BUILTIN_BSWAP32 |
39 | | #endif |
40 | | #if LOCAL_GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
41 | | #define HAVE_BUILTIN_BSWAP64 |
42 | | #endif |
43 | | #endif // !HAVE_CONFIG_H |
44 | | |
45 | 0 | static WEBP_INLINE uint16_t BSwap16(uint16_t x) { |
46 | 0 | #if defined(HAVE_BUILTIN_BSWAP16) |
47 | 0 | return __builtin_bswap16(x); |
48 | 0 | #elif defined(_MSC_VER) |
49 | 0 | return _byteswap_ushort(x); |
50 | 0 | #else |
51 | 0 | // gcc will recognize a 'rorw $8, ...' here: |
52 | 0 | return (x >> 8) | ((x & 0xff) << 8); |
53 | 0 | #endif // HAVE_BUILTIN_BSWAP16 |
54 | 0 | } Unexecuted instantiation: tree_dec.c:BSwap16 Unexecuted instantiation: vp8_dec.c:BSwap16 Unexecuted instantiation: lossless.c:BSwap16 Unexecuted instantiation: bit_reader_utils.c:BSwap16 Unexecuted instantiation: bit_writer_utils.c:BSwap16 |
55 | | |
56 | 0 | static WEBP_INLINE uint32_t BSwap32(uint32_t x) { |
57 | | #if defined(WEBP_USE_MIPS32_R2) |
58 | | uint32_t ret; |
59 | | __asm__ volatile( |
60 | | "wsbh %[ret], %[x] \n\t" |
61 | | "rotr %[ret], %[ret], 16 \n\t" |
62 | | : [ret] "=r"(ret) |
63 | | : [x] "r"(x)); |
64 | | return ret; |
65 | | #elif defined(HAVE_BUILTIN_BSWAP32) |
66 | | return __builtin_bswap32(x); |
67 | | #elif defined(__i386__) || defined(__x86_64__) |
68 | | uint32_t swapped_bytes; |
69 | | __asm__ volatile("bswap %0" : "=r"(swapped_bytes) : "0"(x)); |
70 | | return swapped_bytes; |
71 | | #elif defined(_MSC_VER) |
72 | | return (uint32_t)_byteswap_ulong(x); |
73 | | #else |
74 | | return (x >> 24) | ((x >> 8) & 0xff00) | ((x << 8) & 0xff0000) | (x << 24); |
75 | | #endif // HAVE_BUILTIN_BSWAP32 |
76 | 0 | } Unexecuted instantiation: tree_dec.c:BSwap32 Unexecuted instantiation: vp8_dec.c:BSwap32 Unexecuted instantiation: lossless.c:BSwap32 Unexecuted instantiation: bit_reader_utils.c:BSwap32 Unexecuted instantiation: bit_writer_utils.c:BSwap32 |
77 | | |
78 | 2.24M | static WEBP_INLINE uint64_t BSwap64(uint64_t x) { |
79 | 2.24M | #if defined(HAVE_BUILTIN_BSWAP64) |
80 | 2.24M | return __builtin_bswap64(x); |
81 | | #elif defined(__x86_64__) |
82 | | uint64_t swapped_bytes; |
83 | | __asm__ volatile("bswapq %0" : "=r"(swapped_bytes) : "0"(x)); |
84 | | return swapped_bytes; |
85 | | #elif defined(_MSC_VER) |
86 | | return (uint64_t)_byteswap_uint64(x); |
87 | | #else // generic code for swapping 64-bit values (suggested by bdb@) |
88 | | x = ((x & 0xffffffff00000000ull) >> 32) | ((x & 0x00000000ffffffffull) << 32); |
89 | | x = ((x & 0xffff0000ffff0000ull) >> 16) | ((x & 0x0000ffff0000ffffull) << 16); |
90 | | x = ((x & 0xff00ff00ff00ff00ull) >> 8) | ((x & 0x00ff00ff00ff00ffull) << 8); |
91 | | return x; |
92 | | #endif // HAVE_BUILTIN_BSWAP64 |
93 | 2.24M | } Line | Count | Source | 78 | 125k | static WEBP_INLINE uint64_t BSwap64(uint64_t x) { | 79 | 125k | #if defined(HAVE_BUILTIN_BSWAP64) | 80 | 125k | return __builtin_bswap64(x); | 81 | | #elif defined(__x86_64__) | 82 | | uint64_t swapped_bytes; | 83 | | __asm__ volatile("bswapq %0" : "=r"(swapped_bytes) : "0"(x)); | 84 | | return swapped_bytes; | 85 | | #elif defined(_MSC_VER) | 86 | | return (uint64_t)_byteswap_uint64(x); | 87 | | #else // generic code for swapping 64-bit values (suggested by bdb@) | 88 | | x = ((x & 0xffffffff00000000ull) >> 32) | ((x & 0x00000000ffffffffull) << 32); | 89 | | x = ((x & 0xffff0000ffff0000ull) >> 16) | ((x & 0x0000ffff0000ffffull) << 16); | 90 | | x = ((x & 0xff00ff00ff00ff00ull) >> 8) | ((x & 0x00ff00ff00ff00ffull) << 8); | 91 | | return x; | 92 | | #endif // HAVE_BUILTIN_BSWAP64 | 93 | 125k | } |
Line | Count | Source | 78 | 1.39M | static WEBP_INLINE uint64_t BSwap64(uint64_t x) { | 79 | 1.39M | #if defined(HAVE_BUILTIN_BSWAP64) | 80 | 1.39M | return __builtin_bswap64(x); | 81 | | #elif defined(__x86_64__) | 82 | | uint64_t swapped_bytes; | 83 | | __asm__ volatile("bswapq %0" : "=r"(swapped_bytes) : "0"(x)); | 84 | | return swapped_bytes; | 85 | | #elif defined(_MSC_VER) | 86 | | return (uint64_t)_byteswap_uint64(x); | 87 | | #else // generic code for swapping 64-bit values (suggested by bdb@) | 88 | | x = ((x & 0xffffffff00000000ull) >> 32) | ((x & 0x00000000ffffffffull) << 32); | 89 | | x = ((x & 0xffff0000ffff0000ull) >> 16) | ((x & 0x0000ffff0000ffffull) << 16); | 90 | | x = ((x & 0xff00ff00ff00ff00ull) >> 8) | ((x & 0x00ff00ff00ff00ffull) << 8); | 91 | | return x; | 92 | | #endif // HAVE_BUILTIN_BSWAP64 | 93 | 1.39M | } |
Unexecuted instantiation: lossless.c:BSwap64 bit_reader_utils.c:BSwap64 Line | Count | Source | 78 | 720k | static WEBP_INLINE uint64_t BSwap64(uint64_t x) { | 79 | 720k | #if defined(HAVE_BUILTIN_BSWAP64) | 80 | 720k | return __builtin_bswap64(x); | 81 | | #elif defined(__x86_64__) | 82 | | uint64_t swapped_bytes; | 83 | | __asm__ volatile("bswapq %0" : "=r"(swapped_bytes) : "0"(x)); | 84 | | return swapped_bytes; | 85 | | #elif defined(_MSC_VER) | 86 | | return (uint64_t)_byteswap_uint64(x); | 87 | | #else // generic code for swapping 64-bit values (suggested by bdb@) | 88 | | x = ((x & 0xffffffff00000000ull) >> 32) | ((x & 0x00000000ffffffffull) << 32); | 89 | | x = ((x & 0xffff0000ffff0000ull) >> 16) | ((x & 0x0000ffff0000ffffull) << 16); | 90 | | x = ((x & 0xff00ff00ff00ff00ull) >> 8) | ((x & 0x00ff00ff00ff00ffull) << 8); | 91 | | return x; | 92 | | #endif // HAVE_BUILTIN_BSWAP64 | 93 | 720k | } |
Unexecuted instantiation: bit_writer_utils.c:BSwap64 |
94 | | |
95 | | #endif // WEBP_UTILS_ENDIAN_INL_UTILS_H_ |