diff --git a/jscomp/core/js_long.ml b/jscomp/core/js_long.ml index d35eb39d9d..bdf1e55824 100644 --- a/jscomp/core/js_long.ml +++ b/jscomp/core/js_long.ml @@ -53,8 +53,8 @@ let make ~lo ~hi = ~comment:"int64" (E.zero_int_literal) record_info [ hi; E.to_uint32 lo ] Immutable -let get_lo x = E.array_index_by_int x 1l -let get_hi x = E.array_index_by_int x 0l + + (* below should not depend on layout *) @@ -66,7 +66,9 @@ let of_const (v : Int64.t) = ~hi:(Int64.to_int32 (Int64.shift_right v 32)) let to_int32 args = - E.to_int32 @@ get_lo (Ext_list.singleton_exn args) + int64_call "to_int32" args +(* let get_lo x = E.array_index_by_int x 1l *) + (* E.to_int32 @@ get_lo (Ext_list.singleton_exn args) *) let of_int32 (args : J.expression list) = @@ -108,15 +110,19 @@ let div args = current pipe-line fall back to a function call *) let bit_op (op : E.t -> E.t -> E.t) runtime_call args = - match args with + int64_call runtime_call args + (*disable optimizations relying on int64 representations + this maybe outdated when we switch to bigint + *) + (* match args with | [l;r] -> (* Int64 is a block in ocaml, a little more conservative in inlining *) if Js_analyzer.is_okay_to_duplicate l && Js_analyzer.is_okay_to_duplicate r then make ~lo:(op (get_lo l) (get_lo r)) ~hi:(op (get_hi l) (get_hi r)) - else int64_call runtime_call args - | _ -> assert false + else + | _ -> assert false *) let xor = bit_op E.int32_bxor "xor" let or_ = bit_op E.int32_bor "or_" diff --git a/jscomp/test/int64_test.js b/jscomp/test/int64_test.js index bf9f340ff8..3b9f8f47f2 100644 --- a/jscomp/test/int64_test.js +++ b/jscomp/test/int64_test.js @@ -1059,7 +1059,10 @@ var suites = Pervasives.$at(/* :: */[ (function (param) { return /* Eq */Block.__(0, [ 3, - 3 + Caml_int64.to_int32(/* int64 */[ + /* hi */0, + /* lo */3 + ]) ]); }) ], @@ -1069,7 +1072,10 @@ var suites = Pervasives.$at(/* :: */[ (function (param) { return /* Eq */Block.__(0, [ 3, - 3 + Caml_int64.to_int32(/* int64 */[ + /* hi */0, + /* lo */3 + ]) ]); }) ], @@ -2059,122 +2065,120 @@ var suites = Pervasives.$at(/* :: */[ ], /* :: */[ /* tuple */[ - "to_int32", + "of_int32_singleton", (function (param) { return /* Eq */Block.__(0, [ - $$Array.map((function (prim) { - return prim[1] | 0; - }), /* array */[ - /* int64 */[ - /* hi */0, - /* lo */0 - ], - /* int64 */[ - /* hi */0, - /* lo */2147483648 - ] - ]), - /* array */[ - 0, - -2147483648 + /* int64 */[ + /* hi */-1, + /* lo */4294967293 + ], + /* int64 */[ + /* hi */-1, + /* lo */4294967293 ] ]); }) ], /* :: */[ /* tuple */[ - "discard_sign", + "File \"int64_test.ml\", line 132, characters 4-11", (function (param) { return /* Eq */Block.__(0, [ - Caml_int64.discard_sign(/* int64 */[ - /* hi */-1, - /* lo */4294967295 - ]), /* int64 */[ - /* hi */2147483647, - /* lo */4294967295 + /* hi */0, + /* lo */3 + ], + /* int64 */[ + /* hi */0, + /* lo */3 ] ]); }) ], /* :: */[ /* tuple */[ - "div_mod", + "to_int32", (function (param) { return /* Eq */Block.__(0, [ - Caml_int64.div_mod(/* int64 */[ - /* hi */0, - /* lo */7 - ], /* int64 */[ - /* hi */0, - /* lo */3 + $$Array.map(Caml_int64.to_int32, /* array */[ + /* int64 */[ + /* hi */0, + /* lo */0 + ], + /* int64 */[ + /* hi */0, + /* lo */2147483648 + ] ]), - /* tuple */[ - /* int64 */[ - /* hi */0, - /* lo */2 - ], - /* int64 */[ - /* hi */0, - /* lo */1 - ] + /* array */[ + 0, + -2147483648 ] ]); }) ], /* :: */[ /* tuple */[ - "to_hex", + "discard_sign", (function (param) { return /* Eq */Block.__(0, [ - Caml_int64.to_hex(/* int64 */[ + Caml_int64.discard_sign(/* int64 */[ /* hi */-1, /* lo */4294967295 ]), - "ffffffffffffffff" + /* int64 */[ + /* hi */2147483647, + /* lo */4294967295 + ] ]); }) ], /* :: */[ /* tuple */[ - "generic_compare", + "div_mod", (function (param) { return /* Eq */Block.__(0, [ - Caml_obj.caml_compare(/* int64 */[ - /* hi */1, - /* lo */0 + Caml_int64.div_mod(/* int64 */[ + /* hi */0, + /* lo */7 ], /* int64 */[ /* hi */0, - /* lo */1 - ]) > 0, - true + /* lo */3 + ]), + /* tuple */[ + /* int64 */[ + /* hi */0, + /* lo */2 + ], + /* int64 */[ + /* hi */0, + /* lo */1 + ] + ] ]); }) ], /* :: */[ /* tuple */[ - "test_compier_literal", + "to_hex", (function (param) { return /* Eq */Block.__(0, [ - /* int64 */[ - /* hi */0, - /* lo */4294967295 - ], - /* int64 */[ - /* hi */0, - /* lo */4294967295 - ] + Caml_int64.to_hex(/* int64 */[ + /* hi */-1, + /* lo */4294967295 + ]), + "ffffffffffffffff" ]); }) ], /* :: */[ /* tuple */[ - "generic_compare2", + "generic_compare", (function (param) { return /* Eq */Block.__(0, [ Caml_obj.caml_compare(/* int64 */[ - /* hi */0, - /* lo */2147483648 + /* hi */1, + /* lo */0 ], /* int64 */[ /* hi */0, /* lo */1 @@ -2185,66 +2189,100 @@ var suites = Pervasives.$at(/* :: */[ ], /* :: */[ /* tuple */[ - "shift_left", + "test_compier_literal", (function (param) { return /* Eq */Block.__(0, [ /* int64 */[ /* hi */0, - /* lo */4294967040 + /* lo */4294967295 ], /* int64 */[ /* hi */0, - /* lo */4294967040 + /* lo */4294967295 ] ]); }) ], /* :: */[ /* tuple */[ - "shift_right", + "generic_compare2", (function (param) { return /* Eq */Block.__(0, [ - 4294967295, - 4294967295 + Caml_obj.caml_compare(/* int64 */[ + /* hi */0, + /* lo */2147483648 + ], /* int64 */[ + /* hi */0, + /* lo */1 + ]) > 0, + true ]); }) ], /* :: */[ /* tuple */[ - "fib_int64", + "shift_left", (function (param) { return /* Eq */Block.__(0, [ - fib(1000, /* int64 */[ - /* hi */0, - /* lo */1 - ], /* int64 */[ - /* hi */0, - /* lo */2 - ]), /* int64 */[ - /* hi */-1990564327, - /* lo */2874523960 + /* hi */0, + /* lo */4294967040 + ], + /* int64 */[ + /* hi */0, + /* lo */4294967040 ] ]); }) ], /* :: */[ /* tuple */[ - "fac_int64", + "shift_right", (function (param) { return /* Eq */Block.__(0, [ - fac(30, /* int64 */[ - /* hi */0, - /* lo */1 - ]), - /* int64 */[ - /* hi */-2040662563, - /* lo */1409286144 - ] + 4294967295, + 4294967295 ]); }) ], - /* [] */0 + /* :: */[ + /* tuple */[ + "fib_int64", + (function (param) { + return /* Eq */Block.__(0, [ + fib(1000, /* int64 */[ + /* hi */0, + /* lo */1 + ], /* int64 */[ + /* hi */0, + /* lo */2 + ]), + /* int64 */[ + /* hi */-1990564327, + /* lo */2874523960 + ] + ]); + }) + ], + /* :: */[ + /* tuple */[ + "fac_int64", + (function (param) { + return /* Eq */Block.__(0, [ + fac(30, /* int64 */[ + /* hi */0, + /* lo */1 + ]), + /* int64 */[ + /* hi */-2040662563, + /* lo */1409286144 + ] + ]); + }) + ], + /* [] */0 + ] + ] ] ] ] @@ -2363,37 +2401,37 @@ function id(loc, x) { } } -eq("File \"int64_test.ml\", line 181, characters 5-12", Caml_int64.bits_of_float(0.3), /* int64 */[ +eq("File \"int64_test.ml\", line 188, characters 5-12", Caml_int64.bits_of_float(0.3), /* int64 */[ /* hi */1070805811, /* lo */858993459 ]); -eq("File \"int64_test.ml\", line 182, characters 5-12", Caml_int64.float_of_bits(/* int64 */[ +eq("File \"int64_test.ml\", line 189, characters 5-12", Caml_int64.float_of_bits(/* int64 */[ /* hi */1070805811, /* lo */858993459 ]), 0.3); -id("File \"int64_test.ml\", line 183, characters 5-12", /* int64 */[ +id("File \"int64_test.ml\", line 190, characters 5-12", /* int64 */[ /* hi */-1, /* lo */4294967295 ]); -id("File \"int64_test.ml\", line 184, characters 5-12", /* int64 */[ +id("File \"int64_test.ml\", line 191, characters 5-12", /* int64 */[ /* hi */-1, /* lo */4294967196 ]); -id("File \"int64_test.ml\", line 185, characters 5-12", /* int64 */[ +id("File \"int64_test.ml\", line 192, characters 5-12", /* int64 */[ /* hi */0, /* lo */4294967295 ]); -id("File \"int64_test.ml\", line 186, characters 5-12", /* int64 */[ +id("File \"int64_test.ml\", line 193, characters 5-12", /* int64 */[ /* hi */0, /* lo */536870911 ]); -id("File \"int64_test.ml\", line 187, characters 5-12", /* int64 */[ +id("File \"int64_test.ml\", line 194, characters 5-12", /* int64 */[ /* hi */0, /* lo */536870655 ]); diff --git a/jscomp/test/int64_test.ml b/jscomp/test/int64_test.ml index face420598..370d3a8878 100644 --- a/jscomp/test/int64_test.ml +++ b/jscomp/test/int64_test.ml @@ -124,7 +124,14 @@ let suites : Mt.pair_suites = Mt.[ )); "mul simple", (fun _ -> Eq (6L, mul 3L 2L )); "of_int32", (fun _ -> - Eq(Array.map Int64.of_int32 [|0l;(-2147483648l)|], [|0L; (-2147483648L)|])); + Eq(Array.map Int64.of_int32 [|0l;(-2147483648l)|], [|0L; (-2147483648L)|]); + ); + "of_int32_singleton",(fun _ -> + Eq ( Int64.of_int32 (-3l), -3L ) + ) ; + __LOC__ , (fun _ -> + Eq (Int64.of_int32 3l , 3L) + ); "to_int32", (fun _ -> Eq(Array.map Int64.to_int32 [|0L; 0x0000_0000_8000_0000L|], [|0l;-2147483648l|])); diff --git a/jscomp/test/swap_test.js b/jscomp/test/swap_test.js index ef5972ef26..d82aa01b57 100644 --- a/jscomp/test/swap_test.js +++ b/jscomp/test/swap_test.js @@ -917,7 +917,7 @@ var suites_64 = List.map((function (param) { ]) ]), "swap64 %d" - ]), a[1] | 0), + ]), Caml_int64.to_int32(a)), (function (param) { return /* Eq */Block.__(0, [ Caml_int64.swap(a), diff --git a/lib/4.06.1/unstable/js_compiler.ml b/lib/4.06.1/unstable/js_compiler.ml index 8e27c780d2..b1999a62f7 100644 --- a/lib/4.06.1/unstable/js_compiler.ml +++ b/lib/4.06.1/unstable/js_compiler.ml @@ -117310,8 +117310,8 @@ let make ~lo ~hi = ~comment:"int64" (E.zero_int_literal) record_info [ hi; E.to_uint32 lo ] Immutable -let get_lo x = E.array_index_by_int x 1l -let get_hi x = E.array_index_by_int x 0l + + (* below should not depend on layout *) @@ -117323,7 +117323,9 @@ let of_const (v : Int64.t) = ~hi:(Int64.to_int32 (Int64.shift_right v 32)) let to_int32 args = - E.to_int32 @@ get_lo (Ext_list.singleton_exn args) + int64_call "to_int32" args +(* let get_lo x = E.array_index_by_int x 1l *) + (* E.to_int32 @@ get_lo (Ext_list.singleton_exn args) *) let of_int32 (args : J.expression list) = @@ -117365,15 +117367,19 @@ let div args = current pipe-line fall back to a function call *) let bit_op (op : E.t -> E.t -> E.t) runtime_call args = - match args with + int64_call runtime_call args + (*disable optimizations relying on int64 representations + this maybe outdated when we switch to bigint + *) + (* match args with | [l;r] -> (* Int64 is a block in ocaml, a little more conservative in inlining *) if Js_analyzer.is_okay_to_duplicate l && Js_analyzer.is_okay_to_duplicate r then make ~lo:(op (get_lo l) (get_lo r)) ~hi:(op (get_hi l) (get_hi r)) - else int64_call runtime_call args - | _ -> assert false + else + | _ -> assert false *) let xor = bit_op E.int32_bxor "xor" let or_ = bit_op E.int32_bor "or_" diff --git a/lib/4.06.1/whole_compiler.ml b/lib/4.06.1/whole_compiler.ml index 5a39e19830..5f95eb3392 100644 --- a/lib/4.06.1/whole_compiler.ml +++ b/lib/4.06.1/whole_compiler.ml @@ -108809,8 +108809,8 @@ let make ~lo ~hi = ~comment:"int64" (E.zero_int_literal) record_info [ hi; E.to_uint32 lo ] Immutable -let get_lo x = E.array_index_by_int x 1l -let get_hi x = E.array_index_by_int x 0l + + (* below should not depend on layout *) @@ -108822,7 +108822,9 @@ let of_const (v : Int64.t) = ~hi:(Int64.to_int32 (Int64.shift_right v 32)) let to_int32 args = - E.to_int32 @@ get_lo (Ext_list.singleton_exn args) + int64_call "to_int32" args +(* let get_lo x = E.array_index_by_int x 1l *) + (* E.to_int32 @@ get_lo (Ext_list.singleton_exn args) *) let of_int32 (args : J.expression list) = @@ -108864,15 +108866,19 @@ let div args = current pipe-line fall back to a function call *) let bit_op (op : E.t -> E.t -> E.t) runtime_call args = - match args with + int64_call runtime_call args + (*disable optimizations relying on int64 representations + this maybe outdated when we switch to bigint + *) + (* match args with | [l;r] -> (* Int64 is a block in ocaml, a little more conservative in inlining *) if Js_analyzer.is_okay_to_duplicate l && Js_analyzer.is_okay_to_duplicate r then make ~lo:(op (get_lo l) (get_lo r)) ~hi:(op (get_hi l) (get_hi r)) - else int64_call runtime_call args - | _ -> assert false + else + | _ -> assert false *) let xor = bit_op E.int32_bxor "xor" let or_ = bit_op E.int32_bor "or_" diff --git a/lib/js/caml_format.js b/lib/js/caml_format.js index 6c0425b8b6..9968708b89 100644 --- a/lib/js/caml_format.js +++ b/lib/js/caml_format.js @@ -602,7 +602,7 @@ function caml_int64_format(fmt, x) { /* lo */0 ], match$1[0]); var modulus = match$1[1]; - s = String.fromCharCode(cvtbl.charCodeAt(modulus[1] | 0)) + s; + s = String.fromCharCode(cvtbl.charCodeAt(Caml_int64.to_int32(modulus))) + s; while(Caml_int64.neq(quotient, /* int64 */[ /* hi */0, /* lo */0 @@ -610,13 +610,13 @@ function caml_int64_format(fmt, x) { var match$2 = Caml_int64.div_mod(quotient, wbase); quotient = match$2[0]; modulus = match$2[1]; - s = String.fromCharCode(cvtbl.charCodeAt(modulus[1] | 0)) + s; + s = String.fromCharCode(cvtbl.charCodeAt(Caml_int64.to_int32(modulus))) + s; }; } else { var match$3 = Caml_int64.div_mod(x$1, wbase); var quotient$1 = match$3[0]; var modulus$1 = match$3[1]; - s = String.fromCharCode(cvtbl.charCodeAt(modulus$1[1] | 0)) + s; + s = String.fromCharCode(cvtbl.charCodeAt(Caml_int64.to_int32(modulus$1))) + s; while(Caml_int64.neq(quotient$1, /* int64 */[ /* hi */0, /* lo */0 @@ -624,7 +624,7 @@ function caml_int64_format(fmt, x) { var match$4 = Caml_int64.div_mod(quotient$1, wbase); quotient$1 = match$4[0]; modulus$1 = match$4[1]; - s = String.fromCharCode(cvtbl.charCodeAt(modulus$1[1] | 0)) + s; + s = String.fromCharCode(cvtbl.charCodeAt(Caml_int64.to_int32(modulus$1))) + s; }; } break; @@ -652,7 +652,7 @@ function caml_int64_format(fmt, x) { /* lo */3435973836 ], match$5[0]), match$6[0]); var modulus$2 = match$6[1]; - s = String.fromCharCode(cvtbl$1.charCodeAt(modulus$2[1] | 0)) + s; + s = String.fromCharCode(cvtbl$1.charCodeAt(Caml_int64.to_int32(modulus$2))) + s; while(Caml_int64.neq(quotient$2, /* int64 */[ /* hi */0, /* lo */0 @@ -660,13 +660,13 @@ function caml_int64_format(fmt, x) { var match$7 = Caml_int64.div_mod(quotient$2, wbase$1); quotient$2 = match$7[0]; modulus$2 = match$7[1]; - s = String.fromCharCode(cvtbl$1.charCodeAt(modulus$2[1] | 0)) + s; + s = String.fromCharCode(cvtbl$1.charCodeAt(Caml_int64.to_int32(modulus$2))) + s; }; } else { var match$8 = Caml_int64.div_mod(x$1, wbase$1); var quotient$3 = match$8[0]; var modulus$3 = match$8[1]; - s = String.fromCharCode(cvtbl$1.charCodeAt(modulus$3[1] | 0)) + s; + s = String.fromCharCode(cvtbl$1.charCodeAt(Caml_int64.to_int32(modulus$3))) + s; while(Caml_int64.neq(quotient$3, /* int64 */[ /* hi */0, /* lo */0 @@ -674,7 +674,7 @@ function caml_int64_format(fmt, x) { var match$9 = Caml_int64.div_mod(quotient$3, wbase$1); quotient$3 = match$9[0]; modulus$3 = match$9[1]; - s = String.fromCharCode(cvtbl$1.charCodeAt(modulus$3[1] | 0)) + s; + s = String.fromCharCode(cvtbl$1.charCodeAt(Caml_int64.to_int32(modulus$3))) + s; }; } break; diff --git a/lib/js/random.js b/lib/js/random.js index 653a8c313f..ac106cd506 100644 --- a/lib/js/random.js +++ b/lib/js/random.js @@ -132,10 +132,7 @@ function int64(s, bound) { var b1 = Caml_int64.of_int32(bits(s$1)); var b2 = Caml_int64.lsl_(Caml_int64.of_int32(bits(s$1)), 30); var b3 = Caml_int64.lsl_(Caml_int64.of_int32(bits(s$1) & 7), 60); - var r = Caml_int64.or_(b1, /* int64 */[ - /* hi */b2[0] | b3[0], - /* lo */((b2[1] | b3[1]) >>> 0) - ]); + var r = Caml_int64.or_(b1, Caml_int64.or_(b2, b3)); var v = Caml_int64.mod_(r, n); if (Caml_int64.gt(Caml_int64.sub(r, v), Caml_int64.add(Caml_int64.sub(Int64.max_int, n), /* int64 */[ /* hi */0, @@ -149,7 +146,7 @@ function int64(s, bound) { } var nativeint = Nativeint.size === 32 ? int32 : (function (s, bound) { - return int64(s, Caml_int64.of_int32(bound))[1] | 0; + return Caml_int64.to_int32(int64(s, Caml_int64.of_int32(bound))); }); function rawfloat(s) {