diff --git a/src/quick-lint-js/port/math.h b/src/quick-lint-js/port/math.h index 2ac2258853..268d3104e0 100644 --- a/src/quick-lint-js/port/math.h +++ b/src/quick-lint-js/port/math.h @@ -3,14 +3,6 @@ #pragma once -#include -#include -#include - -#if QLJS_HAVE_INTRIN_H -#include -#endif - namespace quick_lint_js { // On some compilers, std::max is not constexpr. Define our own which is // constexpr. @@ -18,39 +10,6 @@ template constexpr auto maximum(T x, U y) { return x < y ? y : x; } - -// Returns (lhs*rhs)>>64. -inline std::uint64_t multiply_u64_get_top_64(std::uint64_t lhs, - std::uint64_t rhs) { - // Discussion of approaches: https://stackoverflow.com/q/28868367 -#if QLJS_HAVE_INT128 - QLJS_WARNING_PUSH - QLJS_WARNING_IGNORE_GCC("-Wpedantic") - - using U128 = unsigned __int128; - return static_cast( - (static_cast(lhs) * static_cast(rhs)) >> 64); - - QLJS_WARNING_POP -#elif QLJS_HAVE_UMULH - return __umulh(lhs, rhs); -#else - // Algorithm adapted from Fabian 'ryg' Giesen's public domain work: - // https://github.com/jkbonfield/rans_static/blob/576e9db9e02659a5797ce5e21dd99f6ce0285727/rans64.h#L51-L64 - auto lo = [](std::uint64_t x) -> std::uint64_t { return x & 0xffff'ffff; }; - auto hi = [](std::uint64_t x) -> std::uint64_t { return x >> 32; }; - std::uint64_t a = hi(lhs); - std::uint64_t b = lo(lhs); - std::uint64_t c = hi(rhs); - std::uint64_t d = lo(rhs); - std::uint64_t x0 = d * b; - std::uint64_t x1 = lo(d * a) + lo(c * b) + hi(x0); - std::uint64_t x2 = hi(d * a) + hi(c * b) + lo(c * a) + hi(x1); - std::uint64_t x3 = hi(c * a) + hi(x2); - // x3, lo(x2), lo(x1), lo(x0) - return (x3 << 32) + lo(x2); -#endif -} } // quick-lint-js finds bugs in JavaScript programs. diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index da06508cbe..1296033539 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -127,7 +127,6 @@ quick_lint_js_add_executable( test-lsp-uri.cpp test-lsp-workspace-configuration.cpp test-math-overflow.cpp - test-math.cpp test-narrow-cast.cpp test-options.cpp test-output-stream.cpp diff --git a/test/test-math.cpp b/test/test-math.cpp deleted file mode 100644 index 09129e5fbc..0000000000 --- a/test/test-math.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (C) 2020 Matthew "strager" Glazar -// See end of file for extended copyright information. - -#include -#include - -namespace quick_lint_js { -namespace { -TEST(Test_Math, multiply_u64_get_top_64) { - EXPECT_EQ(multiply_u64_get_top_64(0, 0), 0); - - EXPECT_EQ(multiply_u64_get_top_64(0x80000000'00000000ULL, 2), 1); - EXPECT_EQ( - multiply_u64_get_top_64(0x80000000'00000000ULL, 0x80000000'00000000ULL), - 0x40000000'00000000ULL); - EXPECT_EQ( - multiply_u64_get_top_64(13869076433459953670ULL, 14835062956724989689ULL), - 11153655150192271059ULL); -} -} -} - -// quick-lint-js finds bugs in JavaScript programs. -// Copyright (C) 2020 Matthew "strager" Glazar -// -// This file is part of quick-lint-js. -// -// quick-lint-js is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// quick-lint-js is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with quick-lint-js. If not, see .