cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Contributor
Contributor
679 Views
Registered: ‎01-14-2019

ap_fixed & ap_uint : bit set / extraction not functioning properly

Jump to solution

(Using Vivado HLS 2017.2)

 

Hello all. I've been working with ap_fixed data type, but having strange issues with extracting & setting bits. I used following code to test the results :

 

typedef ap_fixed<8,2> TP;	//Transmit Precision
// 1 sign[7], 1 integer[6], 6 decimal[5,0]

//TP buf[0] = -0.406250 (1 0 011010)
printf("float: %f\n",buf[0].to_float();

ap_uint<28> integer = 0;
integer[7] = buf[7];
integer[6] = buf[6];
integer[5] = buf[5];
integer[4] = buf[4];
integer[3] = buf[3];
integer[2] = buf[2];
integer[1] = buf[1];
integer[0] = buf[0];
printf("toint : %d\n",(int)integer);
for(int i=0; i<8; i++) {
	printf("%B ",(bool)integer[7-i]);
}
printf("\n");

TP test = 0;
test[7] = integer[7];
test[6] = integer[6];
test[5] = integer[5];
test[4] = integer[4];
test[3] = integer[3];
test[2] = integer[2];
test[1] = integer[1];
test[0] = integer[0];
printf("tofloat : %d\n",test.to_float());
for(int i=0; i<8; i++) {
	printf("%B ",(bool)test[7-i]);
}
printf("\n");

 

 

Results on printf were :

 

toint : 230
1 1 1 0 0 1 1 0 
tofloat : -0.406250
1 1 1 0 0 1 1 0 
bad : 1
//should be 1 0 0 1 1 0 1 0

 

 

I need to extract the values from ap_fixed<8,2> TP, store them in ap_uint<28>, do bitwise operations, and send output results back to ap_fixed<8,2>.

But bit values extracted with (bool)integer[] shows different bit value. Editing PP_28 integer results in original data being modified in an unintended way.

What is going on here? Is this a known issue with my version of Vivado HLS tool (2017.2)?

 

 

 

0 Kudos
Reply
1 Solution

Accepted Solutions
Scholar
Scholar
636 Views
Registered: ‎03-28-2016

@mh9840,

As far as I can tell, the bit patterns that are printed are correct. 

For an ap_fixed<8,2> variable, the 2's Compliment bit pattern for "-0.406250" is '1110_0110'.  You can't just take the bit pattern for +0.406250 (0001_1010) and then flip the msb (10011010) to create the negative.

Ted Booth | Tech. Lead FPGA Design Engineer | DesignLinx Solutions
https://www.designlinxhs.com

View solution in original post

2 Replies
Scholar
Scholar
637 Views
Registered: ‎03-28-2016

@mh9840,

As far as I can tell, the bit patterns that are printed are correct. 

For an ap_fixed<8,2> variable, the 2's Compliment bit pattern for "-0.406250" is '1110_0110'.  You can't just take the bit pattern for +0.406250 (0001_1010) and then flip the msb (10011010) to create the negative.

Ted Booth | Tech. Lead FPGA Design Engineer | DesignLinx Solutions
https://www.designlinxhs.com

View solution in original post

Contributor
Contributor
608 Views
Registered: ‎01-14-2019

Thanks for clarifying. My understanding of ap_fixed data type was incorrect.

0 Kudos
Reply