Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,22 @@ cc_library(
local_defines = ["HWY_HEADER_ONLY"],
)

cc_library(
name = "intdiv",
compatible_with = [],
copts = COPTS,
hdrs = [
"hwy/contrib/intdiv/intdiv.h",
],
textual_hdrs = [
"hwy/contrib/intdiv/intdiv-inl.h",
],
deps = [
":hwy",
],
)


cc_test(
name = "list_targets",
size = "small",
Expand Down Expand Up @@ -644,6 +660,17 @@ cc_test(
],
)

cc_test(
name = "intdiv_test",
size = "medium",
timeout = "long",
srcs = ["hwy/contrib/intdiv/intdiv_test.cc"],
copts = COPTS + HWY_TEST_COPTS,
local_defines = ["HWY_IS_TEST"],
tags = ["hwy_ops_test"],
deps = HWY_TEST_DEPS + [":intdiv"],
)

# For manually building the tests we define here (:all does not work in --config=msvc)
test_suite(
name = "hwy_ops_tests",
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ list(APPEND HWY_CONTRIB_SOURCES
hwy/contrib/image/image.cc
hwy/contrib/image/image.h
hwy/contrib/math/fast_math-inl.h
hwy/contrib/intdiv/intdiv.h
hwy/contrib/intdiv/intdiv-inl.h
hwy/contrib/math/math-inl.h
hwy/contrib/matvec/matvec-inl.h
hwy/contrib/random/random-inl.h
Expand Down Expand Up @@ -915,6 +917,7 @@ list(APPEND HWY_TEST_FILES
hwy/contrib/bit_pack/bit_pack_test.cc
hwy/contrib/dot/dot_test.cc
hwy/contrib/matvec/matvec_test.cc
hwy/contrib/intdiv/intdiv_test.cc
hwy/contrib/image/image_test.cc
# Disabled due to SIGILL in clang7 debug build during gtest discovery phase,
# not reproducible locally. Still tested via bazel build.
Expand Down
2 changes: 2 additions & 0 deletions hwy.gni
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ hwy_contrib_public = [
"$_hwy/contrib/dot/dot-inl.h",
"$_hwy/contrib/image/image.h",
"$_hwy/contrib/math/fast_math-inl.h",
"$_hwy/contrib/intdiv/intdiv.h",
"$_hwy/contrib/intdiv/intdiv-inl.h",
"$_hwy/contrib/math/math-inl.h",
]

Expand Down
15 changes: 9 additions & 6 deletions hwy/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -3049,10 +3049,11 @@ class Divisor64 {
// Returns n % divisor_.
uint64_t Remainder(uint64_t n) const { return n - (Divide(n) * divisor_); }

private:
uint64_t divisor_;
// private:
// uint64_t divisor_;

static uint64_t Div128(uint64_t hi, uint64_t div) {
HWY_DASSERT(div != 0);
#if HWY_COMPILER_MSVC >= 1920 && HWY_ARCH_X86_64
unsigned __int64 remainder; // unused
return _udiv128(hi, uint64_t{0}, div, &remainder);
Expand All @@ -3063,7 +3064,9 @@ class Divisor64 {
#endif
}

static uint64_t MulHigh(uint64_t a, uint64_t b) {
private:
uint64_t divisor_;
static uint64_t MulHigh(uint64_t a, uint64_t b) {
#if HWY_COMPILER_MSVC >= 1920 && HWY_ARCH_X86_64
return __umulh(a, b);
#else
Expand All @@ -3074,9 +3077,9 @@ class Divisor64 {
#endif
}

uint64_t mul_ = 1;
uint64_t shift1_ = 0;
uint64_t shift2_ = 0;
uint64_t mul_ = 1;
uint64_t shift1_ = 0;
uint64_t shift2_ = 0;
};
#else
// No Div128 available, use built-in 64-bit division on each call.
Expand Down
Loading
Loading