1
0
mirror of https://github.com/golang/go synced 2024-11-07 20:16:10 -07:00

cmd/internal/obj/arm64: fix incorrect rejection of legal instructions

"BFI $0, R1, $7, R2" is expected to copy bit 0~6 from R1 to R2, and
left R2's other bits unchanged.

But the assembler rejects it with error "illegal bit number", and
BFIW/SBFIZ/SBFIZW/UBFIZ/UBFIZW have the same problem.

This CL fixes that issue and adds corresponding test cases.

fixes #26736

Change-Id: Ie0090a0faa38a49dd9b096a0f435987849800b76
Reviewed-on: https://go-review.googlesource.com/127159
Run-TryBot: Ben Shi <powerman1st@163.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
Ben Shi 2018-08-01 06:38:54 +00:00 committed by Cherry Zhang
parent ac6d156479
commit 9594ba4fe5
2 changed files with 32 additions and 6 deletions

View File

@ -716,6 +716,14 @@ again:
STPW (R3, R4), x(SB) STPW (R3, R4), x(SB)
STPW (R3, R4), x+8(SB) STPW (R3, R4), x+8(SB)
// bit field operation
BFI $0, R1, $1, R2 // 220040b3
BFIW $0, R1, $1, R2 // 22000033
SBFIZ $0, R1, $1, R2 // 22004093
SBFIZW $0, R1, $1, R2 // 22000013
UBFIZ $0, R1, $1, R2 // 220040d3
UBFIZW $0, R1, $1, R2 // 22000053
// END // END
// //
// LTYPEE comma // LTYPEE comma

View File

@ -3264,10 +3264,16 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) {
} }
switch p.As { switch p.As {
case ABFI: case ABFI:
o1 = c.opbfm(p, ABFM, 64-r, s-1, rf, rt) if r != 0 {
r = 64 - r
}
o1 = c.opbfm(p, ABFM, r, s-1, rf, rt)
case ABFIW: case ABFIW:
o1 = c.opbfm(p, ABFMW, 32-r, s-1, rf, rt) if r != 0 {
r = 32 - r
}
o1 = c.opbfm(p, ABFMW, r, s-1, rf, rt)
case ABFXIL: case ABFXIL:
o1 = c.opbfm(p, ABFM, r, r+s-1, rf, rt) o1 = c.opbfm(p, ABFM, r, r+s-1, rf, rt)
@ -3276,10 +3282,16 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) {
o1 = c.opbfm(p, ABFMW, r, r+s-1, rf, rt) o1 = c.opbfm(p, ABFMW, r, r+s-1, rf, rt)
case ASBFIZ: case ASBFIZ:
o1 = c.opbfm(p, ASBFM, 64-r, s-1, rf, rt) if r != 0 {
r = 64 - r
}
o1 = c.opbfm(p, ASBFM, r, s-1, rf, rt)
case ASBFIZW: case ASBFIZW:
o1 = c.opbfm(p, ASBFMW, 32-r, s-1, rf, rt) if r != 0 {
r = 32 - r
}
o1 = c.opbfm(p, ASBFMW, r, s-1, rf, rt)
case ASBFX: case ASBFX:
o1 = c.opbfm(p, ASBFM, r, r+s-1, rf, rt) o1 = c.opbfm(p, ASBFM, r, r+s-1, rf, rt)
@ -3288,10 +3300,16 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) {
o1 = c.opbfm(p, ASBFMW, r, r+s-1, rf, rt) o1 = c.opbfm(p, ASBFMW, r, r+s-1, rf, rt)
case AUBFIZ: case AUBFIZ:
o1 = c.opbfm(p, AUBFM, 64-r, s-1, rf, rt) if r != 0 {
r = 64 - r
}
o1 = c.opbfm(p, AUBFM, r, s-1, rf, rt)
case AUBFIZW: case AUBFIZW:
o1 = c.opbfm(p, AUBFMW, 32-r, s-1, rf, rt) if r != 0 {
r = 32 - r
}
o1 = c.opbfm(p, AUBFMW, r, s-1, rf, rt)
case AUBFX: case AUBFX:
o1 = c.opbfm(p, AUBFM, r, r+s-1, rf, rt) o1 = c.opbfm(p, AUBFM, r, r+s-1, rf, rt)