//
// Likewise, each slice of optab is dynamically sorted using the ocmp Sort interface
// to arrange entries to minimize text size of each opcode.
-var optab = []Optab{
+//
+// optab is the sorted result of combining optabBase, optabGen, and prefixableOptab.
+var optab []Optab
+
+var optabBase = []Optab{
{as: obj.ATEXT, a1: C_LOREG, a6: C_TEXTSIZE, type_: 0, size: 0},
{as: obj.ATEXT, a1: C_LOREG, a3: C_LCON, a6: C_TEXTSIZE, type_: 0, size: 0},
{as: obj.ATEXT, a1: C_ADDR, a6: C_TEXTSIZE, type_: 0, size: 0},
entry.ispfx = true
entry.size = entry.pfxsize
}
- // Use the legacy assembler function if none provided.
- if entry.asmout == nil {
- entry.asmout = asmout
- }
prefixOptab = append(prefixOptab, entry.Optab)
}
}
}
}
+
+ // Append the generated entries, sort, and fill out oprange.
+ optab = make([]Optab, 0, len(optabBase)+len(optabGen)+len(prefixOptab))
+ optab = append(optab, optabBase...)
+ optab = append(optab, optabGen...)
+ optab = append(optab, prefixOptab...)
+ sort.Slice(optab, optabLess)
+
for i := range optab {
// Use the legacy assembler function if none provided.
if optab[i].asmout == nil {
optab[i].asmout = asmout
}
}
- // Append the generated entries, sort, and fill out oprange.
- optab = append(optab, optabGen...)
- optab = append(optab, prefixOptab...)
- sort.Slice(optab, optabLess)
for i := 0; i < len(optab); {
r := optab[i].as
import (
"bytes"
"fmt"
+ "internal/buildcfg"
"internal/testenv"
"math"
"os"
}
}
}
+
+// The optab size should remain constant when reinitializing the PPC64 assembler backend.
+func TestOptabReinit(t *testing.T) {
+ buildcfg.GOOS = "linux"
+ buildcfg.GOARCH = "ppc64le"
+ buildcfg.GOPPC64 = 8
+ buildop(nil)
+ optabLen := len(optab)
+ buildcfg.GOPPC64 = 9
+ buildop(nil)
+ reinitOptabLen := len(optab)
+ if reinitOptabLen != optabLen {
+ t.Errorf("rerunning buildop changes optab size from %d to %d", optabLen, reinitOptabLen)
+ }
+}