Shop OBEX P1 Docs P2 Docs Learn Events
Spin2 Operator Syntax - Page 11 — Parallax Forums

Spin2 Operator Syntax

18911131418

Comments

  • Cluso99 wrote:
    And works for both PASM and SPIN!
    Works for PASM. Still prefer <# and #> for Spin.

    -Phil

    Why not something that actually makes sense at quick glance
  • jmgjmg Posts: 15,173
    Be careful when talking about modulus and remainder. They're not the same thing:

    http://www.sitecrafting.com/blog/modulus-remainder/

    Well, yes, signed can show variances, and what is actually done 'in the wild' seems somewhat loose (as in your link)

    There is also this, for FreePascal
    "Mod (modulus) divides two numbers and returns only the remainder. For instance, the expression "a:= 13 mod 4;" would evaluate to 1 (a=1), while "b := 12 mod 4;" would evaluate to 0 (b=0).
    From the language reference:
    "The sign of the result of a Mod operator is the same as the sign of the left side operand of the Mod operator. In fact, the Mod operator is equivalent to the following operation :"
    I mod J = I - (I div J) * J
    For example "c:= -13 mod 4;" results in c = -1 and "c:= 10 mod -3;" results in c = 1.
    This is also what most other languages like C++ and Java do

    From version 3.1.1 FreePascal also supports the mod operator for floating point values when you include the math unit.
    "


  • cgracey wrote: »
    jmg wrote: »
    cgracey wrote: »
    For PASM we could use:

    SETMIN
    SETMAX
    SETMINS
    SETMAXS
    Yes, but for SETMIN, I presume that is the lower bound, so you actually seek >= or GE which is the larger of a pair of values.
    Now you have used a MIN root word, to select the largest of two values.
    Compare that with the common WEB definitions of MIN ?
    Better than SETMIN, would be SETGE, as Greater or Equal is the operation performed in setting the lower-boundary.

    SETGE
    SETLE
    SETSGE
    SETSLE

    Their meaning doesn't pop out, though they are not that bad.

    But SETMIN would set D to a minimum value, in case it was under. I think anyone should understand that. I mean, what else could SETMIN be suspected of doing?
    @Chip,
    with SET I have the perception that I am preparing (parametrizing) the environment for an other instruction.

    LIMGE/LE/SGE/SLE is more clear to me.

    if you dislike LIM also CLIP/CLAMP is fine.
  • cgraceycgracey Posts: 14,152
    For P2 PASM, how about:

    FLE (force less-than or equal)
    FGE (force greater-than or equal)
    FLES, FGES (similarly for signed)

    -Phil

    I like these, too, and they cover both signed and unsigned. Now, does FLE replace MIN or MAX? Just kidding about that part.

    MIN becomes FGE
    MAX becomes FLE
    MINS becomes FGES
    MAXS becomes FLES

    #> is really FGES (FGES would be an ugly spin operator)
    <# is really FLES (FLES would be an ugly spin operator)

    One other thing is that GE and LE are nomenclature used on signed comparisons. Unsigned often uses AE and BE, right? What about:

    MIN becomes FAE
    MAX becomes FBE
    MINS becomes FGE
    MAXS becomes FLE

    We can avoid using 4-letter words, then.
  • T Chap wrote:
    Why not something that actually makes sense at quick glance
    That's the reason I like <# and #>. Operators should look like operators, not variable names.

    -Phil
  • cgraceycgracey Posts: 14,152
    edited 2017-04-14 21:50
    T Chap wrote: »
    Cluso99 wrote:
    And works for both PASM and SPIN!
    Works for PASM. Still prefer <# and #> for Spin.

    -Phil

    Why not something that actually makes sense at quick glance

    The only thing I can think of that would make sense, at first glace, for a Spin operator would be:

    x AT_LEAST 5 AT_MOST 10
  • For P2 PASM, how about:

    FLE (force less-than or equal)
    FGE (force greater-than or equal)
    FLES, FGES (similarly for signed)

    -Phil
    Also OK, like them
  • jmgjmg Posts: 15,173
    cgracey wrote: »
    I like these, too, and they cover both signed and unsigned. Now, does FLE replace MIN or MAX? Just kidding about that part.

    MIN becomes FGE
    MAX becomes FLE
    MINS becomes FGES
    MAXS becomes FLES

    #> is really FGES (FGES would be an ugly spin operator)
    <# is really FLES (FLES would be an ugly spin operator)

    One other thing is that GE and LE are nomenclature used on signed comparisons. Unsigned often uses AE and BE, right? What about:

    MIN becomes FAE
    MAX becomes FBE
    MINS becomes FGE
    MAXS becomes FLE

    We can avoid using 4-letter words, then.
    AE and BE are quite rare usage tho, I've not seen language usage of them, but I have seen GE, LE, LT, GT EQ, NE etc often supported.

    but you could do this in PASM

    MIN becomes FGEU
    MAX becomes FLEU
    MINS becomes FGE
    MAXS becomes FLE
    (ie make signed the default)

    and now FGE, FLE can become (less ugly) aliases to the spin signed operators


  • T ChapT Chap Posts: 4,223
    edited 2017-04-14 21:59
    Anything that is more easily remembered. #> is stigmatized for me it drives me nuts. Function over form in this case
  • T ChapT Chap Posts: 4,223
    edited 2017-04-14 22:00
    X LIMLO 5 LIMHI 10. X LLO 6 LHI 10
  • jmgjmg Posts: 15,173
    T Chap wrote: »
    Why not something that actually makes sense at quick glance
    T Chap wrote: »
    Anything that is more easily remembered. #> is stigmatized for me it drives me nuts. Function over form in this case

    what about the clarity of these ?
      Elev := 1000 FGE Elev FLE 2000  
      Elev := 1000 LIMGE Elev LIMLE 2000  
    


  • AribaAriba Posts: 2,690
    edited 2017-04-14 22:19
    or:
      x !LT 5 !GT 10
    

    or:
      x !< 5 !> 10
    
  • x LO 5 HI 10
  • cgracey wrote:
    x AT_LEAST 5 AT_MOST 10
    Kinda wordy.
    Ariba wrote:
    x !LT 5 !GT 10
    I could live with that, or perhaps better: x !< 5 !> 10. Still like <# and #> better.

    -Phil
  • cgraceycgracey Posts: 14,152
    Ariba wrote: »
    or:
      x !< 5 !> 10
    

    I think this looks great.
  • I'm content with it. -P.
  • AribaAriba Posts: 2,690
    a = min(b,c); in C would then translate to:
    a := b !> c
    
    I find this quite readable, the NOT GREATER value is the LOWER one of b and c.

    Andy
  • cgraceycgracey Posts: 14,152
    Ariba wrote: »
    a = min(b,c); in C would then translate to:
    a := b !> c
    
    I find this quite readable, the NOT GREATER value is the LOWER one of b and c.

    Andy

    Okay. This will be the Spin syntax, then:

    #> becomes !<
    <# becomes !>

    Is that correct? That syntax is so simple and nice! We still need to decide on the PASM instructions.
  • cgraceycgracey Posts: 14,152
    edited 2017-04-14 22:50
    I suppose someone could think that !< means >=. Kind of like !=. Too bad we have to resort to a NOT (!) character when all we really need is some kind of verb and a > or <. If there was something that meant the opposite of !, we could use it with the opposite >, <.

    I think !< and !> make some immediate sense to the reader, though. #> and <# looked quite ambiguous.
  • It is not bad, it is what it is.

    if !< means "clamp to" ("lower limit is") a given number, than the result will be => of the specified number
  • jmgjmg Posts: 15,173
    edited 2017-04-14 23:02
    cgracey wrote: »
    Okay. This will be the Spin syntax, then:

    #> becomes !<
    <# becomes !>

    Is that correct? That syntax is so simple and nice! We still need to decide on the PASM instructions.

    some P1 code like this (from earlier) should ideally be simple-translatable to P2....
    Elev := 1000 #> Elev <# 2000
    can be
    Elev := 1000 FGE Elev FLE 2000
    or
    Elev := Elev FGE 1000 FLE 2000
    all are bound 1000..Elev..2000 (which is another syntax candidate )

    x := x !< 5 !> 10
    simple swap gives
    x := 5 !< x !> 10
    is this last one still 5..10 ?
    FGE allows operand reversal, but does !< ?
    I think it needs to become instead
    x := 5 !> x !> 10


  • AribaAriba Posts: 2,690
    edited 2017-04-14 23:27
    About PASM menonics:
    For me MIN,MAX work a bit like CMPSUB , only that it does not Subtract but Move.

    So maybe:
      CMPSLT  x,#5    'compare, set if lower than (signed)
      CMPSGT  x,#10
    
      CMPMLT  x,#5    'compare, move if lower than (unsigned)
      CMPMGT  x,#10
    
    Just brainstorming...

    CMPFLT, CMPSFLT, CMPFGT, CMPSFGT are alternatives (F = Force as Phil suggested)
  • jmgjmg Posts: 15,173
    edited 2017-04-14 23:17
    cgracey wrote: »
    I think !< and !> make some immediate sense to the reader, though. #> and <# looked quite ambiguous.
    #> and #< have no obvious decode, you have to go to the manual.

    !< are more decodable, but it says not-less-than, which I think now makes operand order matter to the reader.
    Actual field Spin usage seems to be a mix of both ways above (ie order agnostic) ?
  • RaymanRayman Posts: 14,646
    I think the !< stuff is great
    Much better than#
  • kwinnkwinn Posts: 8,697
    Rayman wrote: »
    I think the !< stuff is great
    Much better than#

    +1
  • Cluso99Cluso99 Posts: 18,069
    cgracey wrote: »
    Ariba wrote: »
    a = min(b,c); in C would then translate to:
    a := b !> c
    
    I find this quite readable, the NOT GREATER value is the LOWER one of b and c.

    Andy

    Okay. This will be the Spin syntax, then:

    #> becomes !<
    <# becomes !>

    Is that correct? That syntax is so simple and nice! We still need to decide on the PASM instructions.

    Excellent. (I was going to put Excellent! but that could be misinterpreted;) )
  • Cluso99Cluso99 Posts: 18,069
    edited 2017-04-15 10:14
    For PASM...
    NOTLT D,#S
    NOTGT D,#S
    NOTLTS D,#S
    NOTGTS D,#S

    Otherwise FLE, FGE, FLES, FGES are fine.
  • jmgjmg Posts: 15,173
    edited 2017-04-15 10:10
    Err, has everyone fully grasped this new !< !> syntax now imposes restrictions on the operator order ?
    That restriction was not there on the old syntax.
    If you say 'Hey, let's allow either order', in one case the opcode does not do what it literally says.
    Which repeats the problem of backwards MIN, where what happens is not what the code says..
  • Cluso99Cluso99 Posts: 18,069
    jmg wrote: »
    Err, has everyone fully grasped this new !< !> syntax now imposes restrictions on the operator order ?
    That restriction was not there on the old syntax.
    If you say 'Hey, let's allow either order', in one case the opcode does not do what it literally says.
    Which repeats the problem of backwards MIN, where what happens is not what the code says..
    Please explain?
  • jmgjmg Posts: 15,173
    Cluso99 wrote: »
    jmg wrote: »
    Err, has everyone fully grasped this new !< !> syntax now imposes restrictions on the operator order ?
    That restriction was not there on the old syntax.
    If you say 'Hey, let's allow either order', in one case the opcode does not do what it literally says.
    Which repeats the problem of backwards MIN, where what happens is not what the code says..
    Please explain?
    Already did above...
    This is OK
    Elev := 1000 #> Elev <# 2000
    Which is equivalent to
    Elev := 1000 FGE Elev FLE 2000
    or, this can be re-ordered as
    Elev := Elev FGE 1000 FLE 2000
    all are bound 1000..Elev..2000 (which is another syntax candidate )

    This is ok
    x := x !< 5 !> 10
    simple order swap gives
    x := 5 !< x !> 10
    but what does that now say ? 5 is NOT less Than X, which means 5 is >= X, and X=1 will output 1.
    It is ok to re-code like this
    x := 5 !> x !> 10
    .. but here the operator flips when the order flips, which the old opcode did not require (nor does FGE).


Sign In or Register to comment.