Skip to content

Commit

Permalink
Merge #86 branch 'ffi-pointer-difference-div' into integrate
Browse files Browse the repository at this point in the history
  • Loading branch information
lukego committed Dec 11, 2017
2 parents 5454da8 + cf655d9 commit 520c6d3
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/lj_crecord.c
Original file line number Diff line number Diff line change
Expand Up @@ -1289,12 +1289,17 @@ static TRef crec_arith_ptr(jit_State *J, TRef *sp, CType **s, MMS mm)
if (mm == MM_sub) { /* Pointer difference. */
TRef tr;
CTSize sz = lj_ctype_size(cts, ctype_cid(ctp->info));
if (sz == 0 || (sz & (sz-1)) != 0)
return 0; /* NYI: integer division. */
tr = emitir(IRT(IR_SUB, IRT_INTP), sp[0], sp[1]);
tr = emitir(IRT(IR_BSAR, IRT_INTP), tr, lj_ir_kint(J, lj_fls(sz)));
tr = emitconv(tr, IRT_NUM, IRT_INTP, 0);
return tr;
if (sz == 0) {
return 0;
}
tr = emitir(IRT(IR_SUB, IRT_INTP), sp[0], sp[1]);
if ((sz & (sz-1)) == 0) { /* special case: divide using bit-shift */
tr = emitir(IRT(IR_BSAR, IRT_INTP), tr, lj_ir_kint(J, lj_fls(sz)));
} else { /* general case: divide using division */
tr = emitir(IRT(IR_DIV, IRT_INTP), tr, lj_ir_kint(J, sz));
}
tr = emitconv(tr, IRT_NUM, IRT_INTP, 0);
return tr;
} else { /* Pointer comparison (unsigned). */
/* Assume true comparison. Fixup and emit pending guard later. */
IROp op = mm == MM_eq ? IR_EQ : mm == MM_lt ? IR_ULT : IR_ULE;
Expand Down

0 comments on commit 520c6d3

Please sign in to comment.