Announcement

Collapse
No announcement yet.

Algorithms for combinations of 5 numbers in 50

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Steve,
    How about QUAD?

    Comment


    • Jim,

      Each data size and type needs to be handled differently, in an exchange sort, you swap pointers for string sorts, 32 bit is a bit clunky for quads as it has to make 2 moves for the data size where 64 bit only needs one but depending on what is being done, XMM? registers can handle 128 bit values and from memory PB will handle up to SSE4.1 so it may be useful. To use the later stuff like SSE you need to design it right as swapping in and out conversions is very expensive in processing time. I think from memory that SSE2 scalar doubles (64 bit) can be used for this type of work but you would need to know what the input and output was to get it right.

      This is just a proof of concept.
      Code:
      ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
      
      FUNCTION PBmain as LONG
      
          LOCAL a as QUAD
          LOCAL b as QUAD
      
          a = 12345678
          b = 87654321
      
          StdOut format$(a)+"  "+format$(b)
      
          ! movsd xmm0, a
          ! movsd xmm1, b
      
        ' -----------------------------------
          ! movsd xmm2, xmm0
          ! movsd xmm0, xmm1      ' swap code
          ! movsd xmm1, xmm2
        ' -----------------------------------
      
          ! movsd a, xmm0
          ! movsd b, xmm1
      
          StdOut format$(a)+"  "+format$(b)
      
          waitkey$
      
      
      End FUNCTION
      
      ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
      Just a note, this requires SSE2 with XMM registers.
      hutch at movsd dot com
      The MASM Forum

      www.masm32.com

      Comment


      • Steve's QUAD code is 18.3 times faster than SWAP and 1.09 times faster than b = a: a = c: c = b.
        Thank you Steve

        Comment


        • Originally posted by Jim Fritts View Post
          Steve's QUAD code is 18.3 times faster than SWAP and 1.09 times faster than b = a: a = c: c = b.
          Thank you Steve
          I'm guessing that that's ASM and only handles QUAD values?

          Comment


          • Steve, why not this?
            Code:
            ! movsd xmm0, a
            ! movsd xmm1, b
            ! movsd a, xmm1
            ! movsd b, xmm0

            Comment


            • That would work fine Mark, the reason why I did the 3 value swap was to duplicate the integer register one above it. Any of these depend on how the data is fed in and out and if speed matters, you tune each technique to suit the task you are doing.

              Stuart, as you know, Bob really did know what he was doing with assembler code and when he wrote the SWAP code, he pointed it at a wide range of data types and this entails having enough switching code depending on the data type. A narrow technique has the gain in much lower overhead but you need a separate technique for each data type. Integer registers for integer data, in Bob's case FP registers and code for FP work as SSE was not that well supported in 2012, with string data you swap the pointers.
              hutch at movsd dot com
              The MASM Forum

              www.masm32.com

              Comment


              • Thanks, Steve.

                Comment


                • Or Bob could have done this...

                  SWAP_8U(a,b) AKA BYTE
                  SWAP_16U(a,b) AKA WORD
                  SWAP_32U(a,b) AKA DWORD
                  SWAP_64U(a,b) AKA QUAD

                  SWAP_16S(a,b) AKA INTEGER
                  SWAP_32S(a,b) AKA LONG
                  SWAP_64S(a,b) AKA QUAD

                  SWAP_32F(a,b) AKA SINGLE
                  SWAP_64F(a,b) AKA DOUBLE

                  to skip the overhead.

                  Comment


                  • Deleted

                    Comment

                    Working...
                    X