If you have a problem or need to report a bug please email : support@dsprobotics.com
There are 3 sections to this support area:
DOWNLOADS: access to product manuals, support files and drivers
HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects
USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here
NEW REGISTRATIONS - please contact us if you wish to register on the forum
Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright
DSP code help needed (again)
10 posts
• Page 1 of 1
DSP code help needed (again)
If you know me, then you are aware of my DSP code weakness. Especially the bitmask used to do branching. I need code that does a "either or" (boolean xor).
Imagine this situation: There are two values, one is positive, one negative. The absolute products of the two values are compared and only one of them will be true (and passed), while the other is false. On occasion, both values will be exactly the same, so no xor conclusion, and in that case a default value (for example 0) is the result. For this example, let's assume the larger absolute product is the goal and passes the value. But it should work for the smaller as well, by just applying the math as I understand it from your example.
How to do that in DSP code?
Mockup code (please provide actual working code)
Imagine this situation: There are two values, one is positive, one negative. The absolute products of the two values are compared and only one of them will be true (and passed), while the other is false. On occasion, both values will be exactly the same, so no xor conclusion, and in that case a default value (for example 0) is the result. For this example, let's assume the larger absolute product is the goal and passes the value. But it should work for the smaller as well, by just applying the math as I understand it from your example.
How to do that in DSP code?
Mockup code (please provide actual working code)
- Code: Select all
streamin a;
streamin b;
streamout out;
//abs(a) and abs(b) will be compared
out = ?
//out needs to be 0, or the larger of the two values (not abs(value))
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: DSP code help needed (again)
Here some way, not sure the best in dsp, i forget a little when switching to asm.
For asm i would do like this
- Code: Select all
streamin in; streamin in2;
streamin default;
streamout out;
float a; float b; float c;
a=abs(in); b=abs(in2);
c=in2+(a>b)&(in-in2);
c=c+(a==b)&(default-c);
out=c;
For asm i would do like this
- Code: Select all
streamin in; streamin in2;
streamin default;
streamout out;
int abs=2147483647;
//2 abs//
movaps xmm0,in; movaps xmm1,in2;
movaps xmm2,xmm0; movaps xmm3,xmm1;
movaps xmm4,abs;
andps xmm2,xmm4; andps xmm3,xmm4;
//compare//
movaps xmm5,xmm2; cmpps xmm5,xmm3,1;
subps xmm1,xmm0; andps xmm1,xmm5;
addps xmm0,xmm1;
cmpps xmm2,xmm3,0;
movaps xmm3,default; subps xmm3,xmm0;
andps xmm3,xmm2; addps xmm0,xmm3;
movaps out,xmm0;
- Tepeix
- Posts: 361
- Joined: Sat Oct 16, 2021 3:11 pm
Re: DSP code help needed (again)
I still need to wrap my head around the question. Could you perhaps do this in Ruby with basic numbers? If so, I can translate that to DSP.
- adamszabo
- Posts: 667
- Joined: Sun Jul 11, 2010 7:21 am
Re: DSP code help needed (again)
adamszabo wrote:I still need to wrap my head around the question. Could you perhaps do this in Ruby with basic numbers? If so, I can translate that to DSP.
Damn, whenever I explain something, it tends to confuse more than help. Let's try it with this:
- Code: Select all
true || true
## or, when both true, returns true
true ^ true
## xor, when both true, returns false
I need DSP code that compares two boolean results (imagine instead of true or false, there might be (a > b) or (c <= a) or something along those lines) and gets true ONLY when exactly ONE statement is true. If both are true, it should result in false. That way, I can set the output to the default value, when false. And to the input streams when true.
Does that help?
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: DSP code help needed (again)
Not sure i really understand the meaning of the operation.
In dsp only & is documented as and, but i know that | work as or, but not what could do xor..
But if you need to have a final boolean value like xor you could invert the result of and.
Like out= in1 + (a==b) &(default-in1);
In dsp only & is documented as and, but i know that | work as or, but not what could do xor..
But if you need to have a final boolean value like xor you could invert the result of and.
Like out= in1 + (a==b) &(default-in1);
- Tepeix
- Posts: 361
- Joined: Sat Oct 16, 2021 3:11 pm
Re: DSP code help needed (again)
Tepeix wrote:Not sure i really understand the meaning of the operation.
Exclusive Or. It means that comparing two booleans only returns true if they are different.
- Code: Select all
true ^ true = false
true ^ false = true
false ^ true = true
false ^ false = false
That's unlike Or, which returns true if at least one is true, but doesn't mind both.
- Code: Select all
true || true = true
true || false= true
false || true = true
false || false = false
Tepeix wrote:But if you need to have a final boolean value like xor you could invert the result of and.
Like out= in1 + (a==b) &(default-in1);
I'm not sure I understand this. Does this mean, result is in1 when a != b, but default when a==b? That would help indeed, but I don't know how to turn a and b into comparisons?
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: DSP code help needed (again)
Here’s a couple of solutions.
Now I eagerly await Martin to blow me out of the water…
Now I eagerly await Martin to blow me out of the water…
- Attachments
-
- DSP XOR dev 2 .fsm
- 3.06
- (4.04 KiB) Downloaded 330 times
-
Spogg - Posts: 3358
- Joined: Thu Nov 20, 2014 4:24 pm
- Location: Birmingham, England
Re: DSP code help needed (again)
Spogg beat me to it
I am not sure if this is supported in FS 3, but in the alpha there is actually a xor instruction in assembler, the simplest is:
Or you can also use a not equal (!=) in the DSP box, again I am not sure if its supported in FS 3:
This is the same as this assembly code which should work in any FS version:
I am not sure if this is supported in FS 3, but in the alpha there is actually a xor instruction in assembler, the simplest is:
- Code: Select all
streamboolin bool1;
streamboolin bool2;
streamboolout out;
movaps xmm0,bool1; //move first boolean "bool1" to xmm0,
xorps xmm0,bool2; //do XOR operation with "bool2"
movaps out,xmm0; //send result to "out"
Or you can also use a not equal (!=) in the DSP box, again I am not sure if its supported in FS 3:
- Code: Select all
streamin a;
streamin b;
streamout out;
out = a != b;
This is the same as this assembly code which should work in any FS version:
- Code: Select all
streamin bool1;
streamin bool2;
streamout out;
movaps xmm0,bool1;
cmpps xmm0,bool2,4; //4 is not equal
movaps out,xmm0;
- adamszabo
- Posts: 667
- Joined: Sun Jul 11, 2010 7:21 am
Re: DSP code help needed (again)
a and b are abs in my reverse think.
If i really understand the code needed it might work to reverse the conditional.
When abs(in1) and abs(in2) are equal it will give default, if they are different, it give in1.
so :
But if you need to take the greater value of in1 or in2 or the greater abs value it might be different, but could end up in the same.
If i really understand the code needed it might work to reverse the conditional.
When abs(in1) and abs(in2) are equal it will give default, if they are different, it give in1.
so :
- Code: Select all
streamin in1; streamin in2; streamout out;
streamin default;
float a=0; float b=0;
a=abs(in1); b=abs(in2);
out= in1+(a==b)&(default-in1);
But if you need to take the greater value of in1 or in2 or the greater abs value it might be different, but could end up in the same.
- Code: Select all
streamin in1; streamin in2; streamout out;
streamin default;
float a=0; float b=0; float c=0;
a=abs(in1); b=abs(in2);
c=in1+(a<b)&(in2-in1);
out= c+(a==b)&(default-c);
- Tepeix
- Posts: 361
- Joined: Sat Oct 16, 2021 3:11 pm
Re: DSP code help needed (again)
Hi guys!
I was quiet for a while, because my goal was to provide you with the result of my work and your help. But I couldn't get it to work in a meaningful way. I since got a template of sorts from Rex, that may help me at least finding out if the core idea works or not.
I am really thankful for all your help! Who would have thought that XOR'ing streams based on parameters could be that difficult? And it's not your codes. They work for their intentions. No, it's my idea, I'm afraid.
Thank you!
I was quiet for a while, because my goal was to provide you with the result of my work and your help. But I couldn't get it to work in a meaningful way. I since got a template of sorts from Rex, that may help me at least finding out if the core idea works or not.
I am really thankful for all your help! Who would have thought that XOR'ing streams based on parameters could be that difficult? And it's not your codes. They work for their intentions. No, it's my idea, I'm afraid.
Thank you!
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
10 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 61 guests