I am looking for FPU exception generation code. If some one share, or suggest some document for the same.
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.