Properly own the duplicated string
[openssl.git] / crypto / pariscid.pl
1 #! /usr/bin/env perl
2 # Copyright 2009-2016 The OpenSSL Project Authors. All Rights Reserved.
3 #
4 # Licensed under the OpenSSL license (the "License").  You may not use
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
9
10 $flavour = shift;
11 $output = shift;
12 open STDOUT,">$output";
13
14 if ($flavour =~ /64/) {
15         $LEVEL          ="2.0W";
16         $SIZE_T         =8;
17         $ST             ="std";
18 } else {
19         $LEVEL          ="1.1";
20         $SIZE_T         =4;
21         $ST             ="stw";
22 }
23
24 $rp="%r2";
25 $sp="%r30";
26 $rv="%r28";
27
28 $code=<<___;
29         .LEVEL  $LEVEL
30         .SPACE  \$TEXT\$
31         .SUBSPA \$CODE\$,QUAD=0,ALIGN=8,ACCESS=0x2C,CODE_ONLY
32
33         .EXPORT OPENSSL_cpuid_setup,ENTRY
34         .ALIGN  8
35 OPENSSL_cpuid_setup
36         .PROC
37         .CALLINFO       NO_CALLS
38         .ENTRY
39         bv      ($rp)
40         .EXIT
41         nop
42         .PROCEND
43
44         .EXPORT OPENSSL_rdtsc,ENTRY
45         .ALIGN  8
46 OPENSSL_rdtsc
47         .PROC
48         .CALLINFO       NO_CALLS
49         .ENTRY
50         mfctl   %cr16,$rv
51         bv      ($rp)
52         .EXIT
53         nop
54         .PROCEND
55
56         .EXPORT OPENSSL_wipe_cpu,ENTRY
57         .ALIGN  8
58 OPENSSL_wipe_cpu
59         .PROC
60         .CALLINFO       NO_CALLS
61         .ENTRY
62         xor             %r0,%r0,%r1
63         fcpy,dbl        %fr0,%fr4
64         xor             %r0,%r0,%r19
65         fcpy,dbl        %fr0,%fr5
66         xor             %r0,%r0,%r20
67         fcpy,dbl        %fr0,%fr6
68         xor             %r0,%r0,%r21
69         fcpy,dbl        %fr0,%fr7
70         xor             %r0,%r0,%r22
71         fcpy,dbl        %fr0,%fr8
72         xor             %r0,%r0,%r23
73         fcpy,dbl        %fr0,%fr9
74         xor             %r0,%r0,%r24
75         fcpy,dbl        %fr0,%fr10
76         xor             %r0,%r0,%r25
77         fcpy,dbl        %fr0,%fr11
78         xor             %r0,%r0,%r26
79         fcpy,dbl        %fr0,%fr22
80         xor             %r0,%r0,%r29
81         fcpy,dbl        %fr0,%fr23
82         xor             %r0,%r0,%r31
83         fcpy,dbl        %fr0,%fr24
84         fcpy,dbl        %fr0,%fr25
85         fcpy,dbl        %fr0,%fr26
86         fcpy,dbl        %fr0,%fr27
87         fcpy,dbl        %fr0,%fr28
88         fcpy,dbl        %fr0,%fr29
89         fcpy,dbl        %fr0,%fr30
90         fcpy,dbl        %fr0,%fr31
91         bv              ($rp)
92         .EXIT
93         ldo             0($sp),$rv
94         .PROCEND
95 ___
96 {
97 my $inp="%r26";
98 my $len="%r25";
99
100 $code.=<<___;
101         .EXPORT OPENSSL_cleanse,ENTRY,ARGW0=GR,ARGW1=GR
102         .ALIGN  8
103 OPENSSL_cleanse
104         .PROC
105         .CALLINFO       NO_CALLS
106         .ENTRY
107         cmpib,*=        0,$len,L\$done
108         nop
109         cmpib,*>>=      15,$len,L\$ittle
110         ldi             $SIZE_T-1,%r1
111
112 L\$align
113         and,*<>         $inp,%r1,%r28
114         b,n             L\$aligned
115         stb             %r0,0($inp)
116         ldo             -1($len),$len
117         b               L\$align
118         ldo             1($inp),$inp
119
120 L\$aligned
121         andcm           $len,%r1,%r28
122 L\$ot
123         $ST             %r0,0($inp)
124         addib,*<>       -$SIZE_T,%r28,L\$ot
125         ldo             $SIZE_T($inp),$inp
126
127         and,*<>         $len,%r1,$len
128         b,n             L\$done
129 L\$ittle
130         stb             %r0,0($inp)
131         addib,*<>       -1,$len,L\$ittle
132         ldo             1($inp),$inp
133 L\$done
134         bv              ($rp)
135         .EXIT
136         nop
137         .PROCEND
138 ___
139 }
140 {
141 my ($out,$cnt,$max)=("%r26","%r25","%r24");
142 my ($tick,$lasttick)=("%r23","%r22");
143 my ($diff,$lastdiff)=("%r21","%r20");
144
145 $code.=<<___;
146         .EXPORT OPENSSL_instrument_bus,ENTRY,ARGW0=GR,ARGW1=GR
147         .ALIGN  8
148 OPENSSL_instrument_bus
149         .PROC
150         .CALLINFO       NO_CALLS
151         .ENTRY
152         copy            $cnt,$rv
153         mfctl           %cr16,$tick
154         copy            $tick,$lasttick
155         ldi             0,$diff
156
157         fdc             0($out)
158         ldw             0($out),$tick
159         add             $diff,$tick,$tick
160         stw             $tick,0($out)
161 L\$oop
162         mfctl           %cr16,$tick
163         sub             $tick,$lasttick,$diff
164         copy            $tick,$lasttick
165
166         fdc             0($out)
167         ldw             0($out),$tick
168         add             $diff,$tick,$tick
169         stw             $tick,0($out)
170
171         addib,<>        -1,$cnt,L\$oop
172         addi            4,$out,$out
173
174         bv              ($rp)
175         .EXIT
176         sub             $rv,$cnt,$rv
177         .PROCEND
178
179         .EXPORT OPENSSL_instrument_bus2,ENTRY,ARGW0=GR,ARGW1=GR
180         .ALIGN  8
181 OPENSSL_instrument_bus2
182         .PROC
183         .CALLINFO       NO_CALLS
184         .ENTRY
185         copy            $cnt,$rv
186         sub             %r0,$cnt,$cnt
187
188         mfctl           %cr16,$tick
189         copy            $tick,$lasttick
190         ldi             0,$diff
191
192         fdc             0($out)
193         ldw             0($out),$tick
194         add             $diff,$tick,$tick
195         stw             $tick,0($out)
196
197         mfctl           %cr16,$tick
198         sub             $tick,$lasttick,$diff
199         copy            $tick,$lasttick
200 L\$oop2
201         copy            $diff,$lastdiff
202         fdc             0($out)
203         ldw             0($out),$tick
204         add             $diff,$tick,$tick
205         stw             $tick,0($out)
206
207         addib,=         -1,$max,L\$done2
208         nop
209
210         mfctl           %cr16,$tick
211         sub             $tick,$lasttick,$diff
212         copy            $tick,$lasttick
213         cmpclr,<>       $lastdiff,$diff,$tick
214         ldi             1,$tick
215
216         ldi             1,%r1
217         xor             %r1,$tick,$tick
218         addb,<>         $tick,$cnt,L\$oop2
219         shladd,l        $tick,2,$out,$out
220 L\$done2
221         bv              ($rp)
222         .EXIT
223         add             $rv,$cnt,$rv
224         .PROCEND
225 ___
226 }
227 $code =~ s/cmpib,\*/comib,/gm   if ($SIZE_T==4);
228 $code =~ s/,\*/,/gm             if ($SIZE_T==4);
229 $code =~ s/\bbv\b/bve/gm        if ($SIZE_T==8);
230 print $code;
231 close STDOUT;
232