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
321321 }
322322
323323 static uint8_t fastcall_regs[3] = { TREG_EAX, TREG_EDX, TREG_ECX };
324+static uint8_t fastcallw_regs[2] = { TREG_ECX, TREG_EDX };
324325
325326 /* Generate function call. The function address is pushed first, then
326327 all the parameters in call order. This functions pops all the
@@ -381,13 +382,21 @@ void gfunc_call(int nb_args) · 54 unmodified lines
381382 func_sym = vtop->type.ref;
382383 func_call = func_sym->r;
383384 /* 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) {
385387 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+ }
387396 for(i = 0;i < fastcall_nb_regs; i++) {
388397 if (args_size <= 0)
389398 break;
390− o(0x58 + fastcall_regs[i]); /* pop r */
399+ o(0x58 + fastcall_regs_ptr[i]); /* pop r */
391400 /* XXX: incorrect for struct/floats */
392401 args_size -= 4;
393402 }
@@ -409,6 +418,7 @@ void gfunc_prolog(CType *func_type) · 15 unmodified lines
409418 {
410419 int addr, align, size, func_call, fastcall_nb_regs;
411420 int param_index, param_addr;
421+ uint8_t *fastcall_regs_ptr;
412422 Sym *sym;
413423 CType *type;
414424
@@ -418,8 +428,13 @@ void gfunc_prolog(CType *func_type) · 3 unmodified lines
418428 loc = 0;
419429 if (func_call >= FUNC_FASTCALL1 && func_call <= FUNC_FASTCALL3) {
420430 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;
421435 } else {
422436 fastcall_nb_regs = 0;
437+ fastcall_regs_ptr = NULL;
423438 }
424439 param_index = 0;
425440
@@ -449,7 +464,7 @@ void gfunc_prolog(CType *func_type) · 23 unmodified lines
449464 /* save FASTCALL register */
450465 loc -= 4;
451466 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);
453468 param_addr = loc;
454469 } else {
455470 param_addr = addr;
tcc.c+6−0
@@ -249,6 +249,7 @@ typedef struct AttributeDef { · 248 unmodified lines
249249 #define FUNC_FASTCALL1 2 /* first param in %eax */
250250 #define FUNC_FASTCALL2 3 /* first parameters in %eax, %edx */
251251 #define FUNC_FASTCALL3 4 /* first parameter in %eax, %edx, %ecx */
252+#define FUNC_FASTCALLW 5 /* first parameter in %ecx, %edx */
252253
253254 /* field 'Sym.t' for macros */
254255 #define MACRO_OBJ 0 /* object like macro */
@@ -6428,6 +6429,11 @@ static void parse_attribute(AttributeDef *ad) · 6173 unmodified lines
64286429 ad->func_call = FUNC_FASTCALL1 + n - 1;
64296430 skip(')');
64306431 break;
6432+ case TOK_FASTCALL1:
6433+ case TOK_FASTCALL2:
6434+ case TOK_FASTCALL3:
6435+ ad->func_call = FUNC_FASTCALLW;
6436+ break;
64316437 #endif
64326438 case TOK_DLLEXPORT:
64336439 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