x86: Improve cmov handling
[tinycc.git] / tests / asmtest.S
blob2a9f4039bc79cf4f4c029070a06dbdd042f2db28
1 # gas comment with ``gnu'' style quotes
3 /* some directive tests */
5    .byte 0xff
6    .byte 1, 2, 3
7    .short 1, 2, 3
8    .word 1, 2, 3
9    .long 1, 2, 3
10    .int 1, 2, 3
11    .align 8
12    .byte 1
13 /* .align 16, 0x90 gas is too clever for us with 0x90 fill */
14    .align 16, 0x91 /* 0x91 tests the non-clever behaviour */
15    .skip 3
16    .skip 15, 0x90
17    .string "hello\0world"
19 /* some label tests */
21         movl %eax, %ebx
22 L1:
23         movl %eax, %ebx
24         mov 0x10000, %eax
25 L2:
26         movl $L2 - L1, %ecx
27 var1:
28         nop ; nop ; nop ; nop
30         mov var1, %eax
32 /* instruction tests */
33 movl %eax, %ebx
34 mov 0x10000, %eax
35 mov 0x10000, %ax
36 mov 0x10000, %al
37 mov %al, 0x10000
38                 
39 mov $1, %edx
40 mov $1, %dx
41 mov $1, %cl
42 movb $2, 0x100(%ebx,%edx,2)
43 movw $2, 0x100(%ebx,%edx,2)
44 movl $2, 0x100(%ebx,%edx,2)
45 movl %eax, 0x100(%ebx,%edx,2)
46 movl 0x100(%ebx,%edx,2), %edx
47 movw %ax, 0x100(%ebx,%edx,2)
49 mov %eax, 0x12(,%edx,2)
50         
51 #ifdef __i386__
52 mov %cr3, %edx
53 mov %ecx, %cr3
54 movl %cr3, %eax
55 movl %tr3, %eax
56 movl %db3, %ebx
57 movl %dr6, %eax
58 #else
59 mov %cr3, %rdx
60 mov %rcx, %cr3
61 movq %cr3, %rax
62 movq %db3, %rbx
63 movq %dr6, %rax
64 #endif
65 movl %fs, %ecx
66 movl %ebx, %fs
68      movsbl 0x1000, %eax
69      movsbw 0x1000, %ax
70      movswl 0x1000, %eax
72      movzbl 0x1000, %eax
73      movzbw 0x1000, %ax
74      movzwl 0x1000, %eax
75             
76      movzb 0x1000, %eax
77      movzb 0x1000, %ax
78                 
79         
80 #ifdef __i386__
81   pushl %eax
82   push %eax
83   push %cs
84 #else
85   pushq %rax
86   push %rax
87 #endif
88   pushw %ax
89   push %gs
90   push $1
91   push $100
92                                                 
93 #ifdef __i386__
94   popl %eax
95   pop %eax
96   pop %ds
97 #else
98   popq %rax
99   pop %rax
100 #endif
101   popw %ax
102   pop %fs
103           
104   xchg %eax, %ecx
105   xchg %edx, %eax
106   xchg %bx, 0x10000
107   xchg 0x10000, %ebx
108   xchg 0x10000, %dl
110   in $100, %al               
111   in $100, %ax               
112   in $100, %eax
113   in %dx, %al
114   in %dx, %ax               
115   in %dx, %eax
116   inb %dx
117   inw %dx               
118   inl %dx
120   out %al, $100                       
121   out %ax, $100                       
122   out %eax, $100                       
124   /* NOTE: gas is bugged here, so size must be added */
125   outb %al, %dx                       
126   outw %ax, %dx                       
127   outl %eax, %dx                       
129   leal 0x1000(%ebx), %ecx
130   lea 0x1000(%ebx), %ecx
132 #ifdef __i386__
133   les 0x2000, %eax
134   lds 0x2000, %ebx
135   lss 0x2000, %edx
136 #endif
137   lfs 0x2000, %ecx
138   lgs 0x2000, %edx
140 addl $0x123, %eax
141 add $0x123, %ebx
142 addl $0x123, 0x100
143 addl $0x123, 0x100(%ebx)
144 addl $0x123, 0x100(%ebx,%edx,2)
145 addl $0x123, 0x100(%esp)
146 addl $0x123, (3*8)(%esp)
147 addl $0x123, (%ebp)
148 addl $0x123, (%esp)
149 cmpl $0x123, (%esp)
151 add %eax, (%ebx)
152 add (%ebx), %eax
153                 
154 or %dx, (%ebx)
155 or (%ebx), %si
156         
157 add %cl, (%ebx)
158 add (%ebx), %dl
160     inc %edx
161     incl 0x10000
162     incb 0x10000
163     dec %dx
164   
165   test $1, %al
166   test $1, %cl
168   testl $1, 0x1000
169   testb $1, 0x1000
170   testw $1, 0x1000
171   test %eax, %ebx
172   test %eax, 0x1000
173   test 0x1000, %edx
175     not %edx
176     notw 0x10000
177     notl 0x10000
178     notb 0x10000
180     neg %edx
181     negw 0x10000
182     negl 0x10000
183     negb 0x10000
185     imul %ecx
186     mul %edx
187     mulb %cl
189     imul %eax, %ecx
190     imul 0x1000, %cx
191     imul $10, %eax, %ecx
192     imul $10, %ax, %cx
193     imul $10, %eax
194     imul $0x1100000, %eax
195     imul $1, %eax
196     
197     idivw 0x1000
198     div %ecx
199     div %bl
200     div %ecx, %eax
203 shl %edx
204 shl $10, %edx
205 shl %cl, %edx
207 shld $1, %eax, %edx
208 shld %cl, %eax, %edx
209 shld %eax, %edx
211 shrd $1, %eax, %edx
212 shrd %cl, %eax, %edx
213 shrd %eax, %edx
216 call 0x1000
217 call L4
218 #ifdef __i386__
219 call *%eax
220 #else
221 call *%rax
222 #endif
223 call *0x1000
224 call func1
226 .global L5,L6
231 #ifdef __i386__
232 lcall $0x100, $0x1000
233 #else
234 lcall *0x100
235 lcall *(%rax)
236 #endif
238 jmp 0x1000
239 #ifdef __i386__
240 jmp *%eax
241 #else
242 jmp *%rax
243 #endif
244 jmp *0x1000
246 #ifdef __i386__
247 ljmp $0x100, $0x1000
248 #else
249 ljmp *0x100
250 ljmp *(%rdi)
251 #endif
254 ret $10
255 #ifdef __i386__
256 retl
257 retl $10
258 #else
259 retq
260 retq $10
261 #endif
263 lret
265 lret $10
267 enter $1234, $10
270  jo 0x1000
271  jnp 0x1001
272  jne 0x1002
273  jg 0x1003
275  jo L3
276  jnp L3
277  jne L3
278  jg L3
280  loopne L3
281  loopnz L3
282  loope L3
283  loopz L3
284  loop L3
285  jecxz L3
287         
288  seto %al
289  setc %al
290  setcb %al
291  setnp 0x1000
292  setl 0xaaaa
293  setg %dl
295  fadd
296  fadd %st(1), %st
297  fadd %st(0), %st(1)
298  fadd %st(3)
300  fmul %st(0),%st(0)
301  fmul %st(0),%st(1)
303  faddp %st(5)
304  faddp
305  faddp %st(1), %st
307  fadds 0x1000
308  fiadds 0x1002
309  faddl 0x1004
310  fiaddl 0x1006
312  fmul
313  fmul %st(1), %st
314  fmul %st(3)
316  fmulp %st(5)
317  fmulp
318  fmulp %st(1), %st
320  fmuls 0x1000
321  fimuls 0x1002
322  fmull 0x1004
323  fimull 0x1006
325  fsub
326  fsub %st(1), %st
327  fsub %st(3)
329  fsubp %st(5)
330  fsubp
331  fsubp %st(1), %st
333  fsubs 0x1000
334  fisubs 0x1002
335  fsubl 0x1004
336  fisubl 0x1006
338  fsubr
339  fsubr %st(1), %st
340  fsubr %st(3)
342  fsubrp %st(5)
343  fsubrp
344  fsubrp %st(1), %st
346  fsubrs 0x1000
347  fisubrs 0x1002
348  fsubrl 0x1004
349  fisubrl 0x1006
351  fdiv
352  fdiv %st(1), %st
353  fdiv %st(3)
355  fdivp %st(5)
356  fdivp
357  fdivp %st(1), %st
359  fdivs 0x1000
360  fidivs 0x1002
361  fdivl 0x1004
362  fidivl 0x1006
364  fcom %st(3)
366  fcoms 0x1000
367  ficoms 0x1002
368  fcoml 0x1004
369  ficoml 0x1006
371  fcomp %st(5)
372  fcomp
373  fcompp
375  fcomps 0x1000
376  ficomps 0x1002
377  fcompl 0x1004
378  ficompl 0x1006
380  fld %st(5)
381  fldl 0x1000
382  flds 0x1002
383  fildl 0x1004
384  fst %st(4)
385  fstp %st(6)
386  fstpt 0x1006
387  fbstp 0x1008
389  fxch
390  fxch %st(4)
392  fucom %st(6)
393  fucomp %st(3)
394  fucompp
396  finit
397  fninit
398  fldcw 0x1000
399  fnstcw 0x1002
400  fstcw 0x1002
401  fnstsw 0x1004
402  fnstsw (%eax)
403  fstsw 0x1004
404  fstsw (%eax)
405  fnclex
406  fclex
407  fnstenv 0x1000
408  fstenv 0x1000
409  fldenv 0x1000
410  fnsave 0x1002
411  fsave 0x1000
412  frstor 0x1000
413  ffree %st(7)
414  ffreep %st(6)
416     ftst
417     fxam
418     fld1
419     fldl2t
420     fldl2e
421     fldpi
422     fldlg2
423     fldln2
424     fldz
426     f2xm1
427     fyl2x
428     fptan
429     fpatan
430     fxtract
431     fprem1
432     fdecstp
433     fincstp
434     fprem
435     fyl2xp1
436     fsqrt
437     fsincos
438     frndint
439     fscale
440     fsin
441     fcos
442     fchs
443     fabs
444     fnop
445     fwait
447 bswap %edx
448 xadd %ecx, %edx
449 xaddb %dl, 0x1000
450 xaddw %ax, 0x1000
451 xaddl %eax, 0x1000
452 cmpxchg %ecx, %edx
453 cmpxchgb %dl, 0x1000
454 cmpxchgw %ax, 0x1000
455 cmpxchgl %eax, 0x1000
456 invlpg 0x1000
457 cmpxchg8b 0x1002
459 fcmovb %st(5), %st
460 fcmove %st(5), %st
461 fcmovbe %st(5), %st
462 fcmovu %st(5), %st
463 fcmovnb %st(5), %st
464 fcmovne %st(5), %st
465 fcmovnbe %st(5), %st
466 fcmovnu %st(5), %st
467 fcomi %st(5), %st
468 fucomi %st(5), %st
469 fcomip %st(5), %st
470 fucomip %st(5), %st
474  cmovo 0x1000, %eax
475  cmovs 0x1000, %eax
476  cmovns %edx, %edi
477  cmovne %ax, %si
478 #ifdef __x86_64__
479  cmovz %rdi,%rbx
480 #endif
482 int $3
483 int $0x10
485 #ifdef __i386__
486     pusha
487     popa
488 #endif
489     clc
490     cld
491     cli
492     clts
493     cmc
494     lahf
495     sahf
496 #ifdef __i386__
497     pushfl
498     popfl
499 #else
500     pushfq
501     popfq
502 #endif
503     pushf
504     popf
505     stc
506     std
507     sti
508 #ifdef __i386__
509     aaa
510     aas
511     daa
512     das
513     aad
514     aam
515     into
516 #endif
517     cbw
518     cwd
519     cwde
520     cdq
521     cbtw
522     cwtd
523     cwtl
524     cltd
525     leave
526     int3
527     iret
528     rsm
529     hlt
530     wait
531     nop
533     /* XXX: handle prefixes */
534 #if 0
535     aword
536     addr16
537 #endif
538     lock
539     rep
540     repe
541     repz
542     repne
543     repnz
544     nop
546     lock ;negl (%eax)
547     wait ;pushf
548     rep  ;stosb
549     repe ;lodsb
550     repz ;cmpsb
551     repne;movsb
552     repnz;outsb
554     /* handle one-line prefix + ops */
555     lock  negl (%eax)
556     wait  pushf
557     rep   stosb
558     repe  lodsb
559     repz  cmpsb
560     repne movsb
561     repnz outsb
562     
563     invd
564     wbinvd
565     cpuid
566     wrmsr
567     rdtsc
568     rdmsr
569     rdpmc
570     ud2
572     emms
573     movd %edx, %mm3
574     movd 0x1000, %mm2
575     movd %mm4, %ecx
576     movd %mm5, 0x1000
577                     
578     movq 0x1000, %mm2
579     movq %mm4, 0x1000
580     
581     pand 0x1000, %mm3
582     pand %mm4, %mm5
583     
584     psllw $1, %mm6
585     psllw 0x1000, %mm7
586     psllw %mm2, %mm7
588     xlat
589     cmpsb
590     scmpw
591     insl
592     outsw
593     lodsb
594     slodl
595     movsb
596     movsl
597     smovb
598     scasb
599     sscaw
600     stosw
601     sstol
603     bsf 0x1000, %ebx
604     bsr 0x1000, %ebx
605     bt %edx, 0x1000
606     btl $2, 0x1000
607     btc %edx, 0x1000
608     btcl $2, 0x1000
609     btr %edx, 0x1000
610     btrl $2, 0x1000
611     bts %edx, 0x1000
612     btsl $2, 0x1000
614         
615         
616 #ifdef __i386__
617     boundl %edx, 0x10000
618     boundw %bx, 0x1000
620     arpl %bx, 0x1000
621 #endif
622     lar 0x1000, %eax
623     lgdt 0x1000
624     lidt 0x1000
625     lldt 0x1000
626     lmsw 0x1000
627     lsl 0x1000, %ecx
628     ltr 0x1000
629     
630     sgdt 0x1000
631     sidt 0x1000
632     sldt 0x1000
633     smsw 0x1000
634     str 0x1000
635     
636     verr 0x1000
637     verw 0x1000
638   
639 #ifdef __i386__
640     push %ds
641     pushw %ds
642     pushl %ds
643     pop %ds
644     popw %ds
645     popl %ds
646 #endif
647     fxsave 1(%ebx)
648     fxrstor 1(%ecx)
649 #ifdef __i386__
650     pushl $1
651 #else
652     pushq $1
653 #endif
654     pushw $1
655     push $1
657 #ifdef __ASSEMBLER__ // should be defined, for S files
658     inc %eax
659 #endif
661 ft1: ft2: ft3: ft4: ft5: ft6: ft7: ft8: ft9:
662     xor %eax, %eax
663     ret
665 .type ft1,STT_FUNC
666 .type ft2,@STT_FUNC
667 .type ft3,%STT_FUNC
668 .type ft4,"STT_FUNC"
669 .type ft5,function
670 .type ft6,@function
671 .type ft7,%function
672 .type ft8,"function"
674     pause