std::pow(x, 2) vs x * x assembly difference for integer arguments with GCC/Clang -O3

Viewed 79

For float arguments, fully optimized GCC/Clang assembly code is the same for std::pow(x,2) and x*x. However, for int arguments, there is a difference in the assembly. What is the reason for this extra assembly for int std::pow specification? My code does milions of such operations, so does it make sense to replace all std::pow(x,2) where x is int with x*x for performance reasons?

Godbolt link

0 Answers
Related