mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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 <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
3b251e603d
commit
2ebe1bdd89
3 changed files with 383 additions and 383 deletions
|
|
@ -740,7 +740,6 @@ type Link struct {
|
||||||
Rep int
|
Rep int
|
||||||
Repn int
|
Repn int
|
||||||
Lock int
|
Lock int
|
||||||
AsmBuf AsmBuf // instruction buffer for x86
|
|
||||||
Instoffset int64
|
Instoffset int64
|
||||||
Autosize int32
|
Autosize int32
|
||||||
Armsize int32
|
Armsize int32
|
||||||
|
|
@ -878,96 +877,3 @@ func (h *HeadType) String() string {
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("HeadType(%d)", *h)
|
return fmt.Sprintf("HeadType(%d)", *h)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AsmBuf is a simple buffer to assemble variable-length x86 instructions into.
|
|
||||||
type AsmBuf struct {
|
|
||||||
buf [100]byte
|
|
||||||
off int
|
|
||||||
}
|
|
||||||
|
|
||||||
// Put1 appends one byte to the end of the buffer.
|
|
||||||
func (a *AsmBuf) Put1(x byte) {
|
|
||||||
a.buf[a.off] = x
|
|
||||||
a.off++
|
|
||||||
}
|
|
||||||
|
|
||||||
// Put2 appends two bytes to the end of the buffer.
|
|
||||||
func (a *AsmBuf) Put2(x, y byte) {
|
|
||||||
a.buf[a.off+0] = x
|
|
||||||
a.buf[a.off+1] = y
|
|
||||||
a.off += 2
|
|
||||||
}
|
|
||||||
|
|
||||||
// Put3 appends three bytes to the end of the buffer.
|
|
||||||
func (a *AsmBuf) Put3(x, y, z byte) {
|
|
||||||
a.buf[a.off+0] = x
|
|
||||||
a.buf[a.off+1] = y
|
|
||||||
a.buf[a.off+2] = z
|
|
||||||
a.off += 3
|
|
||||||
}
|
|
||||||
|
|
||||||
// Put4 appends four bytes to the end of the buffer.
|
|
||||||
func (a *AsmBuf) Put4(x, y, z, w byte) {
|
|
||||||
a.buf[a.off+0] = x
|
|
||||||
a.buf[a.off+1] = y
|
|
||||||
a.buf[a.off+2] = z
|
|
||||||
a.buf[a.off+3] = w
|
|
||||||
a.off += 4
|
|
||||||
}
|
|
||||||
|
|
||||||
// PutInt16 writes v into the buffer using little-endian encoding.
|
|
||||||
func (a *AsmBuf) PutInt16(v int16) {
|
|
||||||
a.buf[a.off+0] = byte(v)
|
|
||||||
a.buf[a.off+1] = byte(v >> 8)
|
|
||||||
a.off += 2
|
|
||||||
}
|
|
||||||
|
|
||||||
// PutInt32 writes v into the buffer using little-endian encoding.
|
|
||||||
func (a *AsmBuf) PutInt32(v int32) {
|
|
||||||
a.buf[a.off+0] = byte(v)
|
|
||||||
a.buf[a.off+1] = byte(v >> 8)
|
|
||||||
a.buf[a.off+2] = byte(v >> 16)
|
|
||||||
a.buf[a.off+3] = byte(v >> 24)
|
|
||||||
a.off += 4
|
|
||||||
}
|
|
||||||
|
|
||||||
// PutInt64 writes v into the buffer using little-endian encoding.
|
|
||||||
func (a *AsmBuf) PutInt64(v int64) {
|
|
||||||
a.buf[a.off+0] = byte(v)
|
|
||||||
a.buf[a.off+1] = byte(v >> 8)
|
|
||||||
a.buf[a.off+2] = byte(v >> 16)
|
|
||||||
a.buf[a.off+3] = byte(v >> 24)
|
|
||||||
a.buf[a.off+4] = byte(v >> 32)
|
|
||||||
a.buf[a.off+5] = byte(v >> 40)
|
|
||||||
a.buf[a.off+6] = byte(v >> 48)
|
|
||||||
a.buf[a.off+7] = byte(v >> 56)
|
|
||||||
a.off += 8
|
|
||||||
}
|
|
||||||
|
|
||||||
// Put copies b into the buffer.
|
|
||||||
func (a *AsmBuf) Put(b []byte) {
|
|
||||||
copy(a.buf[a.off:], b)
|
|
||||||
a.off += len(b)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Insert inserts b at offset i.
|
|
||||||
func (a *AsmBuf) Insert(i int, b byte) {
|
|
||||||
a.off++
|
|
||||||
copy(a.buf[i+1:a.off], a.buf[i:a.off-1])
|
|
||||||
a.buf[i] = b
|
|
||||||
}
|
|
||||||
|
|
||||||
// Last returns the byte at the end of the buffer.
|
|
||||||
func (a *AsmBuf) Last() byte { return a.buf[a.off-1] }
|
|
||||||
|
|
||||||
// Len returns the length of the buffer.
|
|
||||||
func (a *AsmBuf) Len() int { return a.off }
|
|
||||||
|
|
||||||
// Bytes returns the contents of the buffer.
|
|
||||||
func (a *AsmBuf) Bytes() []byte { return a.buf[:a.off] }
|
|
||||||
|
|
||||||
// Reset empties the buffer.
|
|
||||||
func (a *AsmBuf) Reset() { a.off = 0 }
|
|
||||||
|
|
||||||
// Peek returns the byte at offset i.
|
|
||||||
func (a *AsmBuf) Peek(i int) byte { return a.buf[i] }
|
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -38,7 +38,6 @@ sync/cond_test.go: assignment copies lock value to c2: sync.Cond contains sync.n
|
||||||
// Except for the runtime/pprof case, the API is not exported.
|
// Except for the runtime/pprof case, the API is not exported.
|
||||||
cmd/internal/bio/buf.go: method Seek(offset int64, whence int) int64 should have signature Seek(int64, int) (int64, error)
|
cmd/internal/bio/buf.go: method Seek(offset int64, whence int) int64 should have signature Seek(int64, int) (int64, error)
|
||||||
cmd/internal/bio/buf.go: method Seek(offset int64, whence int) int64 should have signature Seek(int64, int) (int64, error)
|
cmd/internal/bio/buf.go: method Seek(offset int64, whence int) int64 should have signature Seek(int64, int) (int64, error)
|
||||||
cmd/internal/obj/link.go: method Peek(i int) byte should have signature Peek(int) ([]byte, error)
|
|
||||||
fmt/print.go: method WriteByte(c byte) should have signature WriteByte(byte) error
|
fmt/print.go: method WriteByte(c byte) should have signature WriteByte(byte) error
|
||||||
runtime/pprof/pprof.go: method WriteTo(w io.Writer, debug int) error should have signature WriteTo(io.Writer) (int64, error)
|
runtime/pprof/pprof.go: method WriteTo(w io.Writer, debug int) error should have signature WriteTo(io.Writer) (int64, error)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue