Keil Logo

ARMCLANG V6.12 BUG or my fault?

Next Thread | Thread List | Previous Thread Start a Thread | Settings

Details Message
Author
Thomas Roob
Posted
17-Apr-2019 09:12 GMT
Toolset
ARM
New! ARMCLANG V6.12 BUG or my fault?

Hello,

My function calculates scalar value from dB value using formular
scalar = 10 ^ (dB / 20)

In case of ARMCLANG V6.12 and Optimizer Level -O2 the calculation fails as
it is shown in my test code.

Maybe, I overlook something, do I?

#include "stm32f4xx.h"
#include <stdio.h>
#include <stdint.h>
#include <math.h>

static volatile int8_t dB;
static int8_t lastGain;

/**/
void setGain(int8_t gain)
{
  float vol;

  if (lastGain == gain) {
    // value is already set
    return;
  }
  // calculate scalar value
  vol = powf(10.f, (float)gain / 20.f);  // = 0.199526...
  // check limits
  if (vol > 10) {
    // "vol out of range" is printed in case of ARMCLANG V6.12 and Optimization > -O2
    printf("vol out of range\n");
  } else {
    // "passed" is printed in case of ARMCLANG V6.12 and Optimization -O0 or -O1
    printf("passed\n");
    lastGain = gain;
  }
}

/**/
int main(void)
{
  dB = -14;
  for(;;) {
    setGain(dB);
  }
}

Author
Andrew Neil
Posted
17-Apr-2019 11:49 GMT
Toolset
ARM
New! RE: ARMCLANG V6.12 BUG or my fault?
vol = powf(10.f, (float)gain / 20.f);  // = 0.199526...

Are you saying that's the value you expect it to be, or that's the value actually getting assigned to 'vol' ?

  dB = -14;

you haven't specified a type for 'dB' ...

Author
Thomas Roob
Posted
17-Apr-2019 15:11 GMT
Toolset
ARM
New! RE: ARMCLANG V6.12 BUG or my fault?

Yes, I am expecting 0.199526 and dB (decibel) is defined as
static volatile int8_t dB

Author
Andrew Neil
Posted
17-Apr-2019 16:35 GMT
Toolset
ARM
New! RE: I am expecting 0.199526

So again, as in your previous post, what debugging have you done to see where the "unexpected" behaviour originates ?

What result are you getting for that calculation in the target, and in the simulator.

Your code is just bog-standard 'C' - so what do you get if you build & run it with a native PC compiler?

http://www.keil.com/forum/64307/

Author
Thomas Roob
Posted
18-Apr-2019 20:04 GMT
Toolset
ARM
New! RE: I am expecting 0.199526

Try following links for the requested informations

uVision Projekt
https://www.file-upload.net/download-13576495/uVision-test.zip.html

Screenshot of simulator
https://www.file-upload.net/download-13576497/debug-out.png.html

Author
Andrew Neil
Posted
18-Apr-2019 20:28 GMT
Toolset
ARM
New! RE: I am expecting 0.199526

Please reply in the forum.

Author
Thomas Roob
Posted
18-Apr-2019 22:17 GMT
Toolset
ARM
New! RE: I am expecting 0.199526

The Project was created in Keil-MDK 5.27 for a Cortex M4 CPU
It is compiled with Compiler V6.12 using optimization Level -O2
stdout is retarged to ITM
Running the Code in Simulator is showing "vol out of range" in debug (printf) Viewer
This is not what I would expect because the result of the calculation must be smaller than 10. This issue does not occur with V5.06

Author
Andrew Neil
Posted
18-Apr-2019 23:42 GMT
Toolset
ARM
New! You didn't answer the question!

1. What result do you get for the calculation when running in the simulator?

2. What result do you get for the calculation when running in the real target?

3. What result do you get for the calculation when running on a PC?

Next Thread | Thread List | Previous Thread Start a Thread | Settings

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.