Skip to content

Commit 45d8a79

Browse files
committed
fix: use portable highway vector arithmetic
1 parent 23be82c commit 45d8a79

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

src/core/row_kernel_hwy.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ auto divide_u64_by_reciprocal_table(D64 d64, V64 numerator, V64 denominator) {
9191
hn::BitCast(di64, denominator)
9292
);
9393
auto quotient = hn::ShiftRight<kReciprocalShift>(hn::Mul(numerator, reciprocal));
94-
const auto next_quotient = quotient + one;
94+
const auto next_quotient = hn::Add(quotient, one);
9595
const auto needs_increment = hn::Le(hn::Mul(next_quotient, denominator), numerator);
9696
return hn::IfThenElse(needs_increment, next_quotient, quotient);
9797
}
@@ -122,7 +122,7 @@ auto sample_from_internal(D64 d64, V64I values) {
122122
const auto pixel_max = hn::Set(d64, std::uint64_t{(1 << kBitDepth) - 1});
123123
auto value = hn::BitCast(d64, hn::Max(values, zero_i64));
124124
value = hn::ShiftRight<18 - kBitDepth>(value);
125-
value = hn::ShiftRight<2>(value + one);
125+
value = hn::ShiftRight<2>(hn::Add(value, one));
126126
return hn::Min(value, pixel_max);
127127
}
128128

@@ -147,10 +147,10 @@ std::size_t process_add_row_vector(
147147
const auto source = hn::BitCast(di64, hn::ShiftLeft<20 - kBitDepth>(sample));
148148
const auto color = hn::PromoteTo(di64, hn::LoadN(di32, colors.data() + j, lane_count));
149149
const auto depth = hn::PromoteTo(di64, hn::LoadN(di32, depths.data() + j, lane_count));
150-
const auto remaining = logo_max - depth;
150+
const auto remaining = hn::Sub(logo_max, depth);
151151
auto numerator = hn::Mul(source, remaining);
152-
numerator = numerator + hn::Mul(color, depth);
153-
numerator = numerator + round;
152+
numerator = hn::Add(numerator, hn::Mul(color, depth));
153+
numerator = hn::Add(numerator, round);
154154

155155
const auto mixed = divide_i64_by_reciprocal_table(d64, numerator, logo_max_u);
156156
const auto value = sample_from_internal<kBitDepth>(d64, mixed);
@@ -182,11 +182,11 @@ std::size_t process_erase_row_vector(
182182
const auto color = hn::PromoteTo(di64, hn::LoadN(di32, colors.data() + j, lane_count));
183183
const auto depth = hn::PromoteTo(di64, hn::LoadN(di32, depths.data() + j, lane_count));
184184
const auto alpha = hn::Min(depth, max_alpha);
185-
const auto remaining = logo_max - alpha;
185+
const auto remaining = hn::Sub(logo_max, alpha);
186186

187187
auto numerator = hn::Mul(source, logo_max);
188-
numerator = numerator - hn::Mul(color, alpha);
189-
numerator = numerator + hn::ShiftRight<1>(remaining);
188+
numerator = hn::Sub(numerator, hn::Mul(color, alpha));
189+
numerator = hn::Add(numerator, hn::ShiftRight<1>(remaining));
190190

191191
const auto restored = divide_i64_by_reciprocal_table(
192192
d64,

0 commit comments

Comments
 (0)