Copyright consolidation: perl files
[openssl.git] / crypto / c64xpluscpuid.pl
1 #! /usr/bin/env perl
2 # Copyright 2012-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 while (($output=shift) && ($output!~/\w[\w\-]*\.\w+$/)) {}
10 open STDOUT,">$output";
11
12 $code.=<<___;
13         .text
14
15         .if     .ASSEMBLER_VERSION<7000000
16         .asg    0,__TI_EABI__
17         .endif
18         .if     __TI_EABI__
19         .asg    OPENSSL_rdtsc,_OPENSSL_rdtsc
20         .asg    OPENSSL_cleanse,_OPENSSL_cleanse
21         .asg    OPENSSL_atomic_add,_OPENSSL_atomic_add
22         .asg    OPENSSL_wipe_cpu,_OPENSSL_wipe_cpu
23         .asg    OPENSSL_instrument_bus,_OPENSSL_instrument_bus
24         .asg    OPENSSL_instrument_bus2,_OPENSSL_instrument_bus2
25         .endif
26
27         .asg    B3,RA
28
29         .global _OPENSSL_rdtsc
30 _OPENSSL_rdtsc:
31         .asmfunc
32         B       RA
33         MVC     TSCL,B0
34         MVC     TSCH,B1
35   [!B0] MVC     B0,TSCL         ; start TSC
36         MV      B0,A4
37         MV      B1,A5
38         .endasmfunc
39
40         .global _OPENSSL_cleanse
41 _OPENSSL_cleanse:
42         .asmfunc
43         ZERO    A3:A2
44 ||      ZERO    B2
45 ||      SHRU    B4,3,B0         ; is length >= 8
46 ||      ADD     1,A4,B6
47   [!B0] BNOP    RA
48 ||      ZERO    A1
49 ||      ZERO    B1
50    [B0] MVC     B0,ILC
51 ||[!B0] CMPLT   0,B4,A1
52 ||[!B0] CMPLT   1,B4,B1
53    [A1] STB     A2,*A4++[2]
54 || [B1] STB     B2,*B6++[2]
55 ||[!B0] CMPLT   2,B4,A1
56 ||[!B0] CMPLT   3,B4,B1
57    [A1] STB     A2,*A4++[2]
58 || [B1] STB     B2,*B6++[2]
59 ||[!B0] CMPLT   4,B4,A1
60 ||[!B0] CMPLT   5,B4,B1
61    [A1] STB     A2,*A4++[2]
62 || [B1] STB     B2,*B6++[2]
63 ||[!B0] CMPLT   6,B4,A1
64    [A1] STB     A2,*A4++[2]
65
66         SPLOOP  1
67         STNDW   A3:A2,*A4++
68 ||      SUB     B4,8,B4
69         SPKERNEL
70
71         MV      B4,B0           ; remaining bytes
72 ||      ADD     1,A4,B6
73 ||      BNOP    RA
74    [B0] CMPLT   0,B0,A1
75 || [B0] CMPLT   1,B0,B1
76    [A1] STB     A2,*A4++[2]
77 || [B1] STB     B2,*B6++[2]
78 || [B0] CMPLT   2,B0,A1
79 || [B0] CMPLT   3,B0,B1
80    [A1] STB     A2,*A4++[2]
81 || [B1] STB     B2,*B6++[2]
82 || [B0] CMPLT   4,B0,A1
83 || [B0] CMPLT   5,B0,B1
84    [A1] STB     A2,*A4++[2]
85 || [B1] STB     B2,*B6++[2]
86 || [B0] CMPLT   6,B0,A1
87    [A1] STB     A2,*A4++[2]
88         .endasmfunc
89
90         .global _OPENSSL_atomic_add
91 _OPENSSL_atomic_add:
92         .asmfunc
93         MV      A4,B0
94 atomic_add?:
95         LL      *B0,B5
96         NOP     4
97         ADD     B4,B5,B5
98         SL      B5,*B0
99         CMTL    *B0,B1
100         NOP     4
101   [!B1] B       atomic_add?
102    [B1] BNOP    RA,4
103         MV      B5,A4
104         .endasmfunc
105
106         .global _OPENSSL_wipe_cpu
107 _OPENSSL_wipe_cpu:
108         .asmfunc
109         ZERO    A0
110 ||      ZERO    B0
111 ||      ZERO    A1
112 ||      ZERO    B1
113         ZERO    A3:A2
114 ||      MVD     B0,B2
115 ||      ZERO    A4
116 ||      ZERO    B4
117 ||      ZERO    A5
118 ||      ZERO    B5
119 ||      BNOP    RA
120         ZERO    A7:A6
121 ||      ZERO    B7:B6
122 ||      ZERO    A8
123 ||      ZERO    B8
124 ||      ZERO    A9
125 ||      ZERO    B9
126         ZERO    A17:A16
127 ||      ZERO    B17:B16
128 ||      ZERO    A18
129 ||      ZERO    B18
130 ||      ZERO    A19
131 ||      ZERO    B19
132         ZERO    A21:A20
133 ||      ZERO    B21:B20
134 ||      ZERO    A22
135 ||      ZERO    B22
136 ||      ZERO    A23
137 ||      ZERO    B23
138         ZERO    A25:A24
139 ||      ZERO    B25:B24
140 ||      ZERO    A26
141 ||      ZERO    B26
142 ||      ZERO    A27
143 ||      ZERO    B27
144         ZERO    A29:A28
145 ||      ZERO    B29:B28
146 ||      ZERO    A30
147 ||      ZERO    B30
148 ||      ZERO    A31
149 ||      ZERO    B31
150         .endasmfunc
151
152 CLFLUSH .macro  CONTROL,ADDR,LEN
153         B       passthrough?
154 ||      STW     ADDR,*CONTROL[0]
155         STW     LEN,*CONTROL[1]
156 spinlock?:
157         LDW     *CONTROL[1],A0
158         NOP     3
159 passthrough?:
160         NOP
161   [A0]  BNOP    spinlock?,5
162         .endm
163
164         .global _OPENSSL_instrument_bus
165 _OPENSSL_instrument_bus:
166         .asmfunc
167         MV      B4,B0                   ; reassign sizeof(output)
168 ||      MV      A4,B4                   ; reassign output
169 ||      MVK     0x00004030,A3
170         MV      B0,A4                   ; return value
171 ||      MVK     1,A1
172 ||      MVKH    0x01840000,A3           ; L1DWIBAR
173         MVC     TSCL,B8                 ; collect 1st tick
174 ||      MVK     0x00004010,A5
175         MV      B8,B9                   ; lasttick = tick
176 ||      MVK     0,B7                    ; lastdiff = 0
177 ||      MVKH    0x01840000,A5           ; L2WIBAR
178         CLFLUSH A3,B4,A1                ; write-back and invalidate L1D line
179         CLFLUSH A5,B4,A1                ; write-back and invalidate L2 line
180         LL      *B4,B5
181         NOP     4
182         ADD     B7,B5,B5
183         SL      B5,*B4
184         CMTL    *B4,B1
185         NOP     4
186         STW     B5,*B4
187 bus_loop1?:
188         MVC     TSCL,B8
189 || [B0] SUB     B0,1,B0
190         SUB     B8,B9,B7                ; lastdiff = tick - lasttick
191 ||      MV      B8,B9                   ; lasttick = tick
192         CLFLUSH A3,B4,A1                ; write-back and invalidate L1D line
193         CLFLUSH A5,B4,A1                ; write-back and invalidate L2 line
194         LL      *B4,B5
195         NOP     4
196         ADD     B7,B5,B5
197         SL      B5,*B4
198         CMTL    *B4,B1
199         STW     B5,*B4                  ; [!B1] is removed to flatten samples
200 ||      ADDK    4,B4
201 || [B0] BNOP    bus_loop1?,5
202
203         BNOP    RA,5
204         .endasmfunc
205
206         .global _OPENSSL_instrument_bus2
207 _OPENSSL_instrument_bus2:
208         .asmfunc
209         MV      A6,B0                   ; reassign max
210 ||      MV      B4,A6                   ; reassing sizeof(output)
211 ||      MVK     0x00004030,A3
212         MV      A4,B4                   ; reassign output
213 ||      MVK     0,A4                    ; return value
214 ||      MVK     1,A1
215 ||      MVKH    0x01840000,A3           ; L1DWIBAR
216
217         MVC     TSCL,B8                 ; collect 1st tick
218 ||      MVK     0x00004010,A5
219         MV      B8,B9                   ; lasttick = tick
220 ||      MVK     0,B7                    ; lastdiff = 0
221 ||      MVKH    0x01840000,A5           ; L2WIBAR
222         CLFLUSH A3,B4,A1                ; write-back and invalidate L1D line
223         CLFLUSH A5,B4,A1                ; write-back and invalidate L2 line
224         LL      *B4,B5
225         NOP     4
226         ADD     B7,B5,B5
227         SL      B5,*B4
228         CMTL    *B4,B1
229         NOP     4
230         STW     B5,*B4
231
232         MVC     TSCL,B8                 ; collect 1st diff
233         SUB     B8,B9,B7                ; lastdiff = tick - lasttick
234 ||      MV      B8,B9                   ; lasttick = tick
235 ||      SUB     B0,1,B0
236 bus_loop2?:
237         CLFLUSH A3,B4,A1                ; write-back and invalidate L1D line
238         CLFLUSH A5,B4,A1                ; write-back and invalidate L2 line
239         LL      *B4,B5
240         NOP     4
241         ADD     B7,B5,B5
242         SL      B5,*B4
243         CMTL    *B4,B1
244         STW     B5,*B4                  ; [!B1] is removed to flatten samples
245 ||[!B0] BNOP    bus_loop2_done?,2
246 ||      SUB     B0,1,B0
247         MVC     TSCL,B8
248         SUB     B8,B9,B8
249 ||      MV      B8,B9
250         CMPEQ   B8,B7,B2
251 ||      MV      B8,B7
252   [!B2] ADDAW   B4,1,B4
253 ||[!B2] ADDK    1,A4
254         CMPEQ   A4,A6,A2
255   [!A2] BNOP    bus_loop2?,5
256
257 bus_loop2_done?:
258         BNOP    RA,5
259         .endasmfunc
260 ___
261
262 print $code;
263 close STDOUT;