Skip to content

Commit 6b58370

Browse files
committed
squash! more save/restore points
1 parent 7511dbc commit 6b58370

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

cutils.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,7 @@ int js_thread_join(js_thread_t thrd);
636636

637637
// JS requires strict rounding behavior. Turn on 64-bits double precision
638638
// and disable x87 80-bits extended precision for intermediate floating-point
639-
// results.
640-
// 0x300 is extended precision, 0x200 is double precision.
639+
// results. 0x300 is extended precision, 0x200 is double precision.
641640
// Note that `*&cw` in the asm constraints looks redundant but isn't.
642641
#if defined(__i386__) && !defined(_MSC_VER)
643642
#define JS_X87_FPCW_SAVE_AND_ADJUST(cw) \

quickjs.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13395,12 +13395,17 @@ static int js_is_array(JSContext *ctx, JSValueConst val)
1339513395

1339613396
static double js_math_pow(double a, double b)
1339713397
{
13398+
double d;
13399+
1339813400
if (unlikely(!isfinite(b)) && fabs(a) == 1) {
1339913401
/* not compatible with IEEE 754 */
13400-
return NAN;
13402+
d = NAN;
1340113403
} else {
13402-
return pow(a, b);
13404+
JS_X87_FPCW_SAVE_AND_ADJUST(fpcw);
13405+
d = pow(a, b);
13406+
JS_X87_FPCW_RESTORE(fpcw);
1340313407
}
13408+
return d;
1340413409
}
1340513410

1340613411
JSValue JS_NewBigInt64(JSContext *ctx, int64_t v)
@@ -13820,11 +13825,15 @@ static no_inline __exception int js_binary_arith_slow(JSContext *ctx, JSValue *s
1382013825
}
1382113826
break;
1382213827
case OP_div:
13828+
JS_X87_FPCW_SAVE_AND_ADJUST(fpcw);
1382313829
sp[-2] = js_number((double)v1 / (double)v2);
13830+
JS_X87_FPCW_RESTORE(fpcw);
1382413831
return 0;
1382513832
case OP_mod:
1382613833
if (v1 < 0 || v2 <= 0) {
13834+
JS_X87_FPCW_SAVE_AND_ADJUST(fpcw);
1382713835
sp[-2] = js_number(fmod(v1, v2));
13836+
JS_X87_FPCW_RESTORE(fpcw);
1382813837
return 0;
1382913838
} else {
1383013839
v = (int64_t)v1 % (int64_t)v2;
@@ -13888,6 +13897,7 @@ static no_inline __exception int js_binary_arith_slow(JSContext *ctx, JSValue *s
1388813897
if (JS_ToFloat64Free(ctx, &d2, op2))
1388913898
goto exception;
1389013899
handle_float64:
13900+
JS_X87_FPCW_SAVE_AND_ADJUST(fpcw);
1389113901
switch(op) {
1389213902
case OP_sub:
1389313903
dr = d1 - d2;
@@ -13907,6 +13917,7 @@ static no_inline __exception int js_binary_arith_slow(JSContext *ctx, JSValue *s
1390713917
default:
1390813918
abort();
1390913919
}
13920+
JS_X87_FPCW_RESTORE(fpcw);
1391013921
sp[-2] = js_float64(dr);
1391113922
}
1391213923
return 0;
@@ -14023,7 +14034,9 @@ static no_inline __exception int js_add_slow(JSContext *ctx, JSValue *sp)
1402314034
}
1402414035
if (JS_ToFloat64Free(ctx, &d2, op2))
1402514036
goto exception;
14037+
JS_X87_FPCW_SAVE_AND_ADJUST(fpcw);
1402614038
sp[-2] = js_float64(d1 + d2);
14039+
JS_X87_FPCW_RESTORE(fpcw);
1402714040
}
1402814041
return 0;
1402914042
exception:

0 commit comments

Comments
 (0)