[aarch64-port-dev ] RFR(S): 8243155: AArch64: Add support for SqrtVF

Andrew Haley aph at redhat.com
Tue Apr 28 09:46:43 UTC 2020


On 4/28/20 7:57 AM, Yang Zhang wrote:
> Could you please help to review this patch?
>
> JBS: https://bugs.openjdk.java.net/browse/JDK-8243155
> Webrev: http://cr.openjdk.java.net/~yzhang/8243155/webrev.00/

This was a bit of a head scratcher. To begin with I thought that this
must be wrong, because Math.sqrt() is supposed to be correctly
rounded, and (float)Math.sqrt(float) is double rounded, leading to an
inaccurate result.

Looking round the web, Figueroa [1] proved double rounding to be
innocuous for the square root if it is performed with a precision
larger than twice the original precision, plus two. [2]

But it's not hard to write a program to do an exhaustive search from
x = FLT_MIN; x <= FLT_MAX, like so:

float roundedSqrt(float x) {
  return (float)ieee754_sqrt((double)x);
}

int main() {
  for (float x = FLT_MIN; x <= FLT_MAX; x = nextFloat(x)) {
    if (ieee754_sqrtf(x) != roundedSqrt(x)) {
      fprintf(stdout, "%12.6f\n", x);
    }
  }
}

... and it returns no differences.

The patch is OK, thanks.

[1] Samuel A. Figueroa. When is Double Rounding Innocuous? SIGNUM
Newsl., 30(3):21–26, July 1995.

[2] Pierre Roux. Innocuous Double Rounding of Basic Arithmetic
Operations. Journal of Formalized Reasoning, ASDD-AlmaDL, 2014, 7 (1),
pp.131-142. 10.6092/issn.1972-5787/4359. hal-01091186

-- 
Andrew Haley  (he/him)
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
https://keybase.io/andrewhaley
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671



More information about the hotspot-compiler-dev mailing list