cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
vjyoth01
Observer
Observer
3,207 Views
Registered: ‎07-09-2012

Splicing a bus variable into smaller chunks in HLS

Jump to solution

Is there a way to splice a bus/variable into smaller chunks in HLS.

Lets say, I have a 64 bit signal/wire ==> typedef  ap_uint<64>  a;

I can split the busa into 3 smaller buses in Verilog by :

 

input wire [63:0] a;

assign a1 = a[3:0];

assign  a2 = a[16:4];

assign a3 = a[64:17];

 

How can I get the same functionality in HLS?

0 Kudos
1 Solution

Accepted Solutions
u4223374
Advisor
Advisor
3,860 Views
Registered: ‎04-26-2015

You can do this for any of the ap_* types (ie ap_int, ap_uint, ap_fixed, ap_ufixed). The syntax is:

 

ap_uint<64> a;

ap_uint<4> a1 = a.range(3,0);
ap_uint<13> a2 = a.range(16,4);
ap_uint<47> a3 = a.range(63,17);

You can also get rid of the "range", although I prefer to keep it:

 

ap_uint<64> a;

ap_uint<4> a1 = a(3,0);
ap_uint<13> a2 = a(16,4);
ap_uint<47> a3 = a(63,17);

 

 

 

View solution in original post

5 Replies
u4223374
Advisor
Advisor
3,861 Views
Registered: ‎04-26-2015

You can do this for any of the ap_* types (ie ap_int, ap_uint, ap_fixed, ap_ufixed). The syntax is:

 

ap_uint<64> a;

ap_uint<4> a1 = a.range(3,0);
ap_uint<13> a2 = a.range(16,4);
ap_uint<47> a3 = a.range(63,17);

You can also get rid of the "range", although I prefer to keep it:

 

ap_uint<64> a;

ap_uint<4> a1 = a(3,0);
ap_uint<13> a2 = a(16,4);
ap_uint<47> a3 = a(63,17);

 

 

 

View solution in original post

vjyoth01
Observer
Observer
3,146 Views
Registered: ‎07-09-2012

Thank for the reply. This solution will work if the data types are same uint.  However, when I try to pass the smaller bus to fixed type, HLS seems to typecast from int to fixed type. All I want it to do is simply connect those bus to the underlying fixed arithmetic unit. 

 

ap_uint<64> a;
ap_uint<4> a1 = a.range(3,0);
ap_fixed<13,6> a2 = a.range(16,4);
ap_fixed<47,40> a3 = a.range(63,17);

ap_fixed<47,40> fxp_arith(a2,a3) ;

 The generated  HLS code is typecasting a2 and a3 before sending the data to fxp_arith. Any idea how to stop the typecasting and let the bus pass as it is to the arith unit?

0 Kudos
vjyoth01
Observer
Observer
3,116 Views
Registered: ‎07-09-2012
All I had to do was use struct, and the problem goes away
0 Kudos
nanson
Explorer
Explorer
3,103 Views
Registered: ‎08-31-2017

would you please share your final code here using struct ?  Thanks

0 Kudos
vjyoth01
Observer
Observer
3,020 Views
Registered: ‎07-09-2012

 

#define FIXED_PREC_BITS
#define NUM_OF_ELEMS

typedef ap_fixed<FIXED_PREC_BITS, 6 ,AP_TRN, AP_WRAP> fp_data_t;
// You can pack the values any way you like here..
typedef struct{
     fp_data_t e[NUM_OF_ELEMS*FIXED_PREC_BITS];
unit vj; } memWord; void test_func(volatile memWord *packed_vector, <Any other variables here>) { #pragma HLS data_pack variable=packed_vector memWord val; for(i=0; i < packed_vector.vj; i++) { val.e[i]= packed_vector.e[i] } }
0 Kudos