Skip to content

Commit 78b390e

Browse files
add intdiv imp
Signed-off-by: Abhishek Kumar <abhishek.r.kumar@fujitsu.com>
1 parent 5c7030c commit 78b390e

8 files changed

Lines changed: 1639 additions & 6 deletions

File tree

BUILD

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,22 @@ cc_library(
539539
local_defines = ["HWY_HEADER_ONLY"],
540540
)
541541

542+
cc_library(
543+
name = "intdiv",
544+
compatible_with = [],
545+
copts = COPTS,
546+
hdrs = [
547+
"hwy/contrib/intdiv/intdiv.h",
548+
],
549+
textual_hdrs = [
550+
"hwy/contrib/intdiv/intdiv-inl.h",
551+
],
552+
deps = [
553+
":hwy",
554+
],
555+
)
556+
557+
542558
cc_test(
543559
name = "list_targets",
544560
size = "small",
@@ -644,6 +660,17 @@ cc_test(
644660
],
645661
)
646662

663+
cc_test(
664+
name = "intdiv_test",
665+
size = "medium",
666+
timeout = "long",
667+
srcs = ["hwy/contrib/intdiv/intdiv_test.cc"],
668+
copts = COPTS + HWY_TEST_COPTS,
669+
local_defines = ["HWY_IS_TEST"],
670+
tags = ["hwy_ops_test"],
671+
deps = HWY_TEST_DEPS + [":intdiv"],
672+
)
673+
647674
# For manually building the tests we define here (:all does not work in --config=msvc)
648675
test_suite(
649676
name = "hwy_ops_tests",

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ list(APPEND HWY_CONTRIB_SOURCES
222222
hwy/contrib/image/image.cc
223223
hwy/contrib/image/image.h
224224
hwy/contrib/math/fast_math-inl.h
225+
hwy/contrib/intdiv/intdiv.h
226+
hwy/contrib/intdiv/intdiv-inl.h
225227
hwy/contrib/math/math-inl.h
226228
hwy/contrib/matvec/matvec-inl.h
227229
hwy/contrib/random/random-inl.h
@@ -915,6 +917,7 @@ list(APPEND HWY_TEST_FILES
915917
hwy/contrib/bit_pack/bit_pack_test.cc
916918
hwy/contrib/dot/dot_test.cc
917919
hwy/contrib/matvec/matvec_test.cc
920+
hwy/contrib/intdiv/intdiv_test.cc
918921
hwy/contrib/image/image_test.cc
919922
# Disabled due to SIGILL in clang7 debug build during gtest discovery phase,
920923
# not reproducible locally. Still tested via bazel build.

hwy.gni

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ hwy_contrib_public = [
5252
"$_hwy/contrib/dot/dot-inl.h",
5353
"$_hwy/contrib/image/image.h",
5454
"$_hwy/contrib/math/fast_math-inl.h",
55+
"$_hwy/contrib/intdiv/intdiv.h",
56+
"$_hwy/contrib/intdiv/intdiv-inl.h",
5557
"$_hwy/contrib/math/math-inl.h",
5658
]
5759

hwy/base.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3049,10 +3049,11 @@ class Divisor64 {
30493049
// Returns n % divisor_.
30503050
uint64_t Remainder(uint64_t n) const { return n - (Divide(n) * divisor_); }
30513051

3052-
private:
3053-
uint64_t divisor_;
3052+
// private:
3053+
// uint64_t divisor_;
30543054

30553055
static uint64_t Div128(uint64_t hi, uint64_t div) {
3056+
HWY_DASSERT(div != 0);
30563057
#if HWY_COMPILER_MSVC >= 1920 && HWY_ARCH_X86_64
30573058
unsigned __int64 remainder; // unused
30583059
return _udiv128(hi, uint64_t{0}, div, &remainder);
@@ -3063,7 +3064,9 @@ class Divisor64 {
30633064
#endif
30643065
}
30653066

3066-
static uint64_t MulHigh(uint64_t a, uint64_t b) {
3067+
private:
3068+
uint64_t divisor_;
3069+
static uint64_t MulHigh(uint64_t a, uint64_t b) {
30673070
#if HWY_COMPILER_MSVC >= 1920 && HWY_ARCH_X86_64
30683071
return __umulh(a, b);
30693072
#else
@@ -3074,9 +3077,9 @@ class Divisor64 {
30743077
#endif
30753078
}
30763079

3077-
uint64_t mul_ = 1;
3078-
uint64_t shift1_ = 0;
3079-
uint64_t shift2_ = 0;
3080+
uint64_t mul_ = 1;
3081+
uint64_t shift1_ = 0;
3082+
uint64_t shift2_ = 0;
30803083
};
30813084
#else
30823085
// No Div128 available, use built-in 64-bit division on each call.

0 commit comments

Comments
 (0)