Add generic memory swap routines.
This commit is contained in:
parent
6dcbee18da
commit
bb3291e331
|
@ -8,6 +8,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "xenia/base/memory.h"
|
#include "xenia/base/memory.h"
|
||||||
|
#include "xenia/base/platform.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
@ -22,6 +23,7 @@ void copy_128_aligned(void* dest, const void* src, size_t count) {
|
||||||
std::memcpy(dest, src, count * 16);
|
std::memcpy(dest, src, count * 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if XE_ARCH_AMD64
|
||||||
void copy_and_swap_16_aligned(void* dest, const void* src, size_t count) {
|
void copy_and_swap_16_aligned(void* dest, const void* src, size_t count) {
|
||||||
return copy_and_swap_16_unaligned(dest, src, 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);
|
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
|
} // namespace xe
|
||||||
|
|
Loading…
Reference in New Issue