Skip to content

Commit

Permalink
fix emu128 reduction with infinities. thanks @yohanchatelain, fixes #…
Browse files Browse the repository at this point in the history
…2434

PiperOrigin-RevId: 713663844
  • Loading branch information
jan-wassenberg authored and copybara-github committed Jan 13, 2025
1 parent c8c3f5e commit ade77a5
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions hwy/ops/emu128-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2916,17 +2916,38 @@ HWY_API T ReduceSum(D d, VFromD<D> v) {
}
return sum;
}

namespace detail {
template <class D, typename T = TFromD<D>, HWY_IF_FLOAT_OR_SPECIAL(T)>
T InitReduceMin(D d) {
return GetLane(Inf(d));
}
template <class D, typename T = TFromD<D>, HWY_IF_NOT_FLOAT_NOR_SPECIAL(T)>
T InitReduceMin(D d) {
return HighestValue<T>();
}

template <class D, typename T = TFromD<D>, HWY_IF_FLOAT_OR_SPECIAL(T)>
T InitReduceMax(D d) {
return -GetLane(Inf(d));
}
template <class D, typename T = TFromD<D>, HWY_IF_NOT_FLOAT_NOR_SPECIAL(T)>
T InitReduceMax(D d) {
return LowestValue<T>();
}
} // namespace detail

template <class D, typename T = TFromD<D>, HWY_IF_REDUCE_D(D)>
HWY_API T ReduceMin(D d, VFromD<D> v) {
T min = HighestValue<T>();
T min = detail::InitReduceMin(d);
for (size_t i = 0; i < MaxLanes(d); ++i) {
min = HWY_MIN(min, v.raw[i]);
}
return min;
}
template <class D, typename T = TFromD<D>, HWY_IF_REDUCE_D(D)>
HWY_API T ReduceMax(D d, VFromD<D> v) {
T max = LowestValue<T>();
T max = detail::InitReduceMax(d);
for (size_t i = 0; i < MaxLanes(d); ++i) {
max = HWY_MAX(max, v.raw[i]);
}
Expand Down

0 comments on commit ade77a5

Please sign in to comment.