How is std.atan implemented

Hi, I noticed that AtanOp is added to standard dialect recently in this commit:

However, it seems that there is no lowering rule for std.atan. So how should std.atan be lowered to LLVM dialect?


libm has atan2 and you can just make a call to it, just like alloc is lowered via a call to malloc, but this one is much simpler.

Thanks for your reply. I will try implementing atan using libm. I have one more question, does libm work on GPUs? Should I use another implementation of std.atan for GPUs?

GPUs typically have special function units where trigonometric functions are performed. So typically you can lower it to the corresponding intrinsics. For example, for Vulkan, it would be converting to spv.GLSL.atan.

Tensorflow defines an approximation for some trigonometric functions. See mlir-hlo/ at master · tensorflow/mlir-hlo · GitHub
for the implementation.

Thanks for the replies :wink: