This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler: Aligning memory

Tool/software: TI C/C++ Compiler

Hello:

I am trying to use a function call for an embedded FIR function.  The FIR Function requires that these two arrays are stacked one after the other.

I define my variables as such:

extern float FIR_IN[1240];

extern float FIR_Coef[241];

I do have a .bss and .global statements defined for each.

FIR_IN has to be in the memory right before FIR_Coef for the FIR function to run correctly, but when I compile and look at the map, it puts them where ever it wants to.

Is there a command structure that will guarantee the positioning of these arrays where I want in memory so that one will follow the other?

  • dan kantorski said:
    The FIR Function requires that these two arrays are stacked one after the other.

    That's not typical.  Can this FIR function be changed?

    These lines ...

    dan kantorski said:

    extern float FIR_IN[1240];

    extern float FIR_Coef[241];

    ... are only declarations.  They do not reserve memory for those arrays.  Which brings up the question ...

    Where is the code which defines the arrays?  In C code, or assembly code?

    Which TI device do you use?

    Thanks and regards,

    -George

  • I would define a buffer twice as big as both arrays and set the FIR_IN and FIR_COEFF pointers accordingly.

    i.e. 

    uint_8 buf[500];

    FIR_IN = &buf[0];

    FIR_COEFF = &buf[250];

    Of  course you would use types appropriate to you.

  • dan kantorski said:
    FIR_IN has to be in the memory right before FIR_Coef for the FIR function to run correctly, but when I compile and look at the map, it puts them where ever it wants to.

    Can you define a structure which contains fields for FIR_IN followed by FIR_Coef?

    That is a way of controlling the relative placement without needing linker commands.

  • The processor used is a TMS320C6726.  The FIR Function call comes from a TI optimized library so I really have no access to it.  I do not know enough to design on my own.  The memory is allocated in an ASM file with this structure 

    .bss   FIR_IN, 4960

    .global FIR_IN

    .bss  FIR_Coef, 964

    .global FIR_Coef

    The function used is "DSPF_sp_fir_gen", a Single precision generic FIR filter function.  

    I could try a structure or I could try defining in ASM file:

    .bss FIR, 5924 

    .global FIR

    then in C

    extern float FIR[1481]

    FIR_IN=&FIR[0]

    FIR_Coeff=FIR[1240]

    The extern float is at the top of the program so it can be assessed through all subroutines.  If i declare those pointers right after they would also be assessed by all subroutines?

  • dan kantorski said:
    The FIR Function call comes from a TI optimized library

    I presume this FIR function comes from dsplib.  I further you presume you use the variant of dsplib called C67X-DSPLIB: C67x DSP Library.

    dan kantorski said:
    The function used is "DSPF_sp_fir_gen"

    There is a function of that name in that library.  The library comes with PDF document which, among other things, gives details about every function.  In the documentation for this function, there is no requirement that the input array and coefficient array be adjacent in memory.  

    dan kantorski said:
    The FIR Function call comes from a TI optimized library so I really have no access to it.

    The library installation includes the source.  The file dsp67x.src contains all the source code to the functions implemented in assembly language.  To see the source for the function used in this thread, run this command ...

    % ar6x -x dsp67x.src DSPF_sp_fir_gen.asm

    The command ar6x is the archiver.  It is part of the C6000 compiler installation.  It is documented in the C6000 assembly language tools manual.  The option -x says to extract file.  The last parameter names the file to be extracted.  

    By inspecting the comments to the function in the source, you will learn that both the input array and coefficient array are accessed with the instruction LDDW, which means those arrays must be aligned on 8-byte boundaries.  Therefore these lines ...

    dan kantorski said:

    .bss   FIR_IN, 4960

    .global FIR_IN

    .bss  FIR_Coef, 964

    .global FIR_Coef

    ... must be changed to ...

            .bss   FIR_IN, 4960, 8
            .global FIR_IN
    
            .bss  FIR_Coef, 964, 8
            .global FIR_Coef

    The ,8 at the end of the .bss line means that block of memory is aligned to an 8-byte boundary.  This same requirement is true of the array passed in to receive the results of the calculation.  

    Please let me know if these suggestions resolve the problem.

    Thanks and regards,

    -George

  • Ok, I have read the PDF description for the subroutine again and you are right, it seems that ordering of the arrays are not required.  The way it was written, I misunderstood.  So, I will give it a try as I was going to do it.  The alignment term after my declarations will help insure I don't make one possible mistake, so thank you.  I will come back to this and reply if it works out.