This is an archive of the discontinued LLVM Phabricator instance.

Add polynomial approximation for trigonometric sine and cosine functions
ClosedPublic

Authored by asaadaldien on Jun 18 2021, 4:54 PM.

Details

Summary

The approximation relays on range reduced version y \in [0, pi/2]. An input x will have
the property that sin(x) = sin(y), -sin(y), cos(y), -cos(y) depends on which quadrable x
is in, where sin(y) and cos(y) are approximated with 5th degree polynomial (of x^2).
As a result a single pattern can be used to compute approximation for both sine and cosine.

Diff Detail

Event Timeline

asaadaldien created this revision.Jun 18 2021, 4:54 PM
asaadaldien requested review of this revision.Jun 18 2021, 4:54 PM
ezhulenev accepted this revision.Jun 20 2021, 7:24 AM

There are bunch of variable name warning, I'd say it's ok to keep CC/KR/etc upper case but cast_f32_to_i32 and such are better to keep consistent

mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp
639
private:
  static constexpr bool isSine = std::is_same<OpTy, math::SinOp>::value;

+ static_assert that OpTy is Sin or Cos

This revision is now accepted and ready to land.Jun 20 2021, 7:24 AM

consistant constant / utility func naming

asaadaldien edited the summary of this revision. (Show Details)Jun 21 2021, 9:42 AM

assert cosOp&sinOp types and fix clang-tidy warning

asaadaldien marked an inline comment as done.Jun 21 2021, 10:43 AM