1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374(**************************************************************************)(* This file is part of the Codex semantics library. *)(* *)(* Copyright (C) 2013-2025 *)(* CEA (Commissariat à l'énergie atomique et aux énergies *)(* alternatives) *)(* *)(* you can redistribute it and/or modify it under the terms of the GNU *)(* Lesser General Public License as published by the Free Software *)(* Foundation, version 2.1. *)(* *)(* It is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)(* GNU Lesser General Public License for more details. *)(* *)(* See the GNU Lesser General Public License version 2.1 *)(* for more details (enclosed in the file LICENSE). *)(* *)(**************************************************************************)(* We pack the flags as a single integer, not only for performance,
but also so that it is easy to add or remove flags. *)(* Note:
- nsw means no signed wrap: the result does not overflow in a signed representation.
- nuw means no unsigned wrap: the result does not overflow in an unsigned representation.
- nusw means no unsigned/signed wrap: the first argument is unsigned, the second is signed,
and the computation must not overflow.
*)moduleBimul:sigtypet=privateinttypeunpacked={nsw:bool;nuw:bool}valpack:nsw:bool->nuw:bool->tvalunpack:t->unpackedend=structtypet=inttypeunpacked={nsw:bool;nuw:bool}letpack~nsw~nuw=(ifnuwthen2else0)+(ifnswthen1else0)letis_nswf=(fland1)=1letis_nuwf=(fland2)=2letunpackf={nsw=is_nswf;nuw=is_nuwf}endmoduleBshl:moduletypeofBimul=BimulmoduleBiadd:sigtypet=privateinttypeunpacked={nsw:bool;nuw:bool;nusw:bool}valno_overflow:tvalpack:nsw:bool->nuw:bool->nusw:bool->tvalunpack:t->unpackedvalis_nsw:t->boolvalis_nuw:t->boolend=structtypet=inttypeunpacked={nsw:bool;nuw:bool;nusw:bool}letpack~nsw~nuw~nusw=(ifnuswthen4else0)lor(ifnuwthen2else0)lor(ifnswthen1else0)letno_overflow=pack~nsw:false~nuw:false~nusw:falseletis_nswf=(fland1)=1letis_nuwf=(fland2)=2letis_nuswf=(fland4)=4letunpackf={nsw=is_nswf;nuw=is_nuwf;nusw=is_nuswf}endmoduleBisub=Biadd