Thread overview
versions for thumb and thumb-2 instruction sets
Feb 06, 2016
Dan Olson
Feb 07, 2016
Johannes Pfau
Feb 07, 2016
Mike
Feb 10, 2016
Dan Olson
Feb 11, 2016
Mike
Feb 11, 2016
Dan Olson
Feb 07, 2016
Timo Sintonen
Feb 08, 2016
Dan Olson
February 06, 2016
Hi Iain, Johannes.  I'm asking here because I don't expect anybody else is playing with thumb instructions.

Both GDC and LDC have version ARM_Thumb defined for original thumb (call it thumb-1) and thumb-2.  But there is no way to tell in D code which set is supported.

GCC and clang define these:

__arm__
Always defined when building for the ARM architecture (regardless of
target instruction set)

__thumb__
Defined only when targeting any Thumb instruction set variant (Thumb-1
or Thumb-2)

__thumb2__
Defined only when targeting Thumb-2

We could mimic this by adding ARM_Thumb2.

But in my experience it is usually thumb-1 that needs special handling because it is very limited, and thumb-2 uses unified assembler so often same code works for either thumb-2 or arm modes.

So I am thinking that ARM_Thumb1 would be more practical.  What do you think?
-- 
Dan
February 07, 2016
Am Sat, 06 Feb 2016 13:58:17 -0800
schrieb Dan Olson <gorox@comcast.net>:

> Hi Iain, Johannes.  I'm asking here because I don't expect anybody else is playing with thumb instructions.
> 
> Both GDC and LDC have version ARM_Thumb defined for original thumb (call it thumb-1) and thumb-2.  But there is no way to tell in D code which set is supported.
> 
> GCC and clang define these:
> 
> __arm__
> Always defined when building for the ARM architecture (regardless of
> target instruction set)
> 
> __thumb__
> Defined only when targeting any Thumb instruction set variant (Thumb-1
> or Thumb-2)
> 
> __thumb2__
> Defined only when targeting Thumb-2
> 
> We could mimic this by adding ARM_Thumb2.
> 
> But in my experience it is usually thumb-1 that needs special handling because it is very limited, and thumb-2 uses unified assembler so often same code works for either thumb-2 or arm modes.
> 
> So I am thinking that ARM_Thumb1 would be more practical.  What do you think?

Sorry, I never really used Thumb code so I don't know whether Thumb1 or Thumb2 would be more useful. But both would be trivial to implement in GDC, so just choose what you think makes most sense.

Or we could add both ARM_Thumb1 and ARM_Thumb2 versions. If there'll ever be a Thumb3 we need both anyway.
February 07, 2016
On Saturday, 6 February 2016 at 21:58:17 UTC, Dan Olson wrote:
> Hi Iain, Johannes.  I'm asking here because I don't expect anybody else is playing with thumb instructions.
>
> Both GDC and LDC have version ARM_Thumb defined for original thumb (call it thumb-1) and thumb-2.  But there is no way to tell in D code which set is supported.
>
> GCC and clang define these:
>
> __arm__
> Always defined when building for the ARM architecture (regardless of
> target instruction set)
>
> __thumb__
> Defined only when targeting any Thumb instruction set variant (Thumb-1
> or Thumb-2)
>
> __thumb2__
> Defined only when targeting Thumb-2
>
> We could mimic this by adding ARM_Thumb2.
>
> But in my experience it is usually thumb-1 that needs special handling because it is very limited, and thumb-2 uses unified assembler so often same code works for either thumb-2 or arm modes.
>
> So I am thinking that ARM_Thumb1 would be more practical.  What do you think?

I think to do this properly with ARM you need to consider the ARM architecture (ARMv6, ARMv7, ARMv7-A, ARMv7-M, etc..) AND the instruction set (ARM or ARM_Thumb).  I read it somewhere, but I'm having trouble finding it again.

Anyway, used in conjunction with the architecture, I believe only one ARM_Thumb identifier is needed.

It also appears that, with the introduction of AArch64, ARM is trying to transition this nomenclature to A32 (ARM), T32 (Thumb), A64 (64-bit ARM?).  See http://www.arm.com/products/processors/instruction-set-architectures/

Mike

Mike


February 07, 2016
On Saturday, 6 February 2016 at 21:58:17 UTC, Dan Olson wrote:
> Hi Iain, Johannes.  I'm asking here because I don't expect anybody else is playing with thumb instructions.
>
> Both GDC and LDC have version ARM_Thumb defined for original thumb (call it thumb-1) and thumb-2.  But there is no way to tell in D code which set is supported.
>
> GCC and clang define these:
>
> __arm__
> Always defined when building for the ARM architecture (regardless of
> target instruction set)
>
> __thumb__
> Defined only when targeting any Thumb instruction set variant (Thumb-1
> or Thumb-2)
>
> __thumb2__
> Defined only when targeting Thumb-2
>
> We could mimic this by adding ARM_Thumb2.
>
> But in my experience it is usually thumb-1 that needs special handling because it is very limited, and thumb-2 uses unified assembler so often same code works for either thumb-2 or arm modes.
>
> So I am thinking that ARM_Thumb1 would be more practical.  What do you think?

Thumb2 is an extension to thumb. It has everything that thumb has and more. There is nothing in thumb that is not in thumb2. There is no thumb1. Thumb is sometimes called thumb1 because thumb is often understood to be both thumb and thumb2.

Thumb2 was introduced to some armv6 devices and it is in all v7 and later devices, including all Cortex ones. I do not remember dates but I think it has been nearly 10 years that all new designs have been thumb2. There may not be many old thumb processors out there any more.

I do not know if there is need to support old thumb any more. However, if it is wanted, plain thumb or thumb1 is just what is not thumb2 and can be handled in else branch of thumb2 test.


February 07, 2016
Timo Sintonen <t.sintonen@luukku.com> writes:
> Thumb2 is an extension to thumb. It has everything that thumb has and more. There is nothing in thumb that is not in thumb2. There is no thumb1. Thumb is sometimes called thumb1 because thumb is often understood to be both thumb and thumb2.
>
> Thumb2 was introduced to some armv6 devices and it is in all v7 and later devices, including all Cortex ones. I do not remember dates but I think it has been nearly 10 years that all new designs have been thumb2. There may not be many old thumb processors out there any more.
>
> I do not know if there is need to support old thumb any more. However, if it is wanted, plain thumb or thumb1 is just what is not thumb2 and can be handled in else branch of thumb2 test.

It just made my code uglier with version ARM_Thumb2 only because you can't do !version like ifndef or !defined.  This is on an armv6 with thumb1.  I know Walter is not for extra versions if they can be derived from others though.

version (ARM)
{
    version (ARM_Thumb) // could be thumb1 or thumb2
    {
        version (ARM_Thumb2) {} else version = ARM_Thumb1;
    }

    version (ARM_Thumb1)
    {
        // orginal thumb inline asm
    }
    else
    {
        // arm and thumb-2 inline unified asm
    }
}
February 10, 2016
Mike <none@none.com> writes:
> I think to do this properly with ARM you need to consider the ARM architecture (ARMv6, ARMv7, ARMv7-A, ARMv7-M, etc..) AND the instruction set (ARM or ARM_Thumb).  I read it somewhere, but I'm having trouble finding it again.
>
> Anyway, used in conjunction with the architecture, I believe only one ARM_Thumb identifier is needed.
>
> It also appears that, with the introduction of AArch64, ARM is trying
> to transition this nomenclature to A32 (ARM), T32 (Thumb), A64 (64-bit
> ARM?).  See
> http://www.arm.com/products/processors/instruction-set-architectures/
>
> Mike

You are right.  I noticed that even thumb-1 has different instruction set based on arm architecture.  Now that I think about it and considering Timo's comment that we won't find many thumb-1 devices, it probably doesn't make sense polluting D with versions that no one will use (except me).  Probably best approach for me is to just define ARM_Thumb1 on the command line for my current project.
-- 
Dan
February 11, 2016
On Wednesday, 10 February 2016 at 17:03:35 UTC, Dan Olson wrote:
>
> I noticed that even thumb-1 has different instruction set based on arm architecture.

Yes.  I did a little more research into this, as it peeked my curiosity.  Take a look at this Wikipedia entry (https://en.wikipedia.org/wiki/ARM_Cortex-M#Instruction_sets).  I haven't verified this information independently, but there you can see that although the M0 and M1 support Thumb-1, they don't support all of it.  And worse still, they additionally support some of Thumb-2.  So "Thumb", "Thumb-1", and "Thumb-2" without the architecture/profile are all ambiguous.  As far as I can tell the only true indication of the supported instruction set is the architecture (ARMv6, ARMv7, ARMv8, etc...), the profile (A, R, and M) etc..  AND the target instruction set (ARM "A32", Thumb "T32", or A64) -- all three of them together.

> Probably best approach for me is to just define ARM_Thumb1 on the command line for my current project.

If you make versions for the architecture/profile (ARMv6, ARMv7-A, ARMv7-M, ARMv7E-M, etc...) I think you only need to disambiguate the cases where an architecture/profile supports both Thumb and ARM -- like the A profile, if I remember correctly.

So, I still only see the need for one ARM_Thumb instruction set identifier, but that could very well be a limitation of my own understanding, and a lack of knowledge about your current project.

Mike
February 11, 2016
Mike <none@none.com> writes:

> On Wednesday, 10 February 2016 at 17:03:35 UTC, Dan Olson wrote:
>>
>> I noticed that even thumb-1 has different instruction set based on arm architecture.
>
> Yes.  I did a little more research into this, as it peeked my curiosity.

Good info Mike.  Thanks.

> So, I still only see the need for one ARM_Thumb instruction set identifier, but that could very well be a limitation of my own understanding, and a lack of knowledge about your current project.
>
> Mike

My current project is a not-so-very-important side project to add thumb-1 support to druntime for LDC.  It may not really be needed but thought I'd take a look at it.  I am in the middle of helping cleanup LDC ARM linux target and have been testing on an original Raspberry Pi armv6.  I noticed it had thumb-1 and added the extra support to core.thread.  Now am deciding if it should go anywhere.

For reference, it is this code that started this topic.

https://github.com/smolt/druntime/blob/pi/src/core/thread.d#L2482