x86-asm: Implement clflush opcode
[tinycc.git] / tests / asmtest.S
blob7f2e4ca682694c0841db23e57272a2377a09c3cf
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    .balign 4, 0x92
15    .align 16, 0x91 /* 0x91 tests the non-clever behaviour */
16    .skip 3
17    .skip 15, 0x90
18    .string "hello\0world"
20 /* some label tests */
22         movl %eax, %ebx
23 L1:
24         movl %eax, %ebx
25         mov 0x10000, %eax
26 L2:
27         movl $L2 - L1, %ecx
28 var1:
29         nop ; nop ; nop ; nop
31         mov var1, %eax
33 /* instruction tests */
34 movl %eax, %ebx
35 mov 0x10000, %eax
36 mov 0x10000, %ax
37 mov 0x10000, %al
38 mov %al, 0x10000
39                 
40 mov $1, %edx
41 mov $1, %dx
42 mov $1, %cl
43 movb $2, 0x100(%ebx,%edx,2)
44 movw $2, 0x100(%ebx,%edx,2)
45 movl $2, 0x100(%ebx,%edx,2)
46 movl %eax, 0x100(%ebx,%edx,2)
47 movl 0x100(%ebx,%edx,2), %edx
48 movw %ax, 0x100(%ebx,%edx,2)
50 movw $0x1122,%si
51 movl $0x112233,%edx
52 #ifdef __x86_64__
53 mov $0x11223344,%rbx
54 movq $0x11223344,%rbx
55 mov $0x1122334455,%rbx
56 movq $0x1122334455,%rbx
57 movl $0x11334455,(%rbx)
58 #endif
60 mov %eax, 0x12(,%edx,2)
61         
62 #ifdef __i386__
63 mov %cr3, %edx
64 mov %ecx, %cr3
65 movl %cr3, %eax
66 movl %tr3, %eax
67 movl %db3, %ebx
68 movl %dr6, %eax
69 #else
70 mov %cr3, %rdx
71 mov %rcx, %cr3
72 movq %cr3, %rax
73 movq %db3, %rbx
74 movq %dr6, %rax
75 #endif
76 movl %fs, %ecx
77 movl %ebx, %fs
79      movsbl 0x1000, %eax
80      movsbw 0x1000, %ax
81      movswl 0x1000, %eax
83      movzbl 0x1000, %eax
84      movzbw 0x1000, %ax
85      movzwl 0x1000, %eax
86             
87      movzb 0x1000, %eax
88      movzb 0x1000, %ax
89                 
90 #ifdef __x86_64__
91      movzb 0x1000, %rax
92      movzbq 0x1000, %rbx
93      movsbq 0x1000, %rdx
94      movzwq 0x1000, %rdi
95      movswq 0x1000, %rdx
96 #endif
97         
98 #ifdef __i386__
99   pushl %eax
100   push %eax
101   push %cs
102 #else
103   pushq %rax
104   push %rax
105 #endif
106   pushw %ax
107   push %gs
108   push $1
109   push $100
110                                                 
111 #ifdef __i386__
112   popl %eax
113   pop %eax
114   pop %ds
115 #else
116   popq %rax
117   pop %rax
118 #endif
119   popw %ax
120   pop %fs
121           
122   xchg %eax, %ecx
123   xchg %edx, %eax
124   xchg %bx, 0x10000
125   xchg 0x10000, %ebx
126   xchg 0x10000, %dl
128   in $100, %al               
129   in $100, %ax               
130   in $100, %eax
131   in %dx, %al
132   in %dx, %ax               
133   in %dx, %eax
134   inb %dx
135   inw %dx               
136   inl %dx
138   out %al, $100                       
139   out %ax, $100                       
140   out %eax, $100                       
142   /* NOTE: gas is bugged here, so size must be added */
143   outb %al, %dx                       
144   outw %ax, %dx                       
145   outl %eax, %dx                       
147   leal 0x1000(%ebx), %ecx
148   lea 0x1000(%ebx), %ecx
150 #ifdef __i386__
151   les 0x2000, %eax
152   lds 0x2000, %ebx
153   lss 0x2000, %edx
154 #endif
155   lfs 0x2000, %ecx
156   lgs 0x2000, %edx
158 addl $0x123, %eax
159 add $0x123, %ebx
160 add $-16, %ecx
161 add $-0x123, %esi
162 add $1, %bx
163 add $1, %ebx
164 add $-1, %bx
165 add $-1, %ebx
166 add $127, %bx
167 addl $127, %ebx
168 addl $-128, %ebx
169 addl $-128, %ebx
170 addl $-129, %ebx
171 addl $128, %ebx
172 addl $255, %ebx
173 addl $256, %ebx
174 andb $0xf, %ah
175 andb $-15, %cl
176 xorb $127, %dh
177 cmpb $42, (%eax)
178 addl $0x123, 0x100
179 addl $0x123, 0x100(%ebx)
180 addl $0x123, 0x100(%ebx,%edx,2)
181 addl $0x123, 0x100(%esp)
182 addl $0x123, (3*8)(%esp)
183 addl $0x123, (%ebp)
184 addl $0x123, (%esp)
185 cmpl $0x123, (%esp)
187 add %eax, (%ebx)
188 add (%ebx), %eax
189                 
190 or %dx, (%ebx)
191 or (%ebx), %si
192         
193 add %cl, (%ebx)
194 add (%ebx), %dl
196     inc %edx
197     incl 0x10000
198     incb 0x10000
199     dec %dx
200   
201   test $1, %al
202   test $1, %cl
204   testl $1, 0x1000
205   testb $1, 0x1000
206   testw $1, 0x1000
207   test %eax, %ebx
208   test %eax, 0x1000
209   test 0x1000, %edx
211     not %edx
212     notw 0x10000
213     notl 0x10000
214     notb 0x10000
216     neg %edx
217     negw 0x10000
218     negl 0x10000
219     negb 0x10000
221     imul %ecx
222     mul %edx
223     mulb %cl
225     imul %eax, %ecx
226     imul 0x1000, %cx
227     imul $10, %eax, %ecx
228     imul $10, %ax, %cx
229     imul $10, %eax
230     imul $0x1100000, %eax
231     imul $1, %eax
232     
233     idivw 0x1000
234     div %ecx
235     div %bl
236     div %ecx, %eax
238 and $15,%bx
239 and $-20,%edx
241 shl %edx
242 shl $10, %edx
243 shl %cl, %edx
245 shld $1, %eax, %edx
246 shld %cl, %eax, %edx
247 shld %eax, %edx
249 shrd $1, %eax, %edx
250 shrd %cl, %eax, %edx
251 shrd %eax, %edx
254 call 0x1000
255 call L4
256 #ifdef __i386__
257 call *%eax
258 #else
259 call *%rax
260 #endif
261 call *0x1000
262 call func1
264 .global L5,L6
269 #ifdef __i386__
270 lcall $0x100, $0x1000
271 #else
272 lcall *0x100
273 lcall *(%rax)
274 #endif
276 jmp 0x1000
277 jmp *(%edi)
278 #ifdef __i386__
279 jmp *%eax
280 #else
281 jmp *%rax
282 #endif
283 jmp *0x1000
285 #ifdef __i386__
286 ljmp $0x100, $0x1000
287 #else
288 ljmp *0x100
289 ljmp *(%rdi)
290 #endif
293 ret $10
294 #ifdef __i386__
295 retl
296 retl $10
297 #else
298 retq
299 retq $10
300 #endif
302 lret
304 lret $10
306 enter $1234, $10
309  jo 0x1000
310  jnp 0x1001
311  jne 0x1002
312  jg 0x1003
314  jo L3
315  jnp L3
316  jne L3
317  jg L3
319  loopne L3
320  loopnz L3
321  loope L3
322  loopz L3
323  loop L3
324  jecxz L3
326         
327  seto %al
328  setc %al
329  setcb %al
330  setnp 0x1000
331  setl 0xaaaa
332  setg %dl
334  fadd
335  fadd %st(1), %st
336  fadd %st(0), %st(1)
337  fadd %st(3)
339  fmul %st(0),%st(0)
340  fmul %st(0),%st(1)
342  faddp %st(5)
343  faddp
344  faddp %st(1), %st
346  fadds 0x1000
347  fiadds 0x1002
348  faddl 0x1004
349  fiaddl 0x1006
351  fmul
352  fmul %st(1), %st
353  fmul %st(3)
355  fmulp %st(5)
356  fmulp
357  fmulp %st(1), %st
359  fmuls 0x1000
360  fimuls 0x1002
361  fmull 0x1004
362  fimull 0x1006
364  fsub
365  fsub %st(1), %st
366  fsub %st(3)
368  fsubp %st(5)
369  fsubp
370  fsubp %st(1), %st
372  fsubs 0x1000
373  fisubs 0x1002
374  fsubl 0x1004
375  fisubl 0x1006
377  fsubr
378  fsubr %st(1), %st
379  fsubr %st(3)
381  fsubrp %st(5)
382  fsubrp
383  fsubrp %st(1), %st
385  fsubrs 0x1000
386  fisubrs 0x1002
387  fsubrl 0x1004
388  fisubrl 0x1006
390  fdiv
391  fdiv %st(1), %st
392  fdiv %st(3)
394  fdivp %st(5)
395  fdivp
396  fdivp %st(1), %st
398  fdivs 0x1000
399  fidivs 0x1002
400  fdivl 0x1004
401  fidivl 0x1006
403  fcom %st(3)
405  fcoms 0x1000
406  ficoms 0x1002
407  fcoml 0x1004
408  ficoml 0x1006
410  fcomp %st(5)
411  fcomp
412  fcompp
414  fcomps 0x1000
415  ficomps 0x1002
416  fcompl 0x1004
417  ficompl 0x1006
419  fld %st(5)
420  fldl 0x1000
421  flds 0x1002
422  fildl 0x1004
423  fst %st(4)
424  fstp %st(6)
425  fstpt 0x1006
426  fbstp 0x1008
428  fxch
429  fxch %st(4)
431  fucom %st(6)
432  fucomp %st(3)
433  fucompp
435  finit
436  fninit
437  fldcw 0x1000
438  fnstcw 0x1002
439  fstcw 0x1002
440  fnstsw 0x1004
441  fnstsw (%eax)
442  fstsw 0x1004
443  fstsw (%eax)
444  fnclex
445  fclex
446  fnstenv 0x1000
447  fstenv 0x1000
448  fldenv 0x1000
449  fnsave 0x1002
450  fsave 0x1000
451  frstor 0x1000
452  ffree %st(7)
453  ffreep %st(6)
455     ftst
456     fxam
457     fld1
458     fldl2t
459     fldl2e
460     fldpi
461     fldlg2
462     fldln2
463     fldz
465     f2xm1
466     fyl2x
467     fptan
468     fpatan
469     fxtract
470     fprem1
471     fdecstp
472     fincstp
473     fprem
474     fyl2xp1
475     fsqrt
476     fsincos
477     frndint
478     fscale
479     fsin
480     fcos
481     fchs
482     fabs
483     fnop
484     fwait
486 bswap %edx
487 xadd %ecx, %edx
488 xaddb %dl, 0x1000
489 xaddw %ax, 0x1000
490 xaddl %eax, 0x1000
491 cmpxchg %ecx, %edx
492 cmpxchgb %dl, 0x1000
493 cmpxchgw %ax, 0x1000
494 cmpxchgl %eax, 0x1000
495 invlpg 0x1000
496 cmpxchg8b 0x1002
498 fcmovb %st(5), %st
499 fcmove %st(5), %st
500 fcmovbe %st(5), %st
501 fcmovu %st(5), %st
502 fcmovnb %st(5), %st
503 fcmovne %st(5), %st
504 fcmovnbe %st(5), %st
505 fcmovnu %st(5), %st
506 fcomi %st(5), %st
507 fucomi %st(5), %st
508 fcomip %st(5), %st
509 fucomip %st(5), %st
513  cmovo 0x1000, %eax
514  cmovs 0x1000, %eax
515  cmovns %edx, %edi
516  cmovne %ax, %si
517 #ifdef __x86_64__
518  cmovz %rdi,%rbx
519 #endif
521 int $3
522 int $0x10
524 #ifdef __i386__
525     pusha
526     popa
527 #endif
528     clc
529     cld
530     cli
531     clts
532     cmc
533     lahf
534     sahf
535 #ifdef __i386__
536     pushfl
537     popfl
538 #else
539     pushfq
540     popfq
541 #endif
542     pushf
543     popf
544     stc
545     std
546     sti
547 #ifdef __i386__
548     aaa
549     aas
550     daa
551     das
552     aad
553     aam
554     into
555 #endif
556     cbw
557     cwd
558     cwde
559     cdq
560     cbtw
561     cwtd
562     cwtl
563     cltd
564     leave
565     int3
566     iret
567     rsm
568     hlt
569     wait
570     nop
572     /* XXX: handle prefixes */
573 #if 0
574     aword
575     addr16
576 #endif
577     lock
578     rep
579     repe
580     repz
581     repne
582     repnz
583     nop
585     lock ;negl (%eax)
586     wait ;pushf
587     rep  ;stosb
588     repe ;lodsb
589     repz ;cmpsb
590     repne;movsb
591     repnz;outsb
593     /* handle one-line prefix + ops */
594     lock  negl (%eax)
595     wait  pushf
596     rep   stosb
597     repe  lodsb
598     repz  cmpsb
599     repne movsb
600     repnz outsb
601     
602     invd
603     wbinvd
604     cpuid
605     wrmsr
606     rdtsc
607     rdmsr
608     rdpmc
609     ud2
610 #ifdef __x86_64__
611     syscall
612     sysret
613     lfence
614     mfence
615     sfence
616     clflush 0x1000(%rax,%rcx)
617 #endif
619     emms
620     movd %edx, %mm3
621     movd 0x1000, %mm2
622     movd %mm4, %ecx
623     movd %mm5, 0x1000
624                     
625     movq 0x1000, %mm2
626     movq %mm4, 0x1000
627     
628     pand 0x1000, %mm3
629     pand %mm4, %mm5
630     
631     psllw $1, %mm6
632     psllw 0x1000, %mm7
633     psllw %mm2, %mm7
635     xlat
636     cmpsb
637     scmpw
638     insl
639     outsw
640     lodsb
641     slodl
642     movsb
643     movsl
644     smovb
645     scasb
646     sscaw
647     stosw
648     sstol
650     bsf 0x1000, %ebx
651     bsr 0x1000, %ebx
652     bt %edx, 0x1000
653     btl $2, 0x1000
654     btc %edx, 0x1000
655     btcl $2, 0x1000
656     btr %edx, 0x1000
657     btrl $2, 0x1000
658     bts %edx, 0x1000
659     btsl $2, 0x1000
661         
662         
663 #ifdef __i386__
664     boundl %edx, 0x10000
665     boundw %bx, 0x1000
667     arpl %bx, 0x1000
668 #endif
669     lar 0x1000, %eax
670     lgdt 0x1000
671     lidt 0x1000
672     lldt 0x1000
673     lmsw 0x1000
674     lsl 0x1000, %ecx
675     ltr 0x1000
676     
677     sgdt 0x1000
678     sidt 0x1000
679     sldt 0x1000
680     smsw 0x1000
681     str 0x1000
682     
683     verr 0x1000
684     verw 0x1000
685   
686 #ifdef __i386__
687     push %ds
688     pushw %ds
689     pushl %ds
690     pop %ds
691     popw %ds
692     popl %ds
693 #endif
694     fxsave 1(%ebx)
695     fxrstor 1(%ecx)
696 #ifdef __i386__
697     pushl $1
698 #else
699     pushq $1
700 #endif
701     pushw $1
702     push $1
704 #ifdef __ASSEMBLER__ // should be defined, for S files
705     inc %eax
706 #endif
708 #ifndef _WIN32
709 ft1: ft2: ft3: ft4: ft5: ft6: ft7: ft8: ft9:
710     xor %eax, %eax
711     ret
713 .type ft1,STT_FUNC
714 .type ft2,@STT_FUNC
715 .type ft3,%STT_FUNC
716 .type ft4,"STT_FUNC"
717 .type ft5,function
718 .type ft6,@function
719 .type ft7,%function
720 .type ft8,"function"
721 #endif
723     pause
724 .rept 6
725     nop
726 .endr
727 .fill 4,1,0x90
729 .section .text.one,"ax"
731 .previous
732 .pushsection .text.one,"ax"
734 .pushsection .text.two,"ax"
736 .popsection
737 .popsection
739 1: ud2
740 .pushsection __bug_table,"a"
741 .align 8
742 2: .long 1b - 2b
743    .long 0x600000 - 2b
744    .long 1b + 42
745    .long 43 + 1b
746    .long 2b + 144
747    .long 145 + 2b
748    .word 164, 0
749    .org 2b+32
750    .quad 1b
751 .popsection
752 3: mov %eax,%ecx
754 .pushsection .text.three, "ax"
756 .skip (-((4b-3b) > 0) * 2) , 0x90
757 .popsection
759     movd %esi, %mm1
760     movd %edi, %xmm2
761     movd (%ebx), %mm3
762     movd (%ebx), %xmm3
763     movd %mm1, %esi
764     movd %xmm2, %edi
765     movd %mm3, (%edx)
766     movd %xmm3, (%edx)
767 #ifdef __x86_64__
768     movd %rsi, %mm1
769     movd %rdi, %xmm2
770     movd (%rbx), %mm3
771     movd (%rbx), %xmm3
772     movd %mm1, %rsi
773     movd %xmm2, %rdi
774     movd %mm3, (%rdx)
775     movd %xmm3, (%rdx)
776 #endif
778     movq (%ebp), %mm1
779     movq %mm2, (%edi)
780     movq (%edi), %xmm3
781     movq %mm4, %mm5
782 #ifdef __x86_64__
783     movq %rcx, %mm1
784     movq %rdx, %xmm2
785     /* movq mem64->xmm is encoded as f30f7e by GAS, but as
786        660f6e by tcc (which really is a movd and would need 
787        a REX.W prefix to be movq).  */
788     movq (%rsi), %xmm3
789     movq %mm1, %rdx
790     movq %xmm3, %rcx
791     movq %xmm4, (%rsi)
792 #endif
794 #define TEST_MMX_SSE(insn) \
795     insn %mm1, %mm2; \
796     insn %xmm2, %xmm3; \
797     insn (%ebx), %xmm3;
798 #define TEST_MMX_SSE_I8(insn) \
799     TEST_MMX_SSE(insn) \
800     insn $0x42, %mm4; \
801     insn $0x42, %xmm4;
803     TEST_MMX_SSE(packssdw)
804     TEST_MMX_SSE(packsswb)
805     TEST_MMX_SSE(packuswb)
806     TEST_MMX_SSE(paddb)
807     TEST_MMX_SSE(paddw)
808     TEST_MMX_SSE(paddd)
809     TEST_MMX_SSE(paddsb)
810     TEST_MMX_SSE(paddsw)
811     TEST_MMX_SSE(paddusb)
812     TEST_MMX_SSE(paddusw)
813     TEST_MMX_SSE(pand)
814     TEST_MMX_SSE(pandn)
815     TEST_MMX_SSE(pcmpeqb)
816     TEST_MMX_SSE(pcmpeqw)
817     TEST_MMX_SSE(pcmpeqd)
818     TEST_MMX_SSE(pcmpgtb)
819     TEST_MMX_SSE(pcmpgtw)
820     TEST_MMX_SSE(pcmpgtd)
821     TEST_MMX_SSE(pmaddwd)
822     TEST_MMX_SSE(pmulhw)
823     TEST_MMX_SSE(pmullw)
824     TEST_MMX_SSE(por)
825     TEST_MMX_SSE(psllw)
826 TEST_MMX_SSE_I8(psllw)
827     TEST_MMX_SSE(pslld)
828 TEST_MMX_SSE_I8(pslld)
829     TEST_MMX_SSE(psllq)
830 TEST_MMX_SSE_I8(psllq)
831     TEST_MMX_SSE(psraw)
832 TEST_MMX_SSE_I8(psraw)
833     TEST_MMX_SSE(psrad)
834 TEST_MMX_SSE_I8(psrad)
835     TEST_MMX_SSE(psrlw)
836 TEST_MMX_SSE_I8(psrlw)
837     TEST_MMX_SSE(psrld)
838 TEST_MMX_SSE_I8(psrld)
839     TEST_MMX_SSE(psrlq)
840 TEST_MMX_SSE_I8(psrlq)
841     TEST_MMX_SSE(psubb)
842     TEST_MMX_SSE(psubw)
843     TEST_MMX_SSE(psubd)
844     TEST_MMX_SSE(psubsb)
845     TEST_MMX_SSE(psubsw)
846     TEST_MMX_SSE(psubusb)
847     TEST_MMX_SSE(psubusw)
848     TEST_MMX_SSE(punpckhbw)
849     TEST_MMX_SSE(punpckhwd)
850     TEST_MMX_SSE(punpckhdq)
851     TEST_MMX_SSE(punpcklbw)
852     TEST_MMX_SSE(punpcklwd)
853     TEST_MMX_SSE(punpckldq)
854     TEST_MMX_SSE(pxor)
856     cvtpi2ps %mm1, %xmm2
857     cvtpi2ps (%ebx), %xmm2
858     TEST_MMX_SSE(pmaxsw)
859     TEST_MMX_SSE(pmaxub)
860     TEST_MMX_SSE(pminsw)
861     TEST_MMX_SSE(pminub)