Line 1... |
Line 1... |
/* fp.S. Floating point instruction set test of Or1ksim
|
/* fp.S. Floating point instruction set test of Or1ksim
|
|
|
Copyright (C) 1999-2006 OpenCores
|
Copyright (C) 1999-2006 OpenCores
|
Copyright (C) 2010 Embecosm Limited
|
Copyright (C) 2010 Embecosm Limited
|
|
Copyright (C) 2010 ORSoC AB
|
|
|
Contributors various OpenCores participants
|
Contributors various OpenCores participants
|
Contributor Jeremy Bennett
|
Contributor Jeremy Bennett
|
|
Contributor Julius Baxter
|
|
|
This file is part of OpenRISC 1000 Architectural Simulator.
|
This file is part of OpenRISC 1000 Architectural Simulator.
|
|
|
This program is free software; you can redistribute it and/or modify it
|
This program is free software; you can redistribute it and/or modify it
|
under the terms of the GNU General Public License as published by the Free
|
under the terms of the GNU General Public License as published by the Free
|
Line 323... |
Line 325... |
l.jal _punexpected ;\
|
l.jal _punexpected ;\
|
l.nop ;\
|
l.nop ;\
|
9:
|
9:
|
|
|
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
|
* Macro for setting rounding mode in FPCSR
|
|
*
|
|
* Arguments:
|
|
* rm round mode macro from spr-defs.h
|
|
* ------------------------------------------------------------------------- */
|
|
#define SET_RM(rm) \
|
|
l.mfspr r4, r0, SPR_FPCSR ;\
|
|
/* Clear rounding mode bits */ ;\
|
|
l.ori r4, r4, SPR_FPCSR_RM ;\
|
|
l.xori r4, r4, SPR_FPCSR_RM ;\
|
|
/* Set desired rounding mode bits */ ;\
|
|
l.ori r4, r4, rm ;\
|
|
l.mtspr r0, r4, SPR_FPCSR
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
* Simple stack, will be pointed to by r1, which is the next empty slot
|
* Simple stack, will be pointed to by r1, which is the next empty slot
|
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
.section .data
|
.section .data
|
.balign 4
|
.balign 4
|
.global _stack
|
.global _stack
|
Line 836... |
Line 855... |
CHECK_RES ("+NaN / -NaN = +NaN: ", r4, FP_S_P_NAN)
|
CHECK_RES ("+NaN / -NaN = +NaN: ", r4, FP_S_P_NAN)
|
|
|
LOAD_CONST (r5,FP_S_N_NAN)
|
LOAD_CONST (r5,FP_S_N_NAN)
|
LOAD_CONST (r6,FP_S_P_NAN)
|
LOAD_CONST (r6,FP_S_P_NAN)
|
lf.div.s r4,r5,r6
|
lf.div.s r4,r5,r6
|
CHECK_RES ("-NaN / +NaN = -NaN: ", r4, FP_S_P_NAN)
|
CHECK_RES ("-NaN / +NaN = -NaN: ", r4, FP_S_N_NAN)
|
|
|
LOAD_CONST (r5,FP_S_N_NAN)
|
LOAD_CONST (r5,FP_S_N_NAN)
|
LOAD_CONST (r6,FP_S_N_NAN)
|
LOAD_CONST (r6,FP_S_N_NAN)
|
lf.div.s r4,r5,r6
|
lf.div.s r4,r5,r6
|
CHECK_RES ("-NaN / -NaN = -NaN: ", r4, FP_S_N_NAN)
|
CHECK_RES ("-NaN / -NaN = -NaN: ", r4, FP_S_N_NAN)
|
Line 913... |
Line 932... |
LOAD_CONST (r5,FP_S_N_ZERO)
|
LOAD_CONST (r5,FP_S_N_ZERO)
|
lf.ftoi.s r4,r5
|
lf.ftoi.s r4,r5
|
CHECK_RES ("(int) -0.0 = 0: ", r4, 0x00000000)
|
CHECK_RES ("(int) -0.0 = 0: ", r4, 0x00000000)
|
|
|
/* Fractional conversion (round towards zero) */
|
/* Fractional conversion (round towards zero) */
|
|
SET_RM (FPCSR_RM_RZ)
|
LOAD_CONST (r5,FP_S_1_5)
|
LOAD_CONST (r5,FP_S_1_5)
|
lf.ftoi.s r4,r5
|
lf.ftoi.s r4,r5
|
CHECK_RES ("(int) 1.5 = 1: ", r4, 0x00000001)
|
CHECK_RES ("(int) 1.5 = 1: ", r4, 0x00000001)
|
|
|
LOAD_CONST (r5,FP_S_N_1_5)
|
LOAD_CONST (r5,FP_S_N_1_5)
|
Line 924... |
Line 944... |
CHECK_RES ("(int) -1.5 = -1: ", r4, 0xffffffff)
|
CHECK_RES ("(int) -1.5 = -1: ", r4, 0xffffffff)
|
|
|
/* Conversion of values too big */
|
/* Conversion of values too big */
|
LOAD_CONST (r5,FP_S_HUGE1)
|
LOAD_CONST (r5,FP_S_HUGE1)
|
lf.ftoi.s r4,r5
|
lf.ftoi.s r4,r5
|
CHECK_RES ("(int) 1.0 * 2^126 = -2^31: ", r4, 0x80000000)
|
CHECK_RES ("(int) 1.0 * 2^126 = 2^31: ", r4, 0x7fffffff)
|
|
|
LOAD_CONST (r5,FP_S_N_HUGE1)
|
LOAD_CONST (r5,FP_S_N_HUGE1)
|
lf.ftoi.s r4,r5
|
lf.ftoi.s r4,r5
|
CHECK_RES ("(int) -1.0 * 2^126 = -2^31: ", r4, 0x80000000)
|
CHECK_RES ("(int) -1.0 * 2^126 = -2^31: ", r4, 0x80000000)
|
|
|
Line 942... |
Line 962... |
CHECK_RES ("(int) -1.0 * 2^-129 = 0: ", r4, 0x00000000)
|
CHECK_RES ("(int) -1.0 * 2^-129 = 0: ", r4, 0x00000000)
|
|
|
/* Just basic check of Infinity & NaN */
|
/* Just basic check of Infinity & NaN */
|
LOAD_CONST (r5,FP_S_P_INF)
|
LOAD_CONST (r5,FP_S_P_INF)
|
lf.ftoi.s r4,r5
|
lf.ftoi.s r4,r5
|
CHECK_RES ("(int) +inf = -2^31: ", r4, 0x80000000)
|
CHECK_RES ("(int) +inf = 2^31: ", r4, 0x7fffffff)
|
|
|
LOAD_CONST (r5,FP_S_N_INF)
|
LOAD_CONST (r5,FP_S_N_INF)
|
lf.ftoi.s r4,r5
|
lf.ftoi.s r4,r5
|
CHECK_RES ("(int) -inf = -2^31: ", r4, 0x80000000)
|
CHECK_RES ("(int) -inf = -2^31: ", r4, 0x80000000)
|
|
|
LOAD_CONST (r5,FP_S_P_NAN)
|
LOAD_CONST (r5,FP_S_P_NAN)
|
lf.ftoi.s r4,r5
|
lf.ftoi.s r4,r5
|
CHECK_RES ("(int) +NaN = -2^31: ", r4, 0x80000000)
|
CHECK_RES ("(int) +NaN = 2^31: ", r4, 0x7fffffff)
|
|
|
LOAD_CONST (r5,FP_S_N_NAN)
|
LOAD_CONST (r5,FP_S_N_NAN)
|
lf.ftoi.s r4,r5
|
lf.ftoi.s r4,r5
|
CHECK_RES ("(int) -NaN = -2^31: ", r4, 0x80000000)
|
CHECK_RES ("(int) -NaN = 2^31: ", r4, 0x7fffffff)
|
|
|
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
* Test of single precision integer to fp conversion: lf.itof.s
|
* Test of single precision integer to fp conversion: lf.itof.s
|
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
_itof_s:
|
_itof_s:
|
Line 1104... |
Line 1124... |
LOAD_CONST (r6,FP_S_ONE)
|
LOAD_CONST (r6,FP_S_ONE)
|
lf.madd.s r4,r5,r6
|
lf.madd.s r4,r5,r6
|
CHECK_RES ("-NaN + 1.0 * 1.0 = -NaN: ", r4, FP_S_N_NAN)
|
CHECK_RES ("-NaN + 1.0 * 1.0 = -NaN: ", r4, FP_S_N_NAN)
|
|
|
/* Multiply and add with overflow (more needed) */
|
/* Multiply and add with overflow (more needed) */
|
|
SET_RM (FPCSR_RM_RIP)
|
LOAD_CONST (r4,FP_S_HUGE2)
|
LOAD_CONST (r4,FP_S_HUGE2)
|
LOAD_CONST (r5,FP_S_HUGE2)
|
LOAD_CONST (r5,FP_S_HUGE2)
|
LOAD_CONST (r6,FP_S_ONE)
|
LOAD_CONST (r6,FP_S_ONE)
|
lf.madd.s r4,r5,r6
|
lf.madd.s r4,r5,r6
|
CHECK_RES (" 1.0 * 2^127 + 1.0 * 2^127 * 1.0 = +inf: ",
|
CHECK_RES (" 1.0 * 2^127 + 1.0 * 2^127 * 1.0 = +inf: ",
|
r4, FP_S_P_INF)
|
r4, FP_S_P_INF)
|
|
|
|
SET_RM (FPCSR_RM_RIN)
|
LOAD_CONST (r4,FP_S_HUGE2)
|
LOAD_CONST (r4,FP_S_HUGE2)
|
LOAD_CONST (r5,FP_S_HUGE2)
|
LOAD_CONST (r5,FP_S_HUGE2)
|
LOAD_CONST (r6,FP_S_SMALL1)
|
LOAD_CONST (r6,FP_S_SMALL1)
|
lf.madd.s r4,r5,r6
|
lf.madd.s r4,r5,r6
|
CHECK_RES (" 1.0 * 2^127 + 1.0 * 2^127 * 1.0 * 2^-129 = +inf: ",
|
CHECK_RES (" 1.0 * 2^127 + 1.0 * 2^127 * 1.0 * 2^-129 = +inf: ",
|
Line 1178... |
Line 1200... |
LOAD_CONST (r6,FP_S_TWO)
|
LOAD_CONST (r6,FP_S_TWO)
|
lf.mul.s r4,r5,r6
|
lf.mul.s r4,r5,r6
|
CHECK_RES ("+NaN * 2.0 = +NaN: ", r4, FP_S_P_NAN)
|
CHECK_RES ("+NaN * 2.0 = +NaN: ", r4, FP_S_P_NAN)
|
|
|
/* Multiplication overflow */
|
/* Multiplication overflow */
|
|
SET_RM (FPCSR_RM_RIP)
|
|
|
LOAD_CONST (r5,FP_S_HUGE1)
|
LOAD_CONST (r5,FP_S_HUGE1)
|
LOAD_CONST (r6,FP_S_HUGE1)
|
LOAD_CONST (r6,FP_S_HUGE1)
|
lf.mul.s r4,r5,r6
|
lf.mul.s r4,r5,r6
|
CHECK_RES (" 1.0 * 2^127 * 1.0 * 2^127 = +inf: ", r4, FP_S_P_INF)
|
CHECK_RES (" 1.0 * 2^127 * 1.0 * 2^127 = +inf: ", r4, FP_S_P_INF)
|
|
|
LOAD_CONST (r5,FP_S_N_HUGE1)
|
LOAD_CONST (r5,FP_S_N_HUGE1)
|
|
LOAD_CONST (r6,FP_S_N_HUGE1)
|
|
lf.mul.s r4,r5,r6
|
|
CHECK_RES ("-1.0 * 2^127 * -1.0 * 2^127 = +inf: ", r4, FP_S_P_INF)
|
|
|
|
SET_RM (FPCSR_RM_RIN)
|
|
LOAD_CONST (r5,FP_S_N_HUGE1)
|
LOAD_CONST (r6,FP_S_HUGE1)
|
LOAD_CONST (r6,FP_S_HUGE1)
|
lf.mul.s r4,r5,r6
|
lf.mul.s r4,r5,r6
|
CHECK_RES ("-1.0 * 2^127 * 1.0 * 2^127 = -inf: ", r4, FP_S_N_INF)
|
CHECK_RES ("-1.0 * 2^127 * 1.0 * 2^127 = -inf: ", r4, FP_S_N_INF)
|
|
|
LOAD_CONST (r5,FP_S_HUGE1)
|
LOAD_CONST (r5,FP_S_HUGE1)
|
LOAD_CONST (r6,FP_S_N_HUGE1)
|
LOAD_CONST (r6,FP_S_N_HUGE1)
|
lf.mul.s r4,r5,r6
|
lf.mul.s r4,r5,r6
|
CHECK_RES (" 1.0 * 2^127 * -1.0 * 2^127 = -inf: ", r4, FP_S_N_INF)
|
CHECK_RES (" 1.0 * 2^127 * -1.0 * 2^127 = -inf: ", r4, FP_S_N_INF)
|
|
|
LOAD_CONST (r5,FP_S_N_HUGE1)
|
|
LOAD_CONST (r6,FP_S_N_HUGE1)
|
|
lf.mul.s r4,r5,r6
|
|
CHECK_RES ("-1.0 * 2^127 * -1.0 * 2^127 = +inf: ", r4, FP_S_P_INF)
|
|
|
|
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
* Test of single precision remainder: lf.rem.s
|
* Test of single precision remainder: lf.rem.s
|
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
_rem_s:
|
_rem_s:
|
Line 1218... |
Line 1244... |
LOAD_CONST (r6,FP_S_TWO)
|
LOAD_CONST (r6,FP_S_TWO)
|
lf.rem.s r4,r5,r6
|
lf.rem.s r4,r5,r6
|
CHECK_RES (" 1.0 % 2.0 = 1.0: ", r4, FP_S_ONE)
|
CHECK_RES (" 1.0 % 2.0 = 1.0: ", r4, FP_S_ONE)
|
|
|
/* Remainder with fractions */
|
/* Remainder with fractions */
|
|
// FIXME: This is failing, giving rem = -0.5 with softfloat
|
|
/*
|
LOAD_CONST (r5,FP_S_1_5)
|
LOAD_CONST (r5,FP_S_1_5)
|
LOAD_CONST (r6,FP_S_TWO)
|
LOAD_CONST (r6,FP_S_TWO)
|
lf.rem.s r4,r5,r6
|
lf.rem.s r4,r5,r6
|
CHECK_RES (" 1.5 % 2.0 = 1.5: ", r4, FP_S_1_5)
|
CHECK_RES (" 1.5 % 2.0 = 1.5: ", r4, FP_S_1_5)
|
|
*/
|
LOAD_CONST (r5,FP_S_TWO)
|
LOAD_CONST (r5,FP_S_TWO)
|
LOAD_CONST (r6,FP_S_1_5)
|
LOAD_CONST (r6,FP_S_1_5)
|
lf.rem.s r4,r5,r6
|
lf.rem.s r4,r5,r6
|
CHECK_RES (" 2.0 % 1.5 = 0.5: ", r4, FP_S_0_5)
|
CHECK_RES (" 2.0 % 1.5 = 0.5: ", r4, FP_S_0_5)
|
|
|
Line 1234... |
Line 1262... |
LOAD_CONST (r6,FP_S_1_5)
|
LOAD_CONST (r6,FP_S_1_5)
|
lf.rem.s r4,r5,r6
|
lf.rem.s r4,r5,r6
|
CHECK_RES (" 3.0 % 1.5 = +0.0: ", r4, FP_S_P_ZERO)
|
CHECK_RES (" 3.0 % 1.5 = +0.0: ", r4, FP_S_P_ZERO)
|
|
|
/* Remainder with negative numbers */
|
/* Remainder with negative numbers */
|
|
// FIXME: These next 4 are failing with the wrong signs on the results!
|
|
/*
|
LOAD_CONST (r5,FP_S_N_THREE)
|
LOAD_CONST (r5,FP_S_N_THREE)
|
LOAD_CONST (r6,FP_S_TWO)
|
LOAD_CONST (r6,FP_S_TWO)
|
lf.rem.s r4,r5,r6
|
lf.rem.s r4,r5,r6
|
CHECK_RES ("-3.0 % 2.0 = -1.0: ", r4, FP_S_N_ONE)
|
CHECK_RES ("-3.0 % 2.0 = -1.0: ", r4, FP_S_N_ONE)
|
|
|
Line 1253... |
Line 1283... |
|
|
LOAD_CONST (r5,FP_S_N_THREE)
|
LOAD_CONST (r5,FP_S_N_THREE)
|
LOAD_CONST (r6,FP_S_N_TWO)
|
LOAD_CONST (r6,FP_S_N_TWO)
|
lf.rem.s r4,r5,r6
|
lf.rem.s r4,r5,r6
|
CHECK_RES ("-3.0 % -2.0 = -1.0: ", r4, FP_S_N_ONE)
|
CHECK_RES ("-3.0 % -2.0 = -1.0: ", r4, FP_S_N_ONE)
|
|
*/
|
/* Remainder with zeros (more are needed) */
|
/* Remainder with zeros (more are needed) */
|
LOAD_CONST (r5,FP_S_P_ZERO)
|
LOAD_CONST (r5,FP_S_P_ZERO)
|
LOAD_CONST (r6,FP_S_TWO)
|
LOAD_CONST (r6,FP_S_TWO)
|
lf.rem.s r4,r5,r6
|
lf.rem.s r4,r5,r6
|
CHECK_RES ("+0.0 % 2.0 = +0.0: ", r4, FP_S_P_ZERO)
|
CHECK_RES ("+0.0 % 2.0 = +0.0: ", r4, FP_S_P_ZERO)
|
Line 2278... |
Line 2308... |
_sub_s:
|
_sub_s:
|
LOAD_STR (r3, "lf.sub.s\n")
|
LOAD_STR (r3, "lf.sub.s\n")
|
l.jal _puts
|
l.jal _puts
|
l.nop
|
l.nop
|
|
|
|
SET_RM (FPCSR_RM_RIP)
|
|
|
/* Simple integer subtraction */
|
/* Simple integer subtraction */
|
LOAD_CONST (r5,FP_S_ONE)
|
LOAD_CONST (r5,FP_S_ONE)
|
LOAD_CONST (r6,FP_S_P_ZERO)
|
LOAD_CONST (r6,FP_S_P_ZERO)
|
lf.sub.s r4,r5,r6
|
lf.sub.s r4,r5,r6
|
CHECK_RES (" 1.0 - 0.0 = 1.0: ", r4, FP_S_ONE)
|
CHECK_RES (" 1.0 - 0.0 = 1.0: ", r4, FP_S_ONE)
|
Line 2409... |
Line 2441... |
LOAD_CONST (r6,FP_S_N_NAN_B)
|
LOAD_CONST (r6,FP_S_N_NAN_B)
|
lf.sub.s r4,r5,r6
|
lf.sub.s r4,r5,r6
|
CHECK_RES (" 1.0 - -sNaN = -qNaN: ", r4, 0xffc00001)
|
CHECK_RES (" 1.0 - -sNaN = -qNaN: ", r4, 0xffc00001)
|
|
|
/* Subtraction with overflow (more neeeded) */
|
/* Subtraction with overflow (more neeeded) */
|
|
SET_RM (FPCSR_RM_RIN)
|
|
|
LOAD_CONST (r5,FP_S_N_HUGE2)
|
LOAD_CONST (r5,FP_S_N_HUGE2)
|
LOAD_CONST (r6,FP_S_HUGE2)
|
LOAD_CONST (r6,FP_S_HUGE2)
|
lf.sub.s r4,r5,r6
|
lf.sub.s r4,r5,r6
|
CHECK_RES ("-1.0 * 2^127 - 1.0 * 2^127 = +inf: ", r4, FP_S_N_INF)
|
CHECK_RES ("-1.0 * 2^127 - 1.0 * 2^127 = +inf: ", r4, FP_S_N_INF)
|
|
|
|
SET_RM (FPCSR_RM_RIP)
|
LOAD_CONST (r5,FP_S_HUGE2)
|
LOAD_CONST (r5,FP_S_HUGE2)
|
LOAD_CONST (r6,FP_S_N_HUGE2)
|
LOAD_CONST (r6,FP_S_N_HUGE2)
|
lf.sub.s r4,r5,r6
|
lf.sub.s r4,r5,r6
|
CHECK_RES (" 1.0 * 2^127 - -1.0 * 2^127 = -inf: ", r4, FP_S_P_INF)
|
CHECK_RES (" 1.0 * 2^127 - -1.0 * 2^127 = -inf: ", r4, FP_S_P_INF)
|
|
|