Skip to content

Commit

Permalink
Merge pull request #467 from dawgfoto/master
Browse files Browse the repository at this point in the history
64 bit wrong code for byte sized shift assign
  • Loading branch information
WalterBright committed Oct 22, 2011
2 parents 38c9b7a + 46591b6 commit a669a56
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/backend/cod4.c
Expand Up @@ -1636,11 +1636,15 @@ code *cdshass(elem *e,regm_t *pretregs)
cg = allocreg(&retregs,&reg,tym);
cs.Iop = 0x8B ^ byte;
code_newreg(&cs, reg);
if (byte && I64 && (reg >= 4))
cs.Irex |= REX;
c = ce = gen(CNIL,&cs); /* MOV reg,EA */
if (!I16)
{
assert(!byte || (mask[reg] & BYTEREGS));
ce = genc2(CNIL,v ^ byte,modregrmx(3,op1,reg),shiftcnt);
if (byte && I64 && (reg >= 4))
ce->Irex |= REX;
code_orrex(ce, rex);
/* We can do a 32 bit shift on a 16 bit operand if */
/* it's a left shift and we're not concerned about */
Expand All @@ -1666,6 +1670,8 @@ code *cdshass(elem *e,regm_t *pretregs)
}

cs.Iop = 0x89 ^ byte;
if (byte && I64 && (reg >= 4))
cs.Irex |= REX;
gen(ce,&cs); /* MOV EA,reg */

// If result is not in correct register
Expand Down
31 changes: 31 additions & 0 deletions test/runnable/test42.d
Expand Up @@ -4325,6 +4325,36 @@ void test6563()

/***************************************************/

ubyte foo241(ubyte[] data)
{
ubyte a, b, c, d;

a = data[0];
b = data[1];
c = data[2];
d = data[3];

c <<= 1;
if (c & 0x80)
c >>= 1;
d <<= 1;
if (d & 0x80)
d >>= 1;

return d;
}

void test241()
{
ubyte[4] data;
data[3] = 0x40;
assert(foo241(data[]) == 0x40);
data[3] = 0x20;
assert(foo241(data[]) == 0x40);
}

/***************************************************/

int main()
{
test1();
Expand Down Expand Up @@ -4554,6 +4584,7 @@ int main()
test6506();
test240();
test6563();
test241();

writefln("Success");
return 0;
Expand Down

0 comments on commit a669a56

Please sign in to comment.