tccasm: Implement .set sym, expr
[tinycc.git] / tests / asmtest.S
blobdbc6c15a3c28315acab3bde01f137f51b72a4639
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 mov %cr8, %rsi
76 mov %rdi, %cr8
77 #endif
78 movl %fs, %ecx
79 movl %ebx, %fs
81 #ifdef __x86_64__
82 movq %r8, %r9
83 movq %r10, %r11
84 movq %r12, %r13
85 movq %r14, %r15
86 movq %rax, %r9
87 movq %r15, %rsi
88 inc %r9b
89 dec %r10w
90 not %r11d
91 negq %r12
92 decb %r13b
93 incw %r14w
94 notl %r15d
95 #endif
97      movsbl 0x1000, %eax
98      movsbw 0x1000, %ax
99      movswl 0x1000, %eax
101      movzbl 0x1000, %eax
102      movzbw 0x1000, %ax
103      movzwl 0x1000, %eax
104             
105      movzb 0x1000, %eax
106      movzb 0x1000, %ax
107                 
108 #ifdef __x86_64__
109      movzb 0x1000, %rax
110      movzbq 0x1000, %rbx
111      movsbq 0x1000, %rdx
112      movzwq 0x1000, %rdi
113      movswq 0x1000, %rdx
114 #endif
115         
116 #ifdef __i386__
117   pushl %eax
118   push %eax
119   push %cs
120 #else
121   pushq %rax
122   push %rax
123 #endif
124   pushw %ax
125   push %gs
126   push $1
127   push $100
128   push 0x42(%eax)
129   pop 0x43(%esi)
130                                                 
131 #ifdef __i386__
132   popl %eax
133   pop %eax
134   pop %ds
135 #else
136   popq %rax
137   pop %rax
138 #endif
139   popw %ax
140   pop %fs
141           
142   xchg %eax, %ecx
143   xchg %edx, %eax
144   xchg %bx, 0x10000
145   xchg 0x10000, %ebx
146   xchg 0x10000, %dl
148   in $100, %al               
149   in $100, %ax               
150   in $100, %eax
151   in %dx, %al
152   in %dx, %ax               
153   in %dx, %eax
154   inb %dx
155   inw %dx               
156   inl %dx
158   out %al, $100                       
159   out %ax, $100                       
160   out %eax, $100                       
162   /* NOTE: gas is bugged here, so size must be added */
163   outb %al, %dx                       
164   outw %ax, %dx                       
165   outl %eax, %dx                       
167   leal 0x1000(%ebx), %ecx
168   lea 0x1000(%ebx), %ecx
170 #ifdef __i386__
171   les 0x2000, %eax
172   lds 0x2000, %ebx
173   lss 0x2000, %edx
174 #endif
175   lfs 0x2000, %ecx
176   lgs 0x2000, %edx
178 addl $0x123, %eax
179 add $0x123, %ebx
180 add $-16, %ecx
181 add $-0x123, %esi
182 add $1, %bx
183 add $1, %ebx
184 add $-1, %bx
185 add $-1, %ebx
186 add $127, %bx
187 addl $127, %ebx
188 addl $-128, %ebx
189 addl $-128, %ebx
190 addl $-129, %ebx
191 addl $128, %ebx
192 addl $255, %ebx
193 addl $256, %ebx
194 andb $0xf, %ah
195 andb $-15, %cl
196 xorb $127, %dh
197 cmpb $42, (%eax)
198 addl $0x123, 0x100
199 addl $0x123, 0x100(%ebx)
200 addl $0x123, 0x100(%ebx,%edx,2)
201 addl $0x123, 0x100(%esp)
202 addl $0x123, (3*8)(%esp)
203 addl $0x123, (%ebp)
204 addl $0x123, (%esp)
205 cmpl $0x123, (%esp)
207 #ifdef __x86_64__
208 xor %bl,%ah
209 xor %bl,%r8b
210 xor %r9b,%bl
211 xor %sil,%cl
212 add %eax,(%r8d)
213 add %ebx,(%r9)
214 add %edx,(%r10d,%r11d)
215 add %ecx,(%r12,%r13)
216 add %esi,(%r14,%r15,4)
217 add %edi,0x1000(%rbx,%r12,8)
218 add %r11,0x1000(%ebp,%r9d,8)
219 movb $12, %ah
220 movb $13, %bpl
221 movb $14, %dil
222 movb $15, %r12b
223 #endif
225 add %eax, (%ebx)
226 add (%ebx), %eax
227                 
228 or %dx, (%ebx)
229 or (%ebx), %si
230         
231 add %cl, (%ebx)
232 add (%ebx), %dl
234     inc %edx
235     incl 0x10000
236     incb 0x10000
237     dec %dx
238   
239   test $1, %al
240   test $1, %cl
242   testl $1, 0x1000
243   testb $1, 0x1000
244   testw $1, 0x1000
245   test %eax, %ebx
246   test %eax, 0x1000
247   test 0x1000, %edx
249     not %edx
250     notw 0x10000
251     notl 0x10000
252     notb 0x10000
254     neg %edx
255     negw 0x10000
256     negl 0x10000
257     negb 0x10000
259     imul %ecx
260     mul %edx
261     mulb %cl
263     imul %eax, %ecx
264     imul 0x1000, %cx
265     imul $10, %eax, %ecx
266     imul $10, %ax, %cx
267     imul $10, %eax
268     imul $0x1100000, %eax
269     imul $1, %eax
270     
271     idivw 0x1000
272     div %ecx
273     div %bl
274     div %ecx, %eax
276 and $15,%bx
277 and $-20,%edx
279 shl %edx
280 shl $10, %edx
281 shl %cl, %edx
283 shld $1, %eax, %edx
284 shld %cl, %eax, %edx
285 shld %eax, %edx
287 shrd $1, %eax, %edx
288 shrd %cl, %eax, %edx
289 shrd %eax, %edx
292 call 0x1000
293 call L4
294 #ifdef __i386__
295 call *%eax
296 #else
297 call *%rax
298 #endif
299 call *0x1000
300 call func1
302 .global L5,L6
307 #ifdef __i386__
308 lcall $0x100, $0x1000
309 #else
310 lcall *0x100
311 lcall *(%rax)
312 #endif
314 jmp 0x1000
315 jmp *(%edi)
316 #ifdef __i386__
317 jmp *%eax
318 #else
319 jmp *%rax
320 #endif
321 jmp *0x1000
323 #ifdef __i386__
324 ljmp $0x100, $0x1000
325 #else
326 ljmp *0x100
327 ljmp *(%rdi)
328 ljmpl *(%esi)
329 ljmpw *(%esi)
330 #endif
333 ret $10
334 #ifdef __i386__
335 retl
336 retl $10
337 #else
338 retq
339 retq $10
340 #endif
342 lret
344 lret $10
346 enter $1234, $10
349  jo 0x1000
350  jnp 0x1001
351  jne 0x1002
352  jg 0x1003
354  jo L3
355  jnp L3
356  jne L3
357  jg L3
359  loopne L3
360  loopnz L3
361  loope L3
362  loopz L3
363  loop L3
364  jecxz L3
366         
367  seto %al
368  setc %al
369  setcb %al
370  setnp 0x1000
371  setl 0xaaaa
372  setg %dl
374  fadd
375  fadd %st(1), %st
376  fadd %st(0), %st(1)
377  fadd %st(3)
379  fmul %st(0),%st(0)
380  fmul %st(0),%st(1)
382  faddp %st(5)
383  faddp
384  faddp %st(1), %st
386  fadds 0x1000
387  fiadds 0x1002
388  faddl 0x1004
389  fiaddl 0x1006
391  fmul
392  fmul %st(1), %st
393  fmul %st(3)
395  fmulp %st(5)
396  fmulp
397  fmulp %st(1), %st
399  fmuls 0x1000
400  fimuls 0x1002
401  fmull 0x1004
402  fimull 0x1006
404  fsub
405  fsub %st(1), %st
406  fsub %st(3)
408  fsubp %st(5)
409  fsubp
410  fsubp %st(1), %st
412  fsubs 0x1000
413  fisubs 0x1002
414  fsubl 0x1004
415  fisubl 0x1006
417  fsubr
418  fsubr %st(1), %st
419  fsubr %st(3)
421  fsubrp %st(5)
422  fsubrp
423  fsubrp %st(1), %st
425  fsubrs 0x1000
426  fisubrs 0x1002
427  fsubrl 0x1004
428  fisubrl 0x1006
430  fdiv
431  fdiv %st(1), %st
432  fdiv %st(3)
434  fdivp %st(5)
435  fdivp
436  fdivp %st(1), %st
438  fdivs 0x1000
439  fidivs 0x1002
440  fdivl 0x1004
441  fidivl 0x1006
443  fcom %st(3)
445  fcoms 0x1000
446  ficoms 0x1002
447  fcoml 0x1004
448  ficoml 0x1006
450  fcomp %st(5)
451  fcomp
452  fcompp
454  fcomps 0x1000
455  ficomps 0x1002
456  fcompl 0x1004
457  ficompl 0x1006
459  fld %st(5)
460  fldl 0x1000
461  flds 0x1002
462  fildl 0x1004
463  fst %st(4)
464  fstp %st(6)
465  fstpt 0x1006
466  fbstp 0x1008
468  fxch
469  fxch %st(4)
471  fucom %st(6)
472  fucomp %st(3)
473  fucompp
475  finit
476  fninit
477  fldcw 0x1000
478  fnstcw 0x1002
479  fstcw 0x1002
480  fnstsw 0x1004
481  fnstsw (%eax)
482  fstsw 0x1004
483  fstsw (%eax)
484  fnclex
485  fclex
486  fnstenv 0x1000
487  fstenv 0x1000
488  fldenv 0x1000
489  fnsave 0x1002
490  fsave 0x1000
491  frstor 0x1000
492  ffree %st(7)
493  ffreep %st(6)
495     ftst
496     fxam
497     fld1
498     fldl2t
499     fldl2e
500     fldpi
501     fldlg2
502     fldln2
503     fldz
505     f2xm1
506     fyl2x
507     fptan
508     fpatan
509     fxtract
510     fprem1
511     fdecstp
512     fincstp
513     fprem
514     fyl2xp1
515     fsqrt
516     fsincos
517     frndint
518     fscale
519     fsin
520     fcos
521     fchs
522     fabs
523     fnop
524     fwait
526 bswap %edx
527 bswapl %ecx
528 xadd %ecx, %edx
529 xaddb %dl, 0x1000
530 xaddw %ax, 0x1000
531 xaddl %eax, 0x1000
532 cmpxchg %ecx, %edx
533 cmpxchgb %dl, 0x1000
534 cmpxchgw %ax, 0x1000
535 cmpxchgl %eax, 0x1000
536 invlpg 0x1000
537 cmpxchg8b 0x1002
539 fcmovb %st(5), %st
540 fcmove %st(5), %st
541 fcmovbe %st(5), %st
542 fcmovu %st(5), %st
543 fcmovnb %st(5), %st
544 fcmovne %st(5), %st
545 fcmovnbe %st(5), %st
546 fcmovnu %st(5), %st
547 fcomi %st(5), %st
548 fucomi %st(5), %st
549 fcomip %st(5), %st
550 fucomip %st(5), %st
554  cmovo 0x1000, %eax
555  cmovs 0x1000, %eax
556  cmovns %edx, %edi
557  cmovne %ax, %si
558 #ifdef __x86_64__
559  bswapq %rsi
560  cmovz %rdi,%rbx
561 #endif
563 int $3
564 int $0x10
566 #ifdef __i386__
567     pusha
568     popa
569 #endif
570     clc
571     cld
572     cli
573     clts
574     cmc
575     lahf
576     sahf
577 #ifdef __i386__
578     pushfl
579     popfl
580 #else
581     pushfq
582     popfq
583 #endif
584     pushf
585     popf
586     stc
587     std
588     sti
589 #ifdef __i386__
590     aaa
591     aas
592     daa
593     das
594     aad
595     aam
596     into
597 #endif
598     cbw
599     cwd
600     cwde
601     cdq
602     cbtw
603     cwtd
604     cwtl
605     cltd
606     leave
607     int3
608     iret
609     rsm
610     hlt
611     wait
612     nop
614     /* XXX: handle prefixes */
615 #if 0
616     aword
617     addr16
618 #endif
619     lock
620     rep
621     repe
622     repz
623     repne
624     repnz
625     nop
627     lock ;negl (%eax)
628     wait ;pushf
629     rep  ;stosb
630     repe ;lodsb
631     repz ;cmpsb
632     repne;movsb
633     repnz;outsb
635     /* handle one-line prefix + ops */
636     lock  negl (%eax)
637     wait  pushf
638     rep   stosb
639     repe  lodsb
640     repz  cmpsb
641     repne movsb
642     repnz outsb
643     
644     invd
645     wbinvd
646     cpuid
647     wrmsr
648     rdtsc
649     rdmsr
650     rdpmc
651     ud2
652 #ifdef __x86_64__
653     syscall
654     sysret
655     sysretq
656     lfence
657     mfence
658     sfence
659     prefetchnta 0x18(%rdx)
660     prefetcht0 (%rcx)
661     prefetcht1 (%rsi)
662     prefetcht2 (%rdi)
663     prefetchw (%rdi)
664     clflush 0x1000(%rax,%rcx)
665     fxsaveq (%rdx)
666     fxrstorq (%rcx)
668 #endif
670     lar %ax,%dx
671     lar %eax,%dx
672     lar %ax,%edx
673     lar %eax,%edx
674     lar %ax,%rdx
675     lar %eax,%rdx
676     emms
677     movd %edx, %mm3
678     movd 0x1000, %mm2
679     movd %mm4, %ecx
680     movd %mm5, 0x1000
681                     
682     movq 0x1000, %mm2
683     movq %mm4, 0x1000
684     
685     pand 0x1000, %mm3
686     pand %mm4, %mm5
687     
688     psllw $1, %mm6
689     psllw 0x1000, %mm7
690     psllw %mm2, %mm7
692     xlat
693     cmpsb
694     scmpw
695     insl
696     outsw
697     lodsb
698     slodl
699     movsb
700     movsl
701     smovb
702     scasb
703     sscaw
704     stosw
705     sstol
707     bsf 0x1000, %ebx
708     bsr 0x1000, %ebx
709     bt %edx, 0x1000
710     btl $2, 0x1000
711     btc %edx, 0x1000
712     btcl $2, 0x1000
713     btr %edx, 0x1000
714     btrl $2, 0x1000
715     bts %edx, 0x1000
716     btsl $2, 0x1000
718         
719         
720 #ifdef __i386__
721     boundl %edx, 0x10000
722     boundw %bx, 0x1000
724     arpl %bx, 0x1000
725 #endif
726     lar 0x1000, %eax
727     lgdt 0x1000
728     lidt 0x1000
729     lldt 0x1000
730     sgdt 0x1000
731     sidt 0x1000
732     sldt 0x1000
733 #ifdef __x86_64__
734     lgdtq 0x1000
735     lidtq 0x1000
736     sgdtq 0x1000
737     sidtq 0x1000
739     swapgs
740 #endif
742     lmsw 0x1000
743     lsl 0x1000, %ecx
744     ltr 0x1000
745     ltr %si
746     smsw 0x1000
747     str 0x1000
748     str %ecx
749     str %dx
750     
751     verr 0x1000
752     verw 0x1000
753   
754 #ifdef __i386__
755     push %ds
756     pushw %ds
757     pushl %ds
758     pop %ds
759     popw %ds
760     popl %ds
761 #endif
762     fxsave 1(%ebx)
763     fxrstor 1(%ecx)
764 #ifdef __i386__
765     pushl $1
766 #else
767     pushq $1
768 #endif
769     pushw $1
770     push $1
772 #ifdef __ASSEMBLER__ // should be defined, for S files
773     inc %eax
774 #endif
776 #ifndef _WIN32
777 ft1: ft2: ft3: ft4: ft5: ft6: ft7: ft8: ft9:
778     xor %eax, %eax
779     ret
781 .type ft1,STT_FUNC
782 .type ft2,@STT_FUNC
783 .type ft3,%STT_FUNC
784 .type ft4,"STT_FUNC"
785 .type ft5,function
786 .type ft6,@function
787 .type ft7,%function
788 .type ft8,"function"
789 #endif
791     pause
792 .rept 6
793     nop
794 .endr
795 .fill 4,1,0x90
797 .section .text.one,"ax"
799 .previous
800 .pushsection .text.one,"ax"
802 .pushsection .text.two,"ax"
804 .popsection
805 .popsection
807 1: ud2
808 .pushsection __bug_table,"a"
809 .align 8
810 2: .long 1b - 2b
811    .long 0x600000 - 2b
812    .long 1b + 42
813    .long 43 + 1b
814    .long 2b + 144
815    .long 145 + 2b
816    .word 164, 0
817    .org 2b+32
818    .quad 1b
819 .popsection
820 3: mov %eax,%ecx
822 .pushsection .text.three, "ax"
824 .skip (-((4b-3b) > 0) * 2) , 0x90
825 .popsection
827 .globl overrideme
828 .weak overrideme
829   nop
830 .globl notimplemented
831 notimplemented:
832   ret
833 .set overrideme, notimplemented
834 overrideme = notimplemented
835 overrideme:
836   ret
838     movd %esi, %mm1
839     movd %edi, %xmm2
840     movd (%ebx), %mm3
841     movd (%ebx), %xmm3
842     movd %mm1, %esi
843     movd %xmm2, %edi
844     movd %mm3, (%edx)
845     movd %xmm3, (%edx)
846 #ifdef __x86_64__
847     movd %rsi, %mm1
848     movd %rdi, %xmm2
849     movd (%rbx), %mm3
850     movd (%rbx), %xmm3
851     movd %mm1, %r12
852     movd %xmm2, %rdi
853     movd %mm3, (%r8)
854     movd %xmm3, (%r13)
855 #endif
857     movq (%ebp), %mm1
858     movq %mm2, (%edi)
859     movq (%edi), %xmm3
860     movq %mm4, %mm5
861 #ifdef __x86_64__
862     movq %rcx, %mm1
863     movq %rdx, %xmm2
864     /* movq mem64->xmm is encoded as f30f7e by GAS, but as
865        660f6e by tcc (which really is a movd and would need 
866        a REX.W prefix to be movq).  */
867     movq (%rsi), %xmm3
868     movq %mm1, %rdx
869     movq %xmm3, %rcx
870     movq %xmm4, (%rsi)
871 #endif
873 #define TEST_MMX_SSE(insn) \
874     insn %mm1, %mm2; \
875     insn %xmm2, %xmm3; \
876     insn (%ebx), %xmm3;
877 #define TEST_MMX_SSE_I8(insn) \
878     TEST_MMX_SSE(insn) \
879     insn $0x42, %mm4; \
880     insn $0x42, %xmm4;
882     TEST_MMX_SSE(packssdw)
883     TEST_MMX_SSE(packsswb)
884     TEST_MMX_SSE(packuswb)
885     TEST_MMX_SSE(paddb)
886     TEST_MMX_SSE(paddw)
887     TEST_MMX_SSE(paddd)
888     TEST_MMX_SSE(paddsb)
889     TEST_MMX_SSE(paddsw)
890     TEST_MMX_SSE(paddusb)
891     TEST_MMX_SSE(paddusw)
892     TEST_MMX_SSE(pand)
893     TEST_MMX_SSE(pandn)
894     TEST_MMX_SSE(pcmpeqb)
895     TEST_MMX_SSE(pcmpeqw)
896     TEST_MMX_SSE(pcmpeqd)
897     TEST_MMX_SSE(pcmpgtb)
898     TEST_MMX_SSE(pcmpgtw)
899     TEST_MMX_SSE(pcmpgtd)
900     TEST_MMX_SSE(pmaddwd)
901     TEST_MMX_SSE(pmulhw)
902     TEST_MMX_SSE(pmullw)
903     TEST_MMX_SSE(por)
904     TEST_MMX_SSE(psllw)
905 TEST_MMX_SSE_I8(psllw)
906     TEST_MMX_SSE(pslld)
907 TEST_MMX_SSE_I8(pslld)
908     TEST_MMX_SSE(psllq)
909 TEST_MMX_SSE_I8(psllq)
910     TEST_MMX_SSE(psraw)
911 TEST_MMX_SSE_I8(psraw)
912     TEST_MMX_SSE(psrad)
913 TEST_MMX_SSE_I8(psrad)
914     TEST_MMX_SSE(psrlw)
915 TEST_MMX_SSE_I8(psrlw)
916     TEST_MMX_SSE(psrld)
917 TEST_MMX_SSE_I8(psrld)
918     TEST_MMX_SSE(psrlq)
919 TEST_MMX_SSE_I8(psrlq)
920     TEST_MMX_SSE(psubb)
921     TEST_MMX_SSE(psubw)
922     TEST_MMX_SSE(psubd)
923     TEST_MMX_SSE(psubsb)
924     TEST_MMX_SSE(psubsw)
925     TEST_MMX_SSE(psubusb)
926     TEST_MMX_SSE(psubusw)
927     TEST_MMX_SSE(punpckhbw)
928     TEST_MMX_SSE(punpckhwd)
929     TEST_MMX_SSE(punpckhdq)
930     TEST_MMX_SSE(punpcklbw)
931     TEST_MMX_SSE(punpcklwd)
932     TEST_MMX_SSE(punpckldq)
933     TEST_MMX_SSE(pxor)
935     cvtpi2ps %mm1, %xmm2
936     cvtpi2ps (%ebx), %xmm2
937     TEST_MMX_SSE(pmaxsw)
938     TEST_MMX_SSE(pmaxub)
939     TEST_MMX_SSE(pminsw)
940     TEST_MMX_SSE(pminub)