Which conditional expression is faster?


Results 1 to 5 of 5

Threaded View

  1. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink

    Quote Originally Posted by RussMartin View Post
    Which of these is faster to execute?

    IF A+B+C=0 THEN . . .

    or

    IF A=0 AND B=0 AND C=0 THEN . . .

    Hi, RUSS

    A+B+C = 0 has many solutions AS ... you use an ADDITION and not a Bitwise AND !!!

    253 + 2 + 1 = 0 .... for Bytes !!!
    1 + 1 + 0 = 0 ... for Bits !!!

    so, It can't be equivalent to the second line ... Too Bad !


    Now, let's suppose A, B, C are BITs ...



    so

    Code:
    IF  A | B | C  THEN Z = 1...
    Will be the fastest ... with PBP.`( 17 asm Lines ...)

    Code:
    IF  (NOT A & NOT B & NOT C ) THEN Z = 1
    is somewhat longer ...

    BUT, if A,B,C are inputs ... would be faster to mask the other inputs and test if result is 0

    Code:
    IF ( PORTx & %00000111 ) THEN Z = 1
    Only 12 asm lines ...

    Alain
    Last edited by Acetronics2; - 15th February 2009 at 20:46.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. conditional defines in PBP?
    By rdxbam in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 13th March 2010, 15:40
  2. Replies: 5
    Last Post: - 28th May 2008, 11:20
  3. interrupt handling faster than if's?
    By mbw123 in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 27th October 2006, 02:25
  4. OT - Firefox browser - faster performance
    By malc-c in forum Off Topic
    Replies: 2
    Last Post: - 14th August 2006, 11:33
  5. Conditional Compilation
    By milestag in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd March 2006, 21:29

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