Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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 jdk.graal.compiler.replacements.test;

import org.junit.Test;

import jdk.graal.compiler.jtt.JTTTest;

public class MathCbrtTest extends JTTTest {

public double cbrt(double d) {
return Math.cbrt(d);
}

@Test
public void testCbrt() {
for (double d = -3.0d; d <= 3.0D; d += 0.01D) {
test("cbrt", d);
}

double[] inputs = {Math.PI / 2, Math.PI, -1.0D, Double.MAX_VALUE, Double.MIN_VALUE, Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY,
Double.longBitsToDouble(0x7fffffffffffffffL), Double.longBitsToDouble(0xffffffffffffffffL)};
for (double d : inputs) {
test("cbrt", d);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 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
Expand Down Expand Up @@ -59,19 +59,18 @@ public void testMathSubstitutions() {
testGraph("mathSin");
testGraph("mathSqrt");
testGraph("mathTan");
testGraph("mathTanh");
testGraph("mathCbrt");
testGraph("mathAll");

if (getReplacements().hasSubstitution(getResolvedJavaMethod(Math.class, "tanh"), getInitialOptions())) {
testGraph("mathTanh");
}

test("mathCos", value);
test("mathLog", value);
test("mathLog10", value);
test("mathSin", value);
test("mathSqrt", value);
test("mathTan", value);
test("mathTanh", value);
test("mathCbrt", value);
test("mathAll", value);
}

Expand Down Expand Up @@ -141,8 +140,12 @@ public static double mathTanh(double value) {
return Math.tanh(value);
}

public static double mathCbrt(double value) {
return Math.cbrt(value);
}

public static double mathAll(double value) {
return Math.sqrt(value) + Math.log(value) + Math.log10(value) + Math.sin(value) + Math.cos(value) + Math.tan(value);
return Math.sqrt(value) + Math.log(value) + Math.log10(value) + Math.sin(value) + Math.cos(value) + Math.tan(value) + Math.tanh(value) + Math.cbrt(value);
}

public void testSubstitution(String testMethodName, Class<?> holder, String methodName, boolean optional, Object[] args, Class<?>... intrinsicClasses) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5036,6 +5036,10 @@ public final void incq(AMD64Address dst) {
AMD64MOp.INC.emit(this, OperandSize.QWORD, dst);
}

public final void movapd(Register dst, AMD64Address src) {
SSEOp.MOVAPD.emit(this, OperandSize.PD, dst, src);
}

public final void movapd(Register dst, Register src) {
SSEOp.MOVAPD.emit(this, OperandSize.PD, dst, src);
}
Expand Down Expand Up @@ -5299,6 +5303,10 @@ public final void orl(Register dst, int imm32) {
AMD64BinaryArithmetic.OR.getMIOpcode(OperandSize.DWORD, isByte(imm32)).emit(this, OperandSize.DWORD, dst, imm32);
}

public final void orpd(Register dst, Register src) {
SSEOp.OR.emit(this, OperandSize.PD, dst, src);
}

public final void orq(Register dst, Register src) {
AMD64BinaryArithmetic.OR.rmOp.emit(this, OperandSize.QWORD, dst, src);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
import jdk.graal.compiler.lir.amd64.AMD64CountTrailingZerosOp;
import jdk.graal.compiler.lir.amd64.AMD64FloatToHalfFloatOp;
import jdk.graal.compiler.lir.amd64.AMD64HalfFloatToFloatOp;
import jdk.graal.compiler.lir.amd64.AMD64MathCbrtOp;
import jdk.graal.compiler.lir.amd64.AMD64MathCopySignOp;
import jdk.graal.compiler.lir.amd64.AMD64MathCosOp;
import jdk.graal.compiler.lir.amd64.AMD64MathExpOp;
Expand Down Expand Up @@ -1311,6 +1312,11 @@ public Value emitMathExp(Value input) {
return new AMD64MathExpOp().emitLIRWrapper(getLIRGen(), input);
}

@Override
public Value emitMathCbrt(Value input) {
return new AMD64MathCbrtOp().emitLIRWrapper(getLIRGen(), input);
}

@Override
public Value emitMathPow(Value x, Value y) {
return new AMD64MathPowOp().emitLIRWrapper(getLIRGen(), x, y);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ private long getZGCAddressField(String name) {
public final long arithmeticLogAddress = getFieldValue("CompilerToVM::Data::dlog", Long.class, "address");
public final long arithmeticLog10Address = getFieldValue("CompilerToVM::Data::dlog10", Long.class, "address");
public final long arithmeticPowAddress = getFieldValue("CompilerToVM::Data::dpow", Long.class, "address");
public final long arithmeticCbrtAddress = getFieldValue("CompilerToVM::Data::dcbrt", Long.class, "address");

public final long fremAddress = getAddress("SharedRuntime::frem");
public final long dremAddress = getAddress("SharedRuntime::drem");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 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
Expand Down Expand Up @@ -33,6 +33,7 @@
import static jdk.graal.compiler.hotspot.HotSpotForeignCallLinkage.RegisterEffect.DESTROYS_ALL_CALLER_SAVE_REGISTERS;
import static jdk.graal.compiler.hotspot.meta.HotSpotForeignCallDescriptor.Transition.LEAF;
import static jdk.graal.compiler.replacements.nodes.BinaryMathIntrinsicNode.BinaryOperation.POW;
import static jdk.graal.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.CBRT;
import static jdk.graal.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.COS;
import static jdk.graal.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.EXP;
import static jdk.graal.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.LOG;
Expand Down Expand Up @@ -110,6 +111,7 @@ protected void registerMathStubs(GraalHotSpotVMConfig hotSpotVMConfig, HotSpotPr
link(new AMD64MathStub(LOG, options, providers, registerStubCall(LOG.foreignCallSignature, LEAF, NO_SIDE_EFFECT, COMPUTES_REGISTERS_KILLED, NO_LOCATIONS)));
link(new AMD64MathStub(LOG10, options, providers, registerStubCall(LOG10.foreignCallSignature, LEAF, NO_SIDE_EFFECT, COMPUTES_REGISTERS_KILLED, NO_LOCATIONS)));
link(new AMD64MathStub(POW, options, providers, registerStubCall(POW.foreignCallSignature, LEAF, NO_SIDE_EFFECT, COMPUTES_REGISTERS_KILLED, NO_LOCATIONS)));
link(new AMD64MathStub(CBRT, options, providers, registerStubCall(CBRT.foreignCallSignature, LEAF, NO_SIDE_EFFECT, COMPUTES_REGISTERS_KILLED, NO_LOCATIONS)));
} else {
super.registerMathStubs(hotSpotVMConfig, providers, options);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 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
Expand Down Expand Up @@ -49,24 +49,16 @@ public AMD64MathStub(BinaryOperation operation, OptionValues options, HotSpotPro
}

private static String snippetName(UnaryOperation operation) {
switch (operation) {
case SIN:
return "sin";
case COS:
return "cos";
case TAN:
return "tan";
case TANH:
return "tanh";
case EXP:
return "exp";
case LOG:
return "log";
case LOG10:
return "log10";
default:
throw GraalError.shouldNotReachHere("Unknown operation " + operation); // ExcludeFromJacocoGeneratedReport
}
return switch (operation) {
case SIN -> "sin";
case COS -> "cos";
case TAN -> "tan";
case TANH -> "tanh";
case EXP -> "exp";
case LOG -> "log";
case LOG10 -> "log10";
case CBRT -> "cbrt";
};
}

private static String snippetName(BinaryOperation operation) {
Expand Down Expand Up @@ -115,4 +107,9 @@ private static double exp(double value) {
private static double pow(double value1, double value2) {
return BinaryMathIntrinsicNode.compute(value1, value2, BinaryOperation.POW);
}

@Snippet
private static double cbrt(double value) {
return UnaryMathIntrinsicNode.compute(value, UnaryOperation.CBRT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
import static jdk.graal.compiler.hotspot.stubs.UnwindExceptionToCallerStub.EXCEPTION_HANDLER_FOR_RETURN_ADDRESS;
import static jdk.graal.compiler.nodes.java.ForeignCallDescriptors.REGISTER_FINALIZER;
import static jdk.graal.compiler.replacements.nodes.BinaryMathIntrinsicNode.BinaryOperation.POW;
import static jdk.graal.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.CBRT;
import static jdk.graal.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.COS;
import static jdk.graal.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.EXP;
import static jdk.graal.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation.LOG;
Expand Down Expand Up @@ -706,6 +707,9 @@ protected void registerMathStubs(GraalHotSpotVMConfig hotSpotVMConfig, HotSpotPr
if (hotSpotVMConfig.arithmeticTanhAddress != 0L) {
registerForeignCall(createDescriptor(TANH.foreignCallSignature, LEAF, NO_SIDE_EFFECT, NO_LOCATIONS), hotSpotVMConfig.arithmeticTanhAddress, NativeCall);
}
if (hotSpotVMConfig.arithmeticCbrtAddress != 0L) {
registerForeignCall(createDescriptor(CBRT.foreignCallSignature, LEAF, NO_SIDE_EFFECT, NO_LOCATIONS), hotSpotVMConfig.arithmeticCbrtAddress, NativeCall);
}
}

private void registerSnippetStubs(HotSpotProviders providers, OptionValues options) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ public UnimplementedGraalIntrinsics(Architecture arch) {
// HotSpot runtime does not implement C2Compiler::is_intrinsic_supported for the
// following intrinsics properly
add(ignore,
// JDK-8355644
"java/lang/Math.cbrt(D)D",
// JDK-8338694
"java/lang/Math.tanh(D)D",
// JDK-8309130
Expand Down
Loading
Loading