diff --git a/src/xenia/base/memory.cc b/src/xenia/base/memory.cc index 534b63f9c..1179ecc1f 100644 --- a/src/xenia/base/memory.cc +++ b/src/xenia/base/memory.cc @@ -8,6 +8,7 @@ */ #include "xenia/base/memory.h" +#include "xenia/base/platform.h" #include @@ -22,6 +23,7 @@ void copy_128_aligned(void* dest, const void* src, size_t count) { std::memcpy(dest, src, count * 16); } +#if XE_ARCH_AMD64 void copy_and_swap_16_aligned(void* dest, const void* src, size_t count) { return copy_and_swap_16_unaligned(dest, src, count); } @@ -125,5 +127,59 @@ void copy_and_swap_16_in_32_unaligned(void* dest_ptr, const void* src_ptr, dest[i] = (src[i] >> 16) | (src[i] << 16); } } +#else +// Generic routines. +void copy_and_swap_16_aligned(void* dest, const void* src, size_t count) { + return copy_and_swap_16_unaligned(dest, src, count); +} + +void copy_and_swap_16_unaligned(void* dest_ptr, const void* src_ptr, + size_t count) { + auto dest = reinterpret_cast(dest_ptr); + auto src = reinterpret_cast(src_ptr); + for (size_t i = 0; i < count; ++i) { + dest[i] = byte_swap(src[i]); + } +} + +void copy_and_swap_32_aligned(void* dest, const void* src, size_t count) { + return copy_and_swap_32_unaligned(dest, src, count); +} + +void copy_and_swap_32_unaligned(void* dest_ptr, const void* src_ptr, + size_t count) { + auto dest = reinterpret_cast(dest_ptr); + auto src = reinterpret_cast(src_ptr); + for (size_t i = 0; i < count; ++i) { + dest[i] = byte_swap(src[i]); + } +} + +void copy_and_swap_64_aligned(void* dest, const void* src, size_t count) { + return copy_and_swap_64_unaligned(dest, src, count); +} + +void copy_and_swap_64_unaligned(void* dest_ptr, const void* src_ptr, + size_t count) { + auto dest = reinterpret_cast(dest_ptr); + auto src = reinterpret_cast(src_ptr); + for (size_t i = 0; i < count; ++i) { + dest[i] = byte_swap(src[i]); + } +} + +void copy_and_swap_16_in_32_aligned(void* dest, const void* src, size_t count) { + return copy_and_swap_16_in_32_unaligned(dest, src, count); +} + +void copy_and_swap_16_in_32_unaligned(void* dest_ptr, const void* src_ptr, + size_t count) { + auto dest = reinterpret_cast(dest_ptr); + auto src = reinterpret_cast(src_ptr); + for (size_t i = 0; i < count; ++i) { + dest[i] = (src[i] >> 16) | (src[i] << 16); + } +} +#endif } // namespace xe