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

Generated on Wed Sep 30 2020 14:02:16 for gem5 by doxygen 1.8.17