Adding at code input when variable has self assigment

Discuss suspected defects before submitting a bug report

Moderator: electrogear

Adding at code input when variable has self assigment

Postby oddson on Sun Mar 18, 2012 9:42 pm

It appears you cannot add to a code variable's input with multiple connections (as you can with every other primitive or module input) when that input is involved in a self assign of the form:
Code: Select all
in = in + c;

Is this a bug or is there a reason this should be so?
oddson
wiki guru
 
Posts: 3889
Joined: Sun Jul 03, 2005 6:44 pm

Re: Adding at code input when variable has self assigment

Postby stw on Mon Mar 19, 2012 7:03 am

I'm not very familiar with machine internals but i'd guess the "bug" is the version with only one float connected.
The reason seems to be that the x variable pointer is the same as the input pointer. What is wrong in the way that the input(x) is static but the x variable is incrementing. But on the other hand this is what the code expresses.
If two floats are conected the input and the x var get two different memory addresses which IMHO is the correct way of handling this. The reason for that seems to be that all affected variables are treated individually. Which means we have not only one input (x) but two inputs flota1 and float2 with different memory addresses. These are processed into a third memory address (x).
I guess the attached image expresses better what i try to point out.
(Upper box=two float inputs - lower box=one float input)
(I hope i don't talk complete bulls.. here ;) )
code.jpg
code.jpg (67.32 KiB) Viewed 1209 times

However the really wired thing happens if you connect the second readout in my osm to the code output...
codeBugAddingAtInput2.osm
(2.38 KiB) Downloaded 175 times
stw
smanatic
 
Posts: 641
Joined: Mon Jun 30, 2008 2:55 pm

Re: Adding at code input when variable has self assigment

Postby Xtinct on Mon Mar 19, 2012 10:30 am

Even wierder only connect the second readout :S
capture.png
capture.png (40.58 KiB) Viewed 1186 times
Xtinct
essemilian
 
Posts: 226
Joined: Thu Feb 10, 2011 11:06 pm

Re: Adding at code input when variable has self assigment

Postby trogluddite on Mon Mar 19, 2012 1:13 pm

Not sure I would call this a bug - but it is behaviour that really should be highlighted in the documentation.

As stw says, variables are just 'nick names' for memory addresses. When a 'streamin' is declared it doesn't create a new 'memory space' to hold that variable - it simple copies the output address of whatever is at the other end of the input link. (NB - the input link - this method implies that there can be only a single source)

In general, writing back to streamin variables is not advised. In effect you are actually writing to the output 'variable' of the input source. This can mess with the processing of the 'input' module (if it uses it's 'out' variable recursively, as in a lot of filters etc.).
Also, if you have many destinations fed by one source, all destinations will 'inherit' any changes made whenever a 'streamin' writes-back to the source - depending on the execution order of the destinations, they may even see different values depending when the 'writeback' occurs.

My guess is that it was done this way to save extra CPU overhead from generating 'proxy' code inputs to allow for 'hidden summing'. The same result can, of course, be achieved by summing explicitly , either with primitives, or within the code - but there's no excuse for OutSim not pointing out the need to do that.
Feel free to use any schematics and algorithms I post on the forum in your own designs - a credit is appreciated (but not a requirement).
Don't stagnate, mutate to create. Without randomness and serendipity the earth would be just another barren rock.
User avatar
trogluddite
smychopath
 
Posts: 3033
Joined: Mon Oct 20, 2008 3:52 pm
Location: Yorkshire, UK

Re: Adding at code input when variable has self assigment

Postby stw on Mon Mar 19, 2012 1:49 pm

trogluddite wrote:As stw says, variables are just 'nick names' for memory addresses. When a 'streamin' is declared it doesn't create a new 'memory space' to hold that variable - it simple copies the output address of whatever is at the other end of the input link. (NB - the input link - this method implies that there can be only a single source)


But this won't explain why SM devides the "double input" version into five addresses (in1,in2,const,x,y) but the "single input" version only into three addresses (in=x,const,y). Which means the single input version DOES write back to the input but the double input version does NOT?
stw
smanatic
 
Posts: 641
Joined: Mon Jun 30, 2008 2:55 pm


Return to Bugs

Who is online

Users browsing this forum: No registered users and 1 guest