test.cpp revision 12855:588919e0e4aa
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  test.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//
39//	Verifies the functionality of concanetation operation.
40//	Operands form the rvalue of an assignment
41//
42//	Author: PRP
43//	Date Created: 19 Feb 99
44//
45
46
47#include "systemc.h"
48#include "test.h"
49
50void test::entry()
51{
52  sc_lv<8> a;
53  sc_lv<8> b;
54  sc_lv<8> c;
55  sc_lv<8> d;
56  sc_lv<24> e;
57  sc_lv<24> f;
58
59  sc_logic k;
60  sc_logic n;
61  sc_logic m;
62
63  sc_lv<32> x;
64  sc_lv<32> y;
65  sc_lv<32> z;
66
67  sc_lv<2> kk;
68
69  int i,j;
70
71  while (true) {
72
73  wait ();
74
75  // ------- rvalue ---------------------------------------------
76
77  a = "00000000";  	// 0
78  b = "00000001";	// 1
79  c = "00000011";	// 3
80  d = "00001111";	// 15
81  e = "000000000000000000000001"; // 1
82  f = "000000000000000000001010"; // 10
83
84  // =============== Array + Array ====================================
85  // array constant +  array constant
86  x = ( sc_lv_base( "000000000000000000000000" ), "00010000");	// x = 32
87
88  //  array constant +  array variable
89  y = ("000000000000000000000000", b);	// y = 1
90  z = x | y;	// z = 00000000 00000000 00000000 00010001
91
92  //  array variable +  array constant
93  x = (a, "000000000000000000000011");	// x = 3
94  z = z & x;	// z = 00000000 00000000 00000000 00000001
95
96  //  array variable +  array variable
97  x = (a, f);	// x = 10
98  z = z | x;	// z = 00000000 00000000 00000000 00001011
99
100  // =============== Cascading ====================================
101  // cascading  array variables
102  x = (a, b, c, d);	// x = 00000000 00000001 00000011 00001111
103  z = z & x;		// z = 00000000 00000000 00000000 00001011
104
105  // cascading  array constants
106  x = ( sc_lv_base( "00000011" ), "00000011", "00000011", "00000011");
107  		// x = 00000011 00000011 00000011 00000011
108  z = z | x;	// z = 00000011 00000011 00000011 00001011
109
110  // composing  array concats
111  x = ( sc_lv_base( "00000011" ), ( sc_lv_base( "11111111" ), "00000011", "00000011"));
112  		// x = 00000011 11111111 00000011 00000011
113  z = z | x;	// z = 00000011 11111111 00000011 00001011
114
115  // =============== Array (variable) + Scalar ==============================
116  // array variable + scalar constant
117  m = '0';
118  n = '1';
119  x = (a, b, c, d.range (6, 0), m);
120		// x = 00000000 00000001 00000011 00011110
121  z = z | x;	// z = 00000011 11111111 00000011 00011111
122
123  k = '1';
124  // array variable + scalar variable
125  x = (a, b, k, c.range (6, 0), x.range (7, 0));
126		// x = 00000000 00000001 10000001 00011110
127  z = z & x;	// z = 00000000 00000001 00000001 00011110
128
129  // =============== Null Vector ====================================
130  // null vector - variable
131  kk = ~( sc_lv_base( k ), k); // "00"
132  z = (z.range (31, 2), kk);	// z = 00000000 00000001 00000001 00011100
133
134  // null vector - constant
135  kk = ( sc_lv_base( n ), n); // "11"
136  z = (kk, z.range (29, 0));	// z = 11000000 00000001 00000001 00011100
137
138  // =============== Array (constant) + Scalar ==============================
139  // scalar constant + array constant
140  x = ( sc_lv_base( n ), "1111111000000000000000000000011");
141		// x = 01111111 00000000 00000000 00000011
142  z = z | x;	// z = 11111111 00000001 00000001 00011111
143
144  // array constant + scalar variable
145  x = ( sc_lv_base( "1111111000000000000000000000011" ), k);
146		// x = 11111110 00000000 00000000 00000111
147  z = z & x;	// z = 11111110 00000000 00000000 00000111
148
149  // =============== LHS/RHS of different widths ==============================
150  // lhs and rhs of different widths
151  x = "100001111000000000000000000001111"; // warning should be issued
152  z = z & x;
153	// z = 00001110 00000000 00000000 00000111
154
155  o1 = z.to_int();
156  wait();
157
158  }
159}
160
161