diff --git a/compiler/mips/cgcpu.pas b/compiler/mips/cgcpu.pas index 8542cbe9f3..6a34e33ad6 100644 --- a/compiler/mips/cgcpu.pas +++ b/compiler/mips/cgcpu.pas @@ -1759,6 +1759,7 @@ procedure TCg64MPSel.a_load64_reg_ref(list: tasmlist; reg: tregister64; const re var tmpref: treference; tmpreg: tregister; + incr: shortint; begin if target_info.endian = endian_big then begin @@ -1768,9 +1769,46 @@ begin end; tmpref := ref; tcgmips(cg).make_simple_ref(list,tmpref); - list.concat(taicpu.op_reg_ref(A_SW,reg.reglo,tmpref)); - Inc(tmpref.offset, 4); - list.concat(taicpu.op_reg_ref(A_SW,reg.reghi,tmpref)); + if (ref.alignment <4) then + begin + if target_info.endian = endian_big then + begin + inc(tmpref.offset,3); + incr:=-1; + end + else + incr:=1; + list.concat(taicpu.op_reg_ref(A_SB,reg.reglo,tmpref)); + Inc(tmpref.offset,incr); + list.concat(taicpu.op_reg_reg_const(A_SRL,reg.reglo,reg.reglo,8)); + list.concat(taicpu.op_reg_ref(A_SB,reg.reglo,tmpref)); + Inc(tmpref.offset,incr); + list.concat(taicpu.op_reg_reg_const(A_SRL,reg.reglo,reg.reglo,8)); + list.concat(taicpu.op_reg_ref(A_SB,reg.reglo,tmpref)); + Inc(tmpref.offset,incr); + list.concat(taicpu.op_reg_reg_const(A_SRL,reg.reglo,reg.reglo,8)); + list.concat(taicpu.op_reg_ref(A_SB,reg.reglo,tmpref)); + Inc(tmpref.offset,incr); + if target_info.endian = endian_big then + inc(tmpref.offset,7); + list.concat(taicpu.op_reg_ref(A_SB,reg.reghi,tmpref)); + Inc(tmpref.offset,incr); + list.concat(taicpu.op_reg_reg_const(A_SRL,reg.reghi,reg.reghi,8)); + list.concat(taicpu.op_reg_ref(A_SB,reg.reghi,tmpref)); + Inc(tmpref.offset,incr); + list.concat(taicpu.op_reg_reg_const(A_SRL,reg.reghi,reg.reghi,8)); + list.concat(taicpu.op_reg_ref(A_SB,reg.reghi,tmpref)); + Inc(tmpref.offset,incr); + list.concat(taicpu.op_reg_reg_const(A_SRL,reg.reghi,reg.reghi,8)); + list.concat(taicpu.op_reg_ref(A_SB,reg.reghi,tmpref)); + Inc(tmpref.offset,incr); + end + else + begin + list.concat(taicpu.op_reg_ref(A_SW,reg.reglo,tmpref)); + Inc(tmpref.offset, 4); + list.concat(taicpu.op_reg_ref(A_SW,reg.reghi,tmpref)); + end; end; @@ -1778,6 +1816,7 @@ procedure TCg64MPSel.a_load64_ref_reg(list: tasmlist; const ref: treference; reg var tmpref: treference; tmpreg: tregister; + incr: shortint; begin if target_info.endian = endian_big then begin @@ -1787,9 +1826,46 @@ begin end; tmpref := ref; tcgmips(cg).make_simple_ref(list,tmpref); - list.concat(taicpu.op_reg_ref(A_LW,reg.reglo,tmpref)); - Inc(tmpref.offset, 4); - list.concat(taicpu.op_reg_ref(A_LW,reg.reghi,tmpref)); + if (ref.alignment <4) then + begin + if target_info.endian = endian_big then + begin + inc(tmpref.offset,3); + incr:=-1; + end + else + incr:=1; + list.concat(taicpu.op_reg_ref(A_LBU,reg.reglo,tmpref)); + Inc(tmpref.offset,incr); + list.concat(taicpu.op_reg_reg_const(A_SLL,reg.reglo,reg.reglo,8)); + list.concat(taicpu.op_reg_ref(A_LBU,reg.reglo,tmpref)); + Inc(tmpref.offset,incr); + list.concat(taicpu.op_reg_reg_const(A_SLL,reg.reglo,reg.reglo,8)); + list.concat(taicpu.op_reg_ref(A_LBU,reg.reglo,tmpref)); + Inc(tmpref.offset,incr); + list.concat(taicpu.op_reg_reg_const(A_SLL,reg.reglo,reg.reglo,8)); + list.concat(taicpu.op_reg_ref(A_LBU,reg.reglo,tmpref)); + Inc(tmpref.offset,incr); + if target_info.endian = endian_big then + inc(tmpref.offset,7); + list.concat(taicpu.op_reg_ref(A_LBU,reg.reghi,tmpref)); + Inc(tmpref.offset,incr); + list.concat(taicpu.op_reg_reg_const(A_SLL,reg.reghi,reg.reghi,8)); + list.concat(taicpu.op_reg_ref(A_LBU,reg.reghi,tmpref)); + Inc(tmpref.offset,incr); + list.concat(taicpu.op_reg_reg_const(A_SLL,reg.reghi,reg.reghi,8)); + list.concat(taicpu.op_reg_ref(A_LBU,reg.reghi,tmpref)); + Inc(tmpref.offset,incr); + list.concat(taicpu.op_reg_reg_const(A_SLL,reg.reghi,reg.reghi,8)); + list.concat(taicpu.op_reg_ref(A_LBU,reg.reghi,tmpref)); + Inc(tmpref.offset,incr); + end + else + begin + list.concat(taicpu.op_reg_ref(A_LW,reg.reglo,tmpref)); + Inc(tmpref.offset, 4); + list.concat(taicpu.op_reg_ref(A_LW,reg.reghi,tmpref)); + end; end;