@@ -377,6 +377,11 @@ let caml_format_int fmt i =
377
377
let f = parse_format fmt in
378
378
aux f i
379
379
380
+ (* FIXME: improve codegen for such cases
381
+ let div_mod (x : int64) (y : int64) : int64 * int64 =
382
+ let a, b = Caml_int64.(div_mod (unsafe_of_int64 x) (unsafe_of_int64 y)) in
383
+ Caml_int64.unsafe_to_int64 a , Caml_int64.unsafe_to_int64 b
384
+ *)
380
385
let caml_int64_format fmt x =
381
386
let module String = Bs_string in
382
387
let f = parse_format fmt in
@@ -391,14 +396,14 @@ let caml_int64_format fmt x =
391
396
392
397
begin match f.base with
393
398
| Hex ->
394
- s := Caml_int64_extern . to_hex x ^ ! s
399
+ s := Caml_int64 . to_hex x ^ ! s
395
400
| Oct ->
396
401
let wbase = 8L in
397
402
let cvtbl = " 01234567" in
398
403
399
404
if x < 0L then
400
405
begin
401
- let y = Caml_int64. (unsafe_to_int64 ( discard_sign (unsafe_of_int64 x))) in
406
+ let y = Caml_int64. discard_sign x in
402
407
(* 2 ^ 63 + y `div_mod` 8 *)
403
408
let quotient_l = 1152921504606846976L (* *)
404
409
(* {lo = 0n; hi = 268435456n } *) (* 2 ^ 31 / 8 *)
@@ -407,7 +412,7 @@ let caml_int64_format fmt x =
407
412
(* let c, d = Caml_int64.div_mod (Caml_int64.add y modulus_l) wbase in
408
413
we can not do the code above, it can overflow when y is really large
409
414
*)
410
- let c, d = Caml_int64_extern . div_mod y wbase in
415
+ let c, d = Caml_int64 . div_mod y wbase in
411
416
412
417
let quotient =
413
418
ref (Caml_int64_extern. add quotient_l c ) in
@@ -417,22 +422,22 @@ let caml_int64_format fmt x =
417
422
cvtbl.[ Caml_int64_extern. to_int ! modulus] ^ ! s ;
418
423
419
424
while ! quotient <> 0L do
420
- let a, b = Caml_int64_extern . div_mod (! quotient) wbase in
425
+ let a, b = Caml_int64 . div_mod (! quotient) wbase in
421
426
quotient := a;
422
427
modulus := b;
423
428
s := Bs_string. of_char cvtbl.[Caml_int64_extern. to_int ! modulus] ^ ! s ;
424
429
done ;
425
430
end
426
431
else
427
- let a, b = Caml_int64_extern . div_mod x wbase in
432
+ let a, b = Caml_int64 . div_mod x wbase in
428
433
let quotient = ref a in
429
434
let modulus = ref b in
430
435
s :=
431
436
Bs_string. of_char
432
437
cvtbl.[ Caml_int64_extern. to_int ! modulus] ^ ! s ;
433
438
434
439
while ! quotient <> 0L do
435
- let a, b = Caml_int64_extern . div_mod (! quotient) wbase in
440
+ let a, b = Caml_int64 . div_mod (! quotient) wbase in
436
441
quotient := a;
437
442
modulus := b;
438
443
s := Bs_string. of_char cvtbl.[Caml_int64_extern. to_int ! modulus] ^ ! s ;
@@ -443,7 +448,7 @@ let caml_int64_format fmt x =
443
448
let cvtbl = " 0123456789" in
444
449
445
450
if x < 0L then
446
- let y = Caml_int64. (unsafe_to_int64 ( discard_sign (unsafe_of_int64 x))) in
451
+ let y = Caml_int64. discard_sign x in
447
452
(* 2 ^ 63 + y `div_mod` 10 *)
448
453
449
454
let quotient_l = 922337203685477580L (* 2 ^ 63 / 10 *)
@@ -454,8 +459,8 @@ let caml_int64_format fmt x =
454
459
(* let c, d = Caml_int64.div_mod (Caml_int64.add y modulus_l) wbase in
455
460
we can not do the code above, it can overflow when y is really large
456
461
*)
457
- let c, d = Caml_int64_extern . div_mod y wbase in
458
- let e ,f = Caml_int64_extern . div_mod (Caml_int64_extern. add modulus_l d) wbase in
462
+ let c, d = Caml_int64 . div_mod y wbase in
463
+ let e ,f = Caml_int64 . div_mod (Caml_int64_extern. add modulus_l d) wbase in
459
464
let quotient =
460
465
ref (Caml_int64_extern. add (Caml_int64_extern. add quotient_l c )
461
466
e) in
@@ -465,22 +470,22 @@ let caml_int64_format fmt x =
465
470
cvtbl.[Caml_int64_extern. to_int ! modulus] ^ ! s ;
466
471
467
472
while ! quotient <> 0L do
468
- let a, b = Caml_int64_extern . div_mod (! quotient) wbase in
473
+ let a, b = Caml_int64 . div_mod (! quotient) wbase in
469
474
quotient := a;
470
475
modulus := b;
471
476
s := Bs_string. of_char cvtbl.[Caml_int64_extern. to_int ! modulus] ^ ! s ;
472
477
done ;
473
478
474
479
else
475
- let a, b = Caml_int64_extern . div_mod x wbase in
480
+ let a, b = Caml_int64 . div_mod x wbase in
476
481
let quotient = ref a in
477
482
let modulus = ref b in
478
483
s :=
479
484
Bs_string. of_char
480
485
cvtbl.[ Caml_int64_extern. to_int ! modulus] ^ ! s ;
481
486
482
487
while ! quotient <> 0L do
483
- let a, b = Caml_int64_extern . div_mod (! quotient) wbase in
488
+ let a, b = Caml_int64 . div_mod (! quotient) wbase in
484
489
quotient := a;
485
490
modulus := b;
486
491
s := Bs_string. of_char cvtbl.[Caml_int64_extern. to_int ! modulus] ^ ! s ;
0 commit comments