History

fixed floating poing compare - use LVAL type - optimized bound checking

bellard committed 24 years ago

Commit 264dbcf1 parent 30766d31 file · +58 −41Browse files

Unified · Split

i386-gen.c+58−41
@@ -207,16 +207,17 @@ void load(int r, SValue *sv) · 206 unmodified lines
207207 } else if ((ft & VT_BTYPE) == VT_LDOUBLE) {
208208 o(0xdb); /* fldt */
209209 r = 5;
210− } else if ((ft & VT_TYPE) == VT_BYTE)
210+ } else if ((ft & VT_TYPE) == VT_BYTE) {
211211 o(0xbe0f); /* movsbl */
212− else if ((ft & VT_TYPE) == (VT_BYTE | VT_UNSIGNED))
212+ } else if ((ft & VT_TYPE) == (VT_BYTE | VT_UNSIGNED)) {
213213 o(0xb60f); /* movzbl */
214− else if ((ft & VT_TYPE) == VT_SHORT)
214+ } else if ((ft & VT_TYPE) == VT_SHORT) {
215215 o(0xbf0f); /* movswl */
216− else if ((ft & VT_TYPE) == (VT_SHORT | VT_UNSIGNED))
216+ } else if ((ft & VT_TYPE) == (VT_SHORT | VT_UNSIGNED)) {
217217 o(0xb70f); /* movzwl */
218− else
218+ } else {
219219 o(0x8b); /* movl */
220+ }
220221 gen_modrm(r, fr, fc);
221222 } else {
222223 if (v == VT_CONST) {
@@ -303,7 +304,7 @@ void gfunc_param(GFuncContext *c) · 80 unmodified lines
303304 r = get_reg(RC_INT);
304305 o(0x89); /* mov %esp, r */
305306 o(0xe0 + r);
306− vset(VT_INT, r, 0);
307+ vset(vtop->t, r | VT_LVAL, 0);
307308 vswap();
308309 vstore();
309310 c->args_size += size;
@@ -655,11 +656,22 @@ void gen_opf(int op) · 345 unmodified lines
655656 gv(RC_FLOAT);
656657 vswap();
657658 }
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+ }
658666 if (op >= TOK_ULT && op <= TOK_GT) {
659667 /* load on stack second operand */
660668 load(REG_ST0, vtop);
661669 save_reg(REG_EAX); /* eax is used by FP comparison code */
662670 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)
663675 o(0xc9d9); /* fxch %st(1) */
664676 o(0xe9da); /* fucompp */
665677 o(0xe0df); /* fnstsw %ax */
@@ -681,13 +693,6 @@ void gen_opf(int op) · 15 unmodified lines
681693 vtop->r = VT_CMP;
682694 vtop->c.i = op;
683695 } 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− }
691696 /* no memory reference possible for long double operations */
692697 if ((vtop->t & VT_BTYPE) == VT_LDOUBLE) {
693698 load(REG_ST0, vtop);
@@ -821,45 +826,57 @@ void gen_cvt_ftof(int t) · 127 unmodified lines
821826
822827 /* bound check support functions */
823828 #ifdef CONFIG_TCC_BCHECK
824−/* generate first part of bounded pointer addition */
825−void gen_bounded_ptr_add1(void)
829+
830+/* generate a bounded pointer addition */
831+void gen_bounded_ptr_add(void)
826832 {
833+ int addr;
827834 /* prepare fast i386 function call (args in eax and edx) */
828835 gv2(RC_EAX, RC_EDX);
829836 /* save all temporary registers */
830− vtop--;
831− vtop->r = VT_CONST;
832− save_regs(0);
837+ vtop -= 2;
838+ 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 */
833846 }
834847
835−/* if deref is true, then also test dereferencing */
836−void gen_bounded_ptr_add2(int deref)
848+/* patch pointer addition in vtop so that pointer dereferencing is
849+ also tested */
850+void gen_bounded_ptr_deref(void)
837851 {
838852 void *func;
839− int size, align;
840−
841− if (deref) {
853+ int size, align, addr;
854+
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)
842864 size = type_size(vtop->t, &align);
843− switch(size) {
844− case 1: func = __bound_ptr_indir1; break;
845− case 2: func = __bound_ptr_indir2; break;
846− case 4: func = __bound_ptr_indir4; break;
847− case 8: func = __bound_ptr_indir8; break;
848− case 12: func = __bound_ptr_indir12; break;
849− case 16: func = __bound_ptr_indir16; break;
850− default:
851− error("unhandled size when derefencing bounded pointer");
852− func = NULL;
853− break;
854− }
855− } else {
856− func = __bound_ptr_add;
865+ switch(size) {
866+ case 1: func = __bound_ptr_indir1; break;
867+ case 2: func = __bound_ptr_indir2; break;
868+ case 4: func = __bound_ptr_indir4; break;
869+ case 8: func = __bound_ptr_indir8; break;
870+ case 12: func = __bound_ptr_indir12; break;
871+ case 16: func = __bound_ptr_indir16; break;
872+ default:
873+ error("unhandled size when derefencing bounded pointer");
874+ func = NULL;
875+ break;
857876 }
858877
859− /* do a fast function call */
860− oad(0xe8, (int)func - ind - 5);
861− /* return pointer is there */
862− vtop->r = REG_EAX;
878+ addr = vtop->c.ul;
879+ *(int *)(addr + 1) = (int)func - addr - 5;
863880 }
864881 #endif
865882

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