changeset 3501:600ffdb9adda

Intrinsify Math.sqrt(double). This gives Graal a huge boost in the DaCapo sunflow benchmark.
author Peter Hofer <peter.hofer@jku.at>
date Mon, 08 Aug 2011 16:54:49 +0200
parents 6111c168756f
children ada3ece59c7f 6b5e8da7daac
files graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/MathIntrinsic.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/ValueVisitor.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64LIRGenerator.java graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotRuntime.java
diffstat 4 files changed, 114 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/MathIntrinsic.java	Mon Aug 08 16:54:49 2011 +0200
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2011, 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.max.graal.compiler.ir;
+
+import com.oracle.max.graal.compiler.util.*;
+import com.oracle.max.graal.graph.*;
+import com.sun.cri.ci.*;
+
+public class MathIntrinsic extends FloatingNode {
+
+    public enum Operation {
+        SQRT
+    }
+
+    @Input private Value x;
+
+    private final Operation operation;
+
+    public Value x() {
+        return x;
+    }
+
+    public void setX(Value x) {
+        updateUsages(this.x, x);
+        this.x = x;
+    }
+
+    public Operation operation() {
+        return operation;
+    }
+
+    public MathIntrinsic(Value x, Operation op, Graph graph) {
+        super(x.kind, graph);
+        setX(x);
+        this.operation = op;
+    }
+
+    // for copying
+    private MathIntrinsic(CiKind kind, Operation op, Graph graph) {
+        super(kind, graph);
+        this.operation = op;
+    }
+
+    @Override
+    public void accept(ValueVisitor v) {
+        v.visitMathIntrinsic(this);
+    }
+
+    @Override
+    public int valueNumber() {
+        return Util.hash1(operation.hashCode(), x);
+    }
+
+    @Override
+    public boolean valueEqual(Node i) {
+        if (i instanceof MathIntrinsic) {
+            MathIntrinsic mi = (MathIntrinsic) i;
+            return (operation() == mi.operation && x() == mi.x());
+        }
+        return false;
+    }
+
+    @Override
+    public Node copy(Graph into) {
+        return new MathIntrinsic(kind, operation, into);
+    }
+
+}
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/ValueVisitor.java	Mon Aug 08 15:19:09 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/ValueVisitor.java	Mon Aug 08 16:54:49 2011 +0200
@@ -73,4 +73,5 @@
     public abstract void visitLoopEnd(LoopEnd loopEnd);
     public abstract void visitValueAnchor(ValueAnchor valueAnchor);
     public abstract void visitGuardNode(GuardNode guardNode);
+    public abstract void visitMathIntrinsic(MathIntrinsic node);
 }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64LIRGenerator.java	Mon Aug 08 15:19:09 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64LIRGenerator.java	Mon Aug 08 16:54:49 2011 +0200
@@ -465,6 +465,21 @@
     }
 
     @Override
+    public void visitMathIntrinsic(MathIntrinsic node) {
+        LIRItem opd = new LIRItem(node.x(), this);
+        opd.setDestroysRegister();
+        opd.loadItem();
+        CiVariable dest = createResultVariable(node);
+        switch (node.operation()) {
+            case SQRT:
+                lir.sqrt(opd.result(), dest, CiValue.IllegalValue);
+                break;
+            default:
+                throw Util.shouldNotReachHere();
+        }
+    }
+
+    @Override
     public Condition floatingPointCondition(Condition cond) {
         switch(cond) {
             case LT:
--- a/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotRuntime.java	Mon Aug 08 15:19:09 2011 +0200
+++ b/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotRuntime.java	Mon Aug 08 16:54:49 2011 +0200
@@ -575,6 +575,16 @@
                     graph.setReturn(ret);
                     intrinsicGraphs.put(method, graph);
                 }
+            } else if (holderName.equals("Ljava/lang/Math;")) {
+                if (fullName.equals("sqrt(D)D")) {
+                    CompilerGraph graph = new CompilerGraph(this);
+                    Local value = new Local(CiKind.Double, 0, graph);
+                    MathIntrinsic min = new MathIntrinsic(value, MathIntrinsic.Operation.SQRT, graph);
+                    Return ret = new Return(min, graph);
+                    graph.start().setNext(ret);
+                    graph.setReturn(ret);
+                    intrinsicGraphs.put(method, graph);
+                }
             }
 
             if (!intrinsicGraphs.containsKey(method)) {