1 /* 2 * Copyright (c) 2013, 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.replacements.hsail; 24 25 import com.oracle.graal.api.replacements.ClassSubstitution; 26 import com.oracle.graal.api.replacements.MethodSubstitution; 27 import com.oracle.graal.lir.hsail.HSAILArithmetic; 28 29 /** 30 * Substitutions for {@link java.lang.Math} methods. For any calls to the java.lang.Math routines 31 * listed below and annotated with @MethodSubstitution, Graal replaces the call with a call to 32 * HSAILMathIntrinsicNode.compute() which triggers the creation of an HSAILMathIntrinsicNode to 33 * intrinsify that java.lang.Math routine. 34 */ 35 @ClassSubstitution(java.lang.Math.class) 36 public class HSAILMathSubstitutions { 37 38 /** 39 * Substitution for Math.abs(int). 40 * 41 * @param x the input 42 * @return the result of the computation 43 */ 44 @MethodSubstitution 45 public static int abs(int x) { 46 return HSAILMathIntrinsicsNode.compute(x, HSAILArithmetic.ABS); 47 } 48 49 /** 50 * Substitution for Math.abs(long). 51 * 52 * @param x the input 53 * @return the result of the computation 54 */ 55 @MethodSubstitution 56 public static long abs(long x) { 57 return HSAILMathIntrinsicsNode.compute(x, HSAILArithmetic.ABS); 58 } 59 60 /** 61 * Substitution for Math.abs(float). 62 * 63 * @param x the input 64 * @return the result of the computation 65 */ 66 @MethodSubstitution 67 public static float abs(float x) { 68 return HSAILMathIntrinsicsNode.compute(x, HSAILArithmetic.ABS); 69 } 70 71 /** 72 * Substitution for Math.abs(double). 73 * 74 * @param x the input 75 * @return the result of the computation 76 */ 77 @MethodSubstitution 78 public static double abs(double x) { 79 return HSAILMathIntrinsicsNode.compute(x, HSAILArithmetic.ABS); 80 } 81 82 /** 83 * Substitution for Math.ceil(double). 84 * 85 * @param x the input 86 * @return the result of the computation 87 */ 88 @MethodSubstitution 89 public static double ceil(double x) { 90 return HSAILMathIntrinsicsNode.compute(x, HSAILArithmetic.CEIL); 91 } 92 93 /** 94 * Substitution for Math.floor(double). 95 * 96 * @param x the input 97 * @return the result of the computation 98 */ 99 @MethodSubstitution 100 public static double floor(double x) { 101 return HSAILMathIntrinsicsNode.compute(x, HSAILArithmetic.FLOOR); 102 } 103 104 /** 105 * Substitution for Math.rint(double). 106 * 107 * @param x the input 108 * @return the result of the computation 109 */ 110 @MethodSubstitution 111 public static double rint(double x) { 112 return HSAILMathIntrinsicsNode.compute(x, HSAILArithmetic.RINT); 113 } 114 115 /** 116 * Substitution for Math.sqrt(double). 117 * 118 * @param x the input 119 * @return the result of the computation 120 */ 121 122 @MethodSubstitution 123 public static double sqrt(double x) { 124 return HSAILMathIntrinsicsNode.compute(x, HSAILArithmetic.SQRT); 125 } 126 127 }