aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/int128/ut/int128_via_intrinsic_ut.cpp
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/int128/ut/int128_via_intrinsic_ut.cpp
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/int128/ut/int128_via_intrinsic_ut.cpp')
-rw-r--r--library/cpp/int128/ut/int128_via_intrinsic_ut.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/library/cpp/int128/ut/int128_via_intrinsic_ut.cpp b/library/cpp/int128/ut/int128_via_intrinsic_ut.cpp
new file mode 100644
index 0000000000..9decc2fd48
--- /dev/null
+++ b/library/cpp/int128/ut/int128_via_intrinsic_ut.cpp
@@ -0,0 +1,34 @@
+#include <library/cpp/int128/int128.h>
+
+#include <library/cpp/testing/unittest/registar.h>
+
+// from https://a.yandex-team.ru/arc/trunk/arcadia/library/ticket_parser/c/src/ut/utils_ut.cpp?rev=4221861
+
+#if defined(Y_HAVE_INT128)
+Y_UNIT_TEST_SUITE(Int128ViaIntrinsicSuite) {
+ using guint128_t = unsigned __int128;
+ guint128_t toGcc(ui128 num) {
+ guint128_t res = 0;
+ res |= GetLow(num);
+ res |= guint128_t(GetHigh(num)) << 64;
+ return res;
+ }
+
+ Y_UNIT_TEST(bigintTest) {
+ UNIT_ASSERT(guint128_t(127) == toGcc(ui128(127)));
+ UNIT_ASSERT(guint128_t(127) * guint128_t(127) == toGcc(ui128(127) * ui128(127)));
+ UNIT_ASSERT(guint128_t(127) + guint128_t(127) == toGcc(ui128(127) + ui128(127)));
+ UNIT_ASSERT(guint128_t(127) << 3 == toGcc(ui128(127) << 3));
+ UNIT_ASSERT(guint128_t(127) >> 1 == toGcc(ui128(127) >> 1));
+
+ UNIT_ASSERT(guint128_t(1000000000027UL) * guint128_t(1000000000027UL) == toGcc(ui128(1000000000027UL) * ui128(1000000000027UL)));
+ UNIT_ASSERT(guint128_t(1000000000027UL) + guint128_t(1000000000027UL) == toGcc(ui128(1000000000027UL) + ui128(1000000000027UL)));
+ UNIT_ASSERT(guint128_t(1000000000027UL) << 3 == toGcc(ui128(1000000000027UL) << 3));
+ UNIT_ASSERT(guint128_t(1000000000027UL) >> 1 == toGcc(ui128(1000000000027UL) >> 1));
+ UNIT_ASSERT((guint128_t(1000000000027UL) * guint128_t(1000000000027UL)) << 3 == toGcc((ui128(1000000000027UL) * ui128(1000000000027UL)) << 3));
+ UNIT_ASSERT((guint128_t(1000000000027UL) + guint128_t(1000000000027UL)) >> 1 == toGcc((ui128(1000000000027UL) + ui128(1000000000027UL)) >> 1));
+
+ UNIT_ASSERT((ui64)(guint128_t(1000000000027UL) * guint128_t(1000000000027UL)) == GetLow(ui128(1000000000027UL) * ui128(1000000000027UL)));
+ }
+}
+#endif