Re: [Csnd-dev] pass-by-ref
Eduardo Moguillansky <[email protected]>
| Newsgroups | gmane.comp.audio.csound.devel |
|---|---|
| Message-ID | <CAHFFssKgzrn1KB67XbdPRGf60HK-cyXMwE4G8N96i9Or8q1_0w@mail.gmail.com> |
This is great. Regarding passing by ref for all arguments, does that not change the semantics of opcodes? I for sure would not expect that modifying a k- variable inside an opcode could change the value outside it Cheers, Eduardo On Mon, Feb 19, 2024, 21:43 Steven Yi <[email protected]> wrote: > 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 >