Shop OBEX P1 Docs P2 Docs Learn Events
One operator is faster than the other := 0 or ~ — Parallax Forums

One operator is faster than the other := 0 or ~

BitsBits Posts: 414
edited 2012-05-31 18:34 in Propeller 1
I ran the following pubs and found that Test_a was faster than Test_b. I did not expect this at all. Seems to me that using the := 0 would require more processing than the ~.
Whats the reasoning to this? Anyone have an idea? Thanks
Pub Test_a 
  
  result := -cnt 
  outa[DClk] := 1                                                                
  outa[DClk] := 0
  result += cnt - 544
  
Pub Test_b
 
  result := -cnt 
  outa[DClk]~~                                                                
  outa[DClk]~
  result += cnt - 544

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-05-31 08:36
    It could be because the ~~ operator sets its operand to -1 and that to apply this to a single outa pin requires some additional bit masking. Try the individual operators separately and also on some long variables to see how they compare. Be sure to use "-1" instead of "1" in Test_a so that you're comparing apples with apples.

    -Phil
  • BitsBits Posts: 414
    edited 2012-05-31 08:47
    I tested using -1 and it actually increased speed in Test_a something funny here. You bring up a good point, is ~ the same as -1? I ask because will outa[Dclk] := -1 makes the i/o pin a low?


    *edited. . .


    I tested using -1 and it actually increased speed in Test_a something funny here. <- It is wrong its the same speed. Still I ask the question above.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-05-31 08:50
    ~~ (not ~) is the same as := -1. Setting a pin to -1 will make it go high.

    -Phil
  • BitsBits Posts: 414
    edited 2012-05-31 09:02
    Yea that is what I thought.

    As a side note, I am finding that "IF" commands are faster than "Case" commands. I wonder if there is a thread that has all the speed vs commands etc.
  • BitsBits Posts: 414
    edited 2012-05-31 09:05
    More speed testing, Test_e is much faster than Test_d.
    Pub Test_d | p
    
    
      P := 5 
      result := -cnt  
      P := P + 5
      result += cnt - 544        
                
    Pub Test_e | p
    
    
      P := 5 
      result := -cnt  
      P += 5
      result += cnt - 544
    
  • T ChapT Chap Posts: 4,223
    edited 2012-05-31 17:03
    There are a few gotchas with the minimal commands. For example, try adding a limit MIN or MAX to P += 5
  • localrogerlocalroger Posts: 3,452
    edited 2012-05-31 18:34
    Spin bytecode has a few "conveniences" that sometimes make things improbably fast (or slow). The byte codes for V~~ and V := -1 are not the same, but they are the same size and execute at about the same speed, because the Spin compiler reduces everything to RPN and there is a single byte code that pushes -1. There is a similar bytecode that pushes zero. Meanwhile, ~ and ~~ have to be interpreted via their own operator byte codes. The expression evaluator is also a piece of art which should be hanging in the Louvre as I have never seen anything quite like it for internal consistency, raw power, and middle finger to mere other ways of doing things that might look better but not work quite as well.
Sign In or Register to comment.