Skip to content

Commit 212e329

Browse files
committed
8338694: x86_64 intrinsic for tanh using libm
Reviewed-by: kvn, jbhateja, sgibbons, sviswanathan
1 parent 2669e22 commit 212e329

26 files changed

+980
-10
lines changed

src/hotspot/cpu/x86/assembler_x86.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8048,6 +8048,14 @@ void Assembler::andpd(XMMRegister dst, XMMRegister src) {
80488048
emit_int16(0x54, (0xC0 | encode));
80498049
}
80508050

8051+
void Assembler::andnpd(XMMRegister dst, XMMRegister src) {
8052+
NOT_LP64(assert(VM_Version::supports_sse2(), ""));
8053+
InstructionAttr attributes(AVX_128bit, /* rex_w */ !_legacy_mode_dq, /* legacy_mode */ _legacy_mode_dq, /* no_mask_reg */ true, /* uses_vl */ true);
8054+
attributes.set_rex_vex_w_reverted();
8055+
int encode = simd_prefix_and_encode(dst, dst, src, VEX_SIMD_66, VEX_OPCODE_0F, &attributes);
8056+
emit_int16(0x55, (0xC0 | encode));
8057+
}
8058+
80518059
void Assembler::andps(XMMRegister dst, XMMRegister src) {
80528060
NOT_LP64(assert(VM_Version::supports_sse(), ""));
80538061
InstructionAttr attributes(AVX_128bit, /* rex_w */ false, /* legacy_mode */ _legacy_mode_dq, /* no_mask_reg */ true, /* uses_vl */ true);

src/hotspot/cpu/x86/assembler_x86.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2631,6 +2631,7 @@ class Assembler : public AbstractAssembler {
26312631

26322632
// Bitwise Logical AND of Packed Floating-Point Values
26332633
void andpd(XMMRegister dst, XMMRegister src);
2634+
void andnpd(XMMRegister dst, XMMRegister src);
26342635
void andps(XMMRegister dst, XMMRegister src);
26352636
void vandpd(XMMRegister dst, XMMRegister nds, XMMRegister src, int vector_len);
26362637
void vandps(XMMRegister dst, XMMRegister nds, XMMRegister src, int vector_len);

src/hotspot/cpu/x86/c1_LIRGenerator_x86.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,11 @@ void LIRGenerator::do_MathIntrinsic(Intrinsic* x) {
807807
if (x->id() == vmIntrinsics::_dexp || x->id() == vmIntrinsics::_dlog ||
808808
x->id() == vmIntrinsics::_dpow || x->id() == vmIntrinsics::_dcos ||
809809
x->id() == vmIntrinsics::_dsin || x->id() == vmIntrinsics::_dtan ||
810-
x->id() == vmIntrinsics::_dlog10) {
810+
x->id() == vmIntrinsics::_dlog10
811+
#ifdef _LP64
812+
|| x->id() == vmIntrinsics::_dtanh
813+
#endif
814+
) {
811815
do_LibmIntrinsic(x);
812816
return;
813817
}
@@ -989,11 +993,17 @@ void LIRGenerator::do_LibmIntrinsic(Intrinsic* x) {
989993
break;
990994
case vmIntrinsics::_dtan:
991995
if (StubRoutines::dtan() != nullptr) {
992-
__ call_runtime_leaf(StubRoutines::dtan(), getThreadTemp(), result_reg, cc->args());
996+
__ call_runtime_leaf(StubRoutines::dtan(), getThreadTemp(), result_reg, cc->args());
993997
} else {
994998
__ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtan), getThreadTemp(), result_reg, cc->args());
995999
}
9961000
break;
1001+
case vmIntrinsics::_dtanh:
1002+
assert(StubRoutines::dtanh() != nullptr, "tanh intrinsic not found");
1003+
if (StubRoutines::dtanh() != nullptr) {
1004+
__ call_runtime_leaf(StubRoutines::dtanh(), getThreadTemp(), result_reg, cc->args());
1005+
}
1006+
break;
9971007
default: ShouldNotReachHere();
9981008
}
9991009
#endif // _LP64

src/hotspot/cpu/x86/stubGenerator_x86_64.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3573,6 +3573,9 @@ void StubGenerator::generate_libm_stubs() {
35733573
if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_dtan)) {
35743574
StubRoutines::_dtan = generate_libmTan(); // from stubGenerator_x86_64_tan.cpp
35753575
}
3576+
if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_dtanh)) {
3577+
StubRoutines::_dtanh = generate_libmTanh(); // from stubGenerator_x86_64_tanh.cpp
3578+
}
35763579
if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_dexp)) {
35773580
StubRoutines::_dexp = generate_libmExp(); // from stubGenerator_x86_64_exp.cpp
35783581
}

src/hotspot/cpu/x86/stubGenerator_x86_64.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ class StubGenerator: public StubCodeGenerator {
546546
address generate_libmSin();
547547
address generate_libmCos();
548548
address generate_libmTan();
549+
address generate_libmTanh();
549550
address generate_libmExp();
550551
address generate_libmPow();
551552
address generate_libmLog();

src/hotspot/cpu/x86/stubGenerator_x86_64_tanh.cpp

Lines changed: 502 additions & 0 deletions
Large diffs are not rendered by default.

src/hotspot/cpu/x86/templateInterpreterGenerator_x86_32.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -373,6 +373,10 @@ address TemplateInterpreterGenerator::generate_math_entry(AbstractInterpreter::M
373373
// [ lo(arg) ]
374374
// [ hi(arg) ]
375375
//
376+
if (kind == Interpreter::java_lang_math_tanh) {
377+
return nullptr;
378+
}
379+
376380
if (kind == Interpreter::java_lang_math_fmaD) {
377381
if (!UseFMA) {
378382
return nullptr; // Generate a vanilla entry

src/hotspot/cpu/x86/templateInterpreterGenerator_x86_64.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -465,6 +465,10 @@ address TemplateInterpreterGenerator::generate_math_entry(AbstractInterpreter::M
465465
} else {
466466
__ call_VM_leaf0(CAST_FROM_FN_PTR(address, SharedRuntime::dtan));
467467
}
468+
} else if (kind == Interpreter::java_lang_math_tanh) {
469+
assert(StubRoutines::dtanh() != nullptr, "not initialized");
470+
__ movdbl(xmm0, Address(rsp, wordSize));
471+
__ call(RuntimeAddress(CAST_FROM_FN_PTR(address, StubRoutines::dtanh())));
468472
} else if (kind == Interpreter::java_lang_math_abs) {
469473
assert(StubRoutines::x86::double_sign_mask() != nullptr, "not initialized");
470474
__ movdbl(xmm0, Address(rsp, wordSize));

src/hotspot/share/c1/c1_Compiler.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -167,6 +167,9 @@ bool Compiler::is_intrinsic_supported(vmIntrinsics::ID id) {
167167
case vmIntrinsics::_dsin:
168168
case vmIntrinsics::_dcos:
169169
case vmIntrinsics::_dtan:
170+
#if defined(AMD64)
171+
case vmIntrinsics::_dtanh:
172+
#endif
170173
case vmIntrinsics::_dlog:
171174
case vmIntrinsics::_dlog10:
172175
case vmIntrinsics::_dexp:

src/hotspot/share/c1/c1_GraphBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3339,6 +3339,7 @@ GraphBuilder::GraphBuilder(Compilation* compilation, IRScope* scope)
33393339
case vmIntrinsics::_dsin : // fall through
33403340
case vmIntrinsics::_dcos : // fall through
33413341
case vmIntrinsics::_dtan : // fall through
3342+
case vmIntrinsics::_dtanh : // fall through
33423343
case vmIntrinsics::_dlog : // fall through
33433344
case vmIntrinsics::_dlog10 : // fall through
33443345
case vmIntrinsics::_dexp : // fall through

0 commit comments

Comments
 (0)