Mercurial > vec
changeset 33:4655b49eaf9f
Backed out changeset 6c91cd9a2f2d
author | Paper <paper@tflc.us> |
---|---|
date | Fri, 25 Apr 2025 17:40:42 -0400 |
parents | 0de48dc864ea |
children | 8b5e0974fd41 |
files | include/vec/vec.h |
diffstat | 1 files changed, 12 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/include/vec/vec.h Fri Apr 25 17:40:38 2025 -0400 +++ b/include/vec/vec.h Fri Apr 25 17:40:42 2025 -0400 @@ -239,14 +239,19 @@ inline vec_intmax vec_avg(vec_intmax x, vec_intmax y) { - vec_intmax x_d_quot = (x / 2); - vec_intmax x_d_rem = (x % 2); - vec_intmax y_d_quot = (y / 2); - vec_intmax y_d_rem = (y % 2); - vec_intmax rem_d_quot = ((x_d_rem + y_d_rem) / 2); - vec_intmax rem_d_rem = ((x_d_rem + y_d_rem) % 2); + if ((x < 0) == (y < 0)) { // same sign + // this gets the equivalent of: + // vec_int32 r = ((vec_int64)x + (vec_int64)y) / 2; + vec_intmax r = (x / 2) + (y / 2) + (((x % 2) + (y % 2)) / 2); + + // FIXME emulate AltiVec quirks - return (x_d_quot + y_d_quot) + (rem_d_quot) + (rem_d_rem == 1); + return r; + } else { + vec_intmax r = (x + y) / 2; + // FIXME emulate AltiVec quirks + return r; + } } inline vec_uintmax vec_uavg(vec_uintmax x, vec_uintmax y)