Skip to content

Commit

Permalink
asm/arm64: removes unneeded 16 bytes alignment (#1367)
Browse files Browse the repository at this point in the history
signed-off-by: Takeshi Yoneda <[email protected]>
  • Loading branch information
mathetake authored Apr 17, 2023
1 parent d9e5d6b commit 27b405f
Show file tree
Hide file tree
Showing 7 changed files with 2,606 additions and 2,619 deletions.
14 changes: 1 addition & 13 deletions internal/asm/arm64/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func (a *AssemblerImpl) Assemble() ([]byte, error) {
a.maybeFlushConstPool(n.next == nil)
}

code := a.bytes()
code := a.buf.Bytes()

if err := a.FinalizeJumpTableEntry(code); err != nil {
return nil, err
Expand Down Expand Up @@ -413,18 +413,6 @@ func (a *AssemblerImpl) maybeFlushConstPool(endOfBinary bool) {
}
}

// bytes returns the encoded binary.
func (a *AssemblerImpl) bytes() []byte {
// 16 bytes alignment to match our impl with golang-asm.
// https://github.com/golang/go/blob/release-branch.go1.15/src/cmd/internal/obj/arm64/asm7.go#L62
//
// TODO: Delete after golang-asm removal.
if pad := 16 - a.buf.Len()%16; pad > 0 && pad != 16 {
a.buf.Write(make([]byte, pad))
}
return a.buf.Bytes()
}

// encodeNode encodes the given node into writer.
func (a *AssemblerImpl) encodeNode(n *nodeImpl) (err error) {
switch n.types {
Expand Down
55 changes: 27 additions & 28 deletions internal/asm/arm64/impl_1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ func TestAssemblerImpl_EncodeVectorRegisterToMemory(t *testing.T) {
dstReg2: RegR6,
vectorArrangement: VectorArrangementB,
},
exp: []byte{0x8b, 0x69, 0x26, 0x3c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
exp: []byte{0x8b, 0x69, 0x26, 0x3c},
},
{
name: "str h11, [x12, x6]",
Expand All @@ -753,7 +753,7 @@ func TestAssemblerImpl_EncodeVectorRegisterToMemory(t *testing.T) {
dstReg2: RegR6,
vectorArrangement: VectorArrangementH,
},
exp: []byte{0xb, 0x68, 0x26, 0x7c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
exp: []byte{0xb, 0x68, 0x26, 0x7c},
},
{
name: "str s11, [x29, x6]",
Expand All @@ -764,7 +764,7 @@ func TestAssemblerImpl_EncodeVectorRegisterToMemory(t *testing.T) {
dstReg2: RegR6,
vectorArrangement: VectorArrangementS,
},
exp: []byte{0xab, 0x6b, 0x26, 0xbc, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
exp: []byte{0xab, 0x6b, 0x26, 0xbc},
},
{
name: "str d0, [x0, x0]",
Expand All @@ -775,7 +775,7 @@ func TestAssemblerImpl_EncodeVectorRegisterToMemory(t *testing.T) {
dstReg2: RegR0,
vectorArrangement: VectorArrangementD,
},
exp: []byte{0x0, 0x68, 0x20, 0xfc, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
exp: []byte{0x0, 0x68, 0x20, 0xfc},
},
{
name: "str q30, [x30, x29]",
Expand All @@ -786,7 +786,7 @@ func TestAssemblerImpl_EncodeVectorRegisterToMemory(t *testing.T) {
dstReg2: RegR29,
vectorArrangement: VectorArrangementQ,
},
exp: []byte{0xde, 0x6b, 0xbd, 0x3c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
exp: []byte{0xde, 0x6b, 0xbd, 0x3c},
},
// Constant offset cases.
{
Expand All @@ -798,7 +798,7 @@ func TestAssemblerImpl_EncodeVectorRegisterToMemory(t *testing.T) {
dstConst: 0x7b,
vectorArrangement: VectorArrangementB,
},
exp: []byte{0x8b, 0xed, 0x1, 0x3d, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
exp: []byte{0x8b, 0xed, 0x1, 0x3d},
},
{
name: "ldr w10, #0xc ; str h11, [x12, x10]",
Expand Down Expand Up @@ -831,7 +831,7 @@ func TestAssemblerImpl_EncodeVectorRegisterToMemory(t *testing.T) {
dstConst: 0x3d8,
vectorArrangement: VectorArrangementD,
},
exp: []byte{0x8b, 0xed, 0x1, 0xfd, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
exp: []byte{0x8b, 0xed, 0x1, 0xfd},
},
{
name: "stur q1, [x30, #1]",
Expand All @@ -842,7 +842,7 @@ func TestAssemblerImpl_EncodeVectorRegisterToMemory(t *testing.T) {
dstConst: 1,
vectorArrangement: VectorArrangementQ,
},
exp: []byte{0xc1, 0x13, 0x80, 0x3c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
exp: []byte{0xc1, 0x13, 0x80, 0x3c},
},
{
name: "str q1, [x30, #0x100]",
Expand All @@ -853,7 +853,7 @@ func TestAssemblerImpl_EncodeVectorRegisterToMemory(t *testing.T) {
dstConst: 0x100,
vectorArrangement: VectorArrangementQ,
},
exp: []byte{0xc1, 0x43, 0x80, 0x3d, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
exp: []byte{0xc1, 0x43, 0x80, 0x3d},
},
{
name: "stur q1, [x30, #0xfc]",
Expand All @@ -866,7 +866,7 @@ func TestAssemblerImpl_EncodeVectorRegisterToMemory(t *testing.T) {
dstConst: 0xfc,
vectorArrangement: VectorArrangementQ,
},
exp: []byte{0xc1, 0xc3, 0x8f, 0x3c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
exp: []byte{0xc1, 0xc3, 0x8f, 0x3c},
},
{
name: `ldr w10, #0xc; str q11, [x12, x10]`,
Expand Down Expand Up @@ -915,7 +915,7 @@ func TestAssemblerImpl_EncodeMemoryToVectorRegister(t *testing.T) {
dstReg: RegV11,
vectorArrangement: VectorArrangementB,
},
exp: []byte{0x8b, 0x69, 0x68, 0x3c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
exp: []byte{0x8b, 0x69, 0x68, 0x3c},
},
{
name: "ldr h11, [x30, x0]",
Expand All @@ -926,7 +926,7 @@ func TestAssemblerImpl_EncodeMemoryToVectorRegister(t *testing.T) {
dstReg: RegV11,
vectorArrangement: VectorArrangementH,
},
exp: []byte{0xcb, 0x6b, 0x60, 0x7c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
exp: []byte{0xcb, 0x6b, 0x60, 0x7c},
},
{
name: "ldr s11, [x0, x30]",
Expand All @@ -937,7 +937,7 @@ func TestAssemblerImpl_EncodeMemoryToVectorRegister(t *testing.T) {
dstReg: RegV11,
vectorArrangement: VectorArrangementS,
},
exp: []byte{0xb, 0x68, 0x7e, 0xbc, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
exp: []byte{0xb, 0x68, 0x7e, 0xbc},
},
{
name: "ldr d11, [x15, x15]",
Expand All @@ -948,7 +948,7 @@ func TestAssemblerImpl_EncodeMemoryToVectorRegister(t *testing.T) {
dstReg: RegV11,
vectorArrangement: VectorArrangementD,
},
exp: []byte{0xeb, 0x69, 0x6f, 0xfc, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
exp: []byte{0xeb, 0x69, 0x6f, 0xfc},
},
{
name: "ldr q30, [x0, x0]",
Expand All @@ -959,7 +959,7 @@ func TestAssemblerImpl_EncodeMemoryToVectorRegister(t *testing.T) {
dstReg: RegV30,
vectorArrangement: VectorArrangementQ,
},
exp: []byte{0x1e, 0x68, 0xe0, 0x3c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
exp: []byte{0x1e, 0x68, 0xe0, 0x3c},
},
// ldr Constant offset cases.
{
Expand All @@ -971,7 +971,7 @@ func TestAssemblerImpl_EncodeMemoryToVectorRegister(t *testing.T) {
dstReg: RegV11,
vectorArrangement: VectorArrangementB,
},
exp: []byte{0x8b, 0xed, 0x41, 0x3d, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
exp: []byte{0x8b, 0xed, 0x41, 0x3d},
},
{
name: "str h11, [x12, w30, uxtw]",
Expand All @@ -981,7 +981,7 @@ func TestAssemblerImpl_EncodeMemoryToVectorRegister(t *testing.T) {
srcReg: RegR12,
vectorArrangement: VectorArrangementH,
},
exp: []byte{0x8b, 0x1, 0x40, 0x7d, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
exp: []byte{0x8b, 0x1, 0x40, 0x7d},
},
{
name: "ldr w10, #0xc ; ldr s11, [x12, x10]",
Expand Down Expand Up @@ -1024,7 +1024,7 @@ func TestAssemblerImpl_EncodeMemoryToVectorRegister(t *testing.T) {
dstReg: RegV11,
vectorArrangement: VectorArrangement8B,
},
exp: []byte{0x8b, 0xc1, 0x40, 0xd, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
exp: []byte{0x8b, 0xc1, 0x40, 0xd},
},
{
name: "ld1r {v11.16b}, [x12]",
Expand All @@ -1034,7 +1034,7 @@ func TestAssemblerImpl_EncodeMemoryToVectorRegister(t *testing.T) {
dstReg: RegV11,
vectorArrangement: VectorArrangement16B,
},
exp: []byte{0x8b, 0xc1, 0x40, 0x4d, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
exp: []byte{0x8b, 0xc1, 0x40, 0x4d},
},
{
name: "ld1r {v11.4h}, [x12]",
Expand All @@ -1044,7 +1044,7 @@ func TestAssemblerImpl_EncodeMemoryToVectorRegister(t *testing.T) {
dstReg: RegV11,
vectorArrangement: VectorArrangement4H,
},
exp: []byte{0x8b, 0xc5, 0x40, 0xd, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
exp: []byte{0x8b, 0xc5, 0x40, 0xd},
},
{
name: "ld1r {v9.8h}, [x0]",
Expand All @@ -1054,7 +1054,7 @@ func TestAssemblerImpl_EncodeMemoryToVectorRegister(t *testing.T) {
dstReg: RegV0,
vectorArrangement: VectorArrangement8H,
},
exp: []byte{0x0, 0xc4, 0x40, 0x4d, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
exp: []byte{0x0, 0xc4, 0x40, 0x4d},
},
{
name: "ld1r {v11.2s}, [x12]",
Expand All @@ -1064,7 +1064,7 @@ func TestAssemblerImpl_EncodeMemoryToVectorRegister(t *testing.T) {
dstReg: RegV11,
vectorArrangement: VectorArrangement2S,
},
exp: []byte{0x8b, 0xc9, 0x40, 0xd, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
exp: []byte{0x8b, 0xc9, 0x40, 0xd},
},
{
name: "ld1r {v0.4s}, [x0]",
Expand All @@ -1074,7 +1074,7 @@ func TestAssemblerImpl_EncodeMemoryToVectorRegister(t *testing.T) {
dstReg: RegV0,
vectorArrangement: VectorArrangement4S,
},
exp: []byte{0x0, 0xc8, 0x40, 0x4d, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
exp: []byte{0x0, 0xc8, 0x40, 0x4d},
},
{
name: "ld1r {v11.1d}, [x12]",
Expand All @@ -1084,7 +1084,7 @@ func TestAssemblerImpl_EncodeMemoryToVectorRegister(t *testing.T) {
dstReg: RegV11,
vectorArrangement: VectorArrangement1D,
},
exp: []byte{0x8b, 0xcd, 0x40, 0xd, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
exp: []byte{0x8b, 0xcd, 0x40, 0xd},
},
{
name: "ld1r {v0.2d}, [x0]",
Expand All @@ -1094,7 +1094,7 @@ func TestAssemblerImpl_EncodeMemoryToVectorRegister(t *testing.T) {
dstReg: RegV0,
vectorArrangement: VectorArrangement2D,
},
exp: []byte{0x0, 0xcc, 0x40, 0x4d, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
exp: []byte{0x0, 0xcc, 0x40, 0x4d},
},
}

Expand Down Expand Up @@ -2892,7 +2892,7 @@ func TestAssemblerImpl_EncodeThreeRegistersToRegister(t *testing.T) {
})
require.NoError(t, err)

actual := a.bytes()
actual := a.buf.Bytes()
require.Equal(t, tc.exp, actual[:4])
})
}
Expand Down Expand Up @@ -3976,7 +3976,7 @@ func TestAssemblerImpl_EncodeStaticConstToVectorRegister(t *testing.T) {
0x0, 0x0, 0x0, 0x14,
// 0x8: consts.
0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf,
0x10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x10,
},
},
{
Expand Down Expand Up @@ -4014,7 +4014,6 @@ func TestAssemblerImpl_EncodeStaticConstToVectorRegister(t *testing.T) {
0x0, 0x0, 0x0, 0x14,
// 0x8: consts.
0x1, 0x2, 0x3, 0x4,
0x0, 0x0, 0x0, 0x0,
},
},
}
Expand Down
Loading

0 comments on commit 27b405f

Please sign in to comment.