Clear Filters
Clear Filters

Why is matlab fixed pint arithmetic so slow?

21 views (last 30 days)
I don't have a very strong FPU (no video card). I intended to accelerate my computation representing floating point numbers as 32.32 for 64-bit dwords. However, Matlab's fixed point arithmetic doesn't seem to support 64-bit numbers, and moreover, turns out to be not just not faster, but actually orders of magnitude slower than floating point.
Why? Is there any reasonable way to switch from floading point arithmetic to integer arithmetic (actually representing floating point numbers)?

Answers (1)

MathWorks Fixed Point Team
Edited: MathWorks Fixed Point Team on 31 Aug 2020
There are two aspects to speed that you may be concerned about.
The first is the speed of generated code running on your embedded chip.
The second is the speed of simulation while running MATLAB or Simulink.
For speed on the embedded device,
you want to pick data types that match what the chip's hardware supports efficiently. Among the types that are supported efficiently, you also generally want to pick the smallest type that still provides enough accuracy to pass your functional behavior.
For example on an ARM Cortex M, scalar operations are most efficiently computed on 32 bit integers. The long long 64 bit integers are about 2 to 4 times less efficient, so use them sparingly. Smaller types like 8 and 16 bit are more efficient at storage and moving memory.
As another example, a typical FPGA can efficiently do multiplies and accumulates with 18 bit and smaller inputs.
For both these example, if 64 bits where used everywhere, then it would be expected that the design would be slow and inefficient. In contrast, if the data types are reduced to just what's need to pass functional behavior test, then huge speed ups and reduced power usage can be expected.
Please check out this link for a tool that can automatically find the optimal data types for each Simulink signal in your model.
For simulation speed,
it is possible to get huge speed ups, especially for intensive behavioral testing.
In MATLAB, for intensive behavior simulations using fixed-point fi objects, it is very highly recommended to investigate fiaccel and the techniques mentioned here. Use of these techniques can increase simulation speed by 2 or 3 orders of magnitude. Note, when using fi objects in a Simulink MATLAB Function Block, you will automatically get the same benefits that fiaccel would provide.
In Simulink, significant increases in the speed of simulation can be obtained with two simple steps.
  1. Make sure min, max, overflow instrumentation is only only on when doing analysis or conversion. If it is on during simulation, there will be a message in the Diagnostic Viewer window.
  2. Utilize a simulation mode other than Normal Mode. Fixed-point simulations can be much faster when using accelerator modes and rapid accelerator. Simulink Performance Advisor will help find many speed improvements including the use of accelorator modes. When you need maximum simulation speed, it is highly recommended you run Performance Advisor for all your models, fixed-point, floating-point, or any mixture.




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!