fixes for assignaddrc() and cmpval() (#21195)

This commit is contained in:
Walter Bright 2025-04-10 00:59:53 -07:00 committed by GitHub
parent 52cb9fdc1b
commit 81cd0b26ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 4 deletions

View file

@ -1176,6 +1176,10 @@ void movregconst(ref CodeBuilder cdb,reg_t reg,targ_size_t value,regm_t flags)
r++; r++;
} }
// loading a constant into the lower 32 bits zeros out the upper 32 bits
if ((value & 0xFFFF_FFFF_0000_0000) == 0)
flags &= ~64;
uint sf = (flags & 64) != 0; uint sf = (flags & 64) != 0;
uint opc = 2; // MOVZ uint opc = 2; // MOVZ
uint hw = 0; uint hw = 0;
@ -1240,7 +1244,7 @@ void movregconst(ref CodeBuilder cdb,reg_t reg,targ_size_t value,regm_t flags)
{ {
// Check for ORR one instruction solution // Check for ORR one instruction solution
uint N, immr, imms; uint N, immr, imms;
if (orr_solution(value2, N, immr, imms)) if (orr_solution(value2, N, immr, imms)) // TODO AArch64 not implemented yet
{ {
// MOV Rd,#imm // MOV Rd,#imm
// http://www.scs.stanford.edu/~zyedidia/arm64/mov_orr_log_imm.html // http://www.scs.stanford.edu/~zyedidia/arm64/mov_orr_log_imm.html
@ -1287,6 +1291,7 @@ done:
*/ */
bool orr_solution(ulong value, out uint N, out uint immr, out uint imms) bool orr_solution(ulong value, out uint N, out uint immr, out uint imms)
{ {
// TODO AArch64
return false; return false;
} }
@ -1570,9 +1575,8 @@ void assignaddrc(code* c)
Rn = cast(reg_t)field(ins,9,5); Rn = cast(reg_t)field(ins,9,5);
Rt = cast(reg_t)field(ins,4,0); Rt = cast(reg_t)field(ins,4,0);
if (!cgstate.hasframe || (cgstate.enforcealign && c.IFL1 != FL.para)) if (Rn == 29 && !cgstate.hasframe || (cgstate.enforcealign && c.IFL1 != FL.para))
{ /* Convert to SP relative address instead of BP */ { /* Convert to SP relative address instead of BP */
assert(Rn == 29); // BP
offset += cgstate.EBPtoESP; // add difference in offset offset += cgstate.EBPtoESP; // add difference in offset
ins = setField(ins,9,5,31); // set Rn to SP ins = setField(ins,9,5,31); // set Rn to SP
} }

View file

@ -1603,7 +1603,7 @@ private void cmpval(CGstate cg, ref CodeBuilder cdb, ulong val, uint sz, reg_t r
if (cg.AArch64) if (cg.AArch64)
{ {
assert(sreg == NOREG); assert(sreg == NOREG);
if (val <= 0xFFF || val >= 0x1000 && val <= 0xFFF000) if (val <= 0xFFF || val >= 0x1000 && val <= 0xFFF000 && ((val & 0xFFF) == 0))
{ {
ubyte sh = val >= 0x1000; ubyte sh = val >= 0x1000;
uint imm12 = cast(uint)(sh ? val >> 12 : val); uint imm12 = cast(uint)(sh ? val >> 12 : val);