Nios II Custom Instruction User Guide

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

6.1. Overview of the Floating Point Hardware 2 Component

The following figure shows the structure of the FPH2 component, with the display name Floating Point Hardware 2 and the IP name altera_nios_custom_instr_floating_point_2. Floating Point Hardware 2 packages all the floating point functions in a single component, consisting of the following subcomponents:
  • altera_nios_custom_instr_floating_point_2_combi
  • altera_nios_custom_instr_floating_point_2_multi
Figure 21. Custom Instruction ImplementationThis figure lists the floating-operations implemented by each custom instruction.
The characteristics of the FPH2 are:
  • Supports FPH1 operations (add, sub, multiply, divide) and adds support for square root, comparisons, integer conversions, minimum, maximum, negate, and absolute
  • Single-precision floating point values are stored in the Nios II general purpose registers
  • VHDL only
  • Platform Designer support only
  • Single-precision only
  • Optimized for FPGAs with 4-input LEs and 18-bit multipliers
  • GCC and Nios II SBT (Software Build Tools) software support
  • IEEE 754-2008 compliant except for:
    • Simplified rounding
    • Simplified NaN handling
    • No exceptions
    • No status flags
    • Subnormal supported on a subset of operations
  • Binary-compatibility with FPH1
    • FPH1 implements Round-To-Nearest rounding. Because FPH2 implements different rounding, results might be subtly different between the two generations
  • Resource consumption in a typical system:
    • Approximately 2500 4-input LEs
    • Nine 9-bit multipliers
    • Three M9K memories or larger

In Platform Designer, the Floating Point Hardware 2 component is under Embedded Processors on the Component Library tab.

Table 13.  Floating Point Custom Instruction 2 Operation SummaryIn this table, a and b are assumed to be single-precision floating point values.
Operation 4 N 5 Cycles Result Subnormal Rounding GCC Inference
fdivs 255 16 a ÷ b Flush to 0 Nearest a / b
fsubs 254 5 a – b Flush to 0 Faithful a – b
fadds 253 5 a + b Flush to 0 Faithful a + b
fmuls 252 4 a x b Flush to 0 Faithful a * b
fsqrts 251 8   Faithful sqrtf() 6
floatis 250 4 int_to_float(a) Not applicable Not applicable Casting
fixsi 249 2 float_to_int(a) Flush to 0 Truncation Casting
round 248 2 float_to_int(a) Flush to 0 Nearest lroundf()6
Reserved 234 to 247 Undefined Undefined      
fmins 233 1 (a < b) ? a : b Supported None fminf()6
fmaxs 232 1 (a < b) ? b : a Supported None fmaxf() 6
fcmplts 231 1 (a < b) ? 1 : 0 Supported None a < b
fcmples 230 1 (a ≤ b) ? 1 : 0 Supported None a <= b
fcmpgts 229 1 (a > b) ? 1 : 0 Supported None a > b
fcmpges 228 1 (a ≥ b) ? 1 : 0 Supported None a >= b
fcmpeqs 227 1 (a = b) ? 1 : 0 Supported None a == b
fcmpnes 226 1 (a ≠ b) ? 1 : 0 Supported None a != b
fnegs 225 1 -a Supported None -a
fabss 224 1 |a| Supported None fabsf()

The cycles column specifies the number of cycles required to execute the instruction. A combinatorial custom instruction takes 1 cycle. A multi-cycle custom instruction requires at least 2 cycles. An N-cycle multi-cycle custom instruction has N - 2 register stages inside the custom instruction because the Nios II processor registers the result from the custom instruction and allows another cycle for g wire delays in the source operand bypass multiplexers. The number of cycles does not include the extra cycles (maximum of 2) that an instruction following the multi-cycle custom instruction is stalled by the Nios II/f if the instruction uses the result within 2 cycles. These extra cycles occur because multi-cycle instructions are late result instructions

The Nios II Software Build Tools (SBT) include software support for the FPH2 component. When the FPH2 component is present in hardware, the Nios II compiler compiles the software codes to use the custom instructions for floating point operations.

4 These names match the names of the corresponding GCC command-line options except for round, which GCC does not support.
5 Specifies the 8 bit fixed custom instruction for the operation.
6 Nios II GCC version 4.7.3 is not able to reliably replace calls to newlib floating point functions with the equivalent custom instruction even though it has Flush to 0 -mcustom- <operation> command-line options and pragma support for these operations. Instead, the custom instruction must be invoked directly using the GCC __builtin_custom_* facility. The FPH2 component includes a C header file that provides the required #define macros to invoke the custom instruction directly.