aboutsummaryrefslogtreecommitdiffstats
path: root/util/system/unaligned_mem_ut.cpp
diff options
context:
space:
mode:
authorAlexey Salmin <alexey.salmin@gmail.com>2022-02-10 16:49:37 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:37 +0300
commit3c5b1607b38f637d2f3313791ed25c2e080d2647 (patch)
tree99be7b96e7c66612fbca94331100ef3b5fedcb88 /util/system/unaligned_mem_ut.cpp
parentde89752358147d7b25ef59a85b431bb564068a49 (diff)
downloadydb-3c5b1607b38f637d2f3313791ed25c2e080d2647.tar.gz
Restoring authorship annotation for Alexey Salmin <alexey.salmin@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'util/system/unaligned_mem_ut.cpp')
-rw-r--r--util/system/unaligned_mem_ut.cpp146
1 files changed, 73 insertions, 73 deletions
diff --git a/util/system/unaligned_mem_ut.cpp b/util/system/unaligned_mem_ut.cpp
index 9de3f3e931..3c575d4f69 100644
--- a/util/system/unaligned_mem_ut.cpp
+++ b/util/system/unaligned_mem_ut.cpp
@@ -3,94 +3,94 @@
#include <library/cpp/testing/benchmark/bench.h>
#include <library/cpp/testing/unittest/registar.h>
-#include <util/system/compiler.h>
-
-#ifdef Y_HAVE_INT128
-namespace {
- struct TUInt128 {
- bool operator==(const TUInt128& other) const {
- return x == other.x;
- }
-
- ui64 Low() const {
- return (ui64)x;
- }
-
- ui64 High() const {
- return (ui64)(x >> 64);
- }
-
- static TUInt128 Max() {
+#include <util/system/compiler.h>
+
+#ifdef Y_HAVE_INT128
+namespace {
+ struct TUInt128 {
+ bool operator==(const TUInt128& other) const {
+ return x == other.x;
+ }
+
+ ui64 Low() const {
+ return (ui64)x;
+ }
+
+ ui64 High() const {
+ return (ui64)(x >> 64);
+ }
+
+ static TUInt128 Max() {
return {~(__uint128_t)0};
- }
-
- __uint128_t x;
- };
-}
-#endif
-
+ }
+
+ __uint128_t x;
+ };
+}
+#endif
+
Y_UNIT_TEST_SUITE(UnalignedMem) {
Y_UNIT_TEST(TestReadWrite) {
- alignas(ui64) char buf[100];
+ alignas(ui64) char buf[100];
WriteUnaligned<ui16>(buf + 1, (ui16)1);
WriteUnaligned<ui32>(buf + 1 + 2, (ui32)2);
WriteUnaligned<ui64>(buf + 1 + 2 + 4, (ui64)3);
- UNIT_ASSERT_VALUES_EQUAL(ReadUnaligned<ui16>(buf + 1), 1);
- UNIT_ASSERT_VALUES_EQUAL(ReadUnaligned<ui32>(buf + 1 + 2), 2);
- UNIT_ASSERT_VALUES_EQUAL(ReadUnaligned<ui64>(buf + 1 + 2 + 4), 3);
+ UNIT_ASSERT_VALUES_EQUAL(ReadUnaligned<ui16>(buf + 1), 1);
+ UNIT_ASSERT_VALUES_EQUAL(ReadUnaligned<ui32>(buf + 1 + 2), 2);
+ UNIT_ASSERT_VALUES_EQUAL(ReadUnaligned<ui64>(buf + 1 + 2 + 4), 3);
}
-
+
Y_UNIT_TEST(TestReadWriteRuntime) {
- // Unlike the test above, this test avoids compile-time execution by a smart compiler.
- // It is required to catch the SIGSEGV in case compiler emits an alignment-sensitive instruction.
-
- alignas(ui64) static char buf[100] = {0}; // static is required for Clobber to work
-
+ // Unlike the test above, this test avoids compile-time execution by a smart compiler.
+ // It is required to catch the SIGSEGV in case compiler emits an alignment-sensitive instruction.
+
+ alignas(ui64) static char buf[100] = {0}; // static is required for Clobber to work
+
WriteUnaligned<ui16>(buf + 1, (ui16)1);
WriteUnaligned<ui32>(buf + 1 + 2, (ui32)2);
WriteUnaligned<ui64>(buf + 1 + 2 + 4, (ui64)3);
- NBench::Clobber();
-
- auto val1 = ReadUnaligned<ui16>(buf + 1);
- auto val2 = ReadUnaligned<ui32>(buf + 1 + 2);
- auto val3 = ReadUnaligned<ui64>(buf + 1 + 2 + 4);
-
- Y_DO_NOT_OPTIMIZE_AWAY(&val1);
- Y_DO_NOT_OPTIMIZE_AWAY(&val2);
- Y_DO_NOT_OPTIMIZE_AWAY(&val3);
- Y_DO_NOT_OPTIMIZE_AWAY(val1);
- Y_DO_NOT_OPTIMIZE_AWAY(val2);
- Y_DO_NOT_OPTIMIZE_AWAY(val3);
-
- UNIT_ASSERT_VALUES_EQUAL(val1, 1);
- UNIT_ASSERT_VALUES_EQUAL(val2, 2);
- UNIT_ASSERT_VALUES_EQUAL(val3, 3);
- }
-#ifdef Y_HAVE_INT128
+ NBench::Clobber();
+
+ auto val1 = ReadUnaligned<ui16>(buf + 1);
+ auto val2 = ReadUnaligned<ui32>(buf + 1 + 2);
+ auto val3 = ReadUnaligned<ui64>(buf + 1 + 2 + 4);
+
+ Y_DO_NOT_OPTIMIZE_AWAY(&val1);
+ Y_DO_NOT_OPTIMIZE_AWAY(&val2);
+ Y_DO_NOT_OPTIMIZE_AWAY(&val3);
+ Y_DO_NOT_OPTIMIZE_AWAY(val1);
+ Y_DO_NOT_OPTIMIZE_AWAY(val2);
+ Y_DO_NOT_OPTIMIZE_AWAY(val3);
+
+ UNIT_ASSERT_VALUES_EQUAL(val1, 1);
+ UNIT_ASSERT_VALUES_EQUAL(val2, 2);
+ UNIT_ASSERT_VALUES_EQUAL(val3, 3);
+ }
+#ifdef Y_HAVE_INT128
Y_UNIT_TEST(TestReadWrite128) {
- alignas(TUInt128) char buf[100] = {0};
-
+ alignas(TUInt128) char buf[100] = {0};
+
WriteUnaligned<TUInt128>(buf + 1, TUInt128::Max());
- auto val = ReadUnaligned<TUInt128>(buf + 1);
- UNIT_ASSERT(val == TUInt128::Max());
- }
+ auto val = ReadUnaligned<TUInt128>(buf + 1);
+ UNIT_ASSERT(val == TUInt128::Max());
+ }
Y_UNIT_TEST(TestReadWriteRuntime128) {
- // Unlike the test above, this test avoids compile-time execution by a smart compiler.
- // It is required to catch the SIGSEGV in case compiler emits an alignment-sensitive instruction.
-
- alignas(TUInt128) static char buf[100] = {0}; // static is required for Clobber to work
-
+ // Unlike the test above, this test avoids compile-time execution by a smart compiler.
+ // It is required to catch the SIGSEGV in case compiler emits an alignment-sensitive instruction.
+
+ alignas(TUInt128) static char buf[100] = {0}; // static is required for Clobber to work
+
WriteUnaligned<TUInt128>(buf + 1, TUInt128::Max());
- NBench::Clobber();
-
- auto val = ReadUnaligned<TUInt128>(buf + 1);
- Y_DO_NOT_OPTIMIZE_AWAY(&val);
- Y_DO_NOT_OPTIMIZE_AWAY(val.Low());
- Y_DO_NOT_OPTIMIZE_AWAY(val.High());
-
- UNIT_ASSERT(val == TUInt128::Max());
- }
-#endif
+ NBench::Clobber();
+
+ auto val = ReadUnaligned<TUInt128>(buf + 1);
+ Y_DO_NOT_OPTIMIZE_AWAY(&val);
+ Y_DO_NOT_OPTIMIZE_AWAY(val.Low());
+ Y_DO_NOT_OPTIMIZE_AWAY(val.High());
+
+ UNIT_ASSERT(val == TUInt128::Max());
+ }
+#endif
}