aboutsummaryrefslogtreecommitdiff
path: root/kernel/uint63_63.ml
diff options
context:
space:
mode:
authorcoqbot-app[bot]2021-02-27 10:06:39 +0000
committerGitHub2021-02-27 10:06:39 +0000
commit3915bc904fc16060c25baaf7d5626e3587ad2891 (patch)
tree81c21fc95c1790250396119583a57ef4b6f1f3a1 /kernel/uint63_63.ml
parent1e54fe53ac47f08d7b8f13df16487b5a2639404f (diff)
parent4302a75d82b9ac983cd89dd01c742c36777d921b (diff)
Merge PR #13559: Signed primitive integers
Reviewed-by: SkySkimmer Reviewed-by: silene Reviewed-by: jfehrle Ack-by: gares Ack-by: Zimmi48 Ack-by: proux01
Diffstat (limited to 'kernel/uint63_63.ml')
-rw-r--r--kernel/uint63_63.ml28
1 files changed, 25 insertions, 3 deletions
diff --git a/kernel/uint63_63.ml b/kernel/uint63_63.ml
index 8d052d6593..d017dafd3c 100644
--- a/kernel/uint63_63.ml
+++ b/kernel/uint63_63.ml
@@ -53,6 +53,10 @@ let l_sl x y =
let l_sr x y =
if 0 <= y && y < 63 then x lsr y else 0
+ (* arithmetic shift (for sint63) *)
+let a_sr x y =
+ if 0 <= y && y < 63 then x asr y else 0
+
let l_and x y = x land y
[@@ocaml.inline always]
@@ -84,6 +88,14 @@ let rem (x : int) (y : int) =
let diveucl x y = (div x y, rem x y)
+ (* signed division *)
+let divs (x : int) (y : int) =
+ if y = 0 then 0 else x / y
+
+ (* modulo *)
+let rems (x : int) (y : int) =
+ if y = 0 then 0 else x mod y
+
let addmuldiv p x y =
l_or (l_sl x p) (l_sr y (uint_size - p))
@@ -96,6 +108,15 @@ let le (x : int) (y : int) =
(x lxor 0x4000000000000000) <= (y lxor 0x4000000000000000)
[@@ocaml.inline always]
+ (* signed comparison *)
+let lts (x : int) (y : int) =
+ x < y
+[@@ocaml.inline always]
+
+let les (x : int) (y : int) =
+ x <= y
+[@@ocaml.inline always]
+
let to_int_min n m =
if lt n m then n else m
[@@ocaml.inline always]
@@ -175,9 +196,10 @@ let equal (x : int) (y : int) = x = y
let compare (x:int) (y:int) =
let x = x lxor 0x4000000000000000 in
let y = y lxor 0x4000000000000000 in
- if x > y then 1
- else if y > x then -1
- else 0
+ Int.compare x y
+
+let compares (x : int) (y : int) =
+ Int.compare x y
(* head tail *)