1 /*****************************************************************************
2
3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4 more contributor license agreements. See the NOTICE file distributed
5 with this work for additional information regarding copyright ownership.
6 Accellera licenses this file to you under the Apache License, Version 2.0
7 (the "License"); you may not use this file except in compliance with the
8 License. You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15 implied. See the License for the specific language governing
16 permissions and limitations under the License.
17
18 *****************************************************************************/
19
20 /*****************************************************************************
21
22 sc_signed.h -- Arbitrary precision signed arithmetic.
23
24 This file includes the definitions of sc_signed_bitref,
25 sc_signed_subref, and sc_signed classes. The first two classes are
26 proxy classes to reference one bit and a range of bits of a
27 sc_signed number, respectively.
28
29 An sc_signed number has the sign-magnitude representation
30 internally. However, its interface guarantees a 2's-complement
31 representation. The sign-magnitude representation is chosen
32 because of its efficiency: The sc_signed and sc_unsigned types are
33 optimized for arithmetic rather than bitwise operations. For
34 arithmetic operations, the sign-magnitude representation performs
35 better.
36
37 The implementations of sc_signed and sc_unsigned classes are
38 almost identical: Most of the member and friend functions are
39 defined in sc_nbcommon.cpp and sc_nbfriends.cpp so that they can
40 be shared by both of these classes. These functions are chosed by
41 defining a few macros before including them such as IF_SC_SIGNED
42 and CLASS_TYPE. Our implementation choices are mostly dictated by
43 performance considerations in that we tried to provide the most
44 efficient sc_signed and sc_unsigned types without compromising
45 their interface.
46
47 For the behavior of operators, we have two semantics: the old and
48 new. The most important difference between these two semantics is
49 that the old semantics is closer to C/C++ semantics in that the
50 result type of a binary operator on unsigned and signed arguments
51 is unsigned; the new semantics, on the other hand, requires the
52 result type be signed. The new semantics is required by the VSIA
53 C/C++ data types standard. We have implemented the new semantics.
54
55 Original Author: Ali Dasdan, Synopsys, Inc.
56
57 *****************************************************************************/
58
59 /*****************************************************************************
60
61 MODIFICATION LOG - modifiers, enter your name, affiliation, date and
62 changes you are making here.
63
64 Name, Affiliation, Date:
65 Description of Modification:
66
67 *****************************************************************************/
68
69 // $Log: sc_signed.h,v $
70 // Revision 1.3 2011/08/24 22:05:46 acg
71 // Torsten Maehne: initialization changes to remove warnings.
72 //
73 // Revision 1.2 2011/02/18 20:19:15 acg
74 // Andy Goodrich: updating Copyright notice.
75 //
76 // Revision 1.1.1.1 2006/12/15 20:20:05 acg
77 // SystemC 2.3
78 //
79 // Revision 1.5 2006/05/08 17:50:01 acg
80 // Andy Goodrich: Added David Long's declarations for friend operators,
81 // functions, and methods, to keep the Microsoft compiler happy.
82 //
83 // Revision 1.4 2006/03/13 20:25:27 acg
84 // Andy Goodrich: Addition of function declarations, e.g., xor_signed_friend()
85 // to keep gcc 4.x happy.
86 //
87 // Revision 1.3 2006/01/13 18:49:32 acg
88 // Added $Log command so that CVS check in comments are reproduced in the
89 // source.
90 //
91
92 #ifndef SC_SIGNED_H
93 #define SC_SIGNED_H
94
95
96 #include "sysc/kernel/sc_object.h"
97 #include "sysc/datatypes/misc/sc_value_base.h"
98 #include "sysc/utils/sc_temporary.h"
99 #include "sysc/datatypes/int/sc_length_param.h"
100 #include "sysc/datatypes/int/sc_nbdefs.h"
101 #include "sysc/datatypes/int/sc_nbutils.h"
102 #include "sysc/datatypes/int/sc_nbexterns.h"
103 #include "sysc/datatypes/int/sc_unsigned.h"
104
105
106 namespace sc_dt
107 {
108
109 // classes defined in this module
110 class sc_signed_bitref_r;
111 class sc_signed_bitref;
112 class sc_signed_subref_r;
113 class sc_signed_subref;
114 class sc_concatref;
115 class sc_signed;
116
117 // forward class declarations
118 class sc_bv_base;
119 class sc_lv_base;
120 class sc_int_base;
121 class sc_uint_base;
122 class sc_int_subref_r;
123 class sc_uint_subref_r;
124 class sc_signed;
125 class sc_unsigned;
126 class sc_unsigned_subref_r;
127 class sc_fxval;
128 class sc_fxval_fast;
129 class sc_fxnum;
130 class sc_fxnum_fast;
131
132 } // namespace sc_dt
133
134 // extern template instantiations
135 namespace sc_core {
136 SC_API_TEMPLATE_DECL_ sc_vpool<sc_dt::sc_signed_bitref>;
137 SC_API_TEMPLATE_DECL_ sc_vpool<sc_dt::sc_signed_subref>;
138 } // namespace sc_core
139
140 namespace sc_dt {
141
142 // Helper function declarations
143 sc_signed add_signed_friend(small_type us,
144 int unb,
145 int und,
146 const sc_digit *ud,
147 small_type vs,
148 int vnb,
149 int vnd,
150 const sc_digit *vd);
151
152 sc_signed sub_signed_friend(small_type us,
153 int unb,
154 int und,
155 const sc_digit *ud,
156 small_type vs,
157 int vnb,
158 int vnd,
159 const sc_digit *vd);
160
161 sc_signed mul_signed_friend(small_type s,
162 int unb,
163 int und,
164 const sc_digit *ud,
165 int vnb,
166 int vnd,
167 const sc_digit *vd);
168
169 sc_signed div_signed_friend(small_type s,
170 int unb,
171 int und,
172 const sc_digit *ud,
173 int vnb,
174 int vnd,
175 const sc_digit *vd);
176
177 sc_signed mod_signed_friend(small_type us,
178 int unb,
179 int und,
180 const sc_digit *ud,
181 int vnb,
182 int vnd,
183 const sc_digit *vd);
184
185 sc_signed and_signed_friend(small_type us,
186 int unb,
187 int und,
188 const sc_digit *ud,
189 small_type vs,
190 int vnb,
191 int vnd,
192 const sc_digit *vd);
193
194 sc_signed or_signed_friend(small_type us,
195 int unb,
196 int und,
197 const sc_digit *ud,
198 small_type vs,
199 int vnb,
200 int vnd,
201 const sc_digit *vd);
202
203 sc_signed xor_signed_friend(small_type us,
204 int unb,
205 int und,
206 const sc_digit *ud,
207 small_type vs,
208 int vnb,
209 int vnd,
210 const sc_digit *vd);
211
212
213 // friend operator declarations
214 // ARITHMETIC OPERATORS:
215
216 // ADDition operators:
217
218 SC_API sc_signed operator + (const sc_unsigned& u, const sc_signed& v);
219 SC_API sc_signed operator + (const sc_signed& u, const sc_unsigned& v);
220
221 SC_API sc_signed operator + (const sc_unsigned& u, int64 v);
222 SC_API sc_signed operator + (const sc_unsigned& u, long v);
223 inline sc_signed operator + (const sc_unsigned& u, int v);
224
225 SC_API sc_signed operator + (int64 u, const sc_unsigned& v);
226 SC_API sc_signed operator + (long u, const sc_unsigned& v);
227 inline sc_signed operator + (int u, const sc_unsigned& v);
228
229 SC_API sc_signed operator + (const sc_signed& u, const sc_signed& v);
230 SC_API sc_signed operator + (const sc_signed& u, int64 v);
231 SC_API sc_signed operator + (const sc_signed& u, uint64 v);
232 SC_API sc_signed operator + (const sc_signed& u, long v);
233 SC_API sc_signed operator + (const sc_signed& u, unsigned long v);
234 inline sc_signed operator + (const sc_signed& u, int v);
235 inline sc_signed operator + (const sc_signed& u, unsigned int v);
236
237 SC_API sc_signed operator + (int64 u, const sc_signed& v);
238 SC_API sc_signed operator + (uint64 u, const sc_signed& v);
239 SC_API sc_signed operator + (long u, const sc_signed& v);
240 SC_API sc_signed operator + (unsigned long u, const sc_signed& v);
241 inline sc_signed operator + (int u, const sc_signed& v);
242 inline sc_signed operator + (unsigned int u, const sc_signed& v);
243
244 SC_API sc_signed operator + (const sc_unsigned& u, const sc_int_base& v);
245 SC_API sc_signed operator + (const sc_int_base& u, const sc_unsigned& v);
246 SC_API sc_signed operator + (const sc_signed& u, const sc_int_base& v);
247 SC_API sc_signed operator + (const sc_signed& u, const sc_uint_base& v);
248 SC_API sc_signed operator + (const sc_int_base& u, const sc_signed& v);
249 SC_API sc_signed operator + (const sc_uint_base& u, const sc_signed& v);
250
251
252
253 // SUBtraction operators:
254
255 SC_API sc_signed operator - (const sc_unsigned& u, const sc_signed& v);
256 SC_API sc_signed operator - (const sc_signed& u, const sc_unsigned& v);
257
258 SC_API sc_signed operator - (const sc_unsigned& u, const sc_unsigned& v);
259 SC_API sc_signed operator - (const sc_unsigned& u, int64 v);
260 SC_API sc_signed operator - (const sc_unsigned& u, uint64 v);
261 SC_API sc_signed operator - (const sc_unsigned& u, long v);
262 SC_API sc_signed operator - (const sc_unsigned& u, unsigned long v);
263 inline sc_signed operator - (const sc_unsigned& u, int v);
264 inline sc_signed operator - (const sc_unsigned& u, unsigned int v);
265
266 SC_API sc_signed operator - (int64 u, const sc_unsigned& v);
267 SC_API sc_signed operator - (uint64 u, const sc_unsigned& v);
268 SC_API sc_signed operator - (long u, const sc_unsigned& v);
269 SC_API sc_signed operator - (unsigned long u, const sc_unsigned& v);
270 inline sc_signed operator - (int u, const sc_unsigned& v);
271 inline sc_signed operator - (unsigned int u, const sc_unsigned& v);
272
273 SC_API sc_signed operator - (const sc_signed& u, const sc_signed& v);
274 SC_API sc_signed operator - (const sc_signed& u, int64 v);
275 SC_API sc_signed operator - (const sc_signed& u, uint64 v);
276 SC_API sc_signed operator - (const sc_signed& u, long v);
277 SC_API sc_signed operator - (const sc_signed& u, unsigned long v);
278 inline sc_signed operator - (const sc_signed& u, int v);
279 inline sc_signed operator - (const sc_signed& u, unsigned int v);
280
281 SC_API sc_signed operator - (int64 u, const sc_signed& v);
282 SC_API sc_signed operator - (uint64 u, const sc_signed& v);
283 SC_API sc_signed operator - (long u, const sc_signed& v);
284 SC_API sc_signed operator - (unsigned long u, const sc_signed& v);
285 inline sc_signed operator - (int u, const sc_signed& v);
286 inline sc_signed operator - (unsigned int u, const sc_signed& v);
287
288
289 SC_API sc_signed operator - (const sc_unsigned& u, const sc_int_base& v);
290 SC_API sc_signed operator - (const sc_unsigned& u, const sc_uint_base& v);
291 SC_API sc_signed operator - (const sc_int_base& u, const sc_unsigned& v);
292 SC_API sc_signed operator - (const sc_uint_base& u, const sc_unsigned& v);
293 SC_API sc_signed operator - (const sc_signed& u, const sc_int_base& v);
294 SC_API sc_signed operator - (const sc_signed& u, const sc_uint_base& v);
295 SC_API sc_signed operator - (const sc_int_base& u, const sc_signed& v);
296 SC_API sc_signed operator - (const sc_uint_base& u, const sc_signed& v);
297
298
299
300 // MULtiplication operators:
301
302 SC_API sc_signed operator * (const sc_unsigned& u, const sc_signed& v);
303 SC_API sc_signed operator * (const sc_signed& u, const sc_unsigned& v);
304
305 SC_API sc_signed operator * (const sc_unsigned& u, int64 v);
306 SC_API sc_signed operator * (const sc_unsigned& u, long v);
307 inline sc_signed operator * (const sc_unsigned& u, int v);
308
309 SC_API sc_signed operator * (int64 u, const sc_unsigned& v);
310 SC_API sc_signed operator * (long u, const sc_unsigned& v);
311 inline sc_signed operator * (int u, const sc_unsigned& v);
312
313 SC_API sc_signed operator * (const sc_signed& u, const sc_signed& v);
314 SC_API sc_signed operator * (const sc_signed& u, int64 v);
315 SC_API sc_signed operator * (const sc_signed& u, uint64 v);
316 SC_API sc_signed operator * (const sc_signed& u, long v);
317 SC_API sc_signed operator * (const sc_signed& u, unsigned long v);
318 inline sc_signed operator * (const sc_signed& u, int v);
319 inline sc_signed operator * (const sc_signed& u, unsigned int v);
320
321 SC_API sc_signed operator * (int64 u, const sc_signed& v);
322 SC_API sc_signed operator * (uint64 u, const sc_signed& v);
323 SC_API sc_signed operator * (long u, const sc_signed& v);
324 SC_API sc_signed operator * (unsigned long u, const sc_signed& v);
325 inline sc_signed operator * (int u, const sc_signed& v);
326 inline sc_signed operator * (unsigned int u, const sc_signed& v);
327
328 SC_API sc_signed operator * (const sc_unsigned& u, const sc_int_base& v);
329 SC_API sc_signed operator * (const sc_int_base& u, const sc_unsigned& v);
330 SC_API sc_signed operator * (const sc_signed& u, const sc_int_base& v);
331 SC_API sc_signed operator * (const sc_signed& u, const sc_uint_base& v);
332 SC_API sc_signed operator * (const sc_int_base& u, const sc_signed& v);
333 SC_API sc_signed operator * (const sc_uint_base& u, const sc_signed& v);
334
335
336
337 // DIVision operators:
338
339 SC_API sc_signed operator / (const sc_unsigned& u, const sc_signed& v);
340 SC_API sc_signed operator / (const sc_signed& u, const sc_unsigned& v);
341
342 SC_API sc_signed operator / (const sc_unsigned& u, int64 v);
343 SC_API sc_signed operator / (const sc_unsigned& u, long v);
344 inline sc_signed operator / (const sc_unsigned& u, int v);
345
346 SC_API sc_signed operator / (int64 u, const sc_unsigned& v);
347 SC_API sc_signed operator / (long u, const sc_unsigned& v);
348 inline sc_signed operator / (int u, const sc_unsigned& v);
349
350 SC_API sc_signed operator / (const sc_signed& u, const sc_signed& v);
351 SC_API sc_signed operator / (const sc_signed& u, int64 v);
352 SC_API sc_signed operator / (const sc_signed& u, uint64 v);
353 SC_API sc_signed operator / (const sc_signed& u, long v);
354 SC_API sc_signed operator / (const sc_signed& u, unsigned long v);
355 inline sc_signed operator / (const sc_signed& u, int v);
356 inline sc_signed operator / (const sc_signed& u, unsigned int v);
357
358 SC_API sc_signed operator / (int64 u, const sc_signed& v);
359 SC_API sc_signed operator / (uint64 u, const sc_signed& v);
360 SC_API sc_signed operator / (long u, const sc_signed& v);
361 SC_API sc_signed operator / (unsigned long u, const sc_signed& v);
362 inline sc_signed operator / (int u, const sc_signed& v);
363 inline sc_signed operator / (unsigned int u, const sc_signed& v);
364
365 SC_API sc_signed operator / (const sc_unsigned& u, const sc_int_base& v);
366 SC_API sc_signed operator / (const sc_int_base& u, const sc_unsigned& v);
367 SC_API sc_signed operator / (const sc_signed& u, const sc_int_base& v);
368 SC_API sc_signed operator / (const sc_signed& u, const sc_uint_base& v);
369 SC_API sc_signed operator / (const sc_int_base& u, const sc_signed& v);
370 SC_API sc_signed operator / (const sc_uint_base& u, const sc_signed& v);
371
372
373
374 // MODulo operators:
375
376 SC_API sc_signed operator % (const sc_unsigned& u, const sc_signed& v);
377 SC_API sc_signed operator % (const sc_signed& u, const sc_unsigned& v);
378
379 SC_API sc_signed operator % (const sc_unsigned& u, int64 v);
380 SC_API sc_signed operator % (const sc_unsigned& u, long v);
381 inline sc_signed operator % (const sc_unsigned& u, int v);
382
383 SC_API sc_signed operator % (int64 u, const sc_unsigned& v);
384 SC_API sc_signed operator % (long u, const sc_unsigned& v);
385 inline sc_signed operator % (int u, const sc_unsigned& v);
386
387 SC_API sc_signed operator % (const sc_signed& u, const sc_signed& v);
388 SC_API sc_signed operator % (const sc_signed& u, int64 v);
389 SC_API sc_signed operator % (const sc_signed& u, uint64 v);
390 SC_API sc_signed operator % (const sc_signed& u, long v);
391 SC_API sc_signed operator % (const sc_signed& u, unsigned long v);
392 inline sc_signed operator % (const sc_signed& u, int v);
393 inline sc_signed operator % (const sc_signed& u, unsigned int v);
394
395 SC_API sc_signed operator % (int64 u, const sc_signed& v);
396 SC_API sc_signed operator % (uint64 u, const sc_signed& v);
397 SC_API sc_signed operator % (long u, const sc_signed& v);
398 SC_API sc_signed operator % (unsigned long u, const sc_signed& v);
399 inline sc_signed operator % (int u, const sc_signed& v);
400 inline sc_signed operator % (unsigned int u, const sc_signed& v);
401
402 SC_API sc_signed operator % (const sc_unsigned& u, const sc_int_base& v);
403 SC_API sc_signed operator % (const sc_int_base& u, const sc_unsigned& v);
404 SC_API sc_signed operator % (const sc_signed& u, const sc_int_base& v);
405 SC_API sc_signed operator % (const sc_signed& u, const sc_uint_base& v);
406 SC_API sc_signed operator % (const sc_int_base& u, const sc_signed& v);
407 SC_API sc_signed operator % (const sc_uint_base& u, const sc_signed& v);
408
409
410
411 // BITWISE OPERATORS:
412
413 // Bitwise AND operators:
414
415 SC_API sc_signed operator & (const sc_unsigned& u, const sc_signed& v);
416 SC_API sc_signed operator & (const sc_signed& u, const sc_unsigned& v);
417
418 SC_API sc_signed operator & (const sc_unsigned& u, int64 v);
419 SC_API sc_signed operator & (const sc_unsigned& u, long v);
420 inline sc_signed operator & (const sc_unsigned& u, int v);
421
422 SC_API sc_signed operator & (int64 u, const sc_unsigned& v);
423 SC_API sc_signed operator & (long u, const sc_unsigned& v);
424 inline sc_signed operator & (int u, const sc_unsigned& v);
425
426 SC_API sc_signed operator & (const sc_signed& u, const sc_signed& v);
427 SC_API sc_signed operator & (const sc_signed& u, int64 v);
428 SC_API sc_signed operator & (const sc_signed& u, uint64 v);
429 SC_API sc_signed operator & (const sc_signed& u, long v);
430 SC_API sc_signed operator & (const sc_signed& u, unsigned long v);
431 inline sc_signed operator & (const sc_signed& u, int v);
432 inline sc_signed operator & (const sc_signed& u, unsigned int v);
433
434 SC_API sc_signed operator & (int64 u, const sc_signed& v);
435 SC_API sc_signed operator & (uint64 u, const sc_signed& v);
436 SC_API sc_signed operator & (long u, const sc_signed& v);
437 SC_API sc_signed operator & (unsigned long u, const sc_signed& v);
438 inline sc_signed operator & (int u, const sc_signed& v);
439 inline sc_signed operator & (unsigned int u, const sc_signed& v);
440
441 SC_API sc_signed operator & (const sc_unsigned& u, const sc_int_base& v);
442 SC_API sc_signed operator & (const sc_int_base& u, const sc_unsigned& v);
443 SC_API sc_signed operator & (const sc_signed& u, const sc_int_base& v);
444 SC_API sc_signed operator & (const sc_signed& u, const sc_uint_base& v);
445 SC_API sc_signed operator & (const sc_int_base& u, const sc_signed& v);
446 SC_API sc_signed operator & (const sc_uint_base& u, const sc_signed& v);
447
448
449
450 // Bitwise OR operators:
451
452 SC_API sc_signed operator | (const sc_unsigned& u, const sc_signed& v);
453 SC_API sc_signed operator | (const sc_signed& u, const sc_unsigned& v);
454
455 SC_API sc_signed operator | (const sc_unsigned& u, int64 v);
456 SC_API sc_signed operator | (const sc_unsigned& u, long v);
457 inline sc_signed operator | (const sc_unsigned& u, int v);
458
459 SC_API sc_signed operator | (int64 u, const sc_unsigned& v);
460 SC_API sc_signed operator | (long u, const sc_unsigned& v);
461 inline sc_signed operator | (int u, const sc_unsigned& v);
462
463 SC_API sc_signed operator | (const sc_signed& u, const sc_signed& v);
464 SC_API sc_signed operator | (const sc_signed& u, int64 v);
465 SC_API sc_signed operator | (const sc_signed& u, uint64 v);
466 SC_API sc_signed operator | (const sc_signed& u, long v);
467 SC_API sc_signed operator | (const sc_signed& u, unsigned long v);
468 inline sc_signed operator | (const sc_signed& u, int v);
469 inline sc_signed operator | (const sc_signed& u, unsigned int v);
470
471 SC_API sc_signed operator | (int64 u, const sc_signed& v);
472 SC_API sc_signed operator | (uint64 u, const sc_signed& v);
473 SC_API sc_signed operator | (long u, const sc_signed& v);
474 SC_API sc_signed operator | (unsigned long u, const sc_signed& v);
475 inline sc_signed operator | (int u, const sc_signed& v);
476 inline sc_signed operator | (unsigned int u, const sc_signed& v);
477
478 SC_API sc_signed operator | (const sc_unsigned& u, const sc_int_base& v);
479 SC_API sc_signed operator | (const sc_int_base& u, const sc_unsigned& v);
480 SC_API sc_signed operator | (const sc_signed& u, const sc_int_base& v);
481 SC_API sc_signed operator | (const sc_signed& u, const sc_uint_base& v);
482 SC_API sc_signed operator | (const sc_int_base& u, const sc_signed& v);
483 SC_API sc_signed operator | (const sc_uint_base& u, const sc_signed& v);
484
485
486
487 // Bitwise XOR operators:
488
489 SC_API sc_signed operator ^ (const sc_unsigned& u, const sc_signed& v);
490 SC_API sc_signed operator ^ (const sc_signed& u, const sc_unsigned& v);
491
492 SC_API sc_signed operator ^ (const sc_unsigned& u, int64 v);
493 SC_API sc_signed operator ^ (const sc_unsigned& u, long v);
494 inline sc_signed operator ^ (const sc_unsigned& u, int v);
495
496 SC_API sc_signed operator ^ (int64 u, const sc_unsigned& v);
497 SC_API sc_signed operator ^ (long u, const sc_unsigned& v);
498 inline sc_signed operator ^ (int u, const sc_unsigned& v);
499
500 SC_API sc_signed operator ^ (const sc_signed& u, const sc_signed& v);
501 SC_API sc_signed operator ^ (const sc_signed& u, int64 v);
502 SC_API sc_signed operator ^ (const sc_signed& u, uint64 v);
503 SC_API sc_signed operator ^ (const sc_signed& u, long v);
504 SC_API sc_signed operator ^ (const sc_signed& u, unsigned long v);
505 inline sc_signed operator ^ (const sc_signed& u, int v);
506 inline sc_signed operator ^ (const sc_signed& u, unsigned int v);
507
508 SC_API sc_signed operator ^ (int64 u, const sc_signed& v);
509 SC_API sc_signed operator ^ (uint64 u, const sc_signed& v);
510 SC_API sc_signed operator ^ (long u, const sc_signed& v);
511 SC_API sc_signed operator ^ (unsigned long u, const sc_signed& v);
512 inline sc_signed operator ^ (int u, const sc_signed& v);
513 inline sc_signed operator ^ (unsigned int u, const sc_signed& v);
514
515 SC_API sc_signed operator ^ (const sc_unsigned& u, const sc_int_base& v);
516 SC_API sc_signed operator ^ (const sc_int_base& u, const sc_unsigned& v);
517 SC_API sc_signed operator ^ (const sc_signed& u, const sc_int_base& v);
518 SC_API sc_signed operator ^ (const sc_signed& u, const sc_uint_base& v);
519 SC_API sc_signed operator ^ (const sc_int_base& u, const sc_signed& v);
520 SC_API sc_signed operator ^ (const sc_uint_base& u, const sc_signed& v);
521
522
523
524 // SHIFT OPERATORS:
525
526 // LEFT SHIFT operators:
527
528 SC_API sc_unsigned operator << (const sc_unsigned& u, const sc_signed& v);
529 SC_API sc_signed operator << (const sc_signed& u, const sc_unsigned& v);
530
531 SC_API sc_signed operator << (const sc_signed& u, const sc_signed& v);
532 SC_API sc_signed operator << (const sc_signed& u, int64 v);
533 SC_API sc_signed operator << (const sc_signed& u, uint64 v);
534 SC_API sc_signed operator << (const sc_signed& u, long v);
535 SC_API sc_signed operator << (const sc_signed& u, unsigned long v);
536 inline sc_signed operator << (const sc_signed& u, int v);
537 inline sc_signed operator << (const sc_signed& u, unsigned int v);
538
539 SC_API sc_signed operator << (const sc_signed& u, const sc_int_base& v);
540 SC_API sc_signed operator << (const sc_signed& u, const sc_uint_base& v);
541
542
543
544 // RIGHT SHIFT operators:
545
546 SC_API sc_unsigned operator >> (const sc_unsigned& u, const sc_signed& v);
547 SC_API sc_signed operator >> (const sc_signed& u, const sc_unsigned& v);
548
549 SC_API sc_signed operator >> (const sc_signed& u, const sc_signed& v);
550 SC_API sc_signed operator >> (const sc_signed& u, int64 v);
551 SC_API sc_signed operator >> (const sc_signed& u, uint64 v);
552 SC_API sc_signed operator >> (const sc_signed& u, long v);
553 SC_API sc_signed operator >> (const sc_signed& u, unsigned long v);
554 inline sc_signed operator >> (const sc_signed& u, int v);
555 inline sc_signed operator >> (const sc_signed& u, unsigned int v);
556
557 SC_API sc_signed operator >> (const sc_signed& u, const sc_int_base& v);
558 SC_API sc_signed operator >> (const sc_signed& u, const sc_uint_base& v);
559
560
561
562 // Unary arithmetic operators
563 SC_API sc_signed operator + (const sc_signed& u);
564 SC_API sc_signed operator - (const sc_signed& u);
565 SC_API sc_signed operator - (const sc_unsigned& u);
566
567 // LOGICAL OPERATORS:
568
569 // Logical EQUAL operators:
570
571 SC_API bool operator == (const sc_unsigned& u, const sc_signed& v);
572 SC_API bool operator == (const sc_signed& u, const sc_unsigned& v);
573
574 SC_API bool operator == (const sc_signed& u, const sc_signed& v);
575 SC_API bool operator == (const sc_signed& u, int64 v);
576 SC_API bool operator == (const sc_signed& u, uint64 v);
577 SC_API bool operator == (const sc_signed& u, long v);
578 SC_API bool operator == (const sc_signed& u, unsigned long v);
579 inline bool operator == (const sc_signed& u, int v);
580 inline bool operator == (const sc_signed& u, unsigned int v);
581
582 SC_API bool operator == (int64 u, const sc_signed& v);
583 SC_API bool operator == (uint64 u, const sc_signed& v);
584 SC_API bool operator == (long u, const sc_signed& v);
585 SC_API bool operator == (unsigned long u, const sc_signed& v);
586 inline bool operator == (int u, const sc_signed& v);
587 inline bool operator == (unsigned int u, const sc_signed& v);
588
589 SC_API bool operator == (const sc_signed& u, const sc_int_base& v);
590 SC_API bool operator == (const sc_signed& u, const sc_uint_base& v);
591 SC_API bool operator == (const sc_int_base& u, const sc_signed& v);
592 SC_API bool operator == (const sc_uint_base& u, const sc_signed& v);
593
594 // Logical NOT_EQUAL operators:
595
596 SC_API bool operator != (const sc_unsigned& u, const sc_signed& v);
597 SC_API bool operator != (const sc_signed& u, const sc_unsigned& v);
598
599 SC_API bool operator != (const sc_signed& u, const sc_signed& v);
600 SC_API bool operator != (const sc_signed& u, int64 v);
601 SC_API bool operator != (const sc_signed& u, uint64 v);
602 SC_API bool operator != (const sc_signed& u, long v);
603 SC_API bool operator != (const sc_signed& u, unsigned long v);
604 inline bool operator != (const sc_signed& u, int v);
605 inline bool operator != (const sc_signed& u, unsigned int v);
606
607 SC_API bool operator != (int64 u, const sc_signed& v);
608 SC_API bool operator != (uint64 u, const sc_signed& v);
609 SC_API bool operator != (long u, const sc_signed& v);
610 SC_API bool operator != (unsigned long u, const sc_signed& v);
611 inline bool operator != (int u, const sc_signed& v);
612 inline bool operator != (unsigned int u, const sc_signed& v);
613
614 SC_API bool operator != (const sc_signed& u, const sc_int_base& v);
615 SC_API bool operator != (const sc_signed& u, const sc_uint_base& v);
616 SC_API bool operator != (const sc_int_base& u, const sc_signed& v);
617 SC_API bool operator != (const sc_uint_base& u, const sc_signed& v);
618
619 // Logical LESS_THAN operators:
620
621 SC_API bool operator < (const sc_unsigned& u, const sc_signed& v);
622 SC_API bool operator < (const sc_signed& u, const sc_unsigned& v);
623
624 SC_API bool operator < (const sc_signed& u, const sc_signed& v);
625 SC_API bool operator < (const sc_signed& u, int64 v);
626 SC_API bool operator < (const sc_signed& u, uint64 v);
627 SC_API bool operator < (const sc_signed& u, long v);
628 SC_API bool operator < (const sc_signed& u, unsigned long v);
629 inline bool operator < (const sc_signed& u, int v);
630 inline bool operator < (const sc_signed& u, unsigned int v);
631
632 SC_API bool operator < (int64 u, const sc_signed& v);
633 SC_API bool operator < (uint64 u, const sc_signed& v);
634 SC_API bool operator < (long u, const sc_signed& v);
635 SC_API bool operator < (unsigned long u, const sc_signed& v);
636 inline bool operator < (int u, const sc_signed& v);
637 inline bool operator < (unsigned int u, const sc_signed& v);
638
639 SC_API bool operator < (const sc_signed& u, const sc_int_base& v);
640 SC_API bool operator < (const sc_signed& u, const sc_uint_base& v);
641 SC_API bool operator < (const sc_int_base& u, const sc_signed& v);
642 SC_API bool operator < (const sc_uint_base& u, const sc_signed& v);
643
644 // Logical LESS_THAN_AND_EQUAL operators:
645
646 SC_API bool operator <= (const sc_unsigned& u, const sc_signed& v);
647 SC_API bool operator <= (const sc_signed& u, const sc_unsigned& v);
648
649 SC_API bool operator <= (const sc_signed& u, const sc_signed& v);
650 SC_API bool operator <= (const sc_signed& u, int64 v);
651 SC_API bool operator <= (const sc_signed& u, uint64 v);
652 SC_API bool operator <= (const sc_signed& u, long v);
653 SC_API bool operator <= (const sc_signed& u, unsigned long v);
654 inline bool operator <= (const sc_signed& u, int v);
655 inline bool operator <= (const sc_signed& u, unsigned int v);
656
657 SC_API bool operator <= (int64 u, const sc_signed& v);
658 SC_API bool operator <= (uint64 u, const sc_signed& v);
659 SC_API bool operator <= (long u, const sc_signed& v);
660 SC_API bool operator <= (unsigned long u, const sc_signed& v);
661 inline bool operator <= (int u, const sc_signed& v);
662 inline bool operator <= (unsigned int u, const sc_signed& v);
663
664 SC_API bool operator <= (const sc_signed& u, const sc_int_base& v);
665 SC_API bool operator <= (const sc_signed& u, const sc_uint_base& v);
666 SC_API bool operator <= (const sc_int_base& u, const sc_signed& v);
667 SC_API bool operator <= (const sc_uint_base& u, const sc_signed& v);
668
669 // Logical GREATER_THAN operators:
670
671 SC_API bool operator > (const sc_unsigned& u, const sc_signed& v);
672 SC_API bool operator > (const sc_signed& u, const sc_unsigned& v);
673
674 SC_API bool operator > (const sc_signed& u, const sc_signed& v);
675 SC_API bool operator > (const sc_signed& u, int64 v);
676 SC_API bool operator > (const sc_signed& u, uint64 v);
677 SC_API bool operator > (const sc_signed& u, long v);
678 SC_API bool operator > (const sc_signed& u, unsigned long v);
679 inline bool operator > (const sc_signed& u, int v);
680 inline bool operator > (const sc_signed& u, unsigned int v);
681
682 SC_API bool operator > (int64 u, const sc_signed& v);
683 SC_API bool operator > (uint64 u, const sc_signed& v);
684 SC_API bool operator > (long u, const sc_signed& v);
685 SC_API bool operator > (unsigned long u, const sc_signed& v);
686 inline bool operator > (int u, const sc_signed& v);
687 inline bool operator > (unsigned int u, const sc_signed& v);
688
689 SC_API bool operator > (const sc_signed& u, const sc_int_base& v);
690 SC_API bool operator > (const sc_signed& u, const sc_uint_base& v);
691 SC_API bool operator > (const sc_int_base& u, const sc_signed& v);
692 SC_API bool operator > (const sc_uint_base& u, const sc_signed& v);
693
694 // Logical GREATER_THAN_AND_EQUAL operators:
695
696 SC_API bool operator >= (const sc_unsigned& u, const sc_signed& v);
697 SC_API bool operator >= (const sc_signed& u, const sc_unsigned& v);
698
699 SC_API bool operator >= (const sc_signed& u, const sc_signed& v);
700 SC_API bool operator >= (const sc_signed& u, int64 v);
701 SC_API bool operator >= (const sc_signed& u, uint64 v);
702 SC_API bool operator >= (const sc_signed& u, long v);
703 SC_API bool operator >= (const sc_signed& u, unsigned long v);
704 inline bool operator >= (const sc_signed& u, int v);
705 inline bool operator >= (const sc_signed& u, unsigned int v);
706
707 SC_API bool operator >= (int64 u, const sc_signed& v);
708 SC_API bool operator >= (uint64 u, const sc_signed& v);
709 SC_API bool operator >= (long u, const sc_signed& v);
710 SC_API bool operator >= (unsigned long u, const sc_signed& v);
711 inline bool operator >= (int u, const sc_signed& v);
712 inline bool operator >= (unsigned int u, const sc_signed& v);
713
714 SC_API bool operator >= (const sc_signed& u, const sc_int_base& v);
715 SC_API bool operator >= (const sc_signed& u, const sc_uint_base& v);
716 SC_API bool operator >= (const sc_int_base& u, const sc_signed& v);
717 SC_API bool operator >= (const sc_uint_base& u, const sc_signed& v);
718
719 // Bitwise NOT operator (unary).
720 SC_API sc_signed operator ~ (const sc_signed& u);
721
722 // ----------------------------------------------------------------------------
723 // CLASS : sc_signed_bitref_r
724 //
725 // Proxy class for sc_signed bit selection (r-value only).
726 // ----------------------------------------------------------------------------
727
728 class SC_API sc_signed_bitref_r : public sc_value_base
729 {
730 friend class sc_signed;
731
732 protected:
733
734 // constructor
735
sc_signed_bitref_r()736 sc_signed_bitref_r() : sc_value_base(), m_index(0), m_obj_p(0)
737 {}
738
initialize(const sc_signed * obj_p,int index_)739 void initialize( const sc_signed* obj_p, int index_ )
740 {
741 m_index = index_;
742 m_obj_p = ( const_cast<sc_signed*>( obj_p ) );
743 }
744
745 public:
746
747 // destructor
748
~sc_signed_bitref_r()749 virtual ~sc_signed_bitref_r()
750 {}
751
752 // copy constructor
753
sc_signed_bitref_r(const sc_signed_bitref_r & a)754 sc_signed_bitref_r( const sc_signed_bitref_r& a )
755 : sc_value_base(a), m_index( a.m_index ), m_obj_p( a.m_obj_p )
756 {}
757
758 // capacity
759
length()760 int length() const
761 { return 1; }
762
763
764 // implicit conversion to bool
765
766 operator uint64 () const;
767 bool operator ! () const;
768 bool operator ~ () const;
769
770
771 // explicit conversions
772
value()773 bool value() const
774 { return operator uint64(); }
775
to_bool()776 bool to_bool() const
777 { return operator uint64(); }
778
779 // concatenation support
780
concat_length(bool * xz_present_p)781 virtual int concat_length(bool* xz_present_p) const
782 { if ( xz_present_p ) *xz_present_p = false; return 1; }
concat_get_uint64()783 virtual uint64 concat_get_uint64() const
784 { return (uint64)operator uint64(); }
concat_get_ctrl(sc_digit * dst_p,int low_i)785 virtual bool concat_get_ctrl( sc_digit* dst_p, int low_i ) const
786 {
787 int bit_mask = 1 << (low_i % BITS_PER_DIGIT);
788 int word_i = low_i / BITS_PER_DIGIT;
789 dst_p[word_i] &= ~bit_mask;
790 return false;
791 }
concat_get_data(sc_digit * dst_p,int low_i)792 virtual bool concat_get_data( sc_digit* dst_p, int low_i ) const
793 {
794 int bit_mask = 1 << (low_i % BITS_PER_DIGIT);
795 bool result; // True if non-zero.
796 int word_i = low_i / BITS_PER_DIGIT;
797 if ( operator uint64() )
798 {
799 dst_p[word_i] |= bit_mask;
800 result = true;
801 }
802 else
803 {
804 dst_p[word_i] &= ~bit_mask;
805 result = false;
806 }
807 return result;
808 }
809
810
811 // other methods
812
813 void print( ::std::ostream& os = ::std::cout ) const
814 { os << to_bool(); }
815
816 protected:
817
818 int m_index; // Bit to be selected.
819 sc_signed* m_obj_p; // Target of this bit selection.
820
821 private:
822
823 // disabled
824 const sc_signed_bitref_r& operator = ( const sc_signed_bitref_r& );
825 };
826
827
828
829 inline
830 ::std::ostream&
831 operator << ( ::std::ostream&, const sc_signed_bitref_r& );
832
833
834 // ----------------------------------------------------------------------------
835 // CLASS : sc_signed_bitref
836 //
837 // Proxy class for sc_signed bit selection (r-value and l-value).
838 // ----------------------------------------------------------------------------
839
840 class SC_API sc_signed_bitref
841 : public sc_signed_bitref_r
842 {
843 friend class sc_signed;
844 friend class sc_core::sc_vpool<sc_signed_bitref>;
845
846
847 // constructor
848
849 protected:
850
sc_signed_bitref()851 sc_signed_bitref() : sc_signed_bitref_r()
852 {}
853
854 public:
855
856 // copy constructor
857
sc_signed_bitref(const sc_signed_bitref & a)858 sc_signed_bitref( const sc_signed_bitref& a )
859 : sc_signed_bitref_r( a )
860 {}
861
862 // assignment operators
863
864 const sc_signed_bitref& operator = ( const sc_signed_bitref_r& );
865 const sc_signed_bitref& operator = ( const sc_signed_bitref& );
866 const sc_signed_bitref& operator = ( bool );
867
868 const sc_signed_bitref& operator &= ( bool );
869 const sc_signed_bitref& operator |= ( bool );
870 const sc_signed_bitref& operator ^= ( bool );
871
872 // concatenation methods
873
874 virtual void concat_set(int64 src, int low_i);
875 virtual void concat_set(const sc_signed& src, int low_i);
876 virtual void concat_set(const sc_unsigned& src, int low_i);
877 virtual void concat_set(uint64 src, int low_i);
878
879
880 // other methods
881
882 void scan( ::std::istream& is = ::std::cin );
883
884 protected:
885 static sc_core::sc_vpool<sc_signed_bitref> m_pool;
886 };
887
888
889
890 inline
891 ::std::istream&
892 operator >> ( ::std::istream&, sc_signed_bitref& );
893
894
895 // ----------------------------------------------------------------------------
896 // CLASS : sc_signed_subref_r
897 //
898 // Proxy class for sc_signed part selection (r-value only).
899 // ----------------------------------------------------------------------------
900
901 class SC_API sc_signed_subref_r : public sc_value_base
902 {
903 friend class sc_signed;
904 friend class sc_signed_signal;
905 friend class sc_unsigned;
906
907 protected:
908
909 // constructor
910
sc_signed_subref_r()911 sc_signed_subref_r() : sc_value_base(), m_left(0), m_obj_p(0), m_right(0)
912 {}
913
initialize(const sc_signed * obj_p,int left_,int right_)914 void initialize( const sc_signed* obj_p, int left_, int right_ )
915 {
916 m_obj_p = ( const_cast<sc_signed*>( obj_p ));
917 m_left = left_;
918 m_right = right_;
919 }
920
921
922 public:
923
924 // destructor
925
~sc_signed_subref_r()926 virtual ~sc_signed_subref_r()
927 {}
928
929 // copy constructor
930
sc_signed_subref_r(const sc_signed_subref_r & a)931 sc_signed_subref_r( const sc_signed_subref_r& a )
932 : sc_value_base(a), m_left( a.m_left ), m_obj_p( a.m_obj_p ),
933 m_right( a.m_right )
934 {}
935
936
937 // capacity
938
length()939 int length() const
940 { return m_left >= m_right ? (m_left-m_right+1) : (m_right-m_left+1 ); }
941
942
943 // implicit conversion to sc_unsigned
944
945 operator sc_unsigned () const;
946
947
948 // explicit conversions
949
950 int to_int() const;
951 unsigned int to_uint() const;
952 long to_long() const;
953 unsigned long to_ulong() const;
954 int64 to_int64() const;
955 uint64 to_uint64() const;
956 double to_double() const;
957
958
959 // explicit conversion to character string
960
961 const std::string to_string( sc_numrep numrep = SC_DEC ) const;
962 const std::string to_string( sc_numrep numrep, bool w_prefix ) const;
963
964 // concatenation support
965
concat_length(bool * xz_present_p)966 virtual int concat_length(bool* xz_present_p) const
967 {
968 if ( xz_present_p ) *xz_present_p = false;
969 return m_left - m_right + 1;
970 }
971 virtual uint64 concat_get_uint64() const;
972 virtual bool concat_get_ctrl( sc_digit* dst_p, int low_i ) const;
973 virtual bool concat_get_data( sc_digit* dst_p, int low_i ) const;
974
975 // reduce methods
976
977 bool and_reduce() const;
978 bool nand_reduce() const;
979 bool or_reduce() const;
980 bool nor_reduce() const;
981 bool xor_reduce() const ;
982 bool xnor_reduce() const;
983
984
985 // other methods
986
987 void print( ::std::ostream& os = ::std::cout ) const
988 { os << to_string(sc_io_base(os,SC_DEC),sc_io_show_base(os)); }
989
990 protected:
991
992 int m_left; // Left-most bit in this part selection.
993 sc_signed* m_obj_p; // Target of this part selection.
994 int m_right; // Right-most bit in this part selection.
995
996 private:
997 const sc_signed_subref_r& operator = ( const sc_signed_subref_r& );
998
999 };
1000
1001
1002
1003 inline
1004 ::std::ostream&
1005 operator << ( ::std::ostream&, const sc_signed_subref_r& );
1006
1007
1008 // ----------------------------------------------------------------------------
1009 // CLASS : sc_signed_subref
1010 //
1011 // Proxy class for sc_signed part selection (r-value and l-value).
1012 // ----------------------------------------------------------------------------
1013
1014 class SC_API sc_signed_subref
1015 : public sc_signed_subref_r
1016 {
1017 friend class sc_signed;
1018 friend class sc_core::sc_vpool<sc_signed_subref>;
1019
1020
1021 // constructor
1022
sc_signed_subref()1023 sc_signed_subref() : sc_signed_subref_r()
1024 {}
1025
1026 public:
1027
1028 // copy constructor
1029
sc_signed_subref(const sc_signed_subref & a)1030 sc_signed_subref( const sc_signed_subref& a )
1031 : sc_signed_subref_r( a )
1032 {}
1033
1034
1035 // assignment operators
1036
1037 const sc_signed_subref& operator = ( const sc_signed_subref_r& a );
1038 const sc_signed_subref& operator = ( const sc_signed_subref& a );
1039 const sc_signed_subref& operator = ( const sc_signed& a );
1040
1041 const sc_signed_subref& operator = ( const sc_unsigned_subref_r& a );
1042 const sc_signed_subref& operator = ( const sc_unsigned& a );
1043
1044 template< class T >
1045 const sc_signed_subref& operator = ( const sc_generic_base<T>& a )
1046 {
1047 sc_unsigned temp( length() );
1048 a->to_sc_unsigned(temp);
1049 return operator = (temp);
1050 }
1051
1052 const sc_signed_subref& operator = ( const char* a );
1053 const sc_signed_subref& operator = ( unsigned long a );
1054 const sc_signed_subref& operator = ( long a );
1055 const sc_signed_subref& operator = ( unsigned int a )
1056 { return operator = ( (unsigned long) a ); }
1057
1058 const sc_signed_subref& operator = ( int a )
1059 { return operator = ( (long) a ); }
1060
1061 const sc_signed_subref& operator = ( uint64 a );
1062 const sc_signed_subref& operator = ( int64 a );
1063 const sc_signed_subref& operator = ( double a );
1064 const sc_signed_subref& operator = ( const sc_int_base& a );
1065 const sc_signed_subref& operator = ( const sc_uint_base& a );
1066
1067 // concatenation methods
1068
1069 virtual void concat_set(int64 src, int low_i);
1070 virtual void concat_set(const sc_signed& src, int low_i);
1071 virtual void concat_set(const sc_unsigned& src, int low_i);
1072 virtual void concat_set(uint64 src, int low_i);
1073
1074 // other methods
1075
1076 void scan( ::std::istream& is = ::std::cin );
1077
1078 protected:
1079 static sc_core::sc_vpool<sc_signed_subref> m_pool;
1080 };
1081
1082
1083
1084 inline
1085 ::std::istream&
1086 operator >> ( ::std::istream&, sc_signed_subref& );
1087
1088
1089 // ----------------------------------------------------------------------------
1090 // CLASS : sc_signed
1091 //
1092 // Arbitrary precision signed number.
1093 // ----------------------------------------------------------------------------
1094
1095 class SC_API sc_signed : public sc_value_base
1096 {
1097 friend class sc_concatref;
1098 friend class sc_signed_bitref_r;
1099 friend class sc_signed_bitref;
1100 friend class sc_signed_subref_r;
1101 friend class sc_signed_subref;
1102 friend class sc_unsigned;
1103 friend class sc_unsigned_subref;
1104
1105 // Needed for types using sc_signed.
1106 typedef bool elemtype;
1107
1108 void invalid_init( const char* type_name, int nb ) const;
1109
1110 public:
1111
1112 // constructors
1113
1114 explicit sc_signed( int nb = sc_length_param().len() );
1115 sc_signed( const sc_signed& v );
1116 sc_signed( const sc_unsigned& v );
1117 template<class T>
1118 explicit sc_signed( const sc_generic_base<T>& v );
1119 explicit sc_signed( const sc_bv_base& v );
1120 explicit sc_signed( const sc_lv_base& v );
1121 explicit sc_signed( const sc_int_subref_r& v );
1122 explicit sc_signed( const sc_uint_subref_r& v );
1123 explicit sc_signed( const sc_signed_subref_r& v );
1124 explicit sc_signed( const sc_unsigned_subref_r& v );
1125
1126 // assignment operators
1127
1128 const sc_signed& operator = (const sc_signed& v);
1129 const sc_signed& operator = (const sc_signed_subref_r& a );
1130
1131 template< class T >
1132 const sc_signed& operator = ( const sc_generic_base<T>& a )
1133 { a->to_sc_signed(*this); return *this; }
1134
1135 const sc_signed& operator = (const sc_unsigned& v);
1136 const sc_signed& operator = (const sc_unsigned_subref_r& a );
1137
1138 const sc_signed& operator = (const char* v);
1139 const sc_signed& operator = (int64 v);
1140 const sc_signed& operator = (uint64 v);
1141 const sc_signed& operator = (long v);
1142 const sc_signed& operator = (unsigned long v);
1143
1144 const sc_signed& operator = (int v)
1145 { return operator=((long) v); }
1146
1147 const sc_signed& operator = (unsigned int v)
1148 { return operator=((unsigned long) v); }
1149
1150 const sc_signed& operator = (double v);
1151 const sc_signed& operator = (const sc_int_base& v);
1152 const sc_signed& operator = (const sc_uint_base& v);
1153
1154 const sc_signed& operator = ( const sc_bv_base& );
1155 const sc_signed& operator = ( const sc_lv_base& );
1156
1157 #ifdef SC_INCLUDE_FX
1158 const sc_signed& operator = ( const sc_fxval& );
1159 const sc_signed& operator = ( const sc_fxval_fast& );
1160 const sc_signed& operator = ( const sc_fxnum& );
1161 const sc_signed& operator = ( const sc_fxnum_fast& );
1162 #endif
1163
1164
1165 // destructor
1166
~sc_signed()1167 virtual ~sc_signed()
1168 {
1169 #ifndef SC_MAX_NBITS
1170 delete [] digit;
1171 #endif
1172 }
1173
1174 // Concatenation support:
1175
get_raw()1176 sc_digit* get_raw() const
1177 { return digit; }
concat_length(bool * xz_present_p)1178 virtual int concat_length(bool* xz_present_p) const
1179 { if ( xz_present_p ) *xz_present_p = false; return nbits; }
1180 virtual bool concat_get_ctrl( sc_digit* dst_p, int low_i ) const;
1181 virtual bool concat_get_data( sc_digit* dst_p, int low_i ) const;
1182 virtual uint64 concat_get_uint64() const;
1183 virtual void concat_set(int64 src, int low_i);
1184 virtual void concat_set(const sc_signed& src, int low_i);
1185 virtual void concat_set(const sc_unsigned& src, int low_i);
1186 virtual void concat_set(uint64 src, int low_i);
1187
1188
1189
1190 // Increment operators.
1191 sc_signed& operator ++ ();
1192 const sc_signed operator ++ (int);
1193
1194 // Decrement operators.
1195 sc_signed& operator -- ();
1196 const sc_signed operator -- (int);
1197
1198
1199 // bit selection
1200
check_index(int i)1201 inline void check_index( int i ) const
1202 { if ( i < 0 || i >= nbits ) invalid_index(i); }
1203
1204 void invalid_index( int i ) const;
1205
1206 sc_signed_bitref& operator [] ( int i )
1207 {
1208 check_index(i);
1209 sc_signed_bitref* result_p =
1210 sc_signed_bitref::m_pool.allocate();
1211 result_p->initialize( this, i );
1212 return *result_p;
1213 }
1214
1215 const sc_signed_bitref_r& operator [] ( int i ) const
1216 {
1217 check_index(i);
1218 sc_signed_bitref* result_p =
1219 sc_signed_bitref::m_pool.allocate();
1220 result_p->initialize( this, i );
1221 return *result_p;
1222 }
1223
bit(int i)1224 sc_signed_bitref& bit( int i )
1225 {
1226 check_index(i);
1227 sc_signed_bitref* result_p =
1228 sc_signed_bitref::m_pool.allocate();
1229 result_p->initialize( this, i );
1230 return *result_p;
1231 }
1232
bit(int i)1233 const sc_signed_bitref_r& bit( int i ) const
1234 {
1235 check_index(i);
1236 sc_signed_bitref* result_p =
1237 sc_signed_bitref::m_pool.allocate();
1238 result_p->initialize( this, i );
1239 return *result_p;
1240 }
1241
1242
1243 // part selection
1244
1245 // Subref operators. Help access the range of bits from the ith to
1246 // jth. These indices have arbitrary precedence with respect to each
1247 // other, i.e., we can have i <= j or i > j. Note the equivalence
1248 // between range(i, j) and operator(i, j). Also note that
1249 // operator(i, i) returns a signed number that corresponds to the
1250 // bit operator[i], so these two forms are not the same.
1251
check_range(int l,int r)1252 inline void check_range( int l, int r ) const
1253 {
1254 if ( l < r )
1255 {
1256 if ( l < 0 || r >= nbits ) invalid_range(l,r);
1257 }
1258 else
1259 {
1260 if ( r < 0 || l >= nbits ) invalid_range(l,r);
1261 }
1262 }
1263
1264 void invalid_range( int l, int r ) const;
1265
range(int i,int j)1266 sc_signed_subref& range( int i, int j )
1267 {
1268 check_range( i, j );
1269 sc_signed_subref* result_p =
1270 sc_signed_subref::m_pool.allocate();
1271 result_p->initialize( this, i, j );
1272 return *result_p;
1273 }
1274
range(int i,int j)1275 const sc_signed_subref_r& range( int i, int j ) const
1276 {
1277 check_range( i, j );
1278 sc_signed_subref* result_p =
1279 sc_signed_subref::m_pool.allocate();
1280 result_p->initialize( this, i, j );
1281 return *result_p;
1282 }
1283
operator()1284 sc_signed_subref& operator () ( int i, int j )
1285 {
1286 check_range( i, j );
1287 sc_signed_subref* result_p =
1288 sc_signed_subref::m_pool.allocate();
1289 result_p->initialize( this, i, j );
1290 return *result_p;
1291 }
1292
operator()1293 const sc_signed_subref_r& operator () ( int i, int j ) const
1294 {
1295 check_range( i, j );
1296 sc_signed_subref* result_p =
1297 sc_signed_subref::m_pool.allocate();
1298 result_p->initialize( this, i, j );
1299 return *result_p;
1300 }
1301
1302
1303 // explicit conversions
1304
1305 int to_int() const;
1306 unsigned int to_uint() const;
1307 long to_long() const;
1308 unsigned long to_ulong() const;
1309 int64 to_int64() const;
1310 uint64 to_uint64() const;
1311 double to_double() const;
1312
1313 #ifdef SC_DT_DEPRECATED
to_signed()1314 int to_signed() const
1315 { return to_int(); }
1316
to_unsigned()1317 unsigned int to_unsigned() const
1318 { return to_uint(); }
1319 #endif
1320
1321 // explicit conversion to character string
1322
1323 const std::string to_string( sc_numrep numrep = SC_DEC ) const;
1324 const std::string to_string( sc_numrep numrep, bool w_prefix ) const;
1325
1326
1327 // Print functions. dump prints the internals of the class.
1328
1329 void print( ::std::ostream& os = ::std::cout ) const
1330 { os << to_string(sc_io_base(os,SC_DEC),sc_io_show_base(os)); }
1331
1332 void scan( ::std::istream& is = ::std::cin );
1333
1334 void dump( ::std::ostream& os = ::std::cout ) const;
1335
1336
1337 // Functions to find various properties.
length()1338 int length() const { return nbits; } // Bit width.
1339 bool iszero() const; // Is the number zero?
1340 bool sign() const; // Sign.
1341
1342 // reduce methods
1343
1344 bool and_reduce() const;
1345
nand_reduce()1346 bool nand_reduce() const
1347 { return ( ! and_reduce() ); }
1348
1349 bool or_reduce() const;
1350
nor_reduce()1351 bool nor_reduce() const
1352 { return ( ! or_reduce() ); }
1353
1354 bool xor_reduce() const;
1355
xnor_reduce()1356 bool xnor_reduce() const
1357 { return ( ! xor_reduce() ); }
1358
1359 // Functions to access individual bits.
1360 bool test(int i) const; // Is the ith bit 0 or 1?
1361 void set(int i); // Set the ith bit to 1.
1362 void clear(int i); // Set the ith bit to 0.
set(int i,bool v)1363 void set(int i, bool v) // Set the ith bit to v.
1364 { if (v) set(i); else clear(i); }
invert(int i)1365 void invert(int i) // Negate the ith bit.
1366 { if (test(i)) clear(i); else set(i); }
1367
1368 // Make the number equal to its mirror image.
1369 void reverse();
1370
1371 // Get/set a packed bit representation of the number.
1372 void get_packed_rep(sc_digit *buf) const;
1373 void set_packed_rep(sc_digit *buf);
1374
1375 /*
1376 The comparison of the old and new semantics are as follows:
1377
1378 Let s = sc_signed,
1379 u = sc_unsigned,
1380 un = { uint64, unsigned long, unsigned int },
1381 sn = { int64, long, int, char* }, and
1382 OP = { +, -, *, /, % }.
1383
1384 Old semantics: New semantics:
1385 u OP u -> u u OP u -> u
1386 s OP u -> u s OP u -> s
1387 u OP s -> u u OP s -> s
1388 s OP s -> s s OP s -> s
1389
1390 u OP un = un OP u -> u u OP un = un OP u -> u
1391 u OP sn = sn OP u -> u u OP sn = sn OP u -> s
1392
1393 s OP un = un OP s -> s s OP un = un OP s -> s
1394 s OP sn = sn OP s -> s s OP sn = sn OP s -> s
1395
1396 In the new semantics, the result is u if both operands are u; the
1397 result is s otherwise. The only exception is subtraction. The result
1398 of a subtraction is always s.
1399
1400 The old semantics is like C/C++ semantics on integer types; the
1401 new semantics is due to the VSIA C/C++ data types standard.
1402 */
1403
1404 // ARITHMETIC OPERATORS:
1405
1406 // ADDition operators:
1407
1408 friend SC_API sc_signed operator + (const sc_unsigned& u, const sc_signed& v);
1409 friend SC_API sc_signed operator + (const sc_signed& u, const sc_unsigned& v);
1410
1411 friend SC_API sc_signed operator + (const sc_unsigned& u, int64 v);
1412 friend SC_API sc_signed operator + (const sc_unsigned& u, long v);
1413 friend sc_signed operator + (const sc_unsigned& u, int v)
1414 { return operator+(u, (long) v); }
1415
1416 friend SC_API sc_signed operator + (int64 u, const sc_unsigned& v);
1417 friend SC_API sc_signed operator + (long u, const sc_unsigned& v);
1418 friend sc_signed operator + (int u, const sc_unsigned& v)
1419 { return operator+((long) u, v); }
1420
1421 friend SC_API sc_signed operator + (const sc_signed& u, const sc_signed& v);
1422 friend SC_API sc_signed operator + (const sc_signed& u, int64 v);
1423 friend SC_API sc_signed operator + (const sc_signed& u, uint64 v);
1424 friend SC_API sc_signed operator + (const sc_signed& u, long v);
1425 friend SC_API sc_signed operator + (const sc_signed& u, unsigned long v);
1426 friend sc_signed operator + (const sc_signed& u, int v)
1427 { return operator+(u, (long) v); }
1428 friend sc_signed operator + (const sc_signed& u, unsigned int v)
1429 { return operator+(u, (unsigned long) v); }
1430
1431 friend SC_API sc_signed operator + (int64 u, const sc_signed& v);
1432 friend SC_API sc_signed operator + (uint64 u, const sc_signed& v);
1433 friend SC_API sc_signed operator + (long u, const sc_signed& v);
1434 friend SC_API sc_signed operator + (unsigned long u, const sc_signed& v);
1435 friend sc_signed operator + (int u, const sc_signed& v)
1436 { return operator+((long) u, v); }
1437 friend sc_signed operator + (unsigned int u, const sc_signed& v)
1438 { return operator+((unsigned long) u, v); }
1439
1440 const sc_signed& operator += (const sc_signed& v);
1441 const sc_signed& operator += (const sc_unsigned& v);
1442 const sc_signed& operator += (int64 v);
1443 const sc_signed& operator += (uint64 v);
1444 const sc_signed& operator += (long v);
1445 const sc_signed& operator += (unsigned long v);
1446 const sc_signed& operator += (int v)
1447 { return operator+=((long) v); }
1448 const sc_signed& operator += (unsigned int v)
1449 { return operator+=((unsigned long) v); }
1450
1451 friend SC_API sc_signed operator + (const sc_unsigned& u, const sc_int_base& v);
1452 friend SC_API sc_signed operator + (const sc_int_base& u, const sc_unsigned& v);
1453 friend SC_API sc_signed operator + (const sc_signed& u, const sc_int_base& v);
1454 friend SC_API sc_signed operator + (const sc_signed& u, const sc_uint_base& v);
1455 friend SC_API sc_signed operator + (const sc_int_base& u, const sc_signed& v);
1456 friend SC_API sc_signed operator + (const sc_uint_base& u, const sc_signed& v);
1457 const sc_signed& operator += (const sc_int_base& v);
1458 const sc_signed& operator += (const sc_uint_base& v);
1459
1460 // SUBtraction operators:
1461
1462 friend SC_API sc_signed operator - (const sc_unsigned& u, const sc_signed& v);
1463 friend SC_API sc_signed operator - (const sc_signed& u, const sc_unsigned& v);
1464
1465 friend SC_API sc_signed operator - (const sc_unsigned& u, const sc_unsigned& v);
1466 friend SC_API sc_signed operator - (const sc_unsigned& u, int64 v);
1467 friend SC_API sc_signed operator - (const sc_unsigned& u, uint64 v);
1468 friend SC_API sc_signed operator - (const sc_unsigned& u, long v);
1469 friend SC_API sc_signed operator - (const sc_unsigned& u, unsigned long v);
1470 friend sc_signed operator - (const sc_unsigned& u, int v)
1471 { return operator-(u, (long) v); }
1472 friend sc_signed operator - (const sc_unsigned& u, unsigned int v)
1473 { return operator-(u, (unsigned long) v); }
1474
1475 friend SC_API sc_signed operator - (int64 u, const sc_unsigned& v);
1476 friend SC_API sc_signed operator - (uint64 u, const sc_unsigned& v);
1477 friend SC_API sc_signed operator - (long u, const sc_unsigned& v);
1478 friend SC_API sc_signed operator - (unsigned long u, const sc_unsigned& v);
1479 friend sc_signed operator - (int u, const sc_unsigned& v)
1480 { return operator-((long) u, v); }
1481 friend sc_signed operator - (unsigned int u, const sc_unsigned& v)
1482 { return operator-((unsigned long) u, v); }
1483
1484 friend SC_API sc_signed operator - (const sc_signed& u, const sc_signed& v);
1485 friend SC_API sc_signed operator - (const sc_signed& u, int64 v);
1486 friend SC_API sc_signed operator - (const sc_signed& u, uint64 v);
1487 friend SC_API sc_signed operator - (const sc_signed& u, long v);
1488 friend SC_API sc_signed operator - (const sc_signed& u, unsigned long v);
1489 friend sc_signed operator - (const sc_signed& u, int v)
1490 { return operator-(u, (long) v); }
1491 friend sc_signed operator - (const sc_signed& u, unsigned int v)
1492 { return operator-(u, (unsigned long) v); }
1493
1494 friend SC_API sc_signed operator - (int64 u, const sc_signed& v);
1495 friend SC_API sc_signed operator - (uint64 u, const sc_signed& v);
1496 friend SC_API sc_signed operator - (long u, const sc_signed& v);
1497 friend SC_API sc_signed operator - (unsigned long u, const sc_signed& v);
1498 friend sc_signed operator - (int u, const sc_signed& v)
1499 { return operator-((long) u, v); }
1500 friend sc_signed operator - (unsigned int u, const sc_signed& v)
1501 { return operator-((unsigned long) u, v); }
1502
1503 const sc_signed& operator -= (const sc_signed& v);
1504 const sc_signed& operator -= (const sc_unsigned& v);
1505 const sc_signed& operator -= (int64 v);
1506 const sc_signed& operator -= (uint64 v);
1507 const sc_signed& operator -= (long v);
1508 const sc_signed& operator -= (unsigned long v);
1509 const sc_signed& operator -= (int v)
1510 { return operator -= ((long) v); }
1511 const sc_signed& operator -= (unsigned int v)
1512 { return operator -= ((unsigned long) v); }
1513
1514 friend SC_API sc_signed operator - (const sc_unsigned& u, const sc_int_base& v);
1515 friend SC_API sc_signed operator - (const sc_unsigned& u, const sc_uint_base& v);
1516 friend SC_API sc_signed operator - (const sc_int_base& u, const sc_unsigned& v);
1517 friend SC_API sc_signed operator - (const sc_uint_base& u, const sc_unsigned& v);
1518 friend SC_API sc_signed operator - (const sc_signed& u, const sc_int_base& v);
1519 friend SC_API sc_signed operator - (const sc_signed& u, const sc_uint_base& v);
1520 friend SC_API sc_signed operator - (const sc_int_base& u, const sc_signed& v);
1521 friend SC_API sc_signed operator - (const sc_uint_base& u, const sc_signed& v);
1522 const sc_signed& operator -= (const sc_int_base& v);
1523 const sc_signed& operator -= (const sc_uint_base& v);
1524
1525 // MULtiplication operators:
1526
1527 friend SC_API sc_signed operator * (const sc_unsigned& u, const sc_signed& v);
1528 friend SC_API sc_signed operator * (const sc_signed& u, const sc_unsigned& v);
1529
1530 friend SC_API sc_signed operator * (const sc_unsigned& u, int64 v);
1531 friend SC_API sc_signed operator * (const sc_unsigned& u, long v);
1532 friend sc_signed operator * (const sc_unsigned& u, int v)
1533 { return operator*(u, (long) v); }
1534
1535 friend SC_API sc_signed operator * (int64 u, const sc_unsigned& v);
1536 friend SC_API sc_signed operator * (long u, const sc_unsigned& v);
1537 friend sc_signed operator * (int u, const sc_unsigned& v)
1538 { return operator*((long) u, v); }
1539
1540 friend SC_API sc_signed operator * (const sc_signed& u, const sc_signed& v);
1541 friend SC_API sc_signed operator * (const sc_signed& u, int64 v);
1542 friend SC_API sc_signed operator * (const sc_signed& u, uint64 v);
1543 friend SC_API sc_signed operator * (const sc_signed& u, long v);
1544 friend SC_API sc_signed operator * (const sc_signed& u, unsigned long v);
1545 friend sc_signed operator * (const sc_signed& u, int v)
1546 { return operator*(u, (long) v); }
1547 friend sc_signed operator * (const sc_signed& u, unsigned int v)
1548 { return operator*(u, (unsigned long) v); }
1549
1550 friend SC_API sc_signed operator * (int64 u, const sc_signed& v);
1551 friend SC_API sc_signed operator * (uint64 u, const sc_signed& v);
1552 friend SC_API sc_signed operator * (long u, const sc_signed& v);
1553 friend SC_API sc_signed operator * (unsigned long u, const sc_signed& v);
1554 friend sc_signed operator * (int u, const sc_signed& v)
1555 { return operator*((long) u, v); }
1556 friend sc_signed operator * (unsigned int u, const sc_signed& v)
1557 { return operator*((unsigned long) u, v); }
1558
1559 const sc_signed& operator *= (const sc_signed& v);
1560 const sc_signed& operator *= (const sc_unsigned& v);
1561 const sc_signed& operator *= (int64 v);
1562 const sc_signed& operator *= (uint64 v);
1563 const sc_signed& operator *= (long v);
1564 const sc_signed& operator *= (unsigned long v);
1565 const sc_signed& operator *= (int v)
1566 { return operator*=((long) v); }
1567 const sc_signed& operator *= (unsigned int v)
1568 { return operator*=((unsigned long) v); }
1569
1570 friend SC_API sc_signed operator * (const sc_unsigned& u, const sc_int_base& v);
1571 friend SC_API sc_signed operator * (const sc_int_base& u, const sc_unsigned& v);
1572 friend SC_API sc_signed operator * (const sc_signed& u, const sc_int_base& v);
1573 friend SC_API sc_signed operator * (const sc_signed& u, const sc_uint_base& v);
1574 friend SC_API sc_signed operator * (const sc_int_base& u, const sc_signed& v);
1575 friend SC_API sc_signed operator * (const sc_uint_base& u, const sc_signed& v);
1576 const sc_signed& operator *= (const sc_int_base& v);
1577 const sc_signed& operator *= (const sc_uint_base& v);
1578
1579 // DIVision operators:
1580
1581 friend SC_API sc_signed operator / (const sc_unsigned& u, const sc_signed& v);
1582 friend SC_API sc_signed operator / (const sc_signed& u, const sc_unsigned& v);
1583
1584 friend SC_API sc_signed operator / (const sc_unsigned& u, int64 v);
1585 friend SC_API sc_signed operator / (const sc_unsigned& u, long v);
1586 friend sc_signed operator / (const sc_unsigned& u, int v)
1587 { return operator/(u, (long) v); }
1588
1589 friend SC_API sc_signed operator / (int64 u, const sc_unsigned& v);
1590 friend SC_API sc_signed operator / (long u, const sc_unsigned& v);
1591 friend sc_signed operator / (int u, const sc_unsigned& v)
1592 { return operator/((long) u, v); }
1593
1594 friend SC_API sc_signed operator / (const sc_signed& u, const sc_signed& v);
1595 friend SC_API sc_signed operator / (const sc_signed& u, int64 v);
1596 friend SC_API sc_signed operator / (const sc_signed& u, uint64 v);
1597 friend SC_API sc_signed operator / (const sc_signed& u, long v);
1598 friend SC_API sc_signed operator / (const sc_signed& u, unsigned long v);
1599 friend sc_signed operator / (const sc_signed& u, int v)
1600 { return operator/(u, (long) v); }
1601 friend sc_signed operator / (const sc_signed& u, unsigned int v)
1602 { return operator/(u, (unsigned long) v); }
1603
1604 friend SC_API sc_signed operator / (int64 u, const sc_signed& v);
1605 friend SC_API sc_signed operator / (uint64 u, const sc_signed& v);
1606 friend SC_API sc_signed operator / (long u, const sc_signed& v);
1607 friend SC_API sc_signed operator / (unsigned long u, const sc_signed& v);
1608 friend sc_signed operator / (int u, const sc_signed& v)
1609 { return operator/((long) u, v); }
1610 friend sc_signed operator / (unsigned int u, const sc_signed& v)
1611 { return operator/((unsigned long) u, v); }
1612
1613 const sc_signed& operator /= (const sc_signed& v);
1614 const sc_signed& operator /= (const sc_unsigned& v);
1615 const sc_signed& operator /= (int64 v);
1616 const sc_signed& operator /= (uint64 v);
1617 const sc_signed& operator /= (long v);
1618 const sc_signed& operator /= (unsigned long v);
1619 const sc_signed& operator /= (int v)
1620 { return operator/=((long) v); }
1621 const sc_signed& operator /= (unsigned int v)
1622 { return operator/=((unsigned long) v); }
1623
1624 friend SC_API sc_signed operator / (const sc_unsigned& u, const sc_int_base& v);
1625 friend SC_API sc_signed operator / (const sc_int_base& u, const sc_unsigned& v);
1626 friend SC_API sc_signed operator / (const sc_signed& u, const sc_int_base& v);
1627 friend SC_API sc_signed operator / (const sc_signed& u, const sc_uint_base& v);
1628 friend SC_API sc_signed operator / (const sc_int_base& u, const sc_signed& v);
1629 friend SC_API sc_signed operator / (const sc_uint_base& u, const sc_signed& v);
1630 const sc_signed& operator /= (const sc_int_base& v);
1631 const sc_signed& operator /= (const sc_uint_base& v);
1632
1633 // MODulo operators:
1634
1635 friend SC_API sc_signed operator % (const sc_unsigned& u, const sc_signed& v);
1636 friend SC_API sc_signed operator % (const sc_signed& u, const sc_unsigned& v);
1637
1638 friend SC_API sc_signed operator % (const sc_unsigned& u, int64 v);
1639 friend SC_API sc_signed operator % (const sc_unsigned& u, long v);
1640 friend sc_signed operator % (const sc_unsigned& u, int v)
1641 { return operator%(u, (long) v); }
1642
1643 friend SC_API sc_signed operator % (int64 u, const sc_unsigned& v);
1644 friend SC_API sc_signed operator % (long u, const sc_unsigned& v);
1645 friend sc_signed operator % (int u, const sc_unsigned& v)
1646 { return operator%((long) u, v); }
1647
1648 friend SC_API sc_signed operator % (const sc_signed& u, const sc_signed& v);
1649 friend SC_API sc_signed operator % (const sc_signed& u, int64 v);
1650 friend SC_API sc_signed operator % (const sc_signed& u, uint64 v);
1651 friend SC_API sc_signed operator % (const sc_signed& u, long v);
1652 friend SC_API sc_signed operator % (const sc_signed& u, unsigned long v);
1653 friend sc_signed operator % (const sc_signed& u, int v)
1654 { return operator%(u, (long) v); }
1655 friend sc_signed operator % (const sc_signed& u, unsigned int v)
1656 { return operator%(u, (unsigned long) v); }
1657
1658 friend SC_API sc_signed operator % (int64 u, const sc_signed& v);
1659 friend SC_API sc_signed operator % (uint64 u, const sc_signed& v);
1660 friend SC_API sc_signed operator % (long u, const sc_signed& v);
1661 friend SC_API sc_signed operator % (unsigned long u, const sc_signed& v);
1662 friend sc_signed operator % (int u, const sc_signed& v)
1663 { return operator%((long) u, v); }
1664 friend sc_signed operator % (unsigned int u, const sc_signed& v)
1665 { return operator%((unsigned long) u, v); }
1666
1667 const sc_signed& operator %= (const sc_signed& v);
1668 const sc_signed& operator %= (const sc_unsigned& v);
1669 const sc_signed& operator %= (int64 v);
1670 const sc_signed& operator %= (uint64 v);
1671 const sc_signed& operator %= (long v);
1672 const sc_signed& operator %= (unsigned long v);
1673 const sc_signed& operator %= (int v)
1674 { return operator%=((long) v); }
1675 const sc_signed& operator %= (unsigned int v)
1676 { return operator%=((unsigned long) v); }
1677
1678 friend SC_API sc_signed operator % (const sc_unsigned& u, const sc_int_base& v);
1679 friend SC_API sc_signed operator % (const sc_int_base& u, const sc_unsigned& v);
1680 friend SC_API sc_signed operator % (const sc_signed& u, const sc_int_base& v);
1681 friend SC_API sc_signed operator % (const sc_signed& u, const sc_uint_base& v);
1682 friend SC_API sc_signed operator % (const sc_int_base& u, const sc_signed& v);
1683 friend SC_API sc_signed operator % (const sc_uint_base& u, const sc_signed& v);
1684 const sc_signed& operator %= (const sc_int_base& v);
1685 const sc_signed& operator %= (const sc_uint_base& v);
1686
1687 // BITWISE OPERATORS:
1688
1689 // Bitwise AND operators:
1690
1691 friend SC_API sc_signed operator & (const sc_unsigned& u, const sc_signed& v);
1692 friend SC_API sc_signed operator & (const sc_signed& u, const sc_unsigned& v);
1693
1694 friend SC_API sc_signed operator & (const sc_unsigned& u, int64 v);
1695 friend SC_API sc_signed operator & (const sc_unsigned& u, long v);
1696 friend sc_signed operator & (const sc_unsigned& u, int v)
1697 { return operator&(u, (long) v); }
1698
1699 friend SC_API sc_signed operator & (int64 u, const sc_unsigned& v);
1700 friend SC_API sc_signed operator & (long u, const sc_unsigned& v);
1701 friend sc_signed operator & (int u, const sc_unsigned& v)
1702 { return operator&((long) u, v); }
1703
1704 friend SC_API sc_signed operator & (const sc_signed& u, const sc_signed& v);
1705 friend SC_API sc_signed operator & (const sc_signed& u, int64 v);
1706 friend SC_API sc_signed operator & (const sc_signed& u, uint64 v);
1707 friend SC_API sc_signed operator & (const sc_signed& u, long v);
1708 friend SC_API sc_signed operator & (const sc_signed& u, unsigned long v);
1709 friend sc_signed operator & (const sc_signed& u, int v)
1710 { return operator&(u, (long) v); }
1711 friend sc_signed operator & (const sc_signed& u, unsigned int v)
1712 { return operator&(u, (unsigned long) v); }
1713
1714 friend SC_API sc_signed operator & (int64 u, const sc_signed& v);
1715 friend SC_API sc_signed operator & (uint64 u, const sc_signed& v);
1716 friend SC_API sc_signed operator & (long u, const sc_signed& v);
1717 friend SC_API sc_signed operator & (unsigned long u, const sc_signed& v);
1718 friend sc_signed operator & (int u, const sc_signed& v)
1719 { return operator&((long) u, v); }
1720 friend sc_signed operator & (unsigned int u, const sc_signed& v)
1721 { return operator&((unsigned long) u, v); }
1722
1723 const sc_signed& operator &= (const sc_signed& v);
1724 const sc_signed& operator &= (const sc_unsigned& v);
1725 const sc_signed& operator &= (int64 v);
1726 const sc_signed& operator &= (uint64 v);
1727 const sc_signed& operator &= (long v);
1728 const sc_signed& operator &= (unsigned long v);
1729 const sc_signed& operator &= (int v)
1730 { return operator&=((long) v); }
1731 const sc_signed& operator &= (unsigned int v)
1732 { return operator&=((unsigned long) v); }
1733
1734 friend SC_API sc_signed operator & (const sc_unsigned& u, const sc_int_base& v);
1735 friend SC_API sc_signed operator & (const sc_int_base& u, const sc_unsigned& v);
1736 friend SC_API sc_signed operator & (const sc_signed& u, const sc_int_base& v);
1737 friend SC_API sc_signed operator & (const sc_signed& u, const sc_uint_base& v);
1738 friend SC_API sc_signed operator & (const sc_int_base& u, const sc_signed& v);
1739 friend SC_API sc_signed operator & (const sc_uint_base& u, const sc_signed& v);
1740 const sc_signed& operator &= (const sc_int_base& v);
1741 const sc_signed& operator &= (const sc_uint_base& v);
1742
1743 // Bitwise OR operators:
1744
1745 friend SC_API sc_signed operator | (const sc_unsigned& u, const sc_signed& v);
1746 friend SC_API sc_signed operator | (const sc_signed& u, const sc_unsigned& v);
1747
1748 friend SC_API sc_signed operator | (const sc_unsigned& u, int64 v);
1749 friend SC_API sc_signed operator | (const sc_unsigned& u, long v);
1750 friend sc_signed operator | (const sc_unsigned& u, int v)
1751 { return operator|(u, (long) v); }
1752
1753 friend SC_API sc_signed operator | (int64 u, const sc_unsigned& v);
1754 friend SC_API sc_signed operator | (long u, const sc_unsigned& v);
1755 friend sc_signed operator | (int u, const sc_unsigned& v)
1756 { return operator|((long) u, v); }
1757
1758 friend SC_API sc_signed operator | (const sc_signed& u, const sc_signed& v);
1759 friend SC_API sc_signed operator | (const sc_signed& u, int64 v);
1760 friend SC_API sc_signed operator | (const sc_signed& u, uint64 v);
1761 friend SC_API sc_signed operator | (const sc_signed& u, long v);
1762 friend SC_API sc_signed operator | (const sc_signed& u, unsigned long v);
1763 friend sc_signed operator | (const sc_signed& u, int v)
1764 { return operator|(u, (long) v); }
1765 friend sc_signed operator | (const sc_signed& u, unsigned int v)
1766 { return operator|(u, (unsigned long) v); }
1767
1768 friend SC_API sc_signed operator | (int64 u, const sc_signed& v);
1769 friend SC_API sc_signed operator | (uint64 u, const sc_signed& v);
1770 friend SC_API sc_signed operator | (long u, const sc_signed& v);
1771 friend SC_API sc_signed operator | (unsigned long u, const sc_signed& v);
1772 friend sc_signed operator | (int u, const sc_signed& v)
1773 { return operator|((long) u, v); }
1774 friend sc_signed operator | (unsigned int u, const sc_signed& v)
1775 { return operator|((unsigned long) u, v); }
1776
1777 const sc_signed& operator |= (const sc_signed& v);
1778 const sc_signed& operator |= (const sc_unsigned& v);
1779 const sc_signed& operator |= (int64 v);
1780 const sc_signed& operator |= (uint64 v);
1781 const sc_signed& operator |= (long v);
1782 const sc_signed& operator |= (unsigned long v);
1783 const sc_signed& operator |= (int v)
1784 { return operator|=((long) v); }
1785 const sc_signed& operator |= (unsigned int v)
1786 { return operator|=((unsigned long) v); }
1787
1788 friend SC_API sc_signed operator | (const sc_unsigned& u, const sc_int_base& v);
1789 friend SC_API sc_signed operator | (const sc_int_base& u, const sc_unsigned& v);
1790 friend SC_API sc_signed operator | (const sc_signed& u, const sc_int_base& v);
1791 friend SC_API sc_signed operator | (const sc_signed& u, const sc_uint_base& v);
1792 friend SC_API sc_signed operator | (const sc_int_base& u, const sc_signed& v);
1793 friend SC_API sc_signed operator | (const sc_uint_base& u, const sc_signed& v);
1794 const sc_signed& operator |= (const sc_int_base& v);
1795 const sc_signed& operator |= (const sc_uint_base& v);
1796
1797 // Bitwise XOR operators:
1798
1799 friend SC_API sc_signed operator ^ (const sc_unsigned& u, const sc_signed& v);
1800 friend SC_API sc_signed operator ^ (const sc_signed& u, const sc_unsigned& v);
1801
1802 friend SC_API sc_signed operator ^ (const sc_unsigned& u, int64 v);
1803 friend SC_API sc_signed operator ^ (const sc_unsigned& u, long v);
1804 friend sc_signed operator ^ (const sc_unsigned& u, int v)
1805 { return operator^(u, (long) v); }
1806
1807 friend SC_API sc_signed operator ^ (int64 u, const sc_unsigned& v);
1808 friend SC_API sc_signed operator ^ (long u, const sc_unsigned& v);
1809 friend sc_signed operator ^ (int u, const sc_unsigned& v)
1810 { return operator^((long) u, v); }
1811
1812 friend SC_API sc_signed operator ^ (const sc_signed& u, const sc_signed& v);
1813 friend SC_API sc_signed operator ^ (const sc_signed& u, int64 v);
1814 friend SC_API sc_signed operator ^ (const sc_signed& u, uint64 v);
1815 friend SC_API sc_signed operator ^ (const sc_signed& u, long v);
1816 friend SC_API sc_signed operator ^ (const sc_signed& u, unsigned long v);
1817 friend sc_signed operator ^ (const sc_signed& u, int v)
1818 { return operator^(u, (long) v); }
1819 friend sc_signed operator ^ (const sc_signed& u, unsigned int v)
1820 { return operator^(u, (unsigned long) v); }
1821
1822 friend SC_API sc_signed operator ^ (int64 u, const sc_signed& v);
1823 friend SC_API sc_signed operator ^ (uint64 u, const sc_signed& v);
1824 friend SC_API sc_signed operator ^ (long u, const sc_signed& v);
1825 friend SC_API sc_signed operator ^ (unsigned long u, const sc_signed& v);
1826 friend sc_signed operator ^ (int u, const sc_signed& v)
1827 { return operator^((long) u, v); }
1828 friend sc_signed operator ^ (unsigned int u, const sc_signed& v)
1829 { return operator^((unsigned long) u, v); }
1830
1831 const sc_signed& operator ^= (const sc_signed& v);
1832 const sc_signed& operator ^= (const sc_unsigned& v);
1833 const sc_signed& operator ^= (int64 v);
1834 const sc_signed& operator ^= (uint64 v);
1835 const sc_signed& operator ^= (long v);
1836 const sc_signed& operator ^= (unsigned long v);
1837 const sc_signed& operator ^= (int v)
1838 { return operator^=((long) v); }
1839 const sc_signed& operator ^= (unsigned int v)
1840 { return operator^=((unsigned long) v); }
1841
1842 friend SC_API sc_signed operator ^ (const sc_unsigned& u, const sc_int_base& v);
1843 friend SC_API sc_signed operator ^ (const sc_int_base& u, const sc_unsigned& v);
1844 friend SC_API sc_signed operator ^ (const sc_signed& u, const sc_int_base& v);
1845 friend SC_API sc_signed operator ^ (const sc_signed& u, const sc_uint_base& v);
1846 friend SC_API sc_signed operator ^ (const sc_int_base& u, const sc_signed& v);
1847 friend SC_API sc_signed operator ^ (const sc_uint_base& u, const sc_signed& v);
1848 const sc_signed& operator ^= (const sc_int_base& v);
1849 const sc_signed& operator ^= (const sc_uint_base& v);
1850
1851 // SHIFT OPERATORS:
1852
1853 // LEFT SHIFT operators:
1854
1855 friend SC_API sc_unsigned operator << (const sc_unsigned& u, const sc_signed& v);
1856 friend SC_API sc_signed operator << (const sc_signed& u, const sc_unsigned& v);
1857
1858 friend SC_API sc_signed operator << (const sc_signed& u, const sc_signed& v);
1859 friend SC_API sc_signed operator << (const sc_signed& u, int64 v);
1860 friend SC_API sc_signed operator << (const sc_signed& u, uint64 v);
1861 friend SC_API sc_signed operator << (const sc_signed& u, long v);
1862 friend SC_API sc_signed operator << (const sc_signed& u, unsigned long v);
1863 friend sc_signed operator << (const sc_signed& u, int v)
1864 { return operator<<(u, (long) v); }
1865 friend sc_signed operator << (const sc_signed& u, unsigned int v)
1866 { return operator<<(u, (unsigned long) v); }
1867
1868 const sc_signed& operator <<= (const sc_signed& v);
1869 const sc_signed& operator <<= (const sc_unsigned& v);
1870 const sc_signed& operator <<= (int64 v);
1871 const sc_signed& operator <<= (uint64 v);
1872 const sc_signed& operator <<= (long v);
1873 const sc_signed& operator <<= (unsigned long v);
1874 const sc_signed& operator <<= (int v)
1875 { return operator<<=((long) v); }
1876 const sc_signed& operator <<= (unsigned int v)
1877 { return operator<<=((unsigned long) v); }
1878
1879 friend SC_API sc_signed operator << (const sc_signed& u, const sc_int_base& v);
1880 friend SC_API sc_signed operator << (const sc_signed& u, const sc_uint_base& v);
1881 const sc_signed& operator <<= (const sc_int_base& v);
1882 const sc_signed& operator <<= (const sc_uint_base& v);
1883
1884 // RIGHT SHIFT operators:
1885
1886 friend SC_API sc_unsigned operator >> (const sc_unsigned& u, const sc_signed& v);
1887 friend SC_API sc_signed operator >> (const sc_signed& u, const sc_unsigned& v);
1888
1889 friend SC_API sc_signed operator >> (const sc_signed& u, const sc_signed& v);
1890 friend SC_API sc_signed operator >> (const sc_signed& u, int64 v);
1891 friend SC_API sc_signed operator >> (const sc_signed& u, uint64 v);
1892 friend SC_API sc_signed operator >> (const sc_signed& u, long v);
1893 friend SC_API sc_signed operator >> (const sc_signed& u, unsigned long v);
1894 friend sc_signed operator >> (const sc_signed& u, int v)
1895 { return operator>>(u, (long) v); }
1896 friend sc_signed operator >> (const sc_signed& u, unsigned int v)
1897 { return operator>>(u, (unsigned long) v); }
1898
1899 const sc_signed& operator >>= (const sc_signed& v);
1900 const sc_signed& operator >>= (const sc_unsigned& v);
1901 const sc_signed& operator >>= (int64 v);
1902 const sc_signed& operator >>= (uint64 v);
1903 const sc_signed& operator >>= (long v);
1904 const sc_signed& operator >>= (unsigned long v);
1905 const sc_signed& operator >>= (int v)
1906 { return operator>>=((long) v); }
1907 const sc_signed& operator >>= (unsigned int v)
1908 { return operator>>=((unsigned long) v); }
1909
1910 friend SC_API sc_signed operator >> (const sc_signed& u, const sc_int_base& v);
1911 friend SC_API sc_signed operator >> (const sc_signed& u, const sc_uint_base& v);
1912 const sc_signed& operator >>= (const sc_int_base& v);
1913 const sc_signed& operator >>= (const sc_uint_base& v);
1914
1915 // Unary arithmetic operators
1916 friend SC_API sc_signed operator + (const sc_signed& u);
1917 friend SC_API sc_signed operator - (const sc_signed& u);
1918 friend SC_API sc_signed operator - (const sc_unsigned& u);
1919
1920 // LOGICAL OPERATORS:
1921
1922 // Logical EQUAL operators:
1923
1924 friend SC_API bool operator == (const sc_unsigned& u, const sc_signed& v);
1925 friend SC_API bool operator == (const sc_signed& u, const sc_unsigned& v);
1926
1927 friend SC_API bool operator == (const sc_signed& u, const sc_signed& v);
1928 friend SC_API bool operator == (const sc_signed& u, int64 v);
1929 friend SC_API bool operator == (const sc_signed& u, uint64 v);
1930 friend SC_API bool operator == (const sc_signed& u, long v);
1931 friend SC_API bool operator == (const sc_signed& u, unsigned long v);
1932 friend bool operator == (const sc_signed& u, int v)
1933 { return operator==(u, (long) v); }
1934 friend bool operator == (const sc_signed& u, unsigned int v)
1935 { return operator==(u, (unsigned long) v); }
1936
1937 friend SC_API bool operator == (int64 u, const sc_signed& v);
1938 friend SC_API bool operator == (uint64 u, const sc_signed& v);
1939 friend SC_API bool operator == (long u, const sc_signed& v);
1940 friend SC_API bool operator == (unsigned long u, const sc_signed& v);
1941 friend bool operator == (int u, const sc_signed& v)
1942 { return operator==((long) u, v); }
1943 friend bool operator == (unsigned int u, const sc_signed& v)
1944 { return operator==((unsigned long) u, v); }
1945
1946 friend SC_API bool operator == (const sc_signed& u, const sc_int_base& v);
1947 friend SC_API bool operator == (const sc_signed& u, const sc_uint_base& v);
1948 friend SC_API bool operator == (const sc_int_base& u, const sc_signed& v);
1949 friend SC_API bool operator == (const sc_uint_base& u, const sc_signed& v);
1950
1951 // Logical NOT_EQUAL operators:
1952
1953 friend SC_API bool operator != (const sc_unsigned& u, const sc_signed& v);
1954 friend SC_API bool operator != (const sc_signed& u, const sc_unsigned& v);
1955
1956 friend SC_API bool operator != (const sc_signed& u, const sc_signed& v);
1957 friend SC_API bool operator != (const sc_signed& u, int64 v);
1958 friend SC_API bool operator != (const sc_signed& u, uint64 v);
1959 friend SC_API bool operator != (const sc_signed& u, long v);
1960 friend SC_API bool operator != (const sc_signed& u, unsigned long v);
1961 friend bool operator != (const sc_signed& u, int v)
1962 { return operator!=(u, (long) v); }
1963 friend bool operator != (const sc_signed& u, unsigned int v)
1964 { return operator!=(u, (unsigned long) v); }
1965
1966 friend SC_API bool operator != (int64 u, const sc_signed& v);
1967 friend SC_API bool operator != (uint64 u, const sc_signed& v);
1968 friend SC_API bool operator != (long u, const sc_signed& v);
1969 friend SC_API bool operator != (unsigned long u, const sc_signed& v);
1970 friend bool operator != (int u, const sc_signed& v)
1971 { return operator!=((long) u, v); }
1972 friend bool operator != (unsigned int u, const sc_signed& v)
1973 { return operator!=((unsigned long) u, v); }
1974
1975 friend SC_API bool operator != (const sc_signed& u, const sc_int_base& v);
1976 friend SC_API bool operator != (const sc_signed& u, const sc_uint_base& v);
1977 friend SC_API bool operator != (const sc_int_base& u, const sc_signed& v);
1978 friend SC_API bool operator != (const sc_uint_base& u, const sc_signed& v);
1979
1980 // Logical LESS_THAN operators:
1981
1982 friend SC_API bool operator < (const sc_unsigned& u, const sc_signed& v);
1983 friend SC_API bool operator < (const sc_signed& u, const sc_unsigned& v);
1984
1985 friend SC_API bool operator < (const sc_signed& u, const sc_signed& v);
1986 friend SC_API bool operator < (const sc_signed& u, int64 v);
1987 friend SC_API bool operator < (const sc_signed& u, uint64 v);
1988 friend SC_API bool operator < (const sc_signed& u, long v);
1989 friend SC_API bool operator < (const sc_signed& u, unsigned long v);
1990 friend bool operator < (const sc_signed& u, int v)
1991 { return operator<(u, (long) v); }
1992 friend bool operator < (const sc_signed& u, unsigned int v)
1993 { return operator<(u, (unsigned long) v); }
1994
1995 friend SC_API bool operator < (int64 u, const sc_signed& v);
1996 friend SC_API bool operator < (uint64 u, const sc_signed& v);
1997 friend SC_API bool operator < (long u, const sc_signed& v);
1998 friend SC_API bool operator < (unsigned long u, const sc_signed& v);
1999 friend bool operator < (int u, const sc_signed& v)
2000 { return operator<((long) u, v); }
2001 friend bool operator < (unsigned int u, const sc_signed& v)
2002 { return operator<((unsigned long) u, v); }
2003
2004 friend SC_API bool operator < (const sc_signed& u, const sc_int_base& v);
2005 friend SC_API bool operator < (const sc_signed& u, const sc_uint_base& v);
2006 friend SC_API bool operator < (const sc_int_base& u, const sc_signed& v);
2007 friend SC_API bool operator < (const sc_uint_base& u, const sc_signed& v);
2008
2009 // Logical LESS_THAN_AND_EQUAL operators:
2010
2011 friend SC_API bool operator <= (const sc_unsigned& u, const sc_signed& v);
2012 friend SC_API bool operator <= (const sc_signed& u, const sc_unsigned& v);
2013
2014 friend SC_API bool operator <= (const sc_signed& u, const sc_signed& v);
2015 friend SC_API bool operator <= (const sc_signed& u, int64 v);
2016 friend SC_API bool operator <= (const sc_signed& u, uint64 v);
2017 friend SC_API bool operator <= (const sc_signed& u, long v);
2018 friend SC_API bool operator <= (const sc_signed& u, unsigned long v);
2019 friend bool operator <= (const sc_signed& u, int v)
2020 { return operator<=(u, (long) v); }
2021 friend bool operator <= (const sc_signed& u, unsigned int v)
2022 { return operator<=(u, (unsigned long) v); }
2023
2024 friend SC_API bool operator <= (int64 u, const sc_signed& v);
2025 friend SC_API bool operator <= (uint64 u, const sc_signed& v);
2026 friend SC_API bool operator <= (long u, const sc_signed& v);
2027 friend SC_API bool operator <= (unsigned long u, const sc_signed& v);
2028 friend bool operator <= (int u, const sc_signed& v)
2029 { return operator<=((long) u, v); }
2030 friend bool operator <= (unsigned int u, const sc_signed& v)
2031 { return operator<=((unsigned long) u, v); }
2032
2033 friend SC_API bool operator <= (const sc_signed& u, const sc_int_base& v);
2034 friend SC_API bool operator <= (const sc_signed& u, const sc_uint_base& v);
2035 friend SC_API bool operator <= (const sc_int_base& u, const sc_signed& v);
2036 friend SC_API bool operator <= (const sc_uint_base& u, const sc_signed& v);
2037
2038 // Logical GREATER_THAN operators:
2039
2040 friend SC_API bool operator > (const sc_unsigned& u, const sc_signed& v);
2041 friend SC_API bool operator > (const sc_signed& u, const sc_unsigned& v);
2042
2043 friend SC_API bool operator > (const sc_signed& u, const sc_signed& v);
2044 friend SC_API bool operator > (const sc_signed& u, int64 v);
2045 friend SC_API bool operator > (const sc_signed& u, uint64 v);
2046 friend SC_API bool operator > (const sc_signed& u, long v);
2047 friend SC_API bool operator > (const sc_signed& u, unsigned long v);
2048 friend bool operator > (const sc_signed& u, int v)
2049 { return operator>(u, (long) v); }
2050 friend bool operator > (const sc_signed& u, unsigned int v)
2051 { return operator>(u, (unsigned long) v); }
2052
2053 friend SC_API bool operator > (int64 u, const sc_signed& v);
2054 friend SC_API bool operator > (uint64 u, const sc_signed& v);
2055 friend SC_API bool operator > (long u, const sc_signed& v);
2056 friend SC_API bool operator > (unsigned long u, const sc_signed& v);
2057 friend bool operator > (int u, const sc_signed& v)
2058 { return operator>((long) u, v); }
2059 friend bool operator > (unsigned int u, const sc_signed& v)
2060 { return operator>((unsigned long) u, v); }
2061
2062 friend SC_API bool operator > (const sc_signed& u, const sc_int_base& v);
2063 friend SC_API bool operator > (const sc_signed& u, const sc_uint_base& v);
2064 friend SC_API bool operator > (const sc_int_base& u, const sc_signed& v);
2065 friend SC_API bool operator > (const sc_uint_base& u, const sc_signed& v);
2066
2067 // Logical GREATER_THAN_AND_EQUAL operators:
2068
2069 friend SC_API bool operator >= (const sc_unsigned& u, const sc_signed& v);
2070 friend SC_API bool operator >= (const sc_signed& u, const sc_unsigned& v);
2071
2072 friend SC_API bool operator >= (const sc_signed& u, const sc_signed& v);
2073 friend SC_API bool operator >= (const sc_signed& u, int64 v);
2074 friend SC_API bool operator >= (const sc_signed& u, uint64 v);
2075 friend SC_API bool operator >= (const sc_signed& u, long v);
2076 friend SC_API bool operator >= (const sc_signed& u, unsigned long v);
2077 friend bool operator >= (const sc_signed& u, int v)
2078 { return operator>=(u, (long) v); }
2079 friend bool operator >= (const sc_signed& u, unsigned int v)
2080 { return operator>=(u, (unsigned long) v); }
2081
2082 friend SC_API bool operator >= (int64 u, const sc_signed& v);
2083 friend SC_API bool operator >= (uint64 u, const sc_signed& v);
2084 friend SC_API bool operator >= (long u, const sc_signed& v);
2085 friend SC_API bool operator >= (unsigned long u, const sc_signed& v);
2086 friend bool operator >= (int u, const sc_signed& v)
2087 { return operator>=((long) u, v); }
2088 friend bool operator >= (unsigned int u, const sc_signed& v)
2089 { return operator>=((unsigned long) u, v); }
2090
2091 friend SC_API bool operator >= (const sc_signed& u, const sc_int_base& v);
2092 friend SC_API bool operator >= (const sc_signed& u, const sc_uint_base& v);
2093 friend SC_API bool operator >= (const sc_int_base& u, const sc_signed& v);
2094 friend SC_API bool operator >= (const sc_uint_base& u, const sc_signed& v);
2095
2096 // Bitwise NOT operator (unary).
2097 friend SC_API sc_signed operator ~ (const sc_signed& u);
2098
2099 // Helper functions.
2100 friend sc_signed add_signed_friend(small_type us,
2101 int unb,
2102 int und,
2103 const sc_digit *ud,
2104 small_type vs,
2105 int vnb,
2106 int vnd,
2107 const sc_digit *vd);
2108
2109 friend sc_signed sub_signed_friend(small_type us,
2110 int unb,
2111 int und,
2112 const sc_digit *ud,
2113 small_type vs,
2114 int vnb,
2115 int vnd,
2116 const sc_digit *vd);
2117
2118 friend sc_signed mul_signed_friend(small_type s,
2119 int unb,
2120 int und,
2121 const sc_digit *ud,
2122 int vnb,
2123 int vnd,
2124 const sc_digit *vd);
2125
2126 friend sc_signed div_signed_friend(small_type s,
2127 int unb,
2128 int und,
2129 const sc_digit *ud,
2130 int vnb,
2131 int vnd,
2132 const sc_digit *vd);
2133
2134 friend sc_signed mod_signed_friend(small_type us,
2135 int unb,
2136 int und,
2137 const sc_digit *ud,
2138 int vnb,
2139 int vnd,
2140 const sc_digit *vd);
2141
2142 friend sc_signed and_signed_friend(small_type us,
2143 int unb,
2144 int und,
2145 const sc_digit *ud,
2146 small_type vs,
2147 int vnb,
2148 int vnd,
2149 const sc_digit *vd);
2150
2151 friend sc_signed or_signed_friend(small_type us,
2152 int unb,
2153 int und,
2154 const sc_digit *ud,
2155 small_type vs,
2156 int vnb,
2157 int vnd,
2158 const sc_digit *vd);
2159
2160 friend sc_signed xor_signed_friend(small_type us,
2161 int unb,
2162 int und,
2163 const sc_digit *ud,
2164 small_type vs,
2165 int vnb,
2166 int vnd,
2167 const sc_digit *vd);
2168
2169 private:
2170
2171 small_type sgn; // Shortened as s.
2172 int nbits; // Shortened as nb.
2173 int ndigits; // Shortened as nd.
2174
2175 #ifdef SC_MAX_NBITS
2176 sc_digit digit[DIV_CEIL(SC_MAX_NBITS)]; // Shortened as d.
2177 #else
2178 sc_digit *digit; // Shortened as d.
2179 #endif
2180
2181 // Private constructors:
2182
2183 // Create a copy of v with sign s.
2184 sc_signed(const sc_signed& v, small_type s);
2185 sc_signed(const sc_unsigned& v, small_type s);
2186
2187 // Create a signed number with the given attributes.
2188 sc_signed(small_type s, int nb, int nd,
2189 sc_digit *d, bool alloc = true);
2190
2191 // Create an unsigned number using the bits u[l..r].
2192 sc_signed(const sc_signed* u, int l, int r);
2193 sc_signed(const sc_unsigned* u, int l, int r);
2194
2195 // Private member functions. The called functions are inline functions.
2196
default_sign()2197 small_type default_sign() const
2198 { return SC_NOSIGN; }
2199
num_bits(int nb)2200 int num_bits(int nb) const { return nb; }
2201
2202 bool check_if_outside(int bit_num) const;
2203
copy_digits(int nb,int nd,const sc_digit * d)2204 void copy_digits(int nb, int nd, const sc_digit *d)
2205 { copy_digits_signed(sgn, nbits, ndigits, digit, nb, nd, d); }
2206
makezero()2207 void makezero()
2208 { sgn = make_zero(ndigits, digit); }
2209
2210 // Conversion functions between 2's complement (2C) and
2211 // sign-magnitude (SM):
convert_2C_to_SM()2212 void convert_2C_to_SM()
2213 { sgn = convert_signed_2C_to_SM(nbits, ndigits, digit); }
2214
convert_SM_to_2C_to_SM()2215 void convert_SM_to_2C_to_SM()
2216 { sgn = convert_signed_SM_to_2C_to_SM(sgn, nbits, ndigits, digit); }
2217
convert_SM_to_2C()2218 void convert_SM_to_2C()
2219 { convert_signed_SM_to_2C(sgn, ndigits, digit); }
2220
2221 };
2222
2223
2224
2225 inline
2226 ::std::ostream&
2227 operator << ( ::std::ostream&, const sc_signed& );
2228
2229 inline
2230 ::std::istream&
2231 operator >> ( ::std::istream&, sc_signed& );
2232
2233
2234
2235 inline
2236 ::std::ostream&
2237 operator << ( ::std::ostream& os, const sc_signed_bitref_r& a )
2238 {
2239 a.print( os );
2240 return os;
2241 }
2242
2243
2244 inline
2245 ::std::istream&
2246 operator >> ( ::std::istream& is, sc_signed_bitref& a )
2247 {
2248 a.scan( is );
2249 return is;
2250 }
2251
2252
2253 // ----------------------------------------------------------------------------
2254 // CLASS : sc_signed_subref_r
2255 //
2256 // Proxy class for sc_signed part selection (r-value only).
2257 // ----------------------------------------------------------------------------
2258
2259
2260 // reduce methods
2261
and_reduce()2262 inline bool sc_signed_subref_r::and_reduce() const
2263 {
2264 const sc_signed* target_p = m_obj_p;
2265 for ( int i = m_right; i <= m_left; i++ )
2266 if ( !target_p->test(i) ) return false;
2267 return true;
2268 }
2269
nand_reduce()2270 inline bool sc_signed_subref_r::nand_reduce() const
2271 {
2272 return !and_reduce();
2273 }
2274
or_reduce()2275 inline bool sc_signed_subref_r::or_reduce() const
2276 {
2277 const sc_signed* target_p = m_obj_p;
2278 for ( int i = m_right; i <= m_left; i++ )
2279 if ( target_p->test(i) ) return true;
2280 return false;
2281 }
2282
nor_reduce()2283 inline bool sc_signed_subref_r::nor_reduce() const
2284 {
2285 return !or_reduce();
2286 }
2287
xor_reduce()2288 inline bool sc_signed_subref_r::xor_reduce() const
2289 {
2290 int odd;
2291 const sc_signed* target_p = m_obj_p;
2292 odd = 0;
2293 for ( int i = m_right; i <= m_left; i++ )
2294 if ( target_p->test(i) ) odd = ~odd;
2295 return odd ? true : false;
2296 }
2297
xnor_reduce()2298 inline bool sc_signed_subref_r::xnor_reduce() const
2299 {
2300 return !xor_reduce();
2301 }
2302
2303 inline
2304 ::std::ostream&
2305 operator << ( ::std::ostream& os, const sc_signed_subref_r& a )
2306 {
2307 a.print( os );
2308 return os;
2309 }
2310
2311
2312 // ----------------------------------------------------------------------------
2313 // CLASS : sc_signed_subref
2314 //
2315 // Proxy class for sc_signed part selection (r-value and l-value).
2316 // ----------------------------------------------------------------------------
2317
2318 // assignment operators
2319
2320 inline
2321 const sc_signed_subref&
2322 sc_signed_subref::operator = ( const char* a )
2323 {
2324 sc_signed aa( length() );
2325 return ( *this = aa = a );
2326 }
2327
2328
2329
2330
2331 inline
2332 ::std::istream&
2333 operator >> ( ::std::istream& is, sc_signed_subref& a )
2334 {
2335 a.scan( is );
2336 return is;
2337 }
2338
2339
2340
2341 // ----------------------------------------------------------------------------
2342 // CLASS : sc_signed
2343 //
2344 // Arbitrary precision signed number.
2345 // ----------------------------------------------------------------------------
2346
2347 template<class T>
sc_signed(const sc_generic_base<T> & v)2348 sc_signed::sc_signed( const sc_generic_base<T>& v )
2349 {
2350 int nb = v->length();
2351 sgn = default_sign();
2352 if( nb > 0 ) {
2353 nbits = num_bits( nb );
2354 } else {
2355 invalid_init( "sc_generic_base<T>", nb );
2356 sc_core::sc_abort(); // can't recover from here
2357 }
2358 ndigits = DIV_CEIL(nbits);
2359 # ifdef SC_MAX_NBITS
2360 test_bound(nb);
2361 # else
2362 digit = new sc_digit[ndigits];
2363 # endif
2364 makezero();
2365 v->to_sc_signed(*this);
2366 }
2367
2368
2369
2370 inline
2371 ::std::ostream&
2372 operator << ( ::std::ostream& os, const sc_signed& a )
2373 {
2374 a.print( os );
2375 return os;
2376 }
2377
2378 inline
2379 ::std::istream&
2380 operator >> ( ::std::istream& is, sc_signed& a )
2381 {
2382 a.scan( is );
2383 return is;
2384 }
2385
2386
2387 } // namespace sc_dt
2388
2389 #endif
2390