|
@@ -71,6 +71,7 @@ unit cgrv;
|
|
procedure a_loadfpu_reg_ref(list: TAsmList; fromsize, tosize: tcgsize; reg: tregister; const ref: treference); override;
|
|
procedure a_loadfpu_reg_ref(list: TAsmList; fromsize, tosize: tcgsize; reg: tregister; const ref: treference); override;
|
|
protected
|
|
protected
|
|
function fixref(list: TAsmList; var ref: treference): boolean;
|
|
function fixref(list: TAsmList; var ref: treference): boolean;
|
|
|
|
+ procedure maybeadjustresult(list: TAsmList; op: topcg; size: tcgsize; dst: tregister);
|
|
end;
|
|
end;
|
|
|
|
|
|
const
|
|
const
|
|
@@ -202,7 +203,10 @@ unit cgrv;
|
|
|
|
|
|
if (TOpCG2AsmConstOp[op]<>A_None) and
|
|
if (TOpCG2AsmConstOp[op]<>A_None) and
|
|
is_imm12(a) then
|
|
is_imm12(a) then
|
|
- list.concat(taicpu.op_reg_reg_const(TOpCG2AsmConstOp[op],dst,src,a))
|
|
|
|
|
|
+ begin
|
|
|
|
+ list.concat(taicpu.op_reg_reg_const(TOpCG2AsmConstOp[op],dst,src,a));
|
|
|
|
+ maybeadjustresult(list,op,size,dst);
|
|
|
|
+ end
|
|
else
|
|
else
|
|
begin
|
|
begin
|
|
tmpreg:=getintregister(list,size);
|
|
tmpreg:=getintregister(list,size);
|
|
@@ -216,13 +220,20 @@ unit cgrv;
|
|
begin
|
|
begin
|
|
case op of
|
|
case op of
|
|
OP_NOT:
|
|
OP_NOT:
|
|
- list.concat(taicpu.op_reg_reg_const(A_XORI,dst,src1,-1));
|
|
|
|
|
|
+ begin
|
|
|
|
+ list.concat(taicpu.op_reg_reg_const(A_XORI,dst,src1,-1));
|
|
|
|
+ maybeadjustresult(list,op,size,dst);
|
|
|
|
+ end;
|
|
OP_NEG:
|
|
OP_NEG:
|
|
- list.concat(taicpu.op_reg_reg_reg(A_SUB,dst,NR_X0,src1));
|
|
|
|
|
|
+ begin
|
|
|
|
+ list.concat(taicpu.op_reg_reg_reg(A_SUB,dst,NR_X0,src1));
|
|
|
|
+ maybeadjustresult(list,op,size,dst);
|
|
|
|
+ end;
|
|
OP_MOVE:
|
|
OP_MOVE:
|
|
a_load_reg_reg(list,size,size,src1,dst);
|
|
a_load_reg_reg(list,size,size,src1,dst);
|
|
else
|
|
else
|
|
list.concat(taicpu.op_reg_reg_reg(TOpCG2AsmOp[op],dst,src2,src1));
|
|
list.concat(taicpu.op_reg_reg_reg(TOpCG2AsmOp[op],dst,src2,src1));
|
|
|
|
+ maybeadjustresult(list,op,size,dst);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -652,4 +663,14 @@ unit cgrv;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+
|
|
|
|
+ procedure tcgrv.maybeadjustresult(list: TAsmList; op: topcg; size: tcgsize; dst: tregister);
|
|
|
|
+ const
|
|
|
|
+ overflowops = [OP_MUL,OP_IMUL,OP_SHL,OP_ADD,OP_SUB,OP_NOT,OP_NEG];
|
|
|
|
+ begin
|
|
|
|
+ if (op in overflowops) and
|
|
|
|
+ (size in [OS_8,OS_S8,OS_16,OS_S16{$ifdef RISCV64},OS_32,OS_S32{$endif RISCV64}]) then
|
|
|
|
+ a_load_reg_reg(list,OS_INT,size,dst,dst)
|
|
|
|
+ end;
|
|
|
|
+
|
|
end.
|
|
end.
|