SoC
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
  • Arm Cortex M3
  • Contact
Reading: What is FPU in Cortex-M4?
SUBSCRIBE
SoCSoC
Font ResizerAa
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
Search
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
Have an existing account? Sign In
Follow US
  • Looking for Something?
  • Privacy Policy
  • About Us
  • Sitemap
  • Contact Us
© S-O-C.ORG, All Rights Reserved.
Arm

What is FPU in Cortex-M4?

Scott Allen
Last updated: October 5, 2023 9:56 am
Scott Allen 6 Min Read
Share
SHARE

The FPU (Floating Point Unit) in Cortex-M4 is a hardware unit that provides support for floating point arithmetic operations. It allows the Cortex-M4 processor to efficiently perform mathematical calculations involving floating point numbers.

Contents
Overview of Floating Point NumbersKey Properties of Floating Point NumbersNeed for Floating Point Unit (FPU)FPU in Cortex-M4Key Features of Cortex-M4 FPUFPU RegistersFPU InstructionsLazy Context SavingUsing the Cortex-M4 FPUBenefits of Cortex-M4 FPUSummary

Overview of Floating Point Numbers

Floating point numbers are used to represent real numbers in computing. They allow a wide range of values to be represented with a fixed amount of memory. Unlike integers which have a fixed precision, floating point numbers have a variable precision – the position of the decimal point can “float” to accommodate a large range of values.

A floating point number is typically represented in computer memory using a format specified by the IEEE 754 standard. This defines the bit layout that encodes a floating point value in 32 bits (single precision) or 64 bits (double precision). The bit layout consists of a sign bit, exponent bits, and mantissa/fraction bits.

Key Properties of Floating Point Numbers

  • Allow a wide range of values – from very small fractional values to very large values.
  • Variable precision – the position of the decimal point can change.
  • IEEE 754 standard defines common bit layouts for representation.
  • Consist of sign, exponent, mantissa (fraction) components.

Need for Floating Point Unit (FPU)

Floating point arithmetic such as addition, subtraction, multiplication and division requires complex digital logic circuits. Implementing this directly in the CPU would take up substantial silicon area and impact performance.

Therefore, most processor architectures implement a dedicated Floating Point Unit (FPU) to handle floating point operations efficiently.

The key advantages of having an FPU are:

  • Frees up the main CPU from handling complex floating point logic.
  • Optimized for floating point operations, giving much better performance.
  • Floating point instructions can work in parallel with integer instructions.
  • Modular design allows upgrading the FPU as needed.

FPU in Cortex-M4

The Cortex-M4 processor includes an optional single precision FPU that supports the ARMv7E-M architecture. The FPU provides hardware acceleration for floating point arithmetic and helps Cortex-M4 deliver better performance for math-intensive applications.

Key Features of Cortex-M4 FPU

  • Complies with IEEE 754 single precision (32 bit) floating point standard.
  • Supports SIMD instructions for vector operations.
  • Lazy context switching reduces context saving for lower ISR latency.
  • Configurable as either Shared FPU or Locked FPU via CPACR register.
  • Up to 40% better coremark score compared to Cortex-M3.

FPU Registers

The Cortex-M4 FPU provides 32 single precision floating point registers named S0-S31. These are 32 bit wide registers used for floating point operations. The FPU also uses a 5 bit FPSCR register to control and report on floating point execution.

FPU Instructions

The Cortex-M4 assembly instruction set includes special floating point instructions that operate on the FPU registers. These include:

  • Floating point move, convert, compare, arithmetic instructions.
  • Data type conversion between integer and floating point values.
  • SIMD instructions for vector arithmetic on pairs of FPU registers.

Examples include VADD (vector add), VDIV (vector divide), VCMP (vector compare) etc. This allows the FPU to efficiently perform math operations on floating point arrays and matrices.

Lazy Context Saving

The Cortex-M4 FPU employs lazy context saving for low interrupt latency. This avoids saving FPU registers during context switches unless the FPU state is actually modified. This optimization reduces context saving time from 150 cycles to around 60 cycles for short ISRs that don’t use the FPU.

Using the Cortex-M4 FPU

To use the hardware FPU in Cortex-M4 applications, there are some key steps involved:

  1. Enable FPU in CPACR register during Cortex-M4 configuration.
  2. Use floating point data types like float, double in code where needed.
  3. Use compiler intrinsics or asm for explicit FPU instructions.
  4. Link appropriate floating point library like newlib-nano-fpu.
  5. Set compiler options to target hardware FPU.

This ensures the compiler generates the appropriate FPU instructions and linking brings in floating point support libraries. The FPU handling is then transparent to the application code.

Benefits of Cortex-M4 FPU

Key benefits of using the hardware FPU in Cortex-M4 designs:

  • Accelerate floating point math performance substantially.
  • Frees up CPU cycles for other tasks.
  • Enables advanced math intensive applications.
  • SIMD instructions speed up signal processing code.
  • Lower energy consumption compared to software emulation.

Overall the Cortex-M4 FPU is a very useful feature for embedded systems requiring floating point capability with good performance and power efficiency.

Summary

The FPU in Cortex-M4 is a hardware unit for efficient floating point arithmetic. It provides IEEE 754 compliant single precision operations using dedicated registers and instructions. Key features include SIMD support, lazy context saving and better performance relative to Cortex-M3. Using the FPU is enabled by compiler settings and appropriate libraries. It benefits math-intensive Cortex-M4 applications by accelerating floating point at lower power.

Newsletter Form (#3)

More ARM insights right in your inbox

 


Share This Article
Facebook Twitter Email Copy Link Print
Previous Article Does Arm Cortex-M4 have FPU?
Next Article How to Enable the FPU in Cortex-M4 Microcontrollers?
Leave a comment Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

2k Followers Like
3k Followers Follow
10.1k Followers Pin
- Sponsored-
Ad image

You Might Also Like

What are the basics of cortex-M3 registers?

The Cortex-M3 is an ARM processor core that is widely…

13 Min Read

Use the same ISR for multiple interrupt sources in Cortex M0+

The Cortex M0+ processor supports handling multiple interrupt sources using…

8 Min Read

How to get QEMU to run an ARM Thumb binary?

Getting QEMU to run an ARM Thumb binary requires configuring…

8 Min Read

ARM Cortex-M3 Architecture

The ARM Cortex-M3 is a 32-bit ARM processor core licensed…

6 Min Read
SoCSoC
  • Looking for Something?
  • Privacy Policy
  • About Us
  • Sitemap
  • Contact Us
Welcome Back!

Sign in to your account