Page 4 of 4 FirstFirst ... 234
Results 31 to 35 of 35

Thread: Nearest Power of 2 quickly

  1. #31

    Nearest Power of 2 quickly

    Well you can store a shift count in the byte, and then to shl, right?

  2. #32

    Nearest Power of 2 quickly

    Quote Originally Posted by cairnswm
    instead of using integers in cairnswm's N lookup table, couldn't you use bytes and get both a performance and size win?
    No because byte only goes to 256 and these numbers are larger - but maybe SmallInt could save space.
    The "Twos" array only has a range og 1..11 which means a byte will suffice
    Code:
    Const 
      Twos : Array[1..11] of LongInt = (1,2,4,8,16,32,64,128,256,512,1024); 
    
    var 
        N : Array[1..1024] of Byte;
    just cut of 1024*3 bytes of ram
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  3. #33
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Nearest Power of 2 quickly

    I just mean that the difference between the two ways would probably not be too big as far as speed.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  4. #34

    Nearest Power of 2 quickly

    In a quite surprising move, the shl or shl or shl or shl or ... etc. code is actually faster than the assembler! That's one clever function! Unfortunately it just doesnt beat a brute force lookup!

    Also interestingly, I tried cairnswm's algorithm as a function returning one integer and also straight as an inline lookup and according to the graph below, the overhead incurred by the function is around 640 millionths of a second (0.00064) per execution.

    My site: DelphiTuts.com (coming soon)...

    Download Font Studio 4.21 here.

  5. #35

    Nearest Power of 2 quickly

    Cool

Page 4 of 4 FirstFirst ... 234

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •