This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Use BVS/BCS for fast overflow check with long long

Hi,
I need some long long (64 bit) additions in a fast interrupt code.

After each addition, I need to limit the result to MIN/MAX_INT64 if some overflow occurred.

In assembler, I would use the brach command BVC/BVS to check the overflow flag after the addition - this would be only one additional command, very nice (in normal case, where no overflow occurs).

Is there any way to implement / insert such functionality also in C / C++ code?

I tried to include dspfncts.h, and then check the variable Overflow, but this will add 3 additional assembly lines (to load the value of the overflow bit - it does NOT use the very compact commands BVC/BVS). As I have quite many such additions, this will blow up my code quite a bit.

Is there any possibility to do this overflow check in an efficient way in C/C++?

Parents
  • For this I would need inline assembly.

    But as I see it, inline assembly does not work in STM32F4, as it requires thumb mode, and inline assembly does not work in thumb mode.

    Further I am anxious, that even with inline assembly I might get problems, as for such a branch I also need some label to branch to. Although it is a very local label - only some lines further down - as I read I am frightened labels do not work in Keil inline assembler?

Reply
  • For this I would need inline assembly.

    But as I see it, inline assembly does not work in STM32F4, as it requires thumb mode, and inline assembly does not work in thumb mode.

    Further I am anxious, that even with inline assembly I might get problems, as for such a branch I also need some label to branch to. Although it is a very local label - only some lines further down - as I read I am frightened labels do not work in Keil inline assembler?

Children
No data