Re: [myhdl-list] intbv return types and a fixed-point Object
Brought to you by:
jandecaluwe
From: Felton C. <chr...@gm...> - 2009-05-15 11:12:28
|
>> > > No, I think it would be straighforward. I expect that everything that > works now would continue working, except that you could do some > additional things. In particular, you could index and slice an > arithmetic expression. > > The only price would be simulation performance hit. The question is > whether this is worthwhile for a feature that is seldom (?) used. > Someone would have to analyze this in detail to make a good > decision. Perhaps the performance hit is irrelevant - I don't know. > > Jan > I took some time to profile this change. I used the python built-in cProfile. Below are some numbers (warning lots of stuff below). The results are a little interesting. The total time for the math ops (__add__) effectively doubled. But the overall simulation time increased slightly. From this limited test case (more needs to be done) I would conclude that having the intbv math ops return and intbv type is little effect on overall simulation performance. The change was to the _intbv.py. All math operations were changed to return a intbv type versus an int type. This also suggests that a fair amount of simulation time is spent on other areas. If these other areas are ever change to be more efficient this change could have more effect on overall performance. Intbv Math returns Int Type --------------Start Test Loop-------------- --------------End Test Loop---------------- 10935715 function calls (10900641 primitive calls) in 26.753 CPU seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno(function) 1 0.000 0.000 26.753 26.753 <string>:1(<module>) 10 0.000 0.000 0.000 0.000 _Signal.py:155(_clear) 351088 2.770 0.000 4.089 0.000 _Signal.py:162(_update) 351088 1.268 0.000 14.802 0.000 _Signal.py:191(_set_next) 35070 0.036 0.000 0.036 0.000 _Signal.py: 204(_get_negedge) 70250 0.107 0.000 0.107 0.000 _Signal.py: 235(_setNextBool) 280838 2.165 0.000 12.916 0.000 _Signal.py: 245(_setNextIntbv) 140496 0.157 0.000 0.157 0.000 _Signal.py: 282(__nonzero__) 69447 0.270 0.000 0.463 0.000 _Signal.py:300(__add__) 70148 0.296 0.000 0.466 0.000 _Signal.py:308(__sub__) 35074 0.166 0.000 0.264 0.000 _Signal.py:316(__mul__) 35074 0.118 0.000 0.172 0.000 _Signal.py:420(__int__) 35074 0.072 0.000 0.271 0.000 _Signal.py:437(__cmp__) 1 0.000 0.000 0.000 0.000 _Simulation.py: 72(_finalize) 1 2.196 2.196 26.753 26.753 _Simulation.py:92(run) 70249 0.295 0.000 1.320 0.000 _Waiter.py:123(next) 70250 0.247 0.000 15.794 0.000 _Waiter.py:136(next) 35073 0.338 0.000 2.967 0.000 _Waiter.py:51(next) 140499 0.270 0.000 16.513 0.000 _always.py:98(genfunc) 2 0.000 0.000 0.000 0.000 _delay.py:29(__init__) 563219 0.421 0.000 0.421 0.000 _intbv.py: 105(__nonzero__) 69447 0.110 0.000 0.149 0.000 _intbv.py:187(__add__) 70148 0.114 0.000 0.140 0.000 _intbv.py:195(__sub__) 35074 0.071 0.000 0.083 0.000 _intbv.py:203(__mul__) 279149 1.902 0.000 3.267 0.000 _intbv.py:36(__init__) 35074 0.054 0.000 0.054 0.000 _intbv.py:406(__int__) 315912 0.671 0.000 0.981 0.000 _intbv.py:424(__cmp__) 559987 1.387 0.000 1.387 0.000 _intbv.py: 76(_checkBounds) 279149 0.584 0.000 3.851 0.000 _intbv.py: 95(__deepcopy__) Intbv Math returns Intbv Type --------------Start Test Loop-------------- --------------End Test Loop---------------- 11460400 function calls (11425326 primitive calls) in 28.543 CPU seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno(function) 1 0.000 0.000 28.543 28.543 <string>:1(<module>) 10 0.000 0.000 0.000 0.000 _Signal.py:155(_clear) 351088 2.758 0.000 4.080 0.000 _Signal.py:162(_update) 351088 1.286 0.000 14.785 0.000 _Signal.py:191(_set_next) 35070 0.034 0.000 0.034 0.000 _Signal.py: 204(_get_negedge) 70250 0.114 0.000 0.114 0.000 _Signal.py: 235(_setNextBool) 280838 2.050 0.000 12.881 0.000 _Signal.py: 245(_setNextIntbv) 140496 0.169 0.000 0.169 0.000 _Signal.py: 282(__nonzero__) 69447 0.269 0.000 0.984 0.000 _Signal.py:300(__add__) 70148 0.296 0.000 0.983 0.000 _Signal.py:308(__sub__) 35074 0.159 0.000 0.530 0.000 _Signal.py:316(__mul__) 35074 0.117 0.000 0.175 0.000 _Signal.py:420(__int__) 35074 0.070 0.000 0.281 0.000 _Signal.py:437(__cmp__) 1 0.000 0.000 0.000 0.000 _Simulation.py: 72(_finalize) 1 2.175 2.175 28.543 28.543 _Simulation.py:92(run) 70249 0.285 0.000 1.291 0.000 _Waiter.py:123(next) 70250 0.258 0.000 17.623 0.000 _Waiter.py:136(next) 35073 0.321 0.000 2.976 0.000 _Waiter.py:51(next) 140499 0.248 0.000 18.311 0.000 _always.py:98(genfunc) 2 0.000 0.000 0.000 0.000 _delay.py:29(__init__) 563215 0.417 0.000 0.417 0.000 _intbv.py: 105(__nonzero__) 69447 0.231 0.000 0.672 0.000 _intbv.py:187(__add__) 70148 0.229 0.000 0.657 0.000 _intbv.py:195(__sub__) 35074 0.132 0.000 0.356 0.000 _intbv.py:203(__mul__) 35074 0.115 0.000 0.343 0.000 _intbv.py:261(__rshift__) 488891 2.733 0.000 4.493 0.000 _intbv.py:36(__init__) 35074 0.057 0.000 0.057 0.000 _intbv.py:406(__int__) 315912 0.674 0.000 0.992 0.000 _intbv.py:424(__cmp__) 769729 1.710 0.000 1.710 0.000 _intbv.py: 76(_checkBounds) 279148 0.606 0.000 3.890 0.000 _intbv.py: 95(__deepcopy__) def mathSys1(clk, rst, x, y, N_BITS = 14): """ """ M0 = 2**(N_BITS-1) M1 = 2**(2*N_BITS-1) M2 = 2**(20*N_BITS-1) sine = Signal(intbv(0, min=-M0, max=M0)) v1 = Signal(intbv(0, min=-M1, max=M1)) v1d = Signal(intbv(0, min=-M1, max=M1)) v2 = Signal(intbv(0, min=-2*M1, max=2*M1)) v3 = Signal(intbv(0, min=-M2, max=M2)) i1 = sine_table(clk, rst, sine, N_BITS=N_BITS) @always(clk.posedge) def rtl(): if rst: v1.next = 0 v1d.next = 0 v2.next = 0 v3.next = 0 else: v1.next = x * sine v2.next = v1 - v1d v1d.next = v1 v3.next = (v3 + v2) >> N_BITS y.next = v3 - v1 #print '.... ', v1, v1d, v2, v3, y return i1, rtl |