* SPARC: removed 32 bit shift code, and adjusted 64-bit shifts to take advantage of 3-address instructions (a port of r26142 for MIPS)

git-svn-id: trunk@26263 -
This commit is contained in:
sergei 2013-12-22 14:09:24 +00:00
parent 58cc531dd9
commit 6469d41e2a

View File

@ -33,8 +33,8 @@ interface
procedure pass_generate_code;override; procedure pass_generate_code;override;
end; end;
tSparcshlshrnode = class(tshlshrnode) tSparcshlshrnode = class(tcgshlshrnode)
procedure pass_generate_code;override; procedure second_64bit;override;
{ everything will be handled in pass_2 } { everything will be handled in pass_2 }
function first_shlshr64bitint: tnode; override; function first_shlshr64bitint: tnode; override;
end; end;
@ -183,103 +183,66 @@ implementation
end; end;
procedure tSparcshlshrnode.pass_generate_code; procedure tSparcshlshrnode.second_64bit;
var var
hregister,resultreg,hregister1, hregister,hreg64hi,hreg64lo : tregister;
hreg64hi,hreg64lo : tregister;
op : topcg; op : topcg;
shiftval: aword; shiftval: aword;
const
ops: array [boolean] of topcg = (OP_SHR,OP_SHL);
begin begin
{ 64bit without constants need a helper, and is { 64bit without constants need a helper, and is
already replaced in pass1 } already replaced in pass1 }
if is_64bit(left.resultdef) and if (right.nodetype<>ordconstn) then
(right.nodetype<>ordconstn) then
internalerror(200405301); internalerror(200405301);
secondpass(left); location_reset(location, LOC_REGISTER, def_cgsize(resultdef));
secondpass(right);
if is_64bit(left.resultdef) then { load left operator in a register }
hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,resultdef,true);
hreg64hi:=left.location.register64.reghi;
hreg64lo:=left.location.register64.reglo;
shiftval := tordconstnode(right).value.svalue and 63;
op := ops[nodetype=shln];
if shiftval > 31 then
begin begin
location_reset(location,LOC_REGISTER,OS_64); if nodetype = shln then
{ load left operator in a register }
hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,u64inttype,false);
hreg64hi:=left.location.register64.reghi;
hreg64lo:=left.location.register64.reglo;
shiftval := tordconstnode(right).value.svalue and 63;
if shiftval > 31 then
begin begin
if nodetype = shln then location.register64.reglo:=cg.GetIntRegister(current_asmdata.CurrAsmList,OS_32);
begin cg.a_load_const_reg(current_asmdata.CurrAsmList,OS_32,0,location.register64.reglo);
cg.a_load_const_reg(current_asmdata.CurrAsmList,OS_32,0,hreg64hi); location.register64.reghi:=cg.GetIntRegister(current_asmdata.CurrAsmList,OS_32);
if (shiftval and 31) <> 0 then { if shiftval and 31 = 0, it will optimize to MOVE }
cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SHL,OS_32,shiftval and 31,hreg64lo,hreg64lo); cg.a_op_const_reg_reg(current_asmdata.CurrAsmList, OP_SHL, OS_32, shiftval and 31, hreg64lo, location.register64.reghi);
end
else
begin
cg.a_load_const_reg(current_asmdata.CurrAsmList,OS_32,0,hreg64lo);
if (shiftval and 31) <> 0 then
cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SHR,OS_32,shiftval and 31,hreg64hi,hreg64hi);
end;
location.register64.reglo:=hreg64hi;
location.register64.reghi:=hreg64lo;
end end
else else
begin begin
{ shr 0 or shl 0 are noops, but generate wrong code below, location.register64.reghi:=cg.GetIntRegister(current_asmdata.CurrAsmList,OS_32);
so only add code if shift val is non-zero } cg.a_load_const_reg(current_asmdata.CurrAsmList,OS_32,0,location.register64.reghi);
if (shiftval <> 0) then location.register64.reglo:=cg.GetIntRegister(current_asmdata.CurrAsmList,OS_32);
begin cg.a_op_const_reg_reg(current_asmdata.CurrAsmList, OP_SHR, OS_32, shiftval and 31, hreg64hi, location.register64.reglo);
hregister:=cg.getintregister(current_asmdata.CurrAsmList,OS_32);
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;
end;
location.register64.reghi:=hreg64hi;
location.register64.reglo:=hreg64lo;
end; end;
end end
else else
begin begin
{ load left operators in a register } location.register64.reglo:=cg.GetIntRegister(current_asmdata.CurrAsmList,OS_32);
hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true); location.register64.reghi:=cg.GetIntRegister(current_asmdata.CurrAsmList,OS_32);
location_copy(location,left.location); hregister := cg.getintregister(current_asmdata.CurrAsmList, OS_32);
resultreg := location.register;
hregister1 := location.register; cg.a_op_const_reg_reg(current_asmdata.CurrAsmList, op, OS_32, shiftval, hreg64hi, location.register64.reghi);
if (location.loc = LOC_CREGISTER) then cg.a_op_const_reg_reg(current_asmdata.CurrAsmList, op, OS_32, shiftval, hreg64lo, location.register64.reglo);
if shiftval <> 0 then
begin begin
location.loc := LOC_REGISTER; if nodetype = shln then
resultreg := cg.GetIntRegister(current_asmdata.CurrAsmList,OS_INT); begin
location.register := resultreg; cg.a_op_const_reg_reg(current_asmdata.CurrAsmList, OP_SHR, OS_32, 32-shiftval, hreg64lo, hregister);
end; cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList, OP_OR, OS_32, hregister, location.register64.reghi, location.register64.reghi);
{ determine operator } end
if nodetype=shln then else
op:=OP_SHL begin
else cg.a_op_const_reg_reg(current_asmdata.CurrAsmList, OP_SHL, OS_32, 32-shiftval, hreg64hi, hregister);
op:=OP_SHR; cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList, OP_OR, OS_32, hregister, location.register64.reglo, location.register64.reglo);
{ shifting by a constant directly coded: } end;
if (right.nodetype=ordconstn) then
begin
if tordconstnode(right).value and 31<>0 then
cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,op,OS_32,tordconstnode(right).value.svalue and 31,hregister1,resultreg)
end
else
begin
{ load shift count in a register if necessary }
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);
end; end;
end; end;
end; end;