[vmkit-commits] [PATCH] Fix LSHL to mask the shift operand.
Will Dietz
wdietz2 at illinois.edu
Mon Nov 7 12:14:20 PST 2011
Inlined below.
The masking logic is already used in LUSHR, FWIW.
~Will
>From 029662fa7bd23532d8a5be59793efab715217356 Mon Sep 17 00:00:00 2001
From: Will Dietz <w at wdtz.org>
Date: Sun, 6 Nov 2011 23:26:17 -0600
Subject: [PATCH] Fix LSHL to mask the shift operand.
Simple test case illustrating failure:
class Test {
public static void main(String[] args) {
long l = 1;
System.out.println(l);
System.out.println(l << 10);
System.out.println(l << 32);
System.out.println(l << 64);
System.out.println(l << 128);
System.out.println(l << -10);
}
}
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.
---
lib/J3/Compiler/JavaJITOpcodes.cpp | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/lib/J3/Compiler/JavaJITOpcodes.cpp
b/lib/J3/Compiler/JavaJITOpcodes.cpp
index 4c5e8cd..93b9c3c 100644
--- a/lib/J3/Compiler/JavaJITOpcodes.cpp
+++ b/lib/J3/Compiler/JavaJITOpcodes.cpp
@@ -1185,6 +1185,8 @@ void JavaJIT::compileOpcodes(Reader& reader,
uint32 codeLength) {
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),
--
1.7.5.1
More information about the vmkit-commits
mailing list