summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Moore <DrChat@users.noreply.github.com>2018-04-21 08:54:56 -0500
committerGitHub <noreply@github.com>2018-04-21 08:54:56 -0500
commit6209c4a9315f38136825c5eb20b54c70891cb780 (patch)
tree92c729b9cfbc381fef8012d7d3c5ca9d73cb1509
parent86f387ed42655ca66686b4f3a48cc88b1aa262ce (diff)
parent24e7bb529389897d9da6caa77f1121ad921f3a80 (diff)
Merge pull request #1108 from bwrsandman/memory_tests
Memory tests
-rw-r--r--.travis.yml2
-rw-r--r--src/xenia/base/memory.cc37
-rw-r--r--src/xenia/base/memory_test.cc17
-rw-r--r--src/xenia/base/premake5.lua9
-rw-r--r--src/xenia/base/testing/memory_test.cc419
-rw-r--r--src/xenia/base/testing/premake5.lua11
6 files changed, 446 insertions, 49 deletions
diff --git a/.travis.yml b/.travis.yml
index 430b2f08a..87823fa70 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -59,7 +59,7 @@ script:
# Run linter.
- if [[ $LINT == true ]]; then ./xenia-build lint --all; fi
- # Build and run our simple hello world test.
+ # Build and run base tests
- if [[ $BUILD == true ]]; then ./xenia-build build --config=$CONFIG --target=xenia-base-tests; fi
- if [[ $BUILD == true ]]; then ./build/bin/Linux/$CONFIG/xenia-base-tests; fi
# Build and run ppc tests
diff --git a/src/xenia/base/memory.cc b/src/xenia/base/memory.cc
index bdc0ea7f1..1f9d654a1 100644
--- a/src/xenia/base/memory.cc
+++ b/src/xenia/base/memory.cc
@@ -26,7 +26,9 @@ void copy_128_aligned(void* dest, const void* src, size_t count) {
#if XE_ARCH_AMD64
void copy_and_swap_16_aligned(void* dest_ptr, const void* src_ptr,
size_t count) {
- assert_zero(reinterpret_cast<uintptr_t>(src_ptr) & 0x1);
+ assert_zero(reinterpret_cast<uintptr_t>(dest_ptr) & 0xF);
+ assert_zero(reinterpret_cast<uintptr_t>(src_ptr) & 0xF);
+
auto dest = reinterpret_cast<uint16_t*>(dest_ptr);
auto src = reinterpret_cast<const uint16_t*>(src_ptr);
__m128i shufmask =
@@ -34,12 +36,7 @@ void copy_and_swap_16_aligned(void* dest_ptr, const void* src_ptr,
0x04, 0x05, 0x02, 0x03, 0x00, 0x01);
size_t i = 0;
- size_t unaligned_words = (reinterpret_cast<uintptr_t>(src_ptr) & 0xF) / 2;
- for (; unaligned_words > 0 && i < count; unaligned_words--, i++) {
- // Copy up to 16 byte alignment.
- dest[i] = byte_swap(src[i]);
- }
- for (; i + 8 <= count; i += 8) {
+ for (i = 0; i + 8 <= count; i += 8) {
__m128i input = _mm_load_si128(reinterpret_cast<const __m128i*>(&src[i]));
__m128i output = _mm_shuffle_epi8(input, shufmask);
_mm_store_si128(reinterpret_cast<__m128i*>(&dest[i]), output);
@@ -70,20 +67,17 @@ void copy_and_swap_16_unaligned(void* dest_ptr, const void* src_ptr,
void copy_and_swap_32_aligned(void* dest_ptr, const void* src_ptr,
size_t count) {
- assert_zero(reinterpret_cast<uintptr_t>(src_ptr) & 0x3);
+ assert_zero(reinterpret_cast<uintptr_t>(dest_ptr) & 0xF);
+ assert_zero(reinterpret_cast<uintptr_t>(src_ptr) & 0xF);
+
auto dest = reinterpret_cast<uint32_t*>(dest_ptr);
auto src = reinterpret_cast<const uint32_t*>(src_ptr);
__m128i shufmask =
_mm_set_epi8(0x0C, 0x0D, 0x0E, 0x0F, 0x08, 0x09, 0x0A, 0x0B, 0x04, 0x05,
0x06, 0x07, 0x00, 0x01, 0x02, 0x03);
- size_t i = 0;
- size_t unaligned_dwords = (reinterpret_cast<uintptr_t>(src_ptr) & 0xF) / 4;
- for (; unaligned_dwords > 0 && i < count; unaligned_dwords--, i++) {
- // Copy up to 16 byte alignment.
- dest[i] = byte_swap(src[i]);
- }
- for (; i + 4 <= count; i += 4) {
+ size_t i;
+ for (i = 0; i + 4 <= count; i += 4) {
__m128i input = _mm_load_si128(reinterpret_cast<const __m128i*>(&src[i]));
__m128i output = _mm_shuffle_epi8(input, shufmask);
_mm_store_si128(reinterpret_cast<__m128i*>(&dest[i]), output);
@@ -114,20 +108,17 @@ void copy_and_swap_32_unaligned(void* dest_ptr, const void* src_ptr,
void copy_and_swap_64_aligned(void* dest_ptr, const void* src_ptr,
size_t count) {
- assert_zero(reinterpret_cast<uintptr_t>(src_ptr) & 0x7);
+ assert_zero(reinterpret_cast<uintptr_t>(dest_ptr) & 0xF);
+ assert_zero(reinterpret_cast<uintptr_t>(src_ptr) & 0xF);
+
auto dest = reinterpret_cast<uint64_t*>(dest_ptr);
auto src = reinterpret_cast<const uint64_t*>(src_ptr);
__m128i shufmask =
_mm_set_epi8(0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x00, 0x01,
0x02, 0x03, 0x04, 0x05, 0x06, 0x07);
- size_t i = 0;
- size_t unaligned_qwords = (reinterpret_cast<uintptr_t>(src_ptr) & 0xF) / 8;
- for (; unaligned_qwords > 0 && i < count; unaligned_qwords--, i++) {
- // Copy up to 16 byte alignment.
- dest[i] = byte_swap(src[i]);
- }
- for (; i + 2 <= count; i += 2) {
+ size_t i;
+ for (i = 0; i + 2 <= count; i += 2) {
__m128i input = _mm_load_si128(reinterpret_cast<const __m128i*>(&src[i]));
__m128i output = _mm_shuffle_epi8(input, shufmask);
_mm_store_si128(reinterpret_cast<__m128i*>(&dest[i]), output);
diff --git a/src/xenia/base/memory_test.cc b/src/xenia/base/memory_test.cc
deleted file mode 100644
index 427f132a3..000000000
--- a/src/xenia/base/memory_test.cc
+++ /dev/null
@@ -1,17 +0,0 @@
-/**
- ******************************************************************************
- * Xenia : Xbox 360 Emulator Research Project *
- ******************************************************************************
- * Copyright 2015 Ben Vanik. All rights reserved. *
- * Released under the BSD license - see LICENSE in the root for more details. *
- ******************************************************************************
- */
-
-#include "xenia/base/memory.h"
-
-#include "third_party/catch/include/catch.hpp"
-
-TEST_CASE("copy_and_swap_16_aligned", "Copy and Swap") {
- // TODO(benvanik): tests.
- REQUIRE(true == true);
-}
diff --git a/src/xenia/base/premake5.lua b/src/xenia/base/premake5.lua
index 29a0799ca..960a6500c 100644
--- a/src/xenia/base/premake5.lua
+++ b/src/xenia/base/premake5.lua
@@ -16,11 +16,4 @@ project("xenia-base")
"debug_visualizers.natvis",
})
-test_suite("xenia-base-tests", project_root, ".", {
- includedirs = {
- project_root.."/third_party/gflags/src",
- },
- links = {
- "xenia-base",
- },
-})
+include("testing")
diff --git a/src/xenia/base/testing/memory_test.cc b/src/xenia/base/testing/memory_test.cc
new file mode 100644
index 000000000..5433dc118
--- /dev/null
+++ b/src/xenia/base/testing/memory_test.cc
@@ -0,0 +1,419 @@
+/**
+ ******************************************************************************
+ * Xenia : Xbox 360 Emulator Research Project *
+ ******************************************************************************
+ * Copyright 2015 Ben Vanik. All rights reserved. *
+ * Released under the BSD license - see LICENSE in the root for more details. *
+ ******************************************************************************
+ */
+
+#include "xenia/base/memory.h"
+
+#include "third_party/catch/include/catch.hpp"
+
+namespace xe {
+namespace base {
+namespace test {
+
+TEST_CASE("copy_128_aligned", "Copy and Swap") {
+ alignas(128) uint8_t src[256], dest[256];
+ for (uint8_t i = 0; i < 255; ++i) {
+ src[i] = 255 - i;
+ }
+ std::memset(dest, 0, sizeof(dest));
+ copy_128_aligned(dest, src, 1);
+ REQUIRE(std::memcmp(dest, src, 128));
+ REQUIRE(dest[128] == 0);
+
+ std::memset(dest, 0, sizeof(dest));
+ copy_128_aligned(dest, src, 2);
+ REQUIRE(std::memcmp(dest, src, 256));
+
+ std::memset(dest, 0, sizeof(dest));
+ copy_128_aligned(dest, src + 1, 1);
+ REQUIRE(std::memcmp(dest, src + 1, 128));
+}
+
+TEST_CASE("copy_and_swap_16_aligned", "Copy and Swap") {
+ alignas(16) uint16_t a = 0x1111, b = 0xABCD;
+ copy_and_swap_16_aligned(&a, &b, 1);
+ REQUIRE(a == 0xCDAB);
+ REQUIRE(b == 0xABCD);
+
+ alignas(16) uint16_t c[] = {0x0000, 0x0000, 0x0000, 0x0000};
+ alignas(16) uint16_t d[] = {0x0123, 0x4567, 0x89AB, 0xCDEF};
+ copy_and_swap_16_aligned(c, d, 1);
+ REQUIRE(c[0] == 0x2301);
+ REQUIRE(c[1] == 0x0000);
+ REQUIRE(c[2] == 0x0000);
+ REQUIRE(c[3] == 0x0000);
+
+ copy_and_swap_16_aligned(c, d, 3);
+ REQUIRE(c[0] == 0x2301);
+ REQUIRE(c[1] == 0x6745);
+ REQUIRE(c[2] == 0xAB89);
+ REQUIRE(c[3] == 0x0000);
+
+ copy_and_swap_16_aligned(c, d, 4);
+ REQUIRE(c[0] == 0x2301);
+ REQUIRE(c[1] == 0x6745);
+ REQUIRE(c[2] == 0xAB89);
+ REQUIRE(c[3] == 0xEFCD);
+
+ alignas(16) uint64_t e;
+ copy_and_swap_16_aligned(&e, d, 4);
+ REQUIRE(e == 0xEFCDAB8967452301);
+
+ alignas(16) char f[85] = {0x00};
+ alignas(16) char g[] =
+ "This is a 85 byte long string... "
+ "It's supposed to be longer than standard alignment.";
+ copy_and_swap_16_aligned(f, g, 42);
+ REQUIRE(std::strcmp(f,
+ "hTsii s a58b ty eolgns rtni.g..I 't susppsodet oebl "
+ "noeg rhtnas atdnra dlagimnne.t") == 0);
+
+ std::memset(f, 0, sizeof(f));
+ copy_and_swap_16_aligned(f, g + 16, 34);
+ REQUIRE(std::strcmp(f,
+ " eolgns rtni.g..I 't susppsodet oebl "
+ "noeg rhtnas atdnra dlagimnne.t") == 0);
+
+ std::memset(f, 0, sizeof(f));
+ copy_and_swap_16_aligned(f, g + 32, 26);
+ REQUIRE(std::strcmp(f,
+ "I 't susppsodet oebl "
+ "noeg rhtnas atdnra dlagimnne.t") == 0);
+
+ std::memset(f, 0, sizeof(f));
+ copy_and_swap_16_aligned(f, g + 64, 10);
+ REQUIRE(std::strcmp(f, "s atdnra dlagimnne.t") == 0);
+}
+
+TEST_CASE("copy_and_swap_16_unaligned", "Copy and Swap") {
+ uint16_t a = 0x1111, b = 0xABCD;
+ copy_and_swap_16_unaligned(&a, &b, 1);
+ REQUIRE(a == 0xCDAB);
+ REQUIRE(b == 0xABCD);
+
+ uint16_t c[] = {0x0000, 0x0000, 0x0000, 0x0000};
+ uint16_t d[] = {0x0123, 0x4567, 0x89AB, 0xCDEF};
+ copy_and_swap_16_unaligned(c, d, 1);
+ REQUIRE(c[0] == 0x2301);
+ REQUIRE(c[1] == 0x0000);
+ REQUIRE(c[2] == 0x0000);
+ REQUIRE(c[3] == 0x0000);
+
+ copy_and_swap_16_unaligned(c, d, 4);
+ REQUIRE(c[0] == 0x2301);
+ REQUIRE(c[1] == 0x6745);
+ REQUIRE(c[2] == 0xAB89);
+ REQUIRE(c[3] == 0xEFCD);
+
+ uint64_t e;
+ copy_and_swap_16_unaligned(&e, d, 4);
+ REQUIRE(e == 0xEFCDAB8967452301);
+
+ char f[85] = {0x00};
+ char g[] =
+ "This is a 85 byte long string... "
+ "It's supposed to be longer than standard alignment.";
+ copy_and_swap_16_unaligned(f, g, 42);
+ REQUIRE(std::strcmp(f,
+ "hTsii s a58b ty eolgns rtni.g..I 't susppsodet oebl "
+ "noeg rhtnas atdnra dlagimnne.t") == 0);
+
+ std::memset(f, 0, sizeof(f));
+ copy_and_swap_16_unaligned(f, g + 1, 41);
+ REQUIRE(std::strcmp(f,
+ "ih ssia 8 5ybetl no gtsirgn.. .tIs's puopes dotb "
+ "eolgnret ah ntsnaaddra ilngemtn") == 0);
+
+ std::memset(f, 0, sizeof(f));
+ copy_and_swap_16_unaligned(f, g + 2, 41);
+ REQUIRE(std::strcmp(f,
+ "sii s a58b ty eolgns rtni.g..I 't susppsodet oebl "
+ "noeg rhtnas atdnra dlagimnne.t") == 0);
+}
+
+TEST_CASE("copy_and_swap_32_aligned", "Copy and Swap") {
+ alignas(32) uint32_t a = 0x11111111, b = 0x89ABCDEF;
+ copy_and_swap_32_aligned(&a, &b, 1);
+ REQUIRE(a == 0xEFCDAB89);
+ REQUIRE(b == 0x89ABCDEF);
+
+ alignas(32) uint32_t c[] = {0x00000000, 0x00000000, 0x00000000, 0x00000000};
+ alignas(32) uint32_t d[] = {0x01234567, 0x89ABCDEF, 0xE887EEED, 0xD8514199};
+ copy_and_swap_32_aligned(c, d, 1);
+ REQUIRE(c[0] == 0x67452301);
+ REQUIRE(c[1] == 0x00000000);
+ REQUIRE(c[2] == 0x00000000);
+ REQUIRE(c[3] == 0x00000000);
+
+ copy_and_swap_32_aligned(c, d, 3);
+ REQUIRE(c[0] == 0x67452301);
+ REQUIRE(c[1] == 0xEFCDAB89);
+ REQUIRE(c[2] == 0xEDEE87E8);
+ REQUIRE(c[3] == 0x00000000);
+
+ copy_and_swap_32_aligned(c, d, 4);
+ REQUIRE(c[0] == 0x67452301);
+ REQUIRE(c[1] == 0xEFCDAB89);
+ REQUIRE(c[2] == 0xEDEE87E8);
+ REQUIRE(c[3] == 0x994151D8);
+
+ alignas(32) uint64_t e;
+ copy_and_swap_32_aligned(&e, d, 2);
+ REQUIRE(e == 0xEFCDAB8967452301);
+
+ alignas(32) char f[85] = {0x00};
+ alignas(32) char g[] =
+ "This is a 85 byte long string... "
+ "It's supposed to be longer than standard alignment.";
+ copy_and_swap_32_aligned(f, g, 21);
+ REQUIRE(std::strcmp(f,
+ "sihT si 58 atyb ol es gnnirt...g'tI us ssoppt deeb "
+ "onol regnahtats radnla dmngi.tne") == 0);
+
+ std::memset(f, 0, sizeof(f));
+ copy_and_swap_32_aligned(f, g + 16, 17);
+ REQUIRE(std::strcmp(f,
+ "ol es gnnirt...g'tI us ssoppt deeb "
+ "onol regnahtats radnla dmngi.tne") == 0);
+
+ std::memset(f, 0, sizeof(f));
+ copy_and_swap_32_aligned(f, g + 32, 13);
+ REQUIRE(std::strcmp(f,
+ "'tI us ssoppt deeb "
+ "onol regnahtats radnla dmngi.tne") == 0);
+
+ std::memset(f, 0, sizeof(f));
+ copy_and_swap_32_aligned(f, g + 64, 5);
+ REQUIRE(std::strcmp(f, "ats radnla dmngi.tne") == 0);
+}
+
+TEST_CASE("copy_and_swap_32_unaligned", "Copy and Swap") {
+ uint32_t a = 0x11111111, b = 0x89ABCDEF;
+ copy_and_swap_32_unaligned(&a, &b, 1);
+ REQUIRE(a == 0xEFCDAB89);
+ REQUIRE(b == 0x89ABCDEF);
+
+ uint32_t c[] = {0x00000000, 0x00000000, 0x00000000, 0x00000000};
+ uint32_t d[] = {0x01234567, 0x89ABCDEF, 0xE887EEED, 0xD8514199};
+ copy_and_swap_32_unaligned(c, d, 1);
+ REQUIRE(c[0] == 0x67452301);
+ REQUIRE(c[1] == 0x00000000);
+ REQUIRE(c[2] == 0x00000000);
+ REQUIRE(c[3] == 0x00000000);
+
+ copy_and_swap_32_unaligned(c, d, 3);
+ REQUIRE(c[0] == 0x67452301);
+ REQUIRE(c[1] == 0xEFCDAB89);
+ REQUIRE(c[2] == 0xEDEE87E8);
+ REQUIRE(c[3] == 0x00000000);
+
+ copy_and_swap_32_unaligned(c, d, 4);
+ REQUIRE(c[0] == 0x67452301);
+ REQUIRE(c[1] == 0xEFCDAB89);
+ REQUIRE(c[2] == 0xEDEE87E8);
+ REQUIRE(c[3] == 0x994151D8);
+
+ uint64_t e;
+ copy_and_swap_32_unaligned(&e, d, 2);
+ REQUIRE(e == 0xEFCDAB8967452301);
+
+ char f[85] = {0x00};
+ char g[] =
+ "This is a 85 byte long string... "
+ "It's supposed to be longer than standard alignment.";
+ copy_and_swap_32_unaligned(f, g, 21);
+ REQUIRE(std::strcmp(f,
+ "sihT si 58 atyb ol es gnnirt...g'tI us ssoppt deeb "
+ "onol regnahtats radnla dmngi.tne") == 0);
+
+ std::memset(f, 0, sizeof(f));
+ copy_and_swap_32_unaligned(f, g + 1, 20);
+ REQUIRE(std::strcmp(f,
+ " siha si 58 etybnol ts ggnir ...s'tIpus esopot d eb "
+ "gnolt re nahnatsdradila emng") == 0);
+
+ std::memset(f, 0, sizeof(f));
+ copy_and_swap_32_unaligned(f, g + 2, 20);
+ REQUIRE(std::strcmp(f,
+ "i si a sb 58 etygnolrts .gniI .. s'tppusdeso ot l "
+ "ebegnoht rs nadnat dragilanemn") == 0);
+
+ std::memset(f, 0, sizeof(f));
+ copy_and_swap_32_unaligned(f, g + 3, 20);
+ REQUIRE(std::strcmp(f,
+ "si s8 a yb 5l et gnoirts..gntI .s s'oppu desb otol "
+ "eregnaht ts nadnaa drngiltnem") == 0);
+
+ std::memset(f, 0, sizeof(f));
+ copy_and_swap_32_unaligned(f, g + 4, 20);
+ REQUIRE(std::strcmp(f,
+ " si 58 atyb ol es gnnirt...g'tI us ssoppt deeb onol "
+ "regnahtats radnla dmngi.tne") == 0);
+}
+
+TEST_CASE("copy_and_swap_64_aligned", "Copy and Swap") {
+ alignas(64) uint64_t a = 0x1111111111111111, b = 0x0123456789ABCDEF;
+ copy_and_swap_64_aligned(&a, &b, 1);
+ REQUIRE(a == 0xEFCDAB8967452301);
+ REQUIRE(b == 0x0123456789ABCDEF);
+
+ alignas(64) uint64_t c[] = {0x0000000000000000, 0x0000000000000000,
+ 0x0000000000000000, 0x0000000000000000};
+ alignas(64) uint64_t d[] = {0x0123456789ABCDEF, 0xE887EEEDD8514199,
+ 0x21D4745A1D4A7706, 0xA4174FED675766E3};
+ copy_and_swap_64_aligned(c, d, 1);
+ REQUIRE(c[0] == 0xEFCDAB8967452301);
+ REQUIRE(c[1] == 0x0000000000000000);
+ REQUIRE(c[2] == 0x0000000000000000);
+ REQUIRE(c[3] == 0x0000000000000000);
+
+ copy_and_swap_64_aligned(c, d, 3);
+ REQUIRE(c[0] == 0xEFCDAB8967452301);
+ REQUIRE(c[1] == 0x994151D8EDEE87E8);
+ REQUIRE(c[2] == 0x06774A1D5A74D421);
+ REQUIRE(c[3] == 0x0000000000000000);
+
+ copy_and_swap_64_aligned(c, d, 4);
+ REQUIRE(c[0] == 0xEFCDAB8967452301);
+ REQUIRE(c[1] == 0x994151D8EDEE87E8);
+ REQUIRE(c[2] == 0x06774A1D5A74D421);
+ REQUIRE(c[3] == 0xE3665767ED4F17A4);
+
+ alignas(64) uint64_t e;
+ copy_and_swap_64_aligned(&e, d, 1);
+ REQUIRE(e == 0xEFCDAB8967452301);
+
+ alignas(64) char f[85] = {0x00};
+ alignas(64) char g[] =
+ "This is a 85 byte long string... "
+ "It's supposed to be longer than standard alignment.";
+ copy_and_swap_64_aligned(f, g, 10);
+ REQUIRE(std::strcmp(f,
+ " si sihTtyb 58 as gnol e...gnirtus s'tI t desoppnol eb "
+ "onaht regradnats mngila d") == 0);
+
+ std::memset(f, 0, sizeof(f));
+ copy_and_swap_64_aligned(f, g + 16, 8);
+ REQUIRE(std::strcmp(f,
+ "s gnol e...gnirtus s'tI t desoppnol eb "
+ "onaht regradnats mngila d") == 0);
+
+ std::memset(f, 0, sizeof(f));
+ copy_and_swap_64_aligned(f, g + 32, 6);
+ REQUIRE(std::strcmp(f,
+ "us s'tI t desoppnol eb "
+ "onaht regradnats mngila d") == 0);
+
+ std::memset(f, 0, sizeof(f));
+ copy_and_swap_64_aligned(f, g + 64, 2);
+ REQUIRE(std::strcmp(f, "radnats mngila d") == 0);
+}
+
+TEST_CASE("copy_and_swap_64_unaligned", "Copy and Swap") {
+ uint64_t a = 0x1111111111111111, b = 0x0123456789ABCDEF;
+ copy_and_swap_64_unaligned(&a, &b, 1);
+ REQUIRE(a == 0xEFCDAB8967452301);
+ REQUIRE(b == 0x0123456789ABCDEF);
+
+ uint64_t c[] = {0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
+ 0x0000000000000000};
+ uint64_t d[] = {0x0123456789ABCDEF, 0xE887EEEDD8514199, 0x21D4745A1D4A7706,
+ 0xA4174FED675766E3};
+ copy_and_swap_64_unaligned(c, d, 1);
+ REQUIRE(c[0] == 0xEFCDAB8967452301);
+ REQUIRE(c[1] == 0x0000000000000000);
+ REQUIRE(c[2] == 0x0000000000000000);
+ REQUIRE(c[3] == 0x0000000000000000);
+
+ copy_and_swap_64_unaligned(c, d, 3);
+ REQUIRE(c[0] == 0xEFCDAB8967452301);
+ REQUIRE(c[1] == 0x994151D8EDEE87E8);
+ REQUIRE(c[2] == 0x06774A1D5A74D421);
+ REQUIRE(c[3] == 0x0000000000000000);
+
+ copy_and_swap_64_unaligned(c, d, 4);
+ REQUIRE(c[0] == 0xEFCDAB8967452301);
+ REQUIRE(c[1] == 0x994151D8EDEE87E8);
+ REQUIRE(c[2] == 0x06774A1D5A74D421);
+ REQUIRE(c[3] == 0xE3665767ED4F17A4);
+
+ uint64_t e;
+ copy_and_swap_64_unaligned(&e, d, 1);
+ REQUIRE(e == 0xEFCDAB8967452301);
+
+ char f[85] = {0x00};
+ char g[] =
+ "This is a 85 byte long string... "
+ "It's supposed to be longer than standard alignment.";
+ copy_and_swap_64_unaligned(f, g, 10);
+ REQUIRE(std::strcmp(f,
+ " si sihTtyb 58 as gnol e...gnirtus s'tI t desoppnol eb "
+ "onaht regradnats mngila d") == 0);
+
+ std::memset(f, 0, sizeof(f));
+ copy_and_swap_64_unaligned(f, g + 1, 10);
+ REQUIRE(std::strcmp(f,
+ "a si sihetyb 58 ts gnol ...gnirpus s'tIot desopgnol "
+ "eb naht redradnatsemngila ") == 0);
+
+ std::memset(f, 0, sizeof(f));
+ copy_and_swap_64_unaligned(f, g + 2, 10);
+ REQUIRE(std::strcmp(f,
+ " a si si etyb 58rts gnolI ...gnippus s't ot desoegnol "
+ "ebs naht r dradnatnemngila") == 0);
+
+ std::memset(f, 0, sizeof(f));
+ copy_and_swap_64_unaligned(f, g + 3, 10);
+ REQUIRE(std::strcmp(f,
+ "8 a si sl etyb 5irts gnotI ...gnoppus s'b ot desregnol "
+ "ets naht a dradnatnemngil") == 0);
+
+ std::memset(f, 0, sizeof(f));
+ copy_and_swap_64_unaligned(f, g + 4, 10);
+ REQUIRE(std::strcmp(f,
+ "58 a si ol etyb nirts gn'tI ...gsoppus seb ot de "
+ "regnol ats nahtla dradn.tnemngi") == 0);
+
+ std::memset(f, 0, sizeof(f));
+ copy_and_swap_64_unaligned(f, g + 5, 9);
+ REQUIRE(std::strcmp(f,
+ " 58 a sinol etybgnirts gs'tI ...esoppus eb ot dt "
+ "regnolnats nahila drad") == 0);
+
+ std::memset(f, 0, sizeof(f));
+ copy_and_swap_64_unaligned(f, g + 6, 9);
+ REQUIRE(std::strcmp(f,
+ "b 58 a sgnol ety.gnirts s'tI ..desoppusl eb ot ht "
+ "regnodnats nagila dra") == 0);
+
+ std::memset(f, 0, sizeof(f));
+ copy_and_swap_64_unaligned(f, g + 7, 9);
+ REQUIRE(std::strcmp(f,
+ "yb 58 a gnol et..gnirtss s'tI . desoppuol eb otaht "
+ "regnadnats nngila dr") == 0);
+
+ std::memset(f, 0, sizeof(f));
+ copy_and_swap_64_unaligned(f, g + 8, 9);
+ REQUIRE(std::strcmp(f,
+ "tyb 58 as gnol e...gnirtus s'tI t desoppnol eb onaht "
+ "regradnats mngila d") == 0);
+}
+
+TEST_CASE("copy_and_swap_16_in_32_aligned", "Copy and Swap") {
+ // TODO(bwrsandman): test once properly understood.
+ REQUIRE(true == true);
+}
+
+TEST_CASE("copy_and_swap_16_in_32_unaligned", "Copy and Swap") {
+ // TODO(bwrsandman): test once properly understood.
+ REQUIRE(true == true);
+}
+
+} // namespace test
+} // namespace base
+} // namespace xe
diff --git a/src/xenia/base/testing/premake5.lua b/src/xenia/base/testing/premake5.lua
new file mode 100644
index 000000000..e432d7ec4
--- /dev/null
+++ b/src/xenia/base/testing/premake5.lua
@@ -0,0 +1,11 @@
+project_root = "../../../.."
+include(project_root.."/tools/build")
+
+test_suite("xenia-base-tests", project_root, ".", {
+ includedirs = {
+ project_root.."/third_party/gflags/src",
+ },
+ links = {
+ "xenia-base",
+ },
+})