[Csnd-dev] pass-by-ref
Steven Yi <[email protected]>
| Newsgroups | gmane.comp.audio.csound.devel |
|---|---|
| Message-ID | <CANtcCs5iZOL+93tiRYTcCr6HWi6u6J=H=QCgxuqsepu00DUE7g@mail.gmail.com> |
Hi All, I managed to get through an initial implementation of pass-by-ref for UDOs. Took a while to do analyses of the code to get to this point, but hopes are that it should be quicker to iterate upon from here with this base implementation. If you're interested to try it out, the branch is: feature/pass-by-ref Some notes on this implementation: 1. I moved UDO-related code out from insert.c/.h to a separate udo.c/.h file. 2. I implemented this only for new-style UDOs. There was discussion about making this something we could control on a per-argument basis, but starting with this simplified what had to get figured out. I also wonder if it wouldn't be a good idea to simply go with this, since it makes UDOs have the same characteristics of pass-by-ref as native opcodes. It would also be safe to do this for backwards compatibility and keep pass-by-value for old-style UDOs. 3. I added a new ##userOpcode2 entry that gets used for new-style UDOs. It does not have any perf-time code. useropcdset_newstyle handles ref finding and setting with the following algorithm: * 1. Iterate through the init chain to find xin/xout opcodes. * 2. When found, lookup names of input and output variables for this current UDO instance. * 3. Setup a map of input/output variable names to passed-in arg pointers * 4. Iterate through the init chain to find references to xin/xout vars and set the pointers to the input/out variable argument pointer addresses. * 5. Iterate through the perf chain to find references to xin/xout vars and set the pointers to the input/out variable argument pointer addresses. xinset and xoutset were also modified to skip copying of UDO in/out args to/from IOBUFS when inside a new-style UDO. At the moment, all csd tests are passing including the new test I added while doing dev. There's a number of additional tests to add to ensure this works with UDOs calling UDOs, structs, etc. There's also performance testing to do to see how well this affects things like passing f-sigs and arrays into UDOs. There's also some known issues with returning constants from UDOs and some other arg types I have to check to see if they are working or not. Also, there is a bigger issue of what to do for local ksmps (will likely revert to pass-by-value for short-term) as well as how to handle oversampling (i.e., local sr). I'm pretty excited to get past this initial implementation. Feedback and any tests are welcome and appreciated. Thanks! Steven