112855Sgabeblack@google.com/***************************************************************************** 212855Sgabeblack@google.com 312855Sgabeblack@google.com Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 412855Sgabeblack@google.com more contributor license agreements. See the NOTICE file distributed 512855Sgabeblack@google.com with this work for additional information regarding copyright ownership. 612855Sgabeblack@google.com Accellera licenses this file to you under the Apache License, Version 2.0 712855Sgabeblack@google.com (the "License"); you may not use this file except in compliance with the 812855Sgabeblack@google.com License. You may obtain a copy of the License at 912855Sgabeblack@google.com 1012855Sgabeblack@google.com http://www.apache.org/licenses/LICENSE-2.0 1112855Sgabeblack@google.com 1212855Sgabeblack@google.com Unless required by applicable law or agreed to in writing, software 1312855Sgabeblack@google.com distributed under the License is distributed on an "AS IS" BASIS, 1412855Sgabeblack@google.com WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 1512855Sgabeblack@google.com implied. See the License for the specific language governing 1612855Sgabeblack@google.com permissions and limitations under the License. 1712855Sgabeblack@google.com 1812855Sgabeblack@google.com *****************************************************************************/ 1912855Sgabeblack@google.com 2012855Sgabeblack@google.com/***************************************************************************** 2112855Sgabeblack@google.com 2212855Sgabeblack@google.com popc.cpp -- 2312855Sgabeblack@google.com 2412855Sgabeblack@google.com Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15 2512855Sgabeblack@google.com 2612855Sgabeblack@google.com *****************************************************************************/ 2712855Sgabeblack@google.com 2812855Sgabeblack@google.com/***************************************************************************** 2912855Sgabeblack@google.com 3012855Sgabeblack@google.com MODIFICATION LOG - modifiers, enter your name, affiliation, date and 3112855Sgabeblack@google.com changes you are making here. 3212855Sgabeblack@google.com 3312855Sgabeblack@google.com Name, Affiliation, Date: 3412855Sgabeblack@google.com Description of Modification: 3512855Sgabeblack@google.com 3612855Sgabeblack@google.com *****************************************************************************/ 3712855Sgabeblack@google.com 3812855Sgabeblack@google.com#include "systemc.h" 3912855Sgabeblack@google.com 4012855Sgabeblack@google.com/* 4112855Sgabeblack@google.com * Test bench 4212855Sgabeblack@google.com */ 4312855Sgabeblack@google.com 4412855Sgabeblack@google.comSC_MODULE( proc1 ) 4512855Sgabeblack@google.com{ 4612855Sgabeblack@google.com SC_HAS_PROCESS( proc1 ); 4712855Sgabeblack@google.com 4812855Sgabeblack@google.com sc_in_clk clk; 4912855Sgabeblack@google.com 5012855Sgabeblack@google.com // Inputs 5112855Sgabeblack@google.com sc_in<bool> data_ack; 5212855Sgabeblack@google.com sc_in<int> popc; 5312855Sgabeblack@google.com // Outputs 5412855Sgabeblack@google.com sc_out<bool> reset; 5512855Sgabeblack@google.com sc_out<bool> data_ready; 5612855Sgabeblack@google.com sc_out<int> in; 5712855Sgabeblack@google.com 5812855Sgabeblack@google.com // Constructor 5912855Sgabeblack@google.com proc1( sc_module_name NAME, 6012855Sgabeblack@google.com sc_clock& CLK, 6112855Sgabeblack@google.com sc_signal<bool>& DATA_ACK, 6212855Sgabeblack@google.com sc_signal<int>& POPC, 6312855Sgabeblack@google.com sc_signal<bool>& RESET, 6412855Sgabeblack@google.com sc_signal<bool>& DATA_READY, 6512855Sgabeblack@google.com sc_signal<int>& IN_ ) 6612855Sgabeblack@google.com { 6712855Sgabeblack@google.com clk(CLK); 6812855Sgabeblack@google.com data_ack(DATA_ACK); popc(POPC); 6912855Sgabeblack@google.com reset(RESET); data_ready(DATA_READY); in(IN_); 7012855Sgabeblack@google.com SC_CTHREAD( entry, clk.pos() ); 7112855Sgabeblack@google.com } 7212855Sgabeblack@google.com 7312855Sgabeblack@google.com // Process functionality goes here 7412855Sgabeblack@google.com void entry(); 7512855Sgabeblack@google.com}; 7612855Sgabeblack@google.com 7712855Sgabeblack@google.com/* 7812855Sgabeblack@google.com * popc - The process doing the population count 7912855Sgabeblack@google.com * 8012855Sgabeblack@google.com */ 8112855Sgabeblack@google.com 8212855Sgabeblack@google.comSC_MODULE( proc2 ) 8312855Sgabeblack@google.com{ 8412855Sgabeblack@google.com SC_HAS_PROCESS( proc2 ); 8512855Sgabeblack@google.com 8612855Sgabeblack@google.com sc_in_clk clk; 8712855Sgabeblack@google.com 8812855Sgabeblack@google.com // Inputs 8912855Sgabeblack@google.com sc_in<bool> reset; 9012855Sgabeblack@google.com sc_in<bool> data_ready; 9112855Sgabeblack@google.com sc_in<int> in; 9212855Sgabeblack@google.com // Outputs 9312855Sgabeblack@google.com sc_out<bool> data_ack; 9412855Sgabeblack@google.com sc_out<int> popc; 9512855Sgabeblack@google.com 9612855Sgabeblack@google.com // Internal variables 9712855Sgabeblack@google.com int c; 9812855Sgabeblack@google.com int t; 9912855Sgabeblack@google.com int no; 10012855Sgabeblack@google.com 10112855Sgabeblack@google.com proc2( sc_module_name NAME, 10212855Sgabeblack@google.com sc_clock& CLK, 10312855Sgabeblack@google.com sc_signal<bool>& RESET, 10412855Sgabeblack@google.com sc_signal<bool>& DATA_READY, 10512855Sgabeblack@google.com sc_signal<int>& IN_, 10612855Sgabeblack@google.com sc_signal<bool>& DATA_ACK, 10712855Sgabeblack@google.com sc_signal<int>& POPC ) 10812855Sgabeblack@google.com { 10912855Sgabeblack@google.com clk(CLK); 11012855Sgabeblack@google.com reset(RESET); 11112855Sgabeblack@google.com data_ready(DATA_READY); 11212855Sgabeblack@google.com in(IN_); 11312855Sgabeblack@google.com data_ack(DATA_ACK); 11412855Sgabeblack@google.com popc(POPC); 11512855Sgabeblack@google.com SC_CTHREAD( entry, clk.pos() ); 11612855Sgabeblack@google.com reset_signal_is(reset,true); 11712855Sgabeblack@google.com c = 0; 11812855Sgabeblack@google.com t = 0; 11912855Sgabeblack@google.com } 12012855Sgabeblack@google.com 12112855Sgabeblack@google.com // Process functionality 12212855Sgabeblack@google.com void entry(); 12312855Sgabeblack@google.com}; 12412855Sgabeblack@google.com 12512855Sgabeblack@google.com 12612855Sgabeblack@google.com/* 12712855Sgabeblack@google.com * Testbench functionality 12812855Sgabeblack@google.com */ 12912855Sgabeblack@google.com 13012855Sgabeblack@google.comvoid proc1::entry() 13112855Sgabeblack@google.com{ 13212855Sgabeblack@google.com int i; 13312855Sgabeblack@google.com int j; 13412855Sgabeblack@google.com 13512855Sgabeblack@google.com j = 1; 13612855Sgabeblack@google.com i = 0; 13712855Sgabeblack@google.com data_ready.write(false); 13812855Sgabeblack@google.com reset.write(false); 13912855Sgabeblack@google.com 14012855Sgabeblack@google.com wait(); 14112855Sgabeblack@google.com 14212855Sgabeblack@google.com while(true){ 14312855Sgabeblack@google.com in.write(j); 14412855Sgabeblack@google.com 14512855Sgabeblack@google.com data_ready.write(true); 14612855Sgabeblack@google.com do { wait(); } while (data_ack == false); 14712855Sgabeblack@google.com data_ready.write(false); 14812855Sgabeblack@google.com do { wait(); } while (data_ack == true); 14912855Sgabeblack@google.com 15012855Sgabeblack@google.com char buf[BUFSIZ]; 15112855Sgabeblack@google.com sprintf( buf, "Input: %7d Population Count: %3d", j, popc.read() ); 15212855Sgabeblack@google.com cout << buf << endl; 15312855Sgabeblack@google.com 15412855Sgabeblack@google.com i++; 15512855Sgabeblack@google.com 15612855Sgabeblack@google.com if( i == 3){ 15712855Sgabeblack@google.com reset.write(true); 15812855Sgabeblack@google.com wait(); 15912855Sgabeblack@google.com reset.write(false); 16012855Sgabeblack@google.com wait(2); 16112855Sgabeblack@google.com } 16212855Sgabeblack@google.com 16312855Sgabeblack@google.com if( i == 16) 16412855Sgabeblack@google.com sc_stop(); 16512855Sgabeblack@google.com 16612855Sgabeblack@google.com j = (j<<1)|1; 16712855Sgabeblack@google.com } 16812855Sgabeblack@google.com} 16912855Sgabeblack@google.com 17012855Sgabeblack@google.com 17112855Sgabeblack@google.com/* 17212855Sgabeblack@google.com * popc - functionality 17312855Sgabeblack@google.com */ 17412855Sgabeblack@google.com 17512855Sgabeblack@google.comvoid proc2::entry() 17612855Sgabeblack@google.com{ 17712855Sgabeblack@google.com // Reset behavior 17812855Sgabeblack@google.com no = 0; 17912855Sgabeblack@google.com data_ack.write(false); 18012855Sgabeblack@google.com 18112855Sgabeblack@google.com wait(); 18212855Sgabeblack@google.com 18312855Sgabeblack@google.com while (true) { 18412855Sgabeblack@google.com do { wait(); } while (data_ready == false); 18512855Sgabeblack@google.com 18612855Sgabeblack@google.com t = in.read(); 18712855Sgabeblack@google.com c = 0; 18812855Sgabeblack@google.com while( t ){ 18912855Sgabeblack@google.com c++; 19012855Sgabeblack@google.com t &= (t-1); 19112855Sgabeblack@google.com wait(); 19212855Sgabeblack@google.com } 19312855Sgabeblack@google.com 19412855Sgabeblack@google.com no++; 19512855Sgabeblack@google.com popc.write(c); 19612855Sgabeblack@google.com 19712855Sgabeblack@google.com data_ack.write(true); 19812855Sgabeblack@google.com do { wait(); } while (data_ready == true); 19912855Sgabeblack@google.com data_ack.write(false); 20012855Sgabeblack@google.com } 20112855Sgabeblack@google.com} 20212855Sgabeblack@google.com 20312855Sgabeblack@google.com 20412855Sgabeblack@google.comint 20512855Sgabeblack@google.comsc_main(int argc, char *argv[]) 20612855Sgabeblack@google.com{ 20712855Sgabeblack@google.com sc_signal<bool> data_ready("Ready"); 20812855Sgabeblack@google.com sc_signal<bool> data_ack("Ack"); 20912855Sgabeblack@google.com sc_signal<int> in; 21012855Sgabeblack@google.com sc_signal<int> popc; 21112855Sgabeblack@google.com sc_signal<bool> reset; 21212855Sgabeblack@google.com 21312855Sgabeblack@google.com sc_clock clock("CLOCK", 10, SC_NS, 0.5, 0.0, SC_NS); 21412855Sgabeblack@google.com 21512855Sgabeblack@google.com proc1 TestBench("TestBench", clock, data_ack, popc, reset, data_ready, in); 21612855Sgabeblack@google.com proc2 Popc("Popc", clock, reset, data_ready, in, data_ack, popc); 21712855Sgabeblack@google.com 21812855Sgabeblack@google.com 21912855Sgabeblack@google.com // Create trace file 22012855Sgabeblack@google.com sc_trace_file *tf = sc_create_vcd_trace_file("tracefile"); 22112855Sgabeblack@google.com // Trace signals 22212855Sgabeblack@google.com sc_trace(tf, data_ready, "data_ready"); 22312855Sgabeblack@google.com sc_trace(tf, data_ack, "data_ack"); 22412855Sgabeblack@google.com sc_trace(tf, in, "in"); 22512855Sgabeblack@google.com sc_trace(tf, popc, "popc"); 22612855Sgabeblack@google.com sc_trace(tf, reset, "reset"); 22712855Sgabeblack@google.com // sc_trace(tf, clock.signal(), "Clock"); 22812855Sgabeblack@google.com sc_trace(tf, clock, "Clock"); 22912855Sgabeblack@google.com // Trace internal variables 23012855Sgabeblack@google.com sc_trace(tf, Popc.t, "Popc.t"); 23112855Sgabeblack@google.com sc_trace(tf, Popc.c, "Popc.c"); 23212855Sgabeblack@google.com sc_trace(tf, Popc.no, "Popc.no"); 23312855Sgabeblack@google.com 23412855Sgabeblack@google.com sc_start(); 23512855Sgabeblack@google.com return 0; 23612855Sgabeblack@google.com} 23712855Sgabeblack@google.com 238