implement shr and ushr; teach add and sub about 32 bit immediate operands

This commit is contained in:
Joel Dice 2007-12-17 19:10:12 -07:00
parent 6895ffaa99
commit 3bafbf08bb

View File

@ -1122,12 +1122,19 @@ RegisterOperand::accept(Context* c, Operation operation,
switch (operation) { switch (operation) {
case add: { case add: {
if (operand->value) { if (operand->value) {
assert(c, isInt8(operand->value)); // todo
rex(c); rex(c);
c->code.append(0x83); if (isInt8(operand->value)) {
c->code.append(0xc0 | value); c->code.append(0x83);
c->code.append(operand->value); c->code.append(0xc0 | value);
c->code.append(operand->value);
} else if (isInt32(operand->value)) {
c->code.append(0x81);
c->code.append(0xc0 | value);
c->code.append4(operand->value);
} else {
abort(c);
}
} }
} break; } break;
@ -1179,12 +1186,18 @@ RegisterOperand::accept(Context* c, Operation operation,
case sub: { case sub: {
if (operand->value) { if (operand->value) {
assert(c, isInt8(operand->value)); // todo
rex(c); rex(c);
c->code.append(0x83); if (isInt8(operand->value)) {
c->code.append(0xe8 | value); c->code.append(0x83);
c->code.append(operand->value); c->code.append(0xe8 | value);
c->code.append(operand->value);
} else if (isInt32(operand->value)) {
c->code.append(0x81);
c->code.append(0xe8 | value);
c->code.append4(operand->value);
} else {
abort(c);
}
} }
} break; } break;
@ -1616,6 +1629,20 @@ MemoryOperand::accept(Context* c, Operation operation,
cx->release(c); cx->release(c);
} break; } break;
case shr: {
RegisterOperand* cx = temporary(c, rcx);
cx->accept(c, mov, operand);
encode(c, 0xd3, 5, this, true);
cx->release(c);
} break;
case ushr: {
RegisterOperand* cx = temporary(c, rcx);
cx->accept(c, mov, operand);
encode(c, 0xd3, 7, this, true);
cx->release(c);
} break;
case sub: { case sub: {
encode(c, 0x29, operand->value, this, true); encode(c, 0x29, operand->value, this, true);
} break; } break;