8990 /opt/onbld/gk is useless
[unleashed.git] / usr / src / common / bignum / i386 / bignum_i386.c
blob652967bff5928647e473175ac4186598ee42b11d
1 /*
2 * CDDL HEADER START
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
7 * with the License.
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]
20 * CDDL HEADER END
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.
41 #include "bignum.h"
43 #if defined(_KERNEL)
44 #include <sys/cpuvar.h>
45 #include <sys/disp.h>
46 #endif
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);
60 #endif
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);
76 uint32_t
77 (*big_mul_set_vec_impl)(uint32_t *r, uint32_t *a, int len, uint32_t digit)
78 = &big_mul_set_vec_init;
80 uint32_t
81 (*big_mul_add_vec_impl)(uint32_t *r, uint32_t *a, int len, uint32_t digit)
82 = &big_mul_add_vec_init;
84 void
85 (*big_mul_vec_impl)(uint32_t *r, uint32_t *a, int alen, uint32_t *b, int blen)
86 = &big_mul_vec_init;
87 void
88 (*big_sqr_vec_impl)(uint32_t *r, uint32_t *a, int alen)
89 = &big_sqr_vec_init;
91 static uint32_t
92 big_mul_set_vec_init(uint32_t *r, uint32_t *a, int len, uint32_t digit)
94 bignum_i386_init();
95 return ((*big_mul_set_vec_impl)(r, a, len, digit));
98 static uint32_t
99 big_mul_add_vec_init(uint32_t *r, uint32_t *a, int len, uint32_t digit)
101 bignum_i386_init();
102 return ((*big_mul_add_vec_impl)(r, a, len, digit));
105 static void
106 big_mul_vec_init(uint32_t *r, uint32_t *a, int alen, uint32_t *b, int blen)
108 bignum_i386_init();
109 (*big_mul_vec_impl)(r, a, alen, b, blen);
112 static void
113 big_sqr_vec_init(uint32_t *r, uint32_t *a, int alen)
115 bignum_i386_init();
116 (*big_sqr_vec_impl)(r, a, alen);
119 static void
120 bignum_i386_init()
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;
127 } else {
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;
135 void
136 big_mul_vec_umul(uint32_t *r, uint32_t *a, int alen, uint32_t *b, int blen)
138 int i;
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]);
145 void
146 big_sqr_vec_umul(uint32_t *r, uint32_t *a, int alen)
148 int i;
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]);
155 #if defined(_KERNEL)
157 void
158 kpr_disable()
160 kpreempt_disable();
163 void
164 kpr_enable()
166 kpreempt_enable();
169 #endif