11/*
22 * Copyright (c) 2022, 2023, Arm Limited. All rights reserved.
3+ * Copyright (c) 2025, Rivos Inc. All rights reserved.
34 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
45 *
56 * This code is free software; you can redistribute it and/or modify it
3839import jdk .incubator .vector .VectorSpecies ;
3940
4041import jdk .test .lib .Asserts ;
42+ import jdk .test .lib .Platform ;
4143import jdk .test .lib .Utils ;
4244
4345/**
4446 * @test
4547 * @bug 8282431
4648 * @key randomness
4749 * @library /test/lib /
48- * @requires vm.cpu.features ~= ".*sve.*"
49- * @summary AArch64: Add optimized rules for masked vector multiply-add/sub for SVE
50+ * @requires vm.cpu.features ~= ".*sve.*" | vm.cpu.features ~= ".*rvv.*"
51+ * @summary Add optimized rules for masked vector multiply-add/sub for SVE and RVV
5052 * @modules jdk.incubator.vector
5153 *
5254 * @run driver compiler.vectorapi.VectorFusedMultiplyAddSubTest
@@ -244,7 +246,7 @@ private static void assertArrayEqualsNeg(double[] r, double[] a, double[] b, dou
244246 }
245247
246248 @ Test
247- @ IR (counts = { IRNode .VMLA_MASKED , ">= 1" })
249+ @ IR (applyIfPlatformOr = { "aarch64" , "true" , "riscv64" , "true" }, counts = { IRNode .VMLA_MASKED , ">= 1" })
248250 public static void testByteMultiplyAddMasked () {
249251 VectorMask <Byte > mask = VectorMask .fromArray (B_SPECIES , m , 0 );
250252 for (int i = 0 ; i < LENGTH ; i += B_SPECIES .length ()) {
@@ -257,7 +259,7 @@ public static void testByteMultiplyAddMasked() {
257259 }
258260
259261 @ Test
260- @ IR (counts = { IRNode .VMLS_MASKED , ">= 1" })
262+ @ IR (applyIfPlatformOr = { "aarch64" , "true" , "riscv64" , "true" }, counts = { IRNode .VMLS_MASKED , ">= 1" })
261263 public static void testByteMultiplySubMasked () {
262264 VectorMask <Byte > mask = VectorMask .fromArray (B_SPECIES , m , 0 );
263265 for (int i = 0 ; i < LENGTH ; i += B_SPECIES .length ()) {
@@ -270,7 +272,7 @@ public static void testByteMultiplySubMasked() {
270272 }
271273
272274 @ Test
273- @ IR (counts = { IRNode .VMLA_MASKED , ">= 1" })
275+ @ IR (applyIfPlatformOr = { "aarch64" , "true" , "riscv64" , "true" }, counts = { IRNode .VMLA_MASKED , ">= 1" })
274276 public static void testShortMultiplyAddMasked () {
275277 VectorMask <Short > mask = VectorMask .fromArray (S_SPECIES , m , 0 );
276278 for (int i = 0 ; i < LENGTH ; i += S_SPECIES .length ()) {
@@ -283,7 +285,7 @@ public static void testShortMultiplyAddMasked() {
283285 }
284286
285287 @ Test
286- @ IR (counts = { IRNode .VMLS_MASKED , ">= 1" })
288+ @ IR (applyIfPlatformOr = { "aarch64" , "true" , "riscv64" , "true" }, counts = { IRNode .VMLS_MASKED , ">= 1" })
287289 public static void testShortMultiplySubMasked () {
288290 VectorMask <Short > mask = VectorMask .fromArray (S_SPECIES , m , 0 );
289291 for (int i = 0 ; i < LENGTH ; i += S_SPECIES .length ()) {
@@ -296,7 +298,7 @@ public static void testShortMultiplySubMasked() {
296298 }
297299
298300 @ Test
299- @ IR (counts = { IRNode .VMLA_MASKED , ">= 1" })
301+ @ IR (applyIfPlatformOr = { "aarch64" , "true" , "riscv64" , "true" }, counts = { IRNode .VMLA_MASKED , ">= 1" })
300302 public static void testIntMultiplyAddMasked () {
301303 VectorMask <Integer > mask = VectorMask .fromArray (I_SPECIES , m , 0 );
302304 for (int i = 0 ; i < LENGTH ; i += I_SPECIES .length ()) {
@@ -309,7 +311,7 @@ public static void testIntMultiplyAddMasked() {
309311 }
310312
311313 @ Test
312- @ IR (counts = { IRNode .VMLS_MASKED , ">= 1" })
314+ @ IR (applyIfPlatformOr = { "aarch64" , "true" , "riscv64" , "true" }, counts = { IRNode .VMLS_MASKED , ">= 1" })
313315 public static void testIntMultiplySubMasked () {
314316 VectorMask <Integer > mask = VectorMask .fromArray (I_SPECIES , m , 0 );
315317 for (int i = 0 ; i < LENGTH ; i += I_SPECIES .length ()) {
@@ -322,7 +324,7 @@ public static void testIntMultiplySubMasked() {
322324 }
323325
324326 @ Test
325- @ IR (counts = { IRNode .VMLA_MASKED , ">= 1" })
327+ @ IR (applyIfPlatformOr = { "aarch64" , "true" , "riscv64" , "true" }, counts = { IRNode .VMLA_MASKED , ">= 1" })
326328 public static void testLongMultiplyAddMasked () {
327329 VectorMask <Long > mask = VectorMask .fromArray (L_SPECIES , m , 0 );
328330 for (int i = 0 ; i < LENGTH ; i += L_SPECIES .length ()) {
@@ -335,7 +337,7 @@ public static void testLongMultiplyAddMasked() {
335337 }
336338
337339 @ Test
338- @ IR (counts = { IRNode .VMLS_MASKED , ">= 1" })
340+ @ IR (applyIfPlatformOr = { "aarch64" , "true" , "riscv64" , "true" }, counts = { IRNode .VMLS_MASKED , ">= 1" })
339341 public static void testLongMultiplySubMasked () {
340342 VectorMask <Long > mask = VectorMask .fromArray (L_SPECIES , m , 0 );
341343 for (int i = 0 ; i < LENGTH ; i += L_SPECIES .length ()) {
@@ -348,7 +350,8 @@ public static void testLongMultiplySubMasked() {
348350 }
349351
350352 @ Test
351- @ IR (counts = { IRNode .VFMSB_MASKED , ">= 1" })
353+ @ IR (applyIfPlatform = {"aarch64" , "true" }, counts = { IRNode .VFMSB_MASKED , ">= 1" })
354+ @ IR (applyIfPlatform = {"riscv64" , "true" }, counts = { IRNode .RISCV_VFNMSUB_MASKED , ">= 1" })
352355 public static void testFloatMultiplySubMasked () {
353356 VectorMask <Float > mask = VectorMask .fromArray (F_SPECIES , m , 0 );
354357 for (int i = 0 ; i < LENGTH ; i += F_SPECIES .length ()) {
@@ -361,7 +364,8 @@ public static void testFloatMultiplySubMasked() {
361364 }
362365
363366 @ Test
364- @ IR (counts = { IRNode .VFMAD_MASKED , ">= 1" })
367+ @ IR (applyIfPlatform = {"aarch64" , "true" }, counts = { IRNode .VFMAD_MASKED , ">= 1" })
368+ @ IR (applyIfPlatform = {"riscv64" , "true" }, counts = { IRNode .RISCV_VFMADD_MASKED , ">= 1" })
365369 public static void testFloatMultiplyNegAMasked () {
366370 VectorMask <Float > mask = VectorMask .fromArray (F_SPECIES , m , 0 );
367371 for (int i = 0 ; i < LENGTH ; i += F_SPECIES .length ()) {
@@ -374,7 +378,8 @@ public static void testFloatMultiplyNegAMasked() {
374378 }
375379
376380 @ Test
377- @ IR (counts = { IRNode .VFNMAD_MASKED , ">= 1" })
381+ @ IR (applyIfPlatform = {"aarch64" , "true" }, counts = { IRNode .VFNMAD_MASKED , ">= 1" })
382+ @ IR (applyIfPlatform = {"riscv64" , "true" }, counts = { IRNode .RISCV_VFNMADD_MASKED , ">= 1" })
378383 public static void testFloatNegatedMultiplyAddMasked () {
379384 VectorMask <Float > mask = VectorMask .fromArray (F_SPECIES , m , 0 );
380385 for (int i = 0 ; i < LENGTH ; i += F_SPECIES .length ()) {
@@ -387,7 +392,8 @@ public static void testFloatNegatedMultiplyAddMasked() {
387392 }
388393
389394 @ Test
390- @ IR (counts = { IRNode .VFNMSB_MASKED , ">= 1" })
395+ @ IR (applyIfPlatform = {"aarch64" , "true" }, counts = { IRNode .VFNMSB_MASKED , ">= 1" })
396+ @ IR (applyIfPlatform = {"riscv64" , "true" }, counts = { IRNode .RISCV_VFMSUB_MASKED , ">= 1" })
391397 public static void testFloatNegatedMultiplyNegAMasked () {
392398 VectorMask <Float > mask = VectorMask .fromArray (F_SPECIES , m , 0 );
393399 for (int i = 0 ; i < LENGTH ; i += F_SPECIES .length ()) {
@@ -400,7 +406,8 @@ public static void testFloatNegatedMultiplyNegAMasked() {
400406 }
401407
402408 @ Test
403- @ IR (counts = { IRNode .VFNMSB_MASKED , ">= 1" })
409+ @ IR (applyIfPlatform = {"aarch64" , "true" }, counts = { IRNode .VFNMSB_MASKED , ">= 1" })
410+ @ IR (applyIfPlatform = {"riscv64" , "true" }, counts = { IRNode .RISCV_VFMSUB_MASKED , ">= 1" })
404411 public static void testFloatNegatedMultiplySubMasked () {
405412 VectorMask <Float > mask = VectorMask .fromArray (F_SPECIES , m , 0 );
406413 for (int i = 0 ; i < LENGTH ; i += F_SPECIES .length ()) {
@@ -413,7 +420,8 @@ public static void testFloatNegatedMultiplySubMasked() {
413420 }
414421
415422 @ Test
416- @ IR (counts = { IRNode .VFMSB_MASKED , ">= 1" })
423+ @ IR (applyIfPlatform = {"aarch64" , "true" }, counts = { IRNode .VFMSB_MASKED , ">= 1" })
424+ @ IR (applyIfPlatform = {"riscv64" , "true" }, counts = { IRNode .RISCV_VFNMSUB_MASKED , ">= 1" })
417425 public static void testDoubleMultiplySubMasked () {
418426 VectorMask <Double > mask = VectorMask .fromArray (D_SPECIES , m , 0 );
419427 for (int i = 0 ; i < LENGTH ; i += D_SPECIES .length ()) {
@@ -426,7 +434,8 @@ public static void testDoubleMultiplySubMasked() {
426434 }
427435
428436 @ Test
429- @ IR (counts = { IRNode .VFMAD_MASKED , ">= 1" })
437+ @ IR (applyIfPlatform = {"aarch64" , "true" }, counts = { IRNode .VFMAD_MASKED , ">= 1" })
438+ @ IR (applyIfPlatform = {"riscv64" , "true" }, counts = { IRNode .RISCV_VFMADD_MASKED , ">= 1" })
430439 public static void testDoubleMultiplyNegAMasked () {
431440 VectorMask <Double > mask = VectorMask .fromArray (D_SPECIES , m , 0 );
432441 for (int i = 0 ; i < LENGTH ; i += D_SPECIES .length ()) {
@@ -439,7 +448,8 @@ public static void testDoubleMultiplyNegAMasked() {
439448 }
440449
441450 @ Test
442- @ IR (counts = { IRNode .VFNMAD_MASKED , ">= 1" })
451+ @ IR (applyIfPlatform = {"aarch64" , "true" }, counts = { IRNode .VFNMAD_MASKED , ">= 1" })
452+ @ IR (applyIfPlatform = {"riscv64" , "true" }, counts = { IRNode .RISCV_VFNMADD_MASKED , ">= 1" })
443453 public static void testDoubleNegatedMultiplyAddMasked () {
444454 VectorMask <Double > mask = VectorMask .fromArray (D_SPECIES , m , 0 );
445455 for (int i = 0 ; i < LENGTH ; i += D_SPECIES .length ()) {
@@ -452,7 +462,8 @@ public static void testDoubleNegatedMultiplyAddMasked() {
452462 }
453463
454464 @ Test
455- @ IR (counts = { IRNode .VFNMSB_MASKED , ">= 1" })
465+ @ IR (applyIfPlatform = {"aarch64" , "true" }, counts = { IRNode .VFNMSB_MASKED , ">= 1" })
466+ @ IR (applyIfPlatform = {"riscv64" , "true" }, counts = { IRNode .RISCV_VFMSUB_MASKED , ">= 1" })
456467 public static void testDoubleNegatedMultiplyNegAMasked () {
457468 VectorMask <Double > mask = VectorMask .fromArray (D_SPECIES , m , 0 );
458469 for (int i = 0 ; i < LENGTH ; i += D_SPECIES .length ()) {
@@ -465,7 +476,8 @@ public static void testDoubleNegatedMultiplyNegAMasked() {
465476 }
466477
467478 @ Test
468- @ IR (counts = { IRNode .VFNMSB_MASKED , ">= 1" })
479+ @ IR (applyIfPlatform = {"aarch64" , "true" }, counts = { IRNode .VFNMSB_MASKED , ">= 1" })
480+ @ IR (applyIfPlatform = {"riscv64" , "true" }, counts = { IRNode .RISCV_VFMSUB_MASKED , ">= 1" })
469481 public static void testDoubleNegatedMultiplySubMasked () {
470482 VectorMask <Double > mask = VectorMask .fromArray (D_SPECIES , m , 0 );
471483 for (int i = 0 ; i < LENGTH ; i += D_SPECIES .length ()) {
@@ -479,8 +491,10 @@ public static void testDoubleNegatedMultiplySubMasked() {
479491
480492 public static void main (String [] args ) {
481493 TestFramework testFramework = new TestFramework ();
482- testFramework .setDefaultWarmup (5000 )
483- .addFlags ("--add-modules=jdk.incubator.vector" , "-XX:UseSVE=1" )
484- .start ();
494+ testFramework .setDefaultWarmup (5000 ).addFlags ("--add-modules=jdk.incubator.vector" );
495+ if (Platform .isAArch64 ()) {
496+ testFramework .addFlags ("-XX:UseSVE=1" );
497+ }
498+ testFramework .start ();
485499 }
486500}
0 commit comments