-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8321010: RISC-V: C2 RoundVF #17745
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
8321010: RISC-V: C2 RoundVF #17745
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
86397fa
RoundVF/D: Initial commit
Hamlin-Li ad92189
refine code
Hamlin-Li 029cfe6
Merge branch 'master' into round-F+D-v
Hamlin-Li d6cf04b
Fix corner cases
Hamlin-Li 1b6b7e9
v2: (src + 0.5) + rdn
Hamlin-Li ae70357
add test cases
c7c87bf
add tests
1695aeb
fix space
70c0e99
merge master
ba4cd66
fix minors
457fcfa
Merge branch 'master' into round-F+D-v
b7081bc
restore round mode back to rne
baca01d
Merge branch 'master' into round-F+D-v
2b57205
Merge branch 'master' into round-F+D-v
a9faee8
merge master
ffed86b
enable when vlenb >= 32
708fa0d
Merge branch 'master' into round-F+D-v
42f582e
enable intrinsic when MaxVectorSize >= 32
8f3af2f
enable roundVD when MaxVectorSize >= 64
066e9b7
add additional tests
9cdc198
minor
32baf7e
minor
2455978
minor
959c92e
Merge branch 'master' into round-F+D-v
c35fcdd
comments
68608fb
minor
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
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
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
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
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
84 changes: 84 additions & 0 deletions
84
test/hotspot/jtreg/compiler/floatingpoint/TestRoundFloatAll.java
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,84 @@ | ||
/* | ||
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2024, Rivos Inc. 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. | ||
*/ | ||
|
||
/** | ||
* @test | ||
* @bug 8321010 | ||
* @summary Test intrinsic for Math.round(float) in full 32 bits range | ||
* | ||
* @library /test/lib / | ||
* @modules java.base/jdk.internal.math | ||
* @requires os.arch == "riscv64" | ||
* @run main/othervm -XX:-TieredCompilation -Xbatch -XX:CompileThresholdScaling=0.3 -XX:-UseSuperWord | ||
* -XX:CompileCommand=compileonly,compiler.floatingpoint.TestRoundFloatAll::test* | ||
* compiler.floatingpoint.TestRoundFloatAll | ||
*/ | ||
|
||
package compiler.floatingpoint; | ||
|
||
import static compiler.lib.golden.GoldenRound.golden_round; | ||
|
||
public class TestRoundFloatAll { | ||
|
||
public static void main(String args[]) { | ||
test(); | ||
} | ||
|
||
// return true when test fails | ||
static boolean test(int n, float f) { | ||
int actual = Math.round(f); | ||
int expected = golden_round(f); | ||
if (actual != expected) { | ||
System.err.println("round error, input: " + f + ", res: " + actual + "expected: " + expected + ", input hex: " + n); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
static void test() { | ||
final int ITERS = 11000; | ||
boolean fail = false; | ||
|
||
// Warmup | ||
System.out.println("Warmup"); | ||
for (int i=0; i<ITERS; i++) { | ||
float f = Float.intBitsToFloat(i); | ||
fail |= test(i, f); | ||
} | ||
if (fail) { | ||
throw new RuntimeException("Warmup failed"); | ||
} | ||
|
||
// Test and verify results | ||
System.out.println("Verification"); | ||
int testInt = 0; | ||
do { | ||
float testFloat = Float.intBitsToFloat(testInt); | ||
fail |= test(testInt, testFloat); | ||
} while (++testInt != 0); | ||
if (fail) { | ||
throw new RuntimeException("Test failed"); | ||
} | ||
} | ||
} |
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,95 @@ | ||
/* | ||
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2024, Rivos Inc. 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 compiler.lib.golden; | ||
|
||
import jdk.internal.math.DoubleConsts; | ||
import jdk.internal.math.FloatConsts; | ||
|
||
public class GoldenRound { | ||
public static int golden_round(float a) { | ||
// below code is copied from java.base/share/classes/java/lang/Math.java | ||
// public static int round(float a) { ... } | ||
|
||
int intBits = Float.floatToRawIntBits(a); | ||
int biasedExp = (intBits & FloatConsts.EXP_BIT_MASK) | ||
>> (FloatConsts.SIGNIFICAND_WIDTH - 1); | ||
int shift = (FloatConsts.SIGNIFICAND_WIDTH - 2 | ||
+ FloatConsts.EXP_BIAS) - biasedExp; | ||
if ((shift & -32) == 0) { // shift >= 0 && shift < 32 | ||
// a is a finite number such that pow(2,-32) <= ulp(a) < 1 | ||
int r = ((intBits & FloatConsts.SIGNIF_BIT_MASK) | ||
| (FloatConsts.SIGNIF_BIT_MASK + 1)); | ||
if (intBits < 0) { | ||
r = -r; | ||
} | ||
// In the comments below each Java expression evaluates to the value | ||
// the corresponding mathematical expression: | ||
// (r) evaluates to a / ulp(a) | ||
// (r >> shift) evaluates to floor(a * 2) | ||
// ((r >> shift) + 1) evaluates to floor((a + 1/2) * 2) | ||
// (((r >> shift) + 1) >> 1) evaluates to floor(a + 1/2) | ||
return ((r >> shift) + 1) >> 1; | ||
} else { | ||
// a is either | ||
// - a finite number with abs(a) < exp(2,FloatConsts.SIGNIFICAND_WIDTH-32) < 1/2 | ||
// - a finite number with ulp(a) >= 1 and hence a is a mathematical integer | ||
// - an infinity or NaN | ||
return (int) a; | ||
} | ||
} | ||
|
||
|
||
public static long golden_round(double a) { | ||
// below code is copied from java.base/share/classes/java/lang/Math.java | ||
// public static int round(double a) { ... } | ||
|
||
long longBits = Double.doubleToRawLongBits(a); | ||
long biasedExp = (longBits & DoubleConsts.EXP_BIT_MASK) | ||
>> (DoubleConsts.SIGNIFICAND_WIDTH - 1); | ||
long shift = (DoubleConsts.SIGNIFICAND_WIDTH - 2 | ||
+ DoubleConsts.EXP_BIAS) - biasedExp; | ||
if ((shift & -64) == 0) { // shift >= 0 && shift < 64 | ||
// a is a finite number such that pow(2,-64) <= ulp(a) < 1 | ||
long r = ((longBits & DoubleConsts.SIGNIF_BIT_MASK) | ||
| (DoubleConsts.SIGNIF_BIT_MASK + 1)); | ||
if (longBits < 0) { | ||
r = -r; | ||
} | ||
// In the comments below each Java expression evaluates to the value | ||
// the corresponding mathematical expression: | ||
// (r) evaluates to a / ulp(a) | ||
// (r >> shift) evaluates to floor(a * 2) | ||
// ((r >> shift) + 1) evaluates to floor((a + 1/2) * 2) | ||
// (((r >> shift) + 1) >> 1) evaluates to floor(a + 1/2) | ||
return ((r >> shift) + 1) >> 1; | ||
} else { | ||
// a is either | ||
// - a finite number with abs(a) < exp(2,DoubleConsts.SIGNIFICAND_WIDTH-64) < 1/2 | ||
// - a finite number with ulp(a) >= 1 and hence a is a mathematical integer | ||
// - an infinity or NaN | ||
return (long) a; | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.