Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – planix.SVN – Blame – /os/branches/feature-vt/sys/src/libmp/port/mptouv.c – Rev 2

Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include "os.h"
2
#include <mp.h>
3
#include "dat.h"
4
 
5
#define VLDIGITS (sizeof(vlong)/sizeof(mpdigit))
6
 
7
/*
8
 *  this code assumes that a vlong is an integral number of
9
 *  mpdigits long.
10
 */
11
mpint*
12
uvtomp(uvlong v, mpint *b)
13
{
14
	int s;
15
 
16
	if(b == nil)
17
		b = mpnew(VLDIGITS*sizeof(mpdigit));
18
	else
19
		mpbits(b, VLDIGITS*sizeof(mpdigit));
20
	mpassign(mpzero, b);
21
	if(v == 0)
22
		return b;
23
	for(s = 0; s < VLDIGITS && v != 0; s++){
24
		b->p[s] = v;
25
		v >>= sizeof(mpdigit)*8;
26
	}
27
	b->top = s;
28
	return b;
29
}
30
 
31
uvlong
32
mptouv(mpint *b)
33
{
34
	uvlong v;
35
	int s;
36
 
37
	if(b->top == 0)
38
		return 0LL;
39
 
40
	mpnorm(b);
41
	if(b->top > VLDIGITS)
42
		return MAXVLONG;
43
 
44
	v = 0ULL;
45
	for(s = 0; s < b->top; s++)
46
		v |= (uvlong)b->p[s]<<(s*sizeof(mpdigit)*8);
47
 
48
	return v;
49
}