Byte Packing in DSP BIOS

Hi,

I want to know if there is any utility in DSP BIOS for byte packing like "__attribute__((packed))" in linux. Plz let me know if there's any.

Thanks and regards, Nagendran V

Reply to
nagendran.v
Loading thread data ...

On 17 May 2005 00:59:54 -0700, " snipped-for-privacy@gmail.com" wrote in comp.arch.embedded:

Which TI DSP? Some of them don't have 8-bit bytes, all memory and registers are 16-bit wide. And a lot of them require that 32-bit values start on an even address.

That means a lot of them literally can't support packed structures, because they literally won't address the memory correctly.

What DSP, and what is the reason you think you need to pack structures?

--
Jack Klein
Home: http://JK-Technology.Com
 Click to see the full signature
Reply to
Jack Klein

It certainly would be possible for a compiler to generate correct code, but it would be quite nasty :-).

Assuming you want to update a byte in a packed structure:

- load memory word into register

- make a copy into other register

- shift the byte to the low end of the register

- mask away the bits above the wanted byte

- perform all the operations you want on the byte

- shift the byte back to the original bit position

- mask (make a "hole") in the original register for the byte

- combined the modified byte with the original register by ORing

- store the combination back to memory as a full 32 bit value

If you have a 16 bit integer crossing the memory word boundary, you would need to execute the above algorithm twice, once for the lower memory and once for the upper memory word and need four registers totally. For the memory word that contains the MSB of the desired integer, the byte value is not shifted down to the LSB position of the register but 8 positions to the left of LSB, so that it can be ORed with the LSB in an other register and after manipulation split the integer into these two registers and combining with the unmodified part of each memory word and write back both memory words.

Certainly, the compiler could generate this code each time a byte or unaligned integer is accessed, but it would generate quite a lot of code for each memory reference.

The only reason I can think of is handling a packed struct received from an other system or creating a packed struct going to some external system and that structure has been predefined e.g. in a standard.

So in practice, it makes much more sense to define an unpacked structure similar to the packed received frame and as the first step after receiving the packed frame copy each field into the unpacked internal structure. Just load each memory word of the packed structure into a register and by shifting and masking extract each field and store result into the unpacked structure fields.

Paul

Reply to
Paul Keinanen

Un bel giorno snipped-for-privacy@gmail.com digitò:

Sadly, no (at least not in CCS 2.x compiler, I haven't seen 3.x yet).

--
asd
Reply to
dalai lamah

__attribute__((packed)) is not a utility, it's a feature of a utility. And it's not in Linux, it's in the usual Linux system compiler, GCC.

--
Hans-Bernhard Broeker (broeker@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.
Reply to
Hans-Bernhard Broeker

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.