@@ -376,27 +376,20 @@ typedef struct JSRefCountHeader {
376
376
} JSRefCountHeader;
377
377
378
378
/* bigint */
379
- #if JS_LIMB_BITS == 32
380
-
381
379
typedef int32_t js_slimb_t;
382
380
typedef uint32_t js_limb_t;
383
381
typedef int64_t js_sdlimb_t;
384
382
typedef uint64_t js_dlimb_t;
385
383
386
384
#define JS_LIMB_DIGITS 9
387
385
388
- #else
389
-
390
- typedef __int128 int128_t;
391
- typedef unsigned __int128 uint128_t;
392
- typedef int64_t js_slimb_t;
393
- typedef uint64_t js_limb_t;
394
- typedef int128_t js_sdlimb_t;
395
- typedef uint128_t js_dlimb_t;
386
+ /* Must match the size of short_big_int in JSValueUnion */
387
+ #define JS_LIMB_BITS 32
388
+ #define JS_SHORT_BIG_INT_BITS JS_LIMB_BITS
389
+ #define JS_BIGINT_MAX_SIZE ((1024 * 1024) / JS_LIMB_BITS) /* in limbs */
390
+ #define JS_SHORT_BIG_INT_MIN INT32_MIN
391
+ #define JS_SHORT_BIG_INT_MAX INT32_MAX
396
392
397
- #define JS_LIMB_DIGITS 19
398
-
399
- #endif
400
393
401
394
typedef struct JSBigInt {
402
395
JSRefCountHeader header; /* must come first, 32-bit */
@@ -10473,19 +10466,6 @@ static inline int to_digit(int c)
10473
10466
10474
10467
/* bigint support */
10475
10468
10476
- #define JS_BIGINT_MAX_SIZE ((1024 * 1024) / JS_LIMB_BITS) /* in limbs */
10477
-
10478
- /* it is currently assumed that JS_SHORT_BIG_INT_BITS = JS_LIMB_BITS */
10479
- #if JS_SHORT_BIG_INT_BITS == 32
10480
- #define JS_SHORT_BIG_INT_MIN INT32_MIN
10481
- #define JS_SHORT_BIG_INT_MAX INT32_MAX
10482
- #elif JS_SHORT_BIG_INT_BITS == 64
10483
- #define JS_SHORT_BIG_INT_MIN INT64_MIN
10484
- #define JS_SHORT_BIG_INT_MAX INT64_MAX
10485
- #else
10486
- #error unsupported
10487
- #endif
10488
-
10489
10469
#define ADDC(res, carry_out, op1, op2, carry_in) \
10490
10470
do { \
10491
10471
js_limb_t __v, __a, __k, __k1; \
@@ -10498,18 +10478,11 @@ do { \
10498
10478
res = __a; \
10499
10479
} while (0)
10500
10480
10501
- #if JS_LIMB_BITS == 32
10502
10481
/* a != 0 */
10503
10482
static inline js_limb_t js_limb_clz(js_limb_t a)
10504
10483
{
10505
10484
return clz32(a);
10506
10485
}
10507
- #else
10508
- static inline js_limb_t js_limb_clz(js_limb_t a)
10509
- {
10510
- return clz64(a);
10511
- }
10512
- #endif
10513
10486
10514
10487
static js_limb_t mp_add(js_limb_t *res, const js_limb_t *op1, const js_limb_t *op2,
10515
10488
js_limb_t n, js_limb_t carry)
@@ -10815,9 +10788,6 @@ static JSBigInt *js_bigint_set_si(JSBigIntBuf *buf, js_slimb_t a)
10815
10788
10816
10789
static JSBigInt *js_bigint_set_si64(JSBigIntBuf *buf, int64_t a)
10817
10790
{
10818
- #if JS_LIMB_BITS == 64
10819
- return js_bigint_set_si(buf, a);
10820
- #else
10821
10791
JSBigInt *r = (JSBigInt *)buf->big_int_buf;
10822
10792
r->header.ref_count = 0; /* fail safe */
10823
10793
if (a >= INT32_MIN && a <= INT32_MAX) {
@@ -10829,7 +10799,6 @@ static JSBigInt *js_bigint_set_si64(JSBigIntBuf *buf, int64_t a)
10829
10799
r->tab[1] = a >> JS_LIMB_BITS;
10830
10800
}
10831
10801
return r;
10832
- #endif
10833
10802
}
10834
10803
10835
10804
/* val must be a short big int */
@@ -10844,11 +10813,7 @@ static __maybe_unused void js_bigint_dump1(JSContext *ctx, const char *str,
10844
10813
int i;
10845
10814
printf("%s: ", str);
10846
10815
for(i = len - 1; i >= 0; i--) {
10847
- #if JS_LIMB_BITS == 32
10848
10816
printf(" %08x", tab[i]);
10849
- #else
10850
- printf(" %016" PRIx64, tab[i]);
10851
- #endif
10852
10817
}
10853
10818
printf("\n");
10854
10819
}
@@ -10871,9 +10836,6 @@ static JSBigInt *js_bigint_new_si(JSContext *ctx, js_slimb_t a)
10871
10836
10872
10837
static JSBigInt *js_bigint_new_si64(JSContext *ctx, int64_t a)
10873
10838
{
10874
- #if JS_LIMB_BITS == 64
10875
- return js_bigint_new_si(ctx, a);
10876
- #else
10877
10839
if (a >= INT32_MIN && a <= INT32_MAX) {
10878
10840
return js_bigint_new_si(ctx, a);
10879
10841
} else {
@@ -10885,7 +10847,6 @@ static JSBigInt *js_bigint_new_si64(JSContext *ctx, int64_t a)
10885
10847
r->tab[1] = a >> 32;
10886
10848
return r;
10887
10849
}
10888
- #endif
10889
10850
}
10890
10851
10891
10852
static JSBigInt *js_bigint_new_ui64(JSContext *ctx, uint64_t a)
@@ -10897,14 +10858,9 @@ static JSBigInt *js_bigint_new_ui64(JSContext *ctx, uint64_t a)
10897
10858
r = js_bigint_new(ctx, (65 + JS_LIMB_BITS - 1) / JS_LIMB_BITS);
10898
10859
if (!r)
10899
10860
return NULL;
10900
- #if JS_LIMB_BITS == 64
10901
- r->tab[0] = a;
10902
- r->tab[1] = 0;
10903
- #else
10904
10861
r->tab[0] = a;
10905
10862
r->tab[1] = a >> 32;
10906
10863
r->tab[2] = 0;
10907
- #endif
10908
10864
return r;
10909
10865
}
10910
10866
}
@@ -10970,17 +10926,10 @@ static js_slimb_t js_bigint_get_si_sat(const JSBigInt *a)
10970
10926
if (a->len == 1) {
10971
10927
return a->tab[0];
10972
10928
} else {
10973
- #if JS_LIMB_BITS == 32
10974
10929
if (js_bigint_sign(a))
10975
10930
return INT32_MIN;
10976
10931
else
10977
10932
return INT32_MAX;
10978
- #else
10979
- if (js_bigint_sign(a))
10980
- return INT64_MIN;
10981
- else
10982
- return INT64_MAX;
10983
- #endif
10984
10933
}
10985
10934
}
10986
10935
@@ -11421,21 +11370,11 @@ static uint64_t js_bigint_get_mant_exp(JSContext *ctx,
11421
11370
t[j] = v;
11422
11371
}
11423
11372
11424
- #if JS_LIMB_BITS == 32
11425
11373
a1 = ((uint64_t)t[2] << 32) | t[1];
11426
11374
a0 = (uint64_t)t[0] << 32;
11427
- #else
11428
- a1 = t[1];
11429
- a0 = t[0];
11430
- #endif
11431
11375
a0 |= (low_bits != 0);
11432
11376
/* normalize */
11433
- if (a1 == 0) {
11434
- /* JS_LIMB_BITS = 64 bit only */
11435
- shift = 64;
11436
- a1 = a0;
11437
- a0 = 0;
11438
- } else {
11377
+ {
11439
11378
shift = clz64(a1);
11440
11379
if (shift != 0) {
11441
11380
a1 = (a1 << shift) | (a0 >> (64 - shift));
@@ -11636,18 +11575,6 @@ static const js_limb_t js_pow_dec[JS_LIMB_DIGITS + 1] = {
11636
11575
10000000U,
11637
11576
100000000U,
11638
11577
1000000000U,
11639
- #if JS_LIMB_BITS == 64
11640
- 10000000000U,
11641
- 100000000000U,
11642
- 1000000000000U,
11643
- 10000000000000U,
11644
- 100000000000000U,
11645
- 1000000000000000U,
11646
- 10000000000000000U,
11647
- 100000000000000000U,
11648
- 1000000000000000000U,
11649
- 10000000000000000000U,
11650
- #endif
11651
11578
};
11652
11579
11653
11580
/* syntax: [-]digits in base radix. Return NULL if memory error. radix
@@ -11792,15 +11719,10 @@ static char *limb_to_a(char *q, js_limb_t n, unsigned int radix, int len)
11792
11719
#define JS_RADIX_MAX 36
11793
11720
11794
11721
static const uint8_t digits_per_limb_table[JS_RADIX_MAX - 1] = {
11795
- #if JS_LIMB_BITS == 32
11796
11722
32,20,16,13,12,11,10,10, 9, 9, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
11797
- #else
11798
- 64,40,32,27,24,22,21,20,19,18,17,17,16,16,16,15,15,15,14,14,14,14,13,13,13,13,13,13,13,12,12,12,12,12,12,
11799
- #endif
11800
11723
};
11801
11724
11802
11725
static const js_limb_t radix_base_table[JS_RADIX_MAX - 1] = {
11803
- #if JS_LIMB_BITS == 32
11804
11726
0x00000000, 0xcfd41b91, 0x00000000, 0x48c27395,
11805
11727
0x81bf1000, 0x75db9c97, 0x40000000, 0xcfd41b91,
11806
11728
0x3b9aca00, 0x8c8b6d2b, 0x19a10000, 0x309f1021,
@@ -11810,17 +11732,6 @@ static const js_limb_t radix_base_table[JS_RADIX_MAX - 1] = {
11810
11732
0x1269ae40, 0x17179149, 0x1cb91000, 0x23744899,
11811
11733
0x2b73a840, 0x34e63b41, 0x40000000, 0x4cfa3cc1,
11812
11734
0x5c13d840, 0x6d91b519, 0x81bf1000,
11813
- #else
11814
- 0x0000000000000000, 0xa8b8b452291fe821, 0x0000000000000000, 0x6765c793fa10079d,
11815
- 0x41c21cb8e1000000, 0x3642798750226111, 0x8000000000000000, 0xa8b8b452291fe821,
11816
- 0x8ac7230489e80000, 0x4d28cb56c33fa539, 0x1eca170c00000000, 0x780c7372621bd74d,
11817
- 0x1e39a5057d810000, 0x5b27ac993df97701, 0x0000000000000000, 0x27b95e997e21d9f1,
11818
- 0x5da0e1e53c5c8000, 0xd2ae3299c1c4aedb, 0x16bcc41e90000000, 0x2d04b7fdd9c0ef49,
11819
- 0x5658597bcaa24000, 0xa0e2073737609371, 0x0c29e98000000000, 0x14adf4b7320334b9,
11820
- 0x226ed36478bfa000, 0x383d9170b85ff80b, 0x5a3c23e39c000000, 0x8e65137388122bcd,
11821
- 0xdd41bb36d259e000, 0x0aee5720ee830681, 0x1000000000000000, 0x172588ad4f5f0981,
11822
- 0x211e44f7d02c1000, 0x2ee56725f06e5c71, 0x41c21cb8e1000000,
11823
- #endif
11824
11735
};
11825
11736
11826
11737
static JSValue js_bigint_to_string1(JSContext *ctx, JSValueConst val, int radix)
@@ -13540,11 +13451,7 @@ static __maybe_unused void JS_DumpValue(JSRuntime *rt, JSValueConst val)
13540
13451
for(i = p->len - 1; i >= 0; i--) {
13541
13452
if (i != p->len - 1)
13542
13453
printf("_");
13543
- #if JS_LIMB_BITS == 32
13544
13454
printf("%08x", p->tab[i]);
13545
- #else
13546
- printf("%016" PRIx64, p->tab[i]);
13547
- #endif
13548
13455
}
13549
13456
printf("n");
13550
13457
if (sgn)
@@ -13631,9 +13538,6 @@ static double js_math_pow(double a, double b)
13631
13538
13632
13539
JSValue JS_NewBigInt64(JSContext *ctx, int64_t v)
13633
13540
{
13634
- #if JS_SHORT_BIG_INT_BITS == 64
13635
- return __JS_NewShortBigInt(ctx, v);
13636
- #else
13637
13541
if (v >= JS_SHORT_BIG_INT_MIN && v <= JS_SHORT_BIG_INT_MAX) {
13638
13542
return __JS_NewShortBigInt(ctx, v);
13639
13543
} else {
@@ -13643,7 +13547,6 @@ JSValue JS_NewBigInt64(JSContext *ctx, int64_t v)
13643
13547
return JS_EXCEPTION;
13644
13548
return JS_MKPTR(JS_TAG_BIG_INT, p);
13645
13549
}
13646
- #endif
13647
13550
}
13648
13551
13649
13552
JSValue JS_NewBigUint64(JSContext *ctx, uint64_t v)
@@ -13746,10 +13649,8 @@ static int JS_ToBigInt64Free(JSContext *ctx, int64_t *pres, JSValue val)
13746
13649
JSBigInt *p = JS_VALUE_GET_PTR(val);
13747
13650
/* return the value mod 2^64 */
13748
13651
res = p->tab[0];
13749
- #if JS_LIMB_BITS == 32
13750
13652
if (p->len >= 2)
13751
13653
res |= (uint64_t)p->tab[1] << 32;
13752
- #endif
13753
13654
JS_FreeValue(ctx, val);
13754
13655
}
13755
13656
*pres = res;
@@ -35519,11 +35420,7 @@ static int JS_WriteBigInt(BCWriterState *s, JSValueConst obj)
35519
35420
bc_put_leb128(s, len);
35520
35421
if (len > 0) {
35521
35422
for(i = 0; i < (len / (JS_LIMB_BITS / 8)); i++) {
35522
- #if JS_LIMB_BITS == 32
35523
35423
bc_put_u32(s, p->tab[i]);
35524
- #else
35525
- bc_put_u64(s, p->tab[i]);
35526
- #endif
35527
35424
}
35528
35425
for(i = 0; i < len % (JS_LIMB_BITS / 8); i++) {
35529
35426
bc_put_u8(s, (p->tab[p->len - 1] >> (i * 8)) & 0xff);
@@ -36411,13 +36308,8 @@ static JSValue JS_ReadBigInt(BCReaderState *s)
36411
36308
if (!p)
36412
36309
goto fail;
36413
36310
for(i = 0; i < len / (JS_LIMB_BITS / 8); i++) {
36414
- #if JS_LIMB_BITS == 32
36415
36311
if (bc_get_u32(s, &v))
36416
36312
goto fail;
36417
- #else
36418
- if (bc_get_u64(s, &v))
36419
- goto fail;
36420
- #endif
36421
36313
p->tab[i] = v;
36422
36314
}
36423
36315
n = len % (JS_LIMB_BITS / 8);
0 commit comments