From rsmolin2 at illinois.edu Wed Mar 17 01:46:08 2010 From: rsmolin2 at illinois.edu (Robert Smolinski) Date: Wed, 17 Mar 2010 00:46:08 -0500 Subject: Accessing array of wires Message-ID: <4BA06CA0.8010505@illinois.edu> Hi, I'm just starting out on Ruby-VPI and I'm a little lost on how handles are accessed in this specific case. I have a "reg [79:0] mem[31:0]", I'd like to access mem[0] and such, but I can't find the specific ruby syntax to do so. Is it even possible to access it? Thank you. Rob. From sunaku at gmail.com Wed Mar 17 16:00:57 2010 From: sunaku at gmail.com (Suraj Kurapati) Date: Wed, 17 Mar 2010 13:00:57 -0700 Subject: Accessing array of wires In-Reply-To: <4BA06CA0.8010505@illinois.edu> References: <4BA06CA0.8010505@illinois.edu> Message-ID: On Tue, Mar 16, 2010 at 9:46 PM, Robert Smolinski wrote: > I have a "reg [79:0] mem[31:0]", I'd like to access mem[0] and such, but I > can't find the specific ruby syntax to do so. Is it even possible to access > it? The `mem` here is a "reg array" in VPI terminology (see page 393, section "26.6.7 Regs and reg arrays", of IEEE 1364-2005) because it is a contiguous block of 32 registers, each 80 bits wide. You can convert the "reg array" VPI handle it into a Ruby array (containing new VPI handles that point to the members of the VPI "reg array") by using the VPI::Handle#to_a() method: regs = mem.to_a puts regs[0] # do something with first register regs.each do |reg| # do something with `reg` puts reg end Hope this helps. From rsmolin2 at illinois.edu Wed Mar 17 17:13:35 2010 From: rsmolin2 at illinois.edu (Robert Smolinski) Date: Wed, 17 Mar 2010 16:13:35 -0500 Subject: Accessing array of wires In-Reply-To: References: <4BA06CA0.8010505@illinois.edu> Message-ID: <4BA145FF.2000206@illinois.edu> Suraj Kurapati wrote: > On Tue, Mar 16, 2010 at 9:46 PM, Robert Smolinski wrote: > >> I have a "reg [79:0] mem[31:0]", I'd like to access mem[0] and such, but I >> can't find the specific ruby syntax to do so. Is it even possible to access >> it? >> > > The `mem` here is a "reg array" in VPI terminology (see page 393, > section "26.6.7 Regs and reg arrays", of IEEE 1364-2005) because it is > a contiguous block of 32 registers, each 80 bits wide. > > You can convert the "reg array" VPI handle it into a Ruby array > (containing new VPI handles that point to the members of the VPI "reg > array") by using the VPI::Handle#to_a() method: > > regs = mem.to_a > puts regs[0] # do something with first register > > regs.each do |reg| > # do something with `reg` > puts reg > end > > Hope this helps. > Thanks Suraj. I try "puts DUT.mem.to_a.inspect" which prints "[]". DUT.mem.size == 32 and I'm certain that DUT is the module with mem. Any ideas? From rsmolin2 at illinois.edu Wed Mar 17 21:45:30 2010 From: rsmolin2 at illinois.edu (Robert Smolinski) Date: Wed, 17 Mar 2010 20:45:30 -0500 Subject: Accessing array of wires In-Reply-To: References: <4BA06CA0.8010505@illinois.edu> Message-ID: <4BA185BA.8080609@illinois.edu> Suraj Kurapati wrote: > On Tue, Mar 16, 2010 at 9:46 PM, Robert Smolinski wrote: > >> I have a "reg [79:0] mem[31:0]", I'd like to access mem[0] and such, but I >> can't find the specific ruby syntax to do so. Is it even possible to access >> it? >> > > The `mem` here is a "reg array" in VPI terminology (see page 393, > section "26.6.7 Regs and reg arrays", of IEEE 1364-2005) because it is > a contiguous block of 32 registers, each 80 bits wide. > > You can convert the "reg array" VPI handle it into a Ruby array > (containing new VPI handles that point to the members of the VPI "reg > array") by using the VPI::Handle#to_a() method: > > regs = mem.to_a > puts regs[0] # do something with first register > > regs.each do |reg| > # do something with `reg` > puts reg > end > > Hope this helps. > I print out using DUT.each_vpiNet and it doesn't print out any of the names declared with "reg". I'm running the simulations with cver 2.12.a and ruby-vpi 21.1.0. From sunaku at gmail.com Wed Mar 17 22:55:29 2010 From: sunaku at gmail.com (Suraj Kurapati) Date: Wed, 17 Mar 2010 19:55:29 -0700 Subject: Accessing array of wires In-Reply-To: <4BA185BA.8080609@illinois.edu> References: <4BA06CA0.8010505@illinois.edu> <4BA185BA.8080609@illinois.edu> Message-ID: Hi Robert, On Wed, Mar 17, 2010 at 6:45 PM, Robert Smolinski wrote: >>> >>> I have a "reg [79:0] mem[31:0]", I'd like to access mem[0] and such > > I print out using DUT.each_vpiNet and it doesn't print out any of the names > declared with "reg". > > I'm running the simulations with cver 2.12.a and ruby-vpi 21.1.0. It's been a while since I worked on this project so the details are not fresh in my mind. If you could kindly attach a tarball of the test suite you are running, it would help me to solve this issue. I'm also in the middle of revamping some of my other projects (and their infrastructure) right now, so I thank you in advance for your patience. As for the future of this project, I've had some new (rather low-level) developments brewing since last year: * Ruby 1.9 coroutine support[1] for more efficient & consistent behavior in all simulators. * switch from MRI C extension to Ruby::FFI[2] --- this involves developing and contributing a Ruby::FFI backend to the SWIG project. Hopefully I'll get to finishing these by the end of this year. [1] in particular is very cool; it's a great leap beyond the work I did for my MS thesis. Cheers. [1]: http://redmine.ruby-lang.org/issues/show/2294 [2]: http://github.com/sunaku/swig-ruby-ffi From rsmolin2 at illinois.edu Thu Mar 18 01:23:22 2010 From: rsmolin2 at illinois.edu (Robert Smolinski) Date: Thu, 18 Mar 2010 00:23:22 -0500 Subject: Accessing array of wires In-Reply-To: References: <4BA06CA0.8010505@illinois.edu> <4BA185BA.8080609@illinois.edu> Message-ID: <4BA1B8CA.9030401@illinois.edu> Suraj Kurapati wrote: > Hi Robert, > > On Wed, Mar 17, 2010 at 6:45 PM, Robert Smolinski wrote: > >>>> I have a "reg [79:0] mem[31:0]", I'd like to access mem[0] and such >>>> >> I print out using DUT.each_vpiNet and it doesn't print out any of the names >> declared with "reg". >> >> I'm running the simulations with cver 2.12.a and ruby-vpi 21.1.0. >> > > It's been a while since I worked on this project so the details are > not fresh in my mind. If you could kindly attach a tarball of the > test suite you are running, it would help me to solve this issue. > > I'm also in the middle of revamping some of my other projects (and > their infrastructure) right now, so I thank you in advance for your > patience. > > As for the future of this project, I've had some new (rather > low-level) developments brewing since last year: > > * Ruby 1.9 coroutine support[1] for more efficient & consistent > behavior in all simulators. > > * switch from MRI C extension to Ruby::FFI[2] --- this involves > developing and contributing a Ruby::FFI backend to the SWIG project. > > Hopefully I'll get to finishing these by the end of this year. [1] in > particular is very cool; it's a great leap beyond the work I did for > my MS thesis. > > Cheers. > > [1]: http://redmine.ruby-lang.org/issues/show/2294 > [2]: http://github.com/sunaku/swig-ruby-ffi > It looks like [1] was a tricky issue to find/solve and that you had a decent challenge getting it in. It's very cool that you are continuing your work on the project. I've really enjoyed using your ruby-vpi so far. It seems to me that ruby's unique language features are a definite advantage in design verification. I figured out a work around to get to the array elements using the vpi function "vpi_handle_by_index", since I can't find the correct argument to pass to "to_a". Do you have any further tips / utility functions that you found useful? I'm trying to find an elegant function to shorten the call to get the interger value of a wire. The best I could do seems like overkill: def IntVal wire_name, module="DUT" eval(module + "." + wire_name + ".intVal") end Thank you very much, Rob. From sunaku at gmail.com Fri Mar 19 15:51:02 2010 From: sunaku at gmail.com (Suraj Kurapati) Date: Fri, 19 Mar 2010 11:51:02 -0800 Subject: Accessing array of wires In-Reply-To: <4BA1B8CA.9030401@illinois.edu> References: <4BA06CA0.8010505@illinois.edu> <4BA185BA.8080609@illinois.edu> <4BA1B8CA.9030401@illinois.edu> Message-ID: On Wed, Mar 17, 2010 at 9:23 PM, Robert Smolinski wrote: > Suraj Kurapati wrote: >> As for the future of this project, I've had some new (rather >> low-level) developments brewing since last year: >> >> * Ruby 1.9 coroutine support[1] for more efficient & consistent >> behavior in all simulators. >> >> [1]: http://redmine.ruby-lang.org/issues/show/2294 >> > > It looks like [1] was a tricky issue to find/solve and that you had a decent > challenge getting it in. It's very cool that you are continuing your work on > the project. I've really enjoyed using your ruby-vpi so far. Thanks for the encouragement. > It seems to me > that ruby's unique language features are a definite advantage in design > verification. Agreed. > I figured out a work around to get to the array elements using the vpi > function "vpi_handle_by_index", since I can't find the correct argument to > pass to "to_a". This explains why #to_a did not work: it uses vpi_iterate() instead of vpi_handle_by_index(): http://github.com/sunaku/ruby-vpi/blob/master/lib/ruby-vpi/core/handle.rb#L227 Currently there is no accessor implemented that uses vpi_handle_by_index(): http://snk.tuxfamily.org/lib/ruby-vpi/#tbl:accessors > Do you have any further tips / utility functions that you found useful? I'm > trying to find an elegant function to shorten the call to get the interger > value of a wire. See http://snk.tuxfamily.org/lib/ruby-vpi/#vpi.handles > The best I could do seems like overkill: > def IntVal wire_name, module="DUT" > ?eval(module + "." + wire_name + ".intVal") At first glance, I would change the above line to: module.send(wire_name).intVal because eval() is frowned upon in the Ruby community. It's a necessary evil in some cases, but we generally try to avoid it. Or better yet, you can use the VPI::Handle#/ method[2]: (module / wire_name).intVal which is defined here: http://github.com/sunaku/ruby-vpi/blob/master/lib/ruby-vpi/core/handle.rb#L219 > end Cheers.