diff --git a/javalib/src/main/scala/java/lang/Math.scala b/javalib/src/main/scala/java/lang/Math.scala index 7d77391990..7fe386b7a7 100644 --- a/javalib/src/main/scala/java/lang/Math.scala +++ b/javalib/src/main/scala/java/lang/Math.scala @@ -462,6 +462,43 @@ object Math { if (a >= Integer.MIN_VALUE && a <= Integer.MAX_VALUE) a.toInt else throw new ArithmeticException("Integer overflow") + // RuntimeLong intrinsic + @inline + def multiplyFull(x: scala.Int, y: scala.Int): scala.Long = + x.toLong * y.toLong + + @inline + def multiplyHigh(x: scala.Long, y: scala.Long): scala.Long = { + /* Hacker's Delight, Section 8-2, Figure 8-2, + * where we have "inlined" all the variables used only once to help our + * optimizer perform simplifications. + */ + + val x0 = x & 0xffffffffL + val x1 = x >> 32 + val y0 = y & 0xffffffffL + val y1 = y >> 32 + + val t = x1 * y0 + ((x0 * y0) >>> 32) + x1 * y1 + (t >> 32) + (((t & 0xffffffffL) + x0 * y1) >> 32) + } + + @inline + def unsignedMultiplyHigh(x: scala.Long, y: scala.Long): scala.Long = { + /* Hacker's Delight, Section 8-2: + * > For an unsigned version, simply change all the int declarations to unsigned. + * In Scala, that means changing all the >> into >>>. + */ + + val x0 = x & 0xffffffffL + val x1 = x >>> 32 + val y0 = y & 0xffffffffL + val y1 = y >>> 32 + + val t = x1 * y0 + ((x0 * y0) >>> 32) + x1 * y1 + (t >>> 32) + (((t & 0xffffffffL) + x0 * y1) >>> 32) + } + def floorDiv(a: scala.Int, b: scala.Int): scala.Int = { val quot = a / b if ((a < 0) == (b < 0) || quot * b == a) quot diff --git a/linker-private-library/src/main/scala/org/scalajs/linker/runtime/RuntimeLong.scala b/linker-private-library/src/main/scala/org/scalajs/linker/runtime/RuntimeLong.scala index 7e4e256beb..f570defbe6 100644 --- a/linker-private-library/src/main/scala/org/scalajs/linker/runtime/RuntimeLong.scala +++ b/linker-private-library/src/main/scala/org/scalajs/linker/runtime/RuntimeLong.scala @@ -767,6 +767,47 @@ object RuntimeLong { } } + /** Intrinsic for Math.multiplyFull. + * + * Compared to the regular expansion of `x.toLong * y.toLong`, this + * intrinsic avoids 2 int multiplications. + */ + @inline + def multiplyFull(a: Int, b: Int): RuntimeLong = { + /* We use Hacker's Delight, Section 8-2, Figure 8-2, to compute the hi + * word of the result. We reuse intermediate products to compute the lo + * word, like we do in `RuntimeLong.*`. + * + * We swap the role of a1b0 and a0b1 compared to Hacker's Delight, to + * optimize for the case where a1b0 collapses to 0, like we do in + * `RuntimeLong.*`. The optimizer normalizes constants in multiplyFull to + * be on the left-hand-side (when it cannot do constant-folding to begin + * with). Therefore, `b` is never constant in practice. + */ + + val a0 = a & 0xffff + val a1 = a >> 16 + val b0 = b & 0xffff + val b1 = b >> 16 + + val a0b0 = a0 * b0 + val a1b0 = a1 * b0 // collapses to 0 when a is constant and 0 <= a <= 0xffff + val a0b1 = a0 * b1 + + /* lo = a * b, but we compute the above 3 subproducts for hi anyway, + * so we reuse them to compute lo too, trading a * for 2 +'s and 1 <<. + */ + val lo = a0b0 + ((a1b0 + a0b1) << 16) + + val t = a0b1 + (a0b0 >>> 16) + val hi = { + a1 * b1 + (t >> 16) + + (((t & 0xffff) + a1b0) >> 16) // collapses to 0 when a1b0 = 0 + } + + new RuntimeLong(lo, hi) + } + @inline def divide(a: RuntimeLong, b: RuntimeLong): RuntimeLong = { val lo = divideImpl(a.lo, a.hi, b.lo, b.hi) diff --git a/linker/shared/src/main/scala/org/scalajs/linker/backend/emitter/LongImpl.scala b/linker/shared/src/main/scala/org/scalajs/linker/backend/emitter/LongImpl.scala index 1e1c6b8305..b554c83d8a 100644 --- a/linker/shared/src/main/scala/org/scalajs/linker/backend/emitter/LongImpl.scala +++ b/linker/shared/src/main/scala/org/scalajs/linker/backend/emitter/LongImpl.scala @@ -116,6 +116,13 @@ private[linker] object LongImpl { val AllModuleMethods = Set( fromInt, fromDouble, fromDoubleBits) + // Methods on the companion used for intrinsics + + final val multiplyFull = MethodName("multiplyFull", List(IntRef, IntRef), RTLongRef) + + val AllIntrinsicModuleMethods = Set( + multiplyFull) + // Extract the parts to give to the initFromParts constructor def extractParts(value: Long): (Int, Int) = diff --git a/linker/shared/src/main/scala/org/scalajs/linker/frontend/optimizer/IncOptimizer.scala b/linker/shared/src/main/scala/org/scalajs/linker/frontend/optimizer/IncOptimizer.scala index 38bdb804c3..7aea1cd466 100644 --- a/linker/shared/src/main/scala/org/scalajs/linker/frontend/optimizer/IncOptimizer.scala +++ b/linker/shared/src/main/scala/org/scalajs/linker/frontend/optimizer/IncOptimizer.scala @@ -75,7 +75,10 @@ final class IncOptimizer private[optimizer] (config: CommonPhaseConfig, collOps: multiple( cond(!targetIsWebAssembly && !esFeatures.allowBigIntsForLongs) { // Required by the intrinsics manipulating Longs - callMethods(LongImpl.RuntimeLongClass, LongImpl.AllIntrinsicMethods.toList) + multiple( + callMethods(LongImpl.RuntimeLongClass, LongImpl.AllIntrinsicMethods.toList), + callMethods(LongImpl.RuntimeLongModuleClass, LongImpl.AllIntrinsicModuleMethods.toList) + ) }, cond(targetIsWebAssembly) { // Required by the intrinsic CharacterCodePointToString diff --git a/linker/shared/src/main/scala/org/scalajs/linker/frontend/optimizer/OptimizerCore.scala b/linker/shared/src/main/scala/org/scalajs/linker/frontend/optimizer/OptimizerCore.scala index 2c0fa4ec70..93a8cbbdfc 100644 --- a/linker/shared/src/main/scala/org/scalajs/linker/frontend/optimizer/OptimizerCore.scala +++ b/linker/shared/src/main/scala/org/scalajs/linker/frontend/optimizer/OptimizerCore.scala @@ -2993,6 +2993,32 @@ private[optimizer] abstract class OptimizerCore( case MathMaxDouble => contTree(wasmBinaryOp(WasmBinaryOp.F64Max, targs.head, targs.tail.head)) + case MathMultiplyFull => + def expand(targs: List[PreTransform]): TailRec[Tree] = { + import LongImpl.{RuntimeLongModuleClass => modCls} + val receiver = + makeCast(LoadModule(modCls), ClassType(modCls, nullable = false)).toPreTransform + + pretransformApply(ApplyFlags.empty, + receiver, + MethodIdent(LongImpl.multiplyFull), + targs, + ClassType(LongImpl.RuntimeLongClass, nullable = true), + isStat, usePreTransform)( + cont) + } + + targs match { + case List(PreTransLit(IntLiteral(x)), PreTransLit(IntLiteral(y))) => + // cannot actually call multiplyHigh to constant-fold because it is JDK9+ + contTree(LongLiteral(x.toLong * y.toLong)) + case List(tlhs, trhs @ PreTransLit(_)) => + // normalize a single constant on the left; the implementation is optimized for that case + expand(trhs :: tlhs :: Nil) + case _ => + expand(targs) + } + // scala.collection.mutable.ArrayBuilder case GenericArrayBuilderResult => @@ -4374,6 +4400,14 @@ private[optimizer] abstract class OptimizerCore( PreTransLit(IntLiteral(_))) if (y & 31) != 0 => foldBinaryOp(Int_>>>, lhs, rhs) + case (PreTransBinaryOp(op @ (Int_| | Int_& | Int_^), + PreTransLit(IntLiteral(x)), y), + z @ PreTransLit(IntLiteral(zValue))) => + foldBinaryOp( + op, + PreTransLit(IntLiteral(x >> zValue)), + foldBinaryOp(Int_>>, y, z)) + case (_, PreTransLit(IntLiteral(y))) => val dist = y & 31 if (dist == 0) @@ -6518,8 +6552,9 @@ private[optimizer] object OptimizerCore { final val MathMinDouble = MathMinFloat + 1 final val MathMaxFloat = MathMinDouble + 1 final val MathMaxDouble = MathMaxFloat + 1 + final val MathMultiplyFull = MathMaxDouble + 1 - final val ArrayBuilderZeroOf = MathMaxDouble + 1 + final val ArrayBuilderZeroOf = MathMultiplyFull + 1 final val GenericArrayBuilderResult = ArrayBuilderZeroOf + 1 final val ClassGetName = GenericArrayBuilderResult + 1 @@ -6611,6 +6646,9 @@ private[optimizer] object OptimizerCore { ClassName("java.lang.Long$") -> List( m("toString", List(J), ClassRef(BoxedStringClass)) -> LongToString, m("compare", List(J, J), I) -> LongCompare + ), + ClassName("java.lang.Math$") -> List( + m("multiplyFull", List(I, I), J) -> MathMultiplyFull ) ) diff --git a/project/Build.scala b/project/Build.scala index 7209200769..c1337508a2 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -2138,7 +2138,6 @@ object Build { List(sharedTestDir / "scala", sharedTestDir / "require-scala2") ::: collectionsEraDependentDirectory(scalaV, sharedTestDir) :: includeIf(sharedTestDir / "require-jdk11", javaV >= 11) ::: - includeIf(sharedTestDir / "require-jdk15", javaV >= 15) ::: includeIf(sharedTestDir / "require-jdk17", javaV >= 17) ::: includeIf(sharedTestDir / "require-jdk21", javaV >= 21) ::: includeIf(testDir / "require-scala2", isJSTest) diff --git a/test-suite/shared/src/test/require-jdk11/org/scalajs/testsuite/javalib/lang/MathTestOnJDK11.scala b/test-suite/shared/src/test/require-jdk11/org/scalajs/testsuite/javalib/lang/MathTestOnJDK11.scala new file mode 100644 index 0000000000..a94c198e9e --- /dev/null +++ b/test-suite/shared/src/test/require-jdk11/org/scalajs/testsuite/javalib/lang/MathTestOnJDK11.scala @@ -0,0 +1,242 @@ +/* + * Scala.js (https://www.scala-js.org/) + * + * Copyright EPFL. + * + * Licensed under Apache License 2.0 + * (https://www.apache.org/licenses/LICENSE-2.0). + * + * See the NOTICE file distributed with this work for + * additional information regarding copyright ownership. + */ + +package org.scalajs.testsuite.javalib.lang + +import java.math.BigInteger +import java.util.SplittableRandom + +import org.junit.Test +import org.junit.Assert._ + +class MathTestOnJDK11 { + + @noinline + private def hideFromOptimizer(x: Int): Int = x + + @Test def testMultiplyFull(): Unit = { + @inline def test(expected: Long, x: Int, y: Int): Unit = { + assertEquals(expected, Math.multiplyFull(x, y)) + assertEquals(expected, Math.multiplyFull(x, hideFromOptimizer(y))) + assertEquals(expected, Math.multiplyFull(hideFromOptimizer(x), y)) + assertEquals(expected, Math.multiplyFull(hideFromOptimizer(x), hideFromOptimizer(y))) + } + + test(2641928036408725662L, 1942041231, 1360387202) + test(54843908448922272L, 1565939409, 35023008) + test(510471553407128558L, 1283300489, 397780222) + test(-1211162085735907941L, -1990140693, 608581137) + test(-1197265696701533712L, -584098468, 2049766884) + test(203152587796496856L, -1809591416, -112264341) + test(-1869763755321108598L, 1235591906, -1513253483) + test(-737954189546644064L, 675415792, -1092592442) + test(-2570904460570261986L, 1639253754, -1568338309) + test(1106623967126000400L, 2088029790, 529984760) + test(1407516248272451352L, -869881054, -1618055988) + test(-2120367337662071940L, -1558894530, 1360173698) + test(-1464086284066637244L, -1417313902, 1033000722) + test(36729253163312334L, -1673852034, -21942951) + test(-3197007331876781046L, 1876799847, -1703435418) + test(461794994386945009L, -246001091, -1877207099) + test(-1206231192496917804L, 867896526, -1389832954) + test(-1739671893103255929L, -1083992841, 1604873969) + test(-409626127116780624L, 240101424, -1706054551) + test(-3083566560548370936L, -1568530113, 1965895672) + test(-1205028798380605000L, -1201743532, 1002733750) + test(-1328689065035027168L, 929349664, -1429697687) + test(-124212693522020684L, 80893862, -1535502082) + test(-82341860111074830L, -243230690, 338534007) + test(-846837059701860202L, 1959770926, -432110227) + test(335728245390354432L, 506816728, 662425344) + test(745294755971022170L, 1521993302, 489683335) + test(-2370525755201631608L, 2023520366, -1171485988) + test(-1039854583047715776L, 593162592, -1753068378) + test(-152985384388127808L, -635946432, 240563319) + test(-678107568956539050L, 649113254, -1044667575) + test(-3064094283703186444L, -1890896836, 1620444979) + test(1240687269228318870L, -1080325230, -1148438669) + test(-46551523496333580L, 27167878, -1713476610) + test(-2500430606368427103L, 2023288183, -1235825241) + test(92963399778762084L, 896198732, 103730787) + test(2469065794894324667L, 2105111101, 1172890967) + test(172558569988357136L, -142945148, -1207166332) + test(335684786634110970L, -1647598405, -203741874) + test(2406859843746696240L, 2049365815, 1174441296) + test(3100973294006114952L, 1991928152, 1556769651) + test(-335912134649077352L, 866240524, -387781598) + test(84303320581066207L, 75666091, 1114149277) + test(-2623126349572207976L, 1426933667, -1838295928) + test(59139945163750590L, 149344270, 395997417) + test(-105764175098643999L, 68726447, -1538915217) + test(8595303129864000L, 726092025, 11837760) + test(-2958527843471399088L, 1536412078, -1925608296) + test(1532625839159904477L, 867021537, 1767690621) + test(384402376484481316L, 1207235521, 318415396) + test(-219376614576542698L, 1816299166, -120782203) + test(-672138807810988440L, 531516745, -1264567512) + test(-193351903065245331L, 170858169, -1131651499) + test(71263251057597648L, 51058196, 1395725988) + test(-774312974742971385L, 1958551603, -395349795) + test(-1846593638370672048L, 1190143097, -1551572784) + test(240083094242536384L, 1404614968, 170924488) + test(-130950827889833280L, -115480554, 1133964320) + test(128954457719585228L, 735993884, 175211317) + test(364779990580792000L, -668489125, -545678272) + test(107252402494512045L, 759517757, 141211185) + test(3038084150893069044L, -1924640913, -1578519988) + test(760804294233336624L, -728394552, -1044494762) + test(1171051779605774913L, 848233701, 1380576813) + test(-1805862307837393080L, -1385644986, 1303264780) + test(172227703288618734L, -104999826, -1640266559) + test(150448013961014407L, 163398103, 920745169) + test(-671469201380991232L, 650262784, -1032612073) + test(-1325861126942924945L, -1773644581, 747534845) + test(987406376890116568L, -1626507773, -607071416) + test(2918138947401192144L, 1695881208, 1720721318) + test(-2590993826910153940L, -1397240042, 1854365570) + test(954644624447419276L, -1516139806, -629654746) + test(407510452326678620L, -384747652, -1059162935) + test(149866317537821404L, 1530355444, 97929091) + test(922044716091910632L, 968149268, 952378674) + test(-3508732521573808284L, 1825364562, -1922209182) + test(1701723136959404304L, 894776752, 1901841027) + test(-2435876799625512705L, -1276062909, 1908900245) + test(-516933170985379201L, 657063047, -786732983) + test(123334479976750576L, 313765817, 393078128) + test(-1072624004420456775L, -894199299, 1199535725) + test(301682711612188737L, 330918981, 911651277) + test(1790992996470651507L, -1115945231, -1604911197) + test(-2750453268538140155L, 1878389719, -1464261245) + test(758285757353272504L, 1259684942, 601964612) + test(-218581674312137400L, -161533394, 1353167100) + test(-1824007072461951836L, -1244277844, 1465916219) + test(-92753167730460334L, -65368843, 1418920138) + test(-2326636630979491248L, 1124395877, -2069232624) + test(-7380586257943446L, 29715454, -248375349) + test(31319707234597638L, 491995506, 63658523) + test(-1196559502630778250L, -1752963990, 682592175) + test(166065559841839548L, -911521074, -182185102) + test(-1222260378510810100L, 1071539812, -1140657925) + test(57800571165871464L, -257569032, -224408077) + test(332444627169725608L, 1247224172, 266547614) + test(217903869180130650L, 1069161915, 203808110) + test(920425054266935850L, -901689546, -1020778225) + test(-507632632656614388L, 864632142, -587108214) + } + + @Test def testMultiplyHigh(): Unit = { + def test(expected: Long, x: Long, y: Long): Unit = + assertEquals(expected, Math.multiplyHigh(x, y)) + + test(-2514789262281153376L, 8217931296694472096L, -5644933286224084859L) + test(-298247406641127011L, -8034902747807161194L, 684724352445702293L) + test(242644198957550459L, 717019025263929004L, 6242505821226454837L) + test(-1089698470915011537L, -7558081430876177893L, 2659588811568490384L) + test(138675986327040026L, 2362930226177876193L, 1082605148727562445L) + test(-1260260349245855816L, -3350308785473442797L, 6938972380570262589L) + test(-1799534229489533301L, -4097805274432763180L, 8100811327075225922L) + test(437623091041087696L, -2968271773754119013L, -2719670493975918294L) + test(-107841114219899514L, 2013609532543228156L, -987936043452088475L) + test(2757621741022067854L, -7005993850636185311L, -7260803191272031988L) + test(-187671345159116030L, 1781219534362173574L, -1943570237881252419L) + test(-515018730942796014L, 6085558843030314089L, -1561141543105626636L) + test(-119091959391883575L, 7423442237814967910L, -295935339127164155L) + test(18351865713513547L, -1886460125362775846L, -179453657960126825L) + test(3928100041033091765L, 8449838094261471293L, 8575389888485029447L) + test(-7404756889594137L, -89549316594063561L, 1525345591296625693L) + test(714591873345926311L, -2929853068304815970L, -4499165349746322236L) + test(1305977852854305585L, -5568549492657237090L, -4326268312655360053L) + test(-2435010516398991446L, 6443930667478151719L, -6970592660082469124L) + test(2031324595328562735L, 5390460907312723801L, 6951413911530987604L) + test(34713245667458599L, -535353692461820541L, -1196118319182197181L) + test(255381044848343425L, -3176530727082196631L, -1483048388428836603L) + test(6566871520624982L, -33326351213089011L, -3634883324950494373L) + test(156130078476475485L, 687410849583778615L, 4189767446364284457L) + test(1647679448547038188L, 4460502251200507739L, 6814102850116870938L) + test(-2241611115434343963L, 5633894511267143863L, -7339581257068946568L) + test(-93572860194426351L, -1075368508503119813L, 1605137764964203383L) + test(1663347345126188661L, -6330756750592024018L, -4846710115399342760L) + test(-1686630202076061136L, 5124142056960069542L, -6071813649745693328L) + test(728105493712673843L, -8079843401135830331L, -1662306437683128283L) + test(-2030727779883712688L, 4452689522888653156L, -8412963770845872378L) + test(734253555387491804L, 5835084770836409518L, 2321232330529258387L) + test(2018627311798804222L, -7211950082779933827L, -5163250018863045382L) + test(-1244560006523295051L, -7326211205612788508L, 3133690700470219958L) + test(-492070935033321215L, 1614944457187625808L, -5620692751550184667L) + test(319340972880203566L, 2310036532484690677L, 2550090059672932009L) + test(1766280783448332865L, 5949345770128658249L, 5476590340096838859L) + test(2757208297958468913L, -5707089944199929572L, -8911987777945981523L) + test(408328069441815717L, 1242541635079749093L, 6062028975489127199L) + test(-77985829287979398L, -7943526433115400350L, 181101510313367840L) + test(-230121117022373017L, -780391911062895469L, 5439555807140802418L) + test(2588662639521587653L, 7451684432618227097L, 6408268846625040081L) + test(861249002493118404L, 1744344496585548181L, 9107856827493957233L) + test(-2703044944335540474L, 8052570526613861366L, -6192106997771248181L) + test(-2975059248415970510L, 6503508572335523474L, -8438546047759521035L) + test(-370291189062632935L, -8722964233277178137L, 783067156383574516L) + test(-90473002639507852L, 852694261922564555L, -1957245873225555126L) + test(-218977334338454381L, -1819563432425194345L, 2219993418476586419L) + test(-1087231185918604076L, -2941838679159182506L, 6817462690146034563L) + test(-1170480051005916145L, -2771463765488827700L, 7790665067735548924L) + test(-371145713487913188L, 3224241917397787909L, -2123423169279885562L) + test(-502492608136209963L, 1568228348895174267L, -5910716094215359887L) + test(1445926343733049503L, -7706328512722939071L, -3461133686196008644L) + test(-1374053009197983052L, -8787832166727089323L, 2884306814637966447L) + test(-1910150305525172307L, 8663815092401732543L, -4067036686787486282L) + test(2074971709256543740L, 8092193156887080609L, 4730049238662438083L) + test(953725989108917020L, 8492699833366153401L, 2071560232049848145L) + test(334989155711573307L, 1093268576921704206L, 5652279186765632978L) + test(129011196343964709L, 1000276763122669782L, 2379178052852915387L) + test(239042793587178901L, 3208737625070847213L, 1374235525371105170L) + test(127809344420152430L, -7696730067895344868L, -306320508313194466L) + test(-2506455997163955037L, -5731747797284935902L, 8066641092198683254L) + test(3016086034985660469L, -6992699346126002928L, -7956436339922591224L) + test(-1527917483534567268L, -8938885845855254814L, 3153089016969294968L) + test(-1268939936756528050L, 5537112727075101653L, -4227439716695399205L) + test(-37535014067603004L, -8605247800544091240L, 80462389271855887L) + test(-2710920384572235679L, -7926242046619125682L, 6309125338878172023L) + test(-3331830886924716794L, 6823617049086893513L, -9007163096323738999L) + test(1854911433578401793L, -4644835313936852982L, -7366693150982113934L) + test(-3840461794042836575L, 8006480391435326631L, -8848334396141248546L) + test(-1212641710132993432L, -7017377545321262459L, 3187699555205380404L) + test(946047090630044138L, -5829622550331878687L, -2993588077419595837L) + test(3518955178043574292L, -7909090733489625033L, -8207424565425867851L) + test(1231895337081111773L, 2841977238766797132L, 7996002817598962425L) + test(-1649686524869089287L, -3558405071306300052L, 8551962049372852642L) + test(1156466789444347220L, -8077807627762096372L, -2640945152160624636L) + test(-284428196958678125L, 7604654143237097972L, -689942508603024688L) + test(24530734973246035L, -4976536915346383672L, -90929133590073966L) + test(915668791878818L, -4915702564252847L, -3436153355352311231L) + test(-59487608720960501L, 2234272329433906652L, -491145452224512365L) + test(-935777346233643464L, 2234022931260640741L, -7726888105936443458L) + test(-539196324963981948L, 1233384294780865907L, -8064328899098291942L) + test(-302740552339519239L, 1652272762436229815L, -3379936785683182277L) + test(-1602328337662720444L, -5891195966699023422L, 5017273391344774367L) + test(1971437877011804292L, 6123334000940359947L, 5939021122948580484L) + test(3518273874050862283L, -7935043146462869940L, -8178997459486413381L) + test(989386049294028022L, 3631504400505165814L, 5025727419987895939L) + test(1075600553777136761L, 8162668046881939535L, 2430740540606242760L) + test(555876997051543592L, -1422006546765159905L, -7211022146415941068L) + test(1442987791832810570L, 3172003226122803882L, 8391676993961733131L) + test(122174343239443206L, 592078109511582332L, 3806455273225175653L) + test(-555975358284841098L, -2610695041141095892L, 3928430928909536969L) + test(1217820260754824228L, -2566343358431797989L, -8753629401971345682L) + test(-843540703271762806L, 2010390971620435041L, -7740076278033066915L) + test(28227414827282063L, 1691814723551530731L, 307778322255183098L) + test(-3487482743675782331L, 8885183126228404590L, -7240447464066348779L) + test(-641218088086423374L, -5793475349478143447L, 2041673650588512538L) + test(491218135799199820L, -3483174304311045377L, -2601470510458659970L) + test(-61083956648009538L, -331097881159246733L, 3403223576515274855L) + test(-1760654512150512675L, -6642702867806073297L, 4889326503714183951L) + } + +} diff --git a/test-suite/shared/src/test/require-jdk15/org/scalajs/testsuite/javalib/io/InputStreamTestOnJDK15.scala b/test-suite/shared/src/test/require-jdk17/org/scalajs/testsuite/javalib/io/InputStreamTestOnJDK17.scala similarity index 98% rename from test-suite/shared/src/test/require-jdk15/org/scalajs/testsuite/javalib/io/InputStreamTestOnJDK15.scala rename to test-suite/shared/src/test/require-jdk17/org/scalajs/testsuite/javalib/io/InputStreamTestOnJDK17.scala index 5bda94aa7a..181f15cccf 100644 --- a/test-suite/shared/src/test/require-jdk15/org/scalajs/testsuite/javalib/io/InputStreamTestOnJDK15.scala +++ b/test-suite/shared/src/test/require-jdk17/org/scalajs/testsuite/javalib/io/InputStreamTestOnJDK17.scala @@ -21,7 +21,7 @@ import org.junit.Assume._ import org.scalajs.testsuite.utils.AssertThrows.assertThrows import org.scalajs.testsuite.utils.Platform -class InputStreamTestOnJDK15 { +class InputStreamTestOnJDK17 { /** InputStream that only ever skips max bytes at once */ def lowSkipStream(max: Int, seq: Seq[Int]): InputStream = new SeqInputStreamForTest(seq) { require(max > 0) diff --git a/test-suite/shared/src/test/require-jdk15/org/scalajs/testsuite/javalib/lang/ConstableTest.scala b/test-suite/shared/src/test/require-jdk17/org/scalajs/testsuite/javalib/lang/ConstableTest.scala similarity index 100% rename from test-suite/shared/src/test/require-jdk15/org/scalajs/testsuite/javalib/lang/ConstableTest.scala rename to test-suite/shared/src/test/require-jdk17/org/scalajs/testsuite/javalib/lang/ConstableTest.scala diff --git a/test-suite/shared/src/test/require-jdk15/org/scalajs/testsuite/javalib/lang/ConstantDescTest.scala b/test-suite/shared/src/test/require-jdk17/org/scalajs/testsuite/javalib/lang/ConstantDescTest.scala similarity index 100% rename from test-suite/shared/src/test/require-jdk15/org/scalajs/testsuite/javalib/lang/ConstantDescTest.scala rename to test-suite/shared/src/test/require-jdk17/org/scalajs/testsuite/javalib/lang/ConstantDescTest.scala diff --git a/test-suite/shared/src/test/require-jdk15/org/scalajs/testsuite/javalib/lang/StringTestOnJDK15.scala b/test-suite/shared/src/test/require-jdk17/org/scalajs/testsuite/javalib/lang/StringTestOnJDK17.scala similarity index 99% rename from test-suite/shared/src/test/require-jdk15/org/scalajs/testsuite/javalib/lang/StringTestOnJDK15.scala rename to test-suite/shared/src/test/require-jdk17/org/scalajs/testsuite/javalib/lang/StringTestOnJDK17.scala index 25ed53f386..21ffe9cf1d 100644 --- a/test-suite/shared/src/test/require-jdk15/org/scalajs/testsuite/javalib/lang/StringTestOnJDK15.scala +++ b/test-suite/shared/src/test/require-jdk17/org/scalajs/testsuite/javalib/lang/StringTestOnJDK17.scala @@ -17,7 +17,7 @@ import org.junit.Assert._ import org.scalajs.testsuite.utils.AssertThrows.assertThrows -class StringTestOnJDK15 { +class StringTestOnJDK17 { // indent and transform are available since JDK 12 but we're not testing them separately diff --git a/test-suite/shared/src/test/require-jdk21/org/scalajs/testsuite/javalib/lang/MathTestOnJDK21.scala b/test-suite/shared/src/test/require-jdk21/org/scalajs/testsuite/javalib/lang/MathTestOnJDK21.scala new file mode 100644 index 0000000000..b57216847d --- /dev/null +++ b/test-suite/shared/src/test/require-jdk21/org/scalajs/testsuite/javalib/lang/MathTestOnJDK21.scala @@ -0,0 +1,129 @@ +/* + * Scala.js (https://www.scala-js.org/) + * + * Copyright EPFL. + * + * Licensed under Apache License 2.0 + * (https://www.apache.org/licenses/LICENSE-2.0). + * + * See the NOTICE file distributed with this work for + * additional information regarding copyright ownership. + */ + +package org.scalajs.testsuite.javalib.lang + +import java.math.BigInteger +import java.util.SplittableRandom + +import org.junit.Test +import org.junit.Assert._ + +class MathTestOnJDK21 { + + @Test def testUnsignedMultiplyHigh(): Unit = { + def test(expected: Long, x: Long, y: Long): Unit = + assertEquals(expected, Math.unsignedMultiplyHigh(x, y)) + + test(-4655528149793241951L, -3491544249150011246L, -1435735621922138183L) + test(4723475310515791226L, -5748086171833985033L, 6861570794713764439L) + test(1844940925490449716L, 2113050876768271470L, -2340575756699630680L) + test(702124944283937448L, 2364425117167296916L, 5477830133394302018L) + test(8604154842195983318L, -765591305295706482L, 8976713476968422536L) + test(721433542721114290L, 2866411935332571322L, 4642772995997153672L) + test(198977852337409286L, 901957528446724377L, 4069474895038101365L) + test(763163907759431674L, 5160783458443768226L, 2727858939653224648L) + test(3387911794594526182L, 4369265381816556396L, -4143208729009548760L) + test(7271333002323704409L, -1757891743212949508L, 8037246439257825352L) + test(2439931237179080842L, -6474169961931828112L, 3759324157819640760L) + test(6061120068222317095L, -2837073725411217492L, 7162734907512678039L) + test(34351029958289581L, 2814331433271609755L, 225156373132738607L) + test(5537345867541993285L, -1010313517008906026L, 5858194527486398591L) + test(-5335982525234939944L, -2717969804981747482L, -3070411578621565733L) + test(8785453866123381013L, -8027031729027070236L, -2893241858030230601L) + test(846995399721837047L, 8016550578873635720L, 1949006273527852101L) + test(4706098605093773886L, -8117794498444021304L, 8404745896106734176L) + test(8161884790484487335L, -1014727160850354519L, 8636992531719324619L) + test(-8513922914337796266L, -7911312134726022659L, -1055125873522512866L) + test(5454317624646219097L, -5009725974720812208L, 7487851886286018345L) + test(2492015203153257923L, 5501297108904060131L, 8356132339400095318L) + test(251150029847529372L, 2825249782885673228L, 1639819725946463245L) + test(701745563060384928L, -862030064654873400L, 736146223360275347L) + test(-7730043035170177278L, -81403377518056314L, -7682541838496528017L) + test(7236963176581899295L, -5477193291802744595L, -8153526534093331950L) + test(626928141670112235L, 1514687386182852255L, 7635095589684134756L) + test(413586791425617421L, 2206621030247415833L, 3457471667819472989L) + test(5275688490004831530L, 5303665000787184389L, -97305454699880484L) + test(-4547690235532216689L, -4468474298913285824L, -104539126294685679L) + test(366277061497431976L, 2447428253923437996L, 2760701647814215009L) + test(6869979725009155017L, -6471585201942397935L, -7864107205517734491L) + test(3791302630224081431L, -3133537597544878918L, 4567115935815546723L) + test(1740958585965607218L, -1557363676960182057L, 1901491749479209603L) + test(1523197267704952893L, 6322993002648583029L, 4443786377646975729L) + test(-5259964406327079828L, -1435127053681489364L, -4147506711722433774L) + test(461442857371067152L, -3905080403415491898L, 585360691015982209L) + test(-5941004277830287560L, -823789104926622437L, -5356420579401640852L) + test(-8706994437197957328L, -7948824177902058651L, -1332242280026816373L) + test(-5824918531825640540L, -1108632841430213984L, -5017854248578702419L) + test(-8207168723011034838L, -6116459797997975723L, -3127808865551126328L) + test(73145162458483087L, 984457260399802488L, 1370592860022769137L) + test(1646786118016093153L, 1899627239649590099L, -2455268783649962915L) + test(3040972539165017704L, -1806601545829941920L, 3371127505138255794L) + test(-7035139036718491109L, -5137998055321179172L, -2629554588180521105L) + test(3814121656202007379L, 6827719277638332778L, -8141966856464601543L) + test(846533671710128614L, 928822269112330348L, -1634281118080467412L) + test(2465515036079121285L, -6936668916098982255L, 3951383831786888133L) + test(-8705991089541820518L, -4627352440152123018L, -5444349891042507930L) + test(-1725081446201736077L, -102123348177150214L, -1631993003537285149L) + test(3162229868737586796L, -3928062681119615377L, 4017778440996329527L) + test(-5644865433298065278L, -1848848427461824206L, -4218857359905179258L) + test(8602545182711575119L, -7248610265558893317L, -4275726644671484627L) + test(574312046131959731L, 3094727123103690882L, 3423302576293014745L) + test(1498569573726223576L, -7522287153787738568L, 2530444268837256898L) + test(9201094795447111684L, -7474596509362715910L, -2977553571653290816L) + test(3390173448745695247L, 4278016163532080543L, -3828364997071413384L) + test(1203823557488246474L, 7917135674481131658L, 2804881208044173681L) + test(78424886362034171L, 980323435081771015L, 1475720926338487149L) + test(2441060259411459766L, 5798689165809470750L, 7765481574589679868L) + test(1218713916031010010L, 1847981405952407601L, -6281414035388066866L) + test(3425204597140630L, 23488433971625858L, 2689999370748729443L) + test(1973267136565988242L, -1929721405614247783L, 2203808433804858703L) + test(68657367104675341L, 1589652507076814732L, 796718071475649415L) + test(3001541031524236691L, 8704517430100436852L, 6360910835079676298L) + test(681950840803061472L, 4077993211593106210L, 3084794892591474962L) + test(-8032203953933386693L, -1297027813828962384L, -7244555458827535130L) + test(1705455955228875706L, 7677829613973803154L, 4097526399626386343L) + test(-7072562212974300041L, -4950443113989053629L, -2900512372222814349L) + test(1553202529265923923L, -5818129186601545240L, 2268778469225152008L) + test(468774576517241981L, 4408923425379013709L, 1961332463044936276L) + test(3713249757582606154L, 3805244009484784339L, -445962050491898861L) + test(-6492270872661604844L, -3676904101986751446L, -3516243262736404968L) + test(-1570352970576497130L, -498180996573724276L, -1101931219921881504L) + test(5938952698782807216L, -2212548245883761340L, 6748368792775950262L) + test(6965609214550264138L, -44143931286210318L, 6982318232414802091L) + test(5427827011873507182L, -6210411243958046988L, 8182658739140523648L) + test(-4010444622072654726L, -2893048189377704445L, -1325236533881556505L) + test(-751397756032611136L, -297794630894262553L, -461046011882216476L) + test(547299415238293930L, 4622152711521934473L, 2184240304182297561L) + test(378891801518625290L, -4298572905176069751L, 494008731657528393L) + test(1743296278846509964L, 2577934180605703203L, -5972360304541326595L) + test(1039517173945592548L, 5277562622670643081L, 3633440025065309218L) + test(2800417145934889950L, 4637163034857372585L, -7306618526608114613L) + test(1678445276921448048L, 4821090766475680470L, 6422167091396679498L) + test(6227359204013573541L, -4999273910373625291L, 8542461897755272268L) + test(-5499015746244333303L, -1511897164914852634L, -4343077705835106861L) + test(2697793722365988629L, 6211672456183761935L, 8011612123978580051L) + test(1911468969140043410L, -5555150943474614346L, 2735145185110353700L) + test(2743615826392469850L, 6136958276954783995L, 8246883342207528968L) + test(1464762398133852646L, -6115223270905044522L, 2191140697019557187L) + test(457204414584490485L, -5068587596916665104L, 630425637481565869L) + test(-6229688730810143122L, -4425525343688714952L, -2373612516159392266L) + test(388393998755070731L, 797622384306174158L, 8982451891732844522L) + test(5110014275194731110L, 8574583813914626477L, -7453426194589668982L) + test(6332629791985833635L, -6221980493997883829L, -8891025443683788065L) + test(1100817927132096284L, -5992086725542985450L, 1630434784827422367L) + test(-6893218526017086868L, -566288691658266700L, -6527308893032530287L) + test(6838523840226613906L, 7591397219780968602L, -1829447485155925067L) + test(2870893831454164280L, 3649310365003545712L, -3934784696536939433L) + } + +}