-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8353686: Optimize Math.cbrt for x86 64 bit platforms #24470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
30c48cb
x86_64 intrinsic for cbrt using libm
missa-prime db27673
Merge branch 'master' into user/missa-prime/cbrt
missa-prime 9cab7b2
Change coeff_table alignment from 4 bytes to 16 bytes to conform with…
missa-prime 3212c66
Merge branch 'openjdk:master' into user/missa-prime/cbrt
missa-prime 57412f0
Add new set of cbrt micro-benchmarks
missa-prime 75516f1
Remove unnecessary movapd definitions in macro-assembler header file
missa-prime 14b416c
Remove unnecessary unpckhpd and unpcklpd definitions in macro-assembl…
missa-prime 42424aa
Use rcx as base and r8 as index for address calculations in certain c…
missa-prime ff4d4f2
Remove comment mentioning invalid exception when NaN input is provided
missa-prime c00b625
Add special case values to cbrt micro-benchmark set
missa-prime 233e018
Add newline back to templateInterpreterGenerator_x86_64.cpp source file
missa-prime c931222
Set address attributes in movapd assembly instruction function defini…
missa-prime File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| /* | ||
| * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * | ||
| * This code is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. | ||
| * | ||
| * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| * or visit www.oracle.com if you need additional information or have any | ||
| * questions. | ||
| */ | ||
| package org.openjdk.bench.java.lang; | ||
|
|
||
| import java.util.concurrent.TimeUnit; | ||
| import org.openjdk.jmh.annotations.Benchmark; | ||
| import org.openjdk.jmh.annotations.BenchmarkMode; | ||
| import org.openjdk.jmh.annotations.Fork; | ||
| import org.openjdk.jmh.annotations.Measurement; | ||
| import org.openjdk.jmh.annotations.Mode; | ||
| import org.openjdk.jmh.annotations.Param; | ||
| import org.openjdk.jmh.annotations.Scope; | ||
| import org.openjdk.jmh.annotations.Setup; | ||
| import org.openjdk.jmh.annotations.State; | ||
| import org.openjdk.jmh.annotations.Level; | ||
| import org.openjdk.jmh.annotations.Warmup; | ||
| import org.openjdk.jmh.annotations.OperationsPerInvocation; | ||
| import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
| import org.openjdk.jmh.runner.Runner; | ||
| import org.openjdk.jmh.runner.RunnerException; | ||
| import org.openjdk.jmh.runner.options.Options; | ||
| import org.openjdk.jmh.runner.options.OptionsBuilder; | ||
|
|
||
| import java.util.Random; | ||
|
|
||
| public class CbrtPerf { | ||
|
|
||
| @Warmup(iterations = 3, time = 5, timeUnit = TimeUnit.MILLISECONDS) | ||
| @Measurement(iterations = 4, time = 5, timeUnit = TimeUnit.MILLISECONDS) | ||
| @Fork(2) | ||
| @BenchmarkMode(Mode.Throughput) | ||
| @State(Scope.Thread) | ||
| @OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
| public static class CbrtPerfRanges { | ||
| public static int cbrtInputCount = 2048; | ||
|
|
||
| @Param({"0", "1"}) | ||
| public int cbrtRangeIndex; | ||
|
|
||
| public double [] cbrtPosRandInputs; | ||
| public double [] cbrtNegRandInputs; | ||
| public int cbrtInputIndex = 0; | ||
| public double cbrtRangeInputs[][] = { {0.0, 0x1.0P-1022}, {0x1.0P-1022, 1.7976931348623157E308} }; | ||
|
|
||
| @Setup | ||
| public void setupValues() { | ||
| Random random = new Random(1023); | ||
|
|
||
| // Fill the positive and negative cbrt vectors with random values | ||
| cbrtPosRandInputs = new double[cbrtInputCount]; | ||
| cbrtNegRandInputs = new double[cbrtInputCount]; | ||
|
|
||
| for (int i = 0; i < cbrtInputCount; i++) { | ||
| double cbrtLowerBound = cbrtRangeInputs[cbrtRangeIndex][0]; | ||
| double cbrtUpperBound = cbrtRangeInputs[cbrtRangeIndex][1]; | ||
| cbrtPosRandInputs[i] = random.nextDouble(cbrtLowerBound, cbrtUpperBound); | ||
| cbrtNegRandInputs[i] = random.nextDouble(-cbrtUpperBound, -cbrtLowerBound); | ||
| } | ||
| } | ||
|
|
||
| @Benchmark | ||
| @OperationsPerInvocation(2048) | ||
| public double cbrtPosRangeDouble() { | ||
| double res = 0.0; | ||
| for (int i = 0; i < cbrtInputCount; i++) { | ||
| res += Math.cbrt(cbrtPosRandInputs[i]); | ||
| } | ||
| return res; | ||
| } | ||
|
|
||
| @Benchmark | ||
| @OperationsPerInvocation(2048) | ||
| public double cbrtNegRangeDouble() { | ||
| double res = 0.0; | ||
| for (int i = 0; i < cbrtInputCount; i++) { | ||
| res += Math.cbrt(cbrtNegRandInputs[i]); | ||
| } | ||
| return res; | ||
| } | ||
| } | ||
|
|
||
| @Warmup(iterations = 3, time = 5, timeUnit = TimeUnit.SECONDS) | ||
| @Measurement(iterations = 4, time = 5, timeUnit = TimeUnit.SECONDS) | ||
| @Fork(2) | ||
| @BenchmarkMode(Mode.Throughput) | ||
| @State(Scope.Thread) | ||
| @OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
| public static class CbrtPerfConstant { | ||
| public static final double constDouble0 = 0.0; | ||
| public static final double constDouble1 = 1.0; | ||
| public static final double constDouble27 = 27.0; | ||
| public static final double constDouble512 = 512.0; | ||
|
|
||
| @Benchmark | ||
missa-prime marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public double cbrtConstDouble0() { | ||
| return Math.cbrt(constDouble0); | ||
| } | ||
|
|
||
| @Benchmark | ||
| public double cbrtConstDouble1() { | ||
| return Math.cbrt(constDouble1); | ||
| } | ||
|
|
||
| @Benchmark | ||
| public double cbrtConstDouble27() { | ||
| return Math.cbrt(constDouble27); | ||
| } | ||
|
|
||
| @Benchmark | ||
| public double cbrtConstDouble512() { | ||
| return Math.cbrt(constDouble512); | ||
| } | ||
| } | ||
|
|
||
| public static void main(String[] args) throws RunnerException { | ||
| Options opt = new OptionsBuilder() | ||
| .include(CbrtPerfRanges.class.getSimpleName()) | ||
| .build(); | ||
|
|
||
| new Runner(opt).run(); | ||
|
|
||
| opt = new OptionsBuilder() | ||
| .include(CbrtPerfConstant.class.getSimpleName()) | ||
| .build(); | ||
|
|
||
| new Runner(opt).run(); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.