| 1 |
From Coq Require Import Bool. |
| 2 |
From Coq Require Import ZArith. |
| 3 |
From Coq Require Import Lia. |
| 4 |
Require Import Crypto.Util.ZUtil.Notations. |
| 5 |
Require Import Crypto.Util.ZUtil.Definitions. |
| 6 |
Require Import Crypto.Util.ZUtil.Hints.Core. |
| 7 |
Require Import Crypto.Util.ZUtil.Testbit. |
| 8 |
|
| 9 |
Local Open Scope bool_scope. Local Open Scope Z_scope. |
| 10 |
|
| 11 |
Module Z. |
| 12 |
Lemma lor_m1'_r x : Z.lor x (-1) = -1. |
| 13 |
Proof. apply Z.lor_m1_r. Qed. |
| 14 |
#[global] |
| 15 |
Hint Rewrite lor_m1'_r : zsimplify_const zsimplify zsimplify_fast. |
| 16 |
|
| 17 |
Lemma lor_m1'_l x : Z.lor (-1) x = -1. |
| 18 |
Proof. apply Z.lor_m1_l. Qed. |
| 19 |
#[global] |
| 20 |
Hint Rewrite lor_m1'_l : zsimplify_const zsimplify zsimplify_fast. |
| 21 |
|
| 22 |
Lemma lor_add a b (Hand : a &' b = 0) : a |' b = a + b. |
| 23 |
Proof. rewrite <- Z.lxor_lor, Z.add_nocarry_lxor by assumption; reflexivity. Qed. |
| 24 |
|
| 25 |
Lemma lor_small_neg a b |
| 26 |
(Ha : - 2^b <= a < 0) |
| 27 |
(Hb : 0 < b) : |
| 28 |
2^b |' a = a. |
| 29 |
Proof. |
| 30 |
apply Z.bits_inj_iff; red; intros; rewrite Z.lor_spec. |
| 31 |
destruct (Z.eqb_spec b n); subst. |
| 32 |
- now rewrite (Testbit.Z.testbit_small_neg a), orb_true_r. |
| 33 |
- now rewrite Z.pow2_bits_false, orb_false_l. Qed. |
| 34 |
End Z. |