make skvm lerp() a little smarter

This lets us not worry about the cost of lerp() in what we know
should be cheap edge cases, t=0 and t=1.

These cases can't be handled by skvm's conservative peepholes:
   - (x-y)*0 isn't always 0 (if x-y is inf/NaN);
   - (x-y)*1+y is peepholed to (x-y)+y,
     but (x-y)+y is often not x, even for finite values.

Change-Id: Ia461d664b030c84b812857d346e0ed684eef8293
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/308916
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
This commit is contained in:
Mike Klein 2020-08-08 11:01:58 -05:00 committed by Skia Commit-Bot
parent 081101173a
commit 0467e6cedb
2 changed files with 7 additions and 1 deletions

View File

@ -1399,6 +1399,12 @@ namespace skvm {
};
}
F32 Builder::lerp(F32 lo, F32 hi, F32 t) {
if (this->isImm(t.id, 0.0f)) { return lo; }
if (this->isImm(t.id, 1.0f)) { return hi; }
return mad(sub(hi, lo), t, lo);
}
Color Builder::lerp(Color lo, Color hi, F32 t) {
return {
lerp(lo.r, hi.r, t),

View File

@ -654,7 +654,7 @@ namespace skvm {
F32 approx_atan(F32 x);
F32 approx_atan2(F32 y, F32 x);
F32 lerp(F32 lo, F32 hi, F32 t) { return mad(sub(hi, lo), t, lo); }
F32 lerp(F32 lo, F32 hi, F32 t);
F32 lerp(F32a lo, F32a hi, F32a t) { return lerp(_(lo), _(hi), _(t)); }
F32 clamp(F32 x, F32 lo, F32 hi) { return max(lo, min(x, hi)); }