How to apply the same effect of #pragma pack(1) to TriCore 6.3r2v or newer versions

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
mshebl_98
Level 1
Level 1
First question asked Welcome!

Hello, 

I'm trying to see if I can allocate a struct with members which are bif-field assigned in 1 byte boundary using something similar to #pragma pack(1) but I can't find something in the compiler directives to help me in doing so.

 

TLDR: I want to have the same functionality of #pragma pack(1)

 

Thank you 😄

0 Likes
1 Solution
User13836
Level 6
Level 6
50 likes received 50 solutions authored 100 sign-ins

Since TASKING TriCore v6.3r1 new alignment related keywords have been introduced. You can have a look at chapter:

1.1.4. Changing the Alignment: __unaligned, __packed__ and __align()

of the TASKING TriCore tools user guide. This permits to locate struct members on a byte boundary since the compiler will always issue byte access instructions and those are not affected by TriCore CPU alignment restrictions like word acceses which require an even address.

But keep in mind that you pay a high performance loss and codesize increase price if you use packed. E.g. to access an int type variable or struct member of a packed data type, the compiler will emit four byte access instructions instead of using one word access instruction which is possible if alignment requirements are fulfilled.

 

The appnote

Alignment requirements - restrictions for the TriCore architeture

available at: 

https://resources.tasking.com/tasking-whitepapers/alignment-requirements-restrictions-for-the-tricor...

might be helpful too.

Best regards,

Ulrich Kloidt
TASKING tools support

 

View solution in original post

0 Likes
2 Replies
Anupama_A
Moderator
Moderator
Moderator
50 solutions authored 10 likes received 250 sign-ins

Hi @User13836 ,

 

Could you please help here?

 

Best regards, 
Anupama. 

0 Likes
User13836
Level 6
Level 6
50 likes received 50 solutions authored 100 sign-ins

Since TASKING TriCore v6.3r1 new alignment related keywords have been introduced. You can have a look at chapter:

1.1.4. Changing the Alignment: __unaligned, __packed__ and __align()

of the TASKING TriCore tools user guide. This permits to locate struct members on a byte boundary since the compiler will always issue byte access instructions and those are not affected by TriCore CPU alignment restrictions like word acceses which require an even address.

But keep in mind that you pay a high performance loss and codesize increase price if you use packed. E.g. to access an int type variable or struct member of a packed data type, the compiler will emit four byte access instructions instead of using one word access instruction which is possible if alignment requirements are fulfilled.

 

The appnote

Alignment requirements - restrictions for the TriCore architeture

available at: 

https://resources.tasking.com/tasking-whitepapers/alignment-requirements-restrictions-for-the-tricor...

might be helpful too.

Best regards,

Ulrich Kloidt
TASKING tools support

 

0 Likes