Faster Math ?

Paul Sandoz paul.sandoz at
Thu Nov 9 17:19:32 UTC 2017

Hi Laurent,

A Java method is a candidate for intrinsification if it is annotated with @HotSpotIntrinsicCandidate. When running Java code you can also use the HotSpot flags -XX:+PrintCompilarion -XX:+PrintInlining to show methods that are intrinsic (JIT watch, as mentioned, is also excellent in this regard).

I recommend cloning OpenJDK and browsing the source.

Some of the math functions are intrinsic in the interpreter and all the runtime compilers to ensure consistent results across interpretation and compilation.

Work was done by Intel to improve many of the math functions. See:

  Update for x86 sin and cos in the math lib

  Update for x86 pow in the math lib
  (From these you can track related issues.)

Other Math functions are not intrinsic like cbrt (non-native) and acos (native). There is ongoing work to turn native implementations into Java implementations (i don’t know if there would be any follow up on intrinsification).

Joe knows more.


As part of the Vector API effort we will likely need to investigate the support for less accurate but faster math functions. It’s too early to tell if something like a FastMath class will pop out of that, but FWIW i am sympathetic to that :-)

I liked this tweet:

  life as a gpu compiler dev is basically just fielding repeated complaints that 
  "fast math" isn't precise and "precise math" isn't fast

as an indication of what we could be getting into :-)


> On 9 Nov 2017, at 01:00, Laurent Bourgès <bourges.laurent at> wrote:
> Hi,
> The Marlin renderer (JEP265) uses few Math functions: sqrt, cbrt, acos...
> Could you check if the current JDK uses C2 intrinsics or libfdm (native /
> JNI overhead?) and tell me if such functions are already highly optimized
> in jdk9 or 10 ?
> Some people have implemented their own fast Math like Apache Commons Math
> or JaFaMa libraries that are 10x faster for acos / cbrt.
> I wonder if I should implement my own cbrt function (cubics) in pure java
> as I do not need the highest accuracy but SPEED.
> Would it sound possible to have a JDK FastMath public API (lots faster but
> less accurate?)
> Do you know if recent CPU (intel?) have dedicated instructions for such
> math operations ?
> Why not use it instead?
> Maybe that's part of the new Vectorization API (panama) ?
> Cheers,
> Laurent Bourges

More information about the core-libs-dev mailing list