diff options
| author | WANG Xuerui <git@xen0n.name> | 2023-03-28 19:30:04 +0800 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-04-07 20:20:25 +0000 |
| commit | 47b22b6548822d7b51ba3dca3c8c5fe669bfdd59 (patch) | |
| tree | 9b6da1b8d7f5adc895f441720889e7acc60ccc2f /src/cmd/link | |
| parent | 10c079a0ad2283be3761a47eda6e41bde38fd16b (diff) | |
| download | go-47b22b6548822d7b51ba3dca3c8c5fe669bfdd59.tar.xz | |
cmd/link, cmd/internal/obj/loong64: support the PCALIGN directive
Allow writing `PCALIGN $imm` where imm is a power-of-2 between 8 and
2048 (inclusive), for ensuring that the following instruction is
placed at an imm-byte boundary relative to the beginning of the
function. If the PC is not sufficiently aligned, NOOPs will be
inserted to make it so, otherwise the directive will do nothing.
This could be useful for both asm performance hand-tuning, and future
scenarios where a certain bigger alignment might be required.
Change-Id: Iad6244669a3d5adea88eceb0dc7be1af4f0d4fc9
Reviewed-on: https://go-review.googlesource.com/c/go/+/479815
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Run-TryBot: WANG Xuerui <git@xen0n.name>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: abner chenc <chenguoqi@loongson.cn>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/cmd/link')
| -rw-r--r-- | src/cmd/link/link_test.go | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/cmd/link/link_test.go b/src/cmd/link/link_test.go index 72dbca5c63..c37d6e57bc 100644 --- a/src/cmd/link/link_test.go +++ b/src/cmd/link/link_test.go @@ -567,7 +567,8 @@ func main() { } ` -const testFuncAlignAsmSrc = ` +var testFuncAlignAsmSources = map[string]string{ + "arm64": ` #include "textflag.h" TEXT ·alignPc(SB),NOSPLIT, $0-0 @@ -578,13 +579,27 @@ TEXT ·alignPc(SB),NOSPLIT, $0-0 GLOBL ·alignPcFnAddr(SB),RODATA,$8 DATA ·alignPcFnAddr(SB)/8,$·alignPc(SB) -` +`, + "loong64": ` +#include "textflag.h" + +TEXT ·alignPc(SB),NOSPLIT, $0-0 + MOVV $2, R4 + PCALIGN $512 + MOVV $3, R5 + RET + +GLOBL ·alignPcFnAddr(SB),RODATA,$8 +DATA ·alignPcFnAddr(SB)/8,$·alignPc(SB) +`, +} // TestFuncAlign verifies that the address of a function can be aligned -// with a specific value on arm64. +// with a specific value on arm64 and loong64. func TestFuncAlign(t *testing.T) { - if runtime.GOARCH != "arm64" || runtime.GOOS != "linux" { - t.Skip("skipping on non-linux/arm64 platform") + testFuncAlignAsmSrc := testFuncAlignAsmSources[runtime.GOARCH] + if len(testFuncAlignAsmSrc) == 0 || runtime.GOOS != "linux" { + t.Skip("skipping on non-linux/{arm64,loong64} platform") } testenv.MustHaveGoBuild(t) |
