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 stab2.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 < 10; ++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 sc_bv<450> foo2; 113 foo = x.range(i + 224, i); 114 foo1 = x.range(i, i + 224); 115 foo2 = (foo1, foo); 116 for (j = 0; j < 225; ++j) { 117 sc_assert( foo[j] == x[i + j] ); 118 sc_assert( foo1[224 - j] == x[i + j] ); 119 sc_assert( foo2.range(449,225) == foo1 ); 120 sc_assert( foo2.range(224,0) == foo ); 121 } 122 // (foo, foo1) = (foo1, foo); 123 (foo, foo1) = foo2; 124 for (j = 0; j < 225; ++j) { 125 sc_assert( foo1[j] == x[i + j] ); 126 sc_assert( foo[224 - j] == x[i + j] ); 127 sc_assert( foo2.range(449,225) == foo ); 128 sc_assert( foo2.range(224,0) == foo1 ); 129 } 130 131 sc_lv<42> bar; 132 sc_lv<42> bar1; 133 sc_lv<84> bar2; 134 bar = y.range(i + 41, i); 135 bar1 = y.range(i, i + 41); 136 bar2 = (bar1, bar); 137 for (j = 0; j < 42; ++j) { 138 sc_assert( bar[j] == y[i + j] ); 139 sc_assert( bar1[41 - j] == y[i + j] ); 140 sc_assert( bar2.range(83,42) == bar1 ); 141 sc_assert( bar2.range(41,0) == bar ); 142 } 143 // (bar, bar1) = (bar1, bar); 144 (bar, bar1) = bar2; 145 for (j = 0; j < 42; ++j) { 146 sc_assert( bar1[j] == y[i + j] ); 147 sc_assert( bar[41 - j] == y[i + j] ); 148 sc_assert( bar2.range(83,42) == bar ); 149 sc_assert( bar2.range(41,0) == bar1 ); 150 } 151 152 sc_signed baz(3); 153 sc_signed baz1(3); 154 baz = z.range(i + 2, i); 155 baz1 = z.range(i, i + 2); 156 for (j = 0; j < 3; ++j) { 157 sc_assert( baz[j] == z[i + j] ); 158 sc_assert( baz1[2 - j] == z[i + j] ); 159 } 160 161 sc_unsigned quux(191); 162 sc_unsigned quux1(191); 163 quux = w.range(i + 190, i); 164 quux1 = w.range(i, i + 190); 165 for (j = 0; j < 191; ++j) { 166 sc_assert( quux[j] == w[i + j] ); 167 sc_assert( quux1[190 - j] == w[i + j] ); 168 } 169 } 170 } 171 return 0; 172} 173