Technical discussions about the TI C6000 DSPs (including the c62x, c64x and c67x DSPs).
|
Hi all,
I have a C function which needs to be re-written in Linear Assembly. My problem goes as follows: 1. How do I access a 2-dimensional array in linear assembly? For example, if i have an 2-d array : array_table1[2][3]. how do I access array element array_table[1][1]? I am currently using Code Composer Studio V2.0. TIA. regards, chuan foong, chong |
|
|
|
Chong, The first step should always be to re-write in optimized C. Have you tried that yet ? What is it that the C compiler fails to optimize ? You can easily get the C compiler to use LDDWs, so in general you can get very close to linear assembler performance just by re-writing the C code. Andrew E At 10:09 AM 11/7/01 +0800, Chong Chuan Foong wrote: >Hi all, > I have a C function which needs to be re-written in Linear Assembly. > > My problem goes as follows: > 1. How do I access a 2-dimensional array in linear assembly? For example, >if i have an 2-d array : array_table1[2][3]. > how do I access array element array_table[1][1]? > > I am currently using Code Composer Studio V2.0. > > TIA. > >regards, >chuan foong, chong > >_____________________________________ |
|
> Date: Wed, 7 Nov 2001 10:09:56 +0800 > From: "Chong Chuan Foong" <> > Subject: accessing 2-d array element in linear assembly > > I have a C function which needs to be re-written in Linear Assembly. > > My problem goes as follows: > 1. How do I access a 2-dimensional array in linear assembly? For example, > if i have an 2-d array : array_table1[2][3]. > how do I access array element array_table[1][1]? Generally there are two ways, absolutely similar in either C, linear assembly or assembly, to access an entry in multidimensional array. Both way depend on how an array has been defined: float table1[2][3]; // defines a single pointer // or float *(table2[2]); // defines an array of two poiters to float or float **table3; // equivalently, defines a pointer to a pointer to a // a float in the first case table1[1][1] is *(table1+3*1+1) or generally table1[i][k] is *(table1+num_of_cols*i+k) in the second case table2[1][1] is *(*(table2+1)+1) table3[1][1] is *(*(table3+1)+1) or generally table2[i][k] is *(*(table2+i)+k), so as table3[i][k] In linear assembly this would be coded as (far data model): CASE1: MVKL _table1, ptr_table1 MVKH _table1, prt_table1 ; points to table1[0][0] ADDAW ptr_table1, 4, ptr_table1 ; points to table1[1][1] LDW *ptr_table1, table1_11 ; load table1[1][1] CASE2: MVKL _table2, ptr_table2 MVKH _table2, ptr_table2 ; points to *table2[0] ADDAW ptr_table2, 1, ptr_table2 ; points to *table2[1] LDW *ptr_table2, ptr_table2 ; points to table2[1][0] LDW *+ptr_table2[1], table2_11 ; load table2[1][1] In assembly code one have to take care about the corresponding delay slots and assign execution units. As it seen, the only difference is whether there has been defined a pointer to or an array of pointers to pointers to an integrals or structures. Well, in the case of multidimentional array of structures there must be pointer modification to access an element in the structure. Have fun, Andrew |