History

tccasm: allow one-line prefix+op things like "rep stosb"

Joe Soroka committed 15 years ago

Commit 87d84b71 parent a25325e4 files · +68 −2Browse files

Unified · Split

4 files
  1. i386-asm.c +5 −0
  2. i386-asm.h +2 −2
  3. tests/asmtest.S +18 −0
  4. tests/tcctest.c +43 −0
i386-asm.c+5−0
@@ -574,6 +574,11 @@ ST_FUNC void asm_opcode(TCCState *s1, int opcode) · 573 unmodified lines
574574 static int a32 = 0, o32 = 0, addr32 = 0, data32 = 0;
575575 #endif
576576
577+ /* force synthetic ';' after prefix instruction, so we can handle */
578+ /* one-line things like "rep stosb" instead of only "rep\nstosb" */
579+ if (opcode >= TOK_ASM_wait && opcode <= TOK_ASM_repnz)
580+ unget_tok(';');
581+
577582 /* get operands */
578583 pop = ops;
579584 nb_ops = 0;
i386-asm.h+2−2
@@ -33,7 +33,6 @@ · 32 unmodified lines
3333 DEF_ASM_OP0(iret, 0xcf)
3434 DEF_ASM_OP0(rsm, 0x0faa)
3535 DEF_ASM_OP0(hlt, 0xf4)
36− DEF_ASM_OP0(wait, 0x9b)
3736 DEF_ASM_OP0(nop, 0x90)
3837 DEF_ASM_OP0(xlat, 0xd7)
3938
@@ -74,6 +73,8 @@ ALT(DEF_ASM_OP2(btcw, 0x0fbb, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_REGW | OPT_EA · 34 unmodified lines
7473 ALT(DEF_ASM_OP2(btcw, 0x0fba, 7, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW | OPT_EA))
7574
7675 /* prefixes */
76+ DEF_ASM_OP0(wait, 0x9b)
77+ DEF_ASM_OP0(fwait, 0x9b)
7778 #ifdef I386_ASM_16
7879 DEF_ASM_OP0(a32, 0x67)
7980 DEF_ASM_OP0(o32, 0x66)
@@ -282,7 +283,6 @@ ALT(DEF_ASM_OP1(fiadds, 0xde, 0, OPC_FARITH | OPC_MODRM, OPT_EA)) · 202 unmodified lines
282283 DEF_ASM_OP0(fninit, 0xdbe3)
283284 DEF_ASM_OP0(fnclex, 0xdbe2)
284285 DEF_ASM_OP0(fnop, 0xd9d0)
285− DEF_ASM_OP0(fwait, 0x9b)
286286
287287 /* fp load */
288288 DEF_ASM_OP1(fld, 0xd9c0, 0, OPC_REG, OPT_ST)
tests/asmtest.S+18−0
@@ -478,6 +478,24 @@ int $0x10 · 477 unmodified lines
478478 repz
479479 repne
480480 repnz
481+ nop
482+
483+ lock ;negl (%eax)
484+ wait ;pushf
485+ rep ;stosb
486+ repe ;lodsb
487+ repz ;cmpsb
488+ repne;movsb
489+ repnz;outsb
490+
491+ /* handle one-line prefix + ops */
492+ lock negl (%eax)
493+ wait pushf
494+ rep stosb
495+ repe lodsb
496+ repz cmpsb
497+ repne movsb
498+ repnz outsb
481499
482500 invd
483501 wbinvd
tests/tcctest.c+43−0
@@ -2132,6 +2132,27 @@ __asm__ __volatile__( · 2131 unmodified lines
21322132 return dest;
21332133 }
21342134
2135+static char * strncat2(char * dest,const char * src,size_t count)
2136+{
2137+int d0, d1, d2, d3;
2138+__asm__ __volatile__(
2139+ "repne scasb\n\t" /* one-line repne prefix + string op */
2140+ "decl %1\n\t"
2141+ "movl %8,%3\n"
2142+ "1:\tdecl %3\n\t"
2143+ "js 2f\n\t"
2144+ "lodsb\n\t"
2145+ "stosb\n\t"
2146+ "testb %%al,%%al\n\t"
2147+ "jne 1b\n"
2148+ "2:\txorl %2,%2\n\t"
2149+ "stosb"
2150+ : "=&S" (d0), "=&D" (d1), "=&a" (d2), "=&c" (d3)
2151+ : "0" (src),"1" (dest),"2" (0),"3" (0xffffffff), "g" (count)
2152+ : "memory");
2153+return dest;
2154+}
2155+
21352156 static inline void * memcpy1(void * to, const void * from, size_t n)
21362157 {
21372158 int d0, d1, d2;
@@ -2150,6 +2171,24 @@ __asm__ __volatile__( · 12 unmodified lines
21502171 return (to);
21512172 }
21522173
2174+static inline void * memcpy2(void * to, const void * from, size_t n)
2175+{
2176+int d0, d1, d2;
2177+__asm__ __volatile__(
2178+ "rep movsl\n\t" /* one-line rep prefix + string op */
2179+ "testb $2,%b4\n\t"
2180+ "je 1f\n\t"
2181+ "movsw\n"
2182+ "1:\ttestb $1,%b4\n\t"
2183+ "je 2f\n\t"
2184+ "movsb\n"
2185+ "2:"
2186+ : "=&c" (d0), "=&D" (d1), "=&S" (d2)
2187+ :"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from)
2188+ : "memory");
2189+return (to);
2190+}
2191+
21532192 static __inline__ void sigaddset1(unsigned int *set, int _sig)
21542193 {
21552194 __asm__("btsl %1,%0" : "=m"(*set) : "Ir"(_sig - 1) : "cc");
@@ -2199,6 +2238,10 @@ void asm_test(void) · 43 unmodified lines
21992238 strncat1(buf, " worldXXXXX", 3);
22002239 printf("%s\n", buf);
22012240
2241+ memcpy2(buf, "hello", 6);
2242+ strncat2(buf, " worldXXXXX", 3);
2243+ printf("%s\n", buf);
2244+
22022245 /* 'A' constraint test */
22032246 printf("mul64=0x%Lx\n", mul64(0x12345678, 0xabcd1234));
22042247 printf("inc64=0x%Lx\n", inc64(0x12345678ffffffff));

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t