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

turn on suggestions

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
- :
- What fixed and float arithmetic function can be sy...

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

sanhu

Contributor

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

05-18-2015 01:08 AM

9,051 Views

Registered:
12-04-2014

What fixed and float arithmetic function can be synthesis in vivado hls?

Hi,

Can fixed point / floating point function such as cos , acos , sqrt be synthesis in vivado hls ?

where can I get such information ?

5 Replies

dahenk

Explorer

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

05-18-2015 03:00 AM

9,038 Views

Registered:
09-02-2013

Re: What fixed and float arithmetic function can be synthesis in vivado hls?

#include "hls_math.h"

This should give you access to such synthesizable functions.

debrajr

Moderator

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

05-19-2015 04:55 AM

9,020 Views

Registered:
04-17-2011

Re: What fixed and float arithmetic function can be synthesis in vivado hls?

Regards,

Debraj

----------------------------------------------------------------------------------------------

Kindly note- 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.

----------------------------------------------------------------------------------------------

Debraj

----------------------------------------------------------------------------------------------

Kindly note- 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.

----------------------------------------------------------------------------------------------

sanhu

Contributor

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

05-19-2015 09:09 PM

9,009 Views

Registered:
12-04-2014

Re: What fixed and float arithmetic function can be synthesis in vivado hls?

It listed only floating point function , no fixed point function.

for resource consideration, I'd like to use fixed point functions.

The document says fixed point function also supported by a complex way as follows :

• Review Table 2-5 to determine if a fixed-point implementation is supported.

• Update the math functions to use ap_fixed types.

• Perform C simulation to validate the design still operates with the required precision.

The C simulation is performed using the same bit-accurate types as the RTL

implementation.

• Synthesize the design.

The first step, Table 2-5 list only floating point function , no fixed point function.

The second step. Does it mean that I should copy the source code of floating point functions and rewrite it in fixed point ?

here is my source code converting rgb to hsi, fixed point min/max/sqrt/acos/atan are not reported as error.

#include "hls_math.h"

#include "ap_fixed.h"

void rgb2hsi( ap_uint<8> r, ap_uint<8> g, ap_uint<8> b, ap_uint<8> *h, ap_uint<8> *s, ap_uint<8> *i)

{

ap_ufixed<16,8> rr,gg,bb;

ap_ufixed<16,8> min_val, max_val ;

ap_fixed<16,8> ss, hh, ii ;

ap_fixed<32,16> t1,t2,t3 ;

ap_ufixed<32,16> theta ;

rr = r ; gg = g ; bb = b ;

rr = rr>>8 ; gg = gg>>8 ; bb = bb>>8 ;

ii = (rr+gg+bb)*(ap_ufixed<16,0>)0.333333;

min_val = fmin( rr , gg ) ;

min_val = fmin( bb , min_val ) ;

max_val = fmax( rr , gg ) ;

max_val = fmax( bb , min_val ) ;

if(max_val == min_val)

{

ss = 0;

hh = -1.0;

}

else

{

// c

ss = 1 - 3 * min_val / ( rr + gg + bb ) ;

// h

t1 = (rr - gg + rr - bb )/2 ;

t2 = (rr-gg)*(rr-gg)+(rr-bb)*(gg-bb) ;

t3 = t1 / t2 ;

theta = atanf(t3) ; // acos not supported, use atanf instead

if (b > g)

{

hh = 2 - theta;

}

else

{

hh = theta;

}

}

*h = hh ;

*s = ss ;

*i = ii ;

}

keyvanshahinrub1365

Visitor

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

09-18-2017 02:43 PM

2,141 Views

Registered:
06-13-2017

Re: What fixed and float arithmetic function can be synthesis in vivado hls?

oderousmonk

Visitor

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

09-18-2017 07:43 PM

2,129 Views

Registered:
05-10-2017

Re: What fixed and float arithmetic function can be synthesis in vivado hls?

Hello,

For cos, you should be able to use the DDS ip for a fixed point implementation. Or write your own look-up table implementation.

I don't think there is built-in fixed point IP for the other functions you mentioned, however, there is some examples of CORDIC based square root and atan here that may help:

https://github.com/Xilinx/HLx_Examples/tree/master/Math.

You can also use Newton's method to implement these, but I don't know of a ready to go example anywhere. The issue is that for something like atan or sqrt, when you get close to the boundaries, fixed point solutions have a lot of error, or require a lot of iterations in order to get an accurate result. So if you need a lot of accuracy close to the boundaries it may not be much more efficient to use fixed instead of floating point. Of course it depends a lot on what your system requirements are, but this is something to consider.

Hope this helps,

eschei