Sign in

username:

password:



Not a member?

Search c6x



Search tips

Subscribe to c6x



c6x by Keywords

AD535 | BIOS | Booting | Bootloader | C621 | C6211 | C6415 | C671 | C6711 | C6711DSK | C6713 | CCS | Chassaing | COFF | DAT | DM64 | DM642 | DMA | DSK671 | DSK6711 | EDM | EDMA | EMIF | Emulator | EVM | EVM620 | FFT | FIR | GPIO | Halting | HPI | HWI | IDK | JTAG | LDB | LDH | LDW | Linker | LMS | LOG_printf | Matlab | McBSP | MEM_alloc | MIPS | PCI | PCM3003 | Pipeline | Profiling | QDM | Reset | ROM | RTDX | Sampling | SDRAM | Stack | TEB | THS1206 | TMS320C621 | TMS320C6416 | TMS320C6711 | TMS320C6713 | UART | Vector Table | XBUS | XDS560


Discussion Groups

See Also

Embedded SystemsFPGAElectronics

Discussion Groups | TMS320C6x | Differences between _nassert() and DATA_MEM_BANK

Technical discussions about the TI C6000 DSPs (including the c62x, c64x and c67x DSPs).

  

Post a new Thread

Differences between _nassert() and DATA_MEM_BANK - Giovanni Parodi - Sep 20 6:47:00 2004

Hello everybody, I have a little problem understanding the way by which it's possible to use the instructions
#pragma DATA_MEM_BANK
and
_nassert
In effect in the examples pg_dotp_flt and pg_vecsum proposed by TI it seems that it's necessary to use _nassert with short int and int numbers and DATA_MEM_BANK with floating point number.
However, I don't understand that. The pragma instruction is relative to the preprocessor so when the compiler find that (and it find that before allocating the variables, that's true?), it take the trouble to allocate the variable in the correct way (aligned to memory).
However _nassert doesn't seem to be a preprocessor instruction (I think that all the "instruction" that start with # are of the preprocessor), and so I'm not able to understand how this instruction can say to the system "take the variable x and allocate it aligning to word boundary". It seems as this instruction say simply "this short variable is memory aligned", but how can be this always true?
What's the difference between DATA_MEM_BANK and _nassert?
Please help me, thanks a lot (and please sorry my English sometimes too similar to Italian language:-))


Scopri Mister Yahoo! - il fantatorneo sul calcio di Yahoo! Sport'


______________________________
Start your Android Ice Cream Sandwich development on TI's AM35x Sitara ARM Cortex-A8 processor today.



(You need to be a member of c6x -- send a blank email to c6x-subscribe@yahoogroups.com )

RE: Differences between _nassert() and DATA_MEM_BANK - Mody, Mihir - Sep 20 8:07:00 2004

Hi Parodi,
 
_nassert is preprocessor to pass information to compiler and it generates no code. It tells the compiler that the expression declared with the
assert function is true. This gives a hint to the compiler so that it can generate better code and schedule.
 
/* Example to  pass information that pointer *a is aligned to word boundary. This directive doesn't align pointer 'a' to word boundary, but gives promise to compiler that given pointer is aligned. With this assumption compiler goes ahead with aggressive optimization. During runtime if the assumption is false, then behaviour code is undefined */
_nassert(((int)(a) & 0x3) == 0);
 
/* Example to tell compiler that height and width in video picture is multiple of 8 */
_nassert((height% 8) == 0);
_nassert((width% 8) == 0);
 
/* Example to tell compiler that audio frame size is multiple of 1024 */
_nassert((framesize% 1024) == 0);
 
so on ......
 
In case of c6x, the memory consists of different banks. E.g. all addresses multiple of 8 forms bank 0.  addresss like 8* K +1 forms bank 1, so on.
The DATA_MEM_BANK pragma allows aligns data on any data memory bank that can hold data of the symbol's type size. Use of this directive make sure that data is aligned to particular bank during memory address resolution in link time. This is useful if you need to align data in a particular way to avoid memory bank conflicts in your hand-coded assembly code versus padding with zeros and having to account for the padding in your code.
#pragma DATA_MEM_BANK (x, 2);
short x[100];
#pragma DATA_MEM_BANK (z, 0);
#pragma DATA_SECTION (z, ".z_sect");
short z[100];
void main()
{
    #pragma DATA_MEM_BANK (y, 2);
    short y[100];
    ...
}
 
Regards,
Mihir

 

-----Original Message-----
From: Giovanni Parodi [mailto:g...@yahoo.it]
Sent: Monday, September 20, 2004 12:18 PM
To: c...@yahoogroups.com
Subject: [c6x] Differences between _nassert() and DATA_MEM_BANK

Hello everybody, I have a little problem understanding the way by which it's possible to use the instructions
#pragma DATA_MEM_BANK
and
_nassert
In effect in the examples pg_dotp_flt and pg_vecsum proposed by TI it seems that it's necessary to use _nassert with short int and int numbers and DATA_MEM_BANK with floating point number.
However, I don't understand that. The pragma instruction is relative to the preprocessor so when the compiler find that (and it find that before allocating the variables, that's true?), it take the trouble to allocate the variable in the correct way (aligned to memory).
However _nassert doesn't seem to be a preprocessor instruction (I think that all the "instruction" that start with # are of the preprocessor), and so I'm not able to understand how this instruction can say to the system "take the variable x and allocate it aligning to word boundary". It seems as this instruction say simply "this short variable is memory alig! ned", but how can be this always true?
What's the difference between DATA_MEM_BANK and _nassert?
Please help me, thanks a lot (and please sorry my English sometimes too similar to Italian language:-))


Scopri Mister Yahoo! - il fantatorneo sul calcio di Yahoo! Sport'

_____________________________________


______________________________
Start your Android Ice Cream Sandwich development on TI's AM35x Sitara ARM Cortex-A8 processor today.



(You need to be a member of c6x -- send a blank email to c6x-subscribe@yahoogroups.com )

RE: Differences between _nassert() and DATA_MEM_BANK - Bhooshan iyer - Sep 20 9:59:00 2004


Mihir-

>In case of c6x, the memory consists of different banks. E.g. all addresses
>multiple of 8 forms bank >0. addresss like 8* K +1 forms bank 1, so on.

Correct me if am wrong: You say C6x's memory consists of Bank Structure, but
i think it should read "C60x" device's memory consists of Bank Structure.

As far as i know C6211 and C6711 doesnt have Banked Memory Structure. I
think the L2 memory of C6211 and C6711 are Dual Access Memory, So doesnt
matter which banks the datas are in, you are still guarenteed two loads per
clock without any stalls.

But the 0x devices dont have Dual Access RAM's so if you want to achieve two
loads per clock, it is not guaranteed unless make sure those data points are
stored in two different banks.(The assumption is that you will always want
to do something like x[n]*y[n] in DSP and hence will need two data reads per
clock.Though you have two data units(D1&D2) it is still not guarenteed that
you can achieve two loads per clock but by making sure x is in a *different
bank* compared to y,you make two loads possible in a cycle in banked memory
structures like the one available in C6201)

So, in conclusion i dont think #pragma DATA_MEM_BANK is of any use to C6711
& C6211 variations but it is highly useful to C6201 and C6701 variations.

--Bhooshan

_________________________________________________________________
All the news that matters. All the gossip from home.
http://www.msn.co.in/NRI/ Specially for NRIs!


______________________________
Start your Android Ice Cream Sandwich development on TI's AM35x Sitara ARM Cortex-A8 processor today.



(You need to be a member of c6x -- send a blank email to c6x-subscribe@yahoogroups.com )

RE: Differences between _nassert() and DATA_MEM_BANK - Mody, Mihir - Sep 20 10:18:00 2004

Hi Bhoosan,

You are correct. The number of memory banks (4, 8 etc) and its existence depends
on particular device you are using. You may to refer particular device manual to
find out the details regarding this.

Regards,
Mihir Mody,
Multimedia codecs group,
Texas Instruments India, Ltd,
Email :
Phone : +91-80-25099307

-----Original Message-----
From: Bhooshan iyer [mailto:]
Sent: Monday, September 20, 2004 3:30 PM
To: Mody, Mihir; ;
Subject: RE: [c6x] Differences between _nassert() and DATA_MEM_BANK
Mihir-

>In case of c6x, the memory consists of different banks. E.g. all addresses
>multiple of 8 forms bank >0. addresss like 8* K +1 forms bank 1, so on.

Correct me if am wrong: You say C6x's memory consists of Bank Structure, but
i think it should read "C60x" device's memory consists of Bank Structure.

As far as i know C6211 and C6711 doesnt have Banked Memory Structure. I
think the L2 memory of C6211 and C6711 are Dual Access Memory, So doesnt
matter which banks the datas are in, you are still guarenteed two loads per
clock without any stalls.

But the 0x devices dont have Dual Access RAM's so if you want to achieve two
loads per clock, it is not guaranteed unless make sure those data points are
stored in two different banks.(The assumption is that you will always want
to do something like x[n]*y[n] in DSP and hence will need two data reads per
clock.Though you have two data units(D1&D2) it is still not guarenteed that
you can achieve two loads per clock but by making sure x is in a *different
bank* compared to y,you make two loads possible in a cycle in banked memory
structures like the one available in C6201)

So, in conclusion i dont think #pragma DATA_MEM_BANK is of any use to C6711
& C6211 variations but it is highly useful to C6201 and C6701 variations.

--Bhooshan

_________________________________________________________________
All the news that matters. All the gossip from home.
http://www.msn.co.in/NRI/ Specially for NRIs!







(You need to be a member of c6x -- send a blank email to c6x-subscribe@yahoogroups.com )

Re: Differences between _nassert() and DATA_MEM_BANK - Giovanni - Sep 21 6:07:00 2004

Hello to everybody. First of all, thanks a lot for your suggestions, but
I have another doubt;
I try to resume things that you said me:
_nassert is used to say to the compiler that the array is word aligned
but doesn't force the alignement of the array (so it's possible that
allocating that variable the compiler chose to place it unaligned)
DATA_MEM_BANK "order" to the compiler to word align the variable in a
prearranged BANK of memory.
If that's ok, I'm missing that: how is it possible to use _nassert
without DATA_MEM_BANK.
If I have a situation like this:

void main()
{
int x[4]={1,2,3,4};
func(x);
}

void func(int y)
{
int i=0;
_nassert(((int)(y)&0x3)==0)
for(i=0;i<4;i++)
y[i]=y[i]*y[i];
}

I think that I cannot be sure that the compiler allocate the variables
aligning them to word boundaries, so when I use func() function it's
possible that the variable y isn't word aligned and so the result of the
func() cannot be predetermined.
In effect may be I'm missing something: I have the following doubt: when
the linker runs, it always tries to word align the arrays? If the
response is yes I understand the use of _nassert ('cause if I use this
instruction with a array, I can be sure that the array will always be
aligned unless there's not enough space to word align it), but I don't
understand its usefulness, because I will always have a array word
aligned (if it's possible).
However, if the linker doesn't automatically word align variables, I
think that using _nassert without DATA_MEM_BANK (that said to align to a
specific memory bank) is a Russian roulette, but this approach is used
in the help files of Texas Instruments, so it's impossible that it's wrong.
May be that my questions are a bit stupid, sorry for that, and thanks to
everybody will help me.

Mody, Mihir wrote:

>Hi Bhoosan,
>
>You are correct. The number of memory banks (4, 8 etc) and its existence
depends on particular device you are using. You may to refer particular device
manual to find out the details regarding this.
>
>Regards,
>Mihir Mody,
>Multimedia codecs group,
>Texas Instruments India, Ltd,
>Email :
>Phone : +91-80-25099307
>
>-----Original Message-----
>From: Bhooshan iyer [mailto:]
>Sent: Monday, September 20, 2004 3:30 PM
>To: Mody, Mihir; ;
>Subject: RE: [c6x] Differences between _nassert() and DATA_MEM_BANK >
>Mihir- >
>>In case of c6x, the memory consists of different banks. E.g. all addresses
>>multiple of 8 forms bank >0. addresss like 8* K +1 forms bank 1, so on.
>>
>>
>
>Correct me if am wrong: You say C6x's memory consists of Bank Structure, but
>i think it should read "C60x" device's memory consists of Bank Structure.
>
>As far as i know C6211 and C6711 doesnt have Banked Memory Structure. I
>think the L2 memory of C6211 and C6711 are Dual Access Memory, So doesnt
>matter which banks the datas are in, you are still guarenteed two loads per
>clock without any stalls.
>
>But the 0x devices dont have Dual Access RAM's so if you want to achieve two
>loads per clock, it is not guaranteed unless make sure those data points are
>stored in two different banks.(The assumption is that you will always want
>to do something like x[n]*y[n] in DSP and hence will need two data reads per
>clock.Though you have two data units(D1&D2) it is still not guarenteed that
>you can achieve two loads per clock but by making sure x is in a *different
>bank* compared to y,you make two loads possible in a cycle in banked memory
>structures like the one available in C6201)
>
>So, in conclusion i dont think #pragma DATA_MEM_BANK is of any use to C6711
>& C6211 variations but it is highly useful to C6201 and C6701 variations.
>
>--Bhooshan
>
>_________________________________________________________________
>All the news that matters. All the gossip from home.
>http://www.msn.co.in/NRI/ Specially for NRIs! >
>
>_____________________________________ >Yahoo! Groups Links



______________________________
New Code Sharing Section now Live on DSPRelated.com. Learn about the Reward Program for Contributors here.



(You need to be a member of c6x -- send a blank email to c6x-subscribe@yahoogroups.com )

Re: Differences between _nassert() and DATA_MEM_BANK - Bhooshan iyer - Sep 21 12:44:00 2004

Giovanni-

>If that's ok, I'm missing that: how is it possible to use _nassert
>without DATA_MEM_BANK.

Well you can! As you just proved in your code!

_nassert in yr code is simply asserting(as the name implies) that the last
the two bits of the address is 00. Then it becomes re-assuring to the
compiler that the data is aligned on a 32 bit word boundary. Period. Nothing
else to really do with DATA_MEM_BANK pragma. It is the DATA_ALIGN pragma
that deals with *forcing* data alignment in C & .align directive in linear
asm/asm.
(For alignment related issues you really should be behind the DATA_ALIGN
pragma)

Also you need to look up the default aligment rules of the c compiler for
various data types-For EX: shorts are by default aligned to half-word
boundaries but arrays of shorts are always aligned to word boundaries, ints
are by default aligned to word boundaries...

So, there you go, in your code the data is(in all probability) already
naturally word aligned by the compiler and you are merely asserting that
fact to the compiler through the _nassert

Ps: if you _nassert the data is word aligned and then if the data is not
really aligned, then the behaviour of your program is undefined!

--Bhooshan

If I have a situation like this:

void main()
{
int x[4]={1,2,3,4};
func(x);
}

void func(int y)
{
int i=0;
_nassert(((int)(y)&0x3)==0)
for(i=0;i<4;i++)
y[i]=y[i]*y[i];
}

I think that I cannot be sure that the compiler allocate the variables
aligning them to word boundaries, so when I use func() function it's
possible that the variable y isn't word aligned and so the result of the
func() cannot be predetermined.
In effect may be I'm missing something: I have the following doubt: when
the linker runs, it always tries to word align the arrays? If the
response is yes I understand the use of _nassert ('cause if I use this
instruction with a array, I can be sure that the array will always be
aligned unless there's not enough space to word align it), but I don't
understand its usefulness, because I will always have a array word
aligned (if it's possible).
However, if the linker doesn't automatically word align variables, I
think that using _nassert without DATA_MEM_BANK (that said to align to a
specific memory bank) is a Russian roulette, but this approach is used
in the help files of Texas Instruments, so it's impossible that it's wrong.
May be that my questions are a bit stupid, sorry for that, and thanks to
everybody will help me.

Mody, Mihir wrote:

>Hi Bhoosan,
>
>You are correct. The number of memory banks (4, 8 etc) and its existence
depends on particular device you are using. You may to refer particular
device manual to find out the details regarding this.
>
>Regards,
>Mihir Mody,
>Multimedia codecs group,
>Texas Instruments India, Ltd,
>Email :
>Phone : +91-80-25099307
>
>-----Original Message-----
>From: Bhooshan iyer [mailto:]
>Sent: Monday, September 20, 2004 3:30 PM
>To: Mody, Mihir; ;
>Subject: RE: [c6x] Differences between _nassert() and DATA_MEM_BANK >
>Mihir- >
>>In case of c6x, the memory consists of different banks. E.g. all
addresses
>>multiple of 8 forms bank >0. addresss like 8* K +1 forms bank 1, so on.
>>
>>
>
>Correct me if am wrong: You say C6x's memory consists of Bank Structure,
but
>i think it should read "C60x" device's memory consists of Bank Structure.
>
>As far as i know C6211 and C6711 doesnt have Banked Memory Structure. I
>think the L2 memory of C6211 and C6711 are Dual Access Memory, So doesnt
>matter which banks the datas are in, you are still guarenteed two loads
per
>clock without any stalls.
>
>But the 0x devices dont have Dual Access RAM's so if you want to achieve
two
>loads per clock, it is not guaranteed unless make sure those data points
are
>stored in two different banks.(The assumption is that you will always want
>to do something like x[n]*y[n] in DSP and hence will need two data reads
per
>clock.Though you have two data units(D1&D2) it is still not guarenteed
that
>you can achieve two loads per clock but by making sure x is in a
*different
>bank* compared to y,you make two loads possible in a cycle in banked
memory
>structures like the one available in C6201)
>
>So, in conclusion i dont think #pragma DATA_MEM_BANK is of any use to
C6711
>& C6211 variations but it is highly useful to C6201 and C6701 variations.
>
>--Bhooshan
>
>_________________________________________________________________
>All the news that matters. All the gossip from home.
>http://www.msn.co.in/NRI/ Specially for NRIs! >
>
>_____________________________________ >Yahoo! Groups Links _____________________________________ Yahoo! Groups Links

_________________________________________________________________
1 Paisa No Reserve Auctions.
http://ads2.baazee.com/cgi-bin/banners/redirect.pl?id=2553 T-Shirts, Shirts,
Kurtas, Apparels.



______________________________
New Code Sharing Section now Live on DSPRelated.com. Learn about the Reward Program for Contributors here.



(You need to be a member of c6x -- send a blank email to c6x-subscribe@yahoogroups.com )

Re: Differences between _nassert() and DATA_MEM_BANK - Giovanni Parodi - Sep 22 7:04:00 2004

Hi, thanks a lot.
The last question... in the previous mail you said that DATA_MEM_BANK " allows aligns data on any data memory bank that can hold data of the symbol's type size ". This means  that a variable can be aligned to a data memory bank boundary without being word aligned? If so, how can I be sure that the a local variable is word aligned? In effect you said that that only with DATA_ALIGN I can force alignment But reading the CCS tutorial I found this phrase that seems contraddict your statement "Recall that earlier it was said arrays are aligned on double word boundaries by using either the DATA_ALIGN (for globally defined arrays) or DATA_MEM_BANK (for locally defined arrays) pragmas". May be I'm not able to understand the technical terms used on the tutorial but it seems that using DATA_MEM_BANK you are able to specify both the word alignment and the bank alignment, so the difference between the two different statemnt seems to be limited only by the type of object
that you use (global or locally defined).
So in my humble opininion it seems that using the pragma DATA_MEM_BANK and DATA_ALIGN you specify the alignment (to word and memory bank boundary) and using _nassert you declare that the routine can be compiled in a more efficient way.
However if I choose to not use the pragma I'm able to use _nassert but with some more risk... that's ok?
Can you confirm my interpration of the tutorial?
Thanks a lot
 

Bhooshan iyer <b...@hotmail.com> wrote:
Giovanni-

>If that's ok, I'm missing that: how is it possible to use _nassert
>without DATA_MEM_BANK.

Well you can! As you just proved in your code!

_nassert in yr code is simply asserting(as the name implies) that the last
the two bits of the address is 00. Then it becomes re-assuring to the
compiler that the data is aligned on a 32 bit word boundary. Period. Nothing
else to really do with DATA_MEM_BANK pragma. It is the DATA_ALIGN pragma
that deals with *forcing* data alignment in C & .align directive in linear
asm/asm.
(For alignment related issues you really should be behind the DATA_ALIGN
pragma)

Also you need to look up the default aligment rules of the c compiler for
various data types-For EX: shorts are by default aligned to half-word
boundaries but arrays of shorts are always aligned to word boundaries, ints
are by default aligned to word boundaries...

So, there you go, in your code the data is(in all probability) already
naturally word aligned by the compiler and you are merely asserting that
fact to the compiler through the _nassert

Ps: if you _nassert the data is word aligned and then if the data is not
really aligned, then the behaviour of your program is undefined!

--Bhooshan

If I have a situation like this:

void main()
{
int x[4]={1,2,3,4};
func(x);
}

void func(int y)
{
int i=0;
_nassert(((int)(y)&0x3)==0)
for(i=0;i<4;i++)
y[i]=y[i]*y[i];
}

I think that I cannot be sure that the compiler allocate the variables
aligning them to word boundaries, so when I use func() function it's
possible that the variable y isn't word aligned and so the result of the
func() cannot be predetermined.
In effect may be I'm missing something: I have the following doubt: when
the linker runs, it always tries to word align the arrays? If the
response is yes I understand the use of _nassert ('cause if I use this
instruction with a array, I can be sure that the array will always be
aligned unless there's not enough space to word align it), but I don't
understand its usefulness, because I will always have a array word
aligned (if it's possible).
However, if the linker doesn't automatically word align variables, I
think that using _nassert without DATA_MEM_BANK (that said to align to a
specific memory bank) is a Russian roulette, but this approach is used
in the help files of Texas Instruments, so it's impossible that it's wrong.
May be that my questions are a bit stupid, sorry for that, and thanks to
everybody will help me.

Mody, Mihir wrote:

>Hi Bhoosan,
>
>You are correct. The number of memory banks (4, 8 etc) and its existence
depends on particular device you are using. You may to refer particular
device manual to find out the details regarding this.
>
>Regards,
>Mihir Mody,
>Multimedia codecs group,
>Texas Instruments India, Ltd,
>Email : m...@ti.com
>Phone : +91-80-25099307
>
>-----Original Message-----
>From: Bhooshan iyer [mailto:b...@hotmail.com]
>Sent: Monday, September 20, 2004 3:30 PM
>To: Mody, Mihir; g...@yahoo.it; c...@yahoogroups.com
>Subject: RE: [c6x] Differences between _nassert() and DATA_MEM_BANK>
>Mihir->
>>In case of c6x, the memory consists of different banks. E.g. all
addresses
>>multiple of 8 forms bank >0. addresss like 8* K +1 forms bank 1, so on.
>>
>>
>
>Correct me if am wrong: You say C6x's memory consists of Bank Structure,
but
>i think it should read "C60x" device's memory consists of Bank Structure.
>
>As far as i know C6211 and C6711 doesnt have Banked Memory Structure. I
>think the L2 memory of C6211 and C6711 are Dual Access Memory, So doesnt
>matter which banks the datas are in, you are still guarenteed two loads
per
>clock without any stalls.
>
>But the 0x devices dont have Dual Access RAM's so if you want to achieve
two
>loads per clock, it is not guaranteed unless make sure those data points
are
>stored in two different banks.(The assumption is that you will always want
>to do something like x[n]*y[n] in DSP and hence will need two data reads
per
>clock.Though you have two data units(D1&D2) it is still not guarenteed
that
>you can achieve two loads per clock but by making sure x is in a
*different
>bank* compared to y,you make two loads possible in a cycle in banked
memory
>structures like the one available in C6201)
>
>So, in conclusion i dont think #pragma DATA_MEM_BANK is of any use to
C6711
>& C6211 variations but it is highly useful to C6201 and C6701 variations.
>
>--Bhooshan
>
>_________________________________________________________________
>All the news that matters. All the gossip from home.
>http://www.msn.co.in/NRI/ Specially for NRIs!>
>
>_____________________________________


Scopri Mister Yahoo! - il fantatorneo sul calcio di Yahoo! Sport'





(You need to be a member of c6x -- send a blank email to c6x-subscribe@yahoogroups.com )

Re: Differences between _nassert() and DATA_MEM_BANK - Bhooshan iyer - Sep 22 18:11:00 2004

Giovanni-

Ill hazard an explanation once more,(though not in brief!) and then
specifically answers your questions in the latter part.I hope this helps.

Default Alignment Rules:
-----------------------------------
(The compiler has default aligment rules which are pretty solid except in
cases of bytes and half words)

Short -> 16 bit boundaries(addresess ending with the last bit
as 0)
int -> 32 bit boundaries(addressess ending with the last
bit as 00)
Arrays(any type) -> (atleast) 32 bit boundaries

(There are many more such rules...look up the manuals and dont just read the
CCS help!)

Since you are talking about DATA_MEM_BANK you shd be talking about c620x or
c670x.

Banked Memory Structure of C6201
--------------------------------------------------
The C6201 has 64kb of internal data memory divided into two blocks of 32kb
each.The block-1 starts at 8000 0000h to 8000 7FFFh and block-2 8000 8000h
to 8000 FFFFh. Internally inside each block of memory there are four 4K
banks of half word memory banks -B0, B1,B2 and B3.

DATA_ALIGN
---------------------
The motivation behind using DATA_ALIGN pragma and then _nasserting is to
encourage the compiler to do packed data optimization on these memory
accesses (Load a word and extract the two half words instead of two load
half words).

Hence word aligned half word data's ,double word aligned word data's
etc...are faster to access via the c compiler.This is because the C compiler
might use LDW and LDDW in both the previous cases instead of two LDH and two
LDW's respectively

Usability: Will be usefull to every variable declared in C programs

DATA_MEM_BANK
-------------------------
The motivation behind DATA_MEM_BANK is to *enable* two loads every clock by
originally placing them in two two different(and appropriate) memory
banks(which may occassionally result in word alignment).

Doing so, would avoid any memroy related stalls and the associated penalties
when trying to do two loads per clock. So, the goal of the DATA_MEM_BANK is
not to align data.

Usability: Will be usefull ONLY to TWO objects which are accessed
simultaneously

Example
-------------
Now if you have two short arrays X[] and y[] in C , where:

#pragma DATA_MEM_BANK (X, 0);
#pragma DATA_MEM_BANK (Y, 0);

Then it is possible-
short X[]---->placed at 8000,0000
short Y[]---->placed at 8000,0008

Now you *cant* expect the compiler to produce code that will load *both*
x[i] and y[i] *every clock*.

Notice that both arrays are word aligned but not appropriately bank aligned.
ie they shd be in different banks, not in *ANY* different banks but should
have been in bank-0 and bank-2 of block-1 or one in block-1(as permitted by
the default alignment rules) and the other in block-2.

So, in conclusion id say ALIGNMENT(not necessarily word alignment) of
objects has some implications on its bankability.

1] It's illegal to bank a word data to bank 1 or bank 3 of block-1 and so
on...
2] it's bad programming to bank two word aligned data's to the same bank if
they are involved in a convolution type of situation

And finally its plain stupidity to rely on the compiler to bank
appropriately, though it may incidentally do it quite a number of times!

Answers to ur questions
----------------------------------

>The last question... in the previous mail you said that DATA_MEM_BANK "
>allows aligns data on any >data memory bank that can hold data of the
>symbol's type size ".

Thats right. You cannot bank an int or a double data to the 1st or 3rd
banks,it breaks the default alignment rules.

For ex:

You *cannot* do this:

#pragma DATA_MEM_BANK (z, 3); //Banks 0->1 and Banks 2->3 forms a 32-bit
address
int z; //Equivalent to trying to allocate a 32 bit value starting at
80000006

You *can* do this:

#pragma DATA_MEM_BANK (z, 0);//starting at address 80000000
or
#pragma DATA_MEM_BANK (z, 2);//starting at address 80000004

>This means that a variable can >be aligned to a data memory bank boundary
>without being word >aligned?

If you are talking about a short the answer is yes.If you are talking about
int,float and double the answer is no.

>If so, how can I be sure that the a local variable is word aligned?

As i said it depends on the data type, if the local variable is an int it
WILL be atleast word aligned.

Aside:By the way why are you so stuck up about *word* alignment rather than
alignment itself? I think u need to understand what is alignment first.

>In effect you said that that only with DATA_ALIGN I can force alignment But
>reading the CCS >tutorial I found this phrase that seems contraddict your
>statement "Recall that earlier it was said >arrays are aligned on double
>word boundaries by using either the DATA_ALIGN (for globally >defined
>arrays) or DATA_MEM_BANK (for locally defined arrays) pragmas".

Well how do i answer this? Mmmm...Neither all Banked data's are word aligned
data's and nor are all word aligned data's appropriately banked (read in two
different banks) datas... does that make sense?

>but it seems that using DATA_MEM_BANK you are able to specify both the word
>alignment and >the bank alignment

Not all times. For ex:
#pragma DATA_MEM_BANK (x,0)
#pragma DATA_MEM_BANK (y,1);
short x;
short y;

Here 'x' is word aligned(implicitly by DATA_MEM_BANK) wheras 'y' is'nt!

But I can force 'y' to be word aligned by using DATA_ALIGN(y,4) or
alternatively by using DATA_MEM_BANK(y,2) but the latter is not the
appropriate way to do it, atleast it seems so to me!

>so the difference between the two different statemnt seems to be limited
>only by the type of >object that you use (global or locally defined).

As far as i know there are no local/global issues here...

>However if I choose to not use the pragma I'm able to use _nassert but with
>some more risk... >that's ok?

You risk undefined behavior on shorts and bytes

>Can you confirm my interpration of the tutorial?

I tried my best! But Something tells me i dint convince you! :)

Was there a better a way to phrase all this, anybody?

--Bhooshan.N.Iyer Bhooshan iyer <> wrote:
Giovanni-

>If that's ok, I'm missing that: how is it possible to use _nassert
>without DATA_MEM_BANK.

Well you can! As you just proved in your code!

_nassert in yr code is simply asserting(as the name implies) that the last
the two bits of the address is 00. Then it becomes re-assuring to the
compiler that the data is aligned on a 32 bit word boundary. Period. Nothing
else to really do with DATA_MEM_BANK pragma. It is the DATA_ALIGN pragma
that deals with *forcing* data alignment in C & .align directive in linear
asm/asm.
(For alignment related issues you really should be behind the DATA_ALIGN
pragma)

Also you need to look up the default aligment rules of the c compiler for
various data types-For EX: shorts are by default aligned to half-word
boundaries but arrays of shorts are always aligned to word boundaries, ints
are by default aligned to word boundaries...

So, there you go, in your code the data is(in all probability) already
naturally word aligned by the compiler and you are merely asserting that
fact to the compiler through the _nassert

Ps: if you _nassert the data is word aligned and then if the data is not
really aligned, then the behaviour of your program is undefined!

--Bhooshan

-------------------------------------------------------------------------------- \
----------------------------------------------------------

If I have a situation like this:

void main()
{
int x[4]={1,2,3,4};
func(x);
}

void func(int y)
{
int i=0;
_nassert(((int)(y)&0x3)==0)
for(i=0;i<4;i++)
y[i]=y[i]*y[i];
}

I think that I cannot be sure that the compiler allocate the variables
aligning them to word boundaries, so when I use func() function it's
possible that the variable y isn't word aligned and so the result of the
func() cannot be predetermined.
In effect may be I'm missing something: I have the following doubt: when
the linker runs, it always tries to word align the arrays? If the
response is yes I understand the use of _nassert ('cause if I use this
instruction with a array, I can be sure that the array will always be
aligned unless there's not enough space to word align it), but I don't
understand its usefulness, because I will always have a array word
aligned (if it's possible).
However, if the linker doesn't automatically word align variables, I
think that using _nassert without DATA_MEM_BANK (that said to align to a
specific memory bank) is a Russian roulette, but this approach is used
in the help files of Texas Instruments, so it's impossible that it's wrong.
May be that my questions are a bit stupid, sorry for that, and thanks to
everybody will help me.

Mody, Mihir wrote:

>Hi Bhoosan,
>
>You are correct. The number of memory banks (4, 8 etc) and its existence
depends on particular device you are using. You may to refer particular
device manual to find out the details regarding this.
>
>Regards,
>Mihir Mody,
>Multimedia codecs group,
>Texas Instruments India, Ltd,
>Email :
>Phone : +91-80-25099307
>
>-----Original Message-----
>From: Bhooshan iyer [mailto:]
>Sent: Monday, September 20, 2004 3:30 PM
>To: Mody, Mihir; ;
>Subject: RE: [c6x] Differences between _nassert() and DATA_MEM_BANK >
>Mihir- >
>>In case of c6x, the memory consists of different banks. E.g. all
addresses
>>multiple of 8 forms bank >0. addresss like 8* K +1 forms bank 1, so on.
>>
>>
>
>Correct me if am wrong: You say C6x's memory consists of Bank Structure,
but
>i think it should read "C60x" device's memory consists of Bank Structure.
>
>As far as i know C6211 and C6711 doesnt have Banked Memory Structure. I
>think the L2 memory of C6211 and C6711 are Dual Access Memory, So doesnt
>matter which banks the datas are in, you are still guarenteed two loads
per
>clock without any stalls.
>
>But the 0x devices dont have Dual Access RAM's so if you want to achieve
two
>loads per clock, it is not guaranteed unless make sure those data points
are
>stored in two different banks.(The assumption is that you will always want
>to do something like x[n]*y[n] in DSP and hence will need two data reads
per
>clock.Though you have two data units(D1&D2) it is still not guarenteed
that
>you can achieve two loads per clock but by making sure x is in a
*different
>bank* compared to y,you make two loads possible in a cycle in banked
memory
>structures like the one available in C6201)
>
>So, in conclusion i dont think #pragma DATA_MEM_BANK is of any use to
C6711
>& C6211 variations but it is highly useful to C6201 and C6701 variations.
>
>--Bhooshan

_________________________________________________________________
Search for your life partner made easy.
http://www.bharatmatrimony.com/cgi-bin/bmclicks1.cgi?74 On
BharatMatrimony.com



______________________________
Start your Android Ice Cream Sandwich development on TI's AM35x Sitara ARM Cortex-A8 processor today.



(You need to be a member of c6x -- send a blank email to c6x-subscribe@yahoogroups.com )

Re: Differences between _nassert() and DATA_MEM_BANK - Giovanni - Sep 23 12:18:00 2004

Thanks a lot your explanation was fantastic, my doubts now have been
destroyed :-)
Giovanni

Bhooshan iyer wrote:

> Giovanni-
>
> Ill hazard an explanation once more,(though not in brief!) and then
> specifically answers your questions in the latter part.I hope this helps.
>
> Default Alignment Rules:
> -----------------------------------
> (The compiler has default aligment rules which are pretty solid except
> in cases of bytes and half words)
>
> Short -> 16 bit boundaries(addresess ending with the
> last bit as 0)
> int -> 32 bit boundaries(addressess ending with the
> last bit as 00)
> Arrays(any type) -> (atleast) 32 bit boundaries
>
> (There are many more such rules...look up the manuals and dont just
> read the CCS help!)
>
> Since you are talking about DATA_MEM_BANK you shd be talking about
> c620x or c670x.
>
> Banked Memory Structure of C6201
> --------------------------------------------------
> The C6201 has 64kb of internal data memory divided into two blocks of
> 32kb each.The block-1 starts at 8000 0000h to 8000 7FFFh and block-2
> 8000 8000h to 8000 FFFFh. Internally inside each block of memory there
> are four 4K banks of half word memory banks -B0, B1,B2 and B3.
>
> DATA_ALIGN
> ---------------------
> The motivation behind using DATA_ALIGN pragma and then _nasserting is
> to encourage the compiler to do packed data optimization on these
> memory accesses (Load a word and extract the two half words instead of
> two load half words).
>
> Hence word aligned half word data's ,double word aligned word data's
> etc...are faster to access via the c compiler.This is because the C
> compiler might use LDW and LDDW in both the previous cases instead of
> two LDH and two LDW's respectively
>
> Usability: Will be usefull to every variable declared in C programs
>
> DATA_MEM_BANK
> -------------------------
> The motivation behind DATA_MEM_BANK is to *enable* two loads every
> clock by originally placing them in two two different(and
> appropriate) memory banks(which may occassionally result in word
> alignment).
>
> Doing so, would avoid any memroy related stalls and the associated
> penalties when trying to do two loads per clock. So, the goal of the
> DATA_MEM_BANK is not to align data.
>
> Usability: Will be usefull ONLY to TWO objects which are accessed
> simultaneously
>
> Example
> -------------
> Now if you have two short arrays X[] and y[] in C , where:
>
> #pragma DATA_MEM_BANK (X, 0);
> #pragma DATA_MEM_BANK (Y, 0);
>
> Then it is possible-
> short X[]---->placed at 8000,0000
> short Y[]---->placed at 8000,0008
>
> Now you *cant* expect the compiler to produce code that will load
> *both* x[i] and y[i] *every clock*.
>
> Notice that both arrays are word aligned but not appropriately bank
> aligned. ie they shd be in different banks, not in *ANY* different
> banks but should have been in bank-0 and bank-2 of block-1 or one in
> block-1(as permitted by the default alignment rules) and the other in
> block-2.
>
> So, in conclusion id say ALIGNMENT(not necessarily word alignment) of
> objects has some implications on its bankability.
>
> 1] It's illegal to bank a word data to bank 1 or bank 3 of block-1 and
> so on...
> 2] it's bad programming to bank two word aligned data's to the same
> bank if they are involved in a convolution type of situation
>
> And finally its plain stupidity to rely on the compiler to bank
> appropriately, though it may incidentally do it quite a number of times!
>
> Answers to ur questions
> ----------------------------------
>
>> The last question... in the previous mail you said that DATA_MEM_BANK
>> " allows aligns data on any >data memory bank that can hold data of
>> the symbol's type size ". > Thats right. You cannot bank an int or a double data to the 1st or 3rd
> banks,it breaks the default alignment rules.
>
> For ex:
>
> You *cannot* do this:
>
> #pragma DATA_MEM_BANK (z, 3); //Banks 0->1 and Banks 2->3 forms a
> 32-bit address
> int z; //Equivalent to trying to allocate a 32 bit value starting at
> 80000006
>
> You *can* do this:
>
> #pragma DATA_MEM_BANK (z, 0);//starting at address 80000000
> or
> #pragma DATA_MEM_BANK (z, 2);//starting at address 80000004
>
>> This means that a variable can >be aligned to a data memory bank
>> boundary without being word >aligned? > If you are talking about a short the answer is yes.If you are talking
> about int,float and double the answer is no.
>
>> If so, how can I be sure that the a local variable is word aligned? > As i said it depends on the data type, if the local variable is an int
> it WILL be atleast word aligned.
>
> Aside:By the way why are you so stuck up about *word* alignment rather
> than alignment itself? I think u need to understand what is alignment
> first.
>
>> In effect you said that that only with DATA_ALIGN I can force
>> alignment But reading the CCS >tutorial I found this phrase that
>> seems contraddict your statement "Recall that earlier it was said
>> >arrays are aligned on double word boundaries by using either the
>> DATA_ALIGN (for globally >defined arrays) or DATA_MEM_BANK (for
>> locally defined arrays) pragmas". > Well how do i answer this? Mmmm...Neither all Banked data's are word
> aligned data's and nor are all word aligned data's appropriately
> banked (read in two different banks) datas... does that make sense?
>
>> but it seems that using DATA_MEM_BANK you are able to specify both
>> the word alignment and >the bank alignment > Not all times. For ex:
> #pragma DATA_MEM_BANK (x,0)
> #pragma DATA_MEM_BANK (y,1);
> short x;
> short y;
>
> Here 'x' is word aligned(implicitly by DATA_MEM_BANK) wheras 'y' is'nt!
>
> But I can force 'y' to be word aligned by using DATA_ALIGN(y,4) or
> alternatively by using DATA_MEM_BANK(y,2) but the latter is not the
> appropriate way to do it, atleast it seems so to me!
>
>> so the difference between the two different statemnt seems to be
>> limited only by the type of >object that you use (global or locally
>> defined). > As far as i know there are no local/global issues here...
>
>> However if I choose to not use the pragma I'm able to use _nassert
>> but with some more risk... >that's ok? > You risk undefined behavior on shorts and bytes
>
>> Can you confirm my interpration of the tutorial? > I tried my best! But Something tells me i dint convince you! :)
>
> Was there a better a way to phrase all this, anybody?
>
> --Bhooshan.N.Iyer > Bhooshan iyer <> wrote:
> Giovanni-
>
> >If that's ok, I'm missing that: how is it possible to use _nassert
> >without DATA_MEM_BANK.
>
> Well you can! As you just proved in your code!
>
> _nassert in yr code is simply asserting(as the name implies) that the
> last
> the two bits of the address is 00. Then it becomes re-assuring to the
> compiler that the data is aligned on a 32 bit word boundary. Period.
> Nothing
> else to really do with DATA_MEM_BANK pragma. It is the DATA_ALIGN pragma
> that deals with *forcing* data alignment in C & .align directive in
> linear
> asm/asm.
> (For alignment related issues you really should be behind the DATA_ALIGN
> pragma)
>
> Also you need to look up the default aligment rules of the c compiler for
> various data types-For EX: shorts are by default aligned to half-word
> boundaries but arrays of shorts are always aligned to word boundaries,
> ints
> are by default aligned to word boundaries...
>
> So, there you go, in your code the data is(in all probability) already
> naturally word aligned by the compiler and you are merely asserting that
> fact to the compiler through the _nassert
>
> Ps: if you _nassert the data is word aligned and then if the data is not
> really aligned, then the behaviour of your program is undefined!
>
> --Bhooshan -------------------------------------------------------------------------------- \
---------------------------------------------------------- > If I have a situation like this:
>
> void main()
> {
> int x[4]={1,2,3,4};
> func(x);
> }
>
> void func(int y)
> {
> int i=0;
> _nassert(((int)(y)&0x3)==0)
> for(i=0;i<4;i++)
> y[i]=y[i]*y[i];
> }
>
> I think that I cannot be sure that the compiler allocate the variables
> aligning them to word boundaries, so when I use func() function it's
> possible that the variable y isn't word aligned and so the result of the
> func() cannot be predetermined.
> In effect may be I'm missing something: I have the following doubt: when
> the linker runs, it always tries to word align the arrays? If the
> response is yes I understand the use of _nassert ('cause if I use this
> instruction with a array, I can be sure that the array will always be
> aligned unless there's not enough space to word align it), but I don't
> understand its usefulness, because I will always have a array word
> aligned (if it's possible).
> However, if the linker doesn't automatically word align variables, I
> think that using _nassert without DATA_MEM_BANK (that said to align to a
> specific memory bank) is a Russian roulette, but this approach is used
> in the help files of Texas Instruments, so it's impossible that it's
> wrong.
> May be that my questions are a bit stupid, sorry for that, and thanks to
> everybody will help me.
>
> Mody, Mihir wrote:
>
> >Hi Bhoosan,
> >
> >You are correct. The number of memory banks (4, 8 etc) and its existence
> depends on particular device you are using. You may to refer particular
> device manual to find out the details regarding this.
> >
> >Regards,
> >Mihir Mody,
> >Multimedia codecs group,
> >Texas Instruments India, Ltd,
> >Email :
> >Phone : +91-80-25099307
> >
> >-----Original Message-----
> >From: Bhooshan iyer [mailto:]
> >Sent: Monday, September 20, 2004 3:30 PM
> >To: Mody, Mihir; ;
> >Subject: RE: [c6x] Differences between _nassert() and DATA_MEM_BANK
> >
> >
> >
> >Mihir-
> >
> >
> >
> >>In case of c6x, the memory consists of different banks. E.g. all
> addresses
> >>multiple of 8 forms bank >0. addresss like 8* K +1 forms bank 1, so on.
> >>
> >>
> >
> >Correct me if am wrong: You say C6x's memory consists of Bank Structure,
> but
> >i think it should read "C60x" device's memory consists of Bank
> Structure.
> >
> >As far as i know C6211 and C6711 doesnt have Banked Memory Structure. I
> >think the L2 memory of C6211 and C6711 are Dual Access Memory, So doesnt
> >matter which banks the datas are in, you are still guarenteed two loads
> per
> >clock without any stalls.
> >
> >But the 0x devices dont have Dual Access RAM's so if you want to achieve
> two
> >loads per clock, it is not guaranteed unless make sure those data points
> are
> >stored in two different banks.(The assumption is that you will always
> want
> >to do something like x[n]*y[n] in DSP and hence will need two data reads
> per
> >clock.Though you have two data units(D1&D2) it is still not guarenteed
> that
> >you can achieve two loads per clock but by making sure x is in a
> *different
> >bank* compared to y,you make two loads possible in a cycle in banked
> memory
> >structures like the one available in C6201)
> >
> >So, in conclusion i dont think #pragma DATA_MEM_BANK is of any use to
> C6711
> >& C6211 variations but it is highly useful to C6201 and C6701
> variations.
> >
> >--Bhooshan
>
> _________________________________________________________________
> Search for your life partner made easy.
> http://www.bharatmatrimony.com/cgi-bin/bmclicks1.cgi?74 On
> BharatMatrimony.com


______________________________
New Code Sharing Section now Live on DSPRelated.com. Learn about the Reward Program for Contributors here.



(You need to be a member of c6x -- send a blank email to c6x-subscribe@yahoogroups.com )