Skip to content

Commit 2ebe1bd

Browse files
committed
cmd/internal/obj: make x86's asmbuf a local variable
The x86 assembler requires a buffer to build variable-length instructions. It used to be an obj.Link field. That doesn't play nicely with concurrent assembly. Move the AsmBuf type to the x86 package, where it belongs anyway, and make it a local variable. Passes toolstash-check -all. No compiler performance impact. Updates #15756 Change-Id: I8014e52145380bfd378ee374a0c971ee5bada917 Reviewed-on: https://go-review.googlesource.com/38663 Run-TryBot: Josh Bleecher Snyder <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 3b251e6 commit 2ebe1bd

File tree

3 files changed

+383
-383
lines changed

3 files changed

+383
-383
lines changed

src/cmd/internal/obj/link.go

-94
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,6 @@ type Link struct {
740740
Rep int
741741
Repn int
742742
Lock int
743-
AsmBuf AsmBuf // instruction buffer for x86
744743
Instoffset int64
745744
Autosize int32
746745
Armsize int32
@@ -878,96 +877,3 @@ func (h *HeadType) String() string {
878877
}
879878
return fmt.Sprintf("HeadType(%d)", *h)
880879
}
881-
882-
// AsmBuf is a simple buffer to assemble variable-length x86 instructions into.
883-
type AsmBuf struct {
884-
buf [100]byte
885-
off int
886-
}
887-
888-
// Put1 appends one byte to the end of the buffer.
889-
func (a *AsmBuf) Put1(x byte) {
890-
a.buf[a.off] = x
891-
a.off++
892-
}
893-
894-
// Put2 appends two bytes to the end of the buffer.
895-
func (a *AsmBuf) Put2(x, y byte) {
896-
a.buf[a.off+0] = x
897-
a.buf[a.off+1] = y
898-
a.off += 2
899-
}
900-
901-
// Put3 appends three bytes to the end of the buffer.
902-
func (a *AsmBuf) Put3(x, y, z byte) {
903-
a.buf[a.off+0] = x
904-
a.buf[a.off+1] = y
905-
a.buf[a.off+2] = z
906-
a.off += 3
907-
}
908-
909-
// Put4 appends four bytes to the end of the buffer.
910-
func (a *AsmBuf) Put4(x, y, z, w byte) {
911-
a.buf[a.off+0] = x
912-
a.buf[a.off+1] = y
913-
a.buf[a.off+2] = z
914-
a.buf[a.off+3] = w
915-
a.off += 4
916-
}
917-
918-
// PutInt16 writes v into the buffer using little-endian encoding.
919-
func (a *AsmBuf) PutInt16(v int16) {
920-
a.buf[a.off+0] = byte(v)
921-
a.buf[a.off+1] = byte(v >> 8)
922-
a.off += 2
923-
}
924-
925-
// PutInt32 writes v into the buffer using little-endian encoding.
926-
func (a *AsmBuf) PutInt32(v int32) {
927-
a.buf[a.off+0] = byte(v)
928-
a.buf[a.off+1] = byte(v >> 8)
929-
a.buf[a.off+2] = byte(v >> 16)
930-
a.buf[a.off+3] = byte(v >> 24)
931-
a.off += 4
932-
}
933-
934-
// PutInt64 writes v into the buffer using little-endian encoding.
935-
func (a *AsmBuf) PutInt64(v int64) {
936-
a.buf[a.off+0] = byte(v)
937-
a.buf[a.off+1] = byte(v >> 8)
938-
a.buf[a.off+2] = byte(v >> 16)
939-
a.buf[a.off+3] = byte(v >> 24)
940-
a.buf[a.off+4] = byte(v >> 32)
941-
a.buf[a.off+5] = byte(v >> 40)
942-
a.buf[a.off+6] = byte(v >> 48)
943-
a.buf[a.off+7] = byte(v >> 56)
944-
a.off += 8
945-
}
946-
947-
// Put copies b into the buffer.
948-
func (a *AsmBuf) Put(b []byte) {
949-
copy(a.buf[a.off:], b)
950-
a.off += len(b)
951-
}
952-
953-
// Insert inserts b at offset i.
954-
func (a *AsmBuf) Insert(i int, b byte) {
955-
a.off++
956-
copy(a.buf[i+1:a.off], a.buf[i:a.off-1])
957-
a.buf[i] = b
958-
}
959-
960-
// Last returns the byte at the end of the buffer.
961-
func (a *AsmBuf) Last() byte { return a.buf[a.off-1] }
962-
963-
// Len returns the length of the buffer.
964-
func (a *AsmBuf) Len() int { return a.off }
965-
966-
// Bytes returns the contents of the buffer.
967-
func (a *AsmBuf) Bytes() []byte { return a.buf[:a.off] }
968-
969-
// Reset empties the buffer.
970-
func (a *AsmBuf) Reset() { a.off = 0 }
971-
972-
// Peek returns the byte at offset i.
973-
func (a *AsmBuf) Peek(i int) byte { return a.buf[i] }

0 commit comments

Comments
 (0)