Skip to content

Commit c789ce3

Browse files
bmakam-qdtcherrymui
authored andcommitted
cmd/asm: add vector instructions for ChaCha20Poly1305 on ARM64
This change provides VZIP1, VZIP2, VTBL instruction for supporting ChaCha20Poly1305 implementation later. Change-Id: Ife7c87b8ab1a6495a444478eeb9d906ae4c5ffa9 Reviewed-on: https://go-review.googlesource.com/110015 Reviewed-by: Cherry Zhang <[email protected]> Run-TryBot: Cherry Zhang <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent e3c6847 commit c789ce3

File tree

6 files changed

+91
-1
lines changed

6 files changed

+91
-1
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ func arm64RegisterNumber(name string, n int16) (int16, bool) {
132132
return 0, false
133133
}
134134

135+
// IsARM64TBL reports whether the op (as defined by an arm64.A*
136+
// constant) is one of the table lookup instructions that require special
137+
// handling.
138+
func IsARM64TBL(op obj.As) bool {
139+
return op == arm64.AVTBL
140+
}
141+
135142
// ARM64RegisterExtension parses an ARM64 register with extension or arrangement.
136143
func ARM64RegisterExtension(a *obj.Addr, ext string, reg, num int16, isAmount, isIndex bool) error {
137144
Rnum := (reg & 31) + int16(num<<5)

src/cmd/asm/internal/asm/asm.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,15 @@ func (p *Parser) asmInstruction(op obj.As, cond string, a []obj.Addr) {
576576
prog.To = a[2]
577577
break
578578
}
579+
if arch.IsARM64TBL(op) {
580+
prog.From = a[0]
581+
if a[1].Type != obj.TYPE_REGLIST {
582+
p.errorf("%s: expected list; found %s", op, obj.Dconv(prog, &a[1]))
583+
}
584+
prog.SetFrom3(a[1])
585+
prog.To = a[2]
586+
break
587+
}
579588
prog.From = a[0]
580589
prog.Reg = p.getRegister(prog, op, &a[1])
581590
prog.To = a[2]

src/cmd/asm/internal/asm/testdata/arm64.s

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,28 @@ TEXT foo(SB), DUPOK|NOSPLIT, $-8
107107
VSRI $8, V1.H8, V2.H8 // 2244186f
108108
VSRI $2, V1.B8, V2.B8 // 22440e2f
109109
VSRI $2, V1.B16, V2.B16 // 22440e6f
110+
VTBL V22.B16, [V28.B16, V29.B16], V11.B16 // 8b23164e
111+
VTBL V18.B8, [V17.B16, V18.B16, V19.B16], V22.B8 // 3642120e
112+
VTBL V31.B8, [V14.B16, V15.B16, V16.B16, V17.B16], V15.B8 // cf611f0e
113+
VTBL V14.B16, [V16.B16], V11.B16 // 0b020e4e
114+
VTBL V28.B16, [V25.B16, V26.B16], V5.B16 // 25231c4e
115+
VTBL V16.B8, [V4.B16, V5.B16, V6.B16], V12.B8 // 8c40100e
116+
VTBL V4.B8, [V16.B16, V17.B16, V18.B16, V19.B16], V4.B8 // 0462040e
117+
VTBL V15.B8, [V1.B16], V20.B8 // 34000f0e
118+
VTBL V26.B16, [V2.B16, V3.B16], V26.B16 // 5a201a4e
119+
VTBL V15.B8, [V6.B16, V7.B16, V8.B16], V2.B8 // c2400f0e
120+
VTBL V2.B16, [V27.B16, V28.B16, V29.B16, V30.B16], V18.B16 // 7263024e
121+
VTBL V11.B16, [V13.B16], V27.B16 // bb010b4e
122+
VTBL V3.B8, [V7.B16, V8.B16], V25.B8 // f920030e
123+
VTBL V14.B16, [V3.B16, V4.B16, V5.B16], V17.B16 // 71400e4e
124+
VTBL V13.B16, [V29.B16, V30.B16, V31.B16, V0.B16], V28.B16 // bc630d4e
125+
VTBL V3.B8, [V27.B16], V8.B8 // 6803030e
126+
VZIP1 V16.H8, V3.H8, V19.H8 // 7338504e
127+
VZIP2 V22.D2, V25.D2, V21.D2 // 357bd64e
128+
VZIP1 V6.D2, V9.D2, V11.D2 // 2b39c64e
129+
VZIP2 V10.D2, V13.D2, V3.D2 // a379ca4e
130+
VZIP1 V17.S2, V4.S2, V26.S2 // 9a38910e
131+
VZIP2 V25.S2, V14.S2, V25.S2 // d979990e
110132
MOVD (R2)(R6.SXTW), R4 // 44c866f8
111133
MOVD (R3)(R6), R5 // MOVD (R3)(R6*1), R5 // 656866f8
112134
MOVD (R2)(R6), R4 // MOVD (R2)(R6*1), R4 // 446866f8

src/cmd/internal/obj/arm64/a.out.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,9 @@ const (
897897
AVUSHR
898898
AVSHL
899899
AVSRI
900+
AVTBL
901+
AVZIP1
902+
AVZIP2
900903
ALAST
901904
AB = obj.AJMP
902905
ABL = obj.ACALL

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,5 +399,8 @@ var Anames = []string{
399399
"VUSHR",
400400
"VSHL",
401401
"VSRI",
402+
"VTBL",
403+
"VZIP1",
404+
"VZIP2",
402405
"LAST",
403406
}

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

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,9 @@ var optab = []Optab{
359359
{AVMOVI, C_ADDCON, C_NONE, C_ARNG, 86, 4, 0, 0, 0},
360360
{AVFMLA, C_ARNG, C_ARNG, C_ARNG, 72, 4, 0, 0, 0},
361361
{AVEXT, C_VCON, C_ARNG, C_ARNG, 94, 4, 0, 0, 0},
362+
{AVTBL, C_ARNG, C_NONE, C_ARNG, 100, 4, 0, 0, 0},
362363
{AVUSHR, C_VCON, C_ARNG, C_ARNG, 95, 4, 0, 0, 0},
364+
{AVZIP1, C_ARNG, C_ARNG, C_ARNG, 72, 4, 0, 0, 0},
363365

364366
/* conditional operations */
365367
{ACSEL, C_COND, C_REG, C_REG, 18, 4, 0, 0, 0}, /* from3 optional */
@@ -2381,11 +2383,15 @@ func buildop(ctxt *obj.Link) {
23812383
oprangeset(AVRBIT, t)
23822384
oprangeset(AVREV64, t)
23832385

2386+
case AVZIP1:
2387+
oprangeset(AVZIP2, t)
2388+
23842389
case ASHA1H,
23852390
AVCNT,
23862391
AVMOV,
23872392
AVLD1,
23882393
AVST1,
2394+
AVTBL,
23892395
AVDUP,
23902396
AVMOVI,
23912397
APRFM,
@@ -4507,6 +4513,40 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) {
45074513
rf := int(p.From.Reg)
45084514
o1 |= uint32(rf & 31)
45094515

4516+
case 100: /* VTBL Vn.<T>, [Vt1.<T>, Vt2.<T>, ...], Vd.<T> */
4517+
af := int((p.From.Reg >> 5) & 15)
4518+
at := int((p.To.Reg >> 5) & 15)
4519+
if af != at {
4520+
c.ctxt.Diag("invalid arrangement: %v\n", p)
4521+
}
4522+
var q, len uint32
4523+
switch af {
4524+
case ARNG_8B:
4525+
q = 0
4526+
case ARNG_16B:
4527+
q = 1
4528+
default:
4529+
c.ctxt.Diag("invalid arrangement: %v", p)
4530+
}
4531+
rf := int(p.From.Reg)
4532+
rt := int(p.To.Reg)
4533+
offset := int(p.GetFrom3().Offset)
4534+
opcode := (offset >> 12) & 15
4535+
switch opcode {
4536+
case 0x7:
4537+
len = 0 // one register
4538+
case 0xa:
4539+
len = 1 // two register
4540+
case 0x6:
4541+
len = 2 // three registers
4542+
case 0x2:
4543+
len = 3 // four registers
4544+
default:
4545+
c.ctxt.Diag("invalid register numbers in ARM64 register list: %v", p)
4546+
}
4547+
o1 = q<<30 | 0xe<<24 | len<<13
4548+
o1 |= (uint32(rf&31) << 16) | uint32(offset&31)<<5 | uint32(rt&31)
4549+
45104550
}
45114551
out[0] = o1
45124552
out[1] = o2
@@ -5071,7 +5111,13 @@ func (c *ctxt7) oprrr(p *obj.Prog, a obj.As) uint32 {
50715111
return 1<<29 | 0x71<<21 | 0x23<<10
50725112

50735113
case AVCNT:
5074-
return 0<<31 | 0<<29 | 0xE<<24 | 0x10<<17 | 5<<12 | 2<<10
5114+
return 0xE<<24 | 0x10<<17 | 5<<12 | 2<<10
5115+
5116+
case AVZIP1:
5117+
return 0xE<<24 | 3<<12 | 2<<10
5118+
5119+
case AVZIP2:
5120+
return 0xE<<24 | 1<<14 | 3<<12 | 2<<10
50755121

50765122
case AVEOR:
50775123
return 1<<29 | 0x71<<21 | 7<<10

0 commit comments

Comments
 (0)