File: SIGN_EXTENSION.md

package info (click to toggle)
systemc 3.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 41,768 kB
  • sloc: cpp: 181,958; sh: 4,925; asm: 2,700; perl: 1,980; ansic: 1,931; makefile: 1,761; fortran: 492; python: 482; awk: 157; csh: 50
file content (77 lines) | stat: -rw-r--r-- 1,962 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
Sign Extension of SystemC Data Types
====================================

This document describes how sign extension is done for SystemC data types. This
includes implicit use of those data types, as well as methods like to_int()

The Proof Of Concept simulator is configured to use the following rules:

* Values that are smaller than a required width will be sign extended to the proper width. 

* Signed values will "sign extend" the upper bit of the value to extend to the proper width.

* Unsigned values will "zero extend" a zero bit to extend to the proper width.

These values are signed:

    sc_bigint
    sc_signed
    sc_int
    sc_int_base
    C++ signed integer types, e.g., int, long long

These values are unsigned (includes all the SystemC bit vector types):

    sc_biguint
    sc_unsigned
    sc_uint
    sc_uint_base
    sc_bv
    sc_bv_base
    sc_lv
    sc_lv_base
    sc_signed_subref
    sc_signed_subref_r
    sc_unsigned_subref
    sc_unsigned_subref_r
    sc_int_subref
    sc_int_subref_r
    sc_uint_subref
    sc_uint_subref_r
    C++ unsigned integer types, e.g., unsigned int, unsigned long

These types are bool:

    sc_signed_bitref
    sc_signed_bitref_r
    sc_unsigned_bitref
    sc_unsigned_bitref_r
    sc_int_bitref
    sc_int_bitref_r
    sc_uint_bitref
    sc_uint_bitref_r
    C++ bool type

The sign extension rules are enforced for the to_XXXX methods associated with
the various SystemC types:

    to_int()
    to_uint()
    to_long()
    to_ulong()
    to_int64()
    to_uint64()

Signed SystemC datatypes will sign extend their values when creating the return
type for these methods, For instance, given:

    sc_int<10> x;
    unsigned int j;
    .  .  .
    j = x.to_uint();

x will be sign extended using its upper bit to a width of 32 bits, and that
value assigned to j.

Similarly, to_long for an unsigned type like sc_biguint<12> will be zero
extended to the width of a C++ long, and that value returned.