Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: third_party/libwebp/utils/endian_inl.h

Issue 653803003: libwebp: update to 0.4.2-rc2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/libwebp/utils/bit_writer.c ('k') | third_party/libwebp/utils/quant_levels_dec.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 Google Inc. All Rights Reserved. 1 // Copyright 2014 Google Inc. All Rights Reserved.
2 // 2 //
3 // Use of this source code is governed by a BSD-style license 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 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 5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS. All contributing project authors may 6 // in the file PATENTS. All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree. 7 // be found in the AUTHORS file in the root of the source tree.
8 // ----------------------------------------------------------------------------- 8 // -----------------------------------------------------------------------------
9 // 9 //
10 // Endian related functions. 10 // Endian related functions.
11 11
12 #ifndef WEBP_UTILS_ENDIAN_INL_H_ 12 #ifndef WEBP_UTILS_ENDIAN_INL_H_
13 #define WEBP_UTILS_ENDIAN_INL_H_ 13 #define WEBP_UTILS_ENDIAN_INL_H_
14 14
15 #ifdef HAVE_CONFIG_H 15 #ifdef HAVE_CONFIG_H
16 #include "../webp/config.h" 16 #include "../webp/config.h"
17 #endif 17 #endif
18 18
19 #include "../dsp/dsp.h"
19 #include "../webp/types.h" 20 #include "../webp/types.h"
20 21
21 // some endian fix (e.g.: mips-gcc doesn't define __BIG_ENDIAN__) 22 // some endian fix (e.g.: mips-gcc doesn't define __BIG_ENDIAN__)
22 #if !defined(WORDS_BIGENDIAN) && \ 23 #if !defined(WORDS_BIGENDIAN) && \
23 (defined(__BIG_ENDIAN__) || defined(_M_PPC) || \ 24 (defined(__BIG_ENDIAN__) || defined(_M_PPC) || \
24 (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))) 25 (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)))
25 #define WORDS_BIGENDIAN 26 #define WORDS_BIGENDIAN
26 #endif 27 #endif
27 28
28 #if defined(WORDS_BIGENDIAN) 29 #if defined(WORDS_BIGENDIAN)
29 #define HToLE32 BSwap32 30 #define HToLE32 BSwap32
30 #define HToLE16 BSwap16 31 #define HToLE16 BSwap16
31 #else 32 #else
32 #define HToLE32(x) (x) 33 #define HToLE32(x) (x)
33 #define HToLE16(x) (x) 34 #define HToLE16(x) (x)
34 #endif 35 #endif
35 36
36 #if !defined(HAVE_CONFIG_H) 37 #if !defined(HAVE_CONFIG_H)
37 #ifdef __GNUC__
38 # define LOCAL_GCC_VERSION ((__GNUC__ << 8) | __GNUC_MINOR__)
39 #else
40 # define LOCAL_GCC_VERSION 0
41 #endif // __GNUC__
42
43 #ifdef __clang__
44 # define LOCAL_CLANG_VERSION ((__clang_major__ << 8) | __clang_minor__)
45 #else
46 # define LOCAL_CLANG_VERSION 0
47 #endif // __clang__
48
49 // clang-3.3 and gcc-4.3 have builtin functions for swap32/swap64 38 // clang-3.3 and gcc-4.3 have builtin functions for swap32/swap64
50 #if LOCAL_GCC_VERSION >= 0x403 || LOCAL_CLANG_VERSION >= 0x303 39 #if LOCAL_GCC_PREREQ(4,3) || LOCAL_CLANG_PREREQ(3,3)
51 #define HAVE_BUILTIN_BSWAP32 40 #define HAVE_BUILTIN_BSWAP32
52 #define HAVE_BUILTIN_BSWAP64 41 #define HAVE_BUILTIN_BSWAP64
53 #endif 42 #endif
54 // clang-3.3 and gcc-4.8 have a builtin function for swap16 43 // clang-3.3 and gcc-4.8 have a builtin function for swap16
55 #if LOCAL_GCC_VERSION >= 0x408 || LOCAL_CLANG_VERSION >= 0x303 44 #if LOCAL_GCC_PREREQ(4,8) || LOCAL_CLANG_PREREQ(3,3)
56 #define HAVE_BUILTIN_BSWAP16 45 #define HAVE_BUILTIN_BSWAP16
57 #endif 46 #endif
58 #endif // !HAVE_CONFIG_H 47 #endif // !HAVE_CONFIG_H
59 48
60 static WEBP_INLINE uint16_t BSwap16(uint16_t x) { 49 static WEBP_INLINE uint16_t BSwap16(uint16_t x) {
61 #if defined(HAVE_BUILTIN_BSWAP16) 50 #if defined(HAVE_BUILTIN_BSWAP16)
62 return __builtin_bswap16(x); 51 return __builtin_bswap16(x);
63 #elif defined(_MSC_VER) 52 #elif defined(_MSC_VER)
64 return _byteswap_ushort(x); 53 return _byteswap_ushort(x);
65 #else 54 #else
66 // gcc will recognize a 'rorw $8, ...' here: 55 // gcc will recognize a 'rorw $8, ...' here:
67 return (x >> 8) | ((x & 0xff) << 8); 56 return (x >> 8) | ((x & 0xff) << 8);
68 #endif // HAVE_BUILTIN_BSWAP16 57 #endif // HAVE_BUILTIN_BSWAP16
69 } 58 }
70 59
71 static WEBP_INLINE uint32_t BSwap32(uint32_t x) { 60 static WEBP_INLINE uint32_t BSwap32(uint32_t x) {
72 #if defined(HAVE_BUILTIN_BSWAP32) 61 #if defined(WEBP_USE_MIPS32_R2)
62 uint32_t ret;
63 __asm__ volatile (
64 "wsbh %[ret], %[x] \n\t"
65 "rotr %[ret], %[ret], 16 \n\t"
66 : [ret]"=r"(ret)
67 : [x]"r"(x)
68 );
69 return ret;
70 #elif defined(HAVE_BUILTIN_BSWAP32)
73 return __builtin_bswap32(x); 71 return __builtin_bswap32(x);
74 #elif defined(__i386__) || defined(__x86_64__) 72 #elif defined(__i386__) || defined(__x86_64__)
75 uint32_t swapped_bytes; 73 uint32_t swapped_bytes;
76 __asm__ volatile("bswap %0" : "=r"(swapped_bytes) : "0"(x)); 74 __asm__ volatile("bswap %0" : "=r"(swapped_bytes) : "0"(x));
77 return swapped_bytes; 75 return swapped_bytes;
78 #elif defined(_MSC_VER) 76 #elif defined(_MSC_VER)
79 return (uint32_t)_byteswap_ulong(x); 77 return (uint32_t)_byteswap_ulong(x);
80 #else 78 #else
81 return (x >> 24) | ((x >> 8) & 0xff00) | ((x << 8) & 0xff0000) | (x << 24); 79 return (x >> 24) | ((x >> 8) & 0xff00) | ((x << 8) & 0xff0000) | (x << 24);
82 #endif // HAVE_BUILTIN_BSWAP32 80 #endif // HAVE_BUILTIN_BSWAP32
(...skipping 10 matching lines...) Expand all
93 return (uint64_t)_byteswap_uint64(x); 91 return (uint64_t)_byteswap_uint64(x);
94 #else // generic code for swapping 64-bit values (suggested by bdb@) 92 #else // generic code for swapping 64-bit values (suggested by bdb@)
95 x = ((x & 0xffffffff00000000ull) >> 32) | ((x & 0x00000000ffffffffull) << 32); 93 x = ((x & 0xffffffff00000000ull) >> 32) | ((x & 0x00000000ffffffffull) << 32);
96 x = ((x & 0xffff0000ffff0000ull) >> 16) | ((x & 0x0000ffff0000ffffull) << 16); 94 x = ((x & 0xffff0000ffff0000ull) >> 16) | ((x & 0x0000ffff0000ffffull) << 16);
97 x = ((x & 0xff00ff00ff00ff00ull) >> 8) | ((x & 0x00ff00ff00ff00ffull) << 8); 95 x = ((x & 0xff00ff00ff00ff00ull) >> 8) | ((x & 0x00ff00ff00ff00ffull) << 8);
98 return x; 96 return x;
99 #endif // HAVE_BUILTIN_BSWAP64 97 #endif // HAVE_BUILTIN_BSWAP64
100 } 98 }
101 99
102 #endif // WEBP_UTILS_ENDIAN_INL_H_ 100 #endif // WEBP_UTILS_ENDIAN_INL_H_
OLDNEW
« no previous file with comments | « third_party/libwebp/utils/bit_writer.c ('k') | third_party/libwebp/utils/quant_levels_dec.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698