Re: SQRT optimization
Posted: Sat Feb 22, 2020 3:47 pm
steph_tsf wrote:Without doing anything, without sending an email, I am again allowed to attach files.
Ah, that's good news! I guess maybe somebody else sent a report which has led Malc to clear something?
steph_tsf wrote:The sqrt(x) doesn't deliver what one is expecting. There must me something obvious like an offset
That is very peculiar indeed, and not at all obvious - and very likely a bug in FS.
If you take a multi-line text box and connect it to the (S) output of the DSP primitive, it shows you the compiled assembly for the DSP code. And the compiled assembly is practically the same as the "hand-made" assembly using sqrtps. By changing one register assignment, I made them identical - and still the strange output difference!
I then suspected it might be a known problem where writing to an input variable in a component can change a preceding component's output values (if there is only one source, they may share a memory address, hence you should never write to an input variable). But no - there is no component which does this. I then changed the input variable names in the schematic in case some kind of weird name-sharing was happening - no, nor that, either!
I then changed the DSP code to "b = a" to view the input value. Aha! - this was very strange indeed! The value was not only incorrect; it was continuously changing! To confirm this, I constructed a new DSP component containing the same code - and problem gone!
So, a vanishingly rare bug in FS, it seems. I can only guess that the memory address of the input connector was being shared with something else in the schematic which was overwriting the input value. Quite an entertaining little exercise in debugging - and possibly the strangest FS bug I have ever seen!