summaryrefslogtreecommitdiff
path: root/sys/src/libmp/power/mpvecsub.s
blob: c2a05bc18f6cfce59da83b38aa959b4aadc35f1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#define	BDNZ	BC	16,0,
#define	BDNE	BC	0,2,

/*
 *	mpvecsub(mpdigit *a, int alen, mpdigit *b, int blen, mpdigit *diff)
 *
 *		diff[0:alen-1] = a[0:alen-1] - b[0:blen-1]
 *
 *	prereq: alen >= blen, diff has room for alen digits
 *
 *		R3 == a
 *		R4 == alen
 *		R5 == b
 *		R6 == blen
 *		R7 == diff
 *		R8 == temporary
 *		R9 == temporary
 */
TEXT	mpvecsub(SB),$-4

	MOVW	alen+4(FP),R4
	MOVW	b+8(FP),R5
	MOVW	blen+12(FP),R6
	MOVW	diff+16(FP),R7
	SUB	R6, R4		/* calculate counter for second loop (alen > blen) */
	SUB	$4, R3		/* pre decrement for MOVWU's */
	SUB	$4, R5		/* pre decrement for MOVWU's */
	SUBC	$4, R7		/* pre decrement for MOVWU's and set carry */

	/* skip subraction if b is zero */
	CMP	R0,R6
	BEQ	_sub1

	/* diff[0:blen-1],borrow = a[0:blen-1] - b[0:blen-1] */
	MOVW	R6, CTR
_subloop1:
	MOVWU	4(R3), R8
	MOVWU	4(R5), R9
	SUBE	R9, R8, R8
	MOVWU	R8, 4(R7)
	BDNZ	_subloop1

_sub1:
	/* skip subtraction if a is zero */
	CMP	R0, R4
	BEQ	_subend

	/* diff[blen:alen-1] = a[blen:alen-1] - 0 + carry */
	MOVW	R4, CTR
_subloop2:
	MOVWU	4(R3), R8
	SUBE	R0, R8
	MOVWU	R8, 4(R7)
	BDNZ	_subloop2
_subend:
	RETURN