SystemC DataTypes Part IV

Print

sc_int

sc_int is signed integer, and it is fixed precision integer of size 64 bits. The underlying operations use 64 bits, but the result size is determined at object declaration. 

In sc_int the values is stored in 2's compliment. Since it is signed integer, the sign bit for a N bit wide sc_int is stored at N-1 bit position.

Integer types have a very rich set of operators that work with them.

Basic Operators

Operator

Description

Usage

&

Bitwise AND

expr1 & expr2

1

Bitwise OR

expr1 | expr2

^

Bitwise XOR

expr1 ^ expr2

~

Bitwise NOT

~expr

+

Addition

expr1 + expr2

-

Minus

expr1 - expr2

*

Multiply

expr1 * expr2

/

Divide

expr1 / expr2

%

Modulus

expr1 % expr2

>> 

Arithmetic right shift

expr >> constant

<< 

Arithmetic left shift

expr << constant

Compound Assignment

Operator

Description

Usage

+=

+ assignment

variable += expr

-=

- assignment

variable -= expr

*=

* assignment

variable *= expr

\=

\ assignment

variable \= expr

%=

% assignment

variable %= expr

&=

AND assignment

variable &= expr

|=

OR assignment

variable |= expr

^=

XOR assignment

variable ^= expr

Logic Operators

Operator

Description

Usage

=

Equality

expr1 = expr2

!=

Inequality

expr1 != expr2

< 

Less than

expr1 < expr2

<=

Less than or equal to

expr1 <= expr2

> 

Greater than

expr1 > expr2

>=

Greater than or equal to

expr1 >= expr2

++

AutoIncrement

variable ++

--

AutoDecrement

variable --

Bit Operators

 

Operator

Description

Usage

[]

Bit selection

variable [index ]

(,)

Concatenation

(expr1, expr2,... )

range()

Range Selection

variable.range(index1,index2)

Bitwise operators work on operands 

Type sc_int can be used with C++ integer types without restriction.
Example sc_int

  1 #include

  2

  3 int sc_main (int argc, char* argv[]) {

  4   sc_int<1>  bit_size    = 0;

  5   sc_int<4>  nibble_size = 1;

  6   sc_int<8>  byte_size   = 2;

  7   sc_int<32> dword_size  = 3;

  8   //sc_int addr; sc_int can not be more then 64

  9   // Perform auto increment

 10   dword_size ++;

 11   cout <<"Value of dword_size : " << dword_size << endl;

 12   // Terse method addition

 13   byte_size += nibble_size;

 14   cout <<"Value of byte_size  : " << byte_size << endl;

 15   // Bit selection

 16   bit_size = dword_size[2];

 17   cout <<"Value of bit_size   : " << bit_size << endl;

 18   // Range selection

 19   nibble_size = dword_size.range(4,1); // Can not assign out of range

 20   cout <<"Value of nibble_size: " << nibble_size << endl;

 21   // Concatenated

 22   dword_size = (byte_size,byte_size,byte_size,byte_size);

 23   cout <<"Value of dword_size : " << dword_size << endl;

 24

 25   return 1;

 26 }
Simulator Output: sc_int

              SystemC 2.0.1 --- Oct  6 2006 19:17:37

         Copyright (c) 1996-2002 by all Contributors

                     ALL RIGHTS RESERVED

 Value of dword_size : 4

 Value of byte_size  : 3

 Value of bit_size   : -1

 Value of nibble_size: 2

 Value of dword_size : 50529027

Bạn Có Đam Mê Với Vi Mạch hay Nhúng      -     Bạn Muốn Trau Dồi Thêm Kĩ Năng

Mong Muốn Có Thêm Cơ Hội Trong Công Việc

Và Trở Thành Một Người Có Giá Trị Hơn

Bạn Chưa Biết Phương Thức Nào Nhanh Chóng Để Đạt Được Chúng

Hãy Để Chúng Tôi Hỗ Trợ Cho Bạn. SEMICON  

 

Last Updated ( Tuesday, 29 March 2022 00:45 )