[cfe-dev] Question about thumb2 define in clang for ARMv8

Jessica Clarke via cfe-dev cfe-dev at lists.llvm.org
Fri Dec 10 11:53:05 PST 2021


On 10 Dec 2021, at 19:05, Mikhail R. Gadelha via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> 
> Hi,
> 
> Em sex., 10 de dez. de 2021 às 12:37, Peter Smith <Peter.Smith at arm.com <mailto:Peter.Smith at arm.com>> escreveu:
> Hello,
> 
>  
> 
> My turn for the double post, my mail client stripped off the list on reply-all and I’d assumed it was llvm-dev. My apologies, resending back on cfe-dev
> 
>  
> 
> This is likely down to the default triple and CPU that clang uses.
> 
>  
> 
> An arm-linux-gnueabihf-gcc defaults to Thumb architecture v7-A which supports Thumb2. Whereas clang defaults to Arm state and architecture v4t which does not support Thumb2.
> 
>  
> 
> On a relatively recent build of clang, but I think this goes back some way:
> 
> clang --target=arm-linux-gnueabihf -mthumb -march=armv7-a -dM -E - < /dev/null | grep thumb
> 
> #define __thumb2__ 1
> 
> #define __thumb__ 1
> 
>  
> 
> Can you give that a try?
> 
> 
> Nice, it now defines them:
> 
> $ clang --target=arm-linux-gnueabihf -mthumb -march=armv7-a -dM -E - < /dev/null | grep thumb
> #define __thumb2__ 1
> #define __thumb__ 1
> 
> but does it mean that if I don't pass these arguments clang won't thumb2 code? Despite __ARM_ARCH_ISA_THUMB being set to 2?

I believe __thumb__/__thumb2__ are defined based on what default mode you’re compiling for, and __ARM_ARCH_ISA_THUMB is defined based on what your processor supports. So:

-target=armv4t -marm: __ARM_ARCH_ISA_THUMB=1
-target=armv4t -mthumb: __ARM_ARCH_ISA_THUMB=1 __thumb__=1
-target=armv7 -marm: __ARM_ARCH_ISA_THUMB=2
-target=armv7 -mthumb: __ARM_ARCH_ISA_THUMB=2 __thumb__=1 __thumb2__=1

Jess

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20211210/5efdfece/attachment.html>


More information about the cfe-dev mailing list