Index: EcnlProtoTool/trunk/tcc-0.9.27/tests/asmtest.S
===================================================================
--- EcnlProtoTool/trunk/tcc-0.9.26/tests/asmtest.S	(revision 279)
+++ EcnlProtoTool/trunk/tcc-0.9.27/tests/asmtest.S	(revision 331)
@@ -12,12 +12,20 @@
    .byte 1
 /* .align 16, 0x90 gas is too clever for us with 0x90 fill */
+   .balign 4, 0x92
    .align 16, 0x91 /* 0x91 tests the non-clever behaviour */
    .skip 3
    .skip 15, 0x90
    .string "hello\0world"
-
+/* Macro expansion should work like with C, the #n shouldn't be parsed
+   as asm line comment */
+#define __stringify(n) #n
+#define stringify(n) __stringify(n)
+   .skip 8,0x90
+   .asciz stringify(BLA)
+   .skip 8,0x90
+
+# 28 "asmtest.S"        # a line directive (and a line comment)
+        movl %eax, %ebx # some more asm comment
 /* some label tests */
-
-        movl %eax, %ebx
 L1:
         movl %eax, %ebx
@@ -39,5 +47,5 @@
 mov $1, %edx
 mov $1, %dx
-mov $1, %dl
+mov $1, %cl
 movb $2, 0x100(%ebx,%edx,2)
 movw $2, 0x100(%ebx,%edx,2)
@@ -47,6 +55,19 @@
 movw %ax, 0x100(%ebx,%edx,2)
 
+movw $0x1122,%si
+movl $0x112233,%edx
+movl $0x80000000, %esi
+movl $-0x7fffffff, %edi
+#ifdef __x86_64__
+mov $0x11223344,%rbx
+movq $0x11223344,%rbx
+mov $0x1122334455,%rbx
+movq $0x1122334455,%rbx
+movl $0x11334455,(%rbx)
+#endif
+
 mov %eax, 0x12(,%edx,2)
         
+#ifdef __i386__
 mov %cr3, %edx
 mov %ecx, %cr3
@@ -55,6 +76,31 @@
 movl %db3, %ebx
 movl %dr6, %eax
+#else
+mov %cr3, %rdx
+mov %rcx, %cr3
+movq %cr3, %rax
+movq %db3, %rbx
+movq %dr6, %rax
+mov %cr8, %rsi
+mov %rdi, %cr8
+#endif
 movl %fs, %ecx
 movl %ebx, %fs
+
+#ifdef __x86_64__
+movq %r8, %r9
+movq %r10, %r11
+movq %r12, %r13
+movq %r14, %r15
+movq %rax, %r9
+movq %r15, %rsi
+inc %r9b
+dec %r10w
+not %r11d
+negq %r12
+decb %r13b
+incw %r14w
+notl %r15d
+#endif
 
      movsbl 0x1000, %eax
@@ -69,17 +115,45 @@
      movzb 0x1000, %ax
                 
+     mov $0x12345678,%eax
+
+#ifdef __x86_64__
+     movzb 0x1000, %rax
+     movzbq 0x1000, %rbx
+     movsbq 0x1000, %rdx
+     movzwq 0x1000, %rdi
+     movswq 0x1000, %rdx
+     movslq %eax, %rcx
+     mov $0x12345678,%rax
+     mov $0x12345678,%rdx
+     mov $0x12345678,%r10
+     mov $0x123456789abcdef0,%rax
+     mov $0x123456789abcdef0,%rcx
+     mov $0x123456789abcdef0,%r11
+#endif
         
+#ifdef __i386__
   pushl %eax
-  pushw %ax
   push %eax
   push %cs
+#else
+  pushq %rax
+  push %rax
+#endif
+  pushw %ax
   push %gs
   push $1
   push $100
+  push 0x42(%eax)
+  pop 0x43(%esi)
                                                 
+#ifdef __i386__
   popl %eax
-  popw %ax
   pop %eax
   pop %ds
+#else
+  popq %rax
+  pop %rax
+#endif
+  popw %ax
   pop %fs
           
@@ -112,12 +186,32 @@
   lea 0x1000(%ebx), %ecx
 
+#ifdef __i386__
   les 0x2000, %eax
   lds 0x2000, %ebx
+  lss 0x2000, %edx
+#endif
   lfs 0x2000, %ecx
   lgs 0x2000, %edx
-  lss 0x2000, %edx
 
 addl $0x123, %eax
 add $0x123, %ebx
+add $-16, %ecx
+add $-0x123, %esi
+add $1, %bx
+add $1, %ebx
+add $-1, %bx
+add $-1, %ebx
+add $127, %bx
+addl $127, %ebx
+addl $-128, %ebx
+addl $-128, %ebx
+addl $-129, %ebx
+addl $128, %ebx
+addl $255, %ebx
+addl $256, %ebx
+andb $0xf, %ah
+andb $-15, %cl
+xorb $127, %dh
+cmpb $42, (%eax)
 addl $0x123, 0x100
 addl $0x123, 0x100(%ebx)
@@ -128,4 +222,22 @@
 addl $0x123, (%esp)
 cmpl $0x123, (%esp)
+
+#ifdef __x86_64__
+xor %bl,%ah
+xor %bl,%r8b
+xor %r9b,%bl
+xor %sil,%cl
+add %eax,(%r8d)
+add %ebx,(%r9)
+add %edx,(%r10d,%r11d)
+add %ecx,(%r12,%r13)
+add %esi,(%r14,%r15,4)
+add %edi,0x1000(%rbx,%r12,8)
+add %r11,0x1000(%ebp,%r9d,8)
+movb $12, %ah
+movb $13, %bpl
+movb $14, %dil
+movb $15, %r12b
+#endif
 
 add %eax, (%ebx)
@@ -180,4 +292,6 @@
     div %ecx, %eax
 
+and $15,%bx
+and $-20,%edx
 
 shl %edx
@@ -196,5 +310,9 @@
 call 0x1000
 call L4
+#ifdef __i386__
 call *%eax
+#else
+call *%rax
+#endif
 call *0x1000
 call func1
@@ -205,17 +323,38 @@
 L6:
 
+#ifdef __i386__
 lcall $0x100, $0x1000
+#else
+lcall *0x100
+lcall *(%rax)
+#endif
 
 jmp 0x1000
+jmp *(%edi)
+#ifdef __i386__
 jmp *%eax
+#else
+jmp *%rax
+#endif
 jmp *0x1000
 
+#ifdef __i386__
 ljmp $0x100, $0x1000
+#else
+ljmp *0x100
+ljmp *(%rdi)
+ljmpl *(%esi)
+ljmpw *(%esi)
+#endif
 
 ret
+ret $10
+#ifdef __i386__
 retl
-
-ret $10
 retl $10
+#else
+retq
+retq $10
+#endif
 
 lret
@@ -245,4 +384,6 @@
         
  seto %al
+ setc %al
+ setcb %al
  setnp 0x1000
  setl 0xaaaa
@@ -402,4 +543,5 @@
 
 bswap %edx
+bswapl %ecx
 xadd %ecx, %edx
 xaddb %dl, 0x1000
@@ -412,4 +554,8 @@
 invlpg 0x1000
 cmpxchg8b 0x1002
+#ifdef __x86_64__
+cmpxchg16b (%rax)
+cmpxchg16b (%r10,%r11)
+#endif
 
 fcmovb %st(5), %st
@@ -431,12 +577,23 @@
  cmovs 0x1000, %eax
  cmovns %edx, %edi
+ cmovne %ax, %si
+ cmovbw %ax, %di
+ cmovnbel %edx, %ecx
+#ifdef __x86_64__
+ bswapq %rsi
+ bswapq %r10
+ cmovz %rdi,%rbx
+ cmovpeq %rsi, %rdx
+#endif
 
 int $3
 int $0x10
 
+#ifdef __i386__
     pusha
     popa
-    clc
-    cld
+#endif
+    clc # another comment
+    cld # a comment with embedded ' tick
     cli
     clts
@@ -444,6 +601,11 @@
     lahf
     sahf
+#ifdef __i386__
     pushfl
     popfl
+#else
+    pushfq
+    popfq
+#endif
     pushf
     popf
@@ -451,4 +613,5 @@
     std
     sti
+#ifdef __i386__
     aaa
     aas
@@ -457,4 +620,6 @@
     aad
     aam
+    into
+#endif
     cbw
     cwd
@@ -467,5 +632,4 @@
     leave
     int3
-    into
     iret
     rsm
@@ -512,5 +676,32 @@
     rdpmc
     ud2
-
+#ifdef __x86_64__
+    syscall
+    sysret
+    sysretq
+    lfence
+    mfence
+    sfence
+    prefetchnta 0x18(%rdx)
+    prefetcht0 (%rcx)
+    prefetcht1 (%rsi)
+    prefetcht2 (%rdi)
+    prefetchw (%rdi)
+    clflush 0x1000(%rax,%rcx)
+    fxsaveq (%rdx)
+    fxsaveq (%r11)
+    fxrstorq (%rcx)
+    fxrstorq (%r10)
+
+#endif
+
+    lar %ax,%dx
+    lar %eax,%dx
+    lar %ax,%edx
+    lar %eax,%edx
+#ifdef __x86_64__
+    lar %ax,%rdx
+    lar %eax,%rdx
+#endif
     emms
     movd %edx, %mm3
@@ -557,25 +748,42 @@
         
         
+#ifdef __i386__
     boundl %edx, 0x10000
     boundw %bx, 0x1000
-    
+
     arpl %bx, 0x1000
+#endif
     lar 0x1000, %eax
     lgdt 0x1000
     lidt 0x1000
     lldt 0x1000
+    sgdt 0x1000
+    sidt 0x1000
+    sldt 0x1000
+#ifdef __x86_64__
+    lgdtq 0x1000
+    lidtq 0x1000
+    sgdtq 0x1000
+    sidtq 0x1000
+
+    swapgs
+
+    str %rdx
+    str %r9
+#endif
+
     lmsw 0x1000
     lsl 0x1000, %ecx
     ltr 0x1000
-    
-    sgdt 0x1000
-    sidt 0x1000
-    sldt 0x1000
+    ltr %si
     smsw 0x1000
     str 0x1000
+    str %ecx
+    str %dx
     
     verr 0x1000
     verw 0x1000
   
+#ifdef __i386__
     push %ds
     pushw %ds
@@ -584,7 +792,12 @@
     popw %ds
     popl %ds
+#endif
     fxsave 1(%ebx)
     fxrstor 1(%ecx)
+#ifdef __i386__
     pushl $1
+#else
+    pushq $1
+#endif
     pushw $1
     push $1
@@ -594,4 +807,5 @@
 #endif
 
+#ifndef _WIN32
 ft1: ft2: ft3: ft4: ft5: ft6: ft7: ft8: ft9:
     xor %eax, %eax
@@ -606,4 +820,159 @@
 .type ft7,%function
 .type ft8,"function"
+#endif
 
     pause
+.rept 6
+    nop
+.endr
+.fill 4,1,0x90
+
+.section .text.one,"ax"
+nop
+.previous
+.pushsection .text.one,"ax"
+nop
+.pushsection .text.two,"ax"
+nop
+.popsection
+.popsection
+
+1: ud2
+.pushsection __bug_table,"a"
+.align 8
+2: .long 1b - 2b
+   .long 0x600000 - 2b
+   .long 1b + 42
+   .long 43 + 1b
+   .long 2b + 144
+   .long 145 + 2b
+   .word 164, 0
+   .org 2b+32
+#ifdef __x86_64__
+   .quad 1b
+#else
+   .long 1b
+#endif
+.popsection
+3: mov %eax,%ecx
+4:
+.pushsection .text.three, "ax"
+nop
+.skip (-((4b-3b) > 0) * 2) , 0x90
+.popsection
+
+.globl overrideme
+.weak overrideme
+  nop
+.globl notimplemented
+notimplemented:
+  ret
+.set overrideme, notimplemented
+overrideme = notimplemented
+overrideme:
+  ret
+
+    movd %esi, %mm1
+    movd %edi, %xmm2
+    movd (%ebx), %mm3
+    movd (%ebx), %xmm3
+    movd %mm1, %esi
+    movd %xmm2, %edi
+    movd %mm3, (%edx)
+    movd %xmm3, (%edx)
+#ifdef __x86_64__
+    movd %rsi, %mm1
+    movd %rdi, %xmm2
+    movd (%rbx), %mm3
+    movd (%rbx), %xmm3
+    movd %mm1, %r12
+    movd %xmm2, %rdi
+    movd %mm3, (%r8)
+    movd %xmm3, (%r13)
+#endif
+
+    movq (%ebp), %mm1
+    movq %mm2, (%edi)
+    movq (%edi), %xmm3
+    movq %mm4, %mm5
+#ifdef __x86_64__
+    movq %rcx, %mm1
+    movq %rdx, %xmm2
+    movq %r13, %xmm3
+    /* movq mem64->xmm is encoded as f30f7e by GAS, but as
+       660f6e by tcc (which really is a movd and would need 
+       a REX.W prefix to be movq).  */
+    movq (%rsi), %xmm3
+    movq %mm1, %rdx
+    movq %xmm3, %rcx
+    movq %xmm4, (%rsi)
+#endif
+
+#define TEST_MMX_SSE(insn) \
+    insn %mm1, %mm2; \
+    insn %xmm2, %xmm3; \
+    insn (%ebx), %xmm3;
+#define TEST_MMX_SSE_I8(insn) \
+    TEST_MMX_SSE(insn) \
+    insn $0x42, %mm4; \
+    insn $0x42, %xmm4;
+
+    TEST_MMX_SSE(packssdw)
+    TEST_MMX_SSE(packsswb)
+    TEST_MMX_SSE(packuswb)
+    TEST_MMX_SSE(paddb)
+    TEST_MMX_SSE(paddw)
+    TEST_MMX_SSE(paddd)
+    TEST_MMX_SSE(paddsb)
+    TEST_MMX_SSE(paddsw)
+    TEST_MMX_SSE(paddusb)
+    TEST_MMX_SSE(paddusw)
+    TEST_MMX_SSE(pand)
+    TEST_MMX_SSE(pandn)
+    TEST_MMX_SSE(pcmpeqb)
+    TEST_MMX_SSE(pcmpeqw)
+    TEST_MMX_SSE(pcmpeqd)
+    TEST_MMX_SSE(pcmpgtb)
+    TEST_MMX_SSE(pcmpgtw)
+    TEST_MMX_SSE(pcmpgtd)
+    TEST_MMX_SSE(pmaddwd)
+    TEST_MMX_SSE(pmulhw)
+    TEST_MMX_SSE(pmullw)
+    TEST_MMX_SSE(por)
+    TEST_MMX_SSE(psllw)
+TEST_MMX_SSE_I8(psllw)
+    TEST_MMX_SSE(pslld)
+TEST_MMX_SSE_I8(pslld)
+    TEST_MMX_SSE(psllq)
+TEST_MMX_SSE_I8(psllq)
+    TEST_MMX_SSE(psraw)
+TEST_MMX_SSE_I8(psraw)
+    TEST_MMX_SSE(psrad)
+TEST_MMX_SSE_I8(psrad)
+    TEST_MMX_SSE(psrlw)
+TEST_MMX_SSE_I8(psrlw)
+    TEST_MMX_SSE(psrld)
+TEST_MMX_SSE_I8(psrld)
+    TEST_MMX_SSE(psrlq)
+TEST_MMX_SSE_I8(psrlq)
+    TEST_MMX_SSE(psubb)
+    TEST_MMX_SSE(psubw)
+    TEST_MMX_SSE(psubd)
+    TEST_MMX_SSE(psubsb)
+    TEST_MMX_SSE(psubsw)
+    TEST_MMX_SSE(psubusb)
+    TEST_MMX_SSE(psubusw)
+    TEST_MMX_SSE(punpckhbw)
+    TEST_MMX_SSE(punpckhwd)
+    TEST_MMX_SSE(punpckhdq)
+    TEST_MMX_SSE(punpcklbw)
+    TEST_MMX_SSE(punpcklwd)
+    TEST_MMX_SSE(punpckldq)
+    TEST_MMX_SSE(pxor)
+
+    cvtpi2ps %mm1, %xmm2
+    cvtpi2ps (%ebx), %xmm2
+    TEST_MMX_SSE(pmaxsw)
+    TEST_MMX_SSE(pmaxub)
+    TEST_MMX_SSE(pminsw)
+    TEST_MMX_SSE(pminub)
