Now my comments should be in english....
[pspdecompiler.git] / tests / test_asm.S
blob26167153c8a893f0e6b383220c1a1e3eb41b4d53
1         .section .text
3         .set    noreorder
4         .set    noat
7         .global cfg_branches
8         .ent    cfg_branches
10 cfg_branches:
11         nop
12 cfg_branches_start:
13         bne     $a0, $0, 1f
14         nop
16         bgez    $a0, 2f
17         nop
20         bgtz    $a0, 3f
21         nop
24         blez    $a0, 4f
25         nop
28         bltz    $a0, 5f
29         nop
32         beq     $a0, $at, 6f
33         nop
36         bne     $a0, $at, 7f
37         nop
40         j       cfg_branches_start
41         nop
44         jr      $ra
45         nop
47         .end    cfg_branches
50         .global cfg_branches_likely
51         .ent    cfg_branches_likely
53 cfg_branches_likely:
54         beql    $a0, $a1, 1f
55         nop
57         bgezl   $a1, 1f
58         nop
60         bgtzl   $a2, 1f
61         nop
63         blezl   $a3, 1f
64         nop
66         bltzl   $a0, 1f
67         nop
69         bnel    $a0, $a2, 1f
70         nop
72         nop
75         jr      $ra
76         nop
78         .end    cfg_branches_likely
81         .global cfg_branches_noswap
82         .ent    cfg_branches_noswap
84 cfg_branches_noswap:
85         beq     $a0, $a1, 1f
86         move    $a1, $0
87         lui     $v0, 0
89         bltzal  $a0, cfg_branches_noswap
90 2:      move    $a1, $31
91         bgez    $a0, 2b
92         nop
94         bltzal  $a0, cfg_branches_noswap
95         move    $a1, $31
97         bltzall $a0, cfg_branches_noswap
98 3:      nop
99         bgez    $a0, 3b
100         nop
102         jr      $ra
103         nop
105         .end    cfg_branches_noswap
109         .global cfg_branches_never
110         .ent    cfg_branches_never
112 cfg_branches_never:
113         bgtz    $0, 1f
114         nop
116         bgtzl   $0, 1f
117         nop
119         bltz    $0, 1f
120         nop
122         bltzl   $0, 1f
123         nop
125         bne     $0, $0, 1f
126         nop
128         bne     $a0, $a0, 1f
129         nop
131         bnel    $0, $0, 1f
132         nop
134         bnel    $a0, $a0, 1f
135         nop
137         bltzal  $0, cfg_branches_never
138         nop
140         bltzall  $0, cfg_branches_never
141         nop
144         jr      $ra
145         nop
147         .end    cfg_branches_never
149         .global cfg_branches_always
150         .ent    cfg_branches_always
152 cfg_branches_always:
154         bgez    $0, 7f
155         nop
158         bgezl   $0, 8f
159         nop
162         blez    $0, 1b
163         nop
166         blezl   $0, 2b
167         nop
170         beq     $0, $0, 3b
171         nop
174         beq     $a0, $a0, 4b
175         nop
178         beql    $0, $0, 5b
179         nop
182         beql    $a0, $a0, 6b
183         nop
186         jr      $ra
187         nop
189         .end    cfg_branches_always
191         .global cfg_branchlink
192         .ent    cfg_branchlink
194 cfg_branchlink:
195         bgezal  $a0, cfg_jumptobegin
196         nop
197         bltzal  $a0, cfg_jumptobegin
198         nop
199         bltzall $a0, cfg_jumptobegin
200         nop
202         jr      $ra
203         nop
205         .end    cfg_branchlink
207         .global cfg_strangerefs
208         .ent    cfg_strangerefs
210 cfg_strangerefs:
211         beql    $a0, $a1, 2f
213         nop
214         beq     $a0, $a1, 2f
215         nop
216         j       1b
217         nop
220         bltzall $a0, cfg_jumptobegin
222         nop
223         beq     $a0, $a1, 3b
224         nop
226         jr      $ra
227         nop
229         .end    cfg_strangerefs
231         .global cfg_jumptobegin
232         .ent    cfg_jumptobegin
234 cfg_jumptobegin:
235         nop
236         beq     $a0, $a1, cfg_jumptobegin
237         nop
239         jr      $ra
240         nop
242         .end    cfg_jumptobegin
244         .global cfg_callnoswap
245         .ent    cfg_callnoswap
247 cfg_callnoswap:
248         jal     cfg_callnoswap
249         move    $a0, $31
251         jr      $ra
252         nop
254         .end    cfg_callnoswap
257         .global cfg_switch
258         .ent    cfg_switch
260 cfg_switch:
261         jal     cfg_switch_innercallback
262         nop
263         slti    $t0, $a1, 7
264         sll     $a0, $a1, 2
265         blez    $t0, switch1_default
266         lui     $v0, %hi(switch1)
267         addu    $v0, $a0
268         lw      $v0, %lo(switch1)($v0)
269         jr      $v0
270         nop
271 switch1_case0:
272 switch1_case1:
273 switch1_case6:
274 switch1_case3:
275         jr      $ra
276         nop
278 switch1_case4:
279 switch1_case2:
280         j       switch1_case0
281         move    $a0, $v0
284 switch1_case5:
285         jal     cfg_branches_always
286         nop
288 switch1_default:
290         jr      $ra
291         nop
293 cfg_switch_innercallback:
294         jal     mycallback
295         nop
296         lui     $v0, %hi(inner_callback)
297         lw      $v0, %lo(inner_callback)($v0)
298         jr      $v0
299         nop
301 mycallback:
302         jr      $ra
303         nop
305         .end    cfg_switch
309 int double_break (void)
311   int i, j = 400009, t = 0;
312   for (i = 0; i < 100; i++) {
313     if (j & 1) {
314       j = 3 * j + 1;
315     } else {
316       j >>= 1;
317     }
319     if (j == 50) {
320       j++;
321       if (i > 10) break;
322     } else {
323       t++;
324       if (i == 98) break;
325     }
326     t += 2;
327   }
328   return t;
331         .global graph_double_break
332         .ent    graph_double_break
333 graph_double_break:
334         move    $4,$0
335         li      $2,393216
336         ori     $3,$2,0x1a89
337         move    $5,$0
338         li      $9,3
339         li      $7,50
340         li      $8,98
341         li      $10,51
342         li      $6,100
343 1:      andi    $2,$3,0x1
344         beql    $2,$0,2f
345         sra     $3,$3,1
346         mult    $3,$9
347         mflo    $2
348         addiu   $3,$2,1
349 2:      bne     $3,$7,3f
350         slt     $2,$4,11
351         beq     $2,$0,5f
352         move    $3,$10
353         j       4f
354         addiu   $4,$4,1
355 3:      beq     $4,$8,5f
356         addiu   $5,$5,1
357         addiu   $4,$4,1
358 4:      bne     $4,$6,1b
359         addiu   $5,$5,2
360 5:      j       $ra
361         move    $2,$5
363         .end    graph_double_break
365         .global graph_nested_ifs
366         .ent    graph_nested_ifs
367 graph_nested_ifs:
368         beq     $a0, $0, 2f
369         nop
370         beq     $a1, $0, 1f
371         nop
372         li      $v0, 1
373         j       4f
374         nop
375 1:      li      $v0, 2
376         j       4f
377         nop
378 2:      beq     $a1, $0, 3f
379         nop
380         li      $v0, 3
381         j       4f
382         nop
383 3:      li      $v0, 4
384 4:      jr      $ra
385         nop
387         .end    graph_nested_ifs
389         .global graph_nested_loops
390         .ent    graph_nested_loops
391 graph_nested_loops:
392         move    $v0, $a0
393 1:      beq     $a1, $0, 4f
394         nop
395 2:      beq     $a2, $0, 3f
396         nop
397         addu    $v0, $v0, $a1
398         j       2b
399         addiu   $a2, $a2, -1
400 3:      addu    $v0, $v0, $a1
401         j       1b
402         addiu   $a1, $a1, -1
403 4:      jr      $ra
404         nop
406         .end    graph_nested_loops
409         .global graph_for_inside_if
410         .ent    graph_for_inside_if
411 graph_for_inside_if:
412         beq     $a0, $0, 2f
413         move    $v0, $0
414         li      $a1, 1
415 1:      addiu   $a0, $a0, -1
416         bne     $a0, $0, 1b
417         addu    $a1, $a1, $a1
418         move    $v0, $a0
419 2:      jr      $ra
420         nop
422         .end    graph_for_inside_if
425         .global var_k1
426         .ent    var_k1
427 var_k1:
428         addiu   $sp, $sp, -16
429         sw      $s0, 4($sp)
430         sw      $ra, 8($sp)
431         move    $s0, $k1
432         srl     $k1, $k1, 16
433         li      $a0, 10
434         jal     graph_for_inside_if
435         li      $a1, 5
436         move    $k1, $s0
437         lw      $ra, 8($sp)
438         lw      $s0, 4($sp)
439         jr      $ra
440         addiu   $sp, $sp, 16
441         .end    var_k1
443         .section .rodata
444 switch1:
445         .word   switch1_case0
446         .word   switch1_case1
447         .word   switch1_case2
448         .word   switch1_case3
449         .word   switch1_case4
450         .word   switch1_case5
451         .word   switch1_case6
453 inner_callback:
454         .word   mycallback
455         .word   mycallback