diff options
author | Mike Pall <mike> | 2022-01-13 17:51:09 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2022-01-13 17:51:09 +0100 |
commit | 4ccaf348fb40488c76a78d4b385a313a987fd1ad (patch) | |
tree | 61415fbc9d7415bee450f548f08e61d8e8c2cf8f /src | |
parent | a91d0d9d3bba1a936669cfac3244509a0f2ac0e3 (diff) | |
parent | e56048753634c32ea6eeedf74cef6f9cfea5f4ed (diff) | |
download | luajit-4ccaf348fb40488c76a78d4b385a313a987fd1ad.tar.gz luajit-4ccaf348fb40488c76a78d4b385a313a987fd1ad.tar.bz2 luajit-4ccaf348fb40488c76a78d4b385a313a987fd1ad.zip |
Merge branch 'master' into v2.1
Diffstat (limited to 'src')
-rw-r--r-- | src/lj_opt_fold.c | 5 | ||||
-rw-r--r-- | src/lj_opt_sink.c | 16 | ||||
-rw-r--r-- | src/lj_strscan.c | 13 |
3 files changed, 25 insertions, 9 deletions
diff --git a/src/lj_opt_fold.c b/src/lj_opt_fold.c index bdaa0e4f..83972db9 100644 --- a/src/lj_opt_fold.c +++ b/src/lj_opt_fold.c | |||
@@ -1958,14 +1958,15 @@ LJFOLDF(abc_fwd) | |||
1958 | LJFOLD(ABC any KINT) | 1958 | LJFOLD(ABC any KINT) |
1959 | LJFOLDF(abc_k) | 1959 | LJFOLDF(abc_k) |
1960 | { | 1960 | { |
1961 | PHIBARRIER(fleft); | ||
1961 | if (LJ_LIKELY(J->flags & JIT_F_OPT_ABC)) { | 1962 | if (LJ_LIKELY(J->flags & JIT_F_OPT_ABC)) { |
1962 | IRRef ref = J->chain[IR_ABC]; | 1963 | IRRef ref = J->chain[IR_ABC]; |
1963 | IRRef asize = fins->op1; | 1964 | IRRef asize = fins->op1; |
1964 | while (ref > asize) { | 1965 | while (ref > asize) { |
1965 | IRIns *ir = IR(ref); | 1966 | IRIns *ir = IR(ref); |
1966 | if (ir->op1 == asize && irref_isk(ir->op2)) { | 1967 | if (ir->op1 == asize && irref_isk(ir->op2)) { |
1967 | int32_t k = IR(ir->op2)->i; | 1968 | uint32_t k = (uint32_t)IR(ir->op2)->i; |
1968 | if (fright->i > k) | 1969 | if ((uint32_t)fright->i > k) |
1969 | ir->op2 = fins->op2; | 1970 | ir->op2 = fins->op2; |
1970 | return DROPFOLD; | 1971 | return DROPFOLD; |
1971 | } | 1972 | } |
diff --git a/src/lj_opt_sink.c b/src/lj_opt_sink.c index 5306a7db..f1a67fa1 100644 --- a/src/lj_opt_sink.c +++ b/src/lj_opt_sink.c | |||
@@ -36,12 +36,14 @@ static IRIns *sink_checkalloc(jit_State *J, IRIns *irs) | |||
36 | } | 36 | } |
37 | 37 | ||
38 | /* Recursively check whether a value depends on a PHI. */ | 38 | /* Recursively check whether a value depends on a PHI. */ |
39 | static int sink_phidep(jit_State *J, IRRef ref) | 39 | static int sink_phidep(jit_State *J, IRRef ref, int *workp) |
40 | { | 40 | { |
41 | IRIns *ir = IR(ref); | 41 | IRIns *ir = IR(ref); |
42 | if (!*workp) return 1; /* Give up and pretend it does. */ | ||
43 | (*workp)--; | ||
42 | if (irt_isphi(ir->t)) return 1; | 44 | if (irt_isphi(ir->t)) return 1; |
43 | if (ir->op1 >= REF_FIRST && sink_phidep(J, ir->op1)) return 1; | 45 | if (ir->op1 >= REF_FIRST && sink_phidep(J, ir->op1, workp)) return 1; |
44 | if (ir->op2 >= REF_FIRST && sink_phidep(J, ir->op2)) return 1; | 46 | if (ir->op2 >= REF_FIRST && sink_phidep(J, ir->op2, workp)) return 1; |
45 | return 0; | 47 | return 0; |
46 | } | 48 | } |
47 | 49 | ||
@@ -56,7 +58,13 @@ static int sink_checkphi(jit_State *J, IRIns *ira, IRRef ref) | |||
56 | return 1; /* Sinkable PHI. */ | 58 | return 1; /* Sinkable PHI. */ |
57 | } | 59 | } |
58 | /* Otherwise the value must be loop-invariant. */ | 60 | /* Otherwise the value must be loop-invariant. */ |
59 | return ref < J->loopref && !sink_phidep(J, ref); | 61 | if (ref < J->loopref) { |
62 | /* Check for PHI dependencies, but give up after reasonable effort. */ | ||
63 | int work = 64; | ||
64 | return !sink_phidep(J, ref, &work); | ||
65 | } else { | ||
66 | return 0; /* Loop-variant. */ | ||
67 | } | ||
60 | } | 68 | } |
61 | return 1; /* Constant (non-PHI). */ | 69 | return 1; /* Constant (non-PHI). */ |
62 | } | 70 | } |
diff --git a/src/lj_strscan.c b/src/lj_strscan.c index f681fbb0..173455b4 100644 --- a/src/lj_strscan.c +++ b/src/lj_strscan.c | |||
@@ -63,6 +63,7 @@ | |||
63 | #define STRSCAN_MAXDIG 800 /* 772 + extra are sufficient. */ | 63 | #define STRSCAN_MAXDIG 800 /* 772 + extra are sufficient. */ |
64 | #define STRSCAN_DDIG (STRSCAN_DIG/2) | 64 | #define STRSCAN_DDIG (STRSCAN_DIG/2) |
65 | #define STRSCAN_DMASK (STRSCAN_DDIG-1) | 65 | #define STRSCAN_DMASK (STRSCAN_DDIG-1) |
66 | #define STRSCAN_MAXEXP (1 << 20) | ||
66 | 67 | ||
67 | /* Helpers for circular buffer. */ | 68 | /* Helpers for circular buffer. */ |
68 | #define DNEXT(a) (((a)+1) & STRSCAN_DMASK) | 69 | #define DNEXT(a) (((a)+1) & STRSCAN_DMASK) |
@@ -121,7 +122,8 @@ static StrScanFmt strscan_hex(const uint8_t *p, TValue *o, | |||
121 | /* Format-specific handling. */ | 122 | /* Format-specific handling. */ |
122 | switch (fmt) { | 123 | switch (fmt) { |
123 | case STRSCAN_INT: | 124 | case STRSCAN_INT: |
124 | if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg) { | 125 | if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg && |
126 | !(x == 0 && neg)) { | ||
125 | o->i = neg ? -(int32_t)x : (int32_t)x; | 127 | o->i = neg ? -(int32_t)x : (int32_t)x; |
126 | return STRSCAN_INT; /* Fast path for 32 bit integers. */ | 128 | return STRSCAN_INT; /* Fast path for 32 bit integers. */ |
127 | } | 129 | } |
@@ -448,6 +450,7 @@ StrScanFmt lj_strscan_scan(const uint8_t *p, MSize len, TValue *o, | |||
448 | if (dig) { | 450 | if (dig) { |
449 | ex = (int32_t)(dp-(p-1)); dp = p-1; | 451 | ex = (int32_t)(dp-(p-1)); dp = p-1; |
450 | while (ex < 0 && *dp-- == '0') ex++, dig--; /* Skip trailing zeros. */ | 452 | while (ex < 0 && *dp-- == '0') ex++, dig--; /* Skip trailing zeros. */ |
453 | if (ex <= -STRSCAN_MAXEXP) return STRSCAN_ERROR; | ||
451 | if (base == 16) ex *= 4; | 454 | if (base == 16) ex *= 4; |
452 | } | 455 | } |
453 | } | 456 | } |
@@ -461,7 +464,8 @@ StrScanFmt lj_strscan_scan(const uint8_t *p, MSize len, TValue *o, | |||
461 | if (!lj_char_isdigit(*p)) return STRSCAN_ERROR; | 464 | if (!lj_char_isdigit(*p)) return STRSCAN_ERROR; |
462 | xx = (*p++ & 15); | 465 | xx = (*p++ & 15); |
463 | while (lj_char_isdigit(*p)) { | 466 | while (lj_char_isdigit(*p)) { |
464 | if (xx < 65536) xx = xx * 10 + (*p & 15); | 467 | xx = xx * 10 + (*p & 15); |
468 | if (xx >= STRSCAN_MAXEXP) return STRSCAN_ERROR; | ||
465 | p++; | 469 | p++; |
466 | } | 470 | } |
467 | ex += negx ? -(int32_t)xx : (int32_t)xx; | 471 | ex += negx ? -(int32_t)xx : (int32_t)xx; |
@@ -499,6 +503,9 @@ StrScanFmt lj_strscan_scan(const uint8_t *p, MSize len, TValue *o, | |||
499 | if ((opt & STRSCAN_OPT_TONUM)) { | 503 | if ((opt & STRSCAN_OPT_TONUM)) { |
500 | o->n = neg ? -(double)x : (double)x; | 504 | o->n = neg ? -(double)x : (double)x; |
501 | return STRSCAN_NUM; | 505 | return STRSCAN_NUM; |
506 | } else if (x == 0 && neg) { | ||
507 | o->n = -0.0; | ||
508 | return STRSCAN_NUM; | ||
502 | } else { | 509 | } else { |
503 | o->i = neg ? -(int32_t)x : (int32_t)x; | 510 | o->i = neg ? -(int32_t)x : (int32_t)x; |
504 | return STRSCAN_INT; | 511 | return STRSCAN_INT; |
@@ -516,7 +523,7 @@ StrScanFmt lj_strscan_scan(const uint8_t *p, MSize len, TValue *o, | |||
516 | fmt = strscan_dec(sp, o, fmt, opt, ex, neg, dig); | 523 | fmt = strscan_dec(sp, o, fmt, opt, ex, neg, dig); |
517 | 524 | ||
518 | /* Try to convert number to integer, if requested. */ | 525 | /* Try to convert number to integer, if requested. */ |
519 | if (fmt == STRSCAN_NUM && (opt & STRSCAN_OPT_TOINT)) { | 526 | if (fmt == STRSCAN_NUM && (opt & STRSCAN_OPT_TOINT) && !tvismzero(o)) { |
520 | double n = o->n; | 527 | double n = o->n; |
521 | int32_t i = lj_num2int(n); | 528 | int32_t i = lj_num2int(n); |
522 | if (n == (lua_Number)i) { o->i = i; return STRSCAN_INT; } | 529 | if (n == (lua_Number)i) { o->i = i; return STRSCAN_INT; } |