mirror of
https://github.com/golang/go
synced 2024-11-27 00:01:23 -07:00
cmd/internal/obj/arm64: improve comment and signature of pcAlignPadLength
The function just calculates the number of needed padding bytes, instead of actually carrying out the alignment operation. And it has the context argument at the end of the argument list, while contexts idiomatically come first. Indeed, this is the only case in cmd/internal/obj where ctxt is not the only argument and does not come first. Fix those two nits; no functional change intended. Suggested by Ian during review of CL 479815 (that introduces a copy of this helper into the loong64 port). Change-Id: Ieb221ead23282abe6e04804d537e1234c7ab21d0 Reviewed-on: https://go-review.googlesource.com/c/go/+/483155 Run-TryBot: Cherry Mui <cherryyz@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
parent
f00c54146c
commit
58eaecbf9a
@ -1015,8 +1015,9 @@ var sysInstFields = map[SpecialOperand]struct {
|
|||||||
// Used for padding NOOP instruction
|
// Used for padding NOOP instruction
|
||||||
const OP_NOOP = 0xd503201f
|
const OP_NOOP = 0xd503201f
|
||||||
|
|
||||||
// align code to a certain length by padding bytes.
|
// pcAlignPadLength returns the number of bytes required to align pc to alignedValue,
|
||||||
func pcAlignPadLength(pc int64, alignedValue int64, ctxt *obj.Link) int {
|
// reporting an error if alignedValue is not a power of two or is out of range.
|
||||||
|
func pcAlignPadLength(ctxt *obj.Link, pc int64, alignedValue int64) int {
|
||||||
if !((alignedValue&(alignedValue-1) == 0) && 8 <= alignedValue && alignedValue <= 2048) {
|
if !((alignedValue&(alignedValue-1) == 0) && 8 <= alignedValue && alignedValue <= 2048) {
|
||||||
ctxt.Diag("alignment value of an instruction must be a power of two and in the range [8, 2048], got %d\n", alignedValue)
|
ctxt.Diag("alignment value of an instruction must be a power of two and in the range [8, 2048], got %d\n", alignedValue)
|
||||||
}
|
}
|
||||||
@ -1075,7 +1076,7 @@ func span7(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
|
|||||||
switch p.As {
|
switch p.As {
|
||||||
case obj.APCALIGN:
|
case obj.APCALIGN:
|
||||||
alignedValue := p.From.Offset
|
alignedValue := p.From.Offset
|
||||||
m = pcAlignPadLength(pc, alignedValue, ctxt)
|
m = pcAlignPadLength(ctxt, pc, alignedValue)
|
||||||
// Update the current text symbol alignment value.
|
// Update the current text symbol alignment value.
|
||||||
if int32(alignedValue) > cursym.Func().Align {
|
if int32(alignedValue) > cursym.Func().Align {
|
||||||
cursym.Func().Align = int32(alignedValue)
|
cursym.Func().Align = int32(alignedValue)
|
||||||
@ -1150,7 +1151,7 @@ func span7(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
|
|||||||
switch p.As {
|
switch p.As {
|
||||||
case obj.APCALIGN:
|
case obj.APCALIGN:
|
||||||
alignedValue := p.From.Offset
|
alignedValue := p.From.Offset
|
||||||
m = pcAlignPadLength(pc, alignedValue, ctxt)
|
m = pcAlignPadLength(ctxt, pc, alignedValue)
|
||||||
break
|
break
|
||||||
case obj.ANOP, obj.AFUNCDATA, obj.APCDATA:
|
case obj.ANOP, obj.AFUNCDATA, obj.APCDATA:
|
||||||
continue
|
continue
|
||||||
@ -1183,7 +1184,7 @@ func span7(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
|
|||||||
}
|
}
|
||||||
if p.As == obj.APCALIGN {
|
if p.As == obj.APCALIGN {
|
||||||
alignedValue := p.From.Offset
|
alignedValue := p.From.Offset
|
||||||
v := pcAlignPadLength(p.Pc, alignedValue, c.ctxt)
|
v := pcAlignPadLength(c.ctxt, p.Pc, alignedValue)
|
||||||
for i = 0; i < int(v/4); i++ {
|
for i = 0; i < int(v/4); i++ {
|
||||||
// emit ANOOP instruction by the padding size
|
// emit ANOOP instruction by the padding size
|
||||||
c.ctxt.Arch.ByteOrder.PutUint32(bp, OP_NOOP)
|
c.ctxt.Arch.ByteOrder.PutUint32(bp, OP_NOOP)
|
||||||
|
Loading…
Reference in New Issue
Block a user