Skip to content

Commit 2883dac

Browse files
author
ArsenySamoylov
committed
runtime,cmd/internal/obj/arm64,cmd/internal/objabi,cmd/link/internal/arm64: enable conditional branches on target outside of asm file
Results of running runtime hash benchmarks: goos: linux goarch: arm64 pkg: runtime │ master_noaes_runtime_hash.txt │ arm64-condbr19_noaes_runtime_hash.txt │ │ sec/op │ sec/op vs base │ Hash5-4 9.628n ± 0% 8.858n ± 0% -8.00% (p=0.000 n=25) Hash16-4 9.627n ± 0% 9.627n ± 0% ~ (p=0.117 n=25) Hash64-4 15.03n ± 0% 14.25n ± 0% -5.19% (p=0.000 n=25) Hash1024-4 90.19n ± 0% 88.19n ± 0% -2.22% (p=0.000 n=25) Hash65536-4 5.058µ ± 0% 5.192µ ± 0% +2.65% (p=0.000 n=25) HashStringSpeed-4 19.00n ± 3% 18.46n ± 4% ~ (p=0.096 n=25) HashBytesSpeed-4 65.26n ± 0% 64.36n ± 0% -1.38% (p=0.000 n=25) HashInt32Speed-4 12.46n ± 0% 12.50n ± 1% ~ (p=0.829 n=25) HashInt64Speed-4 13.01n ± 3% 12.47n ± 3% -4.15% (p=0.000 n=25) HashStringArraySpeed-4 43.45n ± 2% 41.55n ± 3% -4.37% (p=0.000 n=25) FastrandHashiter-4 11.72n ± 1% 11.81n ± 1% ~ (p=0.079 n=25) geomean 33.77n 33.00n -2.26% │ master_noaes_runtime_hash.txt │ arm64-condbr19_noaes_runtime_hash.txt │ │ B/s │ B/s vs base │ Hash5-4 495.3Mi ± 0% 538.3Mi ± 0% +8.69% (p=0.000 n=25) Hash16-4 1.548Gi ± 0% 1.548Gi ± 0% +0.00% (p=0.025 n=25) Hash64-4 3.966Gi ± 0% 4.183Gi ± 0% +5.47% (p=0.000 n=25) Hash1024-4 10.57Gi ± 0% 10.81Gi ± 0% +2.27% (p=0.000 n=25) Hash65536-4 12.07Gi ± 0% 11.76Gi ± 0% -2.57% (p=0.000 n=25) geomean 3.279Gi 3.367Gi +2.70% These results are obtained with cpu.ARM64.HasAES == false Change-Id: If282267b9b2dcf474516cb33bfdbda4ee35bb8fa
1 parent e705a2d commit 2883dac

File tree

7 files changed

+118
-78
lines changed

7 files changed

+118
-78
lines changed

src/cmd/internal/obj/arm64/asm7.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2691,6 +2691,11 @@ func cmp(a int, b int) bool {
26912691
return true
26922692
}
26932693

2694+
case C_SBRA:
2695+
if b == C_ADDR {
2696+
return true
2697+
}
2698+
26942699
case C_LBRA:
26952700
if b == C_SBRA {
26962701
return true
@@ -4260,7 +4265,18 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) {
42604265
o1 = c.opirr(p, p.As)
42614266

42624267
o1 |= uint32(p.From.Reg & 31)
4263-
o1 |= uint32(c.brdist(p, 0, 19, 2) << 5)
4268+
4269+
if p.To.Sym == nil {
4270+
o1 |= uint32(c.brdist(p, 0, 19, 2) << 5)
4271+
break
4272+
}
4273+
4274+
rel := obj.Addrel(c.cursym)
4275+
rel.Off = int32(c.pc)
4276+
rel.Siz = 4
4277+
rel.Sym = p.To.Sym
4278+
rel.Add = p.To.Offset
4279+
rel.Type = objabi.R_AARCH64_CONDBR19
42644280

42654281
case 40: /* tbz */
42664282
o1 = c.opirr(p, p.As)

src/cmd/internal/obj/arm64/asm_arm64_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,17 @@ func TestMOVK(t *testing.T) {
3838
t.Errorf("Got %x want %x\n", x, want)
3939
}
4040
}
41+
42+
func testcondbr19() uint64
43+
func testcondbr19_target() uint64 {
44+
return 42
45+
}
46+
47+
// TestCondBr19 makes sure that conditional branch on labels outside of *arm64.s file works fine
48+
func TestCondBr19(t *testing.T) {
49+
x := testcondbr19()
50+
want := uint64(42)
51+
if x != want {
52+
t.Errorf("Got %s want %d\n", x, want)
53+
}
54+
}

src/cmd/internal/obj/arm64/asm_arm64_test.s

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,7 @@ TEXT ·testmovk(SB), NOSPLIT, $0-8
3737
MOVK $(40000<<48), R0
3838
MOVD R0, ret+0(FP)
3939
RET
40+
41+
// testcondbr19() uint64
42+
TEXT ·testcondbr19(SB), NOSPLIT, $0-8
43+
CBZ R0, ·testcondbr19_target(SB)

src/cmd/internal/objabi/reloctype.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ const (
131131
// inherently processor specific.
132132

133133
// Arm64.
134+
R_AARCH64_CONDBR19
134135

135136
// Set a MOV[NZ] immediate field to bits [15:0] of the offset from the thread
136137
// local base to the thread local variable defined by the referenced (thread

src/cmd/internal/objabi/reloctype_string.go

Lines changed: 66 additions & 65 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/link/internal/arm64/asm.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,18 @@ func archreloc(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, r loade
968968
}
969969
return val | ((t >> 2) & 0x03ffffff), noExtReloc, true
970970

971+
case objabi.R_AARCH64_CONDBR19:
972+
var t int64
973+
if ldr.SymType(rs) == sym.SDYNIMPORT {
974+
t = (ldr.SymAddr(syms.PLT) + r.Add()) - (ldr.SymValue(s) + int64(r.Off()))
975+
} else {
976+
t = (ldr.SymAddr(rs) + r.Add()) - (ldr.SymValue(s) + int64(r.Off()))
977+
}
978+
if t >= 1<<20 || t < -1<<20 {
979+
ldr.Errorf(s, "program too large, call relocation distance = %d", t)
980+
}
981+
return val | (((t >> 2) & 0x7ffff) << 5), noExtReloc, true
982+
971983
case objabi.R_ARM64_GOT:
972984
if (val>>24)&0x9f == 0x90 {
973985
// R_AARCH64_ADR_GOT_PAGE

src/runtime/asm_arm64.s

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ CALLFN(·call1073741824, 1073741824)
532532
// func memhash32(p unsafe.Pointer, h uintptr) uintptr
533533
TEXT runtime·memhash32<ABIInternal>(SB),NOSPLIT|NOFRAME,$0-24
534534
MOVB runtime·useAeshash(SB), R10
535-
CBZ R10, noaes
535+
CBZ R10, runtime·memhash32Fallback<ABIInternal>(SB)
536536
MOVD $runtime·aeskeysched+0(SB), R3
537537

538538
VEOR V0.B16, V0.B16, V0.B16
@@ -548,13 +548,11 @@ TEXT runtime·memhash32<ABIInternal>(SB),NOSPLIT|NOFRAME,$0-24
548548

549549
VMOV V0.D[0], R0
550550
RET
551-
noaes:
552-
B runtime·memhash32Fallback<ABIInternal>(SB)
553551

554552
// func memhash64(p unsafe.Pointer, h uintptr) uintptr
555553
TEXT runtime·memhash64<ABIInternal>(SB),NOSPLIT|NOFRAME,$0-24
556554
MOVB runtime·useAeshash(SB), R10
557-
CBZ R10, noaes
555+
CBZ R10, runtime·memhash64Fallback<ABIInternal>(SB)
558556
MOVD $runtime·aeskeysched+0(SB), R3
559557

560558
VEOR V0.B16, V0.B16, V0.B16
@@ -570,25 +568,19 @@ TEXT runtime·memhash64<ABIInternal>(SB),NOSPLIT|NOFRAME,$0-24
570568

571569
VMOV V0.D[0], R0
572570
RET
573-
noaes:
574-
B runtime·memhash64Fallback<ABIInternal>(SB)
575571

576572
// func memhash(p unsafe.Pointer, h, size uintptr) uintptr
577573
TEXT runtime·memhash<ABIInternal>(SB),NOSPLIT|NOFRAME,$0-32
578574
MOVB runtime·useAeshash(SB), R10
579-
CBZ R10, noaes
575+
CBZ R10, runtime·memhashFallback<ABIInternal>(SB)
580576
B aeshashbody<>(SB)
581-
noaes:
582-
B runtime·memhashFallback<ABIInternal>(SB)
583577

584578
// func strhash(p unsafe.Pointer, h uintptr) uintptr
585579
TEXT runtime·strhash<ABIInternal>(SB),NOSPLIT|NOFRAME,$0-24
586580
MOVB runtime·useAeshash(SB), R10
587-
CBZ R10, noaes
581+
CBZ R10, runtime·strhashFallback<ABIInternal>(SB)
588582
LDP (R0), (R0, R2) // string data / length
589583
B aeshashbody<>(SB)
590-
noaes:
591-
B runtime·strhashFallback<ABIInternal>(SB)
592584

593585
// R0: data
594586
// R1: seed data

0 commit comments

Comments
 (0)