m68k: review and some cleanup of the shlshrnode, also add a special case for shifting 64bit values by 1

git-svn-id: trunk@34757 -
This commit is contained in:
Károly Balogh 2016-10-23 16:46:34 +00:00
parent ddaa4d33e3
commit 660432685a

View File

@ -237,12 +237,9 @@ implementation
result := nil; result := nil;
end; end;
{ TODO: FIX ME!!! shlshrnode needs review}
procedure tm68kshlshrnode.pass_generate_code; procedure tm68kshlshrnode.pass_generate_code;
var var
hregister,resultreg,hregister1, hregister, hreg64hi, hreg64lo : tregister;
hreg64hi,hreg64lo : tregister;
op : topcg; op : topcg;
shiftval: aint; shiftval: aint;
begin begin
@ -277,39 +274,48 @@ implementation
location.register64.reghi:=hreg64lo; location.register64.reghi:=hreg64lo;
end end
else else
begin if (shiftval = 1) and (CPUM68K_HAS_ROLROR in cpu_capabilities[current_settings.cputype]) then
hregister:=cg.getintregister(current_asmdata.CurrAsmList,OS_32); begin
if nodetype = shln then if nodetype = shln then
begin begin
cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SHR,OS_32,32-shiftval,hreg64lo,hregister); current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_LSL,S_L,1,hreg64lo));
cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SHL,OS_32,shiftval,hreg64hi,hreg64hi); current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_ROXL,S_L,1,hreg64hi));
cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList,OP_OR,OS_32,hregister,hreg64hi,hreg64hi); end
cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SHL,OS_32,shiftval,hreg64lo,hreg64lo); else
end begin
else current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_LSR,S_L,1,hreg64hi));
begin current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_ROXR,S_L,1,hreg64lo));
cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SHL,OS_32,32-shiftval,hreg64hi,hregister); end;
cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SHR,OS_32,shiftval,hreg64lo,hreg64lo); location.register64.reghi:=hreg64hi;
cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList,OP_OR,OS_32,hregister,hreg64lo,hreg64lo); location.register64.reglo:=hreg64lo;
cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SHR,OS_32,shiftval,hreg64hi,hreg64hi); end
end; else
location.register64.reghi:=hreg64hi; begin
location.register64.reglo:=hreg64lo; hregister:=cg.getintregister(current_asmdata.CurrAsmList,OS_32);
end; if nodetype = shln then
begin
cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SHR,OS_32,32-shiftval,hreg64lo,hregister);
cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SHL,OS_32,shiftval,hreg64hi,hreg64hi);
cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList,OP_OR,OS_32,hregister,hreg64hi,hreg64hi);
cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SHL,OS_32,shiftval,hreg64lo,hreg64lo);
end
else
begin
cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SHL,OS_32,32-shiftval,hreg64hi,hregister);
cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SHR,OS_32,shiftval,hreg64lo,hreg64lo);
cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList,OP_OR,OS_32,hregister,hreg64lo,hreg64lo);
cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SHR,OS_32,shiftval,hreg64hi,hreg64hi);
end;
location.register64.reghi:=hreg64hi;
location.register64.reglo:=hreg64lo;
end;
end end
else else
begin begin
{ load left operators in a register } { load left operators in a register }
hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true); hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
location_copy(location,left.location); location_copy(location,left.location);
resultreg := location.register;
hregister1 := location.register;
if (location.loc = LOC_CREGISTER) then
begin
location.loc := LOC_REGISTER;
resultreg := cg.GetIntRegister(current_asmdata.CurrAsmList,OS_INT);
location.register := resultreg;
end;
{ determine operator } { determine operator }
if nodetype=shln then if nodetype=shln then
op:=OP_SHL op:=OP_SHL
@ -319,13 +325,13 @@ implementation
if (right.nodetype=ordconstn) then if (right.nodetype=ordconstn) then
begin begin
if tordconstnode(right).value.svalue and 31<>0 then if tordconstnode(right).value.svalue and 31<>0 then
cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,op,OS_32,tordconstnode(right).value.svalue and 31,hregister1,resultreg) cg.a_op_const_reg(current_asmdata.CurrAsmList,op,OS_32,tordconstnode(right).value.svalue and 31,location.register)
end end
else else
begin begin
{ load shift count in a register if necessary } { load shift count in a register if necessary }
hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,true); hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,true);
cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList,op,OS_32,right.location.register,hregister1,resultreg); cg.a_op_reg_reg(current_asmdata.CurrAsmList,op,OS_32,right.location.register,location.register);
end; end;
end; end;
end; end;