22// Use of this source code is governed by a BSD-style
33// license that can be found in the LICENSE file.
44
5- //go:build gc && !purego
5+ //go:build gc && !purego && (ppc64 || ppc64le)
66
77#include "textflag.h"
88
99// This was ported from the amd64 implementation.
1010
11+ #ifdef GOARCH_ppc64le
12+ #define LE_MOVD MOVD
13+ #define LE_MOVWZ MOVWZ
14+ #define LE_MOVHZ MOVHZ
15+ #else
16+ #define LE_MOVD MOVDBR
17+ #define LE_MOVWZ MOVWBR
18+ #define LE_MOVHZ MOVHBR
19+ #endif
20+
1121#define POLY1305_ADD(msg, h0, h1, h2, t0, t1, t2) \
12- MOVD (msg), t0; \
13- MOVD 8 (msg), t1; \
22+ LE_MOVD (msg)( R0) , t0; \
23+ LE_MOVD (msg)(R24 ), t1; \
1424 MOVD $1 , t2; \
1525 ADDC t0, h0, h0; \
1626 ADDE t1, h1, h1; \
5060 ADDE t3, h1, h1; \
5161 ADDZE h2
5262
53- DATA ·poly1305Mask<>+0x00 (SB)/8 , $0x0FFFFFFC0FFFFFFF
54- DATA ·poly1305Mask<>+0x08 (SB)/8 , $0x0FFFFFFC0FFFFFFC
55- GLOBL ·poly1305Mask<>(SB), RODATA, $16
56-
5763// func update(state *[7]uint64, msg []byte)
5864TEXT ·update(SB), $0 -32
5965 MOVD state+0 (FP), R3
@@ -66,6 +72,8 @@ TEXT ·update(SB), $0-32
6672 MOVD 24 (R3), R11 // r0
6773 MOVD 32 (R3), R12 // r1
6874
75+ MOVD $8 , R24
76+
6977 CMP R5, $16
7078 BLT bytes_between_0_and_15
7179
@@ -94,7 +102,7 @@ flush_buffer:
94102
95103 // Greater than 8 -- load the rightmost remaining bytes in msg
96104 // and put into R17 (h1)
97- MOVD (R4)(R21), R17
105+ LE_MOVD (R4)(R21), R17
98106 MOVD $16 , R22
99107
100108 // Find the offset to those bytes
@@ -118,7 +126,7 @@ just1:
118126 BLT less8
119127
120128 // Exactly 8
121- MOVD (R4), R16
129+ LE_MOVD (R4), R16
122130
123131 CMP R17, $0
124132
@@ -133,15 +141,15 @@ less8:
133141 MOVD $0 , R22 // shift count
134142 CMP R5, $4
135143 BLT less4
136- MOVWZ (R4), R16
144+ LE_MOVWZ (R4), R16
137145 ADD $4 , R4
138146 ADD $-4 , R5
139147 MOVD $32 , R22
140148
141149less4:
142150 CMP R5, $2
143151 BLT less2
144- MOVHZ (R4), R21
152+ LE_MOVHZ (R4), R21
145153 SLD R22, R21, R21
146154 OR R16, R21, R16
147155 ADD $16 , R22
0 commit comments