History

windows style fastcall (Filip Navara)

bellard committed 21 years ago

Commit e9c64e31 parent 81f957a2 files · +25 −4Browse files

Unified · Split

2 files
  1. i386-gen.c +19 −4
  2. tcc.c +6 −0
i386-gen.c+19−4
@@ -321,6 +321,7 @@ static void gcall_or_jmp(int is_jmp) · 320 unmodified lines
321}321}
322 322
323static uint8_t fastcall_regs[3] = { TREG_EAX, TREG_EDX, TREG_ECX };323static uint8_t fastcall_regs[3] = { TREG_EAX, TREG_EDX, TREG_ECX };
324static uint8_t fastcallw_regs[2] = { TREG_ECX, TREG_EDX };
324 325
325/* Generate function call. The function address is pushed first, then326/* Generate function call. The function address is pushed first, then
326 all the parameters in call order. This functions pops all the327 all the parameters in call order. This functions pops all the
@@ -381,13 +382,21 @@ void gfunc_call(int nb_args) · 54 unmodified lines
381 func_sym = vtop->type.ref;382 func_sym = vtop->type.ref;
382 func_call = func_sym->r;383 func_call = func_sym->r;
383 /* fast call case */384 /* fast call case */
384 if (func_call >= FUNC_FASTCALL1 && func_call <= FUNC_FASTCALL3) {385 if ((func_call >= FUNC_FASTCALL1 && func_call <= FUNC_FASTCALL3) ||
386 func_call == FUNC_FASTCALLW) {
385 int fastcall_nb_regs;387 int fastcall_nb_regs;
386 fastcall_nb_regs = func_call - FUNC_FASTCALL1 + 1;388 uint8_t *fastcall_regs_ptr;
389 if (func_call == FUNC_FASTCALLW) {
390 fastcall_regs_ptr = fastcallw_regs;
391 fastcall_nb_regs = 2;
392 } else {
393 fastcall_regs_ptr = fastcall_regs;
394 fastcall_nb_regs = func_call - FUNC_FASTCALL1 + 1;
395 }
387 for(i = 0;i < fastcall_nb_regs; i++) {396 for(i = 0;i < fastcall_nb_regs; i++) {
388 if (args_size <= 0)397 if (args_size <= 0)
389 break;398 break;
390 o(0x58 + fastcall_regs[i]); /* pop r */399 o(0x58 + fastcall_regs_ptr[i]); /* pop r */
391 /* XXX: incorrect for struct/floats */400 /* XXX: incorrect for struct/floats */
392 args_size -= 4;401 args_size -= 4;
393 }402 }
@@ -409,6 +418,7 @@ void gfunc_prolog(CType *func_type) · 15 unmodified lines
409{418{
410 int addr, align, size, func_call, fastcall_nb_regs;419 int addr, align, size, func_call, fastcall_nb_regs;
411 int param_index, param_addr;420 int param_index, param_addr;
421 uint8_t *fastcall_regs_ptr;
412 Sym *sym;422 Sym *sym;
413 CType *type;423 CType *type;
414 424
@@ -418,8 +428,13 @@ void gfunc_prolog(CType *func_type) · 3 unmodified lines
418 loc = 0;428 loc = 0;
419 if (func_call >= FUNC_FASTCALL1 && func_call <= FUNC_FASTCALL3) {429 if (func_call >= FUNC_FASTCALL1 && func_call <= FUNC_FASTCALL3) {
420 fastcall_nb_regs = func_call - FUNC_FASTCALL1 + 1;430 fastcall_nb_regs = func_call - FUNC_FASTCALL1 + 1;
431 fastcall_regs_ptr = fastcall_regs;
432 } else if (func_call == FUNC_FASTCALLW) {
433 fastcall_nb_regs = 2;
434 fastcall_regs_ptr = fastcallw_regs;
421 } else {435 } else {
422 fastcall_nb_regs = 0;436 fastcall_nb_regs = 0;
437 fastcall_regs_ptr = NULL;
423 }438 }
424 param_index = 0;439 param_index = 0;
425 440
@@ -449,7 +464,7 @@ void gfunc_prolog(CType *func_type) · 23 unmodified lines
449 /* save FASTCALL register */464 /* save FASTCALL register */
450 loc -= 4;465 loc -= 4;
451 o(0x89); /* movl */466 o(0x89); /* movl */
452 gen_modrm(fastcall_regs[param_index], VT_LOCAL, NULL, loc);467 gen_modrm(fastcall_regs_ptr[param_index], VT_LOCAL, NULL, loc);
453 param_addr = loc;468 param_addr = loc;
454 } else {469 } else {
455 param_addr = addr;470 param_addr = addr;
tcc.c+6−0
@@ -249,6 +249,7 @@ typedef struct AttributeDef { · 248 unmodified lines
249#define FUNC_FASTCALL1 2 /* first param in %eax */249#define FUNC_FASTCALL1 2 /* first param in %eax */
250#define FUNC_FASTCALL2 3 /* first parameters in %eax, %edx */250#define FUNC_FASTCALL2 3 /* first parameters in %eax, %edx */
251#define FUNC_FASTCALL3 4 /* first parameter in %eax, %edx, %ecx */251#define FUNC_FASTCALL3 4 /* first parameter in %eax, %edx, %ecx */
252#define FUNC_FASTCALLW 5 /* first parameter in %ecx, %edx */
252 253
253/* field 'Sym.t' for macros */254/* field 'Sym.t' for macros */
254#define MACRO_OBJ 0 /* object like macro */255#define MACRO_OBJ 0 /* object like macro */
@@ -6428,6 +6429,11 @@ static void parse_attribute(AttributeDef *ad) · 6173 unmodified lines
6428 ad->func_call = FUNC_FASTCALL1 + n - 1;6429 ad->func_call = FUNC_FASTCALL1 + n - 1;
6429 skip(')');6430 skip(')');
6430 break;6431 break;
6432 case TOK_FASTCALL1:
6433 case TOK_FASTCALL2:
6434 case TOK_FASTCALL3:
6435 ad->func_call = FUNC_FASTCALLW;
6436 break;
6431#endif6437#endif
6432 case TOK_DLLEXPORT:6438 case TOK_DLLEXPORT:
6433 ad->dllexport = 1;6439 ad->dllexport = 1;

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