File: test_longdiv.py

package info (click to toggle)
myhdl 0.11-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,728 kB
  • sloc: python: 25,033; ansic: 2,203; makefile: 243; sh: 206
file content (84 lines) | stat: -rw-r--r-- 2,097 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from __future__ import absolute_import
import myhdl
from myhdl import *

from glibc_random import glibc_random

from long_divider import long_divider

def test_longdiv(nrvectors=2**18):
    quotient = Signal(intbv(0)[22:])
    ready = Signal(bool())
    dividend = Signal(intbv(0)[38:])
    divisor = Signal(intbv(0)[16:])
    start = Signal(bool())
    clock = Signal(bool())
    reset = Signal(bool())
    stopped = Signal(bool())

    MAXVAL = 2**22 - 1
    
    dut = long_divider(
        quotient,
        ready,
        dividend,
        divisor,
        start,
        clock,
        reset
        )

    @instance
    def clockgen():
        clock.next = 0
        yield delay(10)
        while not stopped:
            clock.next = not clock
            yield delay(10)
        
    @instance
    def stimulus():
        stopped.next = 0
        yield delay(10)
        random_word = intbv(0)[32:]
        p = intbv(0)[16:]
        q = intbv(0)[22:]
        d = intbv(0)[38:]
        yield clock.negedge
        reset.next = 0
        yield clock.negedge
        reset.next = 1
        yield clock.negedge
        reset.next = 0
        start.next = 0
        yield clock.negedge
        random_word[:] = 94
        for i in range(nrvectors):
            yield clock.negedge
            random_word[:] = glibc_random(random_word)
            p[:] = random_word[16:]
            random_word[:] = glibc_random(random_word)
            q[:] = random_word[22:]
            if p == 0:
                q[:] = MAXVAL
            d[:] = p * q
            dividend.next = d
            divisor.next = p
            start.next = 1
            yield clock.negedge
            start.next = 0
            yield ready.posedge
            """compensate for Verilog's non-determinism"""
            yield delay(1) 
            #print d, p, q, quotient
            assert quotient == q
        stopped.next = 1 
        yield delay(10)
        #raise StopSimulation()
            
    return dut, clockgen, stimulus
    
if __name__ == '__main__':    
    sim = Simulation(test_longdiv())
    sim.run()