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 org.junit.*;
  27 
  28 import com.oracle.graal.compiler.hsail.test.infra.*;
  29 
  30 /**
  31  * This was a version of Mandel Test that happened to generate a Nan and so was useful for testing
  32  * ordered and unordered comparison. However, we should probably replace this with a test (or set of
  33  * tests) that is more focussed on Nan and comparisons.
  34  */
  35 public class FcompUnorderedTest extends GraalKernelTester {
  36 
  37     static final int initialWidth = 5;
  38     static final int initialHeight = initialWidth;
  39     static final int range = 25;
  40     @Result private int[] rgb = new int[range];
  41     private float[] lxresult = new float[range];
  42 
  43     public static void run(int[] rgb, float xoffset, float yoffset, float scale, int gid) {
  44         final int width = initialWidth;
  45         final int height = initialHeight;
  46         final int maxIterations = 64;
  47         float lx = (((gid % width * scale) - ((scale / 2) * width)) / width) + xoffset;
  48         float ly = (((gid / width * scale) - ((scale / 2) * height)) / height) + yoffset;
  49         int count = 0;
  50         float zx = lx;
  51         float zy = ly;
  52         float newzx = 0f;
  53         /**
  54          * Iterate until the algorithm converges or until maxIterations are reached.
  55          */
  56         while (count < maxIterations && zx < 8) {
  57             newzx = zx * zx - zy * zy + lx;
  58             zy = 2 * zx * zy + ly;
  59             zx = newzx;
  60             count++;
  61         }
  62         rgb[gid] = count;
  63     }
  64 
  65     void setupPalette(int[] in) {
  66         for (int i = 0; i < in.length; i++) {
  67             in[i] = i;
  68         }
  69     }
  70 
  71     @Override
  72     public void runTest() {
  73         int[] palette = new int[256];
  74         setupPalette(palette);
  75         for (int i = 0; i < range; i++) {
  76             lxresult[i] = -1;
  77         }
  78         /*
  79          * Call it for a range, specifying testmethod args (but not the fields it uses or the gid
  80          * argument).
  81          */
  82         dispatchMethodKernel(range, rgb, 1.0f, 1.0f, 1.0f);
  83     }
  84 
  85     @Test
  86     public void test() {
  87         testGeneratedHsail();
  88     }
  89 
  90 }