Skip to main content
MikeDB
Senior II
May 2, 2019
Question

STMCUBEIDE - H7 series force use of SMLAL (Signed Multiply with Accumulate (32 × 32 + 64), 64-bit result) instruction

  • May 2, 2019
  • 3 replies
  • 3165 views

Code is :

int16_t 	OscPhase[NumOsc];
int32_t 	OscInc[NumOsc];
int32_t 	OscVol[NumOsc];
int32_t 	Sine[65536];
 
int64_t 	OscTotal;
 
 
and then in main() :
 
		OscTotal = 0;
		for (i = 0; i < NumOsc; i++)
		{
			OscPhase[i] = OscPhase[i] + OscInc[i];
			OscTotal = OscTotal + Sine[OscPhase[i]] * OscVol[i];
		}

I was expecting the H7 to use the SMLAL instruction for the final multiply and accumulate but instead it performs a MUL.W which only gives a 32 bit result and then uses an ADD.W and ADC.W to add these 32 bits into the final 64 bit result.

Any suggestions on how to force it to use the correct code ?

This topic has been closed for replies.

3 replies

waclawek.jan
Super User
May 2, 2019

Use inline assembler.

JW

MikeDB
MikeDBAuthor
Senior II
May 2, 2019

Oh come on, this is the 21st century. Even the Arduino compiler produces better code than this managed so I'm sure it's just a compiler directive or something I am missing.

waclawek.jan
Super User
May 2, 2019

Then use Arduino.

JW

MikeDB
MikeDBAuthor
Senior II
May 2, 2019

It doesn't support the full M7 instruction set. Only the M0/3.

Ozone
Principal
May 2, 2019

Does the shiny new STMCubeIDE support the M7 fully ? Including the H7 ?

Else, get a proper toolchain.

Tesla DeLorean
Guru
May 2, 2019

Try casting Sine with (int64_t) in the computaion.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
MikeDB
MikeDBAuthor
Senior II
May 2, 2019

Amazingly that works !!

ldr.w   r3, [r9, r0, lsl #2]

smlal   r4, r5, r1, r3

Definition of SMLAL is

SMLAL       R4, R5, R1, R3   ; Signed (R5,R4) = (R5,R4) + R1 × R3

Casting Sine to be 64 bits surely should force a 32*64 multiply but in fact it is indeed creating a 32*32 multiply (R1 x R3) ?

Methinks there is a bug in the compiler !

Tesla DeLorean
Guru
May 2, 2019

>>Methinks there is a bug in the compiler !

It is GNU, try something more industrial..

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..