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 package com.oracle.graal.compiler.hsail.test;
  24 
  25 import java.util.*;
  26 
  27 import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester;
  28 import org.junit.Test;
  29 
  30 /**
  31  * Tests the spilling of integers into memory.
  32  */
  33 public class StaticIntSpillTest extends GraalKernelTester {
  34 
  35     static final int size = 100;
  36     private int[] in = new int[size * 400];
  37     @Result private int[] out = new int[size * 400];
  38 
  39     public static void run(int[] out, int[] in, int gid) {
  40         int id = gid;
  41         int step = 20;
  42         int sum0;
  43         int sum1;
  44         int sum2;
  45         int sum3;
  46         int sum4;
  47         int sum5;
  48         int sum6;
  49         int sum7;
  50         int sum8;
  51         int sum9;
  52         sum0 = sum1 = sum2 = sum3 = sum4 = sum5 = sum6 = sum7 = sum8 = sum9 = 0;
  53         for (int i = 0; i < size; i += step) {
  54             sum0 += in[i + 0];
  55             sum1 += in[i + 1];
  56             sum2 += in[i + 2];
  57             sum3 += in[i + 3];
  58             sum4 += in[i + 4];
  59             sum5 += in[i + 5];
  60             sum6 += in[i + 6];
  61             sum7 += in[i + 7];
  62             sum8 += in[i + 8];
  63             sum9 += in[i + 9];
  64         }
  65         out[id * step + 0] = sum0;
  66         out[id * step + 1] = sum1;
  67         out[id * step + 2] = sum2;
  68         out[id * step + 3] = sum3;
  69         out[id * step + 4] = sum4;
  70         out[id * step + 5] = sum5;
  71         out[id * step + 6] = sum6;
  72         out[id * step + 7] = sum7;
  73         out[id * step + 8] = sum8;
  74         out[id * step + 9] = sum9;
  75     }
  76 
  77     @Override
  78     public void runTest() {
  79         /**
  80          * Call it for a range, specifying testmethod args (but not the fields it uses or the gid
  81          * argument).
  82          * 
  83          */
  84         Arrays.fill(out, 0);
  85         Arrays.fill(in, 0);
  86         dispatchMethodKernel(size, out, in);
  87     }
  88 
  89     // Marked to only run on hardware until simulator spill bug is fixed.
  90     @Test
  91     public void test() {
  92         testGeneratedHsail();
  93     }
  94 
  95 }