#! /bin/sh -v

echo ""
echo "Testing ToFloat module"
echo "This script file tests the ToFloat module over a fair range of conditions."
echo ""

# Aaron Stewart
# July 17, 2001

# This tests the ToFloat module over a range of conversions:
#
# Try : test_tofloat quiet
#     : test_tofloat verbose
#
# + int-32 to float-32
# + int-32 to float-64
# + int-64 to float-32
# + int-64 to float-64
# + several custom sizes
# + Wide inputs
#
#  In general, the test consists of comparing the structural design against
#  its behavioral model.  The results also show up on the screen for
#  manual sanity-checks and so you can see what is going on.
#
#  To suppress output, try "test_tofloat quiet".

#  One behavior that is not tested is rounding when the integer is too
#  large to fit in the floating-point value.  This test is omitted because
#  the toFloat module does not support this case.  This case would arise
#  if a custom floating-point format with an extremely restricted exponent
#  range were used.

# These cases should convert exactly:
java tb_toFloat $* in.width=4 out.width=32 out.expWidth=8 signed pipelined  || exit 1
java tb_toFloat $* in.width=4 out.width=32 out.expWidth=8 signed pipelined=false  || exit 1
java tb_toFloat $* in.width=4 out.width=32 out.expWidth=8 signed=false pipelined  || exit 1
java tb_toFloat $* in.width=4 out.width=32 out.expWidth=8 signed=false pipelined=false  || exit 1

java tb_toFloat $* in.width=16 in.exp=0 out.width=32 out.expWidth=8  || exit 1
java tb_toFloat $* in.width=16 in.exp=0 out.width=32 out.expWidth=8 signed  || exit 1

# These cases should convert approximately:
# 32-bit signed int to 32-bit float:
java tb_toFloat $* in.width=32 in.exp=0 out.width=32 out.expWidth=8 signed  || exit 1
java tb_toFloat $* in.width=32 in.exp=0 out.width=32 out.expWidth=8 signed  pipelined || exit 1

# 32-bit signed int to 64-bit double:
java tb_toFloat $* in.width=32 in.exp=0 out.width=64 out.expWidth=11 signed  || exit 1
java tb_toFloat $* in.width=32 in.exp=0 out.width=64 out.expWidth=11 signed pipelined  || exit 1

# 64-bit signed long to 32-bit float:
java tb_toFloat $* in.width=64 in.exp=0 out.width=32 out.expWidth=8 signed  || exit 1
java tb_toFloat $* in.width=64 in.exp=0 out.width=32 out.expWidth=8 signed pipelined  || exit 1

# 64-bit signed long to 64-bit double:
java tb_toFloat $* in.width=64 in.exp=0 out.width=64 out.expWidth=11 signed  || exit 1
java tb_toFloat $* in.width=64 in.exp=0 out.width=64 out.expWidth=11 signed pipelined  || exit 1

# Wide fixed to custom wide float:
java tb_toFloat $* in.width=100 in.exp=-20 out.width=80 out.expWidth=16 signed  || exit 1

# Overflow cases: (It's okay if these fail)
# java tb_toFloat $* in.width=4 in.leftbits=4 out.width=4 out.expWidth=2 iterations=1000 || exit 1
# java tb_toFloat $* in.width=64 in.leftbits=64 out.width=4 out.expWidth=2 iterations=20 || exit 1
#
# But this should pass
java tb_toFloat $* in.width=64 in.exp=0 out.width=10 out.expWidth=8 iterations=20 || exit 1

# This test isn't really necessary, but it's nice to see it work with
# humongous numbers.
# Extra-wide fixed to custom wide float:
#java -Xmx256M tb_toFloat $* in.width=1000 in.exp=0 out.width=500 out.expWidth=16 signed  || exit 1

echo Module toFloat: All Tests PASSED.
