Nios II Custom Instruction User Guide

ID 683242
Date 4/27/2020
Public
Document Table of Contents
Give Feedback

6.7.1. -fno-math-errno

From the GCC documentation:
“Do not set ERRNO after calling math functions that are executed with a single instruction, e.g., sqrt. A program that relies on IEEE exceptions for math error handling may want to use this flag for speed while maintaining IEEE arithmetic compatibility.”

If you specify -fno-math-errno on the GCC command line, the compiler maps calls to sqrtf() directly to the fsqrts custom instruction. Otherwise, by default GCC adds several instructions after the fsqrts custom instruction to check for a NaN result, indicating an attempt to take the square root of a negative number. If fsqrts returns NaN, the code calls the newlib sqrtf() function to set the C errno variable.

Typically, this overhead is undesirable. Intel recommends that you enable -fno-math-errno to eliminate the overhead of calling sqrtf().

If you use the Nios II SBT, the generated makefiles set -fno-math-errno by default. You can override this behavior by setting -fmath-errno in the CPPFLAGS make variable.

The -ffinite-math-only option also eliminates the overhead of checking for NaN result for square root. However, this option also has other effects. Refer to "-ffinite-math-only" for details about this option.