**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!

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community Forums
- :
- Forums
- :
- Design Tools
- :
- HLS
- :
- HLS floor() bug

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

dsula

Adventurer

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-12-2018 06:01 AM

252 Views

Registered:
01-14-2008

Hi,

I think there's a bug in the hls_math library. Consider the code fragment below.

ap_fixed<10, 3, AP_TRN> a;

ap_fixed<10, 3, AP_TRN, AP_SAT_SYM> b;

int c;

c = floor(a);

c = floor(b); // compilation error

The line 'floor(b)' doesn't compile with the following error messages:

C:/Xilinx/Vivado/2018.2/include/hls_math.h:310:10: note: candidate: double hls::floor(double)

double floor(double);

^~~~~

C:/Xilinx/Vivado/2018.2/include/hls_math.h:311:10: note: candidate: float hls::floor(float)

float floor(float);

^~~~~

C:/Xilinx/Vivado/2018.2/include/hls_math.h:312:10: note: candidate: half hls::floor(half)

half floor(half);

^~~~~

Is this in fact in the hls_math library? Or am I missing something?

Cheers

1 Solution

Accepted Solutions

nmoeller

Xilinx Employee

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-12-2018 12:58 PM

214 Views

Registered:
09-05-2018

Hey @dsula,

The hls_math.h library only supports the first and second template parameters. This is stated in UG902 on page 242. However, it doesn't explicitly say that the third and beyond template parameters and not supported, and I've reported to the appropriate teams that this is confusing.

The reason c = floor( a ) compiles is that AP_TRN is the default, so ap_fixed<10, 3, AP_TRN> a is understood to be the same type as ap_fixed<10,3> a.

As a workaround, can you cast b to ap_fixed<10, 3> before calling floor()? ap_fixed<10,3> can hold values from -4 to ~3.99, so it is logically the same. The following code compiles successfully:

ap_fixed<10, 3, AP_TRN> a;

ap_fixed<10, 3, AP_TRN, AP_SAT_SYM> b;

int c;

c = floor(a);

c = floor( ap_fixed<10,3> b).to_int() // no compilation error

Nicholas Moellers

Xilinx Worldwide Technical Support

Xilinx Worldwide Technical Support

1 Reply

nmoeller

Xilinx Employee

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-12-2018 12:58 PM

215 Views

Registered:
09-05-2018

Hey @dsula,

The hls_math.h library only supports the first and second template parameters. This is stated in UG902 on page 242. However, it doesn't explicitly say that the third and beyond template parameters and not supported, and I've reported to the appropriate teams that this is confusing.

The reason c = floor( a ) compiles is that AP_TRN is the default, so ap_fixed<10, 3, AP_TRN> a is understood to be the same type as ap_fixed<10,3> a.

As a workaround, can you cast b to ap_fixed<10, 3> before calling floor()? ap_fixed<10,3> can hold values from -4 to ~3.99, so it is logically the same. The following code compiles successfully:

ap_fixed<10, 3, AP_TRN> a;

ap_fixed<10, 3, AP_TRN, AP_SAT_SYM> b;

int c;

c = floor(a);

c = floor( ap_fixed<10,3> b).to_int() // no compilation error

Nicholas Moellers

Xilinx Worldwide Technical Support

Xilinx Worldwide Technical Support