1a8e1175bSopenharmony_ci/* Copyright (c) INRIA and Microsoft Corporation. All rights reserved.
2a8e1175bSopenharmony_ci   Licensed under the Apache 2.0 License. */
3a8e1175bSopenharmony_ci
4a8e1175bSopenharmony_ci/* This file was generated by KreMLin <https://github.com/FStarLang/kremlin>
5a8e1175bSopenharmony_ci * KreMLin invocation: ../krml -fc89 -fparentheses -fno-shadow -header /mnt/e/everest/verify/hdrB9w -minimal -fparentheses -fcurly-braces -fno-shadow -header copyright-header.txt -minimal -tmpdir extracted -warn-error +9+11 -skip-compilation -extract-uints -add-include <inttypes.h> -add-include "kremlib.h" -add-include "kremlin/internal/compat.h" extracted/prims.krml extracted/FStar_Pervasives_Native.krml extracted/FStar_Pervasives.krml extracted/FStar_Mul.krml extracted/FStar_Squash.krml extracted/FStar_Classical.krml extracted/FStar_StrongExcludedMiddle.krml extracted/FStar_FunctionalExtensionality.krml extracted/FStar_List_Tot_Base.krml extracted/FStar_List_Tot_Properties.krml extracted/FStar_List_Tot.krml extracted/FStar_Seq_Base.krml extracted/FStar_Seq_Properties.krml extracted/FStar_Seq.krml extracted/FStar_Math_Lib.krml extracted/FStar_Math_Lemmas.krml extracted/FStar_BitVector.krml extracted/FStar_UInt.krml extracted/FStar_UInt32.krml extracted/FStar_Int.krml extracted/FStar_Int16.krml extracted/FStar_Preorder.krml extracted/FStar_Ghost.krml extracted/FStar_ErasedLogic.krml extracted/FStar_UInt64.krml extracted/FStar_Set.krml extracted/FStar_PropositionalExtensionality.krml extracted/FStar_PredicateExtensionality.krml extracted/FStar_TSet.krml extracted/FStar_Monotonic_Heap.krml extracted/FStar_Heap.krml extracted/FStar_Map.krml extracted/FStar_Monotonic_HyperHeap.krml extracted/FStar_Monotonic_HyperStack.krml extracted/FStar_HyperStack.krml extracted/FStar_Monotonic_Witnessed.krml extracted/FStar_HyperStack_ST.krml extracted/FStar_HyperStack_All.krml extracted/FStar_Date.krml extracted/FStar_Universe.krml extracted/FStar_GSet.krml extracted/FStar_ModifiesGen.krml extracted/LowStar_Monotonic_Buffer.krml extracted/LowStar_Buffer.krml extracted/Spec_Loops.krml extracted/LowStar_BufferOps.krml extracted/C_Loops.krml extracted/FStar_UInt8.krml extracted/FStar_Kremlin_Endianness.krml extracted/FStar_UInt63.krml extracted/FStar_Exn.krml extracted/FStar_ST.krml extracted/FStar_All.krml extracted/FStar_Dyn.krml extracted/FStar_Int63.krml extracted/FStar_Int64.krml extracted/FStar_Int32.krml extracted/FStar_Int8.krml extracted/FStar_UInt16.krml extracted/FStar_Int_Cast.krml extracted/FStar_UInt128.krml extracted/C_Endianness.krml extracted/FStar_List.krml extracted/FStar_Float.krml extracted/FStar_IO.krml extracted/C.krml extracted/FStar_Char.krml extracted/FStar_String.krml extracted/LowStar_Modifies.krml extracted/C_String.krml extracted/FStar_Bytes.krml extracted/FStar_HyperStack_IO.krml extracted/C_Failure.krml extracted/TestLib.krml extracted/FStar_Int_Cast_Full.krml
6a8e1175bSopenharmony_ci * F* version: 059db0c8
7a8e1175bSopenharmony_ci * KreMLin version: 916c37ac
8a8e1175bSopenharmony_ci */
9a8e1175bSopenharmony_ci
10a8e1175bSopenharmony_ci
11a8e1175bSopenharmony_ci#include "FStar_UInt128.h"
12a8e1175bSopenharmony_ci#include "kremlin/c_endianness.h"
13a8e1175bSopenharmony_ci#include "FStar_UInt64_FStar_UInt32_FStar_UInt16_FStar_UInt8.h"
14a8e1175bSopenharmony_ci
15a8e1175bSopenharmony_ciuint64_t FStar_UInt128___proj__Mkuint128__item__low(FStar_UInt128_uint128 projectee)
16a8e1175bSopenharmony_ci{
17a8e1175bSopenharmony_ci  return projectee.low;
18a8e1175bSopenharmony_ci}
19a8e1175bSopenharmony_ci
20a8e1175bSopenharmony_ciuint64_t FStar_UInt128___proj__Mkuint128__item__high(FStar_UInt128_uint128 projectee)
21a8e1175bSopenharmony_ci{
22a8e1175bSopenharmony_ci  return projectee.high;
23a8e1175bSopenharmony_ci}
24a8e1175bSopenharmony_ci
25a8e1175bSopenharmony_cistatic uint64_t FStar_UInt128_constant_time_carry(uint64_t a, uint64_t b)
26a8e1175bSopenharmony_ci{
27a8e1175bSopenharmony_ci  return (a ^ ((a ^ b) | ((a - b) ^ b))) >> (uint32_t)63U;
28a8e1175bSopenharmony_ci}
29a8e1175bSopenharmony_ci
30a8e1175bSopenharmony_cistatic uint64_t FStar_UInt128_carry(uint64_t a, uint64_t b)
31a8e1175bSopenharmony_ci{
32a8e1175bSopenharmony_ci  return FStar_UInt128_constant_time_carry(a, b);
33a8e1175bSopenharmony_ci}
34a8e1175bSopenharmony_ci
35a8e1175bSopenharmony_ciFStar_UInt128_uint128 FStar_UInt128_add(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b)
36a8e1175bSopenharmony_ci{
37a8e1175bSopenharmony_ci  FStar_UInt128_uint128
38a8e1175bSopenharmony_ci  flat = { a.low + b.low, a.high + b.high + FStar_UInt128_carry(a.low + b.low, b.low) };
39a8e1175bSopenharmony_ci  return flat;
40a8e1175bSopenharmony_ci}
41a8e1175bSopenharmony_ci
42a8e1175bSopenharmony_ciFStar_UInt128_uint128
43a8e1175bSopenharmony_ciFStar_UInt128_add_underspec(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b)
44a8e1175bSopenharmony_ci{
45a8e1175bSopenharmony_ci  FStar_UInt128_uint128
46a8e1175bSopenharmony_ci  flat = { a.low + b.low, a.high + b.high + FStar_UInt128_carry(a.low + b.low, b.low) };
47a8e1175bSopenharmony_ci  return flat;
48a8e1175bSopenharmony_ci}
49a8e1175bSopenharmony_ci
50a8e1175bSopenharmony_ciFStar_UInt128_uint128 FStar_UInt128_add_mod(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b)
51a8e1175bSopenharmony_ci{
52a8e1175bSopenharmony_ci  FStar_UInt128_uint128
53a8e1175bSopenharmony_ci  flat = { a.low + b.low, a.high + b.high + FStar_UInt128_carry(a.low + b.low, b.low) };
54a8e1175bSopenharmony_ci  return flat;
55a8e1175bSopenharmony_ci}
56a8e1175bSopenharmony_ci
57a8e1175bSopenharmony_ciFStar_UInt128_uint128 FStar_UInt128_sub(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b)
58a8e1175bSopenharmony_ci{
59a8e1175bSopenharmony_ci  FStar_UInt128_uint128
60a8e1175bSopenharmony_ci  flat = { a.low - b.low, a.high - b.high - FStar_UInt128_carry(a.low, a.low - b.low) };
61a8e1175bSopenharmony_ci  return flat;
62a8e1175bSopenharmony_ci}
63a8e1175bSopenharmony_ci
64a8e1175bSopenharmony_ciFStar_UInt128_uint128
65a8e1175bSopenharmony_ciFStar_UInt128_sub_underspec(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b)
66a8e1175bSopenharmony_ci{
67a8e1175bSopenharmony_ci  FStar_UInt128_uint128
68a8e1175bSopenharmony_ci  flat = { a.low - b.low, a.high - b.high - FStar_UInt128_carry(a.low, a.low - b.low) };
69a8e1175bSopenharmony_ci  return flat;
70a8e1175bSopenharmony_ci}
71a8e1175bSopenharmony_ci
72a8e1175bSopenharmony_cistatic FStar_UInt128_uint128
73a8e1175bSopenharmony_ciFStar_UInt128_sub_mod_impl(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b)
74a8e1175bSopenharmony_ci{
75a8e1175bSopenharmony_ci  FStar_UInt128_uint128
76a8e1175bSopenharmony_ci  flat = { a.low - b.low, a.high - b.high - FStar_UInt128_carry(a.low, a.low - b.low) };
77a8e1175bSopenharmony_ci  return flat;
78a8e1175bSopenharmony_ci}
79a8e1175bSopenharmony_ci
80a8e1175bSopenharmony_ciFStar_UInt128_uint128 FStar_UInt128_sub_mod(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b)
81a8e1175bSopenharmony_ci{
82a8e1175bSopenharmony_ci  return FStar_UInt128_sub_mod_impl(a, b);
83a8e1175bSopenharmony_ci}
84a8e1175bSopenharmony_ci
85a8e1175bSopenharmony_ciFStar_UInt128_uint128 FStar_UInt128_logand(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b)
86a8e1175bSopenharmony_ci{
87a8e1175bSopenharmony_ci  FStar_UInt128_uint128 flat = { a.low & b.low, a.high & b.high };
88a8e1175bSopenharmony_ci  return flat;
89a8e1175bSopenharmony_ci}
90a8e1175bSopenharmony_ci
91a8e1175bSopenharmony_ciFStar_UInt128_uint128 FStar_UInt128_logxor(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b)
92a8e1175bSopenharmony_ci{
93a8e1175bSopenharmony_ci  FStar_UInt128_uint128 flat = { a.low ^ b.low, a.high ^ b.high };
94a8e1175bSopenharmony_ci  return flat;
95a8e1175bSopenharmony_ci}
96a8e1175bSopenharmony_ci
97a8e1175bSopenharmony_ciFStar_UInt128_uint128 FStar_UInt128_logor(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b)
98a8e1175bSopenharmony_ci{
99a8e1175bSopenharmony_ci  FStar_UInt128_uint128 flat = { a.low | b.low, a.high | b.high };
100a8e1175bSopenharmony_ci  return flat;
101a8e1175bSopenharmony_ci}
102a8e1175bSopenharmony_ci
103a8e1175bSopenharmony_ciFStar_UInt128_uint128 FStar_UInt128_lognot(FStar_UInt128_uint128 a)
104a8e1175bSopenharmony_ci{
105a8e1175bSopenharmony_ci  FStar_UInt128_uint128 flat = { ~a.low, ~a.high };
106a8e1175bSopenharmony_ci  return flat;
107a8e1175bSopenharmony_ci}
108a8e1175bSopenharmony_ci
109a8e1175bSopenharmony_cistatic uint32_t FStar_UInt128_u32_64 = (uint32_t)64U;
110a8e1175bSopenharmony_ci
111a8e1175bSopenharmony_cistatic uint64_t FStar_UInt128_add_u64_shift_left(uint64_t hi, uint64_t lo, uint32_t s)
112a8e1175bSopenharmony_ci{
113a8e1175bSopenharmony_ci  return (hi << s) + (lo >> (FStar_UInt128_u32_64 - s));
114a8e1175bSopenharmony_ci}
115a8e1175bSopenharmony_ci
116a8e1175bSopenharmony_cistatic uint64_t FStar_UInt128_add_u64_shift_left_respec(uint64_t hi, uint64_t lo, uint32_t s)
117a8e1175bSopenharmony_ci{
118a8e1175bSopenharmony_ci  return FStar_UInt128_add_u64_shift_left(hi, lo, s);
119a8e1175bSopenharmony_ci}
120a8e1175bSopenharmony_ci
121a8e1175bSopenharmony_cistatic FStar_UInt128_uint128
122a8e1175bSopenharmony_ciFStar_UInt128_shift_left_small(FStar_UInt128_uint128 a, uint32_t s)
123a8e1175bSopenharmony_ci{
124a8e1175bSopenharmony_ci  if (s == (uint32_t)0U)
125a8e1175bSopenharmony_ci  {
126a8e1175bSopenharmony_ci    return a;
127a8e1175bSopenharmony_ci  }
128a8e1175bSopenharmony_ci  else
129a8e1175bSopenharmony_ci  {
130a8e1175bSopenharmony_ci    FStar_UInt128_uint128
131a8e1175bSopenharmony_ci    flat = { a.low << s, FStar_UInt128_add_u64_shift_left_respec(a.high, a.low, s) };
132a8e1175bSopenharmony_ci    return flat;
133a8e1175bSopenharmony_ci  }
134a8e1175bSopenharmony_ci}
135a8e1175bSopenharmony_ci
136a8e1175bSopenharmony_cistatic FStar_UInt128_uint128
137a8e1175bSopenharmony_ciFStar_UInt128_shift_left_large(FStar_UInt128_uint128 a, uint32_t s)
138a8e1175bSopenharmony_ci{
139a8e1175bSopenharmony_ci  FStar_UInt128_uint128 flat = { (uint64_t)0U, a.low << (s - FStar_UInt128_u32_64) };
140a8e1175bSopenharmony_ci  return flat;
141a8e1175bSopenharmony_ci}
142a8e1175bSopenharmony_ci
143a8e1175bSopenharmony_ciFStar_UInt128_uint128 FStar_UInt128_shift_left(FStar_UInt128_uint128 a, uint32_t s)
144a8e1175bSopenharmony_ci{
145a8e1175bSopenharmony_ci  if (s < FStar_UInt128_u32_64)
146a8e1175bSopenharmony_ci  {
147a8e1175bSopenharmony_ci    return FStar_UInt128_shift_left_small(a, s);
148a8e1175bSopenharmony_ci  }
149a8e1175bSopenharmony_ci  else
150a8e1175bSopenharmony_ci  {
151a8e1175bSopenharmony_ci    return FStar_UInt128_shift_left_large(a, s);
152a8e1175bSopenharmony_ci  }
153a8e1175bSopenharmony_ci}
154a8e1175bSopenharmony_ci
155a8e1175bSopenharmony_cistatic uint64_t FStar_UInt128_add_u64_shift_right(uint64_t hi, uint64_t lo, uint32_t s)
156a8e1175bSopenharmony_ci{
157a8e1175bSopenharmony_ci  return (lo >> s) + (hi << (FStar_UInt128_u32_64 - s));
158a8e1175bSopenharmony_ci}
159a8e1175bSopenharmony_ci
160a8e1175bSopenharmony_cistatic uint64_t FStar_UInt128_add_u64_shift_right_respec(uint64_t hi, uint64_t lo, uint32_t s)
161a8e1175bSopenharmony_ci{
162a8e1175bSopenharmony_ci  return FStar_UInt128_add_u64_shift_right(hi, lo, s);
163a8e1175bSopenharmony_ci}
164a8e1175bSopenharmony_ci
165a8e1175bSopenharmony_cistatic FStar_UInt128_uint128
166a8e1175bSopenharmony_ciFStar_UInt128_shift_right_small(FStar_UInt128_uint128 a, uint32_t s)
167a8e1175bSopenharmony_ci{
168a8e1175bSopenharmony_ci  if (s == (uint32_t)0U)
169a8e1175bSopenharmony_ci  {
170a8e1175bSopenharmony_ci    return a;
171a8e1175bSopenharmony_ci  }
172a8e1175bSopenharmony_ci  else
173a8e1175bSopenharmony_ci  {
174a8e1175bSopenharmony_ci    FStar_UInt128_uint128
175a8e1175bSopenharmony_ci    flat = { FStar_UInt128_add_u64_shift_right_respec(a.high, a.low, s), a.high >> s };
176a8e1175bSopenharmony_ci    return flat;
177a8e1175bSopenharmony_ci  }
178a8e1175bSopenharmony_ci}
179a8e1175bSopenharmony_ci
180a8e1175bSopenharmony_cistatic FStar_UInt128_uint128
181a8e1175bSopenharmony_ciFStar_UInt128_shift_right_large(FStar_UInt128_uint128 a, uint32_t s)
182a8e1175bSopenharmony_ci{
183a8e1175bSopenharmony_ci  FStar_UInt128_uint128 flat = { a.high >> (s - FStar_UInt128_u32_64), (uint64_t)0U };
184a8e1175bSopenharmony_ci  return flat;
185a8e1175bSopenharmony_ci}
186a8e1175bSopenharmony_ci
187a8e1175bSopenharmony_ciFStar_UInt128_uint128 FStar_UInt128_shift_right(FStar_UInt128_uint128 a, uint32_t s)
188a8e1175bSopenharmony_ci{
189a8e1175bSopenharmony_ci  if (s < FStar_UInt128_u32_64)
190a8e1175bSopenharmony_ci  {
191a8e1175bSopenharmony_ci    return FStar_UInt128_shift_right_small(a, s);
192a8e1175bSopenharmony_ci  }
193a8e1175bSopenharmony_ci  else
194a8e1175bSopenharmony_ci  {
195a8e1175bSopenharmony_ci    return FStar_UInt128_shift_right_large(a, s);
196a8e1175bSopenharmony_ci  }
197a8e1175bSopenharmony_ci}
198a8e1175bSopenharmony_ci
199a8e1175bSopenharmony_cibool FStar_UInt128_eq(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b)
200a8e1175bSopenharmony_ci{
201a8e1175bSopenharmony_ci  return a.low == b.low && a.high == b.high;
202a8e1175bSopenharmony_ci}
203a8e1175bSopenharmony_ci
204a8e1175bSopenharmony_cibool FStar_UInt128_gt(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b)
205a8e1175bSopenharmony_ci{
206a8e1175bSopenharmony_ci  return a.high > b.high || (a.high == b.high && a.low > b.low);
207a8e1175bSopenharmony_ci}
208a8e1175bSopenharmony_ci
209a8e1175bSopenharmony_cibool FStar_UInt128_lt(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b)
210a8e1175bSopenharmony_ci{
211a8e1175bSopenharmony_ci  return a.high < b.high || (a.high == b.high && a.low < b.low);
212a8e1175bSopenharmony_ci}
213a8e1175bSopenharmony_ci
214a8e1175bSopenharmony_cibool FStar_UInt128_gte(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b)
215a8e1175bSopenharmony_ci{
216a8e1175bSopenharmony_ci  return a.high > b.high || (a.high == b.high && a.low >= b.low);
217a8e1175bSopenharmony_ci}
218a8e1175bSopenharmony_ci
219a8e1175bSopenharmony_cibool FStar_UInt128_lte(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b)
220a8e1175bSopenharmony_ci{
221a8e1175bSopenharmony_ci  return a.high < b.high || (a.high == b.high && a.low <= b.low);
222a8e1175bSopenharmony_ci}
223a8e1175bSopenharmony_ci
224a8e1175bSopenharmony_ciFStar_UInt128_uint128 FStar_UInt128_eq_mask(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b)
225a8e1175bSopenharmony_ci{
226a8e1175bSopenharmony_ci  FStar_UInt128_uint128
227a8e1175bSopenharmony_ci  flat =
228a8e1175bSopenharmony_ci    {
229a8e1175bSopenharmony_ci      FStar_UInt64_eq_mask(a.low,
230a8e1175bSopenharmony_ci        b.low)
231a8e1175bSopenharmony_ci      & FStar_UInt64_eq_mask(a.high, b.high),
232a8e1175bSopenharmony_ci      FStar_UInt64_eq_mask(a.low,
233a8e1175bSopenharmony_ci        b.low)
234a8e1175bSopenharmony_ci      & FStar_UInt64_eq_mask(a.high, b.high)
235a8e1175bSopenharmony_ci    };
236a8e1175bSopenharmony_ci  return flat;
237a8e1175bSopenharmony_ci}
238a8e1175bSopenharmony_ci
239a8e1175bSopenharmony_ciFStar_UInt128_uint128 FStar_UInt128_gte_mask(FStar_UInt128_uint128 a, FStar_UInt128_uint128 b)
240a8e1175bSopenharmony_ci{
241a8e1175bSopenharmony_ci  FStar_UInt128_uint128
242a8e1175bSopenharmony_ci  flat =
243a8e1175bSopenharmony_ci    {
244a8e1175bSopenharmony_ci      (FStar_UInt64_gte_mask(a.high, b.high) & ~FStar_UInt64_eq_mask(a.high, b.high))
245a8e1175bSopenharmony_ci      | (FStar_UInt64_eq_mask(a.high, b.high) & FStar_UInt64_gte_mask(a.low, b.low)),
246a8e1175bSopenharmony_ci      (FStar_UInt64_gte_mask(a.high, b.high) & ~FStar_UInt64_eq_mask(a.high, b.high))
247a8e1175bSopenharmony_ci      | (FStar_UInt64_eq_mask(a.high, b.high) & FStar_UInt64_gte_mask(a.low, b.low))
248a8e1175bSopenharmony_ci    };
249a8e1175bSopenharmony_ci  return flat;
250a8e1175bSopenharmony_ci}
251a8e1175bSopenharmony_ci
252a8e1175bSopenharmony_ciFStar_UInt128_uint128 FStar_UInt128_uint64_to_uint128(uint64_t a)
253a8e1175bSopenharmony_ci{
254a8e1175bSopenharmony_ci  FStar_UInt128_uint128 flat = { a, (uint64_t)0U };
255a8e1175bSopenharmony_ci  return flat;
256a8e1175bSopenharmony_ci}
257a8e1175bSopenharmony_ci
258a8e1175bSopenharmony_ciuint64_t FStar_UInt128_uint128_to_uint64(FStar_UInt128_uint128 a)
259a8e1175bSopenharmony_ci{
260a8e1175bSopenharmony_ci  return a.low;
261a8e1175bSopenharmony_ci}
262a8e1175bSopenharmony_ci
263a8e1175bSopenharmony_ciFStar_UInt128_uint128
264a8e1175bSopenharmony_ci(*FStar_UInt128_op_Plus_Hat)(FStar_UInt128_uint128 x0, FStar_UInt128_uint128 x1) =
265a8e1175bSopenharmony_ci  FStar_UInt128_add;
266a8e1175bSopenharmony_ci
267a8e1175bSopenharmony_ciFStar_UInt128_uint128
268a8e1175bSopenharmony_ci(*FStar_UInt128_op_Plus_Question_Hat)(FStar_UInt128_uint128 x0, FStar_UInt128_uint128 x1) =
269a8e1175bSopenharmony_ci  FStar_UInt128_add_underspec;
270a8e1175bSopenharmony_ci
271a8e1175bSopenharmony_ciFStar_UInt128_uint128
272a8e1175bSopenharmony_ci(*FStar_UInt128_op_Plus_Percent_Hat)(FStar_UInt128_uint128 x0, FStar_UInt128_uint128 x1) =
273a8e1175bSopenharmony_ci  FStar_UInt128_add_mod;
274a8e1175bSopenharmony_ci
275a8e1175bSopenharmony_ciFStar_UInt128_uint128
276a8e1175bSopenharmony_ci(*FStar_UInt128_op_Subtraction_Hat)(FStar_UInt128_uint128 x0, FStar_UInt128_uint128 x1) =
277a8e1175bSopenharmony_ci  FStar_UInt128_sub;
278a8e1175bSopenharmony_ci
279a8e1175bSopenharmony_ciFStar_UInt128_uint128
280a8e1175bSopenharmony_ci(*FStar_UInt128_op_Subtraction_Question_Hat)(
281a8e1175bSopenharmony_ci  FStar_UInt128_uint128 x0,
282a8e1175bSopenharmony_ci  FStar_UInt128_uint128 x1
283a8e1175bSopenharmony_ci) = FStar_UInt128_sub_underspec;
284a8e1175bSopenharmony_ci
285a8e1175bSopenharmony_ciFStar_UInt128_uint128
286a8e1175bSopenharmony_ci(*FStar_UInt128_op_Subtraction_Percent_Hat)(FStar_UInt128_uint128 x0, FStar_UInt128_uint128 x1) =
287a8e1175bSopenharmony_ci  FStar_UInt128_sub_mod;
288a8e1175bSopenharmony_ci
289a8e1175bSopenharmony_ciFStar_UInt128_uint128
290a8e1175bSopenharmony_ci(*FStar_UInt128_op_Amp_Hat)(FStar_UInt128_uint128 x0, FStar_UInt128_uint128 x1) =
291a8e1175bSopenharmony_ci  FStar_UInt128_logand;
292a8e1175bSopenharmony_ci
293a8e1175bSopenharmony_ciFStar_UInt128_uint128
294a8e1175bSopenharmony_ci(*FStar_UInt128_op_Hat_Hat)(FStar_UInt128_uint128 x0, FStar_UInt128_uint128 x1) =
295a8e1175bSopenharmony_ci  FStar_UInt128_logxor;
296a8e1175bSopenharmony_ci
297a8e1175bSopenharmony_ciFStar_UInt128_uint128
298a8e1175bSopenharmony_ci(*FStar_UInt128_op_Bar_Hat)(FStar_UInt128_uint128 x0, FStar_UInt128_uint128 x1) =
299a8e1175bSopenharmony_ci  FStar_UInt128_logor;
300a8e1175bSopenharmony_ci
301a8e1175bSopenharmony_ciFStar_UInt128_uint128
302a8e1175bSopenharmony_ci(*FStar_UInt128_op_Less_Less_Hat)(FStar_UInt128_uint128 x0, uint32_t x1) =
303a8e1175bSopenharmony_ci  FStar_UInt128_shift_left;
304a8e1175bSopenharmony_ci
305a8e1175bSopenharmony_ciFStar_UInt128_uint128
306a8e1175bSopenharmony_ci(*FStar_UInt128_op_Greater_Greater_Hat)(FStar_UInt128_uint128 x0, uint32_t x1) =
307a8e1175bSopenharmony_ci  FStar_UInt128_shift_right;
308a8e1175bSopenharmony_ci
309a8e1175bSopenharmony_cibool
310a8e1175bSopenharmony_ci(*FStar_UInt128_op_Equals_Hat)(FStar_UInt128_uint128 x0, FStar_UInt128_uint128 x1) =
311a8e1175bSopenharmony_ci  FStar_UInt128_eq;
312a8e1175bSopenharmony_ci
313a8e1175bSopenharmony_cibool
314a8e1175bSopenharmony_ci(*FStar_UInt128_op_Greater_Hat)(FStar_UInt128_uint128 x0, FStar_UInt128_uint128 x1) =
315a8e1175bSopenharmony_ci  FStar_UInt128_gt;
316a8e1175bSopenharmony_ci
317a8e1175bSopenharmony_cibool
318a8e1175bSopenharmony_ci(*FStar_UInt128_op_Less_Hat)(FStar_UInt128_uint128 x0, FStar_UInt128_uint128 x1) =
319a8e1175bSopenharmony_ci  FStar_UInt128_lt;
320a8e1175bSopenharmony_ci
321a8e1175bSopenharmony_cibool
322a8e1175bSopenharmony_ci(*FStar_UInt128_op_Greater_Equals_Hat)(FStar_UInt128_uint128 x0, FStar_UInt128_uint128 x1) =
323a8e1175bSopenharmony_ci  FStar_UInt128_gte;
324a8e1175bSopenharmony_ci
325a8e1175bSopenharmony_cibool
326a8e1175bSopenharmony_ci(*FStar_UInt128_op_Less_Equals_Hat)(FStar_UInt128_uint128 x0, FStar_UInt128_uint128 x1) =
327a8e1175bSopenharmony_ci  FStar_UInt128_lte;
328a8e1175bSopenharmony_ci
329a8e1175bSopenharmony_cistatic uint64_t FStar_UInt128_u64_mod_32(uint64_t a)
330a8e1175bSopenharmony_ci{
331a8e1175bSopenharmony_ci  return a & (uint64_t)0xffffffffU;
332a8e1175bSopenharmony_ci}
333a8e1175bSopenharmony_ci
334a8e1175bSopenharmony_cistatic uint32_t FStar_UInt128_u32_32 = (uint32_t)32U;
335a8e1175bSopenharmony_ci
336a8e1175bSopenharmony_cistatic uint64_t FStar_UInt128_u32_combine(uint64_t hi, uint64_t lo)
337a8e1175bSopenharmony_ci{
338a8e1175bSopenharmony_ci  return lo + (hi << FStar_UInt128_u32_32);
339a8e1175bSopenharmony_ci}
340a8e1175bSopenharmony_ci
341a8e1175bSopenharmony_ciFStar_UInt128_uint128 FStar_UInt128_mul32(uint64_t x, uint32_t y)
342a8e1175bSopenharmony_ci{
343a8e1175bSopenharmony_ci  FStar_UInt128_uint128
344a8e1175bSopenharmony_ci  flat =
345a8e1175bSopenharmony_ci    {
346a8e1175bSopenharmony_ci      FStar_UInt128_u32_combine((x >> FStar_UInt128_u32_32)
347a8e1175bSopenharmony_ci        * (uint64_t)y
348a8e1175bSopenharmony_ci        + (FStar_UInt128_u64_mod_32(x) * (uint64_t)y >> FStar_UInt128_u32_32),
349a8e1175bSopenharmony_ci        FStar_UInt128_u64_mod_32(FStar_UInt128_u64_mod_32(x) * (uint64_t)y)),
350a8e1175bSopenharmony_ci      ((x >> FStar_UInt128_u32_32)
351a8e1175bSopenharmony_ci      * (uint64_t)y
352a8e1175bSopenharmony_ci      + (FStar_UInt128_u64_mod_32(x) * (uint64_t)y >> FStar_UInt128_u32_32))
353a8e1175bSopenharmony_ci      >> FStar_UInt128_u32_32
354a8e1175bSopenharmony_ci    };
355a8e1175bSopenharmony_ci  return flat;
356a8e1175bSopenharmony_ci}
357a8e1175bSopenharmony_ci
358a8e1175bSopenharmony_citypedef struct K___uint64_t_uint64_t_uint64_t_uint64_t_s
359a8e1175bSopenharmony_ci{
360a8e1175bSopenharmony_ci  uint64_t fst;
361a8e1175bSopenharmony_ci  uint64_t snd;
362a8e1175bSopenharmony_ci  uint64_t thd;
363a8e1175bSopenharmony_ci  uint64_t f3;
364a8e1175bSopenharmony_ci}
365a8e1175bSopenharmony_ciK___uint64_t_uint64_t_uint64_t_uint64_t;
366a8e1175bSopenharmony_ci
367a8e1175bSopenharmony_cistatic K___uint64_t_uint64_t_uint64_t_uint64_t
368a8e1175bSopenharmony_ciFStar_UInt128_mul_wide_impl_t_(uint64_t x, uint64_t y)
369a8e1175bSopenharmony_ci{
370a8e1175bSopenharmony_ci  K___uint64_t_uint64_t_uint64_t_uint64_t
371a8e1175bSopenharmony_ci  flat =
372a8e1175bSopenharmony_ci    {
373a8e1175bSopenharmony_ci      FStar_UInt128_u64_mod_32(x),
374a8e1175bSopenharmony_ci      FStar_UInt128_u64_mod_32(FStar_UInt128_u64_mod_32(x) * FStar_UInt128_u64_mod_32(y)),
375a8e1175bSopenharmony_ci      x
376a8e1175bSopenharmony_ci      >> FStar_UInt128_u32_32,
377a8e1175bSopenharmony_ci      (x >> FStar_UInt128_u32_32)
378a8e1175bSopenharmony_ci      * FStar_UInt128_u64_mod_32(y)
379a8e1175bSopenharmony_ci      + (FStar_UInt128_u64_mod_32(x) * FStar_UInt128_u64_mod_32(y) >> FStar_UInt128_u32_32)
380a8e1175bSopenharmony_ci    };
381a8e1175bSopenharmony_ci  return flat;
382a8e1175bSopenharmony_ci}
383a8e1175bSopenharmony_ci
384a8e1175bSopenharmony_cistatic uint64_t FStar_UInt128_u32_combine_(uint64_t hi, uint64_t lo)
385a8e1175bSopenharmony_ci{
386a8e1175bSopenharmony_ci  return lo + (hi << FStar_UInt128_u32_32);
387a8e1175bSopenharmony_ci}
388a8e1175bSopenharmony_ci
389a8e1175bSopenharmony_cistatic FStar_UInt128_uint128 FStar_UInt128_mul_wide_impl(uint64_t x, uint64_t y)
390a8e1175bSopenharmony_ci{
391a8e1175bSopenharmony_ci  K___uint64_t_uint64_t_uint64_t_uint64_t scrut = FStar_UInt128_mul_wide_impl_t_(x, y);
392a8e1175bSopenharmony_ci  uint64_t u1 = scrut.fst;
393a8e1175bSopenharmony_ci  uint64_t w3 = scrut.snd;
394a8e1175bSopenharmony_ci  uint64_t x_ = scrut.thd;
395a8e1175bSopenharmony_ci  uint64_t t_ = scrut.f3;
396a8e1175bSopenharmony_ci  FStar_UInt128_uint128
397a8e1175bSopenharmony_ci  flat =
398a8e1175bSopenharmony_ci    {
399a8e1175bSopenharmony_ci      FStar_UInt128_u32_combine_(u1 * (y >> FStar_UInt128_u32_32) + FStar_UInt128_u64_mod_32(t_),
400a8e1175bSopenharmony_ci        w3),
401a8e1175bSopenharmony_ci      x_
402a8e1175bSopenharmony_ci      * (y >> FStar_UInt128_u32_32)
403a8e1175bSopenharmony_ci      + (t_ >> FStar_UInt128_u32_32)
404a8e1175bSopenharmony_ci      + ((u1 * (y >> FStar_UInt128_u32_32) + FStar_UInt128_u64_mod_32(t_)) >> FStar_UInt128_u32_32)
405a8e1175bSopenharmony_ci    };
406a8e1175bSopenharmony_ci  return flat;
407a8e1175bSopenharmony_ci}
408a8e1175bSopenharmony_ci
409a8e1175bSopenharmony_ciFStar_UInt128_uint128 FStar_UInt128_mul_wide(uint64_t x, uint64_t y)
410a8e1175bSopenharmony_ci{
411a8e1175bSopenharmony_ci  return FStar_UInt128_mul_wide_impl(x, y);
412a8e1175bSopenharmony_ci}
413a8e1175bSopenharmony_ci
414