From 212e32931cafe446d94219d6c3ffd92261984dff Mon Sep 17 00:00:00 2001 From: vamsi-parasa Date: Tue, 24 Sep 2024 15:11:13 +0000 Subject: [PATCH] 8338694: x86_64 intrinsic for tanh using libm Reviewed-by: kvn, jbhateja, sgibbons, sviswanathan --- src/hotspot/cpu/x86/assembler_x86.cpp | 8 + src/hotspot/cpu/x86/assembler_x86.hpp | 1 + src/hotspot/cpu/x86/c1_LIRGenerator_x86.cpp | 14 +- src/hotspot/cpu/x86/stubGenerator_x86_64.cpp | 3 + src/hotspot/cpu/x86/stubGenerator_x86_64.hpp | 1 + .../cpu/x86/stubGenerator_x86_64_tanh.cpp | 502 ++++++++++++++++++ .../templateInterpreterGenerator_x86_32.cpp | 6 +- .../templateInterpreterGenerator_x86_64.cpp | 6 +- src/hotspot/share/c1/c1_Compiler.cpp | 5 +- src/hotspot/share/c1/c1_GraphBuilder.cpp | 1 + src/hotspot/share/c1/c1_LIRGenerator.cpp | 1 + src/hotspot/share/c1/c1_Runtime1.cpp | 1 + src/hotspot/share/classfile/vmIntrinsics.cpp | 3 + src/hotspot/share/classfile/vmIntrinsics.hpp | 3 +- .../share/interpreter/abstractInterpreter.cpp | 3 + .../share/interpreter/abstractInterpreter.hpp | 4 +- .../templateInterpreterGenerator.cpp | 4 +- .../zero/zeroInterpreterGenerator.cpp | 4 +- src/hotspot/share/jvmci/jvmciCompilerToVM.hpp | 1 + .../share/jvmci/jvmciCompilerToVMInit.cpp | 14 + src/hotspot/share/opto/c2compiler.cpp | 1 + src/hotspot/share/opto/library_call.cpp | 4 + src/hotspot/share/runtime/stubRoutines.cpp | 1 + src/hotspot/share/runtime/stubRoutines.hpp | 2 + .../share/classes/java/lang/Math.java | 1 + test/jdk/java/lang/Math/HyperbolicTests.java | 396 +++++++++++++- 26 files changed, 980 insertions(+), 10 deletions(-) create mode 100644 src/hotspot/cpu/x86/stubGenerator_x86_64_tanh.cpp diff --git a/src/hotspot/cpu/x86/assembler_x86.cpp b/src/hotspot/cpu/x86/assembler_x86.cpp index 352cfc0018848..07476ab342f6d 100644 --- a/src/hotspot/cpu/x86/assembler_x86.cpp +++ b/src/hotspot/cpu/x86/assembler_x86.cpp @@ -8048,6 +8048,14 @@ void Assembler::andpd(XMMRegister dst, XMMRegister src) { emit_int16(0x54, (0xC0 | encode)); } +void Assembler::andnpd(XMMRegister dst, XMMRegister src) { + NOT_LP64(assert(VM_Version::supports_sse2(), "")); + InstructionAttr attributes(AVX_128bit, /* rex_w */ !_legacy_mode_dq, /* legacy_mode */ _legacy_mode_dq, /* no_mask_reg */ true, /* uses_vl */ true); + attributes.set_rex_vex_w_reverted(); + int encode = simd_prefix_and_encode(dst, dst, src, VEX_SIMD_66, VEX_OPCODE_0F, &attributes); + emit_int16(0x55, (0xC0 | encode)); +} + void Assembler::andps(XMMRegister dst, XMMRegister src) { NOT_LP64(assert(VM_Version::supports_sse(), "")); InstructionAttr attributes(AVX_128bit, /* rex_w */ false, /* legacy_mode */ _legacy_mode_dq, /* no_mask_reg */ true, /* uses_vl */ true); diff --git a/src/hotspot/cpu/x86/assembler_x86.hpp b/src/hotspot/cpu/x86/assembler_x86.hpp index 7f4790e05665e..62700d1fa1bd5 100644 --- a/src/hotspot/cpu/x86/assembler_x86.hpp +++ b/src/hotspot/cpu/x86/assembler_x86.hpp @@ -2631,6 +2631,7 @@ class Assembler : public AbstractAssembler { // Bitwise Logical AND of Packed Floating-Point Values void andpd(XMMRegister dst, XMMRegister src); + void andnpd(XMMRegister dst, XMMRegister src); void andps(XMMRegister dst, XMMRegister src); void vandpd(XMMRegister dst, XMMRegister nds, XMMRegister src, int vector_len); void vandps(XMMRegister dst, XMMRegister nds, XMMRegister src, int vector_len); diff --git a/src/hotspot/cpu/x86/c1_LIRGenerator_x86.cpp b/src/hotspot/cpu/x86/c1_LIRGenerator_x86.cpp index ff237d16d2216..36e2021138f2e 100644 --- a/src/hotspot/cpu/x86/c1_LIRGenerator_x86.cpp +++ b/src/hotspot/cpu/x86/c1_LIRGenerator_x86.cpp @@ -807,7 +807,11 @@ void LIRGenerator::do_MathIntrinsic(Intrinsic* x) { if (x->id() == vmIntrinsics::_dexp || x->id() == vmIntrinsics::_dlog || x->id() == vmIntrinsics::_dpow || x->id() == vmIntrinsics::_dcos || x->id() == vmIntrinsics::_dsin || x->id() == vmIntrinsics::_dtan || - x->id() == vmIntrinsics::_dlog10) { + x->id() == vmIntrinsics::_dlog10 +#ifdef _LP64 + || x->id() == vmIntrinsics::_dtanh +#endif + ) { do_LibmIntrinsic(x); return; } @@ -989,11 +993,17 @@ void LIRGenerator::do_LibmIntrinsic(Intrinsic* x) { break; case vmIntrinsics::_dtan: if (StubRoutines::dtan() != nullptr) { - __ call_runtime_leaf(StubRoutines::dtan(), getThreadTemp(), result_reg, cc->args()); + __ call_runtime_leaf(StubRoutines::dtan(), getThreadTemp(), result_reg, cc->args()); } else { __ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtan), getThreadTemp(), result_reg, cc->args()); } break; + case vmIntrinsics::_dtanh: + assert(StubRoutines::dtanh() != nullptr, "tanh intrinsic not found"); + if (StubRoutines::dtanh() != nullptr) { + __ call_runtime_leaf(StubRoutines::dtanh(), getThreadTemp(), result_reg, cc->args()); + } + break; default: ShouldNotReachHere(); } #endif // _LP64 diff --git a/src/hotspot/cpu/x86/stubGenerator_x86_64.cpp b/src/hotspot/cpu/x86/stubGenerator_x86_64.cpp index 2bc4a0a9cba94..4f37dc31d0305 100644 --- a/src/hotspot/cpu/x86/stubGenerator_x86_64.cpp +++ b/src/hotspot/cpu/x86/stubGenerator_x86_64.cpp @@ -3573,6 +3573,9 @@ void StubGenerator::generate_libm_stubs() { if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_dtan)) { StubRoutines::_dtan = generate_libmTan(); // from stubGenerator_x86_64_tan.cpp } + if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_dtanh)) { + StubRoutines::_dtanh = generate_libmTanh(); // from stubGenerator_x86_64_tanh.cpp + } if (vmIntrinsics::is_intrinsic_available(vmIntrinsics::_dexp)) { StubRoutines::_dexp = generate_libmExp(); // from stubGenerator_x86_64_exp.cpp } diff --git a/src/hotspot/cpu/x86/stubGenerator_x86_64.hpp b/src/hotspot/cpu/x86/stubGenerator_x86_64.hpp index d65c681585d6d..0a81da4f7c957 100644 --- a/src/hotspot/cpu/x86/stubGenerator_x86_64.hpp +++ b/src/hotspot/cpu/x86/stubGenerator_x86_64.hpp @@ -546,6 +546,7 @@ class StubGenerator: public StubCodeGenerator { address generate_libmSin(); address generate_libmCos(); address generate_libmTan(); + address generate_libmTanh(); address generate_libmExp(); address generate_libmPow(); address generate_libmLog(); diff --git a/src/hotspot/cpu/x86/stubGenerator_x86_64_tanh.cpp b/src/hotspot/cpu/x86/stubGenerator_x86_64_tanh.cpp new file mode 100644 index 0000000000000..92ac78e15cba9 --- /dev/null +++ b/src/hotspot/cpu/x86/stubGenerator_x86_64_tanh.cpp @@ -0,0 +1,502 @@ +/* +* Copyright (c) 2024, Intel Corporation. All rights reserved. +* Intel Math Library (LIBM) Source Code +* +* 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. +* +*/ + +#include "precompiled.hpp" +#include "macroAssembler_x86.hpp" +#include "stubGenerator_x86_64.hpp" + +/******************************************************************************/ +// ALGORITHM DESCRIPTION +// --------------------- +// +// tanh(x)=(exp(x)-exp(-x))/(exp(x)+exp(-x))=(1-exp(-2*x))/(1+exp(-2*x)) +// +// Let |x|=xH+xL (upper 26 bits, lower 27 bits) +// log2(e) rounded to 26 bits (high part) plus a double precision low part is +// L2EH+L2EL (upper 26, lower 53 bits) +// +// Let xH*L2EH=k+f+r`, where (k+f)*2^8*2=int(xH*L2EH*2^9), +// f=0.b1 b2 ... b8, k integer +// 2^{-f} is approximated as Tn[f]+Dn[f] +// Tn stores the high 53 bits, Dn stores (2^{-f}-Tn[f]) rounded to double precision +// +// r=r`+xL*L2EH+|x|*L2EL, |r|<2^{-9}+2^{-14}, +// for |x| in [23/64,3*2^7) +// e^{-2*|x|}=2^{-k-f}*2^{-r} ~ 2^{-k}*(Tn+Dn)*(1+p)=(T0+D0)*(1+p) +// +// For |x| in [2^{-4},2^5): +// 2^{-r}-1 ~ p=c1*r+c2*r^2+..+c5*r^5 +// Let R=1/(1+T0+p*T0), truncated to 35 significant bits +// R=1/(1+T0+D0+p*(T0+D0))*(1+eps), |eps|<2^{-33} +// 1+T0+D0+p*(T0+D0)=KH+KL, where +// KH=(1+T0+c1*r*T0)_high (leading 17 bits) +// KL=T0_low+D0+(c1*r*T0)_low+c1*r*D0+(c2*r^2+..c5*r^5)*T0 +// eps ~ (R*KH-1)+R*KL +// 1/(1+T0+D0+p*(T0+D0)) ~ R-R*eps +// The result is approximated as (1-T0-D0-(T0+D0)*p)*(R-R*eps) +// 1-T0-D0-(T0+D0)*p=-((KH-2)+KL) +// The result is formed as +// (KH-2)*R+(-(KH-2)*R*eps+(KL*R-KL*R*eps)), with the correct sign +// set at the end +// +// For |x| in [2^{-64},2^{-4}): +// A Taylor series expansion is used (x+p3*x^3+..+p13*x^{13}) +// +// For |x|<2^{-64}: x is returned +// +// For |x|>=2^32: return +/-1 +// +// Special cases: +// tanh(NaN) = quiet NaN, and raise invalid exception +// tanh(INF) = that INF +// tanh(+/-0) = +/-0 +// +/******************************************************************************/ + +ATTRIBUTE_ALIGNED(4) static const juint _HALFMASK[] = +{ + 4160749568, 2147483647 +}; + +ATTRIBUTE_ALIGNED(4) static const juint _ONEMASK[] = +{ + 0, 1072693248 +}; + +ATTRIBUTE_ALIGNED(4) static const juint _TWOMASK[] = +{ + 0, 1073741824 +}; + +ATTRIBUTE_ALIGNED(16) static const juint _MASK3[] = +{ + 0, 4294967280, 0, 4294967280 +}; + +ATTRIBUTE_ALIGNED(16) static const juint _RMASK[] = +{ + 4294705152, 4294967295, 4294705152, 4294967295 +}; + +ATTRIBUTE_ALIGNED(16) static const juint _L2E[] = +{ + 1610612736, 1082594631, 4166901572, 1055174155 +}; + +ATTRIBUTE_ALIGNED(16) static const juint _Shifter[] = +{ + 0, 1127743488, 0, 3275227136 +}; + +ATTRIBUTE_ALIGNED(16) static const juint _cv[] = +{ + 3884607281, 3168131199, 3607404735, 3190582024, 1874480759, + 1032041131, 4286760334, 1053736893, 4277811695, 3211144770, + 0, 0 +}; + +ATTRIBUTE_ALIGNED(4) static const juint _pv[] = +{ + 236289503, 1064135997, 463583772, 3215696314, 1441186365, + 3212977891, 286331153, 1069617425, 2284589306, 1066820852, + 1431655765, 3218429269 +}; + +ATTRIBUTE_ALIGNED(16) static const juint _T2_neg_f[] = +{ + 0, 1072693248, 0, 0, 1797923801, 1072687577, + 1950547427, 1013229059, 730821105, 1072681922, 2523232743, 1012067188, + 915592468, 1072676282, 352947894, 3161024371, 2174652632, 1072670657, + 4087714590, 1014450259, 35929225, 1072665048, 2809788041, 3159436968, + 2912730644, 1072659453, 3490067722, 3163405074, 2038973688, 1072653874, + 892941374, 1016046459, 1533953344, 1072648310, 769171851, 1015665633, + 1222472308, 1072642761, 1054357470, 3161021018, 929806999, 1072637227, + 3205336643, 1015259557, 481706282, 1072631708, 1696079173, 3162710528, + 3999357479, 1072626203, 2258941616, 1015924724, 2719515920, 1072620714, + 2760332941, 1015137933, 764307441, 1072615240, 3021057420, 3163329523, + 2256325230, 1072609780, 580117746, 1015317295, 2728693978, 1072604335, + 396109971, 3163462691, 2009970496, 1072598905, 2159039665, 3162572948, + 4224142467, 1072593489, 3389820386, 1015207202, 610758006, 1072588089, + 1965209397, 3161866232, 3884662774, 1072582702, 2158611599, 1014210185, + 991358482, 1072577331, 838715019, 3163157668, 351641897, 1072571974, + 2172261526, 3163010599, 1796832535, 1072566631, 3176955716, 3160585513, + 863738719, 1072561303, 1326992220, 3162613197, 1679558232, 1072555989, + 2390342287, 3163333970, 4076975200, 1072550689, 2029000899, 1015208535, + 3594158869, 1072545404, 2456521700, 3163256561, 64696965, 1072540134, + 1768797490, 1015816960, 1912561781, 1072534877, 3147495102, 1015678253, + 382305176, 1072529635, 2347622376, 3162578625, 3898795731, 1072524406, + 1249994144, 1011869818, 3707479175, 1072519192, 3613079303, 1014164738, + 3939148246, 1072513992, 3210352148, 1015274323, 135105010, 1072508807, + 1906148728, 3163375739, 721996136, 1072503635, 563754734, 1015371318, + 1242007932, 1072498477, 1132034716, 3163339831, 1532734324, 1072493333, + 3094216535, 3163162857, 1432208378, 1072488203, 1401068914, 3162363963, + 778901109, 1072483087, 2248183955, 3161268751, 3706687593, 1072477984, + 3521726940, 1013253067, 1464976603, 1072472896, 3507292405, 3161977534, + 2483480501, 1072467821, 1216371780, 1013034172, 2307442995, 1072462760, + 3190117721, 3162404539, 777507147, 1072457713, 4282924205, 1015187533, + 2029714210, 1072452679, 613660079, 1015099143, 1610600570, 1072447659, + 3766732298, 1015760183, 3657065772, 1072442652, 399025623, 3162957078, + 3716502172, 1072437659, 2303740125, 1014042725, 1631695677, 1072432680, + 2717633076, 3162344026, 1540824585, 1072427714, 1064017011, 3163487690, + 3287523847, 1072422761, 1625971539, 3157009955, 2420883922, 1072417822, + 2049810052, 1014119888, 3080351519, 1072412896, 3379126788, 3157218001, + 815859274, 1072407984, 240396590, 3163487443, 4062661092, 1072403084, + 1422616006, 3163255318, 4076559943, 1072398198, 2119478331, 3160758351, + 703710506, 1072393326, 1384660846, 1015195891, 2380618042, 1072388466, + 3149557219, 3163320799, 364333489, 1072383620, 3923737744, 3161421373, + 3092190715, 1072378786, 814012168, 3159523422, 1822067026, 1072373966, + 1241994956, 1015340290, 697153126, 1072369159, 1283515429, 3163283189, + 3861050111, 1072364364, 254893773, 3162813180, 2572866477, 1072359583, + 878562433, 1015521741, 977020788, 1072354815, 3065100517, 1015541563, + 3218338682, 1072350059, 3404164304, 3162477108, 557149882, 1072345317, + 3672720709, 1014537265, 1434058175, 1072340587, 251133233, 1015085769, + 1405169241, 1072335870, 2998539689, 3162830951, 321958744, 1072331166, + 3401933767, 1015794558, 2331271250, 1072326474, 812057446, 1012207446, + 2990417245, 1072321795, 3683467745, 3163369326, 2152073944, 1072317129, + 1486860576, 3163203456, 3964284211, 1072312475, 2111583915, 1015427164, + 3985553595, 1072307834, 4002146062, 1015834136, 2069751141, 1072303206, + 1562170675, 3162724681, 2366108318, 1072298590, 2867985102, 3161762254, + 434316067, 1072293987, 2028358766, 1013458122, 424392917, 1072289396, + 2749202995, 3162838718, 2191782032, 1072284817, 2960257726, 1013742662, + 1297350157, 1072280251, 1308022040, 3163412558, 1892288442, 1072275697, + 2446255666, 3162600381, 3833209506, 1072271155, 2722920684, 1013754842, + 2682146384, 1072266626, 2082178513, 3163363419, 2591453363, 1072262109, + 2132396182, 3159074198, 3418903055, 1072257604, 2527457337, 3160820604, + 727685349, 1072253112, 2038246809, 3162358742, 2966275557, 1072248631, + 2176155324, 3159842759, 1403662306, 1072244163, 2788809599, 3161671007, + 194117574, 1072239707, 777528612, 3163412089, 3492293770, 1072235262, + 2248032210, 1015386826, 2568320822, 1072230830, 2732824428, 1014352915, + 1577608921, 1072226410, 1875489510, 3162968394, 380978316, 1072222002, + 854188970, 3160462686, 3134592888, 1072217605, 4232266862, 1015991134, + 1110089947, 1072213221, 1451641639, 1015474673, 2759350287, 1072208848, + 1148526634, 1015894933, 3649726105, 1072204487, 4085036346, 1015649474, + 3643909174, 1072200138, 3537586109, 1014354647, 2604962541, 1072195801, + 2614425274, 3163539192, 396319521, 1072191476, 4172420816, 3159074632, + 1176749997, 1072187162, 2738998779, 3162035844, 515457527, 1072182860, + 836709333, 1015651226, 2571947539, 1072178569, 3558159064, 3163376669, + 2916157145, 1072174290, 219487565, 1015309367, 1413356050, 1072170023, + 1651349291, 3162668166, 2224145553, 1072165767, 3482522030, 3161489169, + 919555682, 1072161523, 3121969534, 1012948226, 1660913392, 1072157290, + 4218599604, 1015135707, 19972402, 1072153069, 3507899862, 1016009292, + 158781403, 1072148859, 2221464712, 3163286453, 1944781191, 1072144660, + 3993278767, 3161724279, 950803702, 1072140473, 1655364926, 1015237032, + 1339972927, 1072136297, 167908909, 1015572152, 2980802057, 1072132132, + 378619896, 1015773303, 1447192521, 1072127979, 1462857171, 3162514521, + 903334909, 1072123837, 1636462108, 1015039997, 1218806132, 1072119706, + 1818613052, 3162548441, 2263535754, 1072115586, 752233586, 3162639008, + 3907805044, 1072111477, 2257091225, 3161550407, 1727278727, 1072107380, + 3562710623, 1011471940, 4182873220, 1072103293, 629542646, 3161996303, + 2555984613, 1072099218, 2652555442, 3162552692, 1013258799, 1072095154, + 1748797611, 3160129082, 3721688645, 1072091100, 3069276937, 1015839401, + 1963711167, 1072087058, 1744767757, 3160574294, 4201977662, 1072083026, + 748330254, 1013594357, 1719614413, 1072079006, 330458198, 3163282740, + 2979960120, 1072074996, 2599109725, 1014498493, 3561793907, 1072070997, + 1157054053, 1011890350, 3339203574, 1072067009, 1483497780, 3162408754, + 2186617381, 1072063032, 2270764084, 3163272713, 4273770423, 1072059065, + 3383180809, 3163218901, 885834528, 1072055110, 1973258547, 3162261564, + 488188413, 1072051165, 3199821029, 1015564048, 2956612997, 1072047230, + 2118169751, 3162735553, 3872257780, 1072043306, 1253592103, 1015958334, + 3111574537, 1072039393, 2606161479, 3162759746, 551349105, 1072035491, + 3821916050, 3162106589, 363667784, 1072031599, 813753950, 1015785209, + 2425981843, 1072027717, 2830390851, 3163346599, 2321106615, 1072023846, + 2171176610, 1009535771, 4222122499, 1072019985, 1277378074, 3163256737, + 3712504873, 1072016135, 88491949, 1015427660, 671025100, 1072012296, + 3832014351, 3163022030, 3566716925, 1072008466, 1536826856, 1014142433, + 3689071823, 1072004647, 2321004996, 3162552716, 917841882, 1072000839, + 18715565, 1015659308, 3723038930, 1071997040, 378465264, 3162569582, + 3395129871, 1071993252, 4025345435, 3162335388, 4109806887, 1071989474, + 422403966, 1014469229, 1453150082, 1071985707, 498154669, 3161488062, + 3896463087, 1071981949, 1139797873, 3161233805, 2731501122, 1071978202, + 1774031855, 3162470021, 2135241198, 1071974465, 1236747871, 1013589147, + 1990012071, 1071970738, 3529070563, 3162813193, 2178460671, 1071967021, + 777878098, 3162842493, 2583551245, 1071963314, 3161094195, 1015606491, + 3088564500, 1071959617, 1762311517, 1015045673, 3577096743, 1071955930, + 2951496418, 1013793687, 3933059031, 1071952253, 2133366768, 3161531832, + 4040676318, 1071948586, 4090609238, 1015663458, 3784486610, 1071944929, + 1581883040, 3161698953, 3049340112, 1071941282, 3062915824, 1013170595, + 1720398391, 1071937645, 3980678963, 3163300080, 3978100823, 1071934017, + 3513027190, 1015845963, 1118294578, 1071930400, 2197495694, 3159909401, + 1617004845, 1071926792, 82804944, 1010342778, 1065662932, 1071923194, + 2533670915, 1014530238, 3645941911, 1071919605, 3814685081, 3161573341, + 654919306, 1071916027, 3232961757, 3163047469, 569847338, 1071912458, + 472945272, 3159290729, 3278348324, 1071908898, 3069497416, 1014750712, + 78413852, 1071905349, 4183226867, 3163017251, 3743175029, 1071901808, + 2072812490, 3162175075, 1276261410, 1071898278, 300981948, 1014684169, + 1156440435, 1071894757, 2351451249, 1013967056, 3272845541, 1071891245, + 928852419, 3163488248, 3219942644, 1071887743, 3798990616, 1015368806, + 887463927, 1071884251, 3596744163, 3160794166, 460407023, 1071880768, + 4237175092, 3163138469, 1829099622, 1071877294, 1016661181, 3163461005, + 589198666, 1071873830, 2664346172, 3163157962, 926591435, 1071870375, + 3208833762, 3162913514, 2732492859, 1071866929, 2691479646, 3162255684, + 1603444721, 1071863493, 1548633640, 3162201326, 1726216749, 1071860066, + 2466808228, 3161676405, 2992903935, 1071856648, 2218154406, 1015228193, + 1000925746, 1071853240, 1018491672, 3163309544, 4232894513, 1071849840, + 2383938684, 1014668519, 3991843581, 1071846450, 4092853457, 1014585763, + 171030293, 1071843070, 3526460132, 1014428778, 1253935211, 1071839698, + 1395382931, 3159702613, 2839424854, 1071836335, 1171596163, 1013041679, + 526652809, 1071832982, 4223459736, 1015879375, 2799960843, 1071829637, + 1423655381, 1015022151, 964107055, 1071826302, 2800439588, 3162833221, + 3504003472, 1071822975, 3594001060, 3157330652, 1724976915, 1071819658, + 420909223, 3163117379, 4112506593, 1071816349, 2947355221, 1014371048, + 1972484976, 1071813050, 675290301, 3161640050, 3790955393, 1071809759, + 2352942462, 3163180090, 874372905, 1071806478, 100263788, 1015940732, + 1709341917, 1071803205, 2571168217, 1014152499, 1897844341, 1071799941, + 1254300460, 1015275938, 1337108031, 1071796686, 3203724452, 1014677845, + 4219606026, 1071793439, 2434574742, 1014681548, 1853186616, 1071790202, + 3066496371, 1015656574, 2725843665, 1071786973, 1433917087, 1014838523, + 2440944790, 1071783753, 2492769774, 1014147454, 897099801, 1071780542, + 754756297, 1015241005, 2288159958, 1071777339, 2169144469, 1014876021, + 2218315341, 1071774145, 2694295388, 3163288868, 586995997, 1071770960, + 41662348, 3162627992, 1588871207, 1071767783, 143439582, 3162963416, + 828946858, 1071764615, 10642492, 1015939438, 2502433899, 1071761455, + 2148595913, 1015023991, 2214878420, 1071758304, 892270087, 3163116422, + 4162030108, 1071755161, 2763428480, 1015529349, 3949972341, 1071752027, + 2068408548, 1014913868, 1480023343, 1071748902, 2247196168, 1015327453, + 948735466, 1071745785, 3516338028, 3162574883, 2257959872, 1071742676, + 3802946148, 1012964927, 1014845819, 1071739576, 3117910646, 3161559105, + 1416741826, 1071736484, 2196380210, 1011413563, 3366293073, 1071733400, + 3119426314, 1014120554, 2471440686, 1071730325, 968836267, 3162214888, + 2930322912, 1071727258, 2599499422, 3162714047, 351405227, 1071724200, + 3125337328, 3159822479, 3228316108, 1071721149, 3010241991, 3158422804, + 2875075254, 1071718107, 4144233330, 3163333716, 3490863953, 1071715073, + 960797498, 3162948880, 685187902, 1071712048, 378731989, 1014843115, + 2952712987, 1071709030, 3293494651, 3160120301, 1608493509, 1071706021, + 3159622171, 3162807737, 852742562, 1071703020, 667253586, 1009793559, + 590962156, 1071700027, 3829346666, 3163275597, 728909815, 1071697042, + 383930225, 1015029468, 1172597893, 1071694065, 114433263, 1015347593, + 1828292879, 1071691096, 1255956747, 1015588398, 2602514713, 1071688135, + 2268929336, 1014354284, 3402036099, 1071685182, 405889334, 1015105656, + 4133881824, 1071682237, 2148155345, 3162931299, 410360776, 1071679301, + 1269990655, 1011975870, 728934454, 1071676372, 1413842688, 1014178612, + 702412510, 1071673451, 3803266087, 3162280415, 238821257, 1071670538, + 1469694871, 3162884987, 3541402996, 1071667632, 2759177317, 1014854626, + 1928746161, 1071664735, 983617676, 1014285177, 3899555717, 1071661845, + 427280750, 3162546972, 772914124, 1071658964, 4004372762, 1012230161, + 1048019041, 1071656090, 1398474845, 3160510595, 339411585, 1071653224, + 264588982, 3161636657, 2851812149, 1071650365, 2595802551, 1015767337, + 4200250559, 1071647514, 2808127345, 3161781938 +}; + +#define __ _masm-> + +address StubGenerator::generate_libmTanh() { + StubCodeMark mark(this, "StubRoutines", "libmTanh"); + address start = __ pc(); + + Label L_2TAG_PACKET_0_0_1, L_2TAG_PACKET_1_0_1, L_2TAG_PACKET_2_0_1, L_2TAG_PACKET_3_0_1; + Label L_2TAG_PACKET_4_0_1, L_2TAG_PACKET_5_0_1; + Label B1_2, B1_4; + + address HALFMASK = (address)_HALFMASK; + address ONEMASK = (address)_ONEMASK; + address TWOMASK = (address)_TWOMASK; + address MASK3 = (address)_MASK3; + address RMASK = (address)_RMASK; + address L2E = (address)_L2E; + address Shifter = (address)_Shifter; + address cv = (address)_cv; + address pv = (address)_pv; + address T2_neg_f = (address) _T2_neg_f; + + __ enter(); // required for proper stackwalking of RuntimeStub frame + + __ bind(B1_2); + __ movsd(xmm3, ExternalAddress(HALFMASK), r11 /*rscratch*/); + __ xorpd(xmm4, xmm4); + __ movsd(xmm1, ExternalAddress(L2E), r11 /*rscratch*/); + __ movsd(xmm2, ExternalAddress(L2E + 8), r11 /*rscratch*/); + __ movl(rax, 32768); + __ pinsrw(xmm4, rax, 3); + __ movsd(xmm6, ExternalAddress(Shifter), r11 /*rscratch*/); + __ pextrw(rcx, xmm0, 3); + __ andpd(xmm3, xmm0); + __ andnpd(xmm4, xmm0); + __ pshufd(xmm5, xmm4, 68); + __ movl(rdx, 32768); + __ andl(rdx, rcx); + __ andl(rcx, 32767); + __ subl(rcx, 16304); + __ cmpl(rcx, 144); + __ jcc(Assembler::aboveEqual, L_2TAG_PACKET_0_0_1); + __ subsd(xmm4, xmm3); + __ mulsd(xmm3, xmm1); + __ mulsd(xmm2, xmm5); + __ cvtsd2siq(rax, xmm3); + __ movq(xmm7, xmm3); + __ addsd(xmm3, xmm6); + __ mulsd(xmm1, xmm4); + __ movsd(xmm4, ExternalAddress(ONEMASK), r11 /*rscratch*/); + __ subsd(xmm3, xmm6); + __ xorpd(xmm0, xmm0); + __ addsd(xmm2, xmm1); + __ subsd(xmm7, xmm3); + __ movdqu(xmm6, ExternalAddress(cv), r11 /*rscratch*/); + __ addsd(xmm2, xmm7); + __ movl(rcx, 255); + __ andl(rcx, rax); + __ addl(rcx, rcx); + __ lea(r8, ExternalAddress(T2_neg_f)); + __ movdqu(xmm5, Address(r8, rcx, Address::times(8))); + __ shrl(rax, 4); + __ andl(rax, 65520); + __ subl(rax, 16368); + __ negl(rax); + __ pinsrw(xmm0, rax, 3); + __ movdqu(xmm1, ExternalAddress(cv + 16), r11 /*rscratch*/); + __ pshufd(xmm0, xmm0, 68); + __ mulpd(xmm0, xmm5); + __ movsd(xmm7, ExternalAddress(cv + 32), r11 /*rscratch*/); + __ pshufd(xmm2, xmm2, 68); + __ movq(xmm5, xmm4); + __ addsd(xmm4, xmm0); + __ mulpd(xmm6, xmm2); + __ mulsd(xmm7, xmm2); + __ mulpd(xmm2, xmm2); + __ addpd(xmm1, xmm6); + __ mulsd(xmm2, xmm2); + __ movsd(xmm3, ExternalAddress(ONEMASK), r11 /*rscratch*/); + __ mulpd(xmm1, xmm2); + __ pshufd(xmm6, xmm1, 78); + __ addsd(xmm1, xmm6); + __ movq(xmm6, xmm1); + __ addsd(xmm1, xmm7); + __ mulsd(xmm1, xmm0); + __ addsd(xmm1, xmm4); + __ andpd(xmm4, ExternalAddress(MASK3), r11 /*rscratch*/); + __ divsd(xmm5, xmm1); + __ subsd(xmm3, xmm4); + __ pshufd(xmm1, xmm0, 238); + __ addsd(xmm3, xmm0); + __ movq(xmm2, xmm4); + __ addsd(xmm3, xmm1); + __ mulsd(xmm1, xmm7); + __ mulsd(xmm7, xmm0); + __ addsd(xmm3, xmm1); + __ addsd(xmm4, xmm7); + __ movsd(xmm1, ExternalAddress(RMASK), r11 /*rscratch*/); + __ mulsd(xmm6, xmm0); + __ andpd(xmm4, ExternalAddress(MASK3), r11 /*rscratch*/); + __ addsd(xmm3, xmm6); + __ movq(xmm6, xmm4); + __ subsd(xmm2, xmm4); + __ addsd(xmm2, xmm7); + __ movsd(xmm7, ExternalAddress(ONEMASK), r11 /*rscratch*/); + __ andpd(xmm5, xmm1); + __ addsd(xmm3, xmm2); + __ mulsd(xmm4, xmm5); + __ xorpd(xmm2, xmm2); + __ mulsd(xmm3, xmm5); + __ subsd(xmm6, ExternalAddress(TWOMASK), r11 /*rscratch*/); + __ subsd(xmm4, xmm7); + __ xorl(rdx, 32768); + __ pinsrw(xmm2, rdx, 3); + __ addsd(xmm4, xmm3); + __ mulsd(xmm6, xmm5); + __ movq(xmm1, xmm3); + __ mulsd(xmm3, xmm4); + __ movq(xmm0, xmm6); + __ mulsd(xmm6, xmm4); + __ subsd(xmm1, xmm3); + __ subsd(xmm1, xmm6); + __ addsd(xmm0, xmm1); + __ xorpd(xmm0, xmm2); + __ jmp(B1_4); + + __ bind(L_2TAG_PACKET_0_0_1); + __ addl(rcx, 960); + __ cmpl(rcx, 1104); + __ jcc(Assembler::aboveEqual, L_2TAG_PACKET_1_0_1); + __ movdqu(xmm2, ExternalAddress(pv), r11 /*rscratch*/); + __ pshufd(xmm1, xmm0, 68); + __ movdqu(xmm3, ExternalAddress(pv + 16), r11 /*rscratch*/); + __ mulpd(xmm1, xmm1); + __ movdqu(xmm4, ExternalAddress(pv + 32), r11 /*rscratch*/); + __ mulpd(xmm2, xmm1); + __ pshufd(xmm5, xmm1, 68); + __ addpd(xmm2, xmm3); + __ mulsd(xmm5, xmm5); + __ mulpd(xmm2, xmm1); + __ mulsd(xmm5, xmm5); + __ addpd(xmm2, xmm4); + __ mulpd(xmm2, xmm5); + __ pshufd(xmm5, xmm2, 238); + __ addsd(xmm2, xmm5); + __ mulsd(xmm2, xmm0); + __ addsd(xmm0, xmm2); + __ jmp(B1_4); + + __ bind(L_2TAG_PACKET_1_0_1); + __ addl(rcx, 15344); + __ cmpl(rcx, 16448); + __ jcc(Assembler::aboveEqual, L_2TAG_PACKET_2_0_1); + __ cmpl(rcx, 16); + __ jcc(Assembler::below, L_2TAG_PACKET_3_0_1); + __ xorpd(xmm2, xmm2); + __ movl(rax, 17392); + __ pinsrw(xmm2, rax, 3); + __ mulsd(xmm2, xmm0); + __ addsd(xmm2, xmm0); + __ jmp(B1_4); + + __ bind(L_2TAG_PACKET_3_0_1); + __ movq(xmm2, xmm0); + __ mulsd(xmm2, xmm2); + __ jmp(B1_4); + + __ bind(L_2TAG_PACKET_2_0_1); + __ cmpl(rcx, 32752); + __ jcc(Assembler::aboveEqual, L_2TAG_PACKET_4_0_1); + __ xorpd(xmm2, xmm2); + __ movl(rcx, 15344); + __ pinsrw(xmm2, rcx, 3); + __ movq(xmm3, xmm2); + __ mulsd(xmm2, xmm2); + __ addsd(xmm2, xmm3); + + __ bind(L_2TAG_PACKET_5_0_1); + __ xorpd(xmm0, xmm0); + __ orl(rdx, 16368); + __ pinsrw(xmm0, rdx, 3); + __ jmp(B1_4); + + __ bind(L_2TAG_PACKET_4_0_1); + __ movq(xmm2, xmm0); + __ movdl(rax, xmm0); + __ psrlq(xmm2, 20); + __ movdl(rcx, xmm2); + __ orl(rcx, rax); + __ cmpl(rcx, 0); + __ jcc(Assembler::equal, L_2TAG_PACKET_5_0_1); + __ addsd(xmm0, xmm0); + + __ bind(B1_4); + __ leave(); // required for proper stackwalking of RuntimeStub frame + __ ret(0); + + return start; +} + +#undef __ diff --git a/src/hotspot/cpu/x86/templateInterpreterGenerator_x86_32.cpp b/src/hotspot/cpu/x86/templateInterpreterGenerator_x86_32.cpp index ba9eb32e8c13e..75611524e3b0a 100644 --- a/src/hotspot/cpu/x86/templateInterpreterGenerator_x86_32.cpp +++ b/src/hotspot/cpu/x86/templateInterpreterGenerator_x86_32.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2024, 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 @@ -373,6 +373,10 @@ address TemplateInterpreterGenerator::generate_math_entry(AbstractInterpreter::M // [ lo(arg) ] // [ hi(arg) ] // + if (kind == Interpreter::java_lang_math_tanh) { + return nullptr; + } + if (kind == Interpreter::java_lang_math_fmaD) { if (!UseFMA) { return nullptr; // Generate a vanilla entry diff --git a/src/hotspot/cpu/x86/templateInterpreterGenerator_x86_64.cpp b/src/hotspot/cpu/x86/templateInterpreterGenerator_x86_64.cpp index 26eea4c1d6a5f..5ea2d8eba259b 100644 --- a/src/hotspot/cpu/x86/templateInterpreterGenerator_x86_64.cpp +++ b/src/hotspot/cpu/x86/templateInterpreterGenerator_x86_64.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2024, 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 @@ -465,6 +465,10 @@ address TemplateInterpreterGenerator::generate_math_entry(AbstractInterpreter::M } else { __ call_VM_leaf0(CAST_FROM_FN_PTR(address, SharedRuntime::dtan)); } + } else if (kind == Interpreter::java_lang_math_tanh) { + assert(StubRoutines::dtanh() != nullptr, "not initialized"); + __ movdbl(xmm0, Address(rsp, wordSize)); + __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, StubRoutines::dtanh()))); } else if (kind == Interpreter::java_lang_math_abs) { assert(StubRoutines::x86::double_sign_mask() != nullptr, "not initialized"); __ movdbl(xmm0, Address(rsp, wordSize)); diff --git a/src/hotspot/share/c1/c1_Compiler.cpp b/src/hotspot/share/c1/c1_Compiler.cpp index e1c4e90d0637d..a0944c864e68f 100644 --- a/src/hotspot/share/c1/c1_Compiler.cpp +++ b/src/hotspot/share/c1/c1_Compiler.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2024, 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 @@ -167,6 +167,9 @@ bool Compiler::is_intrinsic_supported(vmIntrinsics::ID id) { case vmIntrinsics::_dsin: case vmIntrinsics::_dcos: case vmIntrinsics::_dtan: + #if defined(AMD64) + case vmIntrinsics::_dtanh: + #endif case vmIntrinsics::_dlog: case vmIntrinsics::_dlog10: case vmIntrinsics::_dexp: diff --git a/src/hotspot/share/c1/c1_GraphBuilder.cpp b/src/hotspot/share/c1/c1_GraphBuilder.cpp index a2e903edc342f..02be6f8d49e4a 100644 --- a/src/hotspot/share/c1/c1_GraphBuilder.cpp +++ b/src/hotspot/share/c1/c1_GraphBuilder.cpp @@ -3339,6 +3339,7 @@ GraphBuilder::GraphBuilder(Compilation* compilation, IRScope* scope) case vmIntrinsics::_dsin : // fall through case vmIntrinsics::_dcos : // fall through case vmIntrinsics::_dtan : // fall through + case vmIntrinsics::_dtanh : // fall through case vmIntrinsics::_dlog : // fall through case vmIntrinsics::_dlog10 : // fall through case vmIntrinsics::_dexp : // fall through diff --git a/src/hotspot/share/c1/c1_LIRGenerator.cpp b/src/hotspot/share/c1/c1_LIRGenerator.cpp index 4e63736503fe0..74fdf7a5b76a3 100644 --- a/src/hotspot/share/c1/c1_LIRGenerator.cpp +++ b/src/hotspot/share/c1/c1_LIRGenerator.cpp @@ -2971,6 +2971,7 @@ void LIRGenerator::do_Intrinsic(Intrinsic* x) { case vmIntrinsics::_dsqrt: // fall through case vmIntrinsics::_dsqrt_strict: // fall through case vmIntrinsics::_dtan: // fall through + case vmIntrinsics::_dtanh: // fall through case vmIntrinsics::_dsin : // fall through case vmIntrinsics::_dcos : // fall through case vmIntrinsics::_dexp : // fall through diff --git a/src/hotspot/share/c1/c1_Runtime1.cpp b/src/hotspot/share/c1/c1_Runtime1.cpp index 5b44d5c0f1983..915f00f77c523 100644 --- a/src/hotspot/share/c1/c1_Runtime1.cpp +++ b/src/hotspot/share/c1/c1_Runtime1.cpp @@ -347,6 +347,7 @@ const char* Runtime1::name_for_address(address entry) { FUNCTION_CASE(entry, StubRoutines::dsin()); FUNCTION_CASE(entry, StubRoutines::dcos()); FUNCTION_CASE(entry, StubRoutines::dtan()); + FUNCTION_CASE(entry, StubRoutines::dtanh()); #undef FUNCTION_CASE diff --git a/src/hotspot/share/classfile/vmIntrinsics.cpp b/src/hotspot/share/classfile/vmIntrinsics.cpp index b470eb9b8380d..5e352e42efbc1 100644 --- a/src/hotspot/share/classfile/vmIntrinsics.cpp +++ b/src/hotspot/share/classfile/vmIntrinsics.cpp @@ -90,6 +90,7 @@ bool vmIntrinsics::preserves_state(vmIntrinsics::ID id) { case vmIntrinsics::_dsin: case vmIntrinsics::_dcos: case vmIntrinsics::_dtan: + case vmIntrinsics::_dtanh: case vmIntrinsics::_dlog: case vmIntrinsics::_dlog10: case vmIntrinsics::_dexp: @@ -141,6 +142,7 @@ bool vmIntrinsics::can_trap(vmIntrinsics::ID id) { case vmIntrinsics::_dsin: case vmIntrinsics::_dcos: case vmIntrinsics::_dtan: + case vmIntrinsics::_dtanh: case vmIntrinsics::_dlog: case vmIntrinsics::_dlog10: case vmIntrinsics::_dexp: @@ -288,6 +290,7 @@ bool vmIntrinsics::disabled_by_jvm_flags(vmIntrinsics::ID id) { case vmIntrinsics::_dsin: case vmIntrinsics::_dcos: case vmIntrinsics::_dtan: + case vmIntrinsics::_dtanh: case vmIntrinsics::_dlog: case vmIntrinsics::_dexp: case vmIntrinsics::_dpow: diff --git a/src/hotspot/share/classfile/vmIntrinsics.hpp b/src/hotspot/share/classfile/vmIntrinsics.hpp index 4b772c171d5a6..af1c2b31a9809 100644 --- a/src/hotspot/share/classfile/vmIntrinsics.hpp +++ b/src/hotspot/share/classfile/vmIntrinsics.hpp @@ -135,7 +135,7 @@ class methodHandle; do_name(log_name,"log") do_name(log10_name,"log10") do_name(pow_name,"pow") \ do_name(exp_name,"exp") do_name(min_name,"min") do_name(max_name,"max") \ do_name(floor_name, "floor") do_name(ceil_name, "ceil") do_name(rint_name, "rint") \ - do_name(round_name, "round") \ + do_name(round_name, "round") do_name(tanh_name,"tanh") \ \ do_name(addExact_name,"addExact") \ do_name(decrementExact_name,"decrementExact") \ @@ -161,6 +161,7 @@ class methodHandle; do_intrinsic(_dcos, java_lang_Math, cos_name, double_double_signature, F_S) \ do_intrinsic(_dtan, java_lang_Math, tan_name, double_double_signature, F_S) \ do_intrinsic(_datan2, java_lang_Math, atan2_name, double2_double_signature, F_S) \ + do_intrinsic(_dtanh, java_lang_Math, tanh_name, double_double_signature, F_S) \ do_intrinsic(_dsqrt, java_lang_Math, sqrt_name, double_double_signature, F_S) \ do_intrinsic(_dlog, java_lang_Math, log_name, double_double_signature, F_S) \ do_intrinsic(_dlog10, java_lang_Math, log10_name, double_double_signature, F_S) \ diff --git a/src/hotspot/share/interpreter/abstractInterpreter.cpp b/src/hotspot/share/interpreter/abstractInterpreter.cpp index 2fad5ba39ef5c..9d72f9ba0edec 100644 --- a/src/hotspot/share/interpreter/abstractInterpreter.cpp +++ b/src/hotspot/share/interpreter/abstractInterpreter.cpp @@ -138,6 +138,7 @@ AbstractInterpreter::MethodKind AbstractInterpreter::method_kind(const methodHan case vmIntrinsics::_dsin: return java_lang_math_sin; case vmIntrinsics::_dcos: return java_lang_math_cos; case vmIntrinsics::_dtan: return java_lang_math_tan; + case vmIntrinsics::_dtanh: return java_lang_math_tanh; case vmIntrinsics::_dabs: return java_lang_math_abs; case vmIntrinsics::_dlog: return java_lang_math_log; case vmIntrinsics::_dlog10: return java_lang_math_log10; @@ -198,6 +199,7 @@ vmIntrinsics::ID AbstractInterpreter::method_intrinsic(MethodKind kind) { case java_lang_math_sin : return vmIntrinsics::_dsin; case java_lang_math_cos : return vmIntrinsics::_dcos; case java_lang_math_tan : return vmIntrinsics::_dtan; + case java_lang_math_tanh : return vmIntrinsics::_dtanh; case java_lang_math_abs : return vmIntrinsics::_dabs; case java_lang_math_log : return vmIntrinsics::_dlog; case java_lang_math_log10 : return vmIntrinsics::_dlog10; @@ -309,6 +311,7 @@ void AbstractInterpreter::print_method_kind(MethodKind kind) { case java_lang_math_sin : tty->print("java_lang_math_sin" ); break; case java_lang_math_cos : tty->print("java_lang_math_cos" ); break; case java_lang_math_tan : tty->print("java_lang_math_tan" ); break; + case java_lang_math_tanh : tty->print("java_lang_math_tanh" ); break; case java_lang_math_abs : tty->print("java_lang_math_abs" ); break; case java_lang_math_log : tty->print("java_lang_math_log" ); break; case java_lang_math_log10 : tty->print("java_lang_math_log10" ); break; diff --git a/src/hotspot/share/interpreter/abstractInterpreter.hpp b/src/hotspot/share/interpreter/abstractInterpreter.hpp index e487b152b76ea..790706c2de3cd 100644 --- a/src/hotspot/share/interpreter/abstractInterpreter.hpp +++ b/src/hotspot/share/interpreter/abstractInterpreter.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2024, 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 @@ -72,6 +72,7 @@ class AbstractInterpreter: AllStatic { java_lang_math_sin, // implementation of java.lang.Math.sin (x) java_lang_math_cos, // implementation of java.lang.Math.cos (x) java_lang_math_tan, // implementation of java.lang.Math.tan (x) + java_lang_math_tanh, // implementation of java.lang.Math.tanh (x) java_lang_math_abs, // implementation of java.lang.Math.abs (x) java_lang_math_sqrt, // implementation of java.lang.Math.sqrt (x) java_lang_math_sqrt_strict, // implementation of java.lang.StrictMath.sqrt(x) @@ -151,6 +152,7 @@ class AbstractInterpreter: AllStatic { case vmIntrinsics::_dsin : // fall thru case vmIntrinsics::_dcos : // fall thru case vmIntrinsics::_dtan : // fall thru + case vmIntrinsics::_dtanh : // fall thru case vmIntrinsics::_dabs : // fall thru case vmIntrinsics::_dsqrt : // fall thru case vmIntrinsics::_dsqrt_strict : // fall thru diff --git a/src/hotspot/share/interpreter/templateInterpreterGenerator.cpp b/src/hotspot/share/interpreter/templateInterpreterGenerator.cpp index 9cd6f5ceffbe9..3f497c3360b7e 100644 --- a/src/hotspot/share/interpreter/templateInterpreterGenerator.cpp +++ b/src/hotspot/share/interpreter/templateInterpreterGenerator.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2024, 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 @@ -192,6 +192,7 @@ void TemplateInterpreterGenerator::generate_all() { method_entry(java_lang_math_sin ) method_entry(java_lang_math_cos ) method_entry(java_lang_math_tan ) + method_entry(java_lang_math_tanh ) method_entry(java_lang_math_abs ) method_entry(java_lang_math_sqrt ) method_entry(java_lang_math_sqrt_strict) @@ -457,6 +458,7 @@ address TemplateInterpreterGenerator::generate_intrinsic_entry(AbstractInterpret case Interpreter::java_lang_math_sin : // fall thru case Interpreter::java_lang_math_cos : // fall thru case Interpreter::java_lang_math_tan : // fall thru + case Interpreter::java_lang_math_tanh : // fall thru case Interpreter::java_lang_math_abs : // fall thru case Interpreter::java_lang_math_log : // fall thru case Interpreter::java_lang_math_log10 : // fall thru diff --git a/src/hotspot/share/interpreter/zero/zeroInterpreterGenerator.cpp b/src/hotspot/share/interpreter/zero/zeroInterpreterGenerator.cpp index e08d9553c3e07..27ea1b9706719 100644 --- a/src/hotspot/share/interpreter/zero/zeroInterpreterGenerator.cpp +++ b/src/hotspot/share/interpreter/zero/zeroInterpreterGenerator.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved. * Copyright 2007, 2008, 2009, 2010, 2011 Red Hat, Inc. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -54,6 +54,7 @@ void ZeroInterpreterGenerator::generate_all() { method_entry(java_lang_math_sin ); method_entry(java_lang_math_cos ); method_entry(java_lang_math_tan ); + method_entry(java_lang_math_tanh ); method_entry(java_lang_math_abs ); method_entry(java_lang_math_sqrt ); method_entry(java_lang_math_sqrt_strict); @@ -95,6 +96,7 @@ address ZeroInterpreterGenerator::generate_method_entry( case Interpreter::java_lang_math_sin : // fall thru case Interpreter::java_lang_math_cos : // fall thru case Interpreter::java_lang_math_tan : // fall thru + case Interpreter::java_lang_math_tanh : // fall thru case Interpreter::java_lang_math_abs : // fall thru case Interpreter::java_lang_math_log : // fall thru case Interpreter::java_lang_math_log10 : // fall thru diff --git a/src/hotspot/share/jvmci/jvmciCompilerToVM.hpp b/src/hotspot/share/jvmci/jvmciCompilerToVM.hpp index fa4b1c75c0573..0773de6ddbaa0 100644 --- a/src/hotspot/share/jvmci/jvmciCompilerToVM.hpp +++ b/src/hotspot/share/jvmci/jvmciCompilerToVM.hpp @@ -116,6 +116,7 @@ class CompilerToVM { static address dsin; static address dcos; static address dtan; + static address dtanh; static address dexp; static address dlog; static address dlog10; diff --git a/src/hotspot/share/jvmci/jvmciCompilerToVMInit.cpp b/src/hotspot/share/jvmci/jvmciCompilerToVMInit.cpp index 26c88abec0f18..1612038008a32 100644 --- a/src/hotspot/share/jvmci/jvmciCompilerToVMInit.cpp +++ b/src/hotspot/share/jvmci/jvmciCompilerToVMInit.cpp @@ -135,6 +135,7 @@ int CompilerToVM::Data::sizeof_ZStoreBarrierEntry = sizeof(ZStoreBarrierEntry); address CompilerToVM::Data::dsin; address CompilerToVM::Data::dcos; address CompilerToVM::Data::dtan; +address CompilerToVM::Data::dtanh; address CompilerToVM::Data::dexp; address CompilerToVM::Data::dlog; address CompilerToVM::Data::dlog10; @@ -268,6 +269,19 @@ void CompilerToVM::Data::initialize(JVMCI_TRAPS) { SET_TRIGFUNC(dpow); #undef SET_TRIGFUNC + +#define SET_TRIGFUNC_OR_NULL(name) \ + if (StubRoutines::name() != nullptr) { \ + name = StubRoutines::name(); \ + } else { \ + name = nullptr; \ + } + + SET_TRIGFUNC_OR_NULL(dtanh); + +#undef SET_TRIGFUNC_OR_NULL + + } static jboolean is_c1_supported(vmIntrinsics::ID id){ diff --git a/src/hotspot/share/opto/c2compiler.cpp b/src/hotspot/share/opto/c2compiler.cpp index 2f087858efd48..117e06acd6f31 100644 --- a/src/hotspot/share/opto/c2compiler.cpp +++ b/src/hotspot/share/opto/c2compiler.cpp @@ -610,6 +610,7 @@ bool C2Compiler::is_intrinsic_supported(vmIntrinsics::ID id) { case vmIntrinsics::_dsin: case vmIntrinsics::_dcos: case vmIntrinsics::_dtan: + case vmIntrinsics::_dtanh: case vmIntrinsics::_dabs: case vmIntrinsics::_fabs: case vmIntrinsics::_iabs: diff --git a/src/hotspot/share/opto/library_call.cpp b/src/hotspot/share/opto/library_call.cpp index c95a450272989..8bbb2f8115ec4 100644 --- a/src/hotspot/share/opto/library_call.cpp +++ b/src/hotspot/share/opto/library_call.cpp @@ -254,6 +254,7 @@ bool LibraryCallKit::try_to_inline(int predicate) { case vmIntrinsics::_dsin: case vmIntrinsics::_dcos: case vmIntrinsics::_dtan: + case vmIntrinsics::_dtanh: case vmIntrinsics::_dabs: case vmIntrinsics::_fabs: case vmIntrinsics::_iabs: @@ -1879,6 +1880,9 @@ bool LibraryCallKit::inline_math_native(vmIntrinsics::ID id) { return StubRoutines::dtan() != nullptr ? runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dtan(), "dtan") : runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dtan), "TAN"); + case vmIntrinsics::_dtanh: + return StubRoutines::dtanh() != nullptr ? + runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dtanh(), "dtanh") : false; case vmIntrinsics::_dexp: return StubRoutines::dexp() != nullptr ? runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dexp(), "dexp") : diff --git a/src/hotspot/share/runtime/stubRoutines.cpp b/src/hotspot/share/runtime/stubRoutines.cpp index c13f64fca4bed..a2b8c1da64490 100644 --- a/src/hotspot/share/runtime/stubRoutines.cpp +++ b/src/hotspot/share/runtime/stubRoutines.cpp @@ -171,6 +171,7 @@ address StubRoutines::_dlibm_sin_cos_huge = nullptr; address StubRoutines::_dlibm_reduce_pi04l = nullptr; address StubRoutines::_dlibm_tan_cot_huge = nullptr; address StubRoutines::_dtan = nullptr; +address StubRoutines::_dtanh = nullptr; address StubRoutines::_f2hf = nullptr; address StubRoutines::_hf2f = nullptr; diff --git a/src/hotspot/share/runtime/stubRoutines.hpp b/src/hotspot/share/runtime/stubRoutines.hpp index f5b932569be81..b58c591bbf75c 100644 --- a/src/hotspot/share/runtime/stubRoutines.hpp +++ b/src/hotspot/share/runtime/stubRoutines.hpp @@ -281,6 +281,7 @@ class StubRoutines: AllStatic { static address _dlibm_reduce_pi04l; static address _dlibm_tan_cot_huge; static address _dtan; + static address _dtanh; static address _fmod; static address _f2hf; @@ -472,6 +473,7 @@ class StubRoutines: AllStatic { static address dlibm_sin_cos_huge() { return _dlibm_sin_cos_huge; } static address dlibm_tan_cot_huge() { return _dlibm_tan_cot_huge; } static address dtan() { return _dtan; } + static address dtanh() { return _dtanh; } // These are versions of the java.lang.Float::floatToFloat16() and float16ToFloat() // methods which perform the same operations as the intrinsic version. diff --git a/src/java.base/share/classes/java/lang/Math.java b/src/java.base/share/classes/java/lang/Math.java index 044982a588af8..6b576c88b4710 100644 --- a/src/java.base/share/classes/java/lang/Math.java +++ b/src/java.base/share/classes/java/lang/Math.java @@ -2737,6 +2737,7 @@ public static double cosh(double x) { * @return The hyperbolic tangent of {@code x}. * @since 1.5 */ + @IntrinsicCandidate public static double tanh(double x) { return StrictMath.tanh(x); } diff --git a/test/jdk/java/lang/Math/HyperbolicTests.java b/test/jdk/java/lang/Math/HyperbolicTests.java index cf583ed7b5f27..4534396ee06dd 100644 --- a/test/jdk/java/lang/Math/HyperbolicTests.java +++ b/test/jdk/java/lang/Math/HyperbolicTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2024, 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 @@ -969,6 +969,400 @@ static int testTanh() { failures += testTanhCaseWithUlpDiff(d, 1.0, 2.5); } + failures += testTanhAdditionalTests(); + + return failures; + } + + /** + * Test accuracy of {Math, StrictMath}.tanh using quad precision + * tanh implementation as the reference. There are additional tests. + * The specified accuracy is 2.5 ulps. + * + */ + static int testTanhAdditionalTests() { + int failures = 0; + /* + * Array elements below are generated using a quad precision tanh + * implementation (libquadmath). Rounded to a double, the quad result + * *should* be correctly rounded, unless we are quite unlucky. + * Assuming the quad value is a correctly rounded double, the + * allowed error is 3.0 ulps instead of 2.5 since the quad + * value rounded to double can have its own 1/2 ulp error. + */ + double[][] testCases = { + // x tanh(x) + {1.09951162777600024414062500000000000e+12, 1.00000000000000000000000000000000000e+00}, + {1.56250000000000416333634234433702659e-02, 1.56237285584089068255495133849899136e-02}, + {1.61254882812500000000000000000000000e+01, 9.99999999999980293529906376885389048e-01}, + {2.53165043529127054000582575099542737e-01, 2.47891535884497437358843835970604812e-01}, + {2.05669906337718799704816774465143681e+00, 9.67821952180774991463712302156014956e-01}, + {8.73243486124784240587359818164259195e+00, 9.99999947984421044859570034536492937e-01}, + {1.35302734375000000000000000000000000e+00, 8.74765946489987955543753077657414741e-01}, + {7.51299319580434721288497712521348149e-01, 6.35923468395323117288273690770900477e-01}, + {9.53088818012631927567568368431238923e-02, 9.50213381512267711017656118902912332e-02}, + {7.64443165964961757197215774795040488e-01, 6.43686625696507143760198874608796949e-01}, + {9.80772770147126660145175947036477737e-02, 9.77640088885469645387119927980991050e-02}, + {8.00000000000000044408920985006261617e-01, 6.64036770267848988511881426480887109e-01}, + {6.58800443825626694943631278533757722e-03, 6.58790912948844334160953310959647563e-03}, + {3.50634723606509357551885841530747712e+00, 9.98200861366828007281302037717336212e-01}, + {8.80951107580675074615328412619419396e-01, 7.06895478355484050029724917425086249e-01}, + {9.41693953354077795125931515940465033e-01, 7.35999567964351009171211613664845735e-01}, + {4.86714106743433794211028953213826753e-01, 4.51604571680788935707314000261162601e-01}, + {4.99999999970896114032115065128891729e-01, 4.62117157237121073362068671381593592e-01}, + {1.27999999999999971578290569595992565e+02, 1.00000000000000000000000000000000000e+00}, + {1.00000000000000022204460492503130808e+00, 7.61594155955764981372495044941331753e-01}, + {1.09951162777600024414062500000000000e+12, 1.00000000000000000000000000000000000e+00}, + {5.00000000000000777156117237609578297e-01, 4.62117157260010369694985045764006657e-01}, + {3.90625000000001474514954580286030250e-03, 3.90623013190635482599726614938805467e-03}, + {1.56250000000000659194920871186695877e-02, 1.56237285584089311057499113400637264e-02}, + {1.25000000000001332267629550187848508e-01, 1.24353001771597519720531117125519878e-01}, + {1.56250000000005169475958410885141348e-02, 1.56237285584093820237573019342883109e-02}, + {2.00000000000022737367544323205947876e+00, 9.64027580075832948084133680630298643e-01}, + {6.25000000000080352391407245704613160e-02, 6.24187467475205184231888372622987839e-02}, + {2.50000000000049737991503207013010979e-01, 2.44918662403755883728363950973251081e-01}, + {2.50000000000454747350886464118957520e-01, 2.44918662404136598540089724354621762e-01}, + {7.81250000001537658889105841808486730e-03, 7.81234105817638947180855590780540396e-03}, + {8.00000000002179945113311987370252609e+00, 9.99999774929675899622836792366347278e-01}, + {8.00000000002182787284255027770996094e+00, 9.99999774929675899635630557632573807e-01}, + {1.00000000004506106598967107856879011e+00, 7.61594155974689379640247120538425632e-01}, + {5.00000000024432678102925819985102862e-01, 4.62117157279224782806433798595181278e-01}, + {5.00000000124148025193449029757175595e-01, 4.62117157357645691462301850285961295e-01}, + {1.25000000043655745685100555419921875e-01, 1.24353001814576875736126314329404676e-01}, + {1.56250130385160446166992187500000000e-02, 1.56237415937421937398207048034470765e-02}, + {6.25000596046447753906250000000000000e-02, 6.24188061199314157260056878713262148e-02}, + {6.25001570879248902201652526855468750e-02, 6.24189032234056148184566765458350515e-02}, + {3.12509536743164062500000000000000000e-02, 3.12407841896026978197614959195842857e-02}, + {1.00024414062500000000000000000000000e+00, 7.61696669690972358277739369649969500e-01}, + {1.25091552734375000000000000000000000e-01, 1.24443137738349286849917747910445080e-01}, + {6.25703578334750876166481248219497502e-02, 6.24888301519391612116796252071905868e-02}, + {2.52525252525252597024518763646483421e-01, 2.47290965006585965880182136581880733e-01}, + {1.00000000164410457817454336293394590e-03, 9.99999668310902934017090322313224382e-04}, + {1.00000000966720672609944209341392707e-03, 9.99999676333997058845099107943491685e-04}, + {5.13687551499984795810860305209644139e-01, 4.72813376851263299460550751434331149e-01}, + {1.03125000000000000000000000000000000e+00, 7.74409187434213568286703209738132986e-01}, + {1.03372912114974835340319714305223897e+00, 7.75399652279487427958938283855319050e-01}, + {8.73243486124791523650401359191164374e+00, 9.99999947984421044867146689152891277e-01}, + {5.46364074509520181166521979321260005e-01, 4.97790203319363272413440879555555135e-01}, + {5.48776992118357842542764046811498702e-01, 4.99603030846724465253358333732665160e-01}, + {8.62884521484375000000000000000000000e-03, 8.62863106199946057455229821459862778e-03}, + {5.56840723899044820477399753144709393e-01, 5.05629619734278492036257594911833276e-01}, + {1.12042968912429174999090264464030042e+00, 8.07718324543002512898290101804260243e-01}, + {2.80761718750000000000000000000000000e-01, 2.73609921989813966516244201735889906e-01}, + {4.50982142857161694138312668655999005e+00, 9.99758010610690750512553927515350523e-01}, + {1.79803946803892764072507759465224808e-02, 1.79784572761372499903768063141254578e-02}, + {2.90674624105783541150316295897937380e-01, 2.82755618405959946459876962574827861e-01}, + {3.00000000019552404140199541870970279e-01, 2.91312612469484033539387970973996561e-01}, + {1.52306844600212459850396840010944288e-01, 1.51139964502163284820786391222343666e-01}, + {1.21913138136517762433186362613923848e+00, 8.39397762830401796350294214789399315e-01}, + {1.91612901016097944562055488404439529e-02, 1.91589453912240029886209020645693670e-02}, + {1.23194037796136601770058405236341059e+00, 8.43141232466373734055029303451281784e-01}, + {5.14544145441922751160745974630117416e+00, 9.99932120037417992977353814124626761e-01}, + {1.29608715898613313655118872702587396e+00, 8.60712461444305632100271902930674052e-01}, + {1.35302734375000000000000000000000000e+00, 8.74765946489987955543753077657414741e-01}, + {6.89141205308152926534148718928918242e-01, 5.97430012402391408227990740295335202e-01}, + {2.16702398900134561576802383342510439e-02, 2.16668484172600518601166701940771309e-02}, + {6.95330121814107471323040954302996397e-01, 6.01395252733578654705526153849150843e-01}, + {1.70127028180982076566857275068400668e-04, 1.70127026539641570641832179464678521e-04}, + {6.98731899876564921392230189667316154e-01, 6.03562246839061712657431798989209285e-01}, + {2.82308042901865396956395670713391155e+00, 9.92962754889608618611084237181745775e-01}, + {8.85009765625000000000000000000000000e-02, 8.82706391518277914218106043840064600e-02}, + {1.44086021505376304929768593865446746e+00, 8.93870759190524111186764508137227647e-01}, + {4.52708479240923750142044923450157512e-02, 4.52399464814195843886615749285771251e-02}, + {7.42434201630502221824770003877347335e-01, 6.30613596749571014884527941122811076e-01}, + {7.47314453125000000000000000000000000e-01, 6.33544059591028741704251380359792317e-01}, + {2.33572976827208893257914468222224968e-02, 2.33530509808936286709795071423335732e-02}, + {7.51392746195329142011587464367039502e-01, 6.35979110106607807348963004903609067e-01}, + {7.51649175412362091641682582121575251e-01, 6.36131796640758591543062918907122080e-01}, + {7.62560692649938864917658065678551793e-01, 6.42582785959772486552828548950126373e-01}, + {7.64660852335945273594575155584607273e-01, 6.43814099671361386286313072270915932e-01}, + {1.92871093750000000000000000000000000e-01, 1.90514597602311764623059750704793759e-01}, + {2.43864313521849479515779535176989157e-02, 2.43815983142663741885939851467013521e-02}, + {3.97705078125000000000000000000000000e-01, 3.77983627858614640283948547303348236e-01}, + {7.98034667968750000000000000000000000e-01, 6.62936606884708330125541187161682941e-01}, + {7.99316406250000000000000000000000000e-01, 6.63654430152659513562528989372441102e-01}, + {1.99890136718750000000000000000000000e-01, 1.97269734600247465099938891830640889e-01}, + {2.00000000008910994164779140191967599e-01, 1.97375320233467849151455260287892058e-01}, + {4.00000000093461316463816501709516160e-01, 3.79948962335194012629557116519596150e-01}, + {2.00000000069810862646235705142316874e-01, 1.97375320291995240418209079080646997e-01}, + {1.00000000056612609045103567950718571e-01, 9.96679946810060529704707312198636589e-02}, + {1.00000000080404896629637789828848327e-01, 9.96679947045619948897444345018478492e-02}, + {1.66666666666666696272613990004174411e+00, 9.31109608667577693190680177920119455e-01}, + {1.31034851074218750000000000000000000e-02, 1.31027351970209980614612589861988504e-02}, + {8.43444227005861080215254332870244980e-01, 6.87629045782656322925865941652078512e-01}, + {4.25596815032856623517432126391213387e-01, 4.01634947321531793299729470086813678e-01}, + {8.54614885269050605920426733064232394e-01, 6.93472710492835200064966331725774025e-01}, + {8.63777419830865200722769259300548583e-01, 6.98198780318331041148483592329099127e-01}, + {2.70117449276632004551146337689715438e-02, 2.70051772786722224566765342032635559e-02}, + {2.16282487792377908775165451515931636e-01, 2.12971988592557031781365419455581001e-01}, + {1.73204653003120601084674490266479552e+00, 9.39297315789076214802641716736658105e-01}, + {2.71436010781672190650404274947504746e-02, 2.71369367992428389623549774823710978e-02}, + {8.69092640155437079485523099720012397e-01, 7.00912831250687651307196017605464473e-01}, + {2.78015136718750000000000000000000000e-02, 2.77943530651526982827985645341156701e-02}, + {9.10156250000000000000000000000000000e-01, 7.21207240669352050307412688531998165e-01}, + {2.27787862235060922788676407435559668e-01, 2.23928183342045426304404589794035157e-01}, + {5.71524498377538048288215577485971153e-02, 5.70903033991663026980553749418981725e-02}, + {3.66406250000000000000000000000000000e+00, 9.98687254335130669671645868977829517e-01}, + {5.72863132979952241474741470028675394e-02, 5.72237295373843844708720164610859507e-02}, + {1.15265335196343660095763539175095502e-01, 1.14757558082362397172277983632352767e-01}, + {9.22871508732805212460448274214286357e-01, 7.27253018562057912939305739474564638e-01}, + {1.44882202148437500000000000000000000e-02, 1.44872065663080247568859985337817684e-02}, + {2.33459472656250000000000000000000000e-01, 2.29308506606965514793638071915067313e-01}, + {4.67608948699241744328958247933769599e-01, 4.36265367328226513916944408221096440e-01}, + {2.34375000000000000000000000000000000e-01, 2.30175711032132981819570603563403063e-01}, + {2.93977526337722387672624080323657836e-02, 2.93892867747176836833509722656208701e-02}, + {1.89257812500000000000000000000000000e+00, 9.55597542193888546329823463414294394e-01}, + {2.95798696005085230698039566732404637e-02, 2.95712454656271068251835101101858187e-02}, + {1.89360756176453159937977943627629429e+00, 9.55686843743833788059988471898348142e-01}, + {4.74943000289441419337066463413066231e-01, 4.42184502480986035803118250513914071e-01}, + {4.76562500000000000000000000000000000e-01, 4.43486412595195826790440814160101630e-01}, + {9.59027831303091549131067949929274619e-01, 7.43842915769532264613887042424467929e-01}, + {3.09784640940728682456661857713697827e-02, 3.09685582448730820784897541732374591e-02}, + {1.98437499999999977795539507496869192e+00, 9.62906870975765387287608356129776957e-01}, + {9.97205648659918675313917901803506538e-01, 7.60418100316000600203658397859135661e-01}, + {3.90291213989257769131913100579822640e-03, 3.90289232268659551022766662201699736e-03}, + {3.90481948852539019131913100579822640e-03, 3.90479964225138860483705936617354227e-03}, + {3.12423706054687500000000000000000000e-02, 3.12322094954161727499363714231262395e-02}, + {3.90535406768321947598709975579822640e-03, 3.90533421325712750455622728849037270e-03}, + {7.81154632568359288263826201159645279e-03, 7.81138744204279466358299901763388375e-03}, + {1.24999789521095569511111023075500270e-01, 1.24352794547462473786771370350680283e-01}, + {9.99999444341875043384959553804947063e-01, 7.61593922593510941370556728778707492e-01}, + {9.99999895691871532044103787484345958e-01, 7.61594112149023829770882693858011645e-01}, + {2.49999998130078865399283927217766177e-01, 2.44918660645955495851244772320875652e-01}, + {2.49999998603016110321206610933586489e-01, 2.44918661090523528987141309434443089e-01}, + {4.99999999970896114032115065128891729e-01, 4.62117157237121073362068671381593592e-01}, + {9.99999999999829358721115113439736888e-01, 7.61594155955693223160706417649502130e-01}, + {3.12499999999979183318288278314867057e-02, 3.12398314460291771315638233977623908e-02}, + {6.24999999999973701592104191604448715e-02, 6.24187467475098948954758673929811576e-02}, + {9.99999999999998556710067987296497449e-01, 7.61594155955764281974719327416526334e-01}, + {1.27999999999999971578290569595992565e+02, 1.00000000000000000000000000000000000e+00}, + {3.44827586206896546938693859374325257e-02, 3.44690977543900329082306735053903756e-02}, + {6.89655172413793093877387718748650514e-02, 6.88563859490195017187269420471893052e-02}, + {1.03448275862068964081608157812297577e-01, 1.03080829858086020470241143281488892e-01}, + {1.37931034482758618775477543749730103e-01, 1.37062928881132531260309423128680656e-01}, + {1.72413793103448287347134737501619384e-01, 1.70725445282084714146447066718646674e-01}, + {2.06896551724137955918791931253508665e-01, 2.03994088403983264406130799853712156e-01}, + {2.41379310344827624490449125005397946e-01, 2.36798141876826809207868665407968027e-01}, + {2.75862068965517293062106318757287227e-01, 2.69071023201531202536913498454407638e-01}, + {3.10344827586206961633763512509176508e-01, 3.00750767242988858303859696730149916e-01}, + {3.44827586206896630205420706261065789e-01, 3.31780427497542984412066808006924260e-01}, + {3.79310344827586298777077900012955070e-01, 3.62108391409330839416919529705937418e-01}, + {4.13793103448275967348735093764844351e-01, 3.91688608393346163715111892758489641e-01}, + {4.48275862068965635920392287516733631e-01, 4.20480731486975012003415012347372452e-01}, + {4.82758620689655304492049481268622912e-01, 4.48450175615929701255698232730127770e-01}, + {5.17241379310344973063706675020512193e-01, 4.75568097261544496368767486763625886e-01}, + {5.51724137931034586124212637514574453e-01, 5.01811301809605377924874787743959204e-01}, + {5.86206896551724199184718600008636713e-01, 5.27162086020673527345538794213535134e-01}, + {6.20689655172413812245224562502698973e-01, 5.51608023880856575817362987825134405e-01}, + {6.55172413793103425305730524996761233e-01, 5.75141704579102279221464447290041163e-01}, + {6.89655172413793038366236487490823492e-01, 5.97760431534850182076591161239096491e-01}, + {7.24137931034482651426742449984885752e-01, 6.19465891301270655454827665546029664e-01}, + {7.58620689655172264487248412478948012e-01, 6.40263800834536321750527885396253899e-01}, + {7.93103448275861877547754374973010272e-01, 6.60163541092833363676687202005166905e-01}, + {8.27586206896551490608260337467072532e-01, 6.79177784255529339466238655218797135e-01}, + {8.62068965517241103668766299961134791e-01, 6.97322121077226884958095667604561029e-01}, + {8.96551724137930716729272262455197051e-01, 7.14614694054361357412620518070189428e-01}, + {9.31034482758620329789778224949259311e-01, 7.31075841220047215751737025073520835e-01}, + {9.65517241379309942850284187443321571e-01, 7.46727754527182387965057729340710925e-01}, + {9.99999999999999555910790149937383831e-01, 7.61594155955764701613384757931622516e-01}, + {1.26765060022822940149670320537600000e+30, 1.00000000000000000000000000000000000e+00}, + {1.33436905287182034855574634496000000e+30, 1.00000000000000000000000000000000000e+00}, + {1.40108750551541129561478948454400000e+30, 1.00000000000000000000000000000000000e+00}, + {1.46780595815900224267383262412800000e+30, 1.00000000000000000000000000000000000e+00}, + {1.53452441080259318973287576371200000e+30, 1.00000000000000000000000000000000000e+00}, + {1.60124286344618413679191890329600000e+30, 1.00000000000000000000000000000000000e+00}, + {1.66796131608977508385096204288000000e+30, 1.00000000000000000000000000000000000e+00}, + {1.73467976873336603091000518246400000e+30, 1.00000000000000000000000000000000000e+00}, + {1.80139822137695697796904832204800000e+30, 1.00000000000000000000000000000000000e+00}, + {1.86811667402054792502809146163200000e+30, 1.00000000000000000000000000000000000e+00}, + {1.93483512666413887208713460121600000e+30, 1.00000000000000000000000000000000000e+00}, + {2.00155357930772981914617774080000000e+30, 1.00000000000000000000000000000000000e+00}, + {2.06827203195132076620522088038400000e+30, 1.00000000000000000000000000000000000e+00}, + {2.13499048459491171326426401996800000e+30, 1.00000000000000000000000000000000000e+00}, + {2.20170893723850266032330715955200000e+30, 1.00000000000000000000000000000000000e+00}, + {2.26842738988209360738235029913600000e+30, 1.00000000000000000000000000000000000e+00}, + {2.33514584252568455444139343872000000e+30, 1.00000000000000000000000000000000000e+00}, + {2.40186429516927550150043657830400000e+30, 1.00000000000000000000000000000000000e+00}, + {2.46858274781286644855947971788800000e+30, 1.00000000000000000000000000000000000e+00}, + {2.53530120045645739561852285747200000e+30, 1.00000000000000000000000000000000000e+00}, + {1.60693804425899027554196209234116260e+60, 1.00000000000000000000000000000000000e+00}, + {1.69151373079893703825155926128281056e+60, 1.00000000000000000000000000000000000e+00}, + {1.77608941733888380096115643022445853e+60, 1.00000000000000000000000000000000000e+00}, + {1.86066510387883056367075359916610649e+60, 1.00000000000000000000000000000000000e+00}, + {1.94524079041877732638035076810775445e+60, 1.00000000000000000000000000000000000e+00}, + {2.02981647695872408908994793704940241e+60, 1.00000000000000000000000000000000000e+00}, + {2.11439216349867085179954510599105038e+60, 1.00000000000000000000000000000000000e+00}, + {2.19896785003861761450914227493269834e+60, 1.00000000000000000000000000000000000e+00}, + {2.28354353657856437721873944387434630e+60, 1.00000000000000000000000000000000000e+00}, + {2.36811922311851113992833661281599426e+60, 1.00000000000000000000000000000000000e+00}, + {2.45269490965845790263793378175764222e+60, 1.00000000000000000000000000000000000e+00}, + {2.53727059619840466534753095069929019e+60, 1.00000000000000000000000000000000000e+00}, + {2.62184628273835142805712811964093815e+60, 1.00000000000000000000000000000000000e+00}, + {2.70642196927829819076672528858258611e+60, 1.00000000000000000000000000000000000e+00}, + {2.79099765581824495347632245752423407e+60, 1.00000000000000000000000000000000000e+00}, + {2.87557334235819171618591962646588203e+60, 1.00000000000000000000000000000000000e+00}, + {2.96014902889813847889551679540753000e+60, 1.00000000000000000000000000000000000e+00}, + {3.04472471543808524160511396434917796e+60, 1.00000000000000000000000000000000000e+00}, + {3.12930040197803200431471113329082592e+60, 1.00000000000000000000000000000000000e+00}, + {3.21387608851797876702430830223247388e+60, 1.00000000000000000000000000000000000e+00}, + {1.07150860718626732094842504906000181e+301, 1.00000000000000000000000000000000000e+00}, + {1.12790379703817606470289337889334663e+301, 1.00000000000000000000000000000000000e+00}, + {1.18429898689008480845736170872669145e+301, 1.00000000000000000000000000000000000e+00}, + {1.24069417674199355221183003856003627e+301, 1.00000000000000000000000000000000000e+00}, + {1.29708936659390229596629836839338109e+301, 1.00000000000000000000000000000000000e+00}, + {1.35348455644581103972076669822672591e+301, 1.00000000000000000000000000000000000e+00}, + {1.40987974629771978347523502806007073e+301, 1.00000000000000000000000000000000000e+00}, + {1.46627493614962852722970335789341555e+301, 1.00000000000000000000000000000000000e+00}, + {1.52267012600153727098417168772676037e+301, 1.00000000000000000000000000000000000e+00}, + {1.57906531585344601473864001756010519e+301, 1.00000000000000000000000000000000000e+00}, + {1.63546050570535475849310834739345001e+301, 1.00000000000000000000000000000000000e+00}, + {1.69185569555726350224757667722679483e+301, 1.00000000000000000000000000000000000e+00}, + {1.74825088540917224600204500706013965e+301, 1.00000000000000000000000000000000000e+00}, + {1.80464607526108098975651333689348447e+301, 1.00000000000000000000000000000000000e+00}, + {1.86104126511298973351098166672682928e+301, 1.00000000000000000000000000000000000e+00}, + {1.91743645496489847726544999656017410e+301, 1.00000000000000000000000000000000000e+00}, + {1.97383164481680722101991832639351892e+301, 1.00000000000000000000000000000000000e+00}, + {2.03022683466871596477438665622686374e+301, 1.00000000000000000000000000000000000e+00}, + {2.08662202452062470852885498606020856e+301, 1.00000000000000000000000000000000000e+00}, + {2.14301721437253345228332331589355338e+301, 1.00000000000000000000000000000000000e+00}, + {4.94065645841246544176568792868221372e-324, 4.94065645841246544176568792868221372e-324}, + {4.94065645841246544176568792868221372e-324, 4.94065645841246544176568792868221372e-324}, + {4.99999999999999944488848768742172979e-01, 4.62117157260009714845699443492203290e-01}, + {5.00000000000000000000000000000000000e-01, 4.62117157260009758502318483643672557e-01}, + {5.00000000000000111022302462515654042e-01, 4.62117157260009845815556563946604302e-01}, + {5.49306144334054669009503868437604979e-01, 4.99999999999999867483910937482244858e-01}, + {5.49306144334054780031806330953259021e-01, 4.99999999999999950750637784368995452e-01}, + {5.49306144334054891054108793468913063e-01, 5.00000000000000034017364631255736851e-01}, + {2.19999999999999964472863211994990706e+01, 9.99999999999999999844377355177323009e-01}, + {2.20000000000000000000000000000000000e+01, 9.99999999999999999844377355177324068e-01}, + {2.20000000000000035527136788005009294e+01, 9.99999999999999999844377355177325223e-01}, + {6.93147180559945397249066445510834455e-01, 6.00000000000000056212373967393698031e-01}, + {6.93147180559945286226763982995180413e-01, 5.99999999999999985158100391383682202e-01}, + {6.93147180559945175204461520479526371e-01, 5.99999999999999914103826815373657032e-01}, + {3.46573590279972698624533222755417228e-01, 3.33333333333333372369704144023402903e-01}, + {3.46573590279972643113381991497590207e-01, 3.33333333333333323026458605127557235e-01}, + {3.46573590279972587602230760239763185e-01, 3.33333333333333273683213066231709688e-01}, + {1.73286795139986349312266611377708614e-01, 1.71572875253809923708199182915954510e-01}, + {1.73286795139986321556690995748795103e-01, 1.71572875253809896769671427846052946e-01}, + {1.73286795139986293801115380119881593e-01, 1.71572875253809869831143672776151118e-01}, + {8.66433975699931746561333056888543069e-02, 8.64272337258898029408455765418952337e-02}, + {8.66433975699931607783454978743975516e-02, 8.64272337258897891667202185946638536e-02}, + {8.66433975699931469005576900599407963e-02, 8.64272337258897753925948606474324374e-02}, + {4.33216987849965873280666528444271535e-02, 4.32946174993891841617996586480128793e-02}, + {4.33216987849965803891727489371987758e-02, 4.32946174993891772359121833444914284e-02}, + {4.33216987849965734502788450299703982e-02, 4.32946174993891703100247080409699774e-02}, + {2.16608493924982936640333264222135767e-02, 2.16574623262262954492383391751347008e-02}, + {2.16608493924982901945863744685993879e-02, 2.16574623262262919814187163069359478e-02}, + {2.16608493924982867251394225149851991e-02, 2.16574623262262885135990934387371889e-02}, + {2.16608493924982867251394225149851991e-02, 2.16574623262262885135990934387371889e-02}, + {2.16608493924982901945863744685993879e-02, 2.16574623262262919814187163069359478e-02}, + {2.16608493924982936640333264222135767e-02, 2.16574623262262954492383391751347008e-02}, + {4.33216987849965734502788450299703982e-02, 4.32946174993891703100247080409699774e-02}, + {4.33216987849965803891727489371987758e-02, 4.32946174993891772359121833444914284e-02}, + {4.33216987849965873280666528444271535e-02, 4.32946174993891841617996586480128793e-02}, + {8.66433975699931469005576900599407963e-02, 8.64272337258897753925948606474324374e-02}, + {8.66433975699931607783454978743975516e-02, 8.64272337258897891667202185946638536e-02}, + {8.66433975699931746561333056888543069e-02, 8.64272337258898029408455765418952337e-02}, + {1.73286795139986293801115380119881593e-01, 1.71572875253809869831143672776151118e-01}, + {1.73286795139986321556690995748795103e-01, 1.71572875253809896769671427846052946e-01}, + {1.73286795139986349312266611377708614e-01, 1.71572875253809923708199182915954510e-01}, + {3.46573590279972587602230760239763185e-01, 3.33333333333333273683213066231709688e-01}, + {3.46573590279972643113381991497590207e-01, 3.33333333333333323026458605127557235e-01}, + {3.46573590279972698624533222755417228e-01, 3.33333333333333372369704144023402903e-01}, + {6.93147180559945175204461520479526371e-01, 5.99999999999999914103826815373657032e-01}, + {6.93147180559945286226763982995180413e-01, 5.99999999999999985158100391383682202e-01}, + {6.93147180559945397249066445510834455e-01, 6.00000000000000056212373967393698031e-01}, + {7.09782712893383859409368596971035004e+02, 1.00000000000000000000000000000000000e+00}, + {7.09782712893383973096206318587064743e+02, 1.00000000000000000000000000000000000e+00}, + {7.09782712893384086783044040203094482e+02, 1.00000000000000000000000000000000000e+00}, + {7.41782712893384086783044040203094482e+02, 1.00000000000000000000000000000000000e+00}, + {7.41782712893383973096206318587064743e+02, 1.00000000000000000000000000000000000e+00}, + {7.41782712893383859409368596971035004e+02, 1.00000000000000000000000000000000000e+00}, + {7.10475860073943749739555642008781433e+02, 1.00000000000000000000000000000000000e+00}, + {7.10475860073943863426393363624811172e+02, 1.00000000000000000000000000000000000e+00}, + {7.10475860073943977113231085240840912e+02, 1.00000000000000000000000000000000000e+00}, + {7.09782712893384086783044040203094482e+02, 1.00000000000000000000000000000000000e+00}, + {7.09782712893383973096206318587064743e+02, 1.00000000000000000000000000000000000e+00}, + {7.09782712893383859409368596971035004e+02, 1.00000000000000000000000000000000000e+00}, + {9.22337203685477478400000000000000000e+18, 1.00000000000000000000000000000000000e+00}, + {9.22337203685477580800000000000000000e+18, 1.00000000000000000000000000000000000e+00}, + {9.22337203685477785600000000000000000e+18, 1.00000000000000000000000000000000000e+00}, + {1.34217727999999985098838806152343750e+08, 1.00000000000000000000000000000000000e+00}, + {1.34217728000000000000000000000000000e+08, 1.00000000000000000000000000000000000e+00}, + {1.34217728000000029802322387695312500e+08, 1.00000000000000000000000000000000000e+00}, + {1.67772159999999981373548507690429688e+07, 1.00000000000000000000000000000000000e+00}, + {1.67772160000000000000000000000000000e+07, 1.00000000000000000000000000000000000e+00}, + {1.67772160000000037252902984619140625e+07, 1.00000000000000000000000000000000000e+00}, + {3.19999999999999964472863211994990706e+01, 9.99999999999999999999999999679237812e-01}, + {3.20000000000000000000000000000000000e+01, 9.99999999999999999999999999679237812e-01}, + {3.20000000000000071054273576010018587e+01, 9.99999999999999999999999999679237812e-01}, + {1.59999999999999982236431605997495353e+01, 9.99999999999974671668901811879331665e-01}, + {1.60000000000000000000000000000000000e+01, 9.99999999999974671668901811969315927e-01}, + {1.60000000000000035527136788005009294e+01, 9.99999999999974671668901812149284547e-01}, + {7.99999999999999911182158029987476766e+00, 9.99999774929675889809619027791781323e-01}, + {8.00000000000000000000000000000000000e+00, 9.99999774929675889810018832956368404e-01}, + {8.00000000000000177635683940025046468e+00, 9.99999774929675889810818443285542469e-01}, + {3.99999999999999955591079014993738383e+00, 9.99329299739067043196741615068852355e-01}, + {4.00000000000000000000000000000000000e+00, 9.99329299739067043792243344341724993e-01}, + {4.00000000000000088817841970012523234e+00, 9.99329299739067044983246802887468536e-01}, + {1.99999999999999977795539507496869192e+00, 9.64027580075816868258779231952432911e-01}, + {2.00000000000000000000000000000000000e+00, 9.64027580075816883946413724100923171e-01}, + {2.00000000000000044408920985006261617e+00, 9.64027580075816915321682708397883469e-01}, + {9.99999999999999888977697537484345958e-01, 7.61594155955764841492939901436512668e-01}, + {1.00000000000000000000000000000000000e+00, 7.61594155955764888119458282604793657e-01}, + {1.00000000000000022204460492503130808e+00, 7.61594155955764981372495044941331753e-01}, + {4.99999999999999944488848768742172979e-01, 4.62117157260009714845699443492203290e-01}, + {5.00000000000000000000000000000000000e-01, 4.62117157260009758502318483643672557e-01}, + {5.00000000000000111022302462515654042e-01, 4.62117157260009845815556563946604302e-01}, + {2.49999999999999972244424384371086489e-01, 2.44918662403709103187147915631612892e-01}, + {2.50000000000000000000000000000000000e-01, 2.44918662403709129277801131491016945e-01}, + {2.50000000000000055511151231257827021e-01, 2.44918662403709181459107563209824042e-01}, + {1.24999999999999986122212192185543245e-01, 1.24353001771596194391460985792144305e-01}, + {1.25000000000000000000000000000000000e-01, 1.24353001771596208054647275805892707e-01}, + {1.25000000000000027755575615628913511e-01, 1.24353001771596235381019855833389378e-01}, + {6.24999999999999930611060960927716224e-02, 6.24187467475125075782836114480350829e-02}, + {6.25000000000000000000000000000000000e-02, 6.24187467475125144901428911942113317e-02}, + {6.25000000000000138777878078144567553e-02, 6.24187467475125283138614506865638292e-02}, + {3.12499999999999965305530480463858112e-02, 3.12398314460312533021176543496182149e-02}, + {3.12500000000000000000000000000000000e-02, 3.12398314460312567681786791091369499e-02}, + {3.12500000000000069388939039072283776e-02, 3.12398314460312637003007286281744168e-02}, + {1.56249999999999982652765240231929056e-02, 1.56237285584088634680488027509294906e-02}, + {1.56250000000000000000000000000000000e-02, 1.56237285584088652023488311762919065e-02}, + {1.56250000000000034694469519536141888e-02, 1.56237285584088686709488880270167445e-02}, + {6.10351562499999932237364219655972875e-05, 6.10351561742087681889301535131725312e-05}, + {6.10351562500000000000000000000000000e-05, 6.10351561742087749651937063040263414e-05}, + {6.10351562500000135525271560688054251e-05, 6.10351561742087885177208118857339557e-05}, + {9.31322574615478412227423430871540641e-10, 9.31322574615478411958158908556102005e-10}, + {9.31322574615478515625000000000000000e-10, 9.31322574615478515355735477684561274e-10}, + {9.31322574615478722420153138256918718e-10, 9.31322574615478722150888615941479902e-10}, + {2.77555756156289104291028806826931429e-17, 2.77555756156289104291028806826931349e-17}, + {2.77555756156289135105907917022705078e-17, 2.77555756156289135105907917022704998e-17}, + {2.77555756156289196735666137414252376e-17, 2.77555756156289196735666137414252322e-17}, + {1.79769313486231570814527423731704357e+308, 1.00000000000000000000000000000000000e+00}, + {1.79769313486231570814527423731704357e+308, 1.00000000000000000000000000000000000e+00}, + {1.79769313486231570814527423731704357e+308, 1.00000000000000000000000000000000000e+00}, + {1.79769313486231550856124328384506240e+308, 1.00000000000000000000000000000000000e+00}, + {3.14159265358979311599796346854418516e+00, 9.96272076220749943353314537833579484e-01}, + {1.57079632679489655799898173427209258e+00, 9.17152335667274336647462811870662140e-01}, + {1.00000000000000022204460492503130808e+00, 7.61594155955764981372495044941331753e-01}, + {1.00000000000000000000000000000000000e+00, 7.61594155955764888119458282604793657e-01}, + {9.99999999999999888977697537484345958e-01, 7.61594155955764841492939901436512668e-01}, + {7.85398163397448278999490867136046290e-01, 6.55794202632672418203926030568705821e-01}, + {2.22507385850720187715587855857894824e-308, 2.22507385850720187715587855857894824e-308}, + {2.22507385850720138309023271733240406e-308, 2.22507385850720138309023271733240406e-308}, + {2.22507385850720088902458687608585989e-308, 2.22507385850720088902458687608585989e-308}, + {2.22507385850720039495894103483931571e-308, 2.22507385850720039495894103483931571e-308}, + {9.88131291682493088353137585736442745e-324, 9.88131291682493088353137585736442745e-324}, + {4.94065645841246544176568792868221372e-324, 4.94065645841246544176568792868221372e-324}, + }; + + for (int i = 0; i < testCases.length; i++) { + double[] testCase = testCases[i]; + failures += testTanhCaseWithUlpDiff(testCase[0], + testCase[1], + 3.0); + } + return failures; }