1 /*
   2  * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package com.oracle.graal.compiler.hsail.test;
  25 
  26 import java.util.*;
  27 import org.junit.*;
  28 import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester;
  29 
  30 /**
  31  * Tests floating point comparison.
  32  */
  33 public class FloatConvertTest extends GraalKernelTester {
  34 
  35     static final int size = 128;
  36     static final float[] inputFloat = new float[size];
  37     static final double[] inputDouble = new double[size];
  38     @Result static final float[] outputFloat = new float[size];
  39     @Result static final double[] outputDouble = new double[size];
  40     static float[] seedFloat = new float[size];
  41     {
  42         for (int i = 0; i < seedFloat.length; i++) {
  43             seedFloat[i] = (float) Math.random();
  44         }
  45     }
  46     static double[] seedDouble = new double[size];
  47     {
  48         for (int i = 0; i < seedDouble.length; i++) {
  49             seedDouble[i] = Math.random();
  50         }
  51     }
  52 
  53     public static void run(float[] inFloat, double[] inDouble, float[] outFloat, double[] outDouble, int gid) {
  54         outFloat[gid] = (float) inDouble[gid];
  55         outDouble[gid] = inFloat[gid];
  56     }
  57 
  58     @Override
  59     public void runTest() {
  60         System.arraycopy(seedDouble, 0, inputDouble, 0, seedDouble.length);
  61         Arrays.fill(outputDouble, 0f);
  62         System.arraycopy(seedFloat, 0, inputFloat, 0, seedFloat.length);
  63         Arrays.fill(outputFloat, 0f);
  64         dispatchMethodKernel(64, inputFloat, inputDouble, outputFloat, outputDouble);
  65     }
  66 
  67     @Test
  68     public void test() {
  69         testGeneratedHsail();
  70     }
  71 }