This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

ARM CM4 FPU execption

I am looking for FPU exception generation code. If some one share, or suggest some document for the same.

Regards

Anuj

Parents
  • Hi Anuj,


    there would be several cases to produce the floating point execeptions.
    I would show the below examples.

    FPExc_InvalidOp
         +infinity + (–infinity)
    FPExc_DivideByZero
         normalized number / zero
    FPExc_Overflow
         maximum normalized number + 1
    FPExc_Underflow
         minumum normalized number - 1
    FPExc_Inexact
         maximum normalized number + minumum normalized number
    FPExc_InputDenorm
         operand is denormalized number

    In Cortex-M4 case, the enable bits seem not to be implemented.
    So, you can only see the accumulated exception results in FPSCR.

    Best regards,

    Yasuhiko Koumoto.

Reply
  • Hi Anuj,


    there would be several cases to produce the floating point execeptions.
    I would show the below examples.

    FPExc_InvalidOp
         +infinity + (–infinity)
    FPExc_DivideByZero
         normalized number / zero
    FPExc_Overflow
         maximum normalized number + 1
    FPExc_Underflow
         minumum normalized number - 1
    FPExc_Inexact
         maximum normalized number + minumum normalized number
    FPExc_InputDenorm
         operand is denormalized number

    In Cortex-M4 case, the enable bits seem not to be implemented.
    So, you can only see the accumulated exception results in FPSCR.

    Best regards,

    Yasuhiko Koumoto.

Children
  • Hello Yasuhiko,

    Thanks for your email. To be precise I am using Cortex M4F.

    Regards,

    Anuj

  • Hello,


    I'm very sorry but I had given wrong information.
    The overflow and underflow conditions were wrong.
    I have corrected them in the actual code.
    I have verified them on my FRDM-K64F board.

    The CPU of the board is Cortex-M4F.

    #include <stdio.h>
    #include <stdlib.h>
    #include "fsl_device_registers.h"
    #include "fsl_uart_driver.h"
    #include "fsl_clock_manager.h"
    #include "board.h"
    #ifdef DEBUG
    #include "fsl_debug_console.h"
    #endif
    /*******************************************************************************
     * Definitions
     ******************************************************************************/
    #define USE_STDIO_FUNCTIONS  /* Define this symbol to use STDIO functions */
    
    /*******************************************************************************
     * Global Variables
     ******************************************************************************/
    /*******************************************************************************
     * Prototypes
     ******************************************************************************/
    void FPSCR_CLR(void);
    int  FPSCR_GET(void);
    /*******************************************************************************
     * Code
     ******************************************************************************/
    /********************************************************************/
    int main (void)
    {
      
      union {
        float f;
        int  i;
      } X, Y, Z;
      
        /***************************************************************************
        *  RX buffers
        **************************************************************************/
        /*! @param receiveBuff Buffer used to hold received data */
        uint8_t receiveBuff[19] = {0};
        /* Initialize standard SDK demo application pins */
        hardware_init();
        /* Configure the UART TX/RX pins */
        configure_uart_pins(BOARD_DEBUG_UART_INSTANCE);
        /* Call this function to initialize the console UART.  This function
          enables the use of STDIO functions (printf, scanf, etc.) */
        dbg_uart_init();
        
        /*  Print the initial banner */
        printf("\r\nFPU ExceprionLinpack Bnechmark\n\n\r");
        
        //FPU_Enable();
          
        printf("FPExc_InvalidOp\n\r");
        /* +infinity + (?infinity) */
        FPSCR_CLR();
        X.i = 0x7f800000;
        Y.i = 0xff800000;
        Z.i = 0x00000000;
        Z.f = X.f + Y.f;
        printf("RES=%08x FPSCR=%08x\n\r", Z.i, FPSCR_GET());
      
        printf("FPExc_DivideByZero\n\r");
        /* normalized number / zero */
        FPSCR_CLR();
        X.i = 0x3f800000;
        Y.i = 0x00000000;
        Z.i = 0x00000000;
        Z.f = X.f / Y.f;
        printf("RES=%08x FPSCR=%08x\n\r", Z.i, FPSCR_GET());
      
        printf("FPExc_Overflow\n\r");
        /* maximum normalized number * maximum normalized number */
        FPSCR_CLR();
        X.i = 0x7f7fffff;
        Y.i = 0x7f7fffff;
        Z.i = 0x00000000;
        Z.f = X.f * Y.f;
        printf("RES=%08x FPSCR=%08x\n\r", Z.i, FPSCR_GET());
      
        printf("FPExc_Underflow\n\r");
        /* minumum normalized number /  maximum normalized number */
        FPSCR_CLR();
        X.i = 0x00800000;
        Y.i = 0x7f7fffff;
        Z.i = 0x00000000;
        Z.f = X.f / Y.f;
        printf("RES=%08x FPSCR=%08x\n\r", Z.i, FPSCR_GET());
      
        printf("FPExc_Inexact\n\r");
        /* maximum normalized number + minumum normalized number */
        FPSCR_CLR();
        X.i = 0x7f7fffff;
        Y.i = 0x00800000;
        Z.i = 0x00000000;
        Z.f = X.f + Y.f;
        printf("RES=%08x FPSCR=%08x\n\r", Z.i, FPSCR_GET());
      
        printf("FPExc_InputDenormt\n\r");
        /* operand is denormalized number */
        FPSCR_CLR();
        X.i = 0x00000001;
        Y.i = 0x00000000;
        Z.i = 0x00000000;
        Z.f = X.f + Y.f;
        printf("RES=%08x FPSCR=%08x\n\r", Z.i, FPSCR_GET());
      
        while(1)
        {
        }
    }
    void FPSCR_CLR(void)
    {
      int tmp=(1<<24);
      asm volatile ("VMSR FPSCR,%0\n" : "=r" (tmp) : "0" (tmp));
    }
    int  FPSCR_GET(void)
    {
      int tmp;
      asm volatile ("VMRS %0,FPSCR\n" : "=r" (tmp) : "0" (tmp));
      return tmp;
    }
    

    Best regards,
    Yasuhiko Koumoto.