changeset 13308:d3b3c6e17d40

HSAIL: added Math intrinsifications Contributed-by: Vasanth Venkatachalam <Vasanth.Venkatachalam@amd.com>
author Doug Simon <doug.simon@oracle.com>
date Fri, 13 Dec 2013 10:44:09 +0100
parents c9dd3d5000e8
children 32d2b0de15a8 30e57b49fdb1
files graal/com.oracle.graal.compiler.hsail.test.infra/src/com/oracle/graal/compiler/hsail/test/infra/KernelTester.java graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/DoubleAbsTest.java graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/DoubleCeilTest.java graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/DoubleFloorTest.java graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/DoubleRintTest.java graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/DoubleSqrtTest.java graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/FloatAbsTest.java graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/FloatDivPrecisionTest.java graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/FloatSqrtTest.java graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntAbsTest.java graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongAbsTest.java graal/com.oracle.graal.compiler.hsail/src/com/oracle/graal/compiler/hsail/HSAILLIRGenerator.java graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotBackend.java graal/com.oracle.graal.lir.hsail/src/com/oracle/graal/lir/hsail/HSAILArithmetic.java graal/com.oracle.graal.replacements.hsail/src/com/oracle/graal/replacements/hsail/HSAILMathIntrinsicsNode.java graal/com.oracle.graal.replacements.hsail/src/com/oracle/graal/replacements/hsail/HSAILMathSubstitutions.java mx/projects
diffstat 17 files changed, 1140 insertions(+), 70 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.hsail.test.infra/src/com/oracle/graal/compiler/hsail/test/infra/KernelTester.java	Fri Dec 13 10:39:15 2013 +0100
+++ b/graal/com.oracle.graal.compiler.hsail.test.infra/src/com/oracle/graal/compiler/hsail/test/infra/KernelTester.java	Fri Dec 13 10:44:09 2013 +0100
@@ -280,10 +280,13 @@
     }
 
     /**
-     * This isEqualsFP method allows subclass to override what FP equality means for this particular
-     * unit test.
+     * Tests two floating point values for equality.
      */
     public boolean isEqualsFP(double first, double second) {
+        // Special case for checking whether expected and actual values are both NaNs.
+        if (Double.isNaN(first) && Double.isNaN(second)) {
+            return true;
+        }
         return first == second;
     }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/DoubleAbsTest.java	Fri Dec 13 10:44:09 2013 +0100
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.oracle.graal.compiler.hsail.test;
+
+import org.junit.Test;
+import com.oracle.graal.compiler.hsail.test.infra.*;
+
+/**
+ * Tests intrinsic for calls to Math.abs(double). Generates a abs_f64 instruction.
+ */
+public class DoubleAbsTest extends GraalKernelTester {
+
+    static final int num = 40;
+    // Output array storing the results of calling Math.abs().
+    @Result protected double[] outArray = new double[num];
+
+    /**
+     * The static "kernel" method we will be testing. This method calls Math.abs() on an element of
+     * an input array and writes the result to the corresponding index of an output array. By
+     * convention the gid is the last parameter.
+     * 
+     * @param out the output array.
+     * @param ina the input array.
+     * @param gid the parameter used to index into the input and output arrays.
+     */
+    public static void run(double[] out, double[] ina, int gid) {
+        out[gid] = Math.abs(ina[gid]);
+    }
+
+    /**
+     * Tests the HSAIL code generated for this unit test by comparing the result of executing this
+     * code with the result of executing a sequential Java version of this unit test.
+     */
+    @Test
+    public void test() {
+        super.testGeneratedHsail();
+    }
+
+    /**
+     * Initializes the input and output arrays passed to the run routine.
+     * 
+     * @param in the input array.
+     */
+    void setupArrays(double[] in) {
+        for (int i = 0; i < num; i++) {
+            // Include positive and negative values as well as corner cases.
+            if (i == 1) {
+                in[i] = Double.NaN;
+            } else if (i == 2) {
+                in[i] = Double.NEGATIVE_INFINITY;
+            } else if (i == 3) {
+                in[i] = Double.POSITIVE_INFINITY;
+            } else if (i == 4) {
+                in[i] = -0.0;
+            } else {
+                in[i] = i < num / 2 ? i : -i;
+            }
+            outArray[i] = 0;
+        }
+    }
+
+    /**
+     * Dispatches the HSAIL kernel for this test case.
+     */
+    @Override
+    public void runTest() {
+        double[] inArray = new double[num];
+        setupArrays(inArray);
+        dispatchMethodKernel(num, outArray, inArray);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/DoubleCeilTest.java	Fri Dec 13 10:44:09 2013 +0100
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.oracle.graal.compiler.hsail.test;
+
+import org.junit.Test;
+import com.oracle.graal.compiler.hsail.test.infra.*;
+
+/**
+ * Tests intrinsic for calls to Math.ceil(). Generates a ceil_f64 instruction.
+ */
+public class DoubleCeilTest extends GraalKernelTester {
+
+    static final int num = 40;
+    // Output array storing the results.
+    @Result protected double[] outArray = new double[num];
+
+    /**
+     * The static "kernel" method we will be testing. This method calls Math.ceil() on an element of
+     * an input array and writes the result to the corresponding index of an output array. By
+     * convention the gid is the last parameter.
+     * 
+     * @param out the output array.
+     * @param ina the input array.
+     * @param gid the parameter used to index into the input and output arrays.
+     */
+    public static void run(double[] out, double[] ina, int gid) {
+        out[gid] = Math.ceil(ina[gid]);
+    }
+
+    /**
+     * Tests the HSAIL code generated for this unit test by comparing the result of executing this
+     * code with the result of executing a sequential Java version of this unit test.
+     */
+    @Test
+    public void test() {
+        super.testGeneratedHsail();
+    }
+
+    /**
+     * Initializes the input and output arrays passed to the run routine.
+     * 
+     * @param in the input array.
+     */
+    void setupArrays(double[] in) {
+        // Initialize arrays with a mix of positive and negativ values and any corner cases.
+        for (int i = 0; i < num; i++) {
+            if (i == 0) {
+                in[i] = 0.0;
+            } else if (i == 1) {
+                in[i] = -0.0;
+            } else if (i == 2) {
+                in[i] = Double.NaN;
+            } else if (i == 3) {
+                in[i] = Double.NEGATIVE_INFINITY;
+            } else if (i == 4) {
+                in[i] = Double.POSITIVE_INFINITY;
+            } else {
+                in[i] = i < num / 2 ? i + 0.5 : -i - 0.5;
+            }
+            outArray[i] = 0;
+        }
+    }
+
+    /**
+     * Dispatches the HSAIL kernel for this test case.
+     */
+    @Override
+    public void runTest() {
+        double[] inArray = new double[num];
+        setupArrays(inArray);
+        dispatchMethodKernel(num, outArray, inArray);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/DoubleFloorTest.java	Fri Dec 13 10:44:09 2013 +0100
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.oracle.graal.compiler.hsail.test;
+
+import org.junit.Test;
+import com.oracle.graal.compiler.hsail.test.infra.*;
+
+/**
+ * Tests intrinsic for calls to Math.floor(). Generates a floor_f64 instruction.
+ */
+public class DoubleFloorTest extends GraalKernelTester {
+
+    static final int num = 40;
+    // Output array storing the results.
+    @Result protected double[] outArray = new double[num];
+
+    /**
+     * The static "kernel" method we will be testing. This method calls Math.floor() on an element
+     * of an input array and writes the result to the corresponding index of an output array. By
+     * convention the gid is the last parameter.
+     * 
+     * @param out the output array.
+     * @param ina the input array.
+     * @param gid the parameter used to index into the input and output arrays.
+     */
+    public static void run(double[] out, double[] ina, int gid) {
+        out[gid] = Math.floor(ina[gid]);
+    }
+
+    /**
+     * Tests the HSAIL code generated for this unit test by comparing the result of executing this
+     * code with the result of executing a sequential Java version of this unit test.
+     */
+    @Test
+    public void test() {
+        super.testGeneratedHsail();
+    }
+
+    /**
+     * Initializes the input and output arrays passed to the run routine.
+     * 
+     * @param in the input array.
+     */
+    void setupArrays(double[] in) {
+        // Initialize input array with a mix of positive and negative values and any corner cases.
+        for (int i = 0; i < num; i++) {
+            if (i == 0) {
+                in[i] = 0.0;
+            } else if (i == 1) {
+                in[i] = -0.0;
+            } else if (i == 2) {
+                in[i] = Double.NaN;
+            } else if (i == 3) {
+                in[i] = Double.NEGATIVE_INFINITY;
+            } else if (i == 4) {
+                in[i] = Double.POSITIVE_INFINITY;
+            } else {
+                in[i] = i < num / 2 ? i + 0.5 : -i - 0.5;
+            }
+            outArray[i] = 0;
+        }
+    }
+
+    /**
+     * Dispatches the HSAIL kernel for this test case.
+     */
+    @Override
+    public void runTest() {
+        double[] inArray = new double[num];
+        setupArrays(inArray);
+        dispatchMethodKernel(num, outArray, inArray);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/DoubleRintTest.java	Fri Dec 13 10:44:09 2013 +0100
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.oracle.graal.compiler.hsail.test;
+
+import org.junit.*;
+
+import com.oracle.graal.compiler.hsail.test.infra.*;
+
+/**
+ * Tests intrinsic for Math.rint(). Generates an rint_f64 instruction.
+ */
+public class DoubleRintTest extends GraalKernelTester {
+
+    static final int size = 64;
+    @Result double[] out = new double[size];
+
+    /**
+     * The static "kernel" method we will be testing. This method calls Math.rint() on an element of
+     * an input array and writes the result to the corresponding index of an output array. By
+     * convention the gid is the last parameter.
+     * 
+     * @param out the output array.
+     * @param in the input array.
+     * @param gid the parameter used to index into the input and output arrays.
+     */
+    public static void run(double[] out, double[] in, int gid) {
+        out[gid] = Math.rint(in[gid]);
+    }
+
+    /**
+     * Initialize input arrays.
+     * 
+     * @param in the input array
+     */
+    void setupArrays(double[] in) {
+        // Initialize input array with a mix of positive and negative values and corner cases.
+        for (int i = 0; i < size; i++) {
+            if (i == 1) {
+                in[i] = Double.NaN;
+            } else if (i == 2) {
+                in[i] = Double.NEGATIVE_INFINITY;
+            } else if (i == 3) {
+                in[i] = Double.POSITIVE_INFINITY;
+
+            } else if (i == 4) {
+                in[i] = 0.0;
+            } else if (i == 5) {
+                in[i] = -0.0;
+            } else {
+                in[i] = i < size / 2 ? i + 0.5 : -i - 0.6;
+            }
+            out[i] = 0;
+        }
+    }
+
+    /**
+     * Dispatches the HSAIL kernel for this test case.
+     */
+    @Override
+    public void runTest() {
+        double[] inArray = new double[size];
+        setupArrays(inArray);
+        dispatchMethodKernel(size, out, inArray);
+    }
+
+    /**
+     * Tests the HSAIL code generated for this unit test by comparing the result of executing this
+     * code with the result of executing a sequential Java version of this unit test.
+     */
+    @Test
+    public void test() {
+        testGeneratedHsail();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/DoubleSqrtTest.java	Fri Dec 13 10:44:09 2013 +0100
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.oracle.graal.compiler.hsail.test;
+
+import org.junit.*;
+
+import com.oracle.graal.compiler.hsail.test.infra.*;
+
+/**
+ * Tests intrinsic for call to Math.sqrt(double). Generates a sqrt_f64 instruction.
+ */
+public class DoubleSqrtTest extends GraalKernelTester {
+
+    static final int size = 64;
+    @Result double[] out = new double[size];
+
+    /**
+     * The static "kernel" method we will be testing. This method calls Math.sqrt() on an element of
+     * an input array and writes the result to the corresponding index of an output array. By
+     * convention the gid is the last parameter.
+     * 
+     * @param out the output array.
+     * @param in the input array.
+     * @param gid the parameter used to index into the input and output arrays.
+     */
+    public static void run(double[] in, double[] out, int gid) {
+        out[gid] = Math.sqrt(in[gid]);
+    }
+
+    /**
+     * Initializes the input and output arrays passed to the run routine.
+     * 
+     * @param in the input array.
+     */
+    void setupArrays(double[] in) {
+        for (int i = 0; i < size; i++) {
+            // Include positive and negative values as well as corner cases.
+            if (i == 1) {
+                in[i] = Double.NaN;
+            } else if (i == 2) {
+                in[i] = Double.NEGATIVE_INFINITY;
+            } else if (i == 3) {
+                in[i] = Double.POSITIVE_INFINITY;
+            } else if (i == 4) {
+                in[i] = -0.0;
+            } else if (i > 5 && i < 10) {
+                in[i] = i + 0.5;
+            } else {
+                in[i] = i < size / 2 ? i : -i;
+            }
+            out[i] = 0;
+        }
+    }
+
+    /**
+     * Dispatches the HSAIL kernel for this test case.
+     */
+    @Override
+    public void runTest() {
+        double[] inArray = new double[size];
+        setupArrays(inArray);
+        dispatchMethodKernel(size, inArray, out);
+    }
+
+    /**
+     * Tests the HSAIL code generated for this unit test by comparing the result of executing this
+     * code with the result of executing a sequential Java version of this unit test.
+     */
+    @Test
+    public void test() {
+        testGeneratedHsail();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/FloatAbsTest.java	Fri Dec 13 10:44:09 2013 +0100
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.oracle.graal.compiler.hsail.test;
+
+import org.junit.Test;
+import com.oracle.graal.compiler.hsail.test.infra.*;
+
+/**
+ * Tests intrinsic for calls to Math.abs(float). Generates an abs_f32 instruction.
+ */
+public class FloatAbsTest extends GraalKernelTester {
+
+    static final int num = 40;
+    // Output array storing the results of calling Math.abs().
+    @Result protected float[] outArray = new float[num];
+
+    /**
+     * The static "kernel" method we will be testing. This method calls Math.abs() on an element of
+     * an input array and writes the result to the corresponding index of an output array. By
+     * convention the gid is the last parameter.
+     * 
+     * @param out the output array.
+     * @param ina the input array.
+     * @param gid the parameter used to index into the input and output arrays.
+     */
+    public static void run(float[] out, float[] ina, int gid) {
+        out[gid] = Math.abs(ina[gid]);
+    }
+
+    /**
+     * Tests the HSAIL code generated for this unit test by comparing the result of executing this
+     * code with the result of executing a sequential Java version of this unit test.
+     */
+    @Test
+    public void test() {
+        super.testGeneratedHsail();
+    }
+
+    /**
+     * Initializes the input and output arrays passed to the run routine.
+     * 
+     * @param in the input array.
+     */
+    void setupArrays(float[] in) {
+        for (int i = 0; i < num; i++) {
+            // Initialize array with positive and negative values as well as corner cases.
+            if (i == 1) {
+                in[i] = Float.NaN;
+            } else if (i == 2) {
+                in[i] = Float.NEGATIVE_INFINITY;
+            } else if (i == 3) {
+                in[i] = Float.POSITIVE_INFINITY;
+            } else if (i == 4) {
+                in[i] = -0;
+            } else {
+                in[i] = i < num / 2 ? i : -i;
+            }
+            outArray[i] = 0;
+        }
+    }
+
+    /**
+     * Dispatches the HSAIL kernel for this test case.
+     */
+    @Override
+    public void runTest() {
+        float[] inArray = new float[num];
+        setupArrays(inArray);
+        dispatchMethodKernel(num, outArray, inArray);
+    }
+}
--- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/FloatDivPrecisionTest.java	Fri Dec 13 10:39:15 2013 +0100
+++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/FloatDivPrecisionTest.java	Fri Dec 13 10:44:09 2013 +0100
@@ -47,10 +47,6 @@
 
     }
 
-    /**
-     * Allows subclass to override what FP equality means for this particular unit test.
-     * 
-     */
     @Override
     public boolean isEqualsFP(double first, double second) {
         return Math.abs(first - second) == 0;
--- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/FloatSqrtTest.java	Fri Dec 13 10:39:15 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,59 +0,0 @@
-/*
- * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package com.oracle.graal.compiler.hsail.test;
-
-import org.junit.*;
-
-import com.oracle.graal.compiler.hsail.test.infra.*;
-
-/**
- * Tests floating point square root.
- */
-public class FloatSqrtTest extends GraalKernelTester {
-
-    static final int size = 64;
-    float[] input = new float[size];
-    @Result float[] output = new float[size];
-    {
-        for (int i = 0; i < size; i++) {
-            input[i] = i;
-            output[i] = -1.0f;
-        }
-
-    }
-
-    public static void run(float[] input1, float[] output1, int gid) {
-        output1[gid] = (float) Math.sqrt(input1[gid]);
-    }
-
-    @Override
-    public void runTest() {
-        dispatchMethodKernel(size, input, output);
-    }
-
-    @Test
-    public void test() {
-        testGeneratedHsail();
-    }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntAbsTest.java	Fri Dec 13 10:44:09 2013 +0100
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.oracle.graal.compiler.hsail.test;
+
+import org.junit.Test;
+import com.oracle.graal.compiler.hsail.test.infra.*;
+
+/**
+ * Tests intrinsic for call to Math.abs(int). Generates an abs_s32 instruction.
+ */
+public class IntAbsTest extends GraalKernelTester {
+
+    static final int num = 20;
+    // Output array storing the results of negation operations.
+    @Result protected int[] outArray = new int[num];
+
+    /**
+     * The static "kernel" method we will be testing. This method calls Math.abs( ) on an element of
+     * an input array and writes the result to the corresponding index of an output array. By
+     * convention the gid is the last parameter.
+     * 
+     * @param out the output array.
+     * @param ina the input array.
+     * @param gid the parameter used to index into the input and output arrays.
+     */
+    public static void run(int[] out, int[] ina, int gid) {
+        out[gid] = Math.abs(ina[gid]);
+    }
+
+    /**
+     * Tests the HSAIL code generated for this unit test by comparing the result of executing this
+     * code with the result of executing a sequential Java version of this unit test.
+     */
+    @Test
+    public void test() {
+        super.testGeneratedHsail();
+    }
+
+    /**
+     * Initializes the input and output arrays passed to the run routine.
+     * 
+     * @param in the input array.
+     */
+    void setupArrays(int[] in) {
+        // initialize input array with a mix of positive and negative values and any corner cases.
+        for (int i = 0; i < num; i++) {
+            if (i == 1) {
+                in[i] = Integer.MIN_VALUE;
+            } else {
+                in[i] = i < num / 2 ? i : -i;
+            }
+            outArray[i] = 0;
+        }
+    }
+
+    /**
+     * Dispatches the HSAIL kernel for this test case.
+     */
+    @Override
+    public void runTest() {
+        int[] inArray = new int[num];
+        setupArrays(inArray);
+        dispatchMethodKernel(num, outArray, inArray);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongAbsTest.java	Fri Dec 13 10:44:09 2013 +0100
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.oracle.graal.compiler.hsail.test;
+
+import org.junit.Test;
+import com.oracle.graal.compiler.hsail.test.infra.*;
+
+/**
+ * Tests intrinsic for call to Math.abs(long). Generates an abs_s64 instruction.
+ */
+public class LongAbsTest extends GraalKernelTester {
+
+    static final int num = 20;
+    // Output array storing the results of the operations.
+    @Result protected long[] outArray = new long[num];
+
+    /**
+     * The static "kernel" method we will be testing. This method calls Math.abs( ) on an element of
+     * an input array and writes the result to the corresponding index of an output array. By
+     * convention the gid is the last parameter.
+     * 
+     * @param out the output array.
+     * @param ina the input array.
+     * @param gid the parameter used to index into the input and output arrays.
+     */
+    public static void run(long[] out, long[] ina, int gid) {
+        out[gid] = Math.abs(ina[gid]);
+    }
+
+    /**
+     * Tests the HSAIL code generated for this unit test by comparing the result of executing this
+     * code with the result of executing a sequential Java version of this unit test.
+     */
+    @Test
+    public void test() {
+        super.testGeneratedHsail();
+    }
+
+    /**
+     * Initializes the input and output arrays passed to the run routine.
+     * 
+     * @param in the input array.
+     */
+    void setupArrays(long[] in) {
+        // Initialize input array with a mix of positive and negative values and any corner cases.
+        for (int i = 0; i < num; i++) {
+            if (i == 1) {
+                in[i] = Long.MIN_VALUE;
+            } else {
+                in[i] = i < num / 2 ? i : -i;
+            }
+            outArray[i] = 0;
+        }
+    }
+
+    /**
+     * Dispatches the HSAIL kernel for this test case.
+     */
+    @Override
+    public void runTest() {
+        long[] inArray = new long[num];
+        setupArrays(inArray);
+        dispatchMethodKernel(num, outArray, inArray);
+    }
+}
--- a/graal/com.oracle.graal.compiler.hsail/src/com/oracle/graal/compiler/hsail/HSAILLIRGenerator.java	Fri Dec 13 10:39:15 2013 +0100
+++ b/graal/com.oracle.graal.compiler.hsail/src/com/oracle/graal/compiler/hsail/HSAILLIRGenerator.java	Fri Dec 13 10:44:09 2013 +0100
@@ -646,11 +646,61 @@
         throw GraalInternalError.unimplemented();
     }
 
+    /**
+     * Emits the LIR code for the {@link HSAILArithmetic#ABS} operation.
+     * 
+     * @param input the source operand
+     * @return Value representing the result of the operation
+     */
     @Override
     public Value emitMathAbs(Value input) {
-        throw GraalInternalError.unimplemented();
+        Variable result = newVariable(input.getPlatformKind());
+        append(new Op1Stack(ABS, result, input));
+        return result;
+    }
+
+    /**
+     * Emits the LIR code for the {@link HSAILArithmetic#CEIL} operation.
+     * 
+     * @param input the source operand
+     * @return Value representing the result of the operation
+     */
+    public Value emitMathCeil(Value input) {
+        Variable result = newVariable(input.getPlatformKind());
+        append(new Op1Stack(CEIL, result, input));
+        return result;
     }
 
+    /**
+     * Emits the LIR code for the {@link HSAILArithmetic#FLOOR} operation.
+     * 
+     * @param input the source operand
+     * @return Value representing the result of the operation
+     */
+    public Value emitMathFloor(Value input) {
+        Variable result = newVariable(input.getPlatformKind());
+        append(new Op1Stack(FLOOR, result, input));
+        return result;
+    }
+
+    /**
+     * Emits the LIR code for the {@link HSAILArithmetic#RINT} operation.
+     * 
+     * @param input the source operand
+     * @return Value representing the result of the operation
+     */
+    public Value emitMathRint(Value input) {
+        Variable result = newVariable(input.getPlatformKind());
+        append(new Op1Stack(RINT, result, input));
+        return result;
+    }
+
+    /**
+     * Emits the LIR code for the {@link HSAILArithmetic#SQRT} operation.
+     * 
+     * @param input the source operand
+     * @return value representing the result of the operation
+     */
     @Override
     public Value emitMathSqrt(Value input) {
         Variable result = newVariable(input.getPlatformKind());
--- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotBackend.java	Fri Dec 13 10:39:15 2013 +0100
+++ b/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotBackend.java	Fri Dec 13 10:44:09 2013 +0100
@@ -41,6 +41,8 @@
 import com.oracle.graal.lir.asm.*;
 import com.oracle.graal.lir.hsail.*;
 import com.oracle.graal.nodes.*;
+import com.oracle.graal.nodes.spi.Replacements;
+import com.oracle.graal.replacements.hsail.*;
 
 /**
  * HSAIL specific backend.
@@ -63,12 +65,23 @@
         return true;
     }
 
+    /**
+     * Completes the initialization of the HSAIL backend. This includes initializing the providers
+     * and registering any method substitutions specified by the HSAIL backend.
+     */
     @Override
     public void completeInitialization() {
         final HotSpotProviders providers = getProviders();
         HotSpotVMConfig config = getRuntime().getConfig();
+        // Initialize the lowering provider.
         final HotSpotLoweringProvider lowerer = (HotSpotLoweringProvider) providers.getLowerer();
         lowerer.initialize(providers, config);
+
+        // Register the replacements used by the HSAIL backend.
+        Replacements replacements = providers.getReplacements();
+
+        // Register the substitutions for java.lang.Math routines.
+        replacements.registerSubstitutions(HSAILMathSubstitutions.class);
     }
 
     /**
--- a/graal/com.oracle.graal.lir.hsail/src/com/oracle/graal/lir/hsail/HSAILArithmetic.java	Fri Dec 13 10:39:15 2013 +0100
+++ b/graal/com.oracle.graal.lir.hsail/src/com/oracle/graal/lir/hsail/HSAILArithmetic.java	Fri Dec 13 10:44:09 2013 +0100
@@ -29,14 +29,17 @@
 import com.oracle.graal.asm.hsail.*;
 import com.oracle.graal.graph.*;
 import com.oracle.graal.lir.*;
-import com.oracle.graal.lir.asm.*;
+import com.oracle.graal.lir.asm.CompilationResultBuilder;
 
 /**
  * Defines arithmetic instruction nodes.
  */
 public enum HSAILArithmetic {
+    ABS,
     CALL,
+    CEIL,
     FDIV,
+    FLOOR,
     FREM,
     DADD,
     DDIV,
@@ -97,6 +100,7 @@
     LUSUB,
     LXOR,
     OADD,
+    RINT,
     SQRT,
     UNDEF;
 
@@ -289,10 +293,33 @@
         }
     }
 
+    /**
+     * Emits the HSAIL code for an arithmetic operation taking one input parameter.
+     * 
+     * @param crb the CompilationResultBuilder
+     * @param masm the HSAIL assembler
+     * @param opcode the opcode of the arithmetic operation
+     * @param dst the destination
+     * @param src the source parameter
+     * @param info structure that stores the LIRFrameState. Used for exception handling.
+     */
+
     public static void emit(CompilationResultBuilder crb, HSAILAssembler masm, HSAILArithmetic opcode, Value dst, Value src, LIRFrameState info) {
         int exceptionOffset = -1;
         if (isRegister(src)) {
             switch (opcode) {
+                case ABS:
+                    masm.emit("abs", dst, src);
+                    break;
+                case CEIL:
+                    masm.emit("ceil", dst, src);
+                    break;
+                case FLOOR:
+                    masm.emit("floor", dst, src);
+                    break;
+                case RINT:
+                    masm.emit("rint", dst, src);
+                    break;
                 case SQRT:
                     masm.emit("sqrt", dst, src);
                     break;
@@ -304,14 +331,12 @@
                     break;
                 case INOT:
                 case LNOT:
-                    // Emit the HSAIL instruction for a bitwise not.
                     masm.emitForceBitwise("not", dst, src);
                     break;
                 case INEG:
                 case LNEG:
                 case FNEG:
                 case DNEG:
-                    // Emit the HSAIL instruction for a negate operation.
                     masm.emit("neg", dst, src);
                     break;
                 default:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.replacements.hsail/src/com/oracle/graal/replacements/hsail/HSAILMathIntrinsicsNode.java	Fri Dec 13 10:44:09 2013 +0100
@@ -0,0 +1,178 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.replacements.hsail;
+
+import com.oracle.graal.api.meta.Constant;
+import com.oracle.graal.api.meta.Value;
+import com.oracle.graal.compiler.hsail.HSAILLIRGenerator;
+import com.oracle.graal.graph.GraalInternalError;
+import com.oracle.graal.graph.Node;
+import com.oracle.graal.graph.spi.Canonicalizable;
+import com.oracle.graal.graph.spi.CanonicalizerTool;
+import com.oracle.graal.lir.hsail.HSAILArithmetic;
+import com.oracle.graal.nodes.calc.FloatingNode;
+import com.oracle.graal.nodes.ConstantNode;
+import com.oracle.graal.nodes.ValueNode;
+import com.oracle.graal.nodes.spi.ArithmeticLIRGenerator;
+import com.oracle.graal.nodes.spi.ArithmeticLIRLowerable;
+import com.oracle.graal.nodes.type.StampFactory;
+
+/**
+ * This node implements HSAIL intrinsics for specific {@link Math} routines.
+ */
+public class HSAILMathIntrinsicsNode extends FloatingNode implements Canonicalizable, ArithmeticLIRLowerable {
+
+    /**
+     * The parameter passed to the math operation that this node represents.
+     */
+    @Input private ValueNode param;
+
+    /**
+     * The math operation that this Node represents.
+     */
+    private final HSAILArithmetic operation;
+
+    /**
+     * Gets the parameter passed to the math operation that this node represents.
+     * 
+     * @return the parameter
+     */
+    public ValueNode getParameter() {
+        return param;
+    }
+
+    /**
+     * Returns the math operation represented by this node.
+     * 
+     * @return the operation
+     */
+    public HSAILArithmetic operation() {
+        return operation;
+    }
+
+    /**
+     * Creates a new HSAILMathIntrinsicNode.
+     * 
+     * @param x the argument to the math operation
+     * @param op the math operation
+     */
+    public HSAILMathIntrinsicsNode(ValueNode x, HSAILArithmetic op) {
+        super(StampFactory.forKind(x.kind()));
+        this.param = x;
+        this.operation = op;
+    }
+
+    /**
+     * Generates the LIR instructions for the math operation represented by this node.
+     */
+    @Override
+    public void generate(ArithmeticLIRGenerator gen) {
+        Value input = gen.operand(getParameter());
+        Value result;
+        switch (operation()) {
+            case ABS:
+                result = gen.emitMathAbs(input);
+                break;
+            case CEIL:
+                result = ((HSAILLIRGenerator) (gen)).emitMathCeil(input);
+                break;
+            case FLOOR:
+                result = ((HSAILLIRGenerator) (gen)).emitMathFloor(input);
+                break;
+            case RINT:
+                result = ((HSAILLIRGenerator) (gen)).emitMathRint(input);
+                break;
+            case SQRT:
+                result = gen.emitMathSqrt(input);
+                break;
+
+            default:
+                throw GraalInternalError.shouldNotReachHere();
+        }
+        gen.setResult(this, result);
+    }
+
+    /**
+     * Converts a constant to a boxed double.
+     */
+    public Constant evalConst(Constant... inputs) {
+        assert inputs.length == 1;
+        return Constant.forDouble(compute(inputs[0].asDouble(), operation()));
+    }
+
+    /**
+     * Converts the result of the math operation to a boxed Double constant node.
+     */
+    @Override
+    public Node canonical(CanonicalizerTool tool) {
+        if (getParameter().isConstant()) {
+            return ConstantNode.forPrimitive(evalConst(getParameter().asConstant()), graph());
+        }
+        return this;
+    }
+
+    // The routines below are node intrinsics. A call to any of these routines is replaced by a
+    // HSAILMathIntrinsicNode to handle the Math library operation represented by the
+    // HSAILArithmetic argument.
+
+    /**
+     * Node intrinsic for {@link Math} routines taking a single int parameter.
+     * 
+     * @param value
+     * @param op the math operation
+     * @return the result of the operation
+     */
+    @NodeIntrinsic
+    public static native int compute(int value, @ConstantNodeParameter HSAILArithmetic op);
+
+    /**
+     * Node intrinsic for {@link Math} routines taking a single double parameter.
+     * 
+     * @param value the input parameter
+     * @param op the math operation
+     * @return the result of the operation
+     */
+    @NodeIntrinsic
+    public static native long compute(long value, @ConstantNodeParameter HSAILArithmetic op);
+
+    /**
+     * Node intrinsic for {@link Math} routines taking a single float parameter.
+     * 
+     * @param value the input parameter
+     * @param op the math operation
+     * @return the result of the operation
+     */
+    @NodeIntrinsic
+    public static native float compute(float value, @ConstantNodeParameter HSAILArithmetic op);
+
+    /**
+     * Node intrinsic for {@link Math} routines taking a single double parameter.
+     * 
+     * @param value the input parameter
+     * @param op the math operation
+     * 
+     * @return the result of the operation
+     */
+    @NodeIntrinsic
+    public static native double compute(double value, @ConstantNodeParameter HSAILArithmetic op);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.replacements.hsail/src/com/oracle/graal/replacements/hsail/HSAILMathSubstitutions.java	Fri Dec 13 10:44:09 2013 +0100
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.replacements.hsail;
+
+import com.oracle.graal.api.replacements.ClassSubstitution;
+import com.oracle.graal.api.replacements.MethodSubstitution;
+import com.oracle.graal.lir.hsail.HSAILArithmetic;
+
+/**
+ * Substitutions for {@link Math} methods. For any calls to the routines listed below and annotated
+ * with {@link MethodSubstitution}, Graal replaces the call with a {@link HSAILMathIntrinsicsNode}.
+ */
+@ClassSubstitution(java.lang.Math.class)
+public class HSAILMathSubstitutions {
+
+    /**
+     * Substitution for {@link Math#abs(int)}.
+     * 
+     * @param x the input
+     * @return the result of the computation
+     */
+    @MethodSubstitution
+    public static int abs(int x) {
+        return HSAILMathIntrinsicsNode.compute(x, HSAILArithmetic.ABS);
+    }
+
+    /**
+     * Substitution for {@link Math#abs(long)}.
+     * 
+     * @param x the input
+     * @return the result of the computation
+     */
+    @MethodSubstitution
+    public static long abs(long x) {
+        return HSAILMathIntrinsicsNode.compute(x, HSAILArithmetic.ABS);
+    }
+
+    /**
+     * Substitution for {@link Math#abs(float)}.
+     * 
+     * @param x the input
+     * @return the result of the computation
+     */
+    @MethodSubstitution
+    public static float abs(float x) {
+        return HSAILMathIntrinsicsNode.compute(x, HSAILArithmetic.ABS);
+    }
+
+    /**
+     * Substitution for {@link Math#abs(double)}.
+     * 
+     * @param x the input
+     * @return the result of the computation
+     */
+    @MethodSubstitution
+    public static double abs(double x) {
+        return HSAILMathIntrinsicsNode.compute(x, HSAILArithmetic.ABS);
+    }
+
+    /**
+     * Substitution for Math.ceil(double).
+     * 
+     * @param x the input
+     * @return the result of the computation
+     */
+    @MethodSubstitution
+    public static double ceil(double x) {
+        return HSAILMathIntrinsicsNode.compute(x, HSAILArithmetic.CEIL);
+    }
+
+    /**
+     * Substitution for {@link Math#floor(double)}.
+     * 
+     * @param x the input
+     * @return the result of the computation
+     */
+    @MethodSubstitution
+    public static double floor(double x) {
+        return HSAILMathIntrinsicsNode.compute(x, HSAILArithmetic.FLOOR);
+    }
+
+    /**
+     * Substitution for {@link Math#rint(double)}.
+     * 
+     * @param x the input
+     * @return the result of the computation
+     */
+    @MethodSubstitution
+    public static double rint(double x) {
+        return HSAILMathIntrinsicsNode.compute(x, HSAILArithmetic.RINT);
+    }
+
+    /**
+     * Substitution for {@link Math#sqrt(double)}.
+     * 
+     * @param x the input
+     * @return the result of the computation
+     */
+    @MethodSubstitution
+    public static double sqrt(double x) {
+        return HSAILMathIntrinsicsNode.compute(x, HSAILArithmetic.SQRT);
+    }
+}
--- a/mx/projects	Fri Dec 13 10:39:15 2013 +0100
+++ b/mx/projects	Fri Dec 13 10:44:09 2013 +0100
@@ -162,7 +162,7 @@
 # graal.hotspot.hsail
 project@com.oracle.graal.hotspot.hsail@subDir=graal
 project@com.oracle.graal.hotspot.hsail@sourceDirs=src
-project@com.oracle.graal.hotspot.hsail@dependencies=com.oracle.graal.compiler.hsail,com.oracle.graal.hotspot
+project@com.oracle.graal.hotspot.hsail@dependencies=com.oracle.graal.replacements.hsail,com.oracle.graal.hotspot
 project@com.oracle.graal.hotspot.hsail@checkstyle=com.oracle.graal.graph
 project@com.oracle.graal.hotspot.hsail@annotationProcessors=com.oracle.graal.service.processor
 project@com.oracle.graal.hotspot.hsail@javaCompliance=1.7
@@ -311,6 +311,14 @@
 project@com.oracle.graal.replacements.amd64@javaCompliance=1.7
 project@com.oracle.graal.replacements.amd64@workingSets=Graal,Replacements,AMD64
 
+# graal.replacements.hsail
+project@com.oracle.graal.replacements.hsail@subDir=graal
+project@com.oracle.graal.replacements.hsail@sourceDirs=src
+project@com.oracle.graal.replacements.hsail@dependencies=com.oracle.graal.compiler.hsail
+project@com.oracle.graal.replacements.hsail@checkstyle=com.oracle.graal.graph
+project@com.oracle.graal.replacements.hsail@javaCompliance=1.7
+project@com.oracle.graal.replacements.hsail@workingSets=Graal,Replacements,HSAIL
+
 # graal.replacements.test
 project@com.oracle.graal.replacements.test@subDir=graal
 project@com.oracle.graal.replacements.test@sourceDirs=src