/************************************************************************/ /* * The Rocq Prover / The Rocq Development Team */ /* v * Copyright INRIA, CNRS and contributors */ /* <O___,, * (see version control and CREDITS file for authors & dates) */ /* \VV/ **************************************************************/ /* // * This file is distributed under the terms of the */ /* * GNU Lesser General Public License Version 2.1 */ /* * (see LICENSE file for the text of the license) */ /************************************************************************/
/* addmuldiv(p,x,y) = x * 2^p + y / 2 ^ (63 - p) */ /* (modulo 2^63) for p <= 63 */
value uint63_addmuldiv(value p, value x, value y) {
uint64_t shiftby = uint63_of_value(p); if (shiftby >= 64) return uint63_zero();
uint64_t r = ((uint64_t)x - 1) << shiftby;
r |= ((uint64_t)y >> (63-shiftby)) | 1; return (value)r;
} #define Uint63_addmuldiv(p, x, y) (accu = uint63_addmuldiv(p, x, y))
value uint63_head0(uint64_t x) { int r = 0; if (!(x & 0xFFFFFFFF00000000)) { x <<= 32; r += 32; } if (!(x & 0xFFFF000000000000)) { x <<= 16; r += 16; } if (!(x & 0xFF00000000000000)) { x <<= 8; r += 8; } if (!(x & 0xF000000000000000)) { x <<= 4; r += 4; } if (!(x & 0xC000000000000000)) { x <<= 2; r += 2; } if (!(x & 0x8000000000000000)) { x <<=1; r += 1; } return Val_int(r);
} #define Uint63_head0(x) (accu = uint63_head0(x))
value uint63_tail0(value x) { int r = 0;
x = (uint64_t)x >> 1; if (!(x & 0xFFFFFFFF)) { x >>= 32; r += 32; } if (!(x & 0x0000FFFF)) { x >>= 16; r += 16; } if (!(x & 0x000000FF)) { x >>= 8; r += 8; } if (!(x & 0x0000000F)) { x >>= 4; r += 4; } if (!(x & 0x00000003)) { x >>= 2; r += 2; } if (!(x & 0x00000001)) { x >>=1; r += 1; } return Val_int(r);
} #define Uint63_tail0(x) (accu = uint63_tail0(x))
value uint63_mulc(value x, value y, value* h) {
x = (uint64_t)x >> 1;
y = (uint64_t)y >> 1;
uint64_t lx = x & 0xFFFFFFFF;
uint64_t ly = y & 0xFFFFFFFF;
uint64_t hx = x >> 32;
uint64_t hy = y >> 32;
uint64_t hr = hx * hy;
uint64_t lr = lx * ly;
lx *= hy;
ly *= hx;
hr += (lx >> 32) + (ly >> 32);
lx <<= 32;
lr += lx; if (lr < lx) { hr++; }
ly <<= 32;
lr += ly; if (lr < ly) { hr++; }
hr = (hr << 1) | (lr >> 63);
*h = Val_int(hr); return Val_int(lr);
} #define Uint63_mulc(x, y, h) (accu = uint63_mulc(x, y, h))
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.