[PATCH] 8217561 : X86: Add floating-point Math.min/max intrinsics, approval request
Andrew Haley
aph at redhat.com
Mon Feb 18 16:25:33 UTC 2019
On 2/18/19 4:09 PM, B. Blaser wrote:
> Yes and no, simply try your example with unfavourable data:
>
> @BenchmarkMode(Mode.AverageTime)
> @OutputTimeUnit(TimeUnit.NANOSECONDS)
> @State(Scope.Thread)
> public class FpMinMaxIntrinsics {
> private static final int COUNT = 1000;
>
> private float[] floats = new float[COUNT];
>
> private Random r = new Random();
>
> @Setup
> public void init() {
> for (int i=0; i<COUNT; i++) {
> if (i % 2 == 0)
> floats[i] = r.nextFloat();
> else
> floats[i] = -0.0f;
> }
> }
>
> @Benchmark
> public float fMinReduce() {
> float result = Float.MAX_VALUE;
>
> for (int i=0; i<COUNT; i++)
> result = Math.min(result, floats[i]);
>
> return result;
> }
> }
>
> With the intrinsic:
>
> Benchmark Mode Cnt Score Error Units
> FpMinMaxIntrinsics.fMinReduce avgt 2386.708 ns/op
>
>
> Without:
>
> Benchmark Mode Cnt Score Error Units
> FpMinMaxIntrinsics.fMinReduce avgt 14042.155 ns/op
>
>
> The execution time of the intrinsic will always be stable and you'll
> never have such performance drop-down.
This message is hard to interpret. The question is whether we should
be sure that adding an intrinsic will help Java performance. I don't
know what your point is. Of course there will be some cases where an
intrinsic actually helps, even in the case of a reduction. Whoever
said otherwise? The question is whether, on average or in typical,
such an intrinsic will make Java better. We have not answered that
question, but we are still talking about pushing this intrinsic.
Intel themselves are quite clear in their optimization guide that the
MIN/MAX instructions should be used only when the branch isn't
predictable. We have profile data when generating code in C2, so we
know enough to make an intelligent choice.
--
Andrew Haley
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671
More information about the hotspot-compiler-dev
mailing list