--- /dev/null 2013-12-11 15:38:07.845401995 -0600 +++ new/graal/com.oracle.graal.replacements.hsail/src/com/oracle/graal/replacements/hsail/HSAILMathSubstitutions.java 2013-12-12 12:32:51.237342606 -0600 @@ -0,0 +1,127 @@ +/* + * 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 java.lang.Math} methods. For any calls to the java.lang.Math routines + * listed below and annotated with @MethodSubstitution, Graal replaces the call with a call to + * HSAILMathIntrinsicNode.compute() which triggers the creation of an HSAILMathIntrinsicNode to + * intrinsify that java.lang.Math routine. + */ +@ClassSubstitution(java.lang.Math.class) +public class HSAILMathSubstitutions { + + /** + * Substitution for 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 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 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 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 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 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 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); + } + +}