转载自http://blog.sina.com.cn/s/blog_48b82df90100brke.html
**** TypeWritter: Li Hui
*** Start Time: Nov.19.2008
*** Version 1.3
**
** use word to instead 2 * 16bit short data's access **
void vecsum4(short *restrict sum, restrict short *in1, restrict short *in2, unsigned int N)
{
int i;
#pragma MUST_ITERATE(10);
for(i=0;i<(N/2);i++)
_amem4(&sum[i]) = add2(_amem4_const(&in1[i]),_amem4_const(&in2[i]));
}
** near variable's access **
LDW *dp(_address),a1
** far variables' access **
MVKL _address,a1
MVKH _address,a1
LDW *a1,a0
** far function call **
MVKL _func,a1
MVKH _func,a1
B a1
** default is near type **
** if you use -mr1 option, all the func are 'far'
if you don't use -mr1, default is 'near'
if you use -mr0, then all the array or matrix are 'far', program is 'near'
if you use -mr1, then all the array or matrix are 'near', program is 'far'
if you use -mr2, then all the array, matrix, program are 'far'
if you use -mr3, then all data and program are 'far'
**
** not-related **
void foo(int * restrict a, int * restrict b)
void foo(int c[restrict], int d[restrict])
** difference of const-pointer and point to const**
int * const p = &x; ** a const pointer who point to a variable named x **
const int * p = &x; ** a pointer who point to a const named x, the pointer can point another variable **
** volatile - to guarantee a variable can not be optimized by optimizer **
unsigned int *ctrl;
while(*ctrl !=0xFF)
...
** optimizer will treat ctrl a const **
** so we should specify the ctrl's type is 'volatile' **
volatile unsigned int * ctrl;
** That's ok **
** Embedded the assembly language into the .C file **
asm(" Assembly Language... ");
** Useful Pragma Directive **
** (1) CODE_SECTION **
** Allocate space for symbol in the section named "section name" **
#pragma CODE_SECTION(symbol,"section name"); // in C language
** (2) DATA_ALIGN **
** align symbol to the column edge specfied by the constant **
#pragma DATA_ALIGN(symbol,constant); // constant must be power of 2
eg1:
#pragma DATA_ALIGN(inputArray,8);// when you use DSPLIB FFT functions
** (3) DATA_MEM_BANK **
** align the symbol and variables to the page edge specified by the constant **
** avoid the data's overlapped storage **
#pragma DATA_MEM_BANK(symbol,constant); ** C64 : constant must be 0-15 and must be even **
** (4) DATA_SECTION **
** Allocate space for symbol in the section named "section name" **
** 4-1 C Language **
#pragma DATA_SECTION(symbol,"section name");
** 4-2 C++ Language **
#pragma DATA_SECTION("section name");
** 4-3 Assembly Language **
.global _bufferA
.bss _bufferA,512,4
.global _bufferB
_bufferB .usect "section name",512,4
** (5) FUNC_CANNOT_INLINE **
** this function can not be inline, even the function is defined 'inline' **
#pragma FUNC_CANNOT_INLINE(func);
** (6) FUNC_EXT_CALLED **
** if you add -pm options in the compile period, the compiler will erase the function which haven't been
called by main, but acturally, the function may be called by .asm file. **
#pragma FUNC_EXT_CALLED(func);
** restriction: func can not be _c_int00 **
** (7) FUNC_INTERRUPT_THRESHOLD **
#pragma FUNC_INTERRUPT_THRESHOLD(func,threshold);
eg1:
#pragma FUNC_INTERRUPT_THRESHOLD(func1,2000);
** the period between the func1's interrupts must lager than 2000 clock cycle **
eg2:
#pragma FUNC_INTERRUPT_THRESHOLD(func2,1);
** the func2 can always be interrupted **
eg3:
#pragma FUNC_INTERRUPT_THRESHOLD(func3,-1);
** the func2 can not be interrupted **
** (8) FUNC_IS_PURE **
** This function has no side-effect, if you do not need the value returned by func, you can delete its' call
you can delete the copy of the func**
#pragma FUNC_IS_PURE(func);
** (9) FUNC_IS_SYSTEM **
** this function has the ANSI standard operation, the directive must be used for ANSI standard function **
** for example: memcpy, strcmp and so on **
#pragma FUNC_IS_SYSTEM(func);
** (10) FUNC_NEVER_RETURNS **
** this function never returns, so compiler can not terminate this function or free stack and so on **
#pragma FUNC_NEVER_RETURNS(func);
** (11) FUNC_NO_GLOBAL_ASG **
** this function will not assign global variables and not contains .asm sentences **
#pragma FUNC_NO_GLOBAL_ASG(func);
** (12) FUNC_NO_IND_ASG **
** this function will not allocate space via pointer and not contains .asm sentences **
#pragma FUNC_NO_IND_ASG(func);
** (13) INTERRUPT **
** you can use the function to handle the DSP's interrupt **
#pragma INTERRUPT(func);
** (14) MUST_ITERATE **
** Specify the cycle's minimum times, maximun times and the times must be multiple of 'multiple' **
#pragma MUST_ITERATE(min,max,multiple);
** (15) NMI_INTERRUPT **
** you can use the function to handle the Non Maskable Interrupt(NMI) **
#pragma NMI_INTERRUPT(func);
** (16) PROB_ITERATE **
** Specify the cycle's minimum times, maximun times **
#pragma PROB_ITERATE(min,max);
** (17) STRUCT_ALIGN **
** Like to DATA_ALIGN, using for defination of struct and class **
#pragma STRUCT_ALIGN(type,constact expression);
eg:
typedef strct st_tag
{
int a;
short b;
}st_typedef;
#pragma STRUCT_ALIGN(st_tag,128);
** (18) UNROLL **
** Specify which number of cycle times can not be unfolded **
#pragma UNROLL(n);
-----------------------------------------------------------
** 是注释 如果用“/ * ...... * /”的话,新浪会自动删除注释!