1e1051a39Sopenharmony_ci#! /usr/bin/env perl
2e1051a39Sopenharmony_ci# Copyright 2007-2020 The OpenSSL Project Authors. All Rights Reserved.
3e1051a39Sopenharmony_ci#
4e1051a39Sopenharmony_ci# Licensed under the Apache License 2.0 (the "License").  You may not use
5e1051a39Sopenharmony_ci# this file except in compliance with the License.  You can obtain a copy
6e1051a39Sopenharmony_ci# in the file LICENSE in the source distribution or at
7e1051a39Sopenharmony_ci# https://www.openssl.org/source/license.html
8e1051a39Sopenharmony_ci
9e1051a39Sopenharmony_ci
10e1051a39Sopenharmony_ci# $output is the last argument if it looks like a file (it has an extension)
11e1051a39Sopenharmony_ci# $flavour is the first argument if it doesn't look like a file
12e1051a39Sopenharmony_ci$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
13e1051a39Sopenharmony_ci$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
14e1051a39Sopenharmony_ci
15e1051a39Sopenharmony_ci$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
16e1051a39Sopenharmony_ci( $xlate="${dir}ppc-xlate.pl" and -f $xlate ) or
17e1051a39Sopenharmony_ci( $xlate="${dir}perlasm/ppc-xlate.pl" and -f $xlate) or
18e1051a39Sopenharmony_cidie "can't locate ppc-xlate.pl";
19e1051a39Sopenharmony_ci
20e1051a39Sopenharmony_ciopen STDOUT,"| $^X $xlate $flavour \"$output\""
21e1051a39Sopenharmony_ci    or die "can't call $xlate: $!";
22e1051a39Sopenharmony_ci
23e1051a39Sopenharmony_ciif ($flavour=~/64/) {
24e1051a39Sopenharmony_ci    $CMPLI="cmpldi";
25e1051a39Sopenharmony_ci    $SHRLI="srdi";
26e1051a39Sopenharmony_ci    $SIGNX="extsw";
27e1051a39Sopenharmony_ci} else {
28e1051a39Sopenharmony_ci    $CMPLI="cmplwi";
29e1051a39Sopenharmony_ci    $SHRLI="srwi";
30e1051a39Sopenharmony_ci    $SIGNX="mr";
31e1051a39Sopenharmony_ci}
32e1051a39Sopenharmony_ci
33e1051a39Sopenharmony_ci$code=<<___;
34e1051a39Sopenharmony_ci.machine	"any"
35e1051a39Sopenharmony_ci.text
36e1051a39Sopenharmony_ci
37e1051a39Sopenharmony_ci.globl	.OPENSSL_fpu_probe
38e1051a39Sopenharmony_ci.align	4
39e1051a39Sopenharmony_ci.OPENSSL_fpu_probe:
40e1051a39Sopenharmony_ci	fmr	f0,f0
41e1051a39Sopenharmony_ci	blr
42e1051a39Sopenharmony_ci	.long	0
43e1051a39Sopenharmony_ci	.byte	0,12,0x14,0,0,0,0,0
44e1051a39Sopenharmony_ci.size	.OPENSSL_fpu_probe,.-.OPENSSL_fpu_probe
45e1051a39Sopenharmony_ci.globl	.OPENSSL_ppc64_probe
46e1051a39Sopenharmony_ci.align	4
47e1051a39Sopenharmony_ci.OPENSSL_ppc64_probe:
48e1051a39Sopenharmony_ci	fcfid	f1,f1
49e1051a39Sopenharmony_ci	extrdi	r0,r0,32,0
50e1051a39Sopenharmony_ci	blr
51e1051a39Sopenharmony_ci	.long	0
52e1051a39Sopenharmony_ci	.byte	0,12,0x14,0,0,0,0,0
53e1051a39Sopenharmony_ci.size	.OPENSSL_ppc64_probe,.-.OPENSSL_ppc64_probe
54e1051a39Sopenharmony_ci
55e1051a39Sopenharmony_ci.globl	.OPENSSL_altivec_probe
56e1051a39Sopenharmony_ci.align	4
57e1051a39Sopenharmony_ci.OPENSSL_altivec_probe:
58e1051a39Sopenharmony_ci	.long	0x10000484	# vor	v0,v0,v0
59e1051a39Sopenharmony_ci	blr
60e1051a39Sopenharmony_ci	.long	0
61e1051a39Sopenharmony_ci	.byte	0,12,0x14,0,0,0,0,0
62e1051a39Sopenharmony_ci.size	.OPENSSL_altivec_probe,.-..OPENSSL_altivec_probe
63e1051a39Sopenharmony_ci
64e1051a39Sopenharmony_ci.globl	.OPENSSL_crypto207_probe
65e1051a39Sopenharmony_ci.align	4
66e1051a39Sopenharmony_ci.OPENSSL_crypto207_probe:
67e1051a39Sopenharmony_ci	lvx_u	v0,0,r1
68e1051a39Sopenharmony_ci	vcipher	v0,v0,v0
69e1051a39Sopenharmony_ci	blr
70e1051a39Sopenharmony_ci	.long	0
71e1051a39Sopenharmony_ci	.byte	0,12,0x14,0,0,0,0,0
72e1051a39Sopenharmony_ci.size	.OPENSSL_crypto207_probe,.-.OPENSSL_crypto207_probe
73e1051a39Sopenharmony_ci
74e1051a39Sopenharmony_ci.globl	.OPENSSL_madd300_probe
75e1051a39Sopenharmony_ci.align	4
76e1051a39Sopenharmony_ci.OPENSSL_madd300_probe:
77e1051a39Sopenharmony_ci	xor	r0,r0,r0
78e1051a39Sopenharmony_ci	maddld	r3,r0,r0,r0
79e1051a39Sopenharmony_ci	maddhdu	r3,r0,r0,r0
80e1051a39Sopenharmony_ci	blr
81e1051a39Sopenharmony_ci	.long	0
82e1051a39Sopenharmony_ci	.byte	0,12,0x14,0,0,0,0,0
83e1051a39Sopenharmony_ci
84e1051a39Sopenharmony_ci.globl	.OPENSSL_wipe_cpu
85e1051a39Sopenharmony_ci.align	4
86e1051a39Sopenharmony_ci.OPENSSL_wipe_cpu:
87e1051a39Sopenharmony_ci	xor	r0,r0,r0
88e1051a39Sopenharmony_ci	fmr	f0,f31
89e1051a39Sopenharmony_ci	fmr	f1,f31
90e1051a39Sopenharmony_ci	fmr	f2,f31
91e1051a39Sopenharmony_ci	mr	r3,r1
92e1051a39Sopenharmony_ci	fmr	f3,f31
93e1051a39Sopenharmony_ci	xor	r4,r4,r4
94e1051a39Sopenharmony_ci	fmr	f4,f31
95e1051a39Sopenharmony_ci	xor	r5,r5,r5
96e1051a39Sopenharmony_ci	fmr	f5,f31
97e1051a39Sopenharmony_ci	xor	r6,r6,r6
98e1051a39Sopenharmony_ci	fmr	f6,f31
99e1051a39Sopenharmony_ci	xor	r7,r7,r7
100e1051a39Sopenharmony_ci	fmr	f7,f31
101e1051a39Sopenharmony_ci	xor	r8,r8,r8
102e1051a39Sopenharmony_ci	fmr	f8,f31
103e1051a39Sopenharmony_ci	xor	r9,r9,r9
104e1051a39Sopenharmony_ci	fmr	f9,f31
105e1051a39Sopenharmony_ci	xor	r10,r10,r10
106e1051a39Sopenharmony_ci	fmr	f10,f31
107e1051a39Sopenharmony_ci	xor	r11,r11,r11
108e1051a39Sopenharmony_ci	fmr	f11,f31
109e1051a39Sopenharmony_ci	xor	r12,r12,r12
110e1051a39Sopenharmony_ci	fmr	f12,f31
111e1051a39Sopenharmony_ci	fmr	f13,f31
112e1051a39Sopenharmony_ci	blr
113e1051a39Sopenharmony_ci	.long	0
114e1051a39Sopenharmony_ci	.byte	0,12,0x14,0,0,0,0,0
115e1051a39Sopenharmony_ci.size	.OPENSSL_wipe_cpu,.-.OPENSSL_wipe_cpu
116e1051a39Sopenharmony_ci
117e1051a39Sopenharmony_ci.globl	.OPENSSL_atomic_add
118e1051a39Sopenharmony_ci.align	4
119e1051a39Sopenharmony_ci.OPENSSL_atomic_add:
120e1051a39Sopenharmony_ciLadd:	lwarx	r5,0,r3
121e1051a39Sopenharmony_ci	add	r0,r4,r5
122e1051a39Sopenharmony_ci	stwcx.	r0,0,r3
123e1051a39Sopenharmony_ci	bne-	Ladd
124e1051a39Sopenharmony_ci	$SIGNX	r3,r0
125e1051a39Sopenharmony_ci	blr
126e1051a39Sopenharmony_ci	.long	0
127e1051a39Sopenharmony_ci	.byte	0,12,0x14,0,0,0,2,0
128e1051a39Sopenharmony_ci	.long	0
129e1051a39Sopenharmony_ci.size	.OPENSSL_atomic_add,.-.OPENSSL_atomic_add
130e1051a39Sopenharmony_ci
131e1051a39Sopenharmony_ci.globl	.OPENSSL_rdtsc_mftb
132e1051a39Sopenharmony_ci.align	4
133e1051a39Sopenharmony_ci.OPENSSL_rdtsc_mftb:
134e1051a39Sopenharmony_ci	mftb	r3
135e1051a39Sopenharmony_ci	blr
136e1051a39Sopenharmony_ci	.long	0
137e1051a39Sopenharmony_ci	.byte	0,12,0x14,0,0,0,0,0
138e1051a39Sopenharmony_ci.size	.OPENSSL_rdtsc_mftb,.-.OPENSSL_rdtsc_mftb
139e1051a39Sopenharmony_ci
140e1051a39Sopenharmony_ci.globl	.OPENSSL_rdtsc_mfspr268
141e1051a39Sopenharmony_ci.align	4
142e1051a39Sopenharmony_ci.OPENSSL_rdtsc_mfspr268:
143e1051a39Sopenharmony_ci	mfspr	r3,268
144e1051a39Sopenharmony_ci	blr
145e1051a39Sopenharmony_ci	.long	0
146e1051a39Sopenharmony_ci	.byte	0,12,0x14,0,0,0,0,0
147e1051a39Sopenharmony_ci.size	.OPENSSL_rdtsc_mfspr268,.-.OPENSSL_rdtsc_mfspr268
148e1051a39Sopenharmony_ci
149e1051a39Sopenharmony_ci.globl	.OPENSSL_cleanse
150e1051a39Sopenharmony_ci.align	4
151e1051a39Sopenharmony_ci.OPENSSL_cleanse:
152e1051a39Sopenharmony_ci	$CMPLI	r4,7
153e1051a39Sopenharmony_ci	li	r0,0
154e1051a39Sopenharmony_ci	bge	Lot
155e1051a39Sopenharmony_ci	$CMPLI	r4,0
156e1051a39Sopenharmony_ci	beqlr-
157e1051a39Sopenharmony_ciLittle:	mtctr	r4
158e1051a39Sopenharmony_ci	stb	r0,0(r3)
159e1051a39Sopenharmony_ci	addi	r3,r3,1
160e1051a39Sopenharmony_ci	bdnz	\$-8
161e1051a39Sopenharmony_ci	blr
162e1051a39Sopenharmony_ciLot:	andi.	r5,r3,3
163e1051a39Sopenharmony_ci	beq	Laligned
164e1051a39Sopenharmony_ci	stb	r0,0(r3)
165e1051a39Sopenharmony_ci	subi	r4,r4,1
166e1051a39Sopenharmony_ci	addi	r3,r3,1
167e1051a39Sopenharmony_ci	b	Lot
168e1051a39Sopenharmony_ciLaligned:
169e1051a39Sopenharmony_ci	$SHRLI	r5,r4,2
170e1051a39Sopenharmony_ci	mtctr	r5
171e1051a39Sopenharmony_ci	stw	r0,0(r3)
172e1051a39Sopenharmony_ci	addi	r3,r3,4
173e1051a39Sopenharmony_ci	bdnz	\$-8
174e1051a39Sopenharmony_ci	andi.	r4,r4,3
175e1051a39Sopenharmony_ci	bne	Little
176e1051a39Sopenharmony_ci	blr
177e1051a39Sopenharmony_ci	.long	0
178e1051a39Sopenharmony_ci	.byte	0,12,0x14,0,0,0,2,0
179e1051a39Sopenharmony_ci	.long	0
180e1051a39Sopenharmony_ci.size	.OPENSSL_cleanse,.-.OPENSSL_cleanse
181e1051a39Sopenharmony_ci
182e1051a39Sopenharmony_ciglobl	.CRYPTO_memcmp
183e1051a39Sopenharmony_ci.align	4
184e1051a39Sopenharmony_ci.CRYPTO_memcmp:
185e1051a39Sopenharmony_ci	$CMPLI	r5,0
186e1051a39Sopenharmony_ci	li	r0,0
187e1051a39Sopenharmony_ci	beq	Lno_data
188e1051a39Sopenharmony_ci	mtctr	r5
189e1051a39Sopenharmony_ciLoop_cmp:
190e1051a39Sopenharmony_ci	lbz	r6,0(r3)
191e1051a39Sopenharmony_ci	addi	r3,r3,1
192e1051a39Sopenharmony_ci	lbz	r7,0(r4)
193e1051a39Sopenharmony_ci	addi	r4,r4,1
194e1051a39Sopenharmony_ci	xor	r6,r6,r7
195e1051a39Sopenharmony_ci	or	r0,r0,r6
196e1051a39Sopenharmony_ci	bdnz	Loop_cmp
197e1051a39Sopenharmony_ci
198e1051a39Sopenharmony_ciLno_data:
199e1051a39Sopenharmony_ci	li	r3,0
200e1051a39Sopenharmony_ci	sub	r3,r3,r0
201e1051a39Sopenharmony_ci	extrwi	r3,r3,1,0
202e1051a39Sopenharmony_ci	blr
203e1051a39Sopenharmony_ci	.long	0
204e1051a39Sopenharmony_ci	.byte	0,12,0x14,0,0,0,3,0
205e1051a39Sopenharmony_ci	.long	0
206e1051a39Sopenharmony_ci.size	.CRYPTO_memcmp,.-.CRYPTO_memcmp
207e1051a39Sopenharmony_ci___
208e1051a39Sopenharmony_ci{
209e1051a39Sopenharmony_cimy ($out,$cnt,$max)=("r3","r4","r5");
210e1051a39Sopenharmony_cimy ($tick,$lasttick)=("r6","r7");
211e1051a39Sopenharmony_cimy ($diff,$lastdiff)=("r8","r9");
212e1051a39Sopenharmony_ci
213e1051a39Sopenharmony_ci$code.=<<___;
214e1051a39Sopenharmony_ci.globl	.OPENSSL_instrument_bus_mftb
215e1051a39Sopenharmony_ci.align	4
216e1051a39Sopenharmony_ci.OPENSSL_instrument_bus_mftb:
217e1051a39Sopenharmony_ci	mtctr	$cnt
218e1051a39Sopenharmony_ci
219e1051a39Sopenharmony_ci	mftb	$lasttick		# collect 1st tick
220e1051a39Sopenharmony_ci	li	$diff,0
221e1051a39Sopenharmony_ci
222e1051a39Sopenharmony_ci	dcbf	0,$out			# flush cache line
223e1051a39Sopenharmony_ci	lwarx	$tick,0,$out		# load and lock
224e1051a39Sopenharmony_ci	add	$tick,$tick,$diff
225e1051a39Sopenharmony_ci	stwcx.	$tick,0,$out
226e1051a39Sopenharmony_ci	stwx	$tick,0,$out
227e1051a39Sopenharmony_ci
228e1051a39Sopenharmony_ciLoop:	mftb	$tick
229e1051a39Sopenharmony_ci	sub	$diff,$tick,$lasttick
230e1051a39Sopenharmony_ci	mr	$lasttick,$tick
231e1051a39Sopenharmony_ci	dcbf	0,$out			# flush cache line
232e1051a39Sopenharmony_ci	lwarx	$tick,0,$out		# load and lock
233e1051a39Sopenharmony_ci	add	$tick,$tick,$diff
234e1051a39Sopenharmony_ci	stwcx.	$tick,0,$out
235e1051a39Sopenharmony_ci	stwx	$tick,0,$out
236e1051a39Sopenharmony_ci	addi	$out,$out,4		# ++$out
237e1051a39Sopenharmony_ci	bdnz	Loop
238e1051a39Sopenharmony_ci
239e1051a39Sopenharmony_ci	mr	r3,$cnt
240e1051a39Sopenharmony_ci	blr
241e1051a39Sopenharmony_ci	.long	0
242e1051a39Sopenharmony_ci	.byte	0,12,0x14,0,0,0,2,0
243e1051a39Sopenharmony_ci	.long	0
244e1051a39Sopenharmony_ci.size	.OPENSSL_instrument_bus_mftb,.-.OPENSSL_instrument_bus_mftb
245e1051a39Sopenharmony_ci
246e1051a39Sopenharmony_ci.globl	.OPENSSL_instrument_bus2_mftb
247e1051a39Sopenharmony_ci.align	4
248e1051a39Sopenharmony_ci.OPENSSL_instrument_bus2_mftb:
249e1051a39Sopenharmony_ci	mr	r0,$cnt
250e1051a39Sopenharmony_ci	slwi	$cnt,$cnt,2
251e1051a39Sopenharmony_ci
252e1051a39Sopenharmony_ci	mftb	$lasttick		# collect 1st tick
253e1051a39Sopenharmony_ci	li	$diff,0
254e1051a39Sopenharmony_ci
255e1051a39Sopenharmony_ci	dcbf	0,$out			# flush cache line
256e1051a39Sopenharmony_ci	lwarx	$tick,0,$out		# load and lock
257e1051a39Sopenharmony_ci	add	$tick,$tick,$diff
258e1051a39Sopenharmony_ci	stwcx.	$tick,0,$out
259e1051a39Sopenharmony_ci	stwx	$tick,0,$out
260e1051a39Sopenharmony_ci
261e1051a39Sopenharmony_ci	mftb	$tick			# collect 1st diff
262e1051a39Sopenharmony_ci	sub	$diff,$tick,$lasttick
263e1051a39Sopenharmony_ci	mr	$lasttick,$tick
264e1051a39Sopenharmony_ci	mr	$lastdiff,$diff
265e1051a39Sopenharmony_ciLoop2:
266e1051a39Sopenharmony_ci	dcbf	0,$out			# flush cache line
267e1051a39Sopenharmony_ci	lwarx	$tick,0,$out		# load and lock
268e1051a39Sopenharmony_ci	add	$tick,$tick,$diff
269e1051a39Sopenharmony_ci	stwcx.	$tick,0,$out
270e1051a39Sopenharmony_ci	stwx	$tick,0,$out
271e1051a39Sopenharmony_ci
272e1051a39Sopenharmony_ci	addic.	$max,$max,-1
273e1051a39Sopenharmony_ci	beq	Ldone2
274e1051a39Sopenharmony_ci
275e1051a39Sopenharmony_ci	mftb	$tick
276e1051a39Sopenharmony_ci	sub	$diff,$tick,$lasttick
277e1051a39Sopenharmony_ci	mr	$lasttick,$tick
278e1051a39Sopenharmony_ci	cmplw	7,$diff,$lastdiff
279e1051a39Sopenharmony_ci	mr	$lastdiff,$diff
280e1051a39Sopenharmony_ci
281e1051a39Sopenharmony_ci	mfcr	$tick			# pull cr
282e1051a39Sopenharmony_ci	not	$tick,$tick		# flip bits
283e1051a39Sopenharmony_ci	rlwinm	$tick,$tick,1,29,29	# isolate flipped eq bit and scale
284e1051a39Sopenharmony_ci
285e1051a39Sopenharmony_ci	sub.	$cnt,$cnt,$tick		# conditional --$cnt
286e1051a39Sopenharmony_ci	add	$out,$out,$tick		# conditional ++$out
287e1051a39Sopenharmony_ci	bne	Loop2
288e1051a39Sopenharmony_ci
289e1051a39Sopenharmony_ciLdone2:
290e1051a39Sopenharmony_ci	srwi	$cnt,$cnt,2
291e1051a39Sopenharmony_ci	sub	r3,r0,$cnt
292e1051a39Sopenharmony_ci	blr
293e1051a39Sopenharmony_ci	.long	0
294e1051a39Sopenharmony_ci	.byte	0,12,0x14,0,0,0,3,0
295e1051a39Sopenharmony_ci	.long	0
296e1051a39Sopenharmony_ci.size	.OPENSSL_instrument_bus2_mftb,.-.OPENSSL_instrument_bus2_mftb
297e1051a39Sopenharmony_ci
298e1051a39Sopenharmony_ci.globl	.OPENSSL_instrument_bus_mfspr268
299e1051a39Sopenharmony_ci.align	4
300e1051a39Sopenharmony_ci.OPENSSL_instrument_bus_mfspr268:
301e1051a39Sopenharmony_ci	mtctr	$cnt
302e1051a39Sopenharmony_ci
303e1051a39Sopenharmony_ci	mfspr	$lasttick,268		# collect 1st tick
304e1051a39Sopenharmony_ci	li	$diff,0
305e1051a39Sopenharmony_ci
306e1051a39Sopenharmony_ci	dcbf	0,$out			# flush cache line
307e1051a39Sopenharmony_ci	lwarx	$tick,0,$out		# load and lock
308e1051a39Sopenharmony_ci	add	$tick,$tick,$diff
309e1051a39Sopenharmony_ci	stwcx.	$tick,0,$out
310e1051a39Sopenharmony_ci	stwx	$tick,0,$out
311e1051a39Sopenharmony_ci
312e1051a39Sopenharmony_ciLoop3:	mfspr	$tick,268
313e1051a39Sopenharmony_ci	sub	$diff,$tick,$lasttick
314e1051a39Sopenharmony_ci	mr	$lasttick,$tick
315e1051a39Sopenharmony_ci	dcbf	0,$out			# flush cache line
316e1051a39Sopenharmony_ci	lwarx	$tick,0,$out		# load and lock
317e1051a39Sopenharmony_ci	add	$tick,$tick,$diff
318e1051a39Sopenharmony_ci	stwcx.	$tick,0,$out
319e1051a39Sopenharmony_ci	stwx	$tick,0,$out
320e1051a39Sopenharmony_ci	addi	$out,$out,4		# ++$out
321e1051a39Sopenharmony_ci	bdnz	Loop3
322e1051a39Sopenharmony_ci
323e1051a39Sopenharmony_ci	mr	r3,$cnt
324e1051a39Sopenharmony_ci	blr
325e1051a39Sopenharmony_ci	.long	0
326e1051a39Sopenharmony_ci	.byte	0,12,0x14,0,0,0,2,0
327e1051a39Sopenharmony_ci	.long	0
328e1051a39Sopenharmony_ci.size	.OPENSSL_instrument_bus_mfspr268,.-.OPENSSL_instrument_bus_mfspr268
329e1051a39Sopenharmony_ci
330e1051a39Sopenharmony_ci.globl	.OPENSSL_instrument_bus2_mfspr268
331e1051a39Sopenharmony_ci.align	4
332e1051a39Sopenharmony_ci.OPENSSL_instrument_bus2_mfspr268:
333e1051a39Sopenharmony_ci	mr	r0,$cnt
334e1051a39Sopenharmony_ci	slwi	$cnt,$cnt,2
335e1051a39Sopenharmony_ci
336e1051a39Sopenharmony_ci	mfspr	$lasttick,268		# collect 1st tick
337e1051a39Sopenharmony_ci	li	$diff,0
338e1051a39Sopenharmony_ci
339e1051a39Sopenharmony_ci	dcbf	0,$out			# flush cache line
340e1051a39Sopenharmony_ci	lwarx	$tick,0,$out		# load and lock
341e1051a39Sopenharmony_ci	add	$tick,$tick,$diff
342e1051a39Sopenharmony_ci	stwcx.	$tick,0,$out
343e1051a39Sopenharmony_ci	stwx	$tick,0,$out
344e1051a39Sopenharmony_ci
345e1051a39Sopenharmony_ci	mfspr	$tick,268		# collect 1st diff
346e1051a39Sopenharmony_ci	sub	$diff,$tick,$lasttick
347e1051a39Sopenharmony_ci	mr	$lasttick,$tick
348e1051a39Sopenharmony_ci	mr	$lastdiff,$diff
349e1051a39Sopenharmony_ciLoop4:
350e1051a39Sopenharmony_ci	dcbf	0,$out			# flush cache line
351e1051a39Sopenharmony_ci	lwarx	$tick,0,$out		# load and lock
352e1051a39Sopenharmony_ci	add	$tick,$tick,$diff
353e1051a39Sopenharmony_ci	stwcx.	$tick,0,$out
354e1051a39Sopenharmony_ci	stwx	$tick,0,$out
355e1051a39Sopenharmony_ci
356e1051a39Sopenharmony_ci	addic.	$max,$max,-1
357e1051a39Sopenharmony_ci	beq	Ldone4
358e1051a39Sopenharmony_ci
359e1051a39Sopenharmony_ci	mfspr	$tick,268
360e1051a39Sopenharmony_ci	sub	$diff,$tick,$lasttick
361e1051a39Sopenharmony_ci	mr	$lasttick,$tick
362e1051a39Sopenharmony_ci	cmplw	7,$diff,$lastdiff
363e1051a39Sopenharmony_ci	mr	$lastdiff,$diff
364e1051a39Sopenharmony_ci
365e1051a39Sopenharmony_ci	mfcr	$tick			# pull cr
366e1051a39Sopenharmony_ci	not	$tick,$tick		# flip bits
367e1051a39Sopenharmony_ci	rlwinm	$tick,$tick,1,29,29	# isolate flipped eq bit and scale
368e1051a39Sopenharmony_ci
369e1051a39Sopenharmony_ci	sub.	$cnt,$cnt,$tick		# conditional --$cnt
370e1051a39Sopenharmony_ci	add	$out,$out,$tick		# conditional ++$out
371e1051a39Sopenharmony_ci	bne	Loop4
372e1051a39Sopenharmony_ci
373e1051a39Sopenharmony_ciLdone4:
374e1051a39Sopenharmony_ci	srwi	$cnt,$cnt,2
375e1051a39Sopenharmony_ci	sub	r3,r0,$cnt
376e1051a39Sopenharmony_ci	blr
377e1051a39Sopenharmony_ci	.long	0
378e1051a39Sopenharmony_ci	.byte	0,12,0x14,0,0,0,3,0
379e1051a39Sopenharmony_ci	.long	0
380e1051a39Sopenharmony_ci.size	.OPENSSL_instrument_bus2_mfspr268,.-.OPENSSL_instrument_bus2_mfspr268
381e1051a39Sopenharmony_ci___
382e1051a39Sopenharmony_ci}
383e1051a39Sopenharmony_ci
384e1051a39Sopenharmony_ci$code =~ s/\`([^\`]*)\`/eval $1/gem;
385e1051a39Sopenharmony_ciprint $code;
386e1051a39Sopenharmony_ciclose STDOUT or die "error closing STDOUT: $!";
387