mirror of
https://github.com/corda/corda.git
synced 2025-05-29 05:34:22 +00:00
Remove redundancy in compiling arithmetic operations
This commit is contained in:
parent
eab36b3a23
commit
ac984775a5
239
src/compile.cpp
239
src/compile.cpp
@ -4196,6 +4196,56 @@ class SwitchState {
|
|||||||
unsigned index;
|
unsigned index;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
lir::TernaryOperation toCompilerBinaryOp(MyThread* t, unsigned instruction)
|
||||||
|
{
|
||||||
|
switch (instruction) {
|
||||||
|
case iadd:
|
||||||
|
case ladd:
|
||||||
|
return lir::Add;
|
||||||
|
case ior:
|
||||||
|
case lor:
|
||||||
|
return lir::Or;
|
||||||
|
case ishl:
|
||||||
|
case lshl:
|
||||||
|
return lir::ShiftLeft;
|
||||||
|
case ishr:
|
||||||
|
case lshr:
|
||||||
|
return lir::ShiftRight;
|
||||||
|
case iushr:
|
||||||
|
case lushr:
|
||||||
|
return lir::UnsignedShiftRight;
|
||||||
|
case fadd:
|
||||||
|
case dadd:
|
||||||
|
return lir::FloatAdd;
|
||||||
|
case fsub:
|
||||||
|
case dsub:
|
||||||
|
return lir::FloatSubtract;
|
||||||
|
case fmul:
|
||||||
|
case dmul:
|
||||||
|
return lir::FloatMultiply;
|
||||||
|
case fdiv:
|
||||||
|
case ddiv:
|
||||||
|
return lir::FloatDivide;
|
||||||
|
case frem:
|
||||||
|
case vm::drem:
|
||||||
|
return lir::FloatRemainder;
|
||||||
|
case iand:
|
||||||
|
case land:
|
||||||
|
return lir::And;
|
||||||
|
case isub:
|
||||||
|
case lsub:
|
||||||
|
return lir::Subtract;
|
||||||
|
case ixor:
|
||||||
|
case lxor:
|
||||||
|
return lir::Xor;
|
||||||
|
case imul:
|
||||||
|
case lmul:
|
||||||
|
return lir::Multiply;
|
||||||
|
default:
|
||||||
|
abort(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
|
compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
|
||||||
int exceptionHandlerStart = -1)
|
int exceptionHandlerStart = -1)
|
||||||
@ -4585,11 +4635,15 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
|
|||||||
frame->pushLong(c->f2i(8, 8, frame->popLong()));
|
frame->pushLong(c->f2i(8, 8, frame->popLong()));
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case dadd: {
|
case dadd:
|
||||||
|
case dsub:
|
||||||
|
case dmul:
|
||||||
|
case ddiv:
|
||||||
|
case vm::drem: {
|
||||||
Compiler::Operand* a = frame->popLong();
|
Compiler::Operand* a = frame->popLong();
|
||||||
Compiler::Operand* b = frame->popLong();
|
Compiler::Operand* b = frame->popLong();
|
||||||
|
|
||||||
frame->pushLong(c->binaryOp(lir::FloatAdd, 8, a, b));
|
frame->pushLong(c->binaryOp(toCompilerBinaryOp(t, instruction), 8, a, b));
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case dcmpg: {
|
case dcmpg: {
|
||||||
@ -4634,38 +4688,10 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
|
|||||||
frame->pushLong(c->constant(doubleToBits(1.0), Compiler::FloatType));
|
frame->pushLong(c->constant(doubleToBits(1.0), Compiler::FloatType));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ddiv: {
|
|
||||||
Compiler::Operand* a = frame->popLong();
|
|
||||||
Compiler::Operand* b = frame->popLong();
|
|
||||||
|
|
||||||
frame->pushLong(c->binaryOp(lir::FloatDivide, 8, a, b));
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case dmul: {
|
|
||||||
Compiler::Operand* a = frame->popLong();
|
|
||||||
Compiler::Operand* b = frame->popLong();
|
|
||||||
|
|
||||||
frame->pushLong(c->binaryOp(lir::FloatMultiply, 8, a, b));
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case dneg: {
|
case dneg: {
|
||||||
frame->pushLong(c->unaryOp(lir::FloatNegate, 8, frame->popLong()));
|
frame->pushLong(c->unaryOp(lir::FloatNegate, 8, frame->popLong()));
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case vm::drem: {
|
|
||||||
Compiler::Operand* a = frame->popLong();
|
|
||||||
Compiler::Operand* b = frame->popLong();
|
|
||||||
|
|
||||||
frame->pushLong(c->binaryOp(lir::FloatRemainder, 8, a, b));
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case dsub: {
|
|
||||||
Compiler::Operand* a = frame->popLong();
|
|
||||||
Compiler::Operand* b = frame->popLong();
|
|
||||||
|
|
||||||
frame->pushLong(c->binaryOp(lir::FloatSubtract, 8, a, b));
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case dup:
|
case dup:
|
||||||
frame->dup();
|
frame->dup();
|
||||||
break;
|
break;
|
||||||
@ -4702,11 +4728,15 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
|
|||||||
frame->pushLong(c->f2i(4, 8, frame->popInt()));
|
frame->pushLong(c->f2i(4, 8, frame->popInt()));
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case fadd: {
|
case fadd:
|
||||||
|
case fsub:
|
||||||
|
case fmul:
|
||||||
|
case fdiv:
|
||||||
|
case frem: {
|
||||||
Compiler::Operand* a = frame->popInt();
|
Compiler::Operand* a = frame->popInt();
|
||||||
Compiler::Operand* b = frame->popInt();
|
Compiler::Operand* b = frame->popInt();
|
||||||
|
|
||||||
frame->pushInt(c->binaryOp(lir::FloatAdd, 4, a, b));
|
frame->pushInt(c->binaryOp(toCompilerBinaryOp(t, instruction), 4, a, b));
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case fcmpg: {
|
case fcmpg: {
|
||||||
@ -4751,38 +4781,10 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
|
|||||||
frame->pushInt(c->constant(floatToBits(2.0), Compiler::FloatType));
|
frame->pushInt(c->constant(floatToBits(2.0), Compiler::FloatType));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case fdiv: {
|
|
||||||
Compiler::Operand* a = frame->popInt();
|
|
||||||
Compiler::Operand* b = frame->popInt();
|
|
||||||
|
|
||||||
frame->pushInt(c->binaryOp(lir::FloatDivide, 4, a, b));
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case fmul: {
|
|
||||||
Compiler::Operand* a = frame->popInt();
|
|
||||||
Compiler::Operand* b = frame->popInt();
|
|
||||||
|
|
||||||
frame->pushInt(c->binaryOp(lir::FloatMultiply, 4, a, b));
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case fneg: {
|
case fneg: {
|
||||||
frame->pushInt(c->unaryOp(lir::FloatNegate, 4, frame->popInt()));
|
frame->pushInt(c->unaryOp(lir::FloatNegate, 4, frame->popInt()));
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case vm::frem: {
|
|
||||||
Compiler::Operand* a = frame->popInt();
|
|
||||||
Compiler::Operand* b = frame->popInt();
|
|
||||||
|
|
||||||
frame->pushInt(c->binaryOp(lir::FloatRemainder, 4, a, b));
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case fsub: {
|
|
||||||
Compiler::Operand* a = frame->popInt();
|
|
||||||
Compiler::Operand* b = frame->popInt();
|
|
||||||
|
|
||||||
frame->pushInt(c->binaryOp(lir::FloatSubtract, 4, a, b));
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case getfield:
|
case getfield:
|
||||||
case getstatic: {
|
case getstatic: {
|
||||||
uint16_t index = codeReadInt16(t, code, ip);
|
uint16_t index = codeReadInt16(t, code, ip);
|
||||||
@ -5015,16 +5017,18 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
|
|||||||
(c->load(TargetBytesPerWord, 2, frame->popInt(), TargetBytesPerWord));
|
(c->load(TargetBytesPerWord, 2, frame->popInt(), TargetBytesPerWord));
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case iadd: {
|
case iadd:
|
||||||
|
case iand:
|
||||||
|
case ior:
|
||||||
|
case ishl:
|
||||||
|
case ishr:
|
||||||
|
case iushr:
|
||||||
|
case isub:
|
||||||
|
case ixor:
|
||||||
|
case imul: {
|
||||||
Compiler::Operand* a = frame->popInt();
|
Compiler::Operand* a = frame->popInt();
|
||||||
Compiler::Operand* b = frame->popInt();
|
Compiler::Operand* b = frame->popInt();
|
||||||
frame->pushInt(c->binaryOp(lir::Add, 4, a, b));
|
frame->pushInt(c->binaryOp(toCompilerBinaryOp(t, instruction), 4, a, b));
|
||||||
} break;
|
|
||||||
|
|
||||||
case iand: {
|
|
||||||
Compiler::Operand* a = frame->popInt();
|
|
||||||
Compiler::Operand* b = frame->popInt();
|
|
||||||
frame->pushInt(c->binaryOp(lir::And, 4, a, b));
|
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case iconst_m1:
|
case iconst_m1:
|
||||||
@ -5231,12 +5235,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
|
|||||||
frame->loadInt(3);
|
frame->loadInt(3);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case imul: {
|
|
||||||
Compiler::Operand* a = frame->popInt();
|
|
||||||
Compiler::Operand* b = frame->popInt();
|
|
||||||
frame->pushInt(c->binaryOp(lir::Multiply, 4, a, b));
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case ineg: {
|
case ineg: {
|
||||||
frame->pushInt(c->unaryOp(lir::Negate, 4, frame->popInt()));
|
frame->pushInt(c->unaryOp(lir::Negate, 4, frame->popInt()));
|
||||||
} break;
|
} break;
|
||||||
@ -5467,12 +5465,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
|
|||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case ior: {
|
|
||||||
Compiler::Operand* a = frame->popInt();
|
|
||||||
Compiler::Operand* b = frame->popInt();
|
|
||||||
frame->pushInt(c->binaryOp(lir::Or, 4, a, b));
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case irem: {
|
case irem: {
|
||||||
Compiler::Operand* a = frame->popInt();
|
Compiler::Operand* a = frame->popInt();
|
||||||
Compiler::Operand* b = frame->popInt();
|
Compiler::Operand* b = frame->popInt();
|
||||||
@ -5491,18 +5483,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
|
|||||||
c->return_(4, frame->popInt());
|
c->return_(4, frame->popInt());
|
||||||
} goto next;
|
} goto next;
|
||||||
|
|
||||||
case ishl: {
|
|
||||||
Compiler::Operand* a = frame->popInt();
|
|
||||||
Compiler::Operand* b = frame->popInt();
|
|
||||||
frame->pushInt(c->binaryOp(lir::ShiftLeft, 4, a, b));
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case ishr: {
|
|
||||||
Compiler::Operand* a = frame->popInt();
|
|
||||||
Compiler::Operand* b = frame->popInt();
|
|
||||||
frame->pushInt(c->binaryOp(lir::ShiftRight, 4, a, b));
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case istore:
|
case istore:
|
||||||
case fstore:
|
case fstore:
|
||||||
frame->storeInt(codeBody(t, code, ip++));
|
frame->storeInt(codeBody(t, code, ip++));
|
||||||
@ -5528,24 +5508,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
|
|||||||
frame->storeInt(3);
|
frame->storeInt(3);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case isub: {
|
|
||||||
Compiler::Operand* a = frame->popInt();
|
|
||||||
Compiler::Operand* b = frame->popInt();
|
|
||||||
frame->pushInt(c->binaryOp(lir::Subtract, 4, a, b));
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case iushr: {
|
|
||||||
Compiler::Operand* a = frame->popInt();
|
|
||||||
Compiler::Operand* b = frame->popInt();
|
|
||||||
frame->pushInt(c->binaryOp(lir::UnsignedShiftRight, 4, a, b));
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case ixor: {
|
|
||||||
Compiler::Operand* a = frame->popInt();
|
|
||||||
Compiler::Operand* b = frame->popInt();
|
|
||||||
frame->pushInt(c->binaryOp(lir::Xor, 4, a, b));
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case jsr:
|
case jsr:
|
||||||
case jsr_w: {
|
case jsr_w: {
|
||||||
uint32_t thisIp;
|
uint32_t thisIp;
|
||||||
@ -5584,16 +5546,15 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
|
|||||||
frame->pushInt(c->load(8, 8, frame->popLong(), TargetBytesPerWord));
|
frame->pushInt(c->load(8, 8, frame->popLong(), TargetBytesPerWord));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ladd: {
|
case ladd:
|
||||||
|
case land:
|
||||||
|
case lor:
|
||||||
|
case lsub:
|
||||||
|
case lxor:
|
||||||
|
case lmul: {
|
||||||
Compiler::Operand* a = frame->popLong();
|
Compiler::Operand* a = frame->popLong();
|
||||||
Compiler::Operand* b = frame->popLong();
|
Compiler::Operand* b = frame->popLong();
|
||||||
frame->pushLong(c->binaryOp(lir::Add, 8, a, b));
|
frame->pushLong(c->binaryOp(toCompilerBinaryOp(t, instruction), 8, a, b));
|
||||||
} break;
|
|
||||||
|
|
||||||
case land: {
|
|
||||||
Compiler::Operand* a = frame->popLong();
|
|
||||||
Compiler::Operand* b = frame->popLong();
|
|
||||||
frame->pushLong(c->binaryOp(lir::And, 8, a, b));
|
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case lcmp: {
|
case lcmp: {
|
||||||
@ -5733,12 +5694,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
|
|||||||
frame->loadLong(3);
|
frame->loadLong(3);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case lmul: {
|
|
||||||
Compiler::Operand* a = frame->popLong();
|
|
||||||
Compiler::Operand* b = frame->popLong();
|
|
||||||
frame->pushLong(c->binaryOp(lir::Multiply, 8, a, b));
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case lneg:
|
case lneg:
|
||||||
frame->pushLong(c->unaryOp(lir::Negate, 8, frame->popLong()));
|
frame->pushLong(c->unaryOp(lir::Negate, 8, frame->popLong()));
|
||||||
break;
|
break;
|
||||||
@ -5803,12 +5758,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
|
|||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case lor: {
|
|
||||||
Compiler::Operand* a = frame->popLong();
|
|
||||||
Compiler::Operand* b = frame->popLong();
|
|
||||||
frame->pushLong(c->binaryOp(lir::Or, 8, a, b));
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case lrem: {
|
case lrem: {
|
||||||
Compiler::Operand* a = frame->popLong();
|
Compiler::Operand* a = frame->popLong();
|
||||||
Compiler::Operand* b = frame->popLong();
|
Compiler::Operand* b = frame->popLong();
|
||||||
@ -5827,16 +5776,12 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
|
|||||||
c->return_(8, frame->popLong());
|
c->return_(8, frame->popLong());
|
||||||
} goto next;
|
} goto next;
|
||||||
|
|
||||||
case lshl: {
|
case lshl:
|
||||||
|
case lshr:
|
||||||
|
case lushr: {
|
||||||
Compiler::Operand* a = frame->popInt();
|
Compiler::Operand* a = frame->popInt();
|
||||||
Compiler::Operand* b = frame->popLong();
|
Compiler::Operand* b = frame->popLong();
|
||||||
frame->pushLong(c->binaryOp(lir::ShiftLeft, 8, a, b));
|
frame->pushLong(c->binaryOp(toCompilerBinaryOp(t, instruction), 8, a, b));
|
||||||
} break;
|
|
||||||
|
|
||||||
case lshr: {
|
|
||||||
Compiler::Operand* a = frame->popInt();
|
|
||||||
Compiler::Operand* b = frame->popLong();
|
|
||||||
frame->pushLong(c->binaryOp(lir::ShiftRight, 8, a, b));
|
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case lstore:
|
case lstore:
|
||||||
@ -5864,24 +5809,6 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
|
|||||||
frame->storeLong(3);
|
frame->storeLong(3);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case lsub: {
|
|
||||||
Compiler::Operand* a = frame->popLong();
|
|
||||||
Compiler::Operand* b = frame->popLong();
|
|
||||||
frame->pushLong(c->binaryOp(lir::Subtract, 8, a, b));
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case lushr: {
|
|
||||||
Compiler::Operand* a = frame->popInt();
|
|
||||||
Compiler::Operand* b = frame->popLong();
|
|
||||||
frame->pushLong(c->binaryOp(lir::UnsignedShiftRight, 8, a, b));
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case lxor: {
|
|
||||||
Compiler::Operand* a = frame->popLong();
|
|
||||||
Compiler::Operand* b = frame->popLong();
|
|
||||||
frame->pushLong(c->binaryOp(lir::Xor, 8, a, b));
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case monitorenter: {
|
case monitorenter: {
|
||||||
Compiler::Operand* target = frame->popObject();
|
Compiler::Operand* target = frame->popObject();
|
||||||
c->call
|
c->call
|
||||||
|
Loading…
x
Reference in New Issue
Block a user