test02.cpp revision 12855:588919e0e4aa
16157Snate@binkert.org/*****************************************************************************
26157Snate@binkert.org
36157Snate@binkert.org  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
46157Snate@binkert.org  more contributor license agreements.  See the NOTICE file distributed
56157Snate@binkert.org  with this work for additional information regarding copyright ownership.
66157Snate@binkert.org  Accellera licenses this file to you under the Apache License, Version 2.0
76157Snate@binkert.org  (the "License"); you may not use this file except in compliance with the
86157Snate@binkert.org  License.  You may obtain a copy of the License at
96157Snate@binkert.org
106157Snate@binkert.org    http://www.apache.org/licenses/LICENSE-2.0
116157Snate@binkert.org
126157Snate@binkert.org  Unless required by applicable law or agreed to in writing, software
136157Snate@binkert.org  distributed under the License is distributed on an "AS IS" BASIS,
146157Snate@binkert.org  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
156157Snate@binkert.org  implied.  See the License for the specific language governing
166157Snate@binkert.org  permissions and limitations under the License.
176157Snate@binkert.org
186157Snate@binkert.org *****************************************************************************/
196157Snate@binkert.org
206157Snate@binkert.org/*****************************************************************************
216157Snate@binkert.org
226157Snate@binkert.org  test02.cpp
236157Snate@binkert.org
246157Snate@binkert.org  Original Author: Andy Goodrich, Forte Design Systems, 7 Apr 2005
256157Snate@binkert.org
266157Snate@binkert.org *****************************************************************************/
276157Snate@binkert.org
286157Snate@binkert.org/*****************************************************************************
296157Snate@binkert.org
306157Snate@binkert.org  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
316157Snate@binkert.org  changes you are making here.
326157Snate@binkert.org
336157Snate@binkert.org      Name, Affiliation, Date:
346157Snate@binkert.org  Description of Modification:
356157Snate@binkert.org
366157Snate@binkert.org *****************************************************************************/
376157Snate@binkert.org
386157Snate@binkert.org#include "systemc.h"
396157Snate@binkert.org
4010133Sandreas.hansson@arm.com#define GET_UNSIGNED(VALUE,OFFSET,EXPECTED) \
4110133Sandreas.hansson@arm.com{ \
4210133Sandreas.hansson@arm.com	right_sc_biguint32 = 1 << OFFSET; \
4310133Sandreas.hansson@arm.com	VALUE.concat_get_data( right_sc_biguint32.get_raw(), OFFSET); \
4410133Sandreas.hansson@arm.com	if ( right_sc_biguint32 != ((EXPECTED)<<OFFSET) ) \
4510133Sandreas.hansson@arm.com	cout << __FILE__ << "(" << __LINE__ << ") : " << \
4610133Sandreas.hansson@arm.com		#VALUE << ".concat_get_data(ulong*, " << #OFFSET << ") expected " \
4710133Sandreas.hansson@arm.com		<< ((EXPECTED)<<OFFSET) << " got " << right_sc_biguint32 << endl; \
4810133Sandreas.hansson@arm.com}
4910133Sandreas.hansson@arm.com
5010133Sandreas.hansson@arm.com#define GET_UNSIGNEDS(OFFSET,EXPECTED) \
5110133Sandreas.hansson@arm.com{ \
5210133Sandreas.hansson@arm.com	GET_UNSIGNED(left_sc_bigint12,OFFSET,EXPECTED); \
5310133Sandreas.hansson@arm.com	GET_UNSIGNED(left_sc_biguint12,OFFSET,EXPECTED); \
5410133Sandreas.hansson@arm.com	GET_UNSIGNED(left_sc_int12,OFFSET,EXPECTED); \
5510133Sandreas.hansson@arm.com	GET_UNSIGNED(left_sc_uint12,OFFSET,EXPECTED); \
5610133Sandreas.hansson@arm.com	GET_UNSIGNED(left_sc_int12[1],OFFSET,((EXPECTED>>1)&1)); \
5710133Sandreas.hansson@arm.com	GET_UNSIGNED(left_sc_uint12[1],OFFSET,((EXPECTED>>1)&1)); \
5810133Sandreas.hansson@arm.com	GET_UNSIGNED(left_sc_int12(7,2),OFFSET,((EXPECTED>>2)&0x3f)); \
5910133Sandreas.hansson@arm.com	GET_UNSIGNED(left_sc_uint12(7,2),OFFSET,((EXPECTED>>2)&0x3f)); \
6010133Sandreas.hansson@arm.com}
6110133Sandreas.hansson@arm.com
628492Snilay@cs.wisc.edu#define GET_UINT64(VALUE,EXPECTED) \
636168Snate@binkert.org{ \
646168Snate@binkert.org	uint64 actual = VALUE.concat_get_uint64(); \
656157Snate@binkert.org	if ( actual != (EXPECTED) ) \
666157Snate@binkert.org	cout << __FILE__ << "(" << __LINE__ << ") : " << \
676157Snate@binkert.org		#VALUE << ".const_get_uint64() expected " << (EXPECTED) << " got " \
686157Snate@binkert.org		<< actual << endl; \
696157Snate@binkert.org}
706157Snate@binkert.org
716157Snate@binkert.org#define GET_UINT64S(EXPECTED) \
726157Snate@binkert.org{ \
736157Snate@binkert.org	GET_UINT64(left_sc_bigint12,EXPECTED) \
746157Snate@binkert.org	GET_UINT64(left_sc_biguint12,EXPECTED) \
756157Snate@binkert.org	GET_UINT64(left_sc_int12,EXPECTED) \
766157Snate@binkert.org	GET_UINT64(left_sc_uint12,EXPECTED) \
776157Snate@binkert.org	GET_UINT64(left_sc_int12[1],         ((EXPECTED>>1)&1)) \
786157Snate@binkert.org	GET_UINT64(left_sc_uint12[1],        ((EXPECTED>>1)&1)) \
796157Snate@binkert.org	GET_UINT64(left_sc_int12(7,2),       ((EXPECTED>>2)&0x3f)) \
806157Snate@binkert.org	GET_UINT64(left_sc_uint12(7,2),((EXPECTED>>2)&0x3f)) \
816157Snate@binkert.org}
826157Snate@binkert.org
836157Snate@binkert.org#define LENGTH(LEFT,WIDTH) \
846157Snate@binkert.org{ \
856157Snate@binkert.org	int width = LEFT.concat_length(0); \
866157Snate@binkert.org	if ( width != (WIDTH) ) \
876157Snate@binkert.org    cout << __FILE__ << "(" << __LINE__ << ") : " \
886157Snate@binkert.org		<< #LEFT << ".concat_length() expected " << (WIDTH) \
896157Snate@binkert.org		<< " got " << width << endl; \
906157Snate@binkert.org}
916157Snate@binkert.org
926157Snate@binkert.org#define LENGTHS(WIDTH) \
936157Snate@binkert.org{ \
946157Snate@binkert.org	LENGTH(left_sc_bigint12,WIDTH) \
956157Snate@binkert.org	LENGTH(left_sc_biguint12,WIDTH) \
966157Snate@binkert.org	LENGTH(left_sc_int12,WIDTH) \
976157Snate@binkert.org	LENGTH(left_sc_uint12,WIDTH) \
986157Snate@binkert.org}
996157Snate@binkert.org
1006157Snate@binkert.org#define SET(LEFT,RIGHT,VALUE,OFFSET,EXPECTED) \
1016157Snate@binkert.org{ \
1026157Snate@binkert.org	LEFT.concat_set(RIGHT,OFFSET); \
1036157Snate@binkert.org	wait(); \
1046157Snate@binkert.org	uint64 actual = LEFT.concat_get_uint64(); \
1056157Snate@binkert.org	if ( actual != (EXPECTED) ) \
1066157Snate@binkert.org	cout << #LEFT << ".const_set_uint64(" << #RIGHT <<", " << VALUE << ") \
1076157Snate@binkert.org		<< expected " << (EXPECTED) << " got " << actual << endl; \
1088483Sgblack@eecs.umich.edu}
1098483Sgblack@eecs.umich.edu
1106157Snate@binkert.org#define SET_SIGNED(VALUE,OFFSET,EXPECTED) \
1116882SBrad.Beckmann@amd.com{ \
1126286Snate@binkert.org	right_sc_bigint32 = VALUE; \
1136286Snate@binkert.org	SET(left_sc_bigint12,right_sc_bigint32,VALUE,OFFSET,EXPECTED); \
1148092Snilay@cs.wisc.edu	SET(left_sc_biguint12,right_sc_bigint32,VALUE,OFFSET,EXPECTED); \
1156286Snate@binkert.org	SET(left_sc_int12,right_sc_bigint32,VALUE,OFFSET,EXPECTED); \
1166286Snate@binkert.org	SET(left_sc_uint12,right_sc_bigint32,VALUE,OFFSET,EXPECTED); \
1176157Snate@binkert.org}
11811208Sjoseph.gross@amd.com
1196157Snate@binkert.org#define SET_S64(VALUE,OFFSET,EXPECTED) \
12011210SBrad.Beckmann@amd.com{ \
12110301Snilay@cs.wisc.edu	right_s64 = VALUE; \
1226157Snate@binkert.org	SET(left_sc_bigint12,right_s64,VALUE,OFFSET,EXPECTED); \
1236157Snate@binkert.org	SET(left_sc_biguint12,right_s64,VALUE,OFFSET,EXPECTED); \
12411307Santhony.gutierrez@amd.com	SET(left_sc_int12,right_s64,VALUE,OFFSET,EXPECTED); \
12511122Snilay@cs.wisc.edu	SET(left_sc_uint12,right_s64,VALUE,OFFSET,EXPECTED); \
12610301Snilay@cs.wisc.edu}
1279363Snilay@cs.wisc.edu
12810301Snilay@cs.wisc.edu#define SET_UNSIGNED(VALUE,OFFSET,EXPECTED) \
1296286Snate@binkert.org{ \
13010301Snilay@cs.wisc.edu	right_sc_biguint32 = VALUE; \
13110301Snilay@cs.wisc.edu	SET(left_sc_bigint12,right_sc_biguint32,VALUE,OFFSET,EXPECTED); \
13210301Snilay@cs.wisc.edu	SET(left_sc_biguint12,right_sc_biguint32,VALUE,OFFSET,EXPECTED); \
13310301Snilay@cs.wisc.edu	SET(left_sc_int12,right_sc_biguint32,VALUE,OFFSET,EXPECTED); \
1346157Snate@binkert.org	SET(left_sc_uint12,right_sc_biguint32,VALUE,OFFSET,EXPECTED); \
13510301Snilay@cs.wisc.edu}
13610301Snilay@cs.wisc.edu
137#define SET_U64(VALUE,OFFSET,EXPECTED) \
138{ \
139	right_u64 = VALUE; \
140	SET(left_sc_bigint12,right_u64,VALUE,OFFSET,EXPECTED); \
141	SET(left_sc_biguint12,right_u64,VALUE,OFFSET,EXPECTED); \
142	SET(left_sc_int12,right_u64,VALUE,OFFSET,EXPECTED); \
143	SET(left_sc_uint12,right_u64,VALUE,OFFSET,EXPECTED); \
144}
145
146#define SETS(VALUE,OFFSET,EXPECTED) \
147	SET_S64(VALUE,OFFSET,EXPECTED)  \
148	SET_SIGNED(VALUE,OFFSET,EXPECTED)  \
149	SET_UNSIGNED(VALUE,OFFSET,EXPECTED)  \
150	SET_U64(VALUE,OFFSET,EXPECTED)
151
152SC_MODULE(X)
153{
154    SC_CTOR(X)
155	{
156		SC_CTHREAD(sync, clk.pos());
157	}
158	void sync()
159	{
160		// for (;; )
161		{
162			LENGTHS(12);
163			SETS(0x87654321,0,0x321);
164			SETS(0x87654321,4,0x432);
165			GET_UINT64S(0x432);
166			GET_UNSIGNEDS(0,0x432);
167			GET_UNSIGNEDS(4,0x432);
168		}
169	}
170
171	sc_in_clk                	clk;
172	sc_int<12>               	left_sc_int12;
173	sc_bigint<12>            	left_sc_bigint12;
174	sc_biguint<12>           	left_sc_biguint12;
175	sc_uint<12>              	left_sc_uint12;
176
177	sc_int<32>               right_sc_int32;
178	sc_bigint<32>            right_sc_bigint32;
179	sc_biguint<32>           right_sc_biguint32;
180	sc_uint<32>              right_sc_uint32;
181	int                      right_si;
182	long                     right_sl;
183	int64                    right_s64;
184	unsigned int             right_ui;
185	unsigned long            right_ul;
186	uint64                   right_u64;
187};
188
189int sc_main( int argc, char* argv[] )
190{
191	sc_clock clock;
192	X x("x");
193	x.clk(clock);
194	sc_start(1000, SC_NS);
195
196	cerr << "Program completed\n";
197	return 0;
198}
199