Skip to content

Conversation

@openroad-ci
Copy link
Collaborator

Adjust lerp formula to reduce the introduced rounding error and fix the failure seen at The-OpenROAD-Project/OpenROAD-flow-scripts#3242 (comment)

@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@povik
Copy link
Contributor

povik commented Jun 17, 2025

Secure CI came back green

@povik povik requested a review from maliberty June 17, 2025 16:45
return slack - (ref_slack_ - slack) * 2e-6;
}

float lerp(float a, float b, float t)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use std::lerp

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I purposely open-coded it so we can see the formula and reason about the rounding errors (though I'm not fully sure compiler cannot rewrite it in optimization)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note the std version handles more corner cases but perhaps they don't arise here.

  template<typename _Fp>
    constexpr _Fp
    __lerp(_Fp __a, _Fp __b, _Fp __t) noexcept
    {
      if ((__a <= 0 && __b >= 0) || (__a >= 0 && __b <= 0))
	return __t * __b + (1 - __t) * __a;

      if (__t == 1)
	return __b;                        // exact

      // Exact at __t=0, monotonic except near __t=1,
      // bounded, determinate, and consistent:
      const _Fp __x = __a + __t * (__b - __a);
      return (__t > 1) == (__b > __a)
	? (__b < __x ? __x : __b)
	: (__b > __x ? __x : __b);  // monotonic near __t=1
    }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting they have different cases. I assume that's just one way it may be implemented.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They handle overflow for one. The core formula is similar.

@maliberty maliberty merged commit c394f51 into The-OpenROAD-Project:master Jun 17, 2025
10 of 11 checks passed
@maliberty maliberty deleted the rsz-buffer-lerp branch June 17, 2025 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants