Replace wide integer multiplication

12 views (last 30 days)
Leon Loeser
Leon Loeser on 25 Sep 2019
Answered: Andy Bartlett on 2 Jan 2020
Hello!
I'm using fixed-point data in a Simulink Embedded Coder project. The multipliers henceforth generate code that requires wide integer operations, because two 32-bit fixedpoint types get multiplied into a 64bit type and then shifted. For 32x32 bit multiplication, the code generator uses the utility-function
mul_wide_u32
mul_wide_s32
This function is complex and for my usecase unecessary as the Cortex M3 architecture has the MULL (long multiply) instruction. Is there a way to automatically replace mul_wide_u32 and mul_wide_s32 with custom functions? Since I use fixed point, I'd need to define a multiplication-function for every n of bitshift, so I'd like to replace just the multiplication and let matlab handle the shifting (mul_u32_loSR and so on).
Tl;Dr;: Can I replace generated code strings or functions with custom ones (not replace blocks, but replace generated code)
Thank you
Leon

Answers (2)

Leon Loeser
Leon Loeser on 29 Sep 2019
I have now found the code replacement library for Cortex M3, but few functions still use the utility functions generated by matlab despite the data-types being the same as in the multiplications replaced with Cortex functions. Any ideas?

Andy Bartlett
Andy Bartlett on 2 Jan 2020
Hi Leon,
Solving the problem may be a simple as turning on support long long for the model.
Please see this article.
and/or this video
Please let us know if that solves the problem
Andy

Community Treasure Hunt

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

Start Hunting!