Fast bit doubling, how?


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Aug 2011
    Posts
    453


    Did you find this post helpful? Yes | No

    Default Re: Fast bit doubling, how?

    Even though it looks longer, this should end up almost twice as fast...
    Code:
    outvar = 0
    if (invar.0) then
        outvar.0 = 1
        outvar.1 = 1
    endif
    if (invar.1) then
        outvar.2 = 1
        outvar.3 = 1
    endif
    if (invar.2) then
        outvar.4 = 1
        outvar.5 = 1
    endif
    if (invar.3) then
        outvar.6 = 1
        outvar.7 = 1
    endif
    if (invar.4) then
        outvar.8 = 1
        outvar.9 = 1
    endif
    if (invar.5) then
        outvar.10 = 1
        outvar.11 = 1
    endif
    if (invar.6) then
        outvar.12 = 1
        outvar.13 = 1
    endif
    if (invar.7) then
        outvar.14 = 1
        outvar.15 = 1
    endif

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default Re: Fast bit doubling, how?

    I think #2 is faster.

    Ioannis

  3. #3
    Join Date
    Aug 2011
    Posts
    453


    Did you find this post helpful? Yes | No

    Default Re: Fast bit doubling, how?

    It can depend on the device and where the variables end up, but here's a contrast of the two methods (post #2, post #6)
    Code:
    invar    #2    #6
    $00      64    34
    $01      64    36
    $55      64    42
    $FF      64    50
    That's for an 18F26K22. Results are in instruction cycles.
    Post #2 has the "advantage" of always taking 64 cycles, but #6 is always faster.

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default Re: Fast bit doubling, how?

    Impressive!

    Thanks,
    Ioannis

Similar Threads

  1. Replies: 10
    Last Post: - 8th March 2015, 19:26
  2. Replies: 17
    Last Post: - 22nd May 2014, 19:58
  3. Doubling the pusle count
    By malc-c in forum mel PIC BASIC Pro
    Replies: 43
    Last Post: - 17th May 2012, 13:17
  4. Help! sinking fast!
    By fowardbias in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 31st May 2007, 19:39
  5. A/D on 16F877. How fast can I go?
    By atomski in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 8th April 2004, 06:51

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

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