Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .scripts/FStar.IntN.fstip
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ val shift_arithmetic_right (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.Int.shift_arithmetic_right (v a) (UInt32.v s) = v c))

(** Shift left on the two's complement representation.
Unlike [shift_left], this operates on any signed integer (including negative values).
This matches the semantics of [<<] on signed integers in C++ and Rust. *)
val shift_arithmetic_left (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.Int.shift_arithmetic_left (v a) (UInt32.v s) = v c))

(* Rotate operators *)

(** Rotate right.
Expand Down Expand Up @@ -125,6 +132,7 @@ inline_for_extraction unfold let ( |^ ) = logor
inline_for_extraction unfold let ( <<^ ) = shift_left
inline_for_extraction unfold let ( >>^ ) = shift_right
inline_for_extraction unfold let ( >>>^) = shift_arithmetic_right
inline_for_extraction unfold let ( <<<^) = shift_arithmetic_left
inline_for_extraction unfold let ( =^ ) = eq
inline_for_extraction unfold let ( <>^ ) = ne
inline_for_extraction unfold let ( >^ ) = gt
Expand Down
2 changes: 2 additions & 0 deletions .scripts/FStar.IntN.fstp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ let shift_left a s = Mk (shift_left (v a) (UInt32.v s))

let shift_arithmetic_right a s = Mk (shift_arithmetic_right (v a) (UInt32.v s))

let shift_arithmetic_left a s = Mk (shift_arithmetic_left (v a) (UInt32.v s))

let rotate_right a s = Mk (rotate_right (v a) (UInt32.v s))

let rotate_left a s = Mk (rotate_left (v a) (UInt32.v s))
Expand Down
4 changes: 4 additions & 0 deletions ulib/FStar.Int.fst
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ let shift_arithmetic_right_lemma_1 #n a s i = ()

let shift_arithmetic_right_lemma_2 #n a s i = ()

let shift_arithmetic_left_lemma_1 #n a s i = ()

let shift_arithmetic_left_lemma_2 #n a s i = ()

(* Rotate operators lemmas *)

let rotate_left_lemma #n a s i = ()
Expand Down
17 changes: 17 additions & 0 deletions ulib/FStar.Int.fsti
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,13 @@ let shift_right (#n:pos) (a:int_t n{0 <= a}) (s:nat) : Tot (int_t n) =
let shift_arithmetic_right (#n:pos) (a:int_t n) (s:nat) : Tot (int_t n) =
from_vec (shift_arithmetic_right_vec #n (to_vec #n a) s)

(** Shift left on the two's complement representation.
Unlike [shift_left], this operates on any signed integer (including negative values).
The result is the same bitwise operation: shift bits left and fill with zeroes.
This matches the semantics of [<<] on signed integers in C++ and Rust. *)
let shift_arithmetic_left (#n:pos) (a:int_t n) (s:nat) : Tot (int_t n) =
from_vec (shift_left_vec #n (to_vec #n a) s)

(* Rotate operators *)

(** Rotate left.
Expand Down Expand Up @@ -421,6 +428,16 @@ val shift_arithmetic_right_lemma_2: #n:pos -> a:int_t n -> s:nat -> i:nat{i < n
(ensures (nth (shift_arithmetic_right #n a s) i = nth #n a (i - s)))
[SMTPat (nth (shift_arithmetic_right #n a s) i)]

val shift_arithmetic_left_lemma_1: #n:pos -> a:int_t n -> s:nat -> i:nat{i < n && i >= n - s} ->
Lemma (requires True)
(ensures (nth (shift_arithmetic_left #n a s) i = false))
[SMTPat (nth (shift_arithmetic_left #n a s) i)]

val shift_arithmetic_left_lemma_2: #n:pos -> a:int_t n -> s:nat -> i:nat{i < n && i < n - s} ->
Lemma (requires True)
(ensures (nth (shift_arithmetic_left #n a s) i = nth #n a (i + s)))
[SMTPat (nth (shift_arithmetic_left #n a s) i)]

(* Rotate operators lemmas *)
val rotate_left_lemma: #n:pos -> a:int_t n -> s:nat -> i:nat{i < n} ->
Lemma (requires True)
Expand Down
2 changes: 2 additions & 0 deletions ulib/FStar.Int128.fst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ let shift_left a s = Mk (shift_left (v a) (UInt32.v s))

let shift_arithmetic_right a s = Mk (shift_arithmetic_right (v a) (UInt32.v s))

let shift_arithmetic_left a s = Mk (shift_arithmetic_left (v a) (UInt32.v s))

let rotate_right a s = Mk (rotate_right (v a) (UInt32.v s))

let rotate_left a s = Mk (rotate_left (v a) (UInt32.v s))
Expand Down
8 changes: 8 additions & 0 deletions ulib/FStar.Int128.fsti
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ val shift_arithmetic_right (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.Int.shift_arithmetic_right (v a) (UInt32.v s) = v c))

(** Shift left on the two's complement representation.
Unlike [shift_left], this operates on any signed integer (including negative values).
This matches the semantics of [<<] on signed integers in C++ and Rust. *)
val shift_arithmetic_left (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.Int.shift_arithmetic_left (v a) (UInt32.v s) = v c))

(* Rotate operators *)

(** Rotate right.
Expand Down Expand Up @@ -146,6 +153,7 @@ inline_for_extraction unfold let ( |^ ) = logor
inline_for_extraction unfold let ( <<^ ) = shift_left
inline_for_extraction unfold let ( >>^ ) = shift_right
inline_for_extraction unfold let ( >>>^) = shift_arithmetic_right
inline_for_extraction unfold let ( <<<^) = shift_arithmetic_left
inline_for_extraction unfold let ( =^ ) = eq
inline_for_extraction unfold let ( <>^ ) = ne
inline_for_extraction unfold let ( >^ ) = gt
Expand Down
2 changes: 2 additions & 0 deletions ulib/FStar.Int16.fst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ let shift_left a s = Mk (shift_left (v a) (UInt32.v s))

let shift_arithmetic_right a s = Mk (shift_arithmetic_right (v a) (UInt32.v s))

let shift_arithmetic_left a s = Mk (shift_arithmetic_left (v a) (UInt32.v s))

let rotate_right a s = Mk (rotate_right (v a) (UInt32.v s))

let rotate_left a s = Mk (rotate_left (v a) (UInt32.v s))
Expand Down
8 changes: 8 additions & 0 deletions ulib/FStar.Int16.fsti
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ val shift_arithmetic_right (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.Int.shift_arithmetic_right (v a) (UInt32.v s) = v c))

(** Shift left on the two's complement representation.
Unlike [shift_left], this operates on any signed integer (including negative values).
This matches the semantics of [<<] on signed integers in C++ and Rust. *)
val shift_arithmetic_left (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.Int.shift_arithmetic_left (v a) (UInt32.v s) = v c))

(* Rotate operators *)

(** Rotate right.
Expand Down Expand Up @@ -146,6 +153,7 @@ inline_for_extraction unfold let ( |^ ) = logor
inline_for_extraction unfold let ( <<^ ) = shift_left
inline_for_extraction unfold let ( >>^ ) = shift_right
inline_for_extraction unfold let ( >>>^) = shift_arithmetic_right
inline_for_extraction unfold let ( <<<^) = shift_arithmetic_left
inline_for_extraction unfold let ( =^ ) = eq
inline_for_extraction unfold let ( <>^ ) = ne
inline_for_extraction unfold let ( >^ ) = gt
Expand Down
2 changes: 2 additions & 0 deletions ulib/FStar.Int32.fst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ let shift_left a s = Mk (shift_left (v a) (UInt32.v s))

let shift_arithmetic_right a s = Mk (shift_arithmetic_right (v a) (UInt32.v s))

let shift_arithmetic_left a s = Mk (shift_arithmetic_left (v a) (UInt32.v s))

let rotate_right a s = Mk (rotate_right (v a) (UInt32.v s))

let rotate_left a s = Mk (rotate_left (v a) (UInt32.v s))
Expand Down
8 changes: 8 additions & 0 deletions ulib/FStar.Int32.fsti
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ val shift_arithmetic_right (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.Int.shift_arithmetic_right (v a) (UInt32.v s) = v c))

(** Shift left on the two's complement representation.
Unlike [shift_left], this operates on any signed integer (including negative values).
This matches the semantics of [<<] on signed integers in C++ and Rust. *)
val shift_arithmetic_left (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.Int.shift_arithmetic_left (v a) (UInt32.v s) = v c))

(* Rotate operators *)

(** Rotate right.
Expand Down Expand Up @@ -146,6 +153,7 @@ inline_for_extraction unfold let ( |^ ) = logor
inline_for_extraction unfold let ( <<^ ) = shift_left
inline_for_extraction unfold let ( >>^ ) = shift_right
inline_for_extraction unfold let ( >>>^) = shift_arithmetic_right
inline_for_extraction unfold let ( <<<^) = shift_arithmetic_left
inline_for_extraction unfold let ( =^ ) = eq
inline_for_extraction unfold let ( <>^ ) = ne
inline_for_extraction unfold let ( >^ ) = gt
Expand Down
2 changes: 2 additions & 0 deletions ulib/FStar.Int64.fst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ let shift_left a s = Mk (shift_left (v a) (UInt32.v s))

let shift_arithmetic_right a s = Mk (shift_arithmetic_right (v a) (UInt32.v s))

let shift_arithmetic_left a s = Mk (shift_arithmetic_left (v a) (UInt32.v s))

let rotate_right a s = Mk (rotate_right (v a) (UInt32.v s))

let rotate_left a s = Mk (rotate_left (v a) (UInt32.v s))
Expand Down
8 changes: 8 additions & 0 deletions ulib/FStar.Int64.fsti
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ val shift_arithmetic_right (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.Int.shift_arithmetic_right (v a) (UInt32.v s) = v c))

(** Shift left on the two's complement representation.
Unlike [shift_left], this operates on any signed integer (including negative values).
This matches the semantics of [<<] on signed integers in C++ and Rust. *)
val shift_arithmetic_left (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.Int.shift_arithmetic_left (v a) (UInt32.v s) = v c))

(* Rotate operators *)

(** Rotate right.
Expand Down Expand Up @@ -146,6 +153,7 @@ inline_for_extraction unfold let ( |^ ) = logor
inline_for_extraction unfold let ( <<^ ) = shift_left
inline_for_extraction unfold let ( >>^ ) = shift_right
inline_for_extraction unfold let ( >>>^) = shift_arithmetic_right
inline_for_extraction unfold let ( <<<^) = shift_arithmetic_left
inline_for_extraction unfold let ( =^ ) = eq
inline_for_extraction unfold let ( <>^ ) = ne
inline_for_extraction unfold let ( >^ ) = gt
Expand Down
2 changes: 2 additions & 0 deletions ulib/FStar.Int8.fst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ let shift_left a s = Mk (shift_left (v a) (UInt32.v s))

let shift_arithmetic_right a s = Mk (shift_arithmetic_right (v a) (UInt32.v s))

let shift_arithmetic_left a s = Mk (shift_arithmetic_left (v a) (UInt32.v s))

let rotate_right a s = Mk (rotate_right (v a) (UInt32.v s))

let rotate_left a s = Mk (rotate_left (v a) (UInt32.v s))
Expand Down
8 changes: 8 additions & 0 deletions ulib/FStar.Int8.fsti
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ val shift_arithmetic_right (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.Int.shift_arithmetic_right (v a) (UInt32.v s) = v c))

(** Shift left on the two's complement representation.
Unlike [shift_left], this operates on any signed integer (including negative values).
This matches the semantics of [<<] on signed integers in C++ and Rust. *)
val shift_arithmetic_left (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.Int.shift_arithmetic_left (v a) (UInt32.v s) = v c))

(* Rotate operators *)

(** Rotate right.
Expand Down Expand Up @@ -146,6 +153,7 @@ inline_for_extraction unfold let ( |^ ) = logor
inline_for_extraction unfold let ( <<^ ) = shift_left
inline_for_extraction unfold let ( >>^ ) = shift_right
inline_for_extraction unfold let ( >>>^) = shift_arithmetic_right
inline_for_extraction unfold let ( <<<^) = shift_arithmetic_left
inline_for_extraction unfold let ( =^ ) = eq
inline_for_extraction unfold let ( <>^ ) = ne
inline_for_extraction unfold let ( >^ ) = gt
Expand Down
Loading