~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/security/nss/lib/freebl/mpi/mpv_sparc.c

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * The contents of this file are subject to the Mozilla Public
 
3
 * License Version 1.1 (the "License"); you may not use this file
 
4
 * except in compliance with the License. You may obtain a copy of
 
5
 * the License at http://www.mozilla.org/MPL/
 
6
 * 
 
7
 * Software distributed under the License is distributed on an "AS
 
8
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
9
 * implied. See the License for the specific language governing
 
10
 * rights and limitations under the License.
 
11
 * 
 
12
 * The Original Code is a SPARC/VIS optimized multiply and add function
 
13
 *
 
14
 * The Initial Developer of the Original Code is Sun Microsystems Inc.
 
15
 * Portions created by Sun Microsystems Inc. are 
 
16
 * Copyright (C) 1999-2000 Sun Microsystems Inc.  All Rights Reserved.
 
17
 * 
 
18
 * Contributor(s):
 
19
 * 
 
20
 * Alternatively, the contents of this file may be used under the
 
21
 * terms of the GNU General Public License Version 2 or later (the
 
22
 * "GPL"), in which case the provisions of the GPL are applicable 
 
23
 * instead of those above.   If you wish to allow use of your 
 
24
 * version of this file only under the terms of the GPL and not to
 
25
 * allow others to use your version of this file under the MPL,
 
26
 * indicate your decision by deleting the provisions above and
 
27
 * replace them with the notice and other provisions required by
 
28
 * the GPL.  If you do not delete the provisions above, a recipient
 
29
 * may use your version of this file under either the MPL or the
 
30
 * GPL.
 
31
 *  $Id: mpv_sparc.c,v 1.2 2000/12/08 00:20:36 nelsonb%netscape.com Exp $
 
32
 */
 
33
 
 
34
#include "vis_proto.h"
 
35
 
 
36
/***************************************************************/
 
37
 
 
38
typedef  int                t_s32;
 
39
typedef  unsigned int       t_u32;
 
40
#if defined(__sparcv9)
 
41
typedef  long               t_s64;
 
42
typedef  unsigned long      t_u64;
 
43
#else
 
44
typedef  long long          t_s64;
 
45
typedef  unsigned long long t_u64;
 
46
#endif
 
47
typedef  double             t_d64;
 
48
 
 
49
/***************************************************************/
 
50
 
 
51
typedef union {
 
52
  t_d64 d64;
 
53
  struct {
 
54
    t_s32 i0;
 
55
    t_s32 i1;
 
56
  } i32s;
 
57
} d64_2_i32;
 
58
 
 
59
/***************************************************************/
 
60
 
 
61
#define BUFF_SIZE  256
 
62
 
 
63
#define A_BITS  19
 
64
#define A_MASK  ((1 << A_BITS) - 1)
 
65
 
 
66
/***************************************************************/
 
67
 
 
68
static t_u64 mask_cnst[] = {
 
69
  0x8000000080000000ull
 
70
};
 
71
 
 
72
/***************************************************************/
 
73
 
 
74
#define DEF_VARS(N)                     \
 
75
  t_d64 *py = (t_d64*)y;                \
 
76
  t_d64 mask = *((t_d64*)mask_cnst);    \
 
77
  t_d64 ca = (1u << 31) - 1;            \
 
78
  t_d64 da = (t_d64)a;                  \
 
79
  t_s64 buff[N], s;                     \
 
80
  d64_2_i32 dy
 
81
 
 
82
/***************************************************************/
 
83
 
 
84
#define MUL_U32_S64_2(i)                                \
 
85
  dy.d64 = vis_fxnor(mask, py[i]);                      \
 
86
  buff[2*(i)  ] = (ca - (t_d64)dy.i32s.i0) * da;        \
 
87
  buff[2*(i)+1] = (ca - (t_d64)dy.i32s.i1) * da
 
88
 
 
89
#define MUL_U32_S64_2_D(i)              \
 
90
  dy.d64 = vis_fxnor(mask, py[i]);      \
 
91
  d0 = ca - (t_d64)dy.i32s.i0;          \
 
92
  d1 = ca - (t_d64)dy.i32s.i1;          \
 
93
  buff[4*(i)  ] = (t_s64)(d0 * da);     \
 
94
  buff[4*(i)+1] = (t_s64)(d0 * db);     \
 
95
  buff[4*(i)+2] = (t_s64)(d1 * da);     \
 
96
  buff[4*(i)+3] = (t_s64)(d1 * db)
 
97
 
 
98
/***************************************************************/
 
99
 
 
100
#define ADD_S64_U32(i)          \
 
101
  s = buff[i] + x[i] + c;       \
 
102
  z[i] = s;                     \
 
103
  c = (s >> 32)
 
104
 
 
105
#define ADD_S64_U32_D(i)                        \
 
106
  s = buff[2*(i)] +(((t_s64)(buff[2*(i)+1]))<<A_BITS) + x[i] + uc;   \
 
107
  z[i] = s;                                     \
 
108
  uc = ((t_u64)s >> 32)
 
109
 
 
110
/***************************************************************/
 
111
 
 
112
#define MUL_U32_S64_8(i)        \
 
113
  MUL_U32_S64_2(i);             \
 
114
  MUL_U32_S64_2(i+1);           \
 
115
  MUL_U32_S64_2(i+2);           \
 
116
  MUL_U32_S64_2(i+3)
 
117
 
 
118
#define MUL_U32_S64_D_8(i)      \
 
119
  MUL_U32_S64_2_D(i);           \
 
120
  MUL_U32_S64_2_D(i+1);         \
 
121
  MUL_U32_S64_2_D(i+2);         \
 
122
  MUL_U32_S64_2_D(i+3)
 
123
 
 
124
/***************************************************************/
 
125
 
 
126
#define ADD_S64_U32_8(i)        \
 
127
  ADD_S64_U32(i);               \
 
128
  ADD_S64_U32(i+1);             \
 
129
  ADD_S64_U32(i+2);             \
 
130
  ADD_S64_U32(i+3);             \
 
131
  ADD_S64_U32(i+4);             \
 
132
  ADD_S64_U32(i+5);             \
 
133
  ADD_S64_U32(i+6);             \
 
134
  ADD_S64_U32(i+7)
 
135
 
 
136
#define ADD_S64_U32_D_8(i)      \
 
137
  ADD_S64_U32_D(i);             \
 
138
  ADD_S64_U32_D(i+1);           \
 
139
  ADD_S64_U32_D(i+2);           \
 
140
  ADD_S64_U32_D(i+3);           \
 
141
  ADD_S64_U32_D(i+4);           \
 
142
  ADD_S64_U32_D(i+5);           \
 
143
  ADD_S64_U32_D(i+6);           \
 
144
  ADD_S64_U32_D(i+7)
 
145
 
 
146
/***************************************************************/
 
147
 
 
148
t_u32 mul_add(t_u32 *z, t_u32 *x, t_u32 *y, int n, t_u32 a)
 
149
{
 
150
  if (a < (1 << A_BITS)) {
 
151
 
 
152
    if (n == 8) {
 
153
      DEF_VARS(8);
 
154
      t_s32 c = 0;
 
155
 
 
156
      MUL_U32_S64_8(0);
 
157
      ADD_S64_U32_8(0);
 
158
 
 
159
      return c;
 
160
 
 
161
    } else if (n == 16) {
 
162
      DEF_VARS(16);
 
163
      t_s32 c = 0;
 
164
 
 
165
      MUL_U32_S64_8(0);
 
166
      MUL_U32_S64_8(4);
 
167
      ADD_S64_U32_8(0);
 
168
      ADD_S64_U32_8(8);
 
169
 
 
170
      return c;
 
171
 
 
172
    } else {
 
173
      DEF_VARS(BUFF_SIZE);
 
174
      t_s32 i, c = 0;
 
175
 
 
176
#pragma pipeloop(0)
 
177
      for (i = 0; i < (n+1)/2; i ++) {
 
178
        MUL_U32_S64_2(i);
 
179
      }
 
180
 
 
181
#pragma pipeloop(0)
 
182
      for (i = 0; i < n; i ++) {
 
183
        ADD_S64_U32(i);
 
184
      }
 
185
 
 
186
      return c;
 
187
 
 
188
    }
 
189
  } else {
 
190
 
 
191
    if (n == 8) {
 
192
      DEF_VARS(2*8);
 
193
      t_d64 d0, d1, db;
 
194
      t_u32 uc = 0;
 
195
 
 
196
      da = (t_d64)(a &  A_MASK);
 
197
      db = (t_d64)(a >> A_BITS);
 
198
 
 
199
      MUL_U32_S64_D_8(0);
 
200
      ADD_S64_U32_D_8(0);
 
201
 
 
202
      return uc;
 
203
 
 
204
    } else if (n == 16) {
 
205
      DEF_VARS(2*16);
 
206
      t_d64 d0, d1, db;
 
207
      t_u32 uc = 0;
 
208
 
 
209
      da = (t_d64)(a &  A_MASK);
 
210
      db = (t_d64)(a >> A_BITS);
 
211
 
 
212
      MUL_U32_S64_D_8(0);
 
213
      MUL_U32_S64_D_8(4);
 
214
      ADD_S64_U32_D_8(0);
 
215
      ADD_S64_U32_D_8(8);
 
216
 
 
217
      return uc;
 
218
 
 
219
    } else {
 
220
      DEF_VARS(2*BUFF_SIZE);
 
221
      t_d64 d0, d1, db;
 
222
      t_u32 i, uc = 0;
 
223
 
 
224
      da = (t_d64)(a &  A_MASK);
 
225
      db = (t_d64)(a >> A_BITS);
 
226
 
 
227
#pragma pipeloop(0)
 
228
      for (i = 0; i < (n+1)/2; i ++) {
 
229
        MUL_U32_S64_2_D(i);
 
230
      }
 
231
 
 
232
#pragma pipeloop(0)
 
233
      for (i = 0; i < n; i ++) {
 
234
        ADD_S64_U32_D(i);
 
235
      }
 
236
 
 
237
      return uc;
 
238
    }
 
239
  }
 
240
}
 
241
 
 
242
/***************************************************************/
 
243
 
 
244
t_u32 mul_add_inp(t_u32 *x, t_u32 *y, int n, t_u32 a)
 
245
{
 
246
  return mul_add(x, x, y, n, a);
 
247
}
 
248
 
 
249
/***************************************************************/