[vmkit-commits] [vmkit] r144134 - in /vmkit/trunk: lib/J3/Compiler/JavaJITOpcodes.cpp test/ test/lshl.java

Will Dietz wdietz2 at illinois.edu
Tue Nov 8 14:08:30 PST 2011


Author: wdietz2
Date: Tue Nov  8 16:08:30 2011
New Revision: 144134

URL: http://llvm.org/viewvc/llvm-project?rev=144134&view=rev
Log:
Fix LSHL to mask the shift operand.

Simple test case illustrating failure added.

It should produce (java Hotspot 1.6.0_27)
1
1024
4294967296
1
1
18014398509481984

Before this patch j3 produces:
1
1024
4294967296
4294967296
4294967296
4294967296

This patch aligns j3 with java's behavior.
Additionally, this causes j3 to pass Mauve's Long tests.

Added:
    vmkit/trunk/test/
    vmkit/trunk/test/lshl.java
Modified:
    vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp

Modified: vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp?rev=144134&r1=144133&r2=144134&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp Tue Nov  8 16:08:30 2011
@@ -1185,6 +1185,8 @@
 
       case LSHL : {
         Value* val2 = new ZExtInst(pop(), Type::getInt64Ty(*llvmContext), "", currentBlock);
+        Value* mask = ConstantInt::get(Type::getInt64Ty(*llvmContext), 0x3F);
+        val2 = BinaryOperator::CreateAnd(val2, mask, "", currentBlock);
         pop(); // remove the 0 on the stack
         Value* val1 = pop();
         push(BinaryOperator::CreateShl(val1, val2, "", currentBlock),

Added: vmkit/trunk/test/lshl.java
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/test/lshl.java?rev=144134&view=auto
==============================================================================
--- vmkit/trunk/test/lshl.java (added)
+++ vmkit/trunk/test/lshl.java Tue Nov  8 16:08:30 2011
@@ -0,0 +1,15 @@
+class lshl {
+  public static void check(boolean b) throws Exception {
+    if (!b) throw new Exception("Check failed!");
+  }
+
+  public static void main(String[] args) throws Exception {
+    long l = 1;
+    check(l == 1);
+    check(l << 10 == 1024);
+    check(l << 32 == 4294967296L);
+    check(l << 64 == 1);
+    check(l << 128 == 1);
+    check(l << -10 == 18014398509481984L);
+  }
+}





More information about the vmkit-commits mailing list