aboutsummaryrefslogtreecommitdiffstats
path: root/mppa_k1c
diff options
context:
space:
mode:
authorDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2019-04-27 23:11:17 +0200
committerDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2019-04-27 23:11:17 +0200
commit13a7c021f6447cebbb6bf2716bedb7f9bcb5ddd3 (patch)
tree4d8f152d07a8eb48546c212639b93fd624735cc1 /mppa_k1c
parentc647ca1fa4edc09bea86d5088c2956954269ffa7 (diff)
downloadcompcert-kvx-13a7c021f6447cebbb6bf2716bedb7f9bcb5ddd3.tar.gz
compcert-kvx-13a7c021f6447cebbb6bf2716bedb7f9bcb5ddd3.zip
compute the highest bit in a number
Diffstat (limited to 'mppa_k1c')
-rw-r--r--mppa_k1c/ExtValues.v10
1 files changed, 10 insertions, 0 deletions
diff --git a/mppa_k1c/ExtValues.v b/mppa_k1c/ExtValues.v
index 58e8054f..2faa6b0a 100644
--- a/mppa_k1c/ExtValues.v
+++ b/mppa_k1c/ExtValues.v
@@ -82,3 +82,13 @@ Definition insfl stop start prev fld :=
Val.orl (Val.andl prev (Val.notl mask))
(Val.andl (Val.shll fld (Vint (Int.repr start))) mask)
else Vundef.
+
+Fixpoint highest_bit (x : Z) (n : nat) : N :=
+ match n with
+ | O => 0%N
+ | S n1 =>
+ let n' := N_of_nat n in
+ if Z.testbit x (Z.of_N n')
+ then n'
+ else highest_bit x n1
+ end.