Skip to content

Commit

Permalink
fix addC for case where bit 15 of constant is set
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Dice committed Mar 9, 2009
1 parent 8b0f7d7 commit 68ed5e6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/powerpc.cpp
Expand Up @@ -150,6 +150,12 @@ isInt16(intptr_t v)
return v == static_cast<int16_t>(v);
}

inline int
carry16(intptr_t v)
{
return static_cast<int16_t>(v) < 0 ? 1 : 0;
}

const unsigned FrameFooterSize = 6;

const int StackRegister = 1;
Expand Down Expand Up @@ -701,7 +707,7 @@ void addC(Context* con, unsigned size, Const* a, Reg* b, Reg* t) {
if(i) {
issue(con, addi(R(t), R(b), lo16(i)));
if(not isInt16(i))
issue(con, addis(R(t), R(t), hi16(i)));
issue(con, addis(R(t), R(t), hi16(i) + carry16(i)));
} else {
moveCR(con, size, a, size, t);
}
Expand All @@ -716,17 +722,12 @@ void subR(Context* con, unsigned size, Reg* a, Reg* b, Reg* t) {
}
}

void subC(Context* con, unsigned size, Const* a, Reg* b, Reg* t) {
assert(con, size == BytesPerWord);
void subC(Context* c, unsigned size, Const* a, Reg* b, Reg* t) {
assert(c, size == BytesPerWord);

int64_t i = getVal(a);
if(i) {
issue(con, subi(R(t), R(b), lo16(i)));
if(not isInt16(i))
issue(con, subis(R(t), R(t), hi16(i)));
} else {
moveCR(con, size, a, size, t);
}
ResolvedPromise promise(- a->value->value());
Assembler::Constant constant(&promise);
addC(c, size, &constant, b, t);
}

void multiplyR(Context* con, unsigned size, Reg* a, Reg* b, Reg* t) {
Expand Down
3 changes: 3 additions & 0 deletions test/Integers.java
Expand Up @@ -81,5 +81,8 @@ public static void main(String[] args) {
/ scanlinePad * scanlinePad;
expect(bytesPerLine == 24);
}

int y = -11760768;
expect((y + 0x8000) == (-11760768 + 0x8000));
}
}

0 comments on commit 68ed5e6

Please sign in to comment.