hotspot/test/compiler/loopopts/superword/SumRedAbsNeg_Float.java
author enevill
Wed, 30 Sep 2015 04:35:39 -0400
changeset 33088 34fe49ecee13
child 40059 c2304140ed64
permissions -rw-r--r--
8138583: aarch64: add support for vectorizing fabs/fneg Reviewed-by: aph, roland Contributed-by: felix.yang@linaro.org
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33088
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
     1
/*
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
     4
 *
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
     7
 * published by the Free Software Foundation.
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
     8
 *
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    13
 * accompanied this code).
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    14
 *
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    18
 *
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    21
 * questions.
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    22
 *
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    23
 */
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    24
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    25
/**
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    26
 * @test
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    27
 * @bug 8138583
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    28
 * @summary Add C2 AArch64 Superword support for scalar sum reduction optimizations : float abs & neg test
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    29
 * @requires os.arch=="aarch64"
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    30
 *
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    31
 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+SuperWordReductions -XX:LoopUnrollLimit=250 -XX:LoopMaxUnroll=2 -XX:CompileThresholdScaling=0.1 SumRedAbsNeg_Float
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    32
 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-SuperWordReductions -XX:LoopUnrollLimit=250 -XX:LoopMaxUnroll=2 -XX:CompileThresholdScaling=0.1 SumRedAbsNeg_Float
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    33
 *
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    34
 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+SuperWordReductions -XX:LoopUnrollLimit=250 -XX:LoopMaxUnroll=4 -XX:CompileThresholdScaling=0.1 SumRedAbsNeg_Float
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    35
 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-SuperWordReductions -XX:LoopUnrollLimit=250 -XX:LoopMaxUnroll=4 -XX:CompileThresholdScaling=0.1 SumRedAbsNeg_Float
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    36
 *
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    37
 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+SuperWordReductions -XX:LoopUnrollLimit=250 -XX:LoopMaxUnroll=8 -XX:CompileThresholdScaling=0.1 SumRedAbsNeg_Float
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    38
 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-SuperWordReductions -XX:LoopUnrollLimit=250 -XX:LoopMaxUnroll=8 -XX:CompileThresholdScaling=0.1 SumRedAbsNeg_Float
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    39
 *
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    40
 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+SuperWordReductions -XX:LoopUnrollLimit=250 -XX:LoopMaxUnroll=16 -XX:CompileThresholdScaling=0.1 SumRedAbsNeg_Float
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    41
 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-SuperWordReductions -XX:LoopUnrollLimit=250 -XX:LoopMaxUnroll=16 -XX:CompileThresholdScaling=0.1 SumRedAbsNeg_Float
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    42
 */
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    43
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    44
public class SumRedAbsNeg_Float
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    45
{
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    46
  public static void main(String[] args) throws Exception {
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    47
    float[] a = new float[256*1024];
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    48
    float[] b = new float[256*1024];
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    49
    float[] c = new float[256*1024];
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    50
    float[] d = new float[256*1024];
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    51
    sumReductionInit(a,b,c);
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    52
    float total = 0;
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    53
    float valid = (float)4.611686E18;
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    54
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    55
    for(int j = 0; j < 2000; j++) {
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    56
      total = sumReductionImplement(a,b,c,d,total);
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    57
    }
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    58
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    59
    if(total == valid) {
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    60
      System.out.println("Success");
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    61
    } else {
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    62
      System.out.println("Invalid sum of elements variable in total: " + total);
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    63
      System.out.println("Expected value = " + valid);
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    64
      throw new Exception("Failed");
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    65
    }
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    66
  }
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    67
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    68
  public static void sumReductionInit(
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    69
    float[] a,
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    70
    float[] b,
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    71
    float[] c)
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    72
  {
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    73
    for(int j = 0; j < 1; j++)
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    74
    {
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    75
      for(int i = 0; i < a.length; i++)
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    76
      {
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    77
        a[i] = i * 1 + j;
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    78
        b[i] = i * 1 - j;
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    79
        c[i] = i + j;
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    80
      }
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    81
    }
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    82
  }
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    83
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    84
  public static float sumReductionImplement(
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    85
    float[] a,
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    86
    float[] b,
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    87
    float[] c,
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    88
    float[] d,
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    89
    float total)
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    90
  {
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    91
    for(int i = 0; i < a.length; i++)
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    92
    {
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    93
      d[i] = Math.abs(-a[i] * -b[i]) + Math.abs(-a[i] * -c[i]) + Math.abs(-b[i] * -c[i]);
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    94
      total += d[i];
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    95
    }
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    96
    return total;
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    97
  }
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    98
34fe49ecee13 8138583: aarch64: add support for vectorizing fabs/fneg
enevill
parents:
diff changeset
    99
}