Jump to content
srahulkumar1989

Bit slicing in systemc

Recommended Posts

Hello all,

 

        I have just started the practical implementations in systemC. Here i am trying to implement a paradigm of Bit slicing in systemC.

 

Like:

 My input is a 8 bit unsignedint type which should be sliced and the output to be a 2 bit unsignedint type.

 Here i am trying to slice the bits with some conditions

- bottom bit of slice

- offset by 0

- Relative to LSB

Overall - slicing from bit 0 to bit 5 of a 8 bit input.

 

 

#include "systemc.h"

SC_MODULE(slice){

sc_in<sc_uint< 8,8> > input;
sc_out<sc_uint< 2,2> > output;

void do_slice(){

// slice the inputs and write at the output port

}

SC_CTOR(slice)
{
SC_METHOD(do_slice);
sensitive<< input;
}
};
 

 

 

Is there any methods availabe for slicing or Extracting bits in systemC? if yes, how to choose the exact particular bits need to be sliced

 

It will be grateful if any help is provided to proceed with the solution.

 

Thanks in advance

Share this post


Link to post
Share on other sites

You can use the range() method. However please note that the range() method belongs to the integer and vector classes, not to the ports. So for instance to pick out the bottom 5 bits you could use

 

input.read().range(4,0)
 

 

All the available methods are listed in the IEEE 1666-2011 standard, which you can download free via the accellera website.

 

regards

Alan

 

P.S. for sc_uint there is only one template argument, so sc_uint<8>, not sc_uint<8,8>.

Share this post


Link to post
Share on other sites

Thanks Mr. Alan for the response.

 

i have tried to know about range method by a simple code .

 

variable.range(4,0) will reprensent the bottom 5 bits and discard the remaining 3 bits of a 8 bit input.

 

variable.range(7,5) will discard the bottom 5 bits and represent the remaining 3 bits of a 8 bit input.

 

please correct  me if i am wrong.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×