BitBand support planned?

Asked by Uwe Bonnes

Hello,

is bitband support planed. This would mean that a command like REGinBitBandArea &~ (SINGLEBITFLAG) would be translated into a write 0 to the appropriate bitband reg. AVR GCC already does something similar by translating bit set/reset operations in cbi()/sbi() commands. Perhaps some of that code can be reused.

Thanks

Question information

Language:
English Edit question
Status:
Answered
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Joey Ye (jinyun-ye) said :
#1

Simply no specific support in GCC for bit-band in ARM, and no plan to support it.

Revision history for this message
Harjit Singh (zeetahhs) said :
#2
Revision history for this message
Joey Ye (jinyun-ye) said :
#3

Harjit,

Thanks for sharing this helpful information. The approach described in the article works with GCC for Cortex-M. However, strictly speaking, current GCC does not support bit-band, due to issue in following.

When programing with bit-band, a location has two addresses. In the referenced example NewBBFlagBit1 and NewBBFlags point to same physical location. While from compiler's point of view, they have no overlap. With the assumption of not overlapping, compiler can transform program into instruction sequences breaking the expected program logic.

The following example code:

typedef enum {FALSE = 0, TRUE = !FALSE} bool;
typedef volatile unsigned int vu32;
bool NewBBFlagBit1 __attribute__ ((section ("bbalias")));
vu32 NewBBFlags __attribute__ ((section ("bbram")));

void testFunc2(bool check, bool a, bool b) {

 if (check) {
  if (NewBBFlags == 0) {
   NewBBFlags = b;
  }

 } else {
  NewBBFlagBit1 = 1; // Line 14
  if (NewBBFlags == 0) { // Line 15
   NewBBFlags = a;
  }
 }
}

can result in code sequence that NewBBFlags in line 15 is read before NewBBFlagBit1 in line 14 is written. This is because compiler thinks they are distinct non-overlapping memory accesses and reverts their instruction sequence. Declaring NewBBFlagBit1 as volatile will avoid reversing of memory address, though there is still no guarantee there is no other issue.

So my opinion is that current GCC doesn't have semantic to support bit-band. Though GCC can generate correct code for bit-band source confirming to either rules:
1. Don't mix bit access with its aliasing word access
2. Always be volatile access

Thanks,
Joey

Revision history for this message
Harjit Singh (zeetahhs) said :
#4

Joey, excellent point about two addresses pointing to the same location! Thank you for pointing that out.

I was thinking of using NewBBFlags to do the initialization and then use NewBBFlagBit1 in actual code but given this discussion will do the initialization differently.

Can you help with this problem?

Provide an answer of your own, or ask Uwe Bonnes for more information if necessary.

To post a message you must log in.