Page 1 of 1

How to not become crazy in dsp and asm ;)

PostPosted: Tue Mar 08, 2022 2:02 pm
by Tepeix
Almost every time i write a code in dsp or asm i have i first bad impression that nothing works !)
Then i place a DS or Asio out in my shematics and it begin to works !)
Very fast now to realize that !) Almost a reflex.

Now in asm i find a serious way to become crazy for a longer time !)
Crying that something is not right ! Copying and erasing every complex part of the code.
To have just the simplest movaps out,xmm0; not working !
Restarting the application...
Then i realize that the first thing to check is that all variable or input output have the exact same name.

I was using streamout done; But i completely forget that and the compilator say nothing when we use an undeclared variable like movaps out,xmm0 in this case... ...

Did you have other's thing that become a reflex to checks first when the code is not working ?

Re: How to not become crazy in asm ;)

PostPosted: Tue Mar 08, 2022 2:25 pm
by Spogg
After about 7 years I can finally write small bits of DSP that actually work first time! Sometimes! :lol:

One thing I find useful for DSP is

Code: Select all
streamout test;
test = counter;

The test output allows me to check any part of the code to see what’s going wrong.

In my view so much can be wrong and what’s right is tiny in comparison. That means it’s hard to offer advice, but I can say that experience is the key. I got quicker at finding my mistakes over time.

Re: How to not become crazy in dsp and asm ;)

PostPosted: Tue Mar 08, 2022 4:36 pm
by Tepeix
Very good advice !)
If i have done that always using test to debug i will not have problem with other's syntax !

Now i get another despair.)

Trying to use cmp eax,4095; or any number.

if i assign a negative value to eax it will do like -1 is greater to 4095 !
So i try add eax,1; before cmp eax,4095. Not working..
inc [eax]; crash it !
eax come from xmm0. So i try to paddd xmm0,inc. Not working... ,)

Now i could transform xmm0 in a float with cvtdq2ps, use addps to add a float of 1.
Transform now in a int with cvtps2dq. So now eax must be 0 like xmm0.

But even like this cmp eax refuse to works...

So i suppose that we could not use a int value that was negative when using eax ???

Here's the code if some want to see.

Re: How to not become crazy in dsp and asm ;)

PostPosted: Wed Mar 09, 2022 9:53 am
by Spogg
I’m not into ASM so I hope someone else can chip in…

Re: How to not become crazy in dsp and asm ;)

PostPosted: Wed Mar 09, 2022 1:23 pm
by martinvicanek
@Tepeix, towards the end of your ASM code there is an instruction
addps xmm0,inc;
addps adds floats, but inc is an integer (and so is xmm0). You have to use paddd instead of addps.

General comment regarding the topic: Yes, ASM has an extraordinary potential to drive you mad. :mrgreen: Perhaps the worst errors are undeclared or doubly declared variables. Sometimes the code will execute as expected without problems, sometimes it will produce garbage, and sometimes it will crash Flowstone. Fortunately, these issues are highlighted in FS alpha codebox and thus easily avoided. I have made it a habit to check the more complex ASM codes in FS alpha.

Re: How to not become crazy in dsp and asm ;)

PostPosted: Wed Mar 09, 2022 8:19 pm
by Tepeix
Thanks !)
Correcting this line, now it works to compare negative integer.)
That incident make me falsely believe that compare with a negative eax was not possible !

That's a surprising bug. The paradox is that if the bug occurs the line that make it happen is supposed to be skip.

In my version 3.6. It's not possible to paddd xmm0,xmm1;
So i'm tempted to use addps if it works to not use a variable.
But now i know it could make some things not works..

Re: How to not become crazy in dsp and asm ;)

PostPosted: Wed Mar 09, 2022 9:36 pm
by martinvicanek
Tepeix wrote:In my version 3.6. It's not possible to paddd xmm0,xmm1.

You can add eax,1; in 3.0.6 :)

Re: How to not become crazy in dsp and asm ;)

PostPosted: Thu Mar 10, 2022 11:37 am
by Tepeix
Yes, but it's another case where i need to add in SSE 4 different integer.
But finally i check those code and find i use later another way.)

The idea was to calculate 1 index and 1 or 3 delay in the same variable.
And, that's not so much practical ,) But could have some use if some want the same delay for a stereo signal.

In first attempts i addps index and delay as integer. But finally it's possible to paddd with the index variable..

By the way, i never could do this without yours delays ! Thanks !!!)

So the idea is to write once, 2 channels and the same + 1 sample.
Then to read the array twice to get 2 stereo interpolated delay.

Well some "non-sense optimization" but i learn a lot trying this !)