Unified · Split
| @@ -207,16 +207,17 @@ void load(int r, SValue *sv) · 206 unmodified lines | |||
| 207 | } else if ((ft & VT_BTYPE) == VT_LDOUBLE) { | 207 | } else if ((ft & VT_BTYPE) == VT_LDOUBLE) { |
| 208 | o(0xdb); /* fldt */ | 208 | o(0xdb); /* fldt */ |
| 209 | r = 5; | 209 | r = 5; |
| 210 | } else if ((ft & VT_TYPE) == VT_BYTE) | 210 | } else if ((ft & VT_TYPE) == VT_BYTE) { |
| 211 | o(0xbe0f); /* movsbl */ | 211 | o(0xbe0f); /* movsbl */ |
| 212 | else if ((ft & VT_TYPE) == (VT_BYTE | VT_UNSIGNED)) | 212 | } else if ((ft & VT_TYPE) == (VT_BYTE | VT_UNSIGNED)) { |
| 213 | o(0xb60f); /* movzbl */ | 213 | o(0xb60f); /* movzbl */ |
| 214 | else if ((ft & VT_TYPE) == VT_SHORT) | 214 | } else if ((ft & VT_TYPE) == VT_SHORT) { |
| 215 | o(0xbf0f); /* movswl */ | 215 | o(0xbf0f); /* movswl */ |
| 216 | else if ((ft & VT_TYPE) == (VT_SHORT | VT_UNSIGNED)) | 216 | } else if ((ft & VT_TYPE) == (VT_SHORT | VT_UNSIGNED)) { |
| 217 | o(0xb70f); /* movzwl */ | 217 | o(0xb70f); /* movzwl */ |
| 218 | else | 218 | } else { |
| 219 | o(0x8b); /* movl */ | 219 | o(0x8b); /* movl */ |
| 220 | } | ||
| 220 | gen_modrm(r, fr, fc); | 221 | gen_modrm(r, fr, fc); |
| 221 | } else { | 222 | } else { |
| 222 | if (v == VT_CONST) { | 223 | if (v == VT_CONST) { |
| @@ -303,7 +304,7 @@ void gfunc_param(GFuncContext *c) · 80 unmodified lines | |||
| 303 | r = get_reg(RC_INT); | 304 | r = get_reg(RC_INT); |
| 304 | o(0x89); /* mov %esp, r */ | 305 | o(0x89); /* mov %esp, r */ |
| 305 | o(0xe0 + r); | 306 | o(0xe0 + r); |
| 306 | vset(VT_INT, r, 0); | 307 | vset(vtop->t, r | VT_LVAL, 0); |
| 307 | vswap(); | 308 | vswap(); |
| 308 | vstore(); | 309 | vstore(); |
| 309 | c->args_size += size; | 310 | c->args_size += size; |
| @@ -655,11 +656,22 @@ void gen_opf(int op) · 345 unmodified lines | |||
| 655 | gv(RC_FLOAT); | 656 | gv(RC_FLOAT); |
| 656 | vswap(); | 657 | vswap(); |
| 657 | } | 658 | } |
| 659 | swapped = 0; | ||
| 660 | /* swap the stack if needed so that t1 is the register and t2 is | ||
| 661 | the memory reference */ | ||
| 662 | if (vtop[-1].r & VT_LVAL) { | ||
| 663 | vswap(); | ||
| 664 | swapped = 1; | ||
| 665 | } | ||
| 658 | if (op >= TOK_ULT && op <= TOK_GT) { | 666 | if (op >= TOK_ULT && op <= TOK_GT) { |
| 659 | /* load on stack second operand */ | 667 | /* load on stack second operand */ |
| 660 | load(REG_ST0, vtop); | 668 | load(REG_ST0, vtop); |
| 661 | save_reg(REG_EAX); /* eax is used by FP comparison code */ | 669 | save_reg(REG_EAX); /* eax is used by FP comparison code */ |
| 662 | if (op == TOK_GE || op == TOK_GT) | 670 | if (op == TOK_GE || op == TOK_GT) |
| 671 | swapped = !swapped; | ||
| 672 | else if (op == TOK_EQ || op == TOK_NE) | ||
| 673 | swapped = 0; | ||
| 674 | if (swapped) | ||
| 663 | o(0xc9d9); /* fxch %st(1) */ | 675 | o(0xc9d9); /* fxch %st(1) */ |
| 664 | o(0xe9da); /* fucompp */ | 676 | o(0xe9da); /* fucompp */ |
| 665 | o(0xe0df); /* fnstsw %ax */ | 677 | o(0xe0df); /* fnstsw %ax */ |
| @@ -681,13 +693,6 @@ void gen_opf(int op) · 15 unmodified lines | |||
| 681 | vtop->r = VT_CMP; | 693 | vtop->r = VT_CMP; |
| 682 | vtop->c.i = op; | 694 | vtop->c.i = op; |
| 683 | } else { | 695 | } else { |
| 684 | swapped = 0; | ||
| 685 | /* swap the stack if needed so that t1 is the register and t2 is | ||
| 686 | the memory reference */ | ||
| 687 | if (vtop[-1].r & VT_LVAL) { | ||
| 688 | vswap(); | ||
| 689 | swapped = 1; | ||
| 690 | } | ||
| 691 | /* no memory reference possible for long double operations */ | 696 | /* no memory reference possible for long double operations */ |
| 692 | if ((vtop->t & VT_BTYPE) == VT_LDOUBLE) { | 697 | if ((vtop->t & VT_BTYPE) == VT_LDOUBLE) { |
| 693 | load(REG_ST0, vtop); | 698 | load(REG_ST0, vtop); |
| @@ -821,45 +826,57 @@ void gen_cvt_ftof(int t) · 127 unmodified lines | |||
| 821 | 826 | ||
| 822 | /* bound check support functions */ | 827 | /* bound check support functions */ |
| 823 | #ifdef CONFIG_TCC_BCHECK | 828 | #ifdef CONFIG_TCC_BCHECK |
| 824 | /* generate first part of bounded pointer addition */ | 829 | |
| 825 | void gen_bounded_ptr_add1(void) | 830 | /* generate a bounded pointer addition */ |
| 831 | void gen_bounded_ptr_add(void) | ||
| 826 | { | 832 | { |
| 833 | int addr; | ||
| 827 | /* prepare fast i386 function call (args in eax and edx) */ | 834 | /* prepare fast i386 function call (args in eax and edx) */ |
| 828 | gv2(RC_EAX, RC_EDX); | 835 | gv2(RC_EAX, RC_EDX); |
| 829 | /* save all temporary registers */ | 836 | /* save all temporary registers */ |
| 830 | vtop--; | 837 | vtop -= 2; |
| 831 | vtop->r = VT_CONST; | 838 | save_regs(0); |
| 832 | save_regs(0); | 839 | /* do a fast function call */ |
| 840 | addr = ind; | ||
| 841 | oad(0xe8, (int)__bound_ptr_add - ind - 5); | ||
| 842 | /* returned pointer is in eax */ | ||
| 843 | vtop++; | ||
| 844 | vtop->r = REG_EAX | VT_BOUNDED; | ||
| 845 | vtop->c.ul = addr; /* address of bounding function call point */ | ||
| 833 | } | 846 | } |
| 834 | 847 | ||
| 835 | /* if deref is true, then also test dereferencing */ | 848 | /* patch pointer addition in vtop so that pointer dereferencing is |
| 836 | void gen_bounded_ptr_add2(int deref) | 849 | also tested */ |
| 850 | void gen_bounded_ptr_deref(void) | ||
| 837 | { | 851 | { |
| 838 | void *func; | 852 | void *func; |
| 839 | int size, align; | 853 | int size, align, addr; |
| 840 | 854 | ||
| 841 | if (deref) { | 855 | size = 0; |
| 856 | /* XXX: put that code in generic part of tcc */ | ||
| 857 | if (!is_float(vtop->t)) { | ||
| 858 | if (vtop->r & VT_LVAL_BYTE) | ||
| 859 | size = 1; | ||
| 860 | else if (vtop->r & VT_LVAL_SHORT) | ||
| 861 | size = 2; | ||
| 862 | } | ||
| 863 | if (!size) | ||
| 842 | size = type_size(vtop->t, &align); | 864 | size = type_size(vtop->t, &align); |
| 843 | switch(size) { | 865 | switch(size) { |
| 844 | case 1: func = __bound_ptr_indir1; break; | 866 | case 1: func = __bound_ptr_indir1; break; |
| 845 | case 2: func = __bound_ptr_indir2; break; | 867 | case 2: func = __bound_ptr_indir2; break; |
| 846 | case 4: func = __bound_ptr_indir4; break; | 868 | case 4: func = __bound_ptr_indir4; break; |
| 847 | case 8: func = __bound_ptr_indir8; break; | 869 | case 8: func = __bound_ptr_indir8; break; |
| 848 | case 12: func = __bound_ptr_indir12; break; | 870 | case 12: func = __bound_ptr_indir12; break; |
| 849 | case 16: func = __bound_ptr_indir16; break; | 871 | case 16: func = __bound_ptr_indir16; break; |
| 850 | default: | 872 | default: |
| 851 | error("unhandled size when derefencing bounded pointer"); | 873 | error("unhandled size when derefencing bounded pointer"); |
| 852 | func = NULL; | 874 | func = NULL; |
| 853 | break; | 875 | break; |
| 854 | } | ||
| 855 | } else { | ||
| 856 | func = __bound_ptr_add; | ||
| 857 | } | 876 | } |
| 858 | 877 | ||
| 859 | /* do a fast function call */ | 878 | addr = vtop->c.ul; |
| 860 | oad(0xe8, (int)func - ind - 5); | 879 | *(int *)(addr + 1) = (int)func - addr - 5; |
| 861 | /* return pointer is there */ | ||
| 862 | vtop->r = REG_EAX; | ||
| 863 | } | 880 | } |
| 864 | #endif | 881 | #endif |
| 865 | 882 | ||