Commit 54af1870 authored by Dave Cheney's avatar Dave Cheney

cmd/internal/obj/x86: clean up byteswapreg

Make byteswapreg more Go like.

Change-Id: Ibdf3603cae9cad2b3465b4c224a28a4c4c745c2e
Reviewed-on: https://go-review.googlesource.com/38615
Run-TryBot: Dave Cheney <dave@cheney.net>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent b72636cb
...@@ -4317,68 +4317,53 @@ bad: ...@@ -4317,68 +4317,53 @@ bad:
// If a is empty, it returns BX to account for MULB-like instructions // If a is empty, it returns BX to account for MULB-like instructions
// that might use DX and AX. // that might use DX and AX.
func byteswapreg(ctxt *obj.Link, a *obj.Addr) int { func byteswapreg(ctxt *obj.Link, a *obj.Addr) int {
cand := 1 cana, canb, canc, cand := true, true, true, true
canc := cand
canb := canc
cana := canb
if a.Type == obj.TYPE_NONE { if a.Type == obj.TYPE_NONE {
cand = 0 cana, cand = false, false
cana = cand
} }
if a.Type == obj.TYPE_REG || ((a.Type == obj.TYPE_MEM || a.Type == obj.TYPE_ADDR) && a.Name == obj.NAME_NONE) { if a.Type == obj.TYPE_REG || ((a.Type == obj.TYPE_MEM || a.Type == obj.TYPE_ADDR) && a.Name == obj.NAME_NONE) {
switch a.Reg { switch a.Reg {
case REG_NONE: case REG_NONE:
cand = 0 cana, cand = false, false
cana = cand
case REG_AX, REG_AL, REG_AH: case REG_AX, REG_AL, REG_AH:
cana = 0 cana = false
case REG_BX, REG_BL, REG_BH: case REG_BX, REG_BL, REG_BH:
canb = 0 canb = false
case REG_CX, REG_CL, REG_CH: case REG_CX, REG_CL, REG_CH:
canc = 0 canc = false
case REG_DX, REG_DL, REG_DH: case REG_DX, REG_DL, REG_DH:
cand = 0 cand = false
} }
} }
if a.Type == obj.TYPE_MEM || a.Type == obj.TYPE_ADDR { if a.Type == obj.TYPE_MEM || a.Type == obj.TYPE_ADDR {
switch a.Index { switch a.Index {
case REG_AX: case REG_AX:
cana = 0 cana = false
case REG_BX: case REG_BX:
canb = 0 canb = false
case REG_CX: case REG_CX:
canc = 0 canc = false
case REG_DX: case REG_DX:
cand = 0 cand = false
} }
} }
if cana != 0 { switch {
case cana:
return REG_AX return REG_AX
} case canb:
if canb != 0 {
return REG_BX return REG_BX
} case canc:
if canc != 0 {
return REG_CX return REG_CX
} case cand:
if cand != 0 {
return REG_DX return REG_DX
default:
ctxt.Diag("impossible byte register")
log.Fatalf("bad code")
return 0
} }
ctxt.Diag("impossible byte register")
log.Fatalf("bad code")
return 0
} }
func isbadbyte(a *obj.Addr) bool { func isbadbyte(a *obj.Addr) bool {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment