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  stab1.cpp --
23
24  Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15
25
26 *****************************************************************************/
27
28/*****************************************************************************
29
30  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
31  changes you are making here.
32
33      Name, Affiliation, Date:
34  Description of Modification:
35
36 *****************************************************************************/
37
38#include "systemc.h"
39
40int
41sc_main( int argc, char* argv[] )
42{
43    int i;
44    sc_bv<325> x;
45    sc_lv<142> y;
46
47    sc_signed z(103);
48    sc_unsigned w(291);
49
50    for (i = 0; i < 325; ++i) {
51        x[i] = ((i & 1) ^ ((i >> 1) & 1));
52    };
53    for (i = 0; i < 325; ++i) {
54        sc_assert( x[i] == ((i & 1) ^ ((i >> 1) & 1)) );
55    };
56    for (i = 0; i < 142; ++i) {
57        y[i] = ((i & 1) ^ ((i >> 2) & 1));
58    }
59    for (i = 0; i < 142; ++i) {
60        // sc_assert( y[i] == char((i & 1) ^ ((i >> 2) & 1)) );
61        sc_assert( y[i] == ((i & 1) ^ ((i >> 2) & 1)) );
62    }
63    for (i = 0; i < 103; ++i) {
64        z[i] = (((i >> 2) & 1) ^ ((i >> 1) & 1));
65    }
66    for (i = 0; i < 103; ++i) {
67        sc_assert( (bool) z[i] == (((i >> 2) & 1) ^ ((i >> 1) & 1)) );
68    }
69    for (i = 0; i < 291; ++i) {
70        w[i] = (((i >> 3) & 1) ^ ((i >> 1) & 1));
71    }
72    for (i = 0; i < 291; ++i) {
73        sc_assert( (bool) w[i] == (((i >> 3) & 1) ^ ((i >> 1) & 1)) );
74    }
75
76    cout << x << endl;
77    cout << x.to_string() << endl;
78    cout << y << endl;
79    cout << y.to_string() << endl;
80    cout << z << endl;
81    cout << w << endl;
82
83    for (int k = 0; k < 100; ++k) {
84        cerr << "k = " << k << endl;
85
86        for (i = 0; i < 100; ++i) {
87            int j;
88
89            if (k == 0) {
90                cout << "i = " << i << endl;
91                cout << x.range(i + 224, i) << endl;
92                cout << x.range(i + 224, i).to_string() << endl;
93                cout << y.range(i + 41, i) << endl;
94                cout << y.range(i + 41, i).to_string() << endl;
95                cout << sc_signed(z.range(i + 2, i)) << endl;
96                cout << sc_unsigned(w.range(i + 190, i)) << endl;
97                cout << x.range(i, i + 224) << endl;
98                cout << x.range(i, i + 224).to_string() << endl;
99                cout << y.range(i, i + 41) << endl;
100                cout << y.range(i, i + 41).to_string() << endl;
101                cout << sc_signed(z.range(i, i + 2)) << endl;
102                cout << sc_unsigned(w.range(i, i + 190)) << endl;
103            } else {
104                (void) x.range(i + 224, i);
105                (void) y.range(i + 41, i);
106                (void) sc_signed(z.range(i + 2, i));
107                (void) sc_unsigned(w.range(i + 190, i));
108            }
109
110            sc_bv<225> foo;
111            sc_bv<225> foo1;
112            foo = x.range(i + 224, i);
113            foo1 = x.range(i, i + 224);
114            for (j = 0; j < 225; ++j) {
115                sc_assert( foo[j] == x[i + j] );
116                sc_assert( foo1[224 - j] == x[i + j] );
117            }
118
119            sc_lv<42> bar;
120            sc_lv<42> bar1;
121            bar = y.range(i + 41, i);
122            bar1 = y.range(i, i + 41);
123            for (j = 0; j < 42; ++j) {
124                sc_assert( bar[j] == y[i + j] );
125                sc_assert( bar1[41 - j] == y[i + j] );
126            }
127
128            sc_signed baz(3);
129            sc_signed baz1(3);
130            baz = z.range(i + 2, i);
131            baz1 = z.range(i, i + 2);
132            for (j = 0; j < 3; ++j) {
133                sc_assert( baz[j] == z[i + j] );
134                sc_assert( baz1[2 - j] == z[i + j] );
135            }
136
137            sc_unsigned quux(191);
138            sc_unsigned quux1(191);
139            quux = w.range(i + 190, i);
140            quux1 = w.range(i, i + 190);
141            for (j = 0; j < 191; ++j) {
142                sc_assert( quux[j] == w[i + j] );
143                sc_assert( quux1[190 - j] == w[i + j] );
144            }
145        }
146    }
147    return 0;
148}
149