Add generic memory swap routines.

This commit is contained in:
Dr. Chat 2017-05-09 20:52:09 -05:00
parent 6dcbee18da
commit bb3291e331
1 changed files with 56 additions and 0 deletions

View File

@ -8,6 +8,7 @@
*/
#include "xenia/base/memory.h"
#include "xenia/base/platform.h"
#include <algorithm>
@ -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<uint16_t*>(dest_ptr);
auto src = reinterpret_cast<const uint16_t*>(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<uint32_t*>(dest_ptr);
auto src = reinterpret_cast<const uint32_t*>(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<uint64_t*>(dest_ptr);
auto src = reinterpret_cast<const uint64_t*>(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<uint64_t*>(dest_ptr);
auto src = reinterpret_cast<const uint64_t*>(src_ptr);
for (size_t i = 0; i < count; ++i) {
dest[i] = (src[i] >> 16) | (src[i] << 16);
}
}
#endif
} // namespace xe