-1

I need to force IAR tp use certain Cortex-M0+ instruction in some part of my code while codding with C.

Please do not offer pure asm functions or inline asm etc.

I have managed to do this for 51 instruction but could not for ; ADR, BLX, RSBS, SBCS, SXTH instructions.

Optimization is disabled for this function (#pragma optimization=none)

I have tried many things by considering instruction behaviour. But IAR preferred to same function with different instructions.

Did anyone else struggle with such a unnecessary thing before or has anyone an idea?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • There's no guarantee it's possible to get it to emit all of those, but I'd expect that `rsbs` should be doable. Maybe not with optimizations disable, though; you might only get it when it can CSE between setting flags and a separate subtraction result. – Peter Cordes Dec 06 '17 at 11:59
  • Is there an online compiler anywhere that has IAR? i.e. like [Matt Godbolt's compiler explorer](https://godbolt.org/g/1Fz34d), except that it only has gcc installed. – Peter Cordes Dec 06 '17 at 12:04
  • 1
    gcc uses `rsbs` with `-mcpu=cortex-m4`, but not with `-mcpu=cortext-m0` for this function: https://godbolt.org/g/xUraX9. Perhaps IAR is avoiding it on purpose for some reason? – Peter Cordes Dec 06 '17 at 12:11
  • 3
    What is the purpose of this exercise? – fuz Dec 06 '17 at 14:28
  • asm is the only way to get the instructions you want. if you want specific instructions there you go if you want the compiler to choose then you give up your right to specific instructions. – old_timer Dec 06 '17 at 18:20
  • Instruction set test witout using asm for class c safet app. – Yilmaz Kircicek Dec 07 '17 at 12:49

2 Answers2

1

Please do not offer pure asm functions or inline asm etc.

But these are the only solution to your problem that won't depend on compiler version.

You may have

managed to do this for 51 instruction

..but the next (major) compiler version could have a vastly different idea on how to generate instructions for your C code, even when the optimizer is off. BTDT for GCC.

Coding stuff in assembly language directly eliminates this compiler version dependecy altogether. You should even have some example code, as most C-startup (reset handler) code is shipped as assembly language file.

Turbo J
  • 7,563
  • 1
  • 23
  • 43
  • I agree. If you must ensure an instruction is used assembly (inline or not) is the only way. – Realtime Rik Dec 07 '17 at 08:08
  • This is an class C safety application, so once we have finished and certified, single line of code will not be changed and will not be compiled with different version of compiler. All will be freezed. So I have no concerns such above. – Yilmaz Kircicek Dec 07 '17 at 12:47
  • Processor instruction tests are one of the few things that should be done in assembly language. You might not be *able* to get 100% coverage in pure C, as the compiler could simply not generate certain instructions from C code as long as there are other redundancies. – Turbo J Dec 07 '17 at 22:41
  • The assembly source code would also be a lot simpler and cleaner to read compared to the hoops you will need the C compiler to go through in order to generate "your" instructions. – Turbo J Dec 07 '17 at 22:42
-1

Apart from BLX which isn't available on cortex-m this code may get you there. Maybe you have to turn on some optimizations.

char const * getstr(void)
{
    return "ADR";
}

long long llfunc(long long v1, long long v2)
{
    return v1 - v2;
}

int neg(int i)
{
    return -i;
}


void efunc(short);

void func(short s)
{
    efunc(s + 5);
}
PNY
  • 29
  • 3