12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- /*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
- #include "os.h"
- #include <mp.h>
- #include "dat.h"
- #define VLDIGITS (sizeof(int64_t)/sizeof(mpdigit))
- /*
- * this code assumes that a vlong is an integral number of
- * mpdigits long.
- */
- mpint*
- uvtomp(uint64_t v, mpint *b)
- {
- int s;
- if(b == nil)
- b = mpnew(VLDIGITS*sizeof(mpdigit));
- else
- mpbits(b, VLDIGITS*sizeof(mpdigit));
- mpassign(mpzero, b);
- if(v == 0)
- return b;
- for(s = 0; s < VLDIGITS && v != 0; s++){
- b->p[s] = v;
- v >>= sizeof(mpdigit)*8;
- }
- b->top = s;
- return b;
- }
- uint64_t
- mptouv(mpint *b)
- {
- uint64_t v;
- int s;
- if(b->top == 0)
- return 0LL;
- mpnorm(b);
- if(b->top > VLDIGITS)
- return MAXVLONG;
- v = 0ULL;
- for(s = 0; s < b->top; s++)
- v |= (uint64_t)b->p[s]<<(s*sizeof(mpdigit)*8);
- return v;
- }
|