Subversion Repositories planix.SVN

Rev

Rev 33 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
/*
2
 *	mpvecadd(mpdigit *a, int alen, mpdigit *b, int blen, mpdigit *sum)
3
 *
4
 *		sum[0:alen] = a[0:alen-1] + b[0:blen-1]
5
 *
6
 *	prereq: alen >= blen, sum has room for alen+1 digits
7
 */
8
TEXT	mpvecadd(SB),$0
9
 
10
	MOVL	alen+4(FP),DX
11
	MOVL	blen+12(FP),CX
12
	MOVL	a+0(FP),SI
13
	MOVL	b+8(FP),BX
14
	SUBL	CX,DX
15
	MOVL	sum+16(FP),DI
16
	XORL	BP,BP			/* this also sets carry to 0 */
17
 
18
	/* skip addition if b is zero */
19
	TESTL	CX,CX
20
	JZ	_add1
21
 
22
	/* sum[0:blen-1],carry = a[0:blen-1] + b[0:blen-1] */
23
_addloop1:
24
	MOVL	(SI)(BP*4), AX
25
	ADCL	(BX)(BP*4), AX
26
	MOVL	AX,(DI)(BP*4)
27
	INCL	BP
28
	LOOP	_addloop1
29
 
30
_add1:
31
	/* jump if alen > blen */
32
	INCL	DX
33
	MOVL	DX,CX
34
	LOOP	_addloop2
35
 
36
	/* sum[alen] = carry */
37
_addend:
33 7u83 38
	ADCL	$0, CX
39
	MOVL	CX, (DI)(BP*4)
2 - 40
	RET
41
 
42
	/* sum[blen:alen-1],carry = a[blen:alen-1] + 0 */
43
_addloop2:
44
	MOVL	(SI)(BP*4),AX
45
	ADCL	$0,AX
46
	MOVL	AX,(DI)(BP*4)
47
	INCL	BP
48
	LOOP	_addloop2
49
	JMP	_addend
50