8243155: AArch64: Add support for SqrtVF

Reviewed-by: aph
This commit is contained in:
Yang Zhang 2020-04-29 09:58:09 +08:00
parent d813a883c3
commit e93cd7ed3c
3 changed files with 85 additions and 3 deletions
src/hotspot/cpu/aarch64
test/hotspot/jtreg/compiler/c2/cr6340864

@ -13227,7 +13227,7 @@ instruct sqrtD_reg(vRegD dst, vRegD src) %{
%}
instruct sqrtF_reg(vRegF dst, vRegF src) %{
match(Set dst (ConvD2F (SqrtD (ConvF2D src))));
match(Set dst (SqrtF src));
ins_cost(INSN_COST * 50);
format %{ "fsqrts $dst, $src" %}
@ -17041,6 +17041,28 @@ instruct vdiv2D(vecX dst, vecX src1, vecX src2)
// --------------------------------- SQRT -------------------------------------
instruct vsqrt2F(vecD dst, vecD src)
%{
predicate(n->as_Vector()->length() == 2);
match(Set dst (SqrtVF src));
format %{ "fsqrt $dst, $src\t# vector (2F)" %}
ins_encode %{
__ fsqrt(as_FloatRegister($dst$$reg), __ T2S, as_FloatRegister($src$$reg));
%}
ins_pipe(vunop_fp64);
%}
instruct vsqrt4F(vecX dst, vecX src)
%{
predicate(n->as_Vector()->length() == 4);
match(Set dst (SqrtVF src));
format %{ "fsqrt $dst, $src\t# vector (4F)" %}
ins_encode %{
__ fsqrt(as_FloatRegister($dst$$reg), __ T4S, as_FloatRegister($src$$reg));
%}
ins_pipe(vsqrt_fp128);
%}
instruct vsqrt2D(vecX dst, vecX src)
%{
predicate(n->as_Vector()->length() == 2);

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2020, 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
@ -90,6 +90,7 @@ public class TestDoubleVect {
test_rint(a0, a1);
test_ceil(a0, a1);
test_floor(a0, a1);
test_sqrt(a0, a1);
}
// Test and verify results
System.out.println("Verification");
@ -404,6 +405,22 @@ public class TestDoubleVect {
errn += verify("test_rint_cc: ", 0, other_corner_cases_res[0], -0.0);
errn += verify("test_rint_cc: ", 1, other_corner_cases_res[1], 0.0);
errn += verify("test_rint_cc: ", 2, other_corner_cases_res[2], 9.007199254740992E15);
// Overwrite with +0.0/-0.0 values
a1[6] = (double)0.0;
a1[7] = (double)-0.0;
test_sqrt(a0, a1);
errn += verify("test_sqrt: ", 0, a0[0], (Double.NaN));
errn += verify("test_sqrt: ", 1, a0[1], (Double.POSITIVE_INFINITY));
errn += verify("test_sqrt: ", 2, a0[2], (Double.NaN));
errn += verify("test_sqrt: ", 3, a0[3], Math.sqrt(Double.MAX_VALUE));
errn += verify("test_sqrt: ", 4, a0[4], Math.sqrt(Double.MIN_VALUE));
errn += verify("test_sqrt: ", 5, a0[5], Math.sqrt(Double.MIN_NORMAL));
errn += verify("test_sqrt: ", 6, a0[6], (double)0.0);
errn += verify("test_sqrt: ", 7, a0[7], (double)-0.0);
for (int i=8; i<ARRLEN; i++) {
errn += verify("test_sqrt: ", i, a0[i], Math.sqrt((double)(ADD_INIT+i)));
}
}
if (errn > 0)
@ -540,6 +557,13 @@ public class TestDoubleVect {
end = System.currentTimeMillis();
System.out.println("test_negc_n: " + (end - start));
start = System.currentTimeMillis();
for (int i=0; i<ITERS; i++) {
test_sqrt(a0, a1);
}
end = System.currentTimeMillis();
System.out.println("test_sqrt_n: " + (end - start));
return errn;
}
@ -661,6 +685,12 @@ public class TestDoubleVect {
}
}
static void test_sqrt(double[] a0, double[] a1) {
for (int i = 0; i < a0.length; i+=1) {
a0[i] = (double)(Math.sqrt((double)a1[i]));
}
}
static int verify(String text, int i, double elem, double val) {
if (elem != val && !(Double.isNaN(elem) && Double.isNaN(val))) {
System.err.println(text + "[" + i + "] = " + elem + " != " + val);

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2020, 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
@ -87,6 +87,7 @@ public class TestFloatVect {
test_divv(a0, a1, -VALUE);
test_diva(a0, a1, a3);
test_negc(a0, a1);
test_sqrt(a0, a1);
}
// Test and verify results
System.out.println("Verification");
@ -352,6 +353,22 @@ public class TestFloatVect {
errn += verify("test_negc: ", i, a0[i], (float)(-((float)(ADD_INIT+i))));
}
// Overwrite with +0.0/-0.0 values
a1[6] = (float)0.0;
a1[7] = (float)-0.0;
test_sqrt(a0, a1);
errn += verify("test_sqrt: ", 0, a0[0], (Float.NaN));
errn += verify("test_sqrt: ", 1, a0[1], (Float.POSITIVE_INFINITY));
errn += verify("test_sqrt: ", 2, a0[2], (Float.NaN));
errn += verify("test_sqrt: ", 3, a0[3], (float)(Math.sqrt((double)Float.MAX_VALUE)));
errn += verify("test_sqrt: ", 4, a0[4], (float)(Math.sqrt((double)Float.MIN_VALUE)));
errn += verify("test_sqrt: ", 5, a0[5], (float)(Math.sqrt((double)Float.MIN_NORMAL)));
errn += verify("test_sqrt: ", 6, a0[6], (float)0.0);
errn += verify("test_sqrt: ", 7, a0[7], (float)-0.0);
for (int i=8; i<ARRLEN; i++) {
errn += verify("test_sqrt: ", i, a0[i], (float)(Math.sqrt((double)(ADD_INIT+i))));
}
}
if (errn > 0)
@ -488,6 +505,13 @@ public class TestFloatVect {
end = System.currentTimeMillis();
System.out.println("test_negc_n: " + (end - start));
start = System.currentTimeMillis();
for (int i=0; i<ITERS; i++) {
test_sqrt(a0, a1);
}
end = System.currentTimeMillis();
System.out.println("test_sqrt_n: " + (end - start));
return errn;
}
@ -579,6 +603,12 @@ public class TestFloatVect {
}
}
static void test_sqrt(float[] a0, float[] a1) {
for (int i = 0; i < a0.length; i+=1) {
a0[i] = (float)(Math.sqrt((double)a1[i]));
}
}
static int verify(String text, int i, float elem, float val) {
if (elem != val && !(Float.isNaN(elem) && Float.isNaN(val))) {
System.err.println(text + "[" + i + "] = " + elem + " != " + val);