OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #ifndef SkEndian_DEFINED | 10 #ifndef SkEndian_DEFINED |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 ((value & 0xFF0000) >> 8) | | 58 ((value & 0xFF0000) >> 8) | |
59 (value >> 24); | 59 (value >> 24); |
60 } | 60 } |
61 template<uint32_t N> struct SkTEndianSwap32 { | 61 template<uint32_t N> struct SkTEndianSwap32 { |
62 static const uint32_t value = ((N & 0xFF) << 24) | | 62 static const uint32_t value = ((N & 0xFF) << 24) | |
63 ((N & 0xFF00) << 8) | | 63 ((N & 0xFF00) << 8) | |
64 ((N & 0xFF0000) >> 8) | | 64 ((N & 0xFF0000) >> 8) | |
65 (N >> 24); | 65 (N >> 24); |
66 }; | 66 }; |
67 | 67 |
68 /** Vector version of SkEndianSwap16(), which swaps the | 68 /** Vector version of SkEndianSwap32(), which swaps the |
69 bytes of each value in the array. | 69 bytes of each value in the array. |
70 */ | 70 */ |
71 static inline void SkEndianSwap32s(uint32_t array[], int count) { | 71 static inline void SkEndianSwap32s(uint32_t array[], int count) { |
72 SkASSERT(count == 0 || array != NULL); | 72 SkASSERT(count == 0 || array != NULL); |
73 | 73 |
74 while (--count >= 0) { | 74 while (--count >= 0) { |
75 *array = SkEndianSwap32(*array); | 75 *array = SkEndianSwap32(*array); |
76 array += 1; | 76 array += 1; |
77 } | 77 } |
78 } | 78 } |
79 | 79 |
80 /** Reverse all 8 bytes in a 64bit value. | |
81 e.g. 0x1122334455667788 -> 0x8877665544332211 | |
82 */ | |
83 static inline uint64_t SkEndianSwap64(uint64_t value) { | |
epoger
2013/05/03 16:28:00
Added 64-bit versions of the various converters...
| |
84 return (((value & 0x00000000000000FFULL) << (8*7)) | | |
85 ((value & 0x000000000000FF00ULL) << (8*5)) | | |
86 ((value & 0x0000000000FF0000ULL) << (8*3)) | | |
87 ((value & 0x00000000FF000000ULL) << (8*1)) | | |
88 ((value & 0x000000FF00000000ULL) >> (8*1)) | | |
89 ((value & 0x0000FF0000000000ULL) >> (8*3)) | | |
90 ((value & 0x00FF000000000000ULL) >> (8*5)) | | |
91 ((value) >> (8*7))); | |
92 } | |
93 template<uint64_t N> struct SkTEndianSwap64 { | |
94 static const uint64_t value = (((N & 0x00000000000000FFULL) << (8*7)) | | |
95 ((N & 0x000000000000FF00ULL) << (8*5)) | | |
96 ((N & 0x0000000000FF0000ULL) << (8*3)) | | |
97 ((N & 0x00000000FF000000ULL) << (8*1)) | | |
98 ((N & 0x000000FF00000000ULL) >> (8*1)) | | |
99 ((N & 0x0000FF0000000000ULL) >> (8*3)) | | |
100 ((N & 0x00FF000000000000ULL) >> (8*5)) | | |
101 ((N) >> (8*7))); | |
102 }; | |
103 | |
104 /** Vector version of SkEndianSwap64(), which swaps the | |
105 bytes of each value in the array. | |
106 */ | |
107 static inline void SkEndianSwap64s(uint64_t array[], int count) { | |
108 SkASSERT(count == 0 || array != NULL); | |
109 | |
110 while (--count >= 0) { | |
111 *array = SkEndianSwap64(*array); | |
112 array += 1; | |
113 } | |
114 } | |
115 | |
80 #ifdef SK_CPU_LENDIAN | 116 #ifdef SK_CPU_LENDIAN |
81 #define SkEndian_SwapBE16(n) SkEndianSwap16(n) | 117 #define SkEndian_SwapBE16(n) SkEndianSwap16(n) |
82 #define SkEndian_SwapBE32(n) SkEndianSwap32(n) | 118 #define SkEndian_SwapBE32(n) SkEndianSwap32(n) |
119 #define SkEndian_SwapBE64(n) SkEndianSwap64(n) | |
83 #define SkEndian_SwapLE16(n) (n) | 120 #define SkEndian_SwapLE16(n) (n) |
84 #define SkEndian_SwapLE32(n) (n) | 121 #define SkEndian_SwapLE32(n) (n) |
122 #define SkEndian_SwapLE64(n) (n) | |
85 | 123 |
86 #define SkTEndian_SwapBE16(n) SkTEndianSwap16<n>::value | 124 #define SkTEndian_SwapBE16(n) SkTEndianSwap16<n>::value |
87 #define SkTEndian_SwapBE32(n) SkTEndianSwap32<n>::value | 125 #define SkTEndian_SwapBE32(n) SkTEndianSwap32<n>::value |
126 #define SkTEndian_SwapBE64(n) SkTEndianSwap64<n>::value | |
88 #define SkTEndian_SwapLE16(n) (n) | 127 #define SkTEndian_SwapLE16(n) (n) |
89 #define SkTEndian_SwapLE32(n) (n) | 128 #define SkTEndian_SwapLE32(n) (n) |
129 #define SkTEndian_SwapLE64(n) (n) | |
90 #else // SK_CPU_BENDIAN | 130 #else // SK_CPU_BENDIAN |
91 #define SkEndian_SwapBE16(n) (n) | 131 #define SkEndian_SwapBE16(n) (n) |
92 #define SkEndian_SwapBE32(n) (n) | 132 #define SkEndian_SwapBE32(n) (n) |
133 #define SkEndian_SwapBE64(n) (n) | |
93 #define SkEndian_SwapLE16(n) SkEndianSwap16(n) | 134 #define SkEndian_SwapLE16(n) SkEndianSwap16(n) |
94 #define SkEndian_SwapLE32(n) SkEndianSwap32(n) | 135 #define SkEndian_SwapLE32(n) SkEndianSwap32(n) |
136 #define SkEndian_SwapLE64(n) SkEndianSwap64(n) | |
95 | 137 |
96 #define SkTEndian_SwapBE16(n) (n) | 138 #define SkTEndian_SwapBE16(n) (n) |
97 #define SkTEndian_SwapBE32(n) (n) | 139 #define SkTEndian_SwapBE32(n) (n) |
140 #define SkTEndian_SwapBE64(n) (n) | |
98 #define SkTEndian_SwapLE16(n) SkTEndianSwap16<n>::value | 141 #define SkTEndian_SwapLE16(n) SkTEndianSwap16<n>::value |
99 #define SkTEndian_SwapLE32(n) SkTEndianSwap32<n>::value | 142 #define SkTEndian_SwapLE32(n) SkTEndianSwap32<n>::value |
143 #define SkTEndian_SwapLE64(n) SkTEndianSwap64<n>::value | |
100 #endif | 144 #endif |
101 | 145 |
102 // When a bytestream is embedded in a 32-bit word, how far we need to | 146 // When a bytestream is embedded in a 32-bit word, how far we need to |
103 // shift the word to extract each byte from the low 8 bits by anding with 0xff. | 147 // shift the word to extract each byte from the low 8 bits by anding with 0xff. |
104 #ifdef SK_CPU_LENDIAN | 148 #ifdef SK_CPU_LENDIAN |
105 #define SkEndian_Byte0Shift 0 | 149 #define SkEndian_Byte0Shift 0 |
106 #define SkEndian_Byte1Shift 8 | 150 #define SkEndian_Byte1Shift 8 |
107 #define SkEndian_Byte2Shift 16 | 151 #define SkEndian_Byte2Shift 16 |
108 #define SkEndian_Byte3Shift 24 | 152 #define SkEndian_Byte3Shift 24 |
109 #else // SK_CPU_BENDIAN | 153 #else // SK_CPU_BENDIAN |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 SK_OT_BYTE f6 : 1; \ | 186 SK_OT_BYTE f6 : 1; \ |
143 SK_OT_BYTE f5 : 1; \ | 187 SK_OT_BYTE f5 : 1; \ |
144 SK_OT_BYTE f4 : 1; \ | 188 SK_OT_BYTE f4 : 1; \ |
145 SK_OT_BYTE f3 : 1; \ | 189 SK_OT_BYTE f3 : 1; \ |
146 SK_OT_BYTE f2 : 1; \ | 190 SK_OT_BYTE f2 : 1; \ |
147 SK_OT_BYTE f1 : 1; \ | 191 SK_OT_BYTE f1 : 1; \ |
148 SK_OT_BYTE f0 : 1; | 192 SK_OT_BYTE f0 : 1; |
149 #endif | 193 #endif |
150 | 194 |
151 #endif | 195 #endif |
OLD | NEW |