Ejemplo n.º 1
0
def test_hypothesis_mulAddF64(a, b, c):

    expWidth = 11
    sigWidth = 53
    precision = expWidth + sigWidth
    tolerance = 0.0000001

    out = a * b + c

    op = 0  # fixed at this mode
    a = floatToFN(a, precision=precision)
    b = floatToFN(b, precision=precision)
    c = floatToFN(c, precision=precision)
    out = floatToFN(out, precision=precision)

    run_tv_test(
        MulAddFN(expWidth=expWidth, sigWidth=sigWidth),
        [
            #  op   a   b   c   roundingMode  out*'),
            [
                op,
                a,
                b,
                c,
                0,
                out,
            ],
        ],
        precision,
        tolerance)
Ejemplo n.º 2
0
def test_hypothesis_subF64(a, b):

    expWidth = 11
    sigWidth = 53
    precision = expWidth + sigWidth
    tolerance = 0.00000000001

    out = a - b

    a = floatToFN(a, precision=precision)
    b = floatToFN(b, precision=precision)
    out = floatToFN(out, precision=precision)

    run_tv_test(
        AddFN(expWidth=expWidth, sigWidth=sigWidth),
        [
            #  subOp  a   b   roundingMode   out*'),
            [
                1,
                a,
                b,
                0,
                out,
            ],
        ],
        precision,
        tolerance)
Ejemplo n.º 3
0
def test_subF16_positive_positive():

    expWidth = 5
    sigWidth = 11
    precision = expWidth + sigWidth
    tolerance = 0.001

    a = 17.61
    b = 231.41
    out = a - b

    a = floatToFN(a, precision=precision)
    b = floatToFN(b, precision=precision)
    out = floatToFN(out, precision=precision)

    run_tv_test(
        AddFN(expWidth=expWidth, sigWidth=sigWidth),
        [
            #  subOp  a   b   roundingMode   out*'),
            [
                1,
                a,
                b,
                0,
                out,
            ],
        ],
        precision,
        tolerance)
Ejemplo n.º 4
0
def test_addF64_positive_negative():

    expWidth = 11
    sigWidth = 53
    precision = expWidth + sigWidth
    tolerance = 0.000001

    BN = mk_bits(expWidth + sigWidth)

    a = 288.999102
    b = -12.59101
    out = a + b

    a = floatToFN(a, precision=precision)
    b = floatToFN(b, precision=precision)
    out = floatToFN(out, precision=precision)

    run_tv_test(
        AddFN(expWidth=expWidth, sigWidth=sigWidth),
        [
            #  subOp  a   b   roundingMode   out*'),
            [
                0,
                a,
                b,
                0,
                out,
            ],
        ],
        precision,
        tolerance)
Ejemplo n.º 5
0
def test_addF64_positive_positive():

    expWidth = 11
    sigWidth = 53
    precision = expWidth + sigWidth
    tolerance = 0.000001

    BN = mk_bits(expWidth + sigWidth)

    a = 1829591.29201
    b = 58285.0291
    out = a + b

    a = floatToFN(a, precision=precision)
    b = floatToFN(b, precision=precision)
    out = floatToFN(out, precision=precision)

    run_tv_test(
        AddFN(expWidth=expWidth, sigWidth=sigWidth),
        [
            #  subOp  a   b   roundingMode   out*'),
            [
                0,
                a,
                b,
                0,
                out,
            ],
        ],
        precision,
        tolerance)
Ejemplo n.º 6
0
def test_subF32_negative_negative():

    expWidth = 8
    sigWidth = 24
    precision = expWidth + sigWidth
    tolerance = 0.0001

    BN = mk_bits(expWidth + sigWidth)

    a = -692.21
    b = -12.49102
    out = a - b

    a = floatToFN(a, precision=precision)
    b = floatToFN(b, precision=precision)
    out = floatToFN(out, precision=precision)

    run_tv_test(
        AddFN(expWidth=expWidth, sigWidth=sigWidth),
        [
            #  subOp  a   b   roundingMode   out*'),
            [
                1,
                a,
                b,
                0,
                out,
            ],
        ],
        precision,
        tolerance)
Ejemplo n.º 7
0
def test_mulAddF64_random():

    expWidth = 11
    sigWidth = 53
    precision = expWidth + sigWidth
    tolerance = 0.0001

    random.seed(0)

    op = 0  # fixed at this mode

    test_vector = []

    for test in range(500):
        a = get_rand(-100000.0, 100000.0, 10)
        b = get_rand(-100000.0, 100000.0, 10)
        c = get_rand(-100000.0, 100000.0, 10)

        for op in range(4):
            out = mul_add_op(a, b, c, op)

            a = floatToFN(a, precision=precision)
            b = floatToFN(b, precision=precision)
            c = floatToFN(c, precision=precision)
            out = floatToFN(out, precision=precision)

            test_vector.append([op, a, b, c, 0, out])

    run_tv_test(MulAddFN(expWidth=expWidth, sigWidth=sigWidth), test_vector,
                precision, tolerance)
Ejemplo n.º 8
0
def test_addF64_negative_negative():

    expWidth = 11
    sigWidth = 53
    precision = expWidth + sigWidth
    tolerance = 0.000001

    BN = mk_bits(expWidth + sigWidth)

    a = -192.491023
    b = -5.92929192931823
    out = a + b

    a = floatToFN(a, precision=precision)
    b = floatToFN(b, precision=precision)
    out = floatToFN(out, precision=precision)

    run_tv_test(
        AddFN(expWidth=expWidth, sigWidth=sigWidth),
        [
            #  subOp  a   b   roundingMode   out*'),
            [
                0,
                a,
                b,
                0,
                out,
            ],
        ],
        precision,
        tolerance)
Ejemplo n.º 9
0
def test_subF64_negative_negative():

    expWidth = 11
    sigWidth = 53
    precision = expWidth + sigWidth
    tolerance = 0.000001

    BN = mk_bits(expWidth + sigWidth)

    a = -58182.1913
    b = -1293.10092
    out = a - b

    a = floatToFN(a, precision=precision)
    b = floatToFN(b, precision=precision)
    out = floatToFN(out, precision=precision)

    run_tv_test(
        AddFN(expWidth=expWidth, sigWidth=sigWidth),
        [
            #  subOp  a   b   roundingMode   out*'),
            [
                1,
                a,
                b,
                0,
                out,
            ],
        ],
        precision,
        tolerance)
Ejemplo n.º 10
0
def test_subF64_positive_negative():

    expWidth = 11
    sigWidth = 53
    precision = expWidth + sigWidth
    tolerance = 0.000001

    BN = mk_bits(expWidth + sigWidth)

    a = 1829.5982182
    b = -239484.000192
    out = a - b

    a = floatToFN(a, precision=precision)
    b = floatToFN(b, precision=precision)
    out = floatToFN(out, precision=precision)

    run_tv_test(
        AddFN(expWidth=expWidth, sigWidth=sigWidth),
        [
            #  subOp  a   b   roundingMode   out*'),
            [
                1,
                a,
                b,
                0,
                out,
            ],
        ],
        precision,
        tolerance)
Ejemplo n.º 11
0
def test_addF16_ones():

    expWidth = 5
    sigWidth = 11
    precision = expWidth + sigWidth
    tolerance = 0.001

    a = 1.0
    b = 1.0
    out = a + b

    a = floatToFN(a, precision=precision)
    b = floatToFN(b, precision=precision)
    out = floatToFN(out, precision=precision)

    run_tv_test(
        AddFN(expWidth=expWidth, sigWidth=sigWidth),
        [
            #  subOp a   b   roundingMode  out*'),
            [
                0,
                a,
                b,
                0,
                out,
            ],
        ],
        precision,
        tolerance)
Ejemplo n.º 12
0
def test_subF32_random():

    expWidth = 8
    sigWidth = 24
    precision = expWidth + sigWidth
    tolerance = 0.001

    BN = mk_bits(expWidth + sigWidth)

    random.seed(precision)

    test_vector = []

    for test in range(100):
        a = get_rand(-1000.0, 1000.0, 4)
        b = get_rand(-1000.0, 1000.0, 4)
        out = a - b

        a = floatToFN(a, precision=precision)
        b = floatToFN(b, precision=precision)
        out = floatToFN(out, precision=precision)

        test_vector.append([1, a, b, 0, out])

    run_tv_test(AddFN(expWidth=expWidth, sigWidth=sigWidth), test_vector,
                precision, tolerance)
Ejemplo n.º 13
0
def test_subF64_random():

    expWidth = 11
    sigWidth = 53
    precision = expWidth + sigWidth
    tolerance = 0.000001

    BN = mk_bits(expWidth + sigWidth)

    random.seed(a=None)  # uses current system time for seed

    test_vector = []

    for test in range(100):
        a = get_rand(-3000.0, 3000.0, 6)
        b = get_rand(-3000.0, 3000.0, 6)
        out = a - b

        a = floatToFN(a, precision=precision)
        b = floatToFN(b, precision=precision)
        out = floatToFN(out, precision=precision)

        test_vector.append([1, a, b, 0, out])

    run_tv_test(AddFN(expWidth=expWidth, sigWidth=sigWidth), test_vector,
                precision, tolerance)
Ejemplo n.º 14
0
def test_subF16_negative_negative():

    expWidth = 5
    sigWidth = 11
    precision = expWidth + sigWidth
    tolerance = 0.001

    BN = mk_bits(expWidth + sigWidth)

    a = -127.41
    b = -451.61
    out = a - b

    a = floatToFN(a, precision=precision)
    b = floatToFN(b, precision=precision)
    out = floatToFN(out, precision=precision)

    run_tv_test(
        AddFN(expWidth=expWidth, sigWidth=sigWidth),
        [
            #  subOp  a   b   roundingMode   out*'),
            [
                1,
                a,
                b,
                0,
                out,
            ],
        ],
        precision,
        tolerance)
Ejemplo n.º 15
0
def test_addF32_negative_negative():

    expWidth = 8
    sigWidth = 24
    precision = expWidth + sigWidth
    tolerance = 0.0001

    BN = mk_bits(expWidth + sigWidth)

    a = -385.01
    b = -591.2021
    out = a + b

    a = floatToFN(a, precision=precision)
    b = floatToFN(b, precision=precision)
    out = floatToFN(out, precision=precision)

    run_tv_test(
        AddFN(expWidth=expWidth, sigWidth=sigWidth),
        [
            #  subOp  a   b   roundingMode   out*'),
            [
                0,
                a,
                b,
                0,
                out,
            ],
        ],
        precision,
        tolerance)
Ejemplo n.º 16
0
def test_addF16_integer():
  precision = 16
  tolerance = 0.01

  in_float  = 24
  in_rec    = floatToFN(in_float, precision=precision)
  out_float = fNToFloat(in_rec, precision=precision)

  assert abs(in_float - out_float) < tolerance

  in_float  = -58.0
  in_rec    = floatToFN(in_float, precision=precision)
  out_float = fNToFloat(in_rec, precision=precision)

  assert abs(in_float - out_float) < tolerance
Ejemplo n.º 17
0
def test_addF64_integer():
  precision = 64
  tolerance = 0.00000001

  in_float  = 481331.0
  in_rec    = floatToFN(in_float, precision=precision)
  out_float = fNToFloat(in_rec, precision=precision)

  assert abs(in_float - out_float) < tolerance

  in_float  = -5818283
  in_rec    = floatToFN(in_float, precision=precision)
  out_float = fNToFloat(in_rec, precision=precision)

  assert abs(in_float - out_float) < tolerance
Ejemplo n.º 18
0
def test_addF64_abs_less_than_one():
  precision = 64
  tolerance = 0.00000001

  in_float  = 0.299994812
  in_rec    = floatToFN(in_float, precision=precision)
  out_float = fNToFloat(in_rec, precision=precision)

  assert abs(in_float - out_float) < tolerance

  in_float  = -0.2300001
  in_rec    = floatToFN(in_float, precision=precision)
  out_float = fNToFloat(in_rec, precision=precision)

  assert abs(in_float - out_float) < tolerance
Ejemplo n.º 19
0
def test_addF16_abs_less_than_one():
  precision = 16
  tolerance = 0.01

  in_float  = 0.52
  in_rec    = floatToFN(in_float, precision=precision)
  out_float = fNToFloat(in_rec, precision=precision)

  assert abs(in_float - out_float) < tolerance

  in_float  = -0.12
  in_rec    = floatToFN(in_float, precision=precision)
  out_float = fNToFloat(in_rec, precision=precision)

  assert abs(in_float - out_float) < tolerance
Ejemplo n.º 20
0
def test_addF32_abs_less_than_one():
  precision = 32
  tolerance = 0.000001

  in_float  = 0.29481
  in_rec    = floatToFN(in_float, precision=precision)
  out_float = fNToFloat(in_rec, precision=precision)

  assert abs(in_float - out_float) < tolerance

  in_float  = -0.511003
  in_rec    = floatToFN(in_float, precision=precision)
  out_float = fNToFloat(in_rec, precision=precision)

  assert abs(in_float - out_float) < tolerance
Ejemplo n.º 21
0
def test_addF32_integer():
  precision = 32
  tolerance = 0.000001

  in_float  = 5819
  in_rec    = floatToFN(in_float, precision=precision)
  out_float = fNToFloat(in_rec, precision=precision)

  assert abs(in_float - out_float) < tolerance

  in_float  = -9930.0
  in_rec    = floatToFN(in_float, precision=precision)
  out_float = fNToFloat(in_rec, precision=precision)

  assert abs(in_float - out_float) < tolerance
Ejemplo n.º 22
0
def test_hypothesis_64_small( in_float ):

  in_rec    = floatToFN(in_float, precision=64)
  out_float = fNToFloat(in_rec, precision=64)
  print(in_float, hex(in_rec), out_float)

  assert in_float == out_float
Ejemplo n.º 23
0
def test_hypothesis_mulF64( a, b ):

  expWidth = 11
  sigWidth = 53
  precision = expWidth + sigWidth
  tolerance = 0.000001

  out = a * b

  a = floatToFN(a, precision=precision)
  b = floatToFN(b, precision=precision)
  out = floatToFN(out, precision=precision)

  run_tv_test( MulFN(expWidth = expWidth, sigWidth = sigWidth), [
    #   a   b   roundingMode  out*'),
    [   a,  b,  0,            out ],
  ],  precision, tolerance)
Ejemplo n.º 24
0
def test_hypothesis_32( in_float ):

  in_rec    = floatToFN(in_float, precision=32)
  out_float = fNToFloat(in_rec, precision=32)
  print(in_float, hex(in_rec), out_float)

  if math.isnan(in_float):  assert math.isnan(out_float)
  else:                     assert in_float == out_float
Ejemplo n.º 25
0
def test_addF64_negative():
  precision = 64
  tolerance = 0.00000001

  in_float  = -18884.101
  in_rec    = floatToFN(in_float, precision=precision)
  out_float = fNToFloat(in_rec, precision=precision)

  assert abs(in_float - out_float) < tolerance
Ejemplo n.º 26
0
def test_addF64_trailing_zeroes():
  precision = 64
  tolerance = 0.00000001

  in_float  = 3919.0000192
  in_rec    = floatToFN(in_float, precision=precision)
  out_float = fNToFloat(in_rec, precision=precision)

  assert abs(in_float - out_float) < tolerance
Ejemplo n.º 27
0
def test_addF16_negative():
  precision = 16
  tolerance = 0.01

  in_float  = -18.49
  in_rec    = floatToFN(in_float, precision=precision)
  out_float = fNToFloat(in_rec, precision=precision)

  assert abs(in_float - out_float) < tolerance
Ejemplo n.º 28
0
def test_addF16_trailing_zeroes():
  precision = 16
  tolerance = 0.01

  in_float  = 12.008
  in_rec    = floatToFN(in_float, precision=precision)
  out_float = fNToFloat(in_rec, precision=precision)

  assert abs(in_float - out_float) < tolerance
Ejemplo n.º 29
0
def test_addF32_trailing_zeroes():
  precision = 32
  tolerance = 0.0001

  in_float  = 1289.00019
  in_rec    = floatToFN(in_float, precision=precision)
  out_float = fNToFloat(in_rec, precision=precision)

  assert abs(in_float - out_float) < tolerance
Ejemplo n.º 30
0
def test_addF64_positive():
  precision = 64
  tolerance = 0.00000001

  in_float  = 27367198.201812
  in_rec    = floatToFN(in_float, precision=precision)
  out_float = fNToFloat(in_rec, precision=precision)

  assert abs(in_float - out_float) < tolerance