Skip to content

Commit 9c3ece1

Browse files
committed
byteswap: add MSVC handling
Turns out that even though MSVC is supposed to support std::byteswap, I can't seem to get it to compile with Godbolt. Whats more, the fallback path MSVC cannot optimize. Signed-off-by: Rosen Penev <[email protected]>
1 parent 494ca1d commit 9c3ece1

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/image.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ bool Image::isLittleEndianPlatform() {
184184
uint64_t Image::byteSwap(uint64_t value, bool bSwap) {
185185
#ifdef __cpp_lib_byteswap
186186
return bSwap ? std::byteswap(value) : value;
187+
#elif defined(_MSC_VER)
188+
return bSwap ? _byteswap_uint64(value) : value;
187189
#else
188190
uint64_t result = 0;
189191
auto source_value = reinterpret_cast<const byte*>(&value);
@@ -199,6 +201,8 @@ uint64_t Image::byteSwap(uint64_t value, bool bSwap) {
199201
uint32_t Image::byteSwap(uint32_t value, bool bSwap) {
200202
#ifdef __cpp_lib_byteswap
201203
return bSwap ? std::byteswap(value) : value;
204+
#elif defined(_MSC_VER)
205+
return bSwap ? _byteswap_ulong(value) : value;
202206
#else
203207
uint32_t result = 0;
204208
result |= (value & 0x000000FFU) << 24;
@@ -212,6 +216,8 @@ uint32_t Image::byteSwap(uint32_t value, bool bSwap) {
212216
uint16_t Image::byteSwap(uint16_t value, bool bSwap) {
213217
#ifdef __cpp_lib_byteswap
214218
return bSwap ? std::byteswap(value) : value;
219+
#elif defined(_MSC_VER)
220+
return bSwap ? _byteswap_ushort(value) : value;
215221
#else
216222
uint16_t result = 0;
217223
result |= (value & 0x00FFU) << 8;

src/pgfimage.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ namespace Exiv2 {
3535
static uint32_t byteSwap_(uint32_t value, bool bSwap) {
3636
#ifdef __cpp_lib_byteswap
3737
return bSwap ? std::byteswap(value) : value;
38+
#elif defined(_MSC_VER)
39+
return bSwap ? _byteswap_ulong(value) : value;
3840
#else
3941
uint32_t result = 0;
4042
result |= (value & 0x000000FF) << 24;

0 commit comments

Comments
 (0)