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