SynthMaker

Smallest small volume null? (bitmask help?)

Archive · 2008 23 old posts

From the original SynthMaker forum (2004–2014), with its members’ names and dates.

infuzion ·

Liqih aka SM's Luisi posted this to get rid of denormals & unheard volumes to help with CPU: streamin set; streamout get; get = set&((set>0.0000001)|(set<-0.0000001)); which I can ASM easily to: streamin i;streamout o; float F0P0000001000=0.0000001000; float FM0P0000001000=-0.0000001000; movaps xmm0,i; cmpps xmm0,F0P0000001000,6; movaps xmm1,i; cmpps xmm1,FM0P0000001000,1; orps xmm0,xmm1; andps xmm0,i; movaps o,xmm0;

But I think it can be 1-2 cycles smaller if this can be done: streamin i;streamout o; float fSomeNum=???;float fSomeNumInvert=value of 1/???; int iBitMask=??? (likely the NOT of someNum in Int form) movaps xmm0,i; mulps xmm0,fSomeNum; andps xmm0,iBitMask; mulps xmm0,fSomeNumInvert; movaps o,xmm0; So I need some help for what the fSomeNum & iBitMask will be. I think this is the best approach, if it will work also with negative numbers also. If not, then a round off hack is needed. cheers

rl ·

I think to remove denormals you have to _set_ (andps) the register to zero. Not sure, but I think mulps won't help in this situation, otherwise the result just continues in denormal mode.

MyCo ·

Why don't use the already used hack:

streamin in; streamout out; float F1eM008=1e-008;

movaps xmm0,in; movaps xmm1,F1eM008; addps xmm0,xmm1; subps xmm0,xmm1; movaps out,xmm0;

That forces the CPU to round to the nearest value... btw. that way you could also do a round to int...

MyCo ·

Here is the rounding hack for int:

streamin in; streamout out; float F1e007=1e+007;

movaps xmm0,in; movaps xmm1,F1e007; addps xmm0,xmm1; subps xmm0,xmm1; movaps out,xmm0;

TomC ·

Has someone some coding which has easy to reproduce denormalizing problems?

I'd like to do some tests with a dither algorithm I've implemented some weeks ago.

Thanks.

Tom

infuzion ·

TomC wrote: Has someone some coding which has easy to reproduce denormalizing problems?

I think denormals can be created where ever you have feedback that can become smaller, such as some filters, or reverb. You can try to make the signal-in very very small to try to start some denormals maybe.

TomC ·

If the following code does what I think it should do it's about one cycle better than what we had so far:

streamin in; streamout out;

// Denormalise start -- 8< -- 8< -- float F1eM007=1e-007; int ABSMASK=2147483647; movaps xmm0,in; andps xmm0,ABSMASK; // xmm0 = abs(in) cmpps xmm0,F1eM007,6; // xmm0 = xmm0>0.0000001 andps xmm0,in; movaps out,xmm0; // Denormalise end -- 8< -- 8< --

Edit:...and it's as fast as MyCo's 'rounding hack' without relying on the implied rounding of the architecture.

infuzion ·

TomC wrote: If the following code does what I think it should do it's about one cycle better

In my own test bed, it is 1 cycle faster than my ASM version of Lusi's, but the same using the CPU tester from the WIKI.

How can one test if the output is correct? I'm a bit brain-dead right now & have to go to work, & I can't see if either has the right output 🙂 cheers

TomC ·

infuzion wrote: TomC wrote: If the following code does what I think it should do it's about one cycle better

In my own test bed, it is 1 cycle faster than my ASM version of Lusi's, but the same using the CPU tester from the WIKI.

How can one test if the output is correct? I'm a bit brain-dead right now & have to go to work, & I can't see if either has the right output 🙂 cheers

Testing is quite simple: instead of 0.00000001 use 0.5 as denormalise value, put an OSC with variable gain (from 0-1) in front and route the signal to a signal analyzer. Everything below 0.5 changes to 0.

Cheers.

Tom

infuzion ·

MyCo, yours didn't work 🙁 TomC wrote: If the following code does what I think it should do it's about one cycle better than what we had so far:

So TomC wins the prize, saving 1 cycle on my AMD64 laptop. It reads much better than mine & uses only 1 register. I liked the scissors also. Here is my little tweak to help make it more understandable & plop in easier: streamin in;streamout out; movaps xmm0,in; //Start Denormalise -- 8< -- 8< -- float fNeg140db=1e-007; int ABSMASK=2147483647; andps xmm0,ABSMASK; cmpps xmm0,fNeg140db,6; andps xmm0,in; //End Denormalise -- 8< -- 8< -- movaps out,xmm0;

Thanks for all the help! 😍 edit: I think there should be a Code command of this.

MyCo ·

infuzion wrote: MyCo, yours didn't work 🙁

how do you come to this? Try to put in: 5.877471754111438e-39

and you'll see that it works.

BTW: the way TomCs code work was also my idea, it's ripped out of the HP filter code that I translated for aliasant: Code tips x a beginner

This uses 1e-038 as denormal cutoff, which is more exact than TomCs 1e-7.

BTW2: The 1e-7 is not a denormal cutoff, eg. if you put in 1e-8 in TomC's example you'll get 0 as result, but 1e-8 is not a denormal, because its exponent field is 01100100 (it's only a denormal if the field is completely filled with zero)

TomC ·

MyCo wrote: BTW: the way TomCs code work was also my idea, it's ripped out of the HP filter code that I translated for aliasant: Code tips x a beginner

Believe it or not but I didn't copy it from your coding, I only looked at your second posting (for obvious reasons) where it already was removed.

It's the straight forward approach anyway, so we're most probably aren't the first ones to "invent" (thanks BALTHOR 🙂 ) this anyway.

Tom

infuzion ·

MyCo wrote: This uses 1e-038 as denormal cutoff, which is more exact than TomCs 1e-7.

Ah, you are correct, 1e-7 is really -140db, which most consider to be out of range of hearing, so to limit wasted CPU cycles. I'm assuming that the -140db cut would also rid of denormals please? Sorry if I was confusing in saying "denormal" in my first post :/

But yes, if one wanted only to rid of denormals & keep all other sound information there, then your technique is fastest. I was just intending to cut out a bit more, & have the range to be adjustable.

TomC ·

infuzion wrote: MyCo wrote: This uses 1e-038 as denormal cutoff, which is more exact than TomCs 1e-7.

Ah, you are correct, 1e-7 is really -140db, which most consider to be out of range of hearing, so to limit wasted CPU cycles.

That was my intention (in fact, I used what was in the original posting, thought about it later and decided that it's close enough to the -144db min dynamic range a 24 bit recording can theoretically use).

I'm assuming that the -140db cut would also rid of denormals please? Sorry if I was confusing in saying "denormal" in my first post :/

It's bigger than denormal numbers, so it removes them, too.

Cheers.

Tom

TomC ·

MyCo wrote: 5359&start=120#40535

This uses 1e-038 as denormal cutoff, which is more exact than TomCs 1e-7.

Would you mind explaining this a bit more? From my understanding of IEEE 754 normal positive numbers go from 10^−95 to 9.999999 × 10^96, so why 10^-38 and not lets say 10^-39 or 10^-37?

Curious.

Tom

MyCo ·

the smalles normal number is 1.1754944e-38 so if there is something below that number, the CPU has to switch in an trial & error mode, where it starts looping through values until it fits.

TomC ·

MyCo wrote: the smalles normal number is 1.1754944e-38 so if there is something below that number, the CPU has to switch in an trial & error mode, where it starts looping through values until it fits.

http://www2.hursley.ibm.com/decimal/decifaq2.html#normals http://en.wikipedia.org/wiki/Normal_number_(computing)

?

Cheers.

Tom

Edit: found it, it's ±2^−126. Now I understand

MyCo ·

yeah... you are looking at decimal 32 bit floating numbers. But you have to look at the binary floating numbers

eg. here: http://en.wikipedia.org/wiki/Normal_number_(computing)

you see the binary 32-bit: min exp. −126 max exp. 127

the base of the binary format is 2 not 10, which means the smallest normal number is: 1 * 2^-126 which is...tatatata: 1,17549e-38

You have to look here: http://en.wikipedia.org/wiki/IEEE_754

MyCo ·

damn... let me write before you edit 🙂

Eska ·

Question: Are denormals a noise or a rising level? Means: Can I hop the decision and leave just an and in the sampleprecise area?

MyCo ·

basically denormal is silence... it can be noise or any other waveform, doesn't matter, because you can't hear it.

Eska ·

Oh yeah.. after thinking: this would give a special FX.

infuzion ·

Eska wrote: Oh yeah.. after thinking: this would give a special FX.

Adding denormals, I don't think so. If you have denormals, your CPU usage for that synth will go up +500%.

TomC: I guess you can replace the 1e-7 with 6.30958e-008 (-144db, 24bit floor).

Wrote something here? To have a post removed or your name hidden, write to [email protected].

Before your first post

A few rules keep this a friendly place. You agree to them once.

Shown next to what you post, here and in the app. It doesn’t have to be your real name: 3–24 lower-case letters, digits or _ (capitals become lower case, spaces become _).

    Then your post goes up straight away.

    Delete this reply?

    Open it in SynthMaker?

    It goes on the track you’re editing there, in place of that track’s sound, and into My sounds. Your other tracks stay as they are.

    Want to keep that track’s sound? Start a new song in SynthMaker first (Song › New song), then open this.

    Report this reply?

    Only the developer reads reports. The person isn’t told who reported them.

    What’s wrong with it?

    Block this person?

    You won’t see their posts and replies here any more. They aren’t told, and you can unblock them at any time.

    People you’ve blocked

    Their posts and replies are hidden from you. Unblock someone to see them again.

    The community rules

    A few rules keep this a friendly place. Everyone agrees to them once, before their first post.