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.

Floating point operation results in exception

Hi guys!

I asked this exact same question in the TI C/C++ Compiler subforum, but they couldn't help me, and thought the hardware forum would be a better place for it. I hope someone here can help me with my issue.

I'm having some trouble with floating point operations. Currently I'm running starterware on the beaglebone devboard, which features an AM3359 processor, and CCS 5.1 with TMS470. It is supposed to have support for NEON and VFP, so I tried to enable that in my project. Basically I just checked the boxes for --neon and --float_support (VFPv3). I also added some optimizations to the project, but all I got was crashes. I hence removed the optimizations to start debugging, and it turns out that I get thrown into exceptionhandler.asm as soon as my first floating point operation is done. It looks like this, where A, B, C and D are all integers.

    float time=0.00001;
    float tempx, tempy;
    
    tempx = (((A*time)+B)*time+C)*time+D;          <- Exception thrown here.

So basically now I assume that I've missed some sort of setting somewhere. I have included the relevant libraries; rtsv7A8_A_le_n_v3_eabi.lib for when I tried with --neon, and rtsv7A8_A_le_v3_eabi.lib when I run without --neon. I have also made sure to recompile all my libraries with --neon and --float_support (the project did not want to compile otherwise). I have also tried specifying --fp_mode to relaxed, but that didn't help. So basically my compilation flags look like this:

-mv7A8 -g --fp_mode=relaxed --gcc --include_path="C:/ti/ccsv5/tools/compiler/tms470/include" --include_path="C:/ti/AM335X_StarterWare_02_00_00_06/include/hw" --include_path="C:/ti/AM335X_StarterWare_02_00_00_06/include/" --include_path="C:/ti/AM335X_StarterWare_02_00_00_06/include/armv7a/am335x" --include_path="C:/ti/AM335X_StarterWare_02_00_00_06/include/armv7a/" --include_path="C:/ti/AM335X_StarterWare_02_00_00_06/usblib/include" --diag_warning=225 --display_error_number -me --abi=eabi --code_state=32 --neon --float_support=VFPv3

There feels like I'm still missing something, anybody have any ideas?

Kind regards

Lars

  • I think you have to allow access to CP10 and CP11 to be able to use NEON or VFP. There is a CP15 register, I think called something like Coprocessor Access Control Register, where you set  bits for allowing access to CP10 and CP11.

    Steve K.

  • Hi

    Thanks Steve for the suggestion. StarterWare doesnt enable access to CP10 and CP11 by default.

    Hi Lars,

    You can enable this in StarterWare system_config/armv7a/<toolchain>/init.S  with the below sample code.

             MRC     p15, #0, r3, c1, c0, #2        ; Read CPACR
            ORR     r3, #0x00300000                 ; Enable access to CP10 and CP11
             MCR     p15, #0, r3, c1, c0, #2         ; Write CPACR

    Regards,

    Sujith.

  • Hi guys!

    Thanks for the suggestions!

    Sujith, I took your code ande put it in init.asm (under the "Invalidate and Enable Branch Prediction" section if that makes any sens), which is included in my system.lib, and rebuilt it. However, I got a compilation error of a missing operand for the ORR, so I just expected that it should be:

             MRC     p15, #0, r3, c1, c0, #2        ; Read CPACR
            ORR     r3, r3, #0x00300000                 ; Enable access to CP10 and CP11
             MCR     p15, #0, r3, c1, c0, #2         ; Write CPACR

    At least it now compiled, and after recompiling my own project with the new library, and debugging it, the error still persists. So I started looking at what you were setting the register to, and came across this article: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0433b/CIHEBIFD.html , where it seemed like you would only have enabled CP10. I changed the mask to #0x00F00000 instead, to make sure both CP11 and CP10 were set, but that did not fix my problem either.

    From there on I went to look at what kind of exception I got, but instead of finding a menu for that, I found a menu called ARM Advanced Features that is only visible in Debug mode. After starting my code and running the first couple of lines the NEON tickbox was still not enabled, even though stuff like caches and MMU got ticked. So I ticked the Neon box and continued my code, and now it actually ran the lines without any problems.

    So, it seems like the NEON is still not enabled properly, any ideas on what's missing from the puzzle?

    Kind regards

    Lars

  • Ok guys, It seems like I've kind of fixed it now. It seems that an enable bit has to be set in FPEXC. I added the command for that in the init assembly, but it seems like that caused the MMU and caches to not be enabled properly. I hence moved it to inline assembly after the initialization of those modules, it currently resides in my main function.

       asm(" MRC     p15, #0, r3, c1, c0, #2");
       asm(" ORR     r3, r3, #0x00F00000 ");
       asm(" MCR     p15, #0, r3, c1, c0, #2");

       asm(" MOV r0, #0x40000000");
       asm(" VMSR FPEXC, r0");
       asm(" VMRS R1, FPSID");

    Now my NEON box is ticked, and the system doesn't crash. But as soon as i turn on optimizations for speed, --opt_for_speed, to any number other than 1, I get a float-operation at the very start of main, so that I get thrown another exception (because remember, I have not enabled neon yet). So basically I could just move the code back to the init assembly and have neon enabled before I get to main, but that causes as I stated earlier, that the MMU and caches aren't enabled when they are initialized from main.

    So to me, there seems like this code, when it resides in init.asm (without the "asm" calls of course) causes other initializations (MMU, caches) to not happen, or at least not show up in the ARM Advanced Features screen after they've been called. Any tips on how I should correct this so that I can have NEON with speed optimizations and MMU & Caches?

    Kind regards

    Lars

  • Ok, never mind the problem from my last post, it seems like the ARM Advanced Features screen just had trouble updating, after running the processor a while and pausing it, and changing tab back and forth, I can see that all features are enabled as they should.

    So basically, if anybody else has the problems I have, just put this in your init.asm file or similar:


    ; Initialize NEON and VFP
             MRC     p15, #0, r3, c1, c0, #2        ; Read CPACR
             ORR     r3, r3, #0x00F00000            ; Enable access to CP10 and CP11
             MCR     p15, #0, r3, c1, c0, #2        ; Write CPACR

    ; Enable NEON and VFP
            MOV r0, #0x40000000
            VMSR FPEXC, r0
            VMRS R1, FPSID

    Thanks for the help guys!

    Kind regards

    Lars