CMSIS_6 icon indicating copy to clipboard operation
CMSIS_6 copied to clipboard

Differentiating between CM33 and CM85 with preprocessor

Open renesas-kyle-finch opened this issue 1 year ago • 5 comments

In a previous issue submitted to CMSIS 5, I was told that it was no longer advisable to use the arch defines like __ARM_ARCH_8M_MAIN__ and to instead use __ARM_ARCH.

But dumping preprocessor defines for CM33 and CM85 both yield the same __ARM_ARCH* defines:

// Using GCC 13.2
#define __ARM_ARCH 8
#define __ARM_ARCH_8M_MAIN__ 1
#define __ARM_ARCH_EXT_IDIV__ 1
#define __ARM_ARCH_ISA_THUMB 2
#define __ARM_ARCH_PROFILE 77

Note that GCC generates __ARM_ARCH_8M_MAIN__ for both CM33 and CM85.

LLVM 17 generates the same as GCC, with the exception that it generates __ARM_ARCH_8_1M_MAIN__ for CM85.

How should CM33 and CM85 be differentiated with the preprocessor?

renesas-kyle-finch avatar May 07 '24 22:05 renesas-kyle-finch

Hi @renesas-kyle-finch,

this seems still to be a shortcoming in GCC. According to ACLE one should be able to detect the architecture by looking to __ARM_ARCH, see https://developer.arm.com/documentation/101028/0012/5--Feature-test-macros.

I'll pass this on to our GCC experts.

JonatanAntoni avatar May 08 '24 06:05 JonatanAntoni

@JonatanAntoni thank you.

To be clear, both GCC and LLVM both produce __ARM_ARCH 8 for both CM33 and CM85. From the link you provided, I would expect that they would produce __ARM_ARCH 8 for CM33 and __ARM_ARCH 801 for CM85.

Does that match your expectations as well?

renesas-kyle-finch avatar May 08 '24 16:05 renesas-kyle-finch

From some more testing of CM85 with multiple toolchains, this is what I am seeing for __ARM_ARCH and __ARM_ARCH_xx__

Toolchain __ARM_ARCH __ARM_ARCH_xx__
GCC 8 __ARM_ARCH_8M_MAIN__
LLVM 8 __ARM_ARCH_8_1M_MAIN__
AC6 8 __ARM_ARCH_8_1M_MAIN__
IAR 801 __ARM_ARCH_8M_MAIN__

So it seems neither paradigm produces correct output across all of these toolchains.

renesas-kyle-finch avatar May 08 '24 20:05 renesas-kyle-finch

CMSIS contains the revision number of each core using these defines: https://arm-software.github.io/CMSIS_6/v6.0.0/Core/group__device__config.html

Even when a device vendor does not provide the exact revision of the implementation, the fallback ensures that this define exists:

  • https://github.com/ARM-software/CMSIS_6/blob/main/CMSIS/Core/Include/core_cm85.h#L222
  • https://github.com/ARM-software/CMSIS_5/blob/master/CMSIS/Core/Include/core_cm85.h#L201

This information is therefore less dependent on Compiler internal defines specified by ACLE and maybe easier to query.

#if defined (__CM85_REV)    // running on Cortex-M85
 ...

I hope this helps.

ReinhardKeil avatar May 10 '24 07:05 ReinhardKeil

I will give that a try.

As far as looking to the future, are the __ARM_ARCH and __ARM_ARCH_ISA_THUMB macros still the advised macros to use and what the compilers should be striving to produce?

renesas-kyle-finch avatar May 10 '24 16:05 renesas-kyle-finch