Csound Csound-dev Csound-tekno Search About

[Csnd] UDO order of execution question

Date2024-12-17 08:25
FromOeyvind Brandtsegg
Subject[Csnd] UDO order of execution question
Hello

Within a UDO, we can insert code after the xout, but it seems it will be processed before the xout.
For example
opcode MyTest, k, i
  i1 xin
  k1 init i1
  k1 += 1
  xout k1
  k1 += 1
endop

If I run this like
k1 MyTest, 1
printk2 k1
... it will print 3,5,7,9,....

If the last line before endop is processed after the value has been sent out via xout, then I'd expect it to print 2,4,6,8,...
What am I missing?

Øyvind
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2024-12-17 09:26
FromVictor Lazzarini <000010b17ddd988e-dmarc-request@LISTSERV.HEANET.IE>
SubjectRe: [Csnd] [EXTERNAL] [Csnd] UDO order of execution question
yes, I would expect that to happen at perf-time, because xout runs at i-time 
but does not run at perf-time. 

The other thing it does is indicate to the compiler the output variables that will 
be passed out by copy or by reference to the caller. 

So, with pass-by-copy (the original behaviour), any i-time code after xout will
not have any effect on the output, but perf-time code will be copied at the
end of the k-cycle, so the xout position does not matter. Incidentally, in this case, you
can only have one xout per UDO, more than one is a synterr.

Now, and this may yet change before the release, with pass-by-reference the position
of xout does not matter at i or perf-time (as long as it is placed after its arguments have 
been defined) because all it does is connect the memory locations of inputs and outputs.
Multiple xouts seem to be allowed, the last one executed (at i-time) is the one
that makes the connection between the UDO and the outside.
========================
Prof. Victor Lazzarini
Maynooth University
Ireland

> On 17 Dec 2024, at 08:25, Oeyvind Brandtsegg  wrote:
> 
> *Warning*
> This email originated from outside of Maynooth University's Mail System. Do not reply, click links or open attachments unless you recognise the sender and know the content is safe.
> Hello 
> 
> Within a UDO, we can insert code after the xout, but it seems it will be processed before the xout.
> For example
> opcode MyTest, k, i
>   i1 xin
>   k1 init i1
>   k1 += 1
>   xout k1
>   k1 += 1
> endop
> 
> If I run this like
> k1 MyTest, 1
> printk2 k1
> ... it will print 3,5,7,9,....
> 
> If the last line before endop is processed after the value has been sent out via xout, then I'd expect it to print 2,4,6,8,...
> What am I missing?
> 
> Øyvind
> Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here


Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2024-12-17 11:59
FromOeyvind Brandtsegg
SubjectRe: [Csnd] [EXTERNAL] [Csnd] UDO order of execution question
Interesting. Thanks for the explanation.

tir. 17. des. 2024 kl. 10:26 skrev Victor Lazzarini <000010b17ddd988e-dmarc-request@listserv.heanet.ie>:
yes, I would expect that to happen at perf-time, because xout runs at i-time
but does not run at perf-time.

The other thing it does is indicate to the compiler the output variables that will
be passed out by copy or by reference to the caller.

So, with pass-by-copy (the original behaviour), any i-time code after xout will
not have any effect on the output, but perf-time code will be copied at the
end of the k-cycle, so the xout position does not matter. Incidentally, in this case, you
can only have one xout per UDO, more than one is a synterr.

Now, and this may yet change before the release, with pass-by-reference the position
of xout does not matter at i or perf-time (as long as it is placed after its arguments have
been defined) because all it does is connect the memory locations of inputs and outputs.
Multiple xouts seem to be allowed, the last one executed (at i-time) is the one
that makes the connection between the UDO and the outside.
========================
Prof. Victor Lazzarini
Maynooth University
Ireland

> On 17 Dec 2024, at 08:25, Oeyvind Brandtsegg <obrandts@GMAIL.COM> wrote:
>
> *Warning*
> This email originated from outside of Maynooth University's Mail System. Do not reply, click links or open attachments unless you recognise the sender and know the content is safe.
> Hello
>
> Within a UDO, we can insert code after the xout, but it seems it will be processed before the xout.
> For example
> opcode MyTest, k, i
>   i1 xin
>   k1 init i1
>   k1 += 1
>   xout k1
>   k1 += 1
> endop
>
> If I run this like
> k1 MyTest, 1
> printk2 k1
> ... it will print 3,5,7,9,....
>
> If the last line before endop is processed after the value has been sent out via xout, then I'd expect it to print 2,4,6,8,...
> What am I missing?
>
> Øyvind
> Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here


Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here