multiplication vs shifting


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default That's a Bug



    Nice find Kamikaze!

    There's a small bug in the pbppi18l.mac file.
    The SHIFTL?NCN macro should be changed as follows. (3's in red)
    Code:
    SHIFTL?NCN macro Nin, Cin, Nout
        if ((Cin) == 1)
            bcf     STATUS, C
          if ((Nout) == (Nin))
            CHK?RP  Nout
            rlcf    Nout, F
            rlcf    (Nout) + 1, F
            rlcf    (Nout) + 2, F
            rlcf    (Nout) + 3, F
          else
            CHK?RP  Nin
            rlcf    Nin, W
            MOVE?AB Nout
            CHK?RP  Nin
            rlcf    (Nin) + 1, W
            MOVE?AB (Nout) + 1
            CHK?RP  Nin
            rlcf    (Nin) + 2, W
            MOVE?AB (Nout) + 2
            CHK?RP  Nin
            rlcf    (Nin) + 3, W     ; was 2
            MOVE?AB (Nout) + 3
          endif
        else
            MOVE?NN Nin, R0
            movlw   Cin
            L?CALL  SHIFTL
            MOVE?ANN R0, Nout
        endif
        endm
    SHIFTL_USED = 1
      endmod
    I'll let the guys know.
    <br>
    DT

  2. #2
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    Yep, that fixed it. Thanks DT.

    I'm surprised that the bug hasn't been found before now.

    Out of curiosity, why did it only affect the shift on the last line, and not the first three?

    Code:
    T = X << 1
    T = T << 1
    T = T << 1
    Y = T << 1 + T + X
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kamikaze47
    why did it only affect the shift on the last line, and not the first three?
    Exactly, that was the question I had too.

    But as it turns out, the problem was in the 3rd/4th byte, only when shifting 1 place. Found that easily using the ISIS simulator.
    So shifting 8100 the first time, wasn't big enough for the 3rd/4th byte to matter.

    With the second and third shift it uses a different part of the macro.
    The Input and Output variables are the same (Nout) == (Nin), so it uses the code in Red (4 instructions)

    Then on the last line, the Input and Output variables were different, so it used the code in blue, the number was big enough, and the 3rd byte was corrupt.
    --Error-- Danger Will Robinson, Danger, Danger.

    Code:
    SHIFTL?NCN macro Nin, Cin, Nout
        if ((Cin) == 1)
            bcf     STATUS, C
          if ((Nout) == (Nin))
            CHK?RP  Nout
            rlcf    Nout, F
            rlcf    (Nout) + 1, F
            rlcf    (Nout) + 2, F
            rlcf    (Nout) + 3, F
          else
            CHK?RP  Nin
            rlcf    Nin, W
            MOVE?AB Nout
            CHK?RP  Nin
            rlcf    (Nin) + 1, W
            MOVE?AB (Nout) + 1
            CHK?RP  Nin
            rlcf    (Nin) + 2, W
            MOVE?AB (Nout) + 2
            CHK?RP  Nin
            rlcf    (Nin) + 3, W     ; was 2
            MOVE?AB (Nout) + 3
          endif
        else
            MOVE?NN Nin, R0
            movlw   Cin
            L?CALL  SHIFTL
            MOVE?ANN R0, Nout
        endif
        endm
    SHIFTL_USED = 1
      endmod
    To answer your previous question.

    When you shift more than 1 place at a time, it copies the variable to a system register, saves how many bits to shift, then calls a Library routine (SHIFTL) to loop through the number of shifts required. There's quite a bit of overhead in that saving and looping. (the Magenta code)

    Avoiding that is how I got the speed increase in my previous post.
    Although my previous numbers have no bearing on PBPL.

    If that actually made any sense, I will eat a bug.
    DT

  4. #4
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    If that actually made any sense, I will eat a bug.
    Made sense to me, so eat up.

    Thanks DT for your in depth analysis. All is clear now.
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

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