Guest User

Untitled

a guest
Feb 18th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. diff --git a/asmcomp/cmmgen.ml b/asmcomp/cmmgen.ml
  2. index 1f640b9..3bd65a5 100644
  3. --- a/asmcomp/cmmgen.ml
  4. +++ b/asmcomp/cmmgen.ml
  5. @@ -349,9 +349,9 @@ let mod_int c1 c2 dbg =
  6. (c1, Cconst_int 0) ->
  7. Csequence(c1, Cop(Craise (Raise_regular, dbg),
  8. [Cconst_symbol "caml_exn_Division_by_zero"]))
  9. - | (c1, Cconst_int 1) ->
  10. - c1
  11. - | (Cconst_int(0 | 1) as c1, c2) ->
  12. + | (c1, Cconst_int (1 | (-1))) ->
  13. + Csequence(c1, Cconst_int 0)
  14. + | (Cconst_int(0 | 1 | (-1)) as c1, c2) ->
  15. Csequence(c2, c1)
  16. | (Cconst_int n1, Cconst_int n2) ->
  17. Cconst_int (n1 mod n2)
  18. diff --git a/testsuite/tests/basic/divint.ml b/testsuite/tests/basic/divint.ml
  19. index 52d14b9..fea3263 100644
  20. --- a/testsuite/tests/basic/divint.ml
  21. +++ b/testsuite/tests/basic/divint.ml
  22. @@ -74,6 +74,7 @@ let do_test divisor (df: nativeint -> nativeint) (mf: nativeint -> nativeint) =
  23. end
  24.  
  25. let _ =
  26. + printf "1 int\n"; WithInt.do_test 1 (fun x -> x / 1)(fun x -> x mod 1);
  27. printf "2 int\n"; WithInt.do_test 2 (fun x -> x / 2)(fun x -> x mod 2);
  28. printf "3 int\n"; WithInt.do_test 3 (fun x -> x / 3)(fun x -> x mod 3);
  29. printf "4 int\n"; WithInt.do_test 4 (fun x -> x / 4)(fun x -> x mod 4);
  30. @@ -88,9 +89,11 @@ let _ =
  31. printf "55 int\n"; WithInt.do_test 55 (fun x -> x / 55)(fun x -> x mod 55);
  32. printf "125 int\n"; WithInt.do_test 125 (fun x -> x / 125)(fun x -> x mod 125);
  33. printf "625 int\n"; WithInt.do_test 625 (fun x -> x / 625)(fun x -> x mod 625);
  34. + printf "-1 int\n"; WithInt.do_test (-1) (fun x -> x / (-1))(fun x -> x mod (-1));
  35. printf "-2 int\n"; WithInt.do_test (-2) (fun x -> x / (-2))(fun x -> x mod (-2));
  36. printf "-3 int\n"; WithInt.do_test (-3) (fun x -> x / (-3))(fun x -> x mod (-3));
  37.  
  38. + printf "1 nat\n"; WithNat.do_test 1 (fun x -> Nativeint.div x 1n)(fun x -> Nativeint.rem x 1n);
  39. printf "2 nat\n"; WithNat.do_test 2 (fun x -> Nativeint.div x 2n)(fun x -> Nativeint.rem x 2n);
  40. printf "3 nat\n"; WithNat.do_test 3 (fun x -> Nativeint.div x 3n)(fun x -> Nativeint.rem x 3n);
  41. printf "4 nat\n"; WithNat.do_test 4 (fun x -> Nativeint.div x 4n)(fun x -> Nativeint.rem x 4n);
  42. @@ -105,6 +108,7 @@ let _ =
  43. printf "55 nat\n"; WithNat.do_test 55 (fun x -> Nativeint.div x 55n)(fun x -> Nativeint.rem x 55n);
  44. printf "125 nat\n"; WithNat.do_test 125 (fun x -> Nativeint.div x 125n)(fun x -> Nativeint.rem x 125n);
  45. printf "625 nat\n"; WithNat.do_test 625 (fun x -> Nativeint.div x 625n)(fun x -> Nativeint.rem x 625n);
  46. + printf "-1 nat\n"; WithNat.do_test (-1) (fun x -> Nativeint.div x (-1n))(fun x -> Nativeint.rem x (-1n));
  47. printf "-2 nat\n"; WithNat.do_test (-2) (fun x -> Nativeint.div x (-2n))(fun x -> Nativeint.rem x (-2n));
  48. printf "-3 nat\n"; WithNat.do_test (-3) (fun x -> Nativeint.div x (-3n))(fun x -> Nativeint.rem x (-3n));
  49.  
  50. diff --git a/testsuite/tests/basic/divint.reference b/testsuite/tests/basic/divint.reference
  51. index 4aa1e21..e9a6387 100644
  52. --- a/testsuite/tests/basic/divint.reference
  53. +++ b/testsuite/tests/basic/divint.reference
  54. @@ -1,3 +1,4 @@
  55. +1 int
  56. 2 int
  57. 3 int
  58. 4 int
  59. @@ -12,8 +13,10 @@
  60. 55 int
  61. 125 int
  62. 625 int
  63. +-1 int
  64. -2 int
  65. -3 int
  66. +1 nat
  67. 2 nat
  68. 3 nat
  69. 4 nat
  70. @@ -28,6 +31,7 @@
  71. 55 nat
  72. 125 nat
  73. 625 nat
  74. +-1 nat
  75. -2 nat
  76. -3 nat
  77. Test passed.
Add Comment
Please, Sign In to add comment