4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * This file contains bignum implementation code that
31 * is specific to x86, but which is still more appropriate
32 * to write in C, rather than assembly language.
33 * bignum_i386_asm.s does all the assembly language code
34 * for x86 specific bignum support. The assembly language
35 * source file has pure code, no data. Let the C compiler
36 * generate what is needed to handle the variations in
37 * data representation and addressing, for example,
38 * statically linked vs PIC.
44 #include <sys/cpuvar.h>
48 extern uint32_t big_mul_set_vec_sse2(uint32_t *, uint32_t *, int, uint32_t);
49 extern uint32_t big_mul_add_vec_sse2(uint32_t *, uint32_t *, int, uint32_t);
50 extern void big_mul_vec_sse2(uint32_t *, uint32_t *, int, uint32_t *, int);
51 extern void big_sqr_vec_sse2(uint32_t *, uint32_t *, int);
53 #if defined(MMX_MANAGE)
55 extern uint32_t big_mul_set_vec_sse2_nsv(uint32_t *, uint32_t *, int, uint32_t);
56 extern uint32_t big_mul_add_vec_sse2_nsv(uint32_t *, uint32_t *, int, uint32_t);
57 extern void big_mul_vec_sse2_nsv(uint32_t *, uint32_t *, int, uint32_t *, int);
58 extern void big_sqr_vec_sse2_nsv(uint32_t *, uint32_t *, int);
62 extern uint32_t big_mul_set_vec_umul(uint32_t *, uint32_t *, int, uint32_t);
63 extern uint32_t big_mul_add_vec_umul(uint32_t *, uint32_t *, int, uint32_t);
64 extern void big_mul_vec_umul(uint32_t *, uint32_t *, int, uint32_t *, int);
65 extern void big_sqr_vec_umul(uint32_t *, uint32_t *, int);
67 extern uint32_t bignum_use_sse2();
69 static void bignum_i386_init();
71 static uint32_t big_mul_set_vec_init(uint32_t *, uint32_t *, int, uint32_t);
72 static uint32_t big_mul_add_vec_init(uint32_t *, uint32_t *, int, uint32_t);
73 static void big_mul_vec_init(uint32_t *, uint32_t *, int, uint32_t *, int);
74 static void big_sqr_vec_init(uint32_t *, uint32_t *, int);
77 (*big_mul_set_vec_impl
)(uint32_t *r
, uint32_t *a
, int len
, uint32_t digit
)
78 = &big_mul_set_vec_init
;
81 (*big_mul_add_vec_impl
)(uint32_t *r
, uint32_t *a
, int len
, uint32_t digit
)
82 = &big_mul_add_vec_init
;
85 (*big_mul_vec_impl
)(uint32_t *r
, uint32_t *a
, int alen
, uint32_t *b
, int blen
)
88 (*big_sqr_vec_impl
)(uint32_t *r
, uint32_t *a
, int alen
)
92 big_mul_set_vec_init(uint32_t *r
, uint32_t *a
, int len
, uint32_t digit
)
95 return ((*big_mul_set_vec_impl
)(r
, a
, len
, digit
));
99 big_mul_add_vec_init(uint32_t *r
, uint32_t *a
, int len
, uint32_t digit
)
102 return ((*big_mul_add_vec_impl
)(r
, a
, len
, digit
));
106 big_mul_vec_init(uint32_t *r
, uint32_t *a
, int alen
, uint32_t *b
, int blen
)
109 (*big_mul_vec_impl
)(r
, a
, alen
, b
, blen
);
113 big_sqr_vec_init(uint32_t *r
, uint32_t *a
, int alen
)
116 (*big_sqr_vec_impl
)(r
, a
, alen
);
122 if (bignum_use_sse2() != 0) {
123 big_mul_set_vec_impl
= &big_mul_set_vec_sse2
;
124 big_mul_add_vec_impl
= &big_mul_add_vec_sse2
;
125 big_mul_vec_impl
= &big_mul_vec_sse2
;
126 big_sqr_vec_impl
= &big_sqr_vec_sse2
;
128 big_mul_set_vec_impl
= &big_mul_set_vec_umul
;
129 big_mul_add_vec_impl
= &big_mul_add_vec_umul
;
130 big_mul_vec_impl
= &big_mul_vec_umul
;
131 big_sqr_vec_impl
= &big_sqr_vec_umul
;
136 big_mul_vec_umul(uint32_t *r
, uint32_t *a
, int alen
, uint32_t *b
, int blen
)
140 r
[alen
] = big_mul_set_vec_umul(r
, a
, alen
, b
[0]);
141 for (i
= 1; i
< blen
; ++i
)
142 r
[alen
+ i
] = big_mul_add_vec_umul(r
+i
, a
, alen
, b
[i
]);
146 big_sqr_vec_umul(uint32_t *r
, uint32_t *a
, int alen
)
150 r
[alen
] = big_mul_set_vec_umul(r
, a
, alen
, a
[0]);
151 for (i
= 1; i
< alen
; ++i
)
152 r
[alen
+ i
] = big_mul_add_vec_umul(r
+i
, a
, alen
, a
[i
]);