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
Visitor bit_slicer
Visitor
229 Views
Registered: ‎07-25-2018

Unnecessary float casting described in the MicroBlaze reference manual

Jump to solution

While reading through the MicroBlaze Reference Manual I ran across an alarming entry (UG984 v2018.2 page 93):

"While conversions between floating point and integer formats are supported in hardware by the FPU, when C_USE_FPU is set to 2 (Extended), it is still best to avoid them when possible."

(!!!)

No further explanation is given.  Why is it best to avoid them???  When is it ok or not ok to use a hard cast?  Is there any instance where a hard cast will yield an erroneous result?  An example is given where a hard cast is in a loop which suggests it's a performance issue, but the wording isn't all that clear.

It's a bit like putting the text "Airbags may fail" somewhere in a car owners user manual, and leaving it at that.

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
Xilinx Employee
Xilinx Employee
146 Views
Registered: ‎08-01-2019

Re: Unnecessary float casting described in the MicroBlaze reference manual

Jump to solution

The convention of avoiding unnecesary casting isn't specific to the MicroBlaze, but rather a general programming guideline. When you perform an explicit type cast, you are essentially telling the compiler "I know what I'm doing so stop checking". In other words, explicit type casting overrides compiler functionality and can be dangerous if used incorrectly. But again, this is true for all programming applications and not just the MicroBlaze.

 

Here are some relevant resources:

https://developerinsider.co/type-casting-c-programming/

https://stackoverflow.com/questions/1942159/need-some-clarification-regarding-casting-in-c

https://stackoverflow.com/questions/4167304/why-should-casting-be-avoided

 

Hope this helps!

View solution in original post

0 Kudos
1 Reply
Xilinx Employee
Xilinx Employee
147 Views
Registered: ‎08-01-2019

Re: Unnecessary float casting described in the MicroBlaze reference manual

Jump to solution

The convention of avoiding unnecesary casting isn't specific to the MicroBlaze, but rather a general programming guideline. When you perform an explicit type cast, you are essentially telling the compiler "I know what I'm doing so stop checking". In other words, explicit type casting overrides compiler functionality and can be dangerous if used incorrectly. But again, this is true for all programming applications and not just the MicroBlaze.

 

Here are some relevant resources:

https://developerinsider.co/type-casting-c-programming/

https://stackoverflow.com/questions/1942159/need-some-clarification-regarding-casting-in-c

https://stackoverflow.com/questions/4167304/why-should-casting-be-avoided

 

Hope this helps!

View solution in original post

0 Kudos