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 
  28 import com.oracle.graal.compiler.hsail.test.infra.*;
  29 
  30 /**
  31  * Tests integer to float conversion.
  32  */
  33 public class IntFloatConvertTest extends GraalKernelTester {
  34 
  35     static final int size = 128;
  36     static final int[] inputInt = new int[size];
  37     static final double[] inputDouble = new double[size];
  38     @Result static final int[] outputInt = new int[size];
  39     @Result static final double[] outputDouble = new double[size];
  40     static int[] seedInt = new int[size];
  41     {
  42         for (int i = 0; i < seedInt.length; i++) {
  43             seedInt[i] = (int) 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(int[] inInt, double[] inDouble, int[] outInt, double[] outDouble, int gid) {
  54         outInt[gid] = (int) inDouble[gid];
  55         outDouble[gid] = inInt[gid];
  56     }
  57 
  58     @Override
  59     public void runTest() {
  60         System.arraycopy(seedDouble, 0, inputDouble, 0, seedDouble.length);
  61         Arrays.fill(outputDouble, 0);
  62         System.arraycopy(seedInt, 0, inputInt, 0, seedInt.length);
  63         Arrays.fill(outputInt, 0);
  64         dispatchMethodKernel(64, inputInt, inputDouble, outputInt, outputDouble);
  65     }
  66 
  67     public void test() {
  68         super.testGeneratedHsail();
  69     }
  70 
  71 }