SynthMaker

fastest code ABS()?

Archive · 2006 5 old posts

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

infuzion ·

Not a biggy, but I'm curous what's fastest?:

//ABS() sam/stefan streamin in; streamout abs; float absmask;

stage(0) { absmask = 3.4e38|0.999999|0.1; }

stage(1) { abs = in&absmask; } or //ABS() Borogove streamin in; streamout abs; abs=max(in,0-in); I'm guessing Sam's is better for several ABS in the code, Borogove's is best only if it used once.

Also, do varable's values get assigned in stage(0)? So Sam's code can be shortened: //ABS() sam/stefan streamin in; streamout abs; float absmask = 3.4e38|0.999999|0.1; abs = in&absmask; ? TIA

doug4350 ·

(1) If it's optimized correctly, bool-$4it 🙂 are processor opcodes, which can be bool-dozed at the cpu register level. Whereas max(...) is a function which requires more overhead pushing the code component registers on the stack so they don't get stepped on in max() and popping them off coming back. (I'm assuming the 'C' calling convention is used of course).

(2) Makes sense 2 me. I'm not sure what the func constructs do?.?. Anyone care to clarify???

Aloha, Doug

infuzion ·

doug4350 wrote: (1) ...Whereas max(...) is a function which requires more overhead pushing the code component registers on the stack so they don't get stepped on in max() and popping them off coming back.

Seems to be, but if you connect a Text to the Code's output, you'll see the assembly for the mask-version: streamin in; streamout abs; float absmask=0.0000000000; float F339999995214436420000000000000000000000P0000000000=339999995214436420000000000000000000000.0000000000; float F0P9999989867=0.9999989867; float F0P1000000015=0.1000000015; stage0; movaps xmm0,F339999995214436420000000000000000000000P0000000000; orps xmm0,F0P9999989867; movaps xmm1,xmm0; orps xmm1,F0P1000000015; //Assignment> sLeft=xmm1 movaps absmask,xmm1; stage1; stage1; movaps xmm0,in; andps xmm0,absmask; //Assignment> sLeft=xmm0 movaps abs,xmm0; stage1; Seems to be quite a lot of steps setting up absmask? & the Max version: streamin in; streamout abs; float F0P0000000000=0.0000000000; movaps xmm0,F0P0000000000; subps xmm0,in; movaps xmm1,xmm0; maxps xmm1,xmm0; maxps xmm1,in; //Assignment> sLeft=xmm1 movaps abs,xmm1; I can see how 2 maxps-s will slow things up...but is it significant?

doug4350 ·

Good point Infuzion... I don't know 'nuff about the code component to be that clever yet 🙂 . So they have opcodes for the max() stuff these days ... cool. Kind of like when I believe it was the 486 introduced the strcmp() replacement opcode.

I left X86 assembly (coding anyways) on the shelf waayyyyy back in the 286 days. I haven't dabbled much with the code component, but just rambling from past experience. What you need to do to answer the question is look at the clock cycle cost of the maxps opcode. My gut tells me it's more than a logical and/or opcodes. Way back on the 8086, the and/or opcodes took only 4 cycles. I'm sure nowadays with prefetch/readahead/predictor queueing, it could be less. There's also the issue of byte alignment. I believe since the pentium family of recent, being 64 bits would require 8 byte byte alignment (8 bytes * 8 bits/byte == 64 bits) for maximum thrust, that if the data isn't aligned, there's cpu cost to do it transparently. As a side note, I think there's too much hype, or maybe misleading on the megabyte ram thing. The reason is if you have a 64 bit machine with 1 GB of ram, effectively, you sort of only have 128 MB, or you trade the alignment cost. I'm rambling on that because floats are only 4 bytes. When it comes down to tooth & nail, ya gotta look at the ram during execution. Isn't this fun 🙂 .

'K den. It's almost 10:30 p.m. here and I need to get some ivory time in b4 lights out.

Aloha, Doug

doug4350 ·

Good point Infuzion... I don't know 'nuff about the code component to be that clever yet 🙂 . So they have opcodes for the max() stuff these days ... cool. Kind of like when I believe it was the 486 introduced the strcmp() replacement opcode. One of these days I should take a peek at the sse opcodes...

I left X86 assembly (coding anyways) on the shelf waayyyyy back in the 286 days. I haven't dabbled much with the code component, but just rambling from past experience. What you need to do to answer the question is look at the clock cycle cost of the maxps opcode. My gut tells me it's more than a logical and/or opcodes. Way back on the 8086, the and/or opcodes took only 4 cycles. I'm sure nowadays with prefetch/readahead/predictor queueing, it could be less. There's also the issue of byte alignment. I believe since the pentium family of recent, being 64 bits would require 8 byte byte alignment (8 bytes * 8 bits/byte == 64 bits) for maximum thrust, that if the data isn't aligned, there's cpu cost to do it transparently. As a side note, I think there's too much hype, or maybe misleading on the megabyte ram thing. The reason is if you have a 64 bit machine with 1 GB of ram, effectively, you sort of only have 128 MB, or you trade the alignment cost. I'm rambling on that because floats are only 4 bytes. When it comes down to tooth & nail, ya gotta look at the ram during execution. Isn't this fun 🙂 .

'K den. It's almost 10:30 p.m. here and I need to get some ivory time in b4 lights out.

Aloha, Doug

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.