]>
git.saurik.com Git - apple/security.git/blob - OSX/include/security_cryptkit/giantPort_PPC.c
1 /* Copyright (c) 1998,2011,2014 Apple Inc. All Rights Reserved.
3 * NOTICE: USE OF THE MATERIALS ACCOMPANYING THIS NOTICE IS SUBJECT
4 * TO THE TERMS OF THE SIGNED "FAST ELLIPTIC ENCRYPTION (FEE) REFERENCE
5 * SOURCE CODE EVALUATION AGREEMENT" BETWEEN APPLE, INC. AND THE
6 * ORIGINAL LICENSEE THAT OBTAINED THESE MATERIALS FROM APPLE,
7 * INC. ANY USE OF THESE MATERIALS NOT PERMITTED BY SUCH AGREEMENT WILL
8 * EXPOSE YOU TO LIABILITY.
9 ***************************************************************************
11 * giantPort_PPC.c - PPC-dependent giant definitions.
16 * Changed to compile with C++.
17 * 06 Apr 1998 at Apple
23 #include "giantPort_PPC.h"
25 #if !PPC_GIANT_PORT_INLINE
29 * Multiple-precision arithmetic routines/macros.
32 asm giantDigit
giantAddDigits(
33 register giantDigit dig1
,
34 register giantDigit dig2
,
35 register giantDigit
*carry
) /* RETURNED, 0 or 1 */
45 /* sum = dig1 + dig2 */
48 /* if((sum < dig1) || (sum < dig2)) */
59 /* else *carry = 0; */
63 /* return sum in r3 */
69 * Add a single digit value to a double digit accumulator in place.
70 * Carry out of the MSD of the accumulator is not handled.
71 * This should work any size giantDigits up to unsigned int.
73 asm void giantAddDouble(
74 register giantDigit
*accLow
, /* IN/OUT */
75 register giantDigit
*accHigh
, /* IN/OUT */
76 register giantDigit val
)
86 /* giantDigit sumLo = *accLow + val; */
90 /* if((sumLo < *accLow) || (sumLo < val)) { */
101 /* *accLow = sumLo; */
106 asm giantDigit
giantSubDigits(
107 register giantDigit a
,
108 register giantDigit b
,
109 register giantDigit
*borrow
) /* RETURNED, 0 or 1 */
117 /* giantDigit diff = a - b; */
129 /* else *borrow = 0; */
133 /* return diff in r3 */
138 asm void giantMulDigits(
139 register giantDigit dig1
,
140 register giantDigit dig2
,
141 register giantDigit
*lowProduct
, /* RETURNED, low digit */
142 register giantDigit
*hiProduct
) /* RETURNED, high digit */
149 /* dprod = (unsigned long long)dig1 * (unsigned long long)dig2; */
150 mullw r7
, dig1
, dig2
/* r7 = low(dig1 * dig2) */
151 mulhwu r8
, dig1
, dig2
/* r8 - hi(dig1 * dig2) */
153 /* *hiProduct = (giantDigit)(dprod >> GIANT_BITS_PER_DIGIT); */
156 /* *lowProduct = (giantDigit)dprod; */
157 stw r7
, 0(lowProduct
)
161 asm giantDigit
VectorMultiply(
162 register giantDigit plierDigit
, /* r3 */
163 register giantDigit
*candVector
, /* r4 */
164 register unsigned candLength
, /* r5 */
165 register giantDigit
*prodVector
) /* r6 */
167 register unsigned candDex
; /* index into multiplicandVector */
168 register giantDigit lastCarry
;
169 register giantDigit prodLo
;
170 register giantDigit prodHi
;
171 register unsigned scr1
;
172 register unsigned sumLo
;
176 /* giantDigit lastCarry = 0; */
180 /* for(candDex=0; candDex<candLength; ++candDex) { */
185 * prod = *(candVector++) * plierDigit + *prodVector + lastCarry
188 lwz scr1
,0(candVector
) /* *candVector --> scr1 */
189 addi candVector
,candVector
,4 /* candVector++ */
191 mullw prodLo
,scr1
,plierDigit
/* prodLo = low(*candVector * plierDigit) */
192 mulhwu prodHi
,scr1
,plierDigit
/* prodHi = high(*candVector * plierDigit) */
194 /* giantAddDouble(&prodLo, &prodHi, *prodVector); */
195 lwz scr1
,0(prodVector
) /* *prodVector --> r9 */
196 add sumLo
,prodLo
,scr1
/* prodLo + *prodVector --> sumLo */
197 cmpl crf0
,0,sumLo
,prodLo
/* sumLo < prodLo? */
199 cmpl crf0
,0,sumLo
,scr1
/* sumLo < *prodVector? */
202 addi prodHi
,prodHi
,1 /* prodHi++ */
204 mr
. prodLo
,sumLo
/* prodLo := sumLo */
206 /* giantAddDouble(&prodLo, &prodHi, lastCarry); */
207 add sumLo
,sumLo
,lastCarry
/* sumLo += lastCarry */
208 cmpl crf0
,0,sumLo
,prodLo
/* sumLo < prodLo? */
210 cmpl crf0
,0,sumLo
,lastCarry
/* sumLo < lastCarry? */
213 addi prodHi
,prodHi
,1 /* prodHi++ */
215 mr
. prodLo
,sumLo
/* prodLo := sumLo */
217 /* *(prodVector++) = prodLo; */
218 stw prodLo
,0(prodVector
) /* prodLo --> *prodVector */
219 addi prodVector
,prodVector
,4 /* prodVector++ */
221 /* lastCarry = prodHi; */
225 addi candDex
,candDex
,1 /* candDex++ */
227 cmpl crf0
,0,candDex
,candLength
/* candDex < candLength? */
230 /* return lastCarry; */
231 mr
. r3
,lastCarry
/* return lastCarry in r3 */
236 #endif // PPC_GIANT_PORT_INLINE