OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [sw/] [apps/] [testfloat/] [testfloat.c] - Diff between revs 393 and 425

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 393 Rev 425
 
 
/*
/*
===============================================================================
===============================================================================
 
 
This C source file is part of TestFloat, Release 2a, a package of programs
This C source file is part of TestFloat, Release 2a, a package of programs
for testing the correctness of floating-point arithmetic complying to the
for testing the correctness of floating-point arithmetic complying to the
IEC/IEEE Standard for Floating-Point.
IEC/IEEE Standard for Floating-Point.
 
 
Written by John R. Hauser.  More information is available through the Web
Written by John R. Hauser.  More information is available through the Web
page `http://HTTP.CS.Berkeley.EDU/~jhauser/arithmetic/TestFloat.html'.
page `http://HTTP.CS.Berkeley.EDU/~jhauser/arithmetic/TestFloat.html'.
 
 
THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE.  Although reasonable effort
THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE.  Although reasonable effort
has been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT
has been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT
TIMES RESULT IN INCORRECT BEHAVIOR.  USE OF THIS SOFTWARE IS RESTRICTED TO
TIMES RESULT IN INCORRECT BEHAVIOR.  USE OF THIS SOFTWARE IS RESTRICTED TO
PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY
PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY
AND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE.
AND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE.
 
 
Derivative works are acceptable, even for commercial purposes, so long as
Derivative works are acceptable, even for commercial purposes, so long as
(1) they include prominent notice that the work is derivative, and (2) they
(1) they include prominent notice that the work is derivative, and (2) they
include prominent notice akin to these four paragraphs for those parts of
include prominent notice akin to these four paragraphs for those parts of
this code that are retained.
this code that are retained.
 
 
Modified for use with or1ksim's testsuite.
Modified for use with or1ksim's testsuite.
 
 
Contributor Julius Baxter <julius.baxter@orsoc.se>
Contributor Julius Baxter <julius.baxter@orsoc.se>
 
 
 
 
===============================================================================
===============================================================================
*/
*/
                                                                 /*
                                                                 /*
#include <stdlib.h>
#include <stdlib.h>
#include <signal.h>
#include <signal.h>
#include <string.h>
#include <string.h>
                                                                 */
                                                                 */
#include "or32-utils.h" // OR1k support C library
#include "cpu-utils.h" // OR1k support C library
#include "milieu.h"
#include "milieu.h"
#include "printf.h"
#include "printf.h"
#include "spr-defs.h"
#include "spr-defs.h"
#include "int.h"
#include "int.h"
#include "fail.h"
#include "fail.h"
#include "softfloat.h"
#include "softfloat.h"
#include "testCases.h"
#include "testCases.h"
#include "testLoops.h"
#include "testLoops.h"
#include "systflags.h" // defines fpcsr_flags global
#include "systflags.h" // defines fpcsr_flags global
#include "testFunction.h"
#include "testFunction.h"
                                                                 /*
                                                                 /*
static void catchSIGINT( int signalCode )
static void catchSIGINT( int signalCode )
{
{
 
 
    if ( stop ) exit( EXIT_FAILURE );
    if ( stop ) exit( EXIT_FAILURE );
    stop = TRUE;
    stop = TRUE;
 
 
}
}
*/
*/
 
 
// Clear flags in floating point control/status reg (FPCSR), and enable
// Clear flags in floating point control/status reg (FPCSR), and enable
// exception
// exception
void inline or1k_enable_fpee(void)
void inline or1k_enable_fpee(void)
{
{
  // Read the FPCSR
  // Read the FPCSR
  unsigned int spr = SPR_FPCSR;
  unsigned int spr = SPR_FPCSR;
  unsigned int value;
  unsigned int value;
  // Read the SPR
  // Read the SPR
  asm("l.mfspr\t\t%0,%1,0" : "=r" (value) : "r" (spr));
  asm("l.mfspr\t\t%0,%1,0" : "=r" (value) : "r" (spr));
 
 
  // Clear flags in FPCSR
  // Clear flags in FPCSR
  value &= ~(SPR_FPCSR_ALLF);
  value &= ~(SPR_FPCSR_ALLF);
 
 
  // Re-enable floating point exceptions
  // Re-enable floating point exceptions
  value |= SPR_FPCSR_FPEE;
  value |= SPR_FPCSR_FPEE;
 
 
  // Write value back to FPCSR
  // Write value back to FPCSR
  asm("l.mtspr\t\t%0,%1,0": : "r" (spr), "r" (value));
  asm("l.mtspr\t\t%0,%1,0": : "r" (spr), "r" (value));
 
 
}
}
  // Interrupt handler for floating point exceptions
  // Interrupt handler for floating point exceptions
  // Just copy out the flags and go back to work...
  // Just copy out the flags and go back to work...
 
 
void float_except_handler(void)
void float_except_handler(void)
{
{
 
 
  // Read the FPCSR
  // Read the FPCSR
  unsigned int spr = SPR_FPCSR;
  unsigned int spr = SPR_FPCSR;
  unsigned int value;
  unsigned int value;
 
 
  // Clear the global we'll use 
  // Clear the global we'll use 
  fpcsr_flags = 0;
  fpcsr_flags = 0;
  // Read the SPR
  // Read the SPR
  asm("l.mfspr\t\t%0,%1,0" : "=r" (value) : "r" (spr));
  asm("l.mfspr\t\t%0,%1,0" : "=r" (value) : "r" (spr));
 
 
  // Extract the flags from OR1K's FPCSR, put into testfloat's flags format  
  // Extract the flags from OR1K's FPCSR, put into testfloat's flags format  
  if (value & SPR_FPCSR_IXF)
  if (value & SPR_FPCSR_IXF)
    fpcsr_flags |= float_flag_inexact;
    fpcsr_flags |= float_flag_inexact;
 
 
  if (value & SPR_FPCSR_UNF)
  if (value & SPR_FPCSR_UNF)
    fpcsr_flags |= float_flag_underflow;
    fpcsr_flags |= float_flag_underflow;
 
 
  if (value & SPR_FPCSR_OVF)
  if (value & SPR_FPCSR_OVF)
    fpcsr_flags |= float_flag_overflow;
    fpcsr_flags |= float_flag_overflow;
 
 
  if (value & SPR_FPCSR_DZF)
  if (value & SPR_FPCSR_DZF)
    fpcsr_flags |= float_flag_divbyzero;
    fpcsr_flags |= float_flag_divbyzero;
 
 
  if (value & SPR_FPCSR_IVF)
  if (value & SPR_FPCSR_IVF)
    fpcsr_flags |= float_flag_invalid;
    fpcsr_flags |= float_flag_invalid;
 
 
  //  printf("testfloat: getting flags, FPCSR: 0x%x, softfloatflags: 0x%x\n", 
  //  printf("testfloat: getting flags, FPCSR: 0x%x, softfloatflags: 0x%x\n", 
  //         value & SPR_FPCSR_ALLF, flags);
  //         value & SPR_FPCSR_ALLF, flags);
 
 
  // This clears flags and re-enables FPEE bit
  // This clears flags and re-enables FPEE bit
  or1k_enable_fpee();
  or1k_enable_fpee();
 
 
}
}
 
 
// Running this bare metal standalone for OR1K - hard set the configuration
// Running this bare metal standalone for OR1K - hard set the configuration
int
int
main( int argc, char **argv )
main( int argc, char **argv )
{
{
  //    char *argPtr; // Unused variable
  //    char *argPtr; // Unused variable
    flag functionArgument;
    flag functionArgument;
    uint8 functionCode;
    uint8 functionCode;
    int8 operands, roundingPrecision, roundingMode;
    int8 operands, roundingPrecision, roundingMode;
 
 
    // Add exception handler for floating point exception
    // Add exception handler for floating point exception
    add_handler(0xd, float_except_handler);
    add_handler(0xd, float_except_handler);
 
 
    // Enable floating point exceptions in FPCSR
    // Enable floating point exceptions in FPCSR
    or1k_enable_fpee();
    or1k_enable_fpee();
 
 
    // If we have UART init it:
    // If we have UART init it:
#ifdef _UART_H_
#ifdef _UART_H_
    uart_init(DEFAULT_UART);
    uart_init(DEFAULT_UART);
#endif
#endif
 
 
    printf("testfloat\n");
    printf("testfloat\n");
 
 
    fail_programName = "testfloat";
    fail_programName = "testfloat";
    //if ( argc <= 1 ) goto writeHelpMessage;
    //if ( argc <= 1 ) goto writeHelpMessage;
    testCases_setLevel( 1 );
    testCases_setLevel( 1 );
    trueName = "soft";
    trueName = "soft";
    testName = "syst";
    testName = "syst";
    errorStop = FALSE;
    errorStop = FALSE;
    forever = FALSE;
    forever = FALSE;
    maxErrorCount = 0;
    maxErrorCount = 0;
    trueFlagsPtr = &float_exception_flags;
    trueFlagsPtr = &float_exception_flags;
    testFlagsFunctionPtr = syst_float_flags_clear;
    testFlagsFunctionPtr = syst_float_flags_clear;
    tininessModeName = 0;
    tininessModeName = 0;
    operands = 0;
    operands = 0;
    roundingPrecision = 0;
    roundingPrecision = 0;
    roundingMode = 0;// ROUND_DOWN// - for only round down tests ; 
    roundingMode = 0;// ROUND_DOWN// - for only round down tests ; 
                     //0 - for do all rounding modes 
                     //0 - for do all rounding modes 
    // "all" setting:
    // "all" setting:
    functionArgument = TRUE;
    functionArgument = TRUE;
    functionCode = 0; // See testFunction.c for list. 
    functionCode = 0; // See testFunction.c for list. 
    // 0 = all possible functions
    // 0 = all possible functions
    // 9 = float32_to_int32
    // 9 = float32_to_int32
    // 10 = float32_to_int32_round_to_zero
    // 10 = float32_to_int32_round_to_zero
    // 17 = float32_add
    // 17 = float32_add
    // 18 = float32_sub
    // 18 = float32_sub
    // 19 = float32_mul
    // 19 = float32_mul
    // 20 = float32_div
    // 20 = float32_div
    // 23 = float32_eq
    // 23 = float32_eq
    // 24 = float32_le
    // 24 = float32_le
    // 25 = float32_lt
    // 25 = float32_lt
 
 
    operands = 0;
    operands = 0;
 
 
    if ( ! functionArgument ) fail( "Function argument required" );
    if ( ! functionArgument ) fail( "Function argument required" );
    //    (void) signal( SIGINT, catchSIGINT );
    //    (void) signal( SIGINT, catchSIGINT );
    //    (void) signal( SIGTERM, catchSIGINT );
    //    (void) signal( SIGTERM, catchSIGINT );
    if ( functionCode ) {
    if ( functionCode ) {
        if ( forever ) {
        if ( forever ) {
            if ( ! roundingPrecision ) roundingPrecision = 80;
            if ( ! roundingPrecision ) roundingPrecision = 80;
            if ( ! roundingMode ) roundingMode = ROUND_NEAREST_EVEN;
            if ( ! roundingMode ) roundingMode = ROUND_NEAREST_EVEN;
        }
        }
        testFunction( functionCode, roundingPrecision, roundingMode );
        testFunction( functionCode, roundingPrecision, roundingMode );
    }
    }
    else {
    else {
 
 
      for ( functionCode = 1;
      for ( functionCode = 1;
                  functionCode < NUM_FUNCTIONS;
                  functionCode < NUM_FUNCTIONS;
                  ++functionCode
                  ++functionCode
                ) {
                ) {
        //printf("trying function %d\n",functionCode);
        //printf("trying function %d\n",functionCode);
                if ( functionExists[ functionCode ] ) {
                if ( functionExists[ functionCode ] ) {
                    testFunction(
                    testFunction(
                        functionCode, roundingPrecision, roundingMode );
                        functionCode, roundingPrecision, roundingMode );
                }
                }
            }
            }
 
 
    }
    }
    exitWithStatus();
    exitWithStatus();
 
 
    // Should never reach here
    // Should never reach here
    return 1;
    return 1;
 
 
}
}
 
 
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.