diff options
author | Alexander Ivchenko <alexander.ivchenko@intel.com> | 2013-06-27 12:55:46 +0400 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2013-08-02 17:57:23 -0700 |
commit | baa91f4f8974b6e9a81fa3aa49f051b3bf823653 (patch) | |
tree | 5107a2ba56f4f360dd171abaa3f84e360ab0ab5b /tests/string_test.cpp | |
parent | aa2733d17b87c607fccbd6e6a0f44d2d411ffd77 (diff) | |
download | android_bionic-baa91f4f8974b6e9a81fa3aa49f051b3bf823653.tar.gz android_bionic-baa91f4f8974b6e9a81fa3aa49f051b3bf823653.tar.bz2 android_bionic-baa91f4f8974b6e9a81fa3aa49f051b3bf823653.zip |
Add ssse3 implementation of __memcmp16.
__memcmp16 was missing in x86. Also added C-version for backward
compatibility. Added bionic test for __memcmp16 and for wmemcmp.
Change-Id: I33718441e7ee343cdb021d91dbeaf9ce2d4d7eb4
Signed-off-by: Alexander Ivchenko <alexander.ivchenko@intel.com>
Diffstat (limited to 'tests/string_test.cpp')
-rw-r--r-- | tests/string_test.cpp | 100 |
1 files changed, 77 insertions, 23 deletions
diff --git a/tests/string_test.cpp b/tests/string_test.cpp index 91d1904e8..ef43f5d3c 100644 --- a/tests/string_test.cpp +++ b/tests/string_test.cpp @@ -131,14 +131,15 @@ TEST(string, strsignal_concurrent) { // expected result and then run function and compare what we got. // These tests contributed by Intel Corporation. // TODO: make these tests more intention-revealing and less random. +template<class Character> struct StringTestState { StringTestState(size_t MAX_LEN) : MAX_LEN(MAX_LEN) { int max_alignment = 64; // TODO: fix the tests to not sometimes use twice their specified "MAX_LEN". - glob_ptr = reinterpret_cast<char*>(valloc(2 * MAX_LEN + max_alignment)); - glob_ptr1 = reinterpret_cast<char*>(valloc(2 * MAX_LEN + max_alignment)); - glob_ptr2 = reinterpret_cast<char*>(valloc(2 * MAX_LEN + max_alignment)); + glob_ptr = reinterpret_cast<Character*>(valloc(2 * sizeof(Character) * MAX_LEN + max_alignment)); + glob_ptr1 = reinterpret_cast<Character*>(valloc(2 * sizeof(Character) * MAX_LEN + max_alignment)); + glob_ptr2 = reinterpret_cast<Character*>(valloc(2 * sizeof(Character) * MAX_LEN + max_alignment)); InitLenArray(); @@ -163,12 +164,12 @@ struct StringTestState { } const size_t MAX_LEN; - char *ptr, *ptr1, *ptr2; + Character *ptr, *ptr1, *ptr2; size_t n; int len[ITER + 1]; private: - char *glob_ptr, *glob_ptr1, *glob_ptr2; + Character *glob_ptr, *glob_ptr1, *glob_ptr2; // Calculate input lengths and fill state.len with them. // Test small lengths with more density than big ones. Manually push @@ -188,7 +189,7 @@ struct StringTestState { }; TEST(string, strcat) { - StringTestState state(SMALL); + StringTestState<char> state(SMALL); for (size_t i = 1; i < state.n; i++) { for (size_t j = 0; j < POS_ITER; j++) { state.NewIteration(); @@ -380,7 +381,7 @@ TEST(string, strchr_with_0) { TEST(string, strchr) { int seek_char = random() & 255; - StringTestState state(SMALL); + StringTestState<char> state(SMALL); for (size_t i = 1; i < state.n; i++) { for (size_t j = 0; j < POS_ITER; j++) { state.NewIteration(); @@ -411,7 +412,7 @@ TEST(string, strchr) { } TEST(string, strcmp) { - StringTestState state(SMALL); + StringTestState<char> state(SMALL); for (size_t i = 1; i < state.n; i++) { for (size_t j = 0; j < POS_ITER; j++) { state.NewIteration(); @@ -448,7 +449,7 @@ TEST(string, strcmp) { } TEST(string, strcpy) { - StringTestState state(SMALL); + StringTestState<char> state(SMALL); for (size_t j = 0; j < POS_ITER; j++) { state.NewIteration(); @@ -476,7 +477,7 @@ TEST(string, strcpy) { #if __BIONIC__ TEST(string, strlcat) { - StringTestState state(SMALL); + StringTestState<char> state(SMALL); for (size_t i = 0; i < state.n; i++) { for (size_t j = 0; j < POS_ITER; j++) { state.NewIteration(); @@ -505,7 +506,7 @@ TEST(string, strlcat) { #if __BIONIC__ TEST(string, strlcpy) { - StringTestState state(SMALL); + StringTestState<char> state(SMALL); for (size_t j = 0; j < POS_ITER; j++) { state.NewIteration(); @@ -539,7 +540,7 @@ TEST(string, strlcpy) { #endif TEST(string, strncat) { - StringTestState state(SMALL); + StringTestState<char> state(SMALL); for (size_t i = 1; i < state.n; i++) { for (size_t j = 0; j < POS_ITER; j++) { state.NewIteration(); @@ -565,7 +566,7 @@ TEST(string, strncat) { } TEST(string, strncmp) { - StringTestState state(SMALL); + StringTestState<char> state(SMALL); for (size_t i = 1; i < state.n; i++) { for (size_t j = 0; j < POS_ITER; j++) { state.NewIteration(); @@ -602,7 +603,7 @@ TEST(string, strncmp) { } TEST(string, strncpy) { - StringTestState state(SMALL); + StringTestState<char> state(SMALL); for (size_t j = 0; j < ITER; j++) { state.NewIteration(); @@ -630,7 +631,7 @@ TEST(string, strncpy) { TEST(string, strrchr) { int seek_char = random() & 255; - StringTestState state(SMALL); + StringTestState<char> state(SMALL); for (size_t i = 1; i < state.n; i++) { for (size_t j = 0; j < POS_ITER; j++) { state.NewIteration(); @@ -662,7 +663,7 @@ TEST(string, strrchr) { TEST(string, memchr) { int seek_char = random() & 255; - StringTestState state(SMALL); + StringTestState<char> state(SMALL); for (size_t i = 0; i < state.n; i++) { for (size_t j = 0; j < POS_ITER; j++) { state.NewIteration(); @@ -685,7 +686,7 @@ TEST(string, memchr) { TEST(string, memrchr) { int seek_char = random() & 255; - StringTestState state(SMALL); + StringTestState<char> state(SMALL); for (size_t i = 0; i < state.n; i++) { for (size_t j = 0; j < POS_ITER; j++) { state.NewIteration(); @@ -707,7 +708,7 @@ TEST(string, memrchr) { } TEST(string, memcmp) { - StringTestState state(SMALL); + StringTestState<char> state(SMALL); for (size_t i = 0; i < state.n; i++) { for (size_t j = 0; j < POS_ITER; j++) { state.NewIteration(); @@ -728,8 +729,61 @@ TEST(string, memcmp) { } } +#if defined(__BIONIC__) +extern "C" int __memcmp16(const unsigned short *ptr1, const unsigned short *ptr2, size_t n); + +TEST(string, __memcmp16) { + StringTestState<unsigned short> state(SMALL); + + for (size_t i = 0; i < state.n; i++) { + for (size_t j = 0; j < POS_ITER; j++) { + state.NewIteration(); + + unsigned short mask = 0xffff; + unsigned short c1 = rand() & mask; + unsigned short c2 = rand() & mask; + + std::fill(state.ptr1, state.ptr1 + state.MAX_LEN, c1); + std::fill(state.ptr2, state.ptr2 + state.MAX_LEN, c1); + + int pos = (state.len[i] == 0) ? 0 : (random() % state.len[i]); + state.ptr2[pos] = c2; + + int expected = (static_cast<unsigned short>(c1) - static_cast<unsigned short>(c2)); + int actual = __memcmp16(state.ptr1, state.ptr2, (size_t) state.MAX_LEN); + + ASSERT_EQ(expected, actual); + } + } +} +#endif + +TEST(string, wmemcmp) { + StringTestState<wchar_t> state(SMALL); + + for (size_t i = 0; i < state.n; i++) { + for (size_t j = 0; j < POS_ITER; j++) { + state.NewIteration(); + + long long mask = ((long long) 1 << 8 * sizeof(wchar_t)) - 1; + int c1 = rand() & mask; + int c2 = rand() & mask; + wmemset(state.ptr1, c1, state.MAX_LEN); + wmemset(state.ptr2, c1, state.MAX_LEN); + + int pos = (state.len[i] == 0) ? 0 : (random() % state.len[i]); + state.ptr2[pos] = c2; + + int expected = (static_cast<int>(c1) - static_cast<int>(c2)); + int actual = wmemcmp(state.ptr1, state.ptr2, (size_t) state.MAX_LEN); + + ASSERT_EQ(signum(expected), signum(actual)); + } + } +} + TEST(string, memcpy) { - StringTestState state(LARGE); + StringTestState<char> state(LARGE); int rand = random() & 255; for (size_t i = 0; i < state.n - 1; i++) { for (size_t j = 0; j < POS_ITER; j++) { @@ -751,7 +805,7 @@ TEST(string, memcpy) { } TEST(string, memset) { - StringTestState state(LARGE); + StringTestState<char> state(LARGE); char ch = random () & 255; for (size_t i = 0; i < state.n - 1; i++) { for (size_t j = 0; j < POS_ITER; j++) { @@ -773,7 +827,7 @@ TEST(string, memset) { } TEST(string, memmove) { - StringTestState state(LARGE); + StringTestState<char> state(LARGE); for (size_t i = 0; i < state.n - 1; i++) { for (size_t j = 0; j < POS_ITER; j++) { state.NewIteration(); @@ -794,7 +848,7 @@ TEST(string, memmove) { } TEST(string, bcopy) { - StringTestState state(LARGE); + StringTestState<char> state(LARGE); for (size_t i = 0; i < state.n; i++) { for (size_t j = 0; j < POS_ITER; j++) { state.NewIteration(); @@ -813,7 +867,7 @@ TEST(string, bcopy) { } TEST(string, bzero) { - StringTestState state(LARGE); + StringTestState<char> state(LARGE); for (size_t j = 0; j < ITER; j++) { state.NewIteration(); |