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.

How Do I Force Single Precision Calculations for 674x Using CCS 4.x

My application must be miserly with memory usage, and single precision math is enough. I am coming from using assmebly language on the TMS20VC33 to using CCS 4.x and the C compiler.  My initial test app is an analytic (complex) oscillator.

Here is the simple function in C:

Note that cosc is an array of floats.

void analytic_osc ( void )

{


float register mag_sq, tcos, tsin;  // compiler issues warning "storage class is not first" whatever that means

// the vc33 assembler takes 19 cycles and 16 words for the entire function including exit cycles
// when put into this as a function, it takes the 674x 125 + exit cycles and 67 words of memory !!

        tcos = cosc[2] * cosc[4] - cosc[3] * cosc[5];

        tsin = cosc[2] * cosc[5] + cosc[3] * cosc[4];

// now apply AGC

        mag_sq = tcos * tcos + tsin * tsin;

        tcos = tcos * (3.0 - (mag_sq)) * 0.5;

        tsin = tsin * (3.0 - (mag_sq)) * 0.5;

// update previous results with current results for next iteration

        cosc[4] = tcos;

        cosc[5] = tsin;

}

 

When compiled and disassembled, there is a huge memory and performance penalty taken because the compiler seems to insist on making the 'float register" values into "double register" and applying double-precision math.  Here is a snippet of the disassembled code:

25                  tcos = tcos * (3.0 - (mag_sq)) * 0.5;


020C10A2            SPDP.S2X      A3,B5:B4
06A6                MVK.L1        0,A5
0626                MVK.L1        0,A4
02A00468 ||         MVKH.S1       0x40080000,A5
02109338            SUBDP.L1X     A5:A4,B5:B4,A5:A4
03800028            MVK.S1        0x0000,A7
039EBD88            SET.S1        A7,21,29,A7
E0800020            .fphead       n, l, W, BU, nobr, nosat, 0000100
00006000            NOP           4
0210C5B0            MPYSPDP.M1    A6,A5:A4,A5:A4
0726                MVK.L1        0,A6
8C6E                NOP           5
0210C700            MPYDP.M1      A7:A6,A5:A4,A5:A4
00010000            NOP           9
04148138            DPSP.L1       A5:A4,A8
00004000            NOP           3

This snippet takes 14 words and 31 cycles to execute, compared with the 'VC33 section taking 3 words and 3 cycles.

As you can see there is a huge penalty in execution time (NOP 9 for example) as well as memory.  I'm still trying to figure out why all the constants are being generated and loaded into various registers.

I admit to being a complete novice with the IDE (I am used to Code Composer, not CCS, for the VC33) and with C (I am used to assembler, but the 674x assembly language is scary with all the limitations and dependencies and pipeline delays etc).

Any help on how to force the compiler to use single precision math?  If it is a compiler option that has to be set somehow, help on where/how to set it within the CCS 4.x project IDE would be most appreciated, too

 

Thanks in advance for any help!

 

Lyle Johnson

Elecraft, Inc.

 

  • Consider using the build option --fp_mode=relaxed.  Before you use that in a production system, definitely read up on the limitations of this option in the compiler manual.

    Thanks and regards,

    -George

  • Thank you for that, George.  I had  searched the compiler manual previously, but was looking for SP and single precision, not --fp. And, unfortunatley, it tell sm nothing about how to configure the CCS 4.x IDE to allow me to set or change compile-time options.

    Thus, the second part of the question is" How do I tell the compiler which options ot use from the CCS 4.x gui?  I looked in the wiki under CGT, and found it is very simple in CCS 3.3 (and the CC I am used to for the vc33).  But I can't find how to do it in CCS 4.x. I've looked over the FAQs, done searches on the wiki and E2E, etc.  I've left and right-clicked everything I can find in the IDE that might be remotely related.

     

    No luck.

     

    I'm sure it is something trivially simple...

     

    Thanks for any help,

     

    Lyle Johnson

    Elecraft, Inc.

  • Right click on the project name and choose "Build Properties".  Then make it look like the screen image attached to this post.

    Thanks and regards,

    -George

  • FWIW, I am running Windows 7 Professional, 64-bit, 8 Gigs of RAM, Core i5 (HP dv7-4283cl laptop computer to which CCS is node-locked).

    Right-clicking the active project and bringng up "Build Options" brings up the below, which suggests I ought to be able to view and change configuration settings, but can't since it is totaly blank.

     

    ?

    Lyle Johnson

     

  • When I try that I get a blank configuration screen.  How do I get all the options to appear like you show?

     

    The CCS I am using is  Version: 4.2.1.00004

    Computer is Windows 7 Professional, 64-bit, Intel i5, 8 Gigs RAM.

     

    Regards,

    Lyle Johnson

  • Lyle,

    What you are running into is a known issue with 64-bit OS like Window7. Please take a look at this FAQ for how to work around this dialog drawing issue:
    http://processors.wiki.ti.com/index.php/FAQ_-_CCSv4#Q:_Does_CCS_support_64bit_Operating_Systems.3F

  • The "storage class" is "register";  the compiler would prefer that appear first, ahead of "float."

    Note that floating-point literals like 3.0 and 0.5 are doubles.  To force them to be floats, use 3.0f and 0.5f.  When I do that, I no longer see any double-precision instructions.

    Are you compiling with optimisation?  When I use -o2, I see results rather different than you report.  Even with double-precision literals, it's only 67 cycles and 192 8-bit bytes of code;  with single-precision literals and -o2, 45 cycles and 160 bytes.

  • That fixed it!

    Thank so VERY MUCH for all your help with this, George.

    Regards,

    Lyle

  • pf,

     

    Thank you for the suggestions and observations.  I no longer get the compiler warning.

    I used your notes (trailing f on floating point constants, optimization level 2), still compiling for debug (not release) so I can use the simulator.  Using the compiler switch that George suggested to not use double-precison intermediate results.  CGT is version 7.04.

    I get 212 bytes and 85 cycles (including the 6 cycles to return from the function call).  This is much better than before.

     

    Regards,

     

    Lyle