Skip to content

Commit

Permalink
cmd/asm, cmd/internal/obj/loong64: implement {8,16}-bit sign extensio…
Browse files Browse the repository at this point in the history
…ns with EXTW{B,H}

Updates golang#59120

Change-Id: Ia7dd0dfe20c0ea3e64889e2b38c6b2118b50d56e
  • Loading branch information
xen0n committed Mar 21, 2023
1 parent 901a6ed commit ede4688
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/cmd/asm/internal/asm/testdata/loong64enc1.s
Expand Up @@ -20,6 +20,8 @@ lable2:
MOVW $4096, R4 // 24000014
MOVV $65536, R4 // 04020014
MOVV $4096, R4 // 24000014
MOVB R4, R5 // 855c0000
MOVH R4, R5 // 85580000
MOVW R4, R5 // 85001700
MOVV R4, R5 // 85001500
MOVBU R4, R5 // 85fc4303
Expand Down
2 changes: 0 additions & 2 deletions src/cmd/asm/internal/asm/testdata/loong64enc2.s
Expand Up @@ -5,7 +5,6 @@
#include "../../../../../runtime/textflag.h"

TEXT asmtest(SB),DUPOK|NOSPLIT,$0
MOVB R4, R5 // 85e04000a5e04800
MOVWU R4, R5 // 85804100a5804500
MOVW $74565, R4 // 4402001484148d03
MOVW $4097, R4 // 2400001484048003
Expand Down Expand Up @@ -59,7 +58,6 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$0
XOR $4096, R4 // 3e00001484f81500
XOR $-1, R4, R5 // 1efcbf0285f81500
XOR $-1, R4 // 1efcbf0284f81500
MOVH R4, R5 // 85c04000a5c04800

// relocation instructions
MOVW R4, name(SB) // 1e00001cc4038029
Expand Down
18 changes: 10 additions & 8 deletions src/cmd/internal/obj/loong64/asm.go
Expand Up @@ -52,7 +52,7 @@ var optab = []Optab{

{AMOVW, C_REG, C_NONE, C_NONE, C_REG, C_NONE, 1, 4, 0, 0},
{AMOVV, C_REG, C_NONE, C_NONE, C_REG, C_NONE, 1, 4, 0, 0},
{AMOVB, C_REG, C_NONE, C_NONE, C_REG, C_NONE, 12, 8, 0, NOTUSETMP},
{AMOVB, C_REG, C_NONE, C_NONE, C_REG, C_NONE, 12, 4, 0, NOTUSETMP},
{AMOVBU, C_REG, C_NONE, C_NONE, C_REG, C_NONE, 13, 4, 0, 0},
{AMOVWU, C_REG, C_NONE, C_NONE, C_REG, C_NONE, 14, 8, 0, NOTUSETMP},

Expand Down Expand Up @@ -1308,14 +1308,16 @@ func (c *ctxt0) asmout(p *obj.Prog, o *Optab, out []uint32) {
rel.Type = objabi.R_CALLLOONG64

case 12: // movbs r,r
// NOTE: this case does not use REGTMP. If it ever does,
// remove the NOTUSETMP flag in optab.
v := 16
if p.As == AMOVB {
v = 24
var insn obj.As
switch p.As {
case AMOVB:
insn = AEXTWB
case AMOVH:
insn = AEXTWH
default:
c.ctxt.Diag("unexpected encoding")
}
o1 = OP_16IRR(c.opirr(ASLL), uint32(v), uint32(p.From.Reg), uint32(p.To.Reg))
o2 = OP_16IRR(c.opirr(ASRA), uint32(v), uint32(p.To.Reg), uint32(p.To.Reg))
o1 = OP_RR(c.oprr(insn), uint32(p.From.Reg), uint32(p.To.Reg))

case 13: // movbu r,r
if p.As == AMOVBU {
Expand Down

0 comments on commit ede4688

Please sign in to comment.