From: Joel Sing Date: Wed, 3 May 2023 08:19:30 +0000 (+1000) Subject: cmd/internal/obj/arm64: simplify buildop X-Git-Tag: go1.22rc1~1529 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2a1ba6ebb12994f4df15236f03eb63116b4a0c4d;p=gostls13.git cmd/internal/obj/arm64: simplify buildop This code stems from the original 7l C code, where one way to determine the end of a table is to put a sentinel entry, then scan for it. This is now Go code and the length of an array is readily available. Remove the sentinel and sentinel scan, then adjust the remaining code to work accordingly. Change-Id: I8964c787f5149f3548fa78bf8923aa7a93f9482e Reviewed-on: https://go-review.googlesource.com/c/go/+/512536 Reviewed-by: Cherry Mui TryBot-Result: Gopher Robot Reviewed-by: Matthew Dempsky Run-TryBot: Joel Sing --- diff --git a/src/cmd/internal/obj/arm64/asm7.go b/src/cmd/internal/obj/arm64/asm7.go index 2ee7b0f6c6..d5f3f20410 100644 --- a/src/cmd/internal/obj/arm64/asm7.go +++ b/src/cmd/internal/obj/arm64/asm7.go @@ -853,8 +853,6 @@ var optab = []Optab{ {obj.ADUFFZERO, C_NONE, C_NONE, C_NONE, C_SBRA, 5, 4, 0, 0, 0}, // same as AB/ABL {obj.ADUFFCOPY, C_NONE, C_NONE, C_NONE, C_SBRA, 5, 4, 0, 0, 0}, // same as AB/ABL {obj.APCALIGN, C_LCON, C_NONE, C_NONE, C_NONE, 0, 0, 0, 0, 0}, // align code - - {obj.AXXX, C_NONE, C_NONE, C_NONE, C_NONE, 0, 4, 0, 0, 0}, } // Valid pstate field values, and value to use in instruction. @@ -2596,29 +2594,27 @@ func buildop(ctxt *obj.Link) { return } - var n int for i := 0; i < C_GOK; i++ { - for n = 0; n < C_GOK; n++ { - if cmp(n, i) { - xcmp[i][n] = true + for j := 0; j < C_GOK; j++ { + if cmp(j, i) { + xcmp[i][j] = true } } } - for n = 0; optab[n].as != obj.AXXX; n++ { - } - sort.Sort(ocmp(optab[:n])) - for i := 0; i < n; i++ { - r := optab[i].as - start := i - for optab[i].as == r { - i++ + + sort.Sort(ocmp(optab)) + for i := 0; i < len(optab); i++ { + as, start := optab[i].as, i + for ; i < len(optab)-1; i++ { + if optab[i+1].as != as { + break + } } - t := optab[start:i] - i-- - oprangeset(r, t) - switch r { + t := optab[start : i+1] + oprangeset(as, t) + switch as { default: - ctxt.Diag("unknown op in build: %v", r) + ctxt.Diag("unknown op in build: %v", as) ctxt.DiagFlush() log.Fatalf("bad code")