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