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

Spin2 Operator Syntax

17810121318

Comments

  • Roy ElthamRoy Eltham Posts: 3,000
    edited 2017-04-14 03:06
    Cluso,
    In OpenSpin, I could have an option that would make it have whatever Spin2 features are reasonable on the P1 also. I can't change the built in rom image for the interpreter, but I can change things like keywords and instruction names for Spin/PASM quite easily. I can also add some new stuff, like the ? : operator, and other new things.

    Of course, this would largely be up to Parallax/Chip to decide if they want it in the official version of OpenSpin. It would have to be an option, so that all the existing code would still work. It's a little iffy, since it means we'd now have a Spin 1.5 (or whatever). there would be confusion if PropTool didn't get updated to use OpenSpin also, so that it works in official tools.
  • Roy,

    That sounds like a great idea! Please use whatever influence you have with Parallax to modify PropTool to use OpenSpin. Also, be sure to create a command-line version that can replace Propellent without modifying any of its command-line options. If you then call it Propellent, other tools that rely upon it should work without modification.

    Thanks,
    -Phil
  • Phil,
    I have talked with Jeff Martin a couple times about putting OpenSpin into PropTool, and he seemed keen, it's just a matter of work on his part in PropTool now. However, he has been busy will lots of other things. I have made changes to OpenSpin so it will fit the proptool model better (like you give it a function to call when it wants to open/get a file, so it can deliver the data from a in memory tab/window or from disk. However, PropTool needs some other work to support new stuff like larger symbols, unused method elimination, and some other minor stuff. Ken/Jeff need to decide when that is a priority enough for them to do the work.
  • cgraceycgracey Posts: 14,134
    Ariba wrote: »
    cgracey wrote: »
    I will change back to #> and <#.

    Not sure how to rename the PASM mnemonics.

    How about these mnemonics:

    MINU, MAXU for unsigned version
    MINS, MAXS for the signed version

    So min and max are no longer reserved words, and the menmonics do not look like min(,) max(,) macros in C.

    Andy

    These are simple, not far from what we've got (except some feel they are backwards), and they free up the names MIN and MAX. I like these.
  • jmgjmg Posts: 15,161
    edited 2017-04-14 06:59
    Ariba wrote: »
    How about these mnemonics:

    MINU, MAXU for unsigned version
    MINS, MAXS for the signed version

    So min and max are no longer reserved words, and the menmonics do not look like min(,) max(,) macros in C.

    That would be fine, but PASM1 already defines MAXS (MAX Signed) the backwards way, so instantly there is conflict/confusion.
    This fix requires a new name, that aligns with what the operator actually does.

    Cryptic operators merely send users straight to the manual (unless there is also a comment explaining what the code does, in which case underlining why cryptic operators are not a good idea, if you need to write things twice: once for the machine, and again for the human reader)

  • and they free up the names MIN and MAX. I like these.

    I do too.

  • jmgjmg Posts: 15,161
    edited 2017-04-14 06:15
    Cluso99 wrote: »
    Here are some possible suggestions for naming...
    Possible suggestions:
              --P1--  -----new suggestions---------------------------------------------------
    PASM2:
              MAX     MIN     LOWER   LOLIM   LIMLO   LIMITL  LIMITLO LIMMIN  CLAMPL  CLAMPLE  
              MAXS    MINS    LOWERS  LOLIMS  LIMLOS  LIMITLS LIMITLS LIMMINS CLAMPLS CLAMPLS 
              MIN     MAX     UPPER   HILIM   LIMHI   LIMITH  LIMITHI LIMMAX  CLAMPU  CLAMPGE  
              MINS    MAXS    UPPERS  HILIMS  LIMHIS  LIMITHS LIMITHS LIMMAXS CLAMPUS CLAMPGS 
    SPIN2:
              #>      #>      LOWERS  LOLIMS  LIMLOS  LIMITLS LIMITLS LIMMINS CLAMPLS CLAMPLS
              <#      <#      UPPERS  HILIMS  LIMHIS  LIMITHS LIMITHS LIMMAXS CLAMPUS CLAMPGS
    

    Once decided, can we back fix (the same into???) P1 PASM1 and SPIN1 ???
    Yes, back fix into PASM1 and Spin1 should be simple to do, and deprecate the broken/confusion one.
    I prefer names closest to what the operator actually does, so simple LO and HI are out, as are L and H,

    Of the above, those with LE, GE meet what the operator does.

    There is also the TRIMLE, TRIMGE, TRIMSLE, TRIMSGE I suggested above (Trim Greater or Equal, and Trim Less or Equal), but CLAMPLE, CLAMPGE is equally readable, if one character longer.
    CLIPLE, CLIPGE is another possible variant, synonym of Trim,Clamp
    or LIMLE, LIMGE, LIMSLE, LIMSGE, adding limit to the list, but keeping the important LE (Less or Equal) , GE (Greater or Equal).

  • jmgjmg Posts: 15,161
    cgracey wrote: »
    I figured MIN (,) and MAX (,) were common C functions. I figured that must be where these notions came from.

    They are commonly defined as found on the web :

    FreePascal
    Min : Return smallest of two values.
    Max : Return largest of two values

    Python:
    min(iterable[, key])
    min(arg1, arg2, *args[, key])
    Return the smallest item in an iterable or the smallest of two or more arguments.

    max(iterable[, key])
    max(arg1, arg2, *args[, key])
    Return the largest item in an iterable or the largest of two or more arguments.
  • AribaAriba Posts: 2,687
    edited 2017-04-14 06:22
    JMG

    For sure they get not reversed, they work like always only that MIN & MAX get an U appended.

    On mnemonic level there is no "traditional way" or do you know any other CPU that has such Instructions?
    For me they align with what they actually do: Limiting to a min/max value.

    You always can read it like that:
    MINU = MIN Upside down
    MAXS = MAX Swapped
    ;)
  • The TRIMxx names may get confused with P2's TRIMR & TRIML instructions.
    I'm more comfortable with the MAXS,MAXU etc names.
  • jmgjmg Posts: 15,161
    Ariba wrote: »
    You always can read it like that:
    MINU = MIN Upside down
    MAXS = MAX Swapped
    ;)
    ROFL, now that makes some sort of perverse sense....., especially the upside down....

    Ariba wrote: »
    On mnemonic level there is no "traditional way" or do you know any other CPU that has such Instructions?
    Not so much pure ASM mnemonic, but certainly the MIN and MAX are very widely used, as found on the web above

    Min : Return smallest of two values
    Max : Return largest of two values

  • cgraceycgracey Posts: 14,134
    edited 2017-04-14 06:35
    For PASM we could use:

    SETMIN
    SETMAX
    SETMINS
    SETMAXS
  • jmgjmg Posts: 15,161
    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.

  • cgraceycgracey Posts: 14,134
    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?
  • jmgjmg Posts: 15,161
    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?
    SETMIN would set D to a minimum value, in case it was under.
    It does that by increasing the value of D, and the root semantics of SETMIN do not hint at any increase, rather the opposite

    As an example of code

    Thresh=20
    eg SETMIN 10,Thresh
    without reading a full manual, that includes in case it was under, which of two possible values of 10 & 20 would users expect the SETMIN exit value to be ? Minimum is the root.

    compare with
    SETGE 10,Thresh
    SETGE 25,Thresh

    is doing a Greater or Equal test, with a given Threshold. GE is == Not Less Than, so first exit value is 20, and second exit value is 25.
    No extra text reading is required.

  • Cluso99Cluso99 Posts: 18,069
    Roy Eltham wrote: »
    Cluso,
    In OpenSpin, I could have an option that would make it have whatever Spin2 features are reasonable on the P1 also. I can't change the built in rom image for the interpreter, but I can change things like keywords and instruction names for Spin/PASM quite easily. I can also add some new stuff, like the ? : operator, and other new things.

    Of course, this would largely be up to Parallax/Chip to decide if they want it in the official version of OpenSpin. It would have to be an option, so that all the existing code would still work. It's a little iffy, since it means we'd now have a Spin 1.5 (or whatever). there would be confusion if PropTool didn't get updated to use OpenSpin also, so that it works in official tools.
    Sounds good to me.

  • Heater. wrote: »
    min and max are often used in C. Generally as macros rather than functions.

    I can't think it through now but the simplistic macros David presents are full of problems when used with different types.

    Linus Torvalds made a bit of a storm about this when min/max was used badly in his kernel some years ago. The end result is this (from /kernel.h):
    /*
     * min()/max()/clamp() macros that also do
     * strict type-checking.. See the
     * "unnecessary" pointer comparison.
     */
    #define __min(t1, t2, min1, min2, x, y) ({              \
             t1 min1 = (x);                                  \
             t2 min2 = (y);                                  \
             (void) (&min1 == &min2);                        \
             min1 < min2 ? min1 : min2; })
    #define min(x, y)                                       \
             __min(typeof(x), typeof(y),                     \
                   __UNIQUE_ID(min1_), __UNIQUE_ID(min2_),   \
                   x, y)
     
    #define __max(t1, t2, max1, max2, x, y) ({              \
             t1 max1 = (x);                                  \
             t2 max2 = (y);                                  \
             (void) (&max1 == &max2);                        \
             max1 > max2 ? max1 : max2; })
    #define max(x, y)                                       \
            __max(typeof(x), typeof(y),                     \
                  __UNIQUE_ID(max1_), __UNIQUE_ID(max2_),   \
                  x, y)
    
    


    Yeah, you have to be careful when using the simple ones. For one thing, they reference one argument twice so any side effects would happen twice. I would only use those for very simple cases. In fact, since the simple macros require such care when used I'm surprised that math.h doesn't include the more complex ones. The ones I showed are easy enough to add yourself but adding the more complex and safer ones is quite cumbersome.
  • Q: in the forum:
    I need the smaller of two values (b,c) in a variable a.
    I tried a:=MIN(b,c) but it doesn't work.
    A::
    you have to use a:=MAX(b,c)
    you have to use a:=LOLIM (b,c)
    you have to use a:=LIMLO (b,c)
    you have to use a:=LIMITL(b,c)
    you have to use a:=LIMITLO(b,c)
    you have to use a:=LIMMIN(b,c)
    you have to use a:=CLAMPL(b,c)
    you have to use a:=CLAMPLE (b,c)
    Q: oh well

  • LIMHI LIMLO LIMSHI LIMSLO
  • Heater.Heater. Posts: 21,230
    edited 2017-04-14 11:50
    A: TL;DR(WTF(LOL(b,c)))
  • Heater. wrote: »
    A: TL;DR(WTF(LOL(b,c)))

    Ahh! Functions! I'm glad to see we're finally on the same page. ;):D

  • AribaAriba Posts: 2,687
    A:
    a := b <# c
  • Dave HeinDave Hein Posts: 6,347
    edited 2017-04-14 13:25
    Yes, just use <#. Is that the minimum of b and c or the maximum? I need to go look that up again. :)

    Seriously though, I agree with T Chap's suggestions: LIMHI LIMLO LIMSHI LIMSLO
  • T ChapT Chap Posts: 4,223
    edited 2017-04-14 13:18
    a := b <# c I have no idea what this means. My brain will not memorize this after 10 years of using it. So in every application of using it I put a comment so I can then copy and paste it to new uses.
  • kwinnkwinn Posts: 8,697
    Why not use MIN and MAX to select the minimum or maximum of two values and LIM to limit a result to a range? So:

    X := LIM (expression) 0, 99
  • For P2 PASM, how about:

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

    -Phil
  • jmgjmg Posts: 15,161
    For P2 PASM, how about:

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

    That's fine too, as it has the important LE GE in there.
    The Force/Trim/Set/Clip/Clamp prefix is somewhat less important, and FLE will appeal to those who like very compact mnemonics.

  • Be careful when talking about modulus and remainder. They're not the same thing:

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

    -Phil
  • Cluso99Cluso99 Posts: 18,069
    For P2 PASM, how about:

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

    -Phil
    Yes! Love it! Short and to the point! And works for both PASM and SPIN!
  • Cluso99 wrote:
    And works for both PASM and SPIN!
    Works for PASM. Still prefer <# and #> for Spin.

    -Phil
Sign In or Register to comment.