History

x86-64: Run asmtest as well

This fixes and activates the asm test that's part of tcctest.c also on x86-64, requiring a small fix for the 'm' constraint.

Michael Matz committed 10 years ago

Commit f0fa5601 parent 4d688282 files · +31 −13Browse files

Unified · Split

2 files
  1. i386-asm.c +4 −0
  2. tests/tcctest.c +27 −13
i386-asm.c+4−0
@@ -1366,7 +1366,11 @@ ST_FUNC void subst_asm_operand(CString *add_str, · 1365 unmodified lines
13661366 snprintf(buf, sizeof(buf), "%d", (int)sv->c.i);
13671367 cstr_cat(add_str, buf, -1);
13681368 } else if ((r & VT_VALMASK) == VT_LOCAL) {
1369+#ifdef TCC_TARGET_X86_64
1370+ snprintf(buf, sizeof(buf), "%d(%%rbp)", (int)sv->c.i);
1371+#else
13691372 snprintf(buf, sizeof(buf), "%d(%%ebp)", (int)sv->c.i);
1373+#endif
13701374 cstr_cat(add_str, buf, -1);
13711375 } else if (r & VT_LVAL) {
13721376 reg = r & VT_VALMASK;
tests/tcctest.c+27−13
@@ -2411,24 +2411,24 @@ void local_label_test(void) · 2410 unmodified lines
24112411 }
24122412
24132413 /* inline assembler test */
2414−#ifdef __i386__
2414+#if defined(__i386__) || defined(__x86_64__)
24152415
24162416 /* from linux kernel */
24172417 static char * strncat1(char * dest,const char * src,size_t count)
24182418 {
2419−int d0, d1, d2, d3;
2419+long d0, d1, d2, d3;
24202420 __asm__ __volatile__(
24212421 "repne\n\t"
24222422 "scasb\n\t"
2423− "decl %1\n\t"
2424− "movl %8,%3\n"
2425− "1:\tdecl %3\n\t"
2423+ "dec %1\n\t"
2424+ "mov %8,%3\n"
2425+ "1:\tdec %3\n\t"
24262426 "js 2f\n\t"
24272427 "lodsb\n\t"
24282428 "stosb\n\t"
24292429 "testb %%al,%%al\n\t"
24302430 "jne 1b\n"
2431− "2:\txorl %2,%2\n\t"
2431+ "2:\txor %2,%2\n\t"
24322432 "stosb"
24332433 : "=&S" (d0), "=&D" (d1), "=&a" (d2), "=&c" (d3)
24342434 : "0" (src),"1" (dest),"2" (0),"3" (0xffffffff), "g" (count)
@@ -2438,18 +2438,18 @@ return dest; · 3 unmodified lines
24382438
24392439 static char * strncat2(char * dest,const char * src,size_t count)
24402440 {
2441−int d0, d1, d2, d3;
2441+long d0, d1, d2, d3;
24422442 __asm__ __volatile__(
24432443 "repne scasb\n\t" /* one-line repne prefix + string op */
2444− "decl %1\n\t"
2445− "movl %8,%3\n"
2446− "1:\tdecl %3\n\t"
2444+ "dec %1\n\t"
2445+ "mov %8,%3\n"
2446+ "1:\tdec %3\n\t"
24472447 "js 2f\n\t"
24482448 "lodsb\n\t"
24492449 "stosb\n\t"
24502450 "testb %%al,%%al\n\t"
24512451 "jne 1b\n"
2452− "2:\txorl %2,%2\n\t"
2452+ "2:\txor %2,%2\n\t"
24532453 "stosb"
24542454 : "=&S" (d0), "=&D" (d1), "=&a" (d2), "=&c" (d3)
24552455 : "0" (src),"1" (dest),"2" (0),"3" (0xffffffff), "g" (count)
@@ -2459,7 +2459,7 @@ return dest; · 3 unmodified lines
24592459
24602460 static inline void * memcpy1(void * to, const void * from, size_t n)
24612461 {
2462−int d0, d1, d2;
2462+long d0, d1, d2;
24632463 __asm__ __volatile__(
24642464 "rep ; movsl\n\t"
24652465 "testb $2,%b4\n\t"
@@ -2477,7 +2477,7 @@ return (to); · 11 unmodified lines
24772477
24782478 static inline void * memcpy2(void * to, const void * from, size_t n)
24792479 {
2480−int d0, d1, d2;
2480+long d0, d1, d2;
24812481 __asm__ __volatile__(
24822482 "rep movsl\n\t" /* one-line rep prefix + string op */
24832483 "testb $2,%b4\n\t"
@@ -2516,14 +2516,28 @@ static __inline__ __const__ unsigned int swab32(unsigned int x) · 32 unmodified lines
25162516 static __inline__ unsigned long long mul64(unsigned int a, unsigned int b)
25172517 {
25182518 unsigned long long res;
2519+#ifdef __x86_64__
2520+ /* Using the A constraint is wrong (it means rdx:rax, which is too large)
2521+ but still test the 32bit->64bit mull. */
2522+ unsigned int resh, resl;
2523+ __asm__("mull %2" : "=a" (resl), "=d" (resh) : "a" (a), "r" (b));
2524+ res = ((unsigned long long)resh << 32) | resl;
2525+#else
25192526 __asm__("mull %2" : "=A" (res) : "a" (a), "r" (b));
2527+#endif
25202528 return res;
25212529 }
25222530
25232531 static __inline__ unsigned long long inc64(unsigned long long a)
25242532 {
25252533 unsigned long long res;
2534+#ifdef __x86_64__
2535+ /* Using the A constraint is wrong, and increments are tested
2536+ elsewere. */
2537+ res = a + 1;
2538+#else
25262539 __asm__("addl $1, %%eax ; adcl $0, %%edx" : "=A" (res) : "A" (a));
2540+#endif
25272541 return res;
25282542 }
25292543