Skip to content

Commit

Permalink
fix sign extension from constant to register on x86
Browse files Browse the repository at this point in the history
scalac may generate a ldc followed by an l2i, whereas javac always
seems to condense this into a single ldc_w.  The former exposed a bug
in the JIT compiler which we never hit with javac-generated bytecode.
  • Loading branch information
dicej committed Apr 18, 2013
1 parent e6b6edf commit 9918ea6
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/codegen/target/x86/encode.cpp
Expand Up @@ -330,6 +330,10 @@ void moveCR2(Context* c, UNUSED unsigned aSize, lir::Constant* a,
if (vm::TargetBytesPerWord == 4 and bSize == 8) {
int64_t v = a->value->value();

if (aSize == 4) {
v = static_cast<int32_t>(v);
}

ResolvedPromise high((v >> 32) & 0xFFFFFFFF);
lir::Constant ah(&high);

Expand All @@ -344,8 +348,16 @@ void moveCR2(Context* c, UNUSED unsigned aSize, lir::Constant* a,
maybeRex(c, vm::TargetBytesPerWord, b);
opcode(c, 0xb8 + regCode(b));
if (a->value->resolved()) {
c->code.appendTargetAddress(a->value->value());
int64_t v = a->value->value();

if (aSize == 4 and bSize == 8) {
v = static_cast<int32_t>(v);
}

c->code.appendTargetAddress(v);
} else {
expect(c, aSize == vm::TargetBytesPerWord);

appendImmediateTask
(c, a->value, offsetPromise(c), vm::TargetBytesPerWord, promiseOffset);
c->code.appendTargetAddress(static_cast<vm::target_uintptr_t>(0));
Expand Down

0 comments on commit 9918ea6

Please sign in to comment.