History

primitive fastcall functions support

bellard committed 22 years ago

Commit 72a88fb1 parent 4d9f6d21 file · +46 −9Browse files

Unified · Split

i386-gen.c+46−9
@@ -320,12 +320,14 @@ static void gcall_or_jmp(int is_jmp) · 319 unmodified lines
320320 }
321321 }
322322
323+static uint8_t fastcall_regs[3] = { TREG_EAX, TREG_EDX, TREG_ECX };
324+
323325 /* Generate function call. The function address is pushed first, then
324326 all the parameters in call order. This functions pops all the
325327 parameters and the function address. */
326328 void gfunc_call(int nb_args)
327329 {
328− int size, align, r, args_size, i;
330+ int size, align, r, args_size, i, func_call;
329331 Sym *func_sym;
330332
331333 args_size = 0;
@@ -377,8 +379,21 @@ void gfunc_call(int nb_args) · 45 unmodified lines
377379 }
378380 save_regs(0); /* save used temporary registers */
379381 func_sym = vtop->type.ref;
382+ func_call = func_sym->r;
383+ /* fast call case */
384+ if (func_call >= FUNC_FASTCALL1 && func_call <= FUNC_FASTCALL3) {
385+ int fastcall_nb_regs;
386+ fastcall_nb_regs = func_call - FUNC_FASTCALL1 + 1;
387+ for(i = 0;i < fastcall_nb_regs; i++) {
388+ if (args_size <= 0)
389+ break;
390+ o(0x58 + fastcall_regs[i]); /* pop r */
391+ /* XXX: incorrect for struct/floats */
392+ args_size -= 4;
393+ }
394+ }
380395 gcall_or_jmp(0);
381− if (args_size && func_sym->r == FUNC_CDECL)
396+ if (args_size && func_sym->r != FUNC_STDCALL)
382397 gadd_sp(args_size);
383398 vtop--;
384399 }
@@ -386,25 +401,37 @@ void gfunc_call(int nb_args) · 1 unmodified line
386401 /* generate function prolog of type 't' */
387402 void gfunc_prolog(CType *func_type)
388403 {
389− int addr, align, size, func_call;
404+ int addr, align, size, func_call, fastcall_nb_regs;
405+ int param_index, param_addr;
390406 Sym *sym;
391407 CType *type;
392408
393409 sym = func_type->ref;
394410 func_call = sym->r;
395411 addr = 8;
412+ loc = 0;
413+ if (func_call >= FUNC_FASTCALL1 && func_call <= FUNC_FASTCALL3) {
414+ fastcall_nb_regs = func_call - FUNC_FASTCALL1 + 1;
415+ } else {
416+ fastcall_nb_regs = 0;
417+ }
418+ param_index = 0;
419+
420+ o(0xe58955); /* push %ebp, mov %esp, %ebp */
421+ func_sub_sp_offset = oad(0xec81, 0); /* sub $xxx, %esp */
422+
396423 /* if the function returns a structure, then add an
397424 implicit pointer parameter */
398425 func_vt = sym->type;
399426 if ((func_vt.t & VT_BTYPE) == VT_STRUCT) {
427+ /* XXX: fastcall case ? */
400428 func_vc = addr;
401429 addr += 4;
430+ param_index++;
402431 }
403432 /* define parameters */
404433 while ((sym = sym->next) != NULL) {
405434 type = &sym->type;
406− sym_push(sym->v & ~SYM_FIELD, type,
407− VT_LOCAL | VT_LVAL, addr);
408435 size = type_size(type, &align);
409436 size = (size + 3) & ~3;
410437 #ifdef FUNC_STRUCT_PARAM_AS_PTR
@@ -413,21 +440,31 @@ void gfunc_prolog(CType *func_type) · 2 unmodified lines
413440 size = 4;
414441 }
415442 #endif
416− addr += size;
443+ if (param_index < fastcall_nb_regs) {
444+ /* save FASTCALL register */
445+ loc -= 4;
446+ o(0x89); /* movl */
447+ gen_modrm(fastcall_regs[param_index], VT_LOCAL, NULL, loc);
448+ param_addr = loc;
449+ } else {
450+ param_addr = addr;
451+ addr += size;
452+ }
453+ sym_push(sym->v & ~SYM_FIELD, type,
454+ VT_LOCAL | VT_LVAL, param_addr);
455+ param_index++;
417456 }
418457 func_ret_sub = 0;
419458 /* pascal type call ? */
420459 if (func_call == FUNC_STDCALL)
421460 func_ret_sub = addr - 8;
422− o(0xe58955); /* push %ebp, mov %esp, %ebp */
423− func_sub_sp_offset = oad(0xec81, 0); /* sub $xxx, %esp */
461+
424462 /* leave some room for bound checking code */
425463 if (do_bounds_check) {
426464 oad(0xb8, 0); /* lbound section pointer */
427465 oad(0xb8, 0); /* call to function */
428466 func_bound_offset = lbounds_section->data_offset;
429467 }
430− loc = 0;
431468 }
432469
433470 /* generate function epilog */

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