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/CC3200: bug in Ti compiler preprocessor - #define float constant is set to zero

Part Number: CC3200

Tool/software: TI C/C++ Compiler

I've been baffled by this and it seems the Ti ARM compiler is misbehaving.

#define API_POLL_QUEUE_INTERVAL 30.0f

const float _API_POLL_QUEUE_INTERVAL=30.0f;

Report("adding #define float + const float: %f + %f = %f\n\r",API_POLL_QUEUE_INTERVAL,_API_POLL_QUEUE_INTERVAL,API_POLL_QUEUE_INTERVAL+_API_POLL_QUEUE_INTERVAL);

----> output

adding #define float + const float: 0.000000 + 30.000000 = 30.000000

I'm using Ti compiler v5.2.8, which is required for a library I'm using

This happens in both strict and relaxed fp modes

  • it turns out it isn't the preprocessor.

    it turns out that float arithmetic doesn't work correctly in function arguments. not even with literals.
  • Hi Tim,

    Could you send a code snippet please?

    ~roger
  • that is a code snippet above.

    what I'm seeing is that float arithmetic isn't evaluating properly, although in relaxed mode a statement like:

    float a = 2.0 + 2.0;

    does work somewhat.
  • Hi Tim,

    That code snippet above, works ok for me, so I guess some other option is different.

    Can you try this test to make sure we're using the same test-case?

    #include "hw_types.h"
    #include "hw_memmap.h"
    #include "hw_gpio.h"
    #include "hw_ints.h"
    #include "pin.h"
    #include "rom.h"
    #include "rom_map.h"
    #include "gpio.h"
    #include "prcm.h"
    #include "interrupt.h"
    
    #include "uart_if.h"
    
    extern void (* const g_pfnVectors[])(void);
    
    #define API_POLL_QUEUE_INTERVAL 30.0f
    const float _API_POLL_QUEUE_INTERVAL=30.0f;
    
    void testFloatAddAndPrint(float a, float b)
    {
        Report("adding #define float + const float: %f + %f = %f\n\r",a,b,a+b);
    }
    
    void testFloatPrint(void)
    {
        Report("adding #define float + const float: %f + %f = %f\n\r",API_POLL_QUEUE_INTERVAL,_API_POLL_QUEUE_INTERVAL,API_POLL_QUEUE_INTERVAL+_API_POLL_QUEUE_INTERVAL);
    }
    
    
    void main()
    {
        MAP_IntVTableBaseSet((unsigned long)&g_pfnVectors[0]);
        MAP_IntMasterEnable();
        MAP_IntEnable(FAULT_SYSTICK);
        PRCMCC3200MCUInit();
    
        MAP_PRCMPeripheralClkEnable(PRCM_GPIOA1, PRCM_RUN_MODE_CLK);
        MAP_PinTypeGPIO(PIN_01, PIN_MODE_0, false);
        MAP_GPIODirModeSet(GPIOA1_BASE, 0x4, GPIO_DIR_MODE_OUT);
        MAP_PinTypeGPIO(PIN_02, PIN_MODE_0, false);
        MAP_GPIODirModeSet(GPIOA1_BASE, 0x8, GPIO_DIR_MODE_OUT);
    
        InitTerm();
    
        testFloatAddAndPrint(API_POLL_QUEUE_INTERVAL+_API_POLL_QUEUE_INTERVAL,API_POLL_QUEUE_INTERVAL+_API_POLL_QUEUE_INTERVAL);
        testFloatAddAndPrint(API_POLL_QUEUE_INTERVAL,_API_POLL_QUEUE_INTERVAL);
        testFloatPrint();
    }

    Thanks,

    ~roger

  • Hi Roger thanks, this is a good approach.

    I compiled your main.c with my existing compiler and settings.

    I had to remove FREERTOS flags and add startup_ccs.c and uart_if.c from the existing project.

    This is the output I got:

    adding #define float + const float: 60.000000 + 60.000000 = 120.000000

    adding #define float + const float: 30.000000 + 30.000000 = 60.000000

    adding #define float + const float: 0.000000 + 30.000000 = 60.000000

    which is different to what I was seeing, but still bat-*** crazy.

     

  • I switched from compiler 5.2.8 to 16.9.0 LTS and I got the same output:

    adding #define float + const float: 60.000000 + 60.000000 = 120.000000

    adding #define float + const float: 30.000000 + 30.000000 = 60.000000

    adding #define float + const float: 0.000000 + 30.000000 = 60.000000

    What output do you get?

  • Hmm, ok,

    Could you add a couple of compiler switches, if you haven't got these already.

    1.  -pdr (--issue_remarks) (to add extra compiler remarks)

    This will generate compiler remarks and may give us some clues.

    2.  -ppl (--preproc_with_line) -ppa (--preproc_with_compile) (to generate .pp pre-processor file and continue)

    This should generate a .pp file after the pre-processor, and give you something like :-

    const float _API_POLL_QUEUE_INTERVAL=30.0f;
    
    void testFloatAddAndPrint(float a, float b)
    {
        Report("adding #define float + const float: %f + %f = %f\n\r",a,b,a+b);
    }
    
    void testFloatPrint(void)
    {
        Report("adding #define float + const float: %f + %f = %f\n\r",30.0f,_API_POLL_QUEUE_INTERVAL,30.0f+_API_POLL_QUEUE_INTERVAL);
    }
    
    
    void main()
    {
        IntVTableBaseSet((unsigned long)&g_pfnVectors[0]);
        IntMasterEnable();
        IntEnable(15);
        PRCMCC3200MCUInit();
    
        PRCMPeripheralClkEnable(0x00000007, 0x00000001);
        PinTypeGPIO(0x00000000, 0x00000000, 0);
        GPIODirModeSet(0x40005000, 0x4, 0x00000001);
        PinTypeGPIO(0x00000001, 0x00000000, 0);
        GPIODirModeSet(0x40005000, 0x8, 0x00000001);
    
        InitTerm();
    
        testFloatAddAndPrint(30.0f+_API_POLL_QUEUE_INTERVAL,30.0f+_API_POLL_QUEUE_INTERVAL);
        testFloatAddAndPrint(30.0f,_API_POLL_QUEUE_INTERVAL);
        testFloatPrint();
    }

    and I get the output as expected :-

    adding #define float + const float: 60.000000 + 60.000000 = 120.000000
    adding #define float + const float: 30.000000 + 30.000000 = 60.000000
    adding #define float + const float: 30.000000 + 30.000000 = 60.000000
    

    Can you send your complete compile options?

    ~roger

  • I switched from strict to relaxed FP mode and I got the same answer.

    I also turned off the option --fp_reassoc and I got the same answer:

    adding #define float + const float: 60.000000 + 60.000000 = 120.000000

    adding #define float + const float: 30.000000 + 30.000000 = 60.000000

    adding #define float + const float: 0.000000 + 30.000000 = 60.000000

    however, I changed the --float_support from fpalib to vfplib and the output changed:

    adding #define float + const float: 60.000000 + 60.000000 = 120.000000
    adding #define float + const float: 30.000000 + 30.000000 = 60.000000
    adding #define float + const float: 30.000000 + 30.000000 = 60.000000


     

     

  • Hi Roger,

    -pdr -ppl and --ppa don't work for me in CCS. would I have to set these on the command line?

    here are the flags as reported by CCS:

    -mv7M4 --code_state=16 --float_support=fpalib -me -Ooff --opt_for_speed=0 --fp_mode=relaxed --include_path="/Applications/ti/ccsv7/tools/compiler/ti-cgt-arm_16.9.0.LTS/include" --include_path="/Users/tim/ti/CC3200SDK_1.2.0/cc3200-sdk/simplelink_extlib/provisioninglib" --include_path="/Users/tim/ti/CC3200SDK_1.2.0/cc3200-sdk" --include_path="/Users/tim/ti/CC3200SDK_1.2.0/cc3200-sdk/oslib/" --include_path="/Users/tim/ti/CC3200SDK_1.2.0/cc3200-sdk/driverlib/" --include_path="/Users/tim/ti/CC3200SDK_1.2.0/cc3200-sdk/simplelink/" --include_path="/Users/tim/ti/CC3200SDK_1.2.0/cc3200-sdk/simplelink/source" --include_path="/Users/tim/ti/CC3200SDK_1.2.0/cc3200-sdk/simplelink/include" --include_path="/Users/tim/ti/CC3200SDK_1.2.0/cc3200-sdk/inc/" --include_path="/Users/tim/ti/CC3200SDK_1.2.0/cc3200-sdk/example/common" --define=ccs --define=cc3200 -g --c89 --c++03 --relaxed_ansi --diag_warning=225 --diag_wrap=off --display_error_number --issue_remarks --gen_func_subsections=on --abi=eabi --fp_reassoc=off

    seems that the --float_support is the problem, and I can't recall when this was set in the project.

    what are your reccomended options for FP support on the cc3200?

  • Ah, I see you are using fpalib.

    I think you're probably hitting SDSCM00044035. (C:\ti\ccsv7\tools\compiler\ti-cgt-arm_16.9.3.LTS\Open_defects.html)

    I would use --float_support=vfplib.

    ~roger

    FYI - in-case you need in the future, those other options I mentioned are aliases for the longer options :-
    -pdr, --issue_remarks
    -ppa,--preproc_with_compile
    -ppl, --preproc_with_line

  • thanks Roger

    I'm not sure when exactly this was set, but would Ti consider disabling this option in CCS until the bug is fixed?
  • Hi Tim,

    Yes, I agree - we definitely need to look to see how we can avoid hitting this one again.

    ~roger