Uploaded image for project: 'Embedded Software & Tools'
  1. Embedded Software & Tools
  2. EXT_EP-10499

Compiler computes slightly different float values when they should match

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Won't Implement
    • Icon: Not Prioritized Not Prioritized

      For these assignments to float variables ...

         f1 = 540.0f;
         f2 = f1 / (728.0f) ;
         f3 = 540.0f / (728.0f) ;
      

      Note f2 and f3 should get the same value. However, when this code is built with optimization level 3, slightly different values are assigned. Here are some key lines from the compiler generated assembly code ...

              MOVIZ     R1H,#16189            ; [CPU_FPU] |8|
              MOVIZ     R0H,#16189            ; [CPU_FPU] |9|
              MOVIZ     R2H,#17415            ; [CPU_FPU] |7|
              MOVW      DP,#_f1               ; [CPU_ARAU]
              MOVXI     R1H,#58335            ; [CPU_FPU] |8|
              MOVXI     R0H,#58334            ; [CPU_FPU] |9|
              MOV32     @_f1,R2H              ; [CPU_FPU] |7|
              MOV32     @_f2,R1H              ; [CPU_FPU] |8|
              MOV32     @_f3,R0H              ; [CPU_FPU] |9|
      

      The two MOVXI instructions should assign the same value. But they are off by 1.

            syncuser TI User
            syncuser TI User
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: