Skip to content

Commit 98155d0

Browse files
bschommerxavierleroy
authored andcommitted
Change signature of BI_i16_bswap.
The signature of `BI_i16_bswap` is unsigned short to unsigned short. Bug 38592
1 parent 1854670 commit 98155d0

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

common/Builtins0.v

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ Definition standard_builtin_sig (b: standard_builtin) : signature :=
445445
| BI_i64_bswap =>
446446
[Xlong ---> Xlong]
447447
| BI_i16_bswap =>
448-
[Xint ---> Xint]
448+
[Xint16unsigned ---> Xint16unsigned]
449449
| BI_unreachable =>
450450
mksignature nil Xvoid cc_default
451451
| BI_i64_shl | BI_i64_shr | BI_i64_sar =>
@@ -474,7 +474,7 @@ Program Definition standard_builtin_sem (b: standard_builtin) : builtin_sem (sig
474474
| BI_subl => mkbuiltin_v2t Xlong Val.subl _ _
475475
| BI_mull => mkbuiltin_v2t Xlong Val.mull' _ _
476476
| BI_i16_bswap =>
477-
mkbuiltin_n1t Tint Xint
477+
mkbuiltin_n1t Tint Xint16unsigned
478478
(fun n => Int.repr (decode_int (List.rev (encode_int 2%nat (Int.unsigned n)))))
479479
| BI_i32_bswap =>
480480
mkbuiltin_n1t Tint Xint
@@ -527,6 +527,17 @@ Qed.
527527
Next Obligation.
528528
inv H; simpl; auto. inv H0; auto.
529529
Qed.
530+
Next Obligation.
531+
set (bl := rev (encode_int 2 (Int.unsigned n))).
532+
set (x := decode_int bl).
533+
assert (length bl = 2%nat).
534+
{ unfold bl. rewrite List.rev_length. apply encode_int_length. }
535+
assert (0 <= x < two_p 16).
536+
{ generalize (int_of_bytes_range (rev_if_be bl)). rewrite rev_if_be_length, H. auto. }
537+
assert (two_p 16 < Int.max_unsigned) by (compute; auto).
538+
apply Int.eqm_samerepr. rewrite Int.unsigned_repr by lia. rewrite Zbits.Zzero_ext_mod by lia.
539+
apply Int.eqm_refl2. rewrite Z.mod_small; auto.
540+
Qed.
530541
Next Obligation.
531542
red. destruct v1; simpl; auto. destruct v2; auto. destruct orb; exact I.
532543
Qed.

0 commit comments

Comments
 (0)