< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.amd64/src/org/graalvm/compiler/hotspot/amd64/AMD64MathStub.java

Print this page




   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 
  25 package org.graalvm.compiler.hotspot.amd64;
  26 
  27 import static org.graalvm.compiler.hotspot.amd64.AMD64HotSpotForeignCallsProvider.ARITHMETIC_COS_STUB;
  28 import static org.graalvm.compiler.hotspot.amd64.AMD64HotSpotForeignCallsProvider.ARITHMETIC_EXP_STUB;
  29 import static org.graalvm.compiler.hotspot.amd64.AMD64HotSpotForeignCallsProvider.ARITHMETIC_LOG10_STUB;
  30 import static org.graalvm.compiler.hotspot.amd64.AMD64HotSpotForeignCallsProvider.ARITHMETIC_LOG_STUB;
  31 import static org.graalvm.compiler.hotspot.amd64.AMD64HotSpotForeignCallsProvider.ARITHMETIC_POW_STUB;
  32 import static org.graalvm.compiler.hotspot.amd64.AMD64HotSpotForeignCallsProvider.ARITHMETIC_SIN_STUB;
  33 import static org.graalvm.compiler.hotspot.amd64.AMD64HotSpotForeignCallsProvider.ARITHMETIC_TAN_STUB;
  34 
  35 import org.graalvm.compiler.api.replacements.Snippet;
  36 import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor;
  37 import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage;
  38 import org.graalvm.compiler.hotspot.meta.HotSpotProviders;
  39 import org.graalvm.compiler.hotspot.stubs.SnippetStub;
  40 import org.graalvm.compiler.options.OptionValues;
  41 import org.graalvm.compiler.replacements.nodes.BinaryMathIntrinsicNode;
  42 import org.graalvm.compiler.replacements.nodes.BinaryMathIntrinsicNode.BinaryOperation;
  43 import org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode;
  44 import org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation;
  45 
  46 /**
  47  * Stub called to support {@link Math}.
  48  */
  49 public class AMD64MathStub extends SnippetStub {
  50 
  51     public AMD64MathStub(ForeignCallDescriptor descriptor, OptionValues options, HotSpotProviders providers, HotSpotForeignCallLinkage linkage) {
  52         super(snippetName(descriptor), options, providers, linkage);
  53     }
  54 
  55     private static String snippetName(ForeignCallDescriptor descriptor) {
  56         if (descriptor == ARITHMETIC_LOG_STUB) {
  57             return "log";
  58         }
  59         if (descriptor == ARITHMETIC_LOG10_STUB) {
  60             return "log10";
  61         }
  62         if (descriptor == ARITHMETIC_SIN_STUB) {
  63             return "sin";
  64         }
  65         if (descriptor == ARITHMETIC_COS_STUB) {
  66             return "cos";
  67         }
  68         if (descriptor == ARITHMETIC_TAN_STUB) {
  69             return "tan";
  70         }
  71         if (descriptor == ARITHMETIC_EXP_STUB) {
  72             return "exp";


  73         }
  74         if (descriptor == ARITHMETIC_POW_STUB) {



  75             return "pow";
  76         }
  77         throw new InternalError("Unknown operation " + descriptor);
  78     }
  79 
  80     @Snippet
  81     private static double log(double value) {
  82         return UnaryMathIntrinsicNode.compute(value, UnaryOperation.LOG);
  83     }
  84 
  85     @Snippet
  86     private static double log10(double value) {
  87         return UnaryMathIntrinsicNode.compute(value, UnaryOperation.LOG10);
  88     }
  89 
  90     @Snippet
  91     private static double sin(double value) {
  92         return UnaryMathIntrinsicNode.compute(value, UnaryOperation.SIN);
  93     }
  94 
  95     @Snippet
  96     private static double cos(double value) {
  97         return UnaryMathIntrinsicNode.compute(value, UnaryOperation.COS);


   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 
  25 package org.graalvm.compiler.hotspot.amd64;
  26 








  27 import org.graalvm.compiler.api.replacements.Snippet;
  28 import org.graalvm.compiler.debug.GraalError;
  29 import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage;
  30 import org.graalvm.compiler.hotspot.meta.HotSpotProviders;
  31 import org.graalvm.compiler.hotspot.stubs.SnippetStub;
  32 import org.graalvm.compiler.options.OptionValues;
  33 import org.graalvm.compiler.replacements.nodes.BinaryMathIntrinsicNode;
  34 import org.graalvm.compiler.replacements.nodes.BinaryMathIntrinsicNode.BinaryOperation;
  35 import org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode;
  36 import org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation;
  37 
  38 /**
  39  * Stub called to support {@link Math}.
  40  */
  41 public class AMD64MathStub extends SnippetStub {
  42 
  43     public AMD64MathStub(UnaryOperation operation, OptionValues options, HotSpotProviders providers, HotSpotForeignCallLinkage linkage) {
  44         super(snippetName(operation), options, providers, linkage);
  45     }
  46 
  47     public AMD64MathStub(BinaryOperation operation, OptionValues options, HotSpotProviders providers, HotSpotForeignCallLinkage linkage) {
  48         super(snippetName(operation), options, providers, linkage);
  49     }
  50 
  51     private static String snippetName(UnaryOperation operation) {
  52         switch (operation) {
  53             case SIN:
  54                 return "sin";
  55             case COS:
  56                 return "cos";
  57             case TAN:
  58                 return "tan";
  59             case EXP:
  60                 return "exp";
  61             case LOG:
  62                 return "log";
  63             case LOG10:
  64                 return "log10";
  65             default:
  66                 throw GraalError.shouldNotReachHere("Unknown operation " + operation);
  67         }
  68     }
  69 
  70     private static String snippetName(BinaryOperation operation) {
  71         if (operation == BinaryOperation.POW) {
  72             return "pow";
  73         }
  74         throw GraalError.shouldNotReachHere("Unknown operation " + operation);
  75     }
  76 
  77     @Snippet
  78     private static double log(double value) {
  79         return UnaryMathIntrinsicNode.compute(value, UnaryOperation.LOG);
  80     }
  81 
  82     @Snippet
  83     private static double log10(double value) {
  84         return UnaryMathIntrinsicNode.compute(value, UnaryOperation.LOG10);
  85     }
  86 
  87     @Snippet
  88     private static double sin(double value) {
  89         return UnaryMathIntrinsicNode.compute(value, UnaryOperation.SIN);
  90     }
  91 
  92     @Snippet
  93     private static double cos(double value) {
  94         return UnaryMathIntrinsicNode.compute(value, UnaryOperation.COS);
< prev index next >