UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Observer bulunhaimu
Observer
4,092 Views
Registered: ‎11-21-2016

HLS divide an int into 4 char

Hi, I am writing a code where I got the data as an int array like : int input[32];

now I need to process each bytes in one int parameter, that is saying that one int has to be divided into 4 char parameters. And after processing this I need to combine the 4 together.

I found that in HLS this is not allowed:

char a1,a2,a3,a4;

a1=char(input[i]);

a2=char(input[i]>>8);

a3=char(input[i]>>16);

a4=char(input[i]>>24);

 

How should I handle this?

 

Thanks in advance.

0 Kudos
5 Replies
Teacher muzaffer
Teacher
4,089 Views
Registered: ‎03-31-2012

Re: HLS divide an int into 4 char

@bulunhaimu 

 

>> I found that in HLS this is not allowed:

>>  a1=char(input[i]);

 

can you describe what error you see? This is fairly benign c++ code.

- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.
0 Kudos
Scholar u4223374
Scholar
4,050 Views
Registered: ‎04-26-2015

Re: HLS divide an int into 4 char

I too would like to know what error you see; I use that sort of code all the time. The only possible error I can see is if "input" is an AXI Stream; HLS demands pure sequential access (ie you read every element exactly once, in sequence) for AXI Streams and in your example you read each element of "input" four times.

 

The easy alternative, at least in C++, is to convert to the ap_int types:

 

ap_int<32> input[32];
ap_uint<8> a1, a2, a3, a4;

a1 = input(31,24);
a2 = input(23,16);
a3 = input(15,8);
a4 = input(7,0);
0 Kudos
Teacher muzaffer
Teacher
4,035 Views
Registered: ‎03-31-2012

Re: HLS divide an int into 4 char

@u4223374 

if

ap_int<32> input[32];

 

then 

a1 = input[i](31,24);

 

no?

 

a1 = input(31,24);

would be not work.

- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.
Scholar u4223374
Scholar
4,019 Views
Registered: ‎04-26-2015

Re: HLS divide an int into 4 char

@muzaffer

 

Yes, you're completely correct.

0 Kudos
Xilinx Employee
Xilinx Employee
3,968 Views
Registered: ‎07-18-2014

Re: HLS divide an int into 4 char

You can also try like this if you do not want to use ap_uint/ap_int:

 

char a1,a2,a3,a4;

unsigned int tmpInt;

tmpInt = input[i];

a1 = tmpInt & 0xFF;

a2 = (tmpInt >> 8 ) & 0xFF;

a3 = (tmpInt >> 16) & 0xFF;

a4 = (tmpInt >> 24) & 0xFF;

 

 

 

0 Kudos