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