Skip to content

Commit

Permalink
refactor(port): delete unused multiply_u64_get_top_64
Browse files Browse the repository at this point in the history
multiply_u64_get_top_64 is no longer used anywhere. Delete its
implementation and tests.
  • Loading branch information
strager committed Dec 22, 2023
1 parent 3332f89 commit e80ca00
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 81 deletions.
41 changes: 0 additions & 41 deletions src/quick-lint-js/port/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,13 @@

#pragma once

#include <cstdint>
#include <quick-lint-js/port/have.h>
#include <quick-lint-js/port/warning.h>

#if QLJS_HAVE_INTRIN_H
#include <intrin.h>
#endif

namespace quick_lint_js {
// On some compilers, std::max is not constexpr. Define our own which is
// constexpr.
template <class T, class U>
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<std::uint64_t>(
(static_cast<U128>(lhs) * static_cast<U128>(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.
Expand Down
1 change: 0 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 0 additions & 39 deletions test/test-math.cpp

This file was deleted.

0 comments on commit e80ca00

Please sign in to comment.