Shop OBEX P1 Docs P2 Docs Learn Events
SFUNC question - Page 7 — Parallax Forums

SFUNC question

145791013

Comments

  • jmgjmg Posts: 15,173
    cgracey wrote: »
    They were great, in their own domain, but they didn't fit syntactically. They felt like a separate processor architecture.
    In many ways they are a separate processor - boolean opcodes are always something of an ill fit to all others.
    Their operation is unique, but they are grouped, so that is fine.
  • cgraceycgracey Posts: 14,152
    jmg wrote: »
    cgracey wrote: »
    They were great, in their own domain, but they didn't fit syntactically. They felt like a separate processor architecture.
    In many ways they are a separate processor - boolean opcodes are always something of an ill fit to all others.
    Their operation is unique, but they are grouped, so that is fine.

    But those C and Z flags are expressed so differently between the two domains. It's too persnickety.
  • Chip, I really like CLAMPHI for what is now MAX (which is taking the smaller of the two values and putting it in D) and CLAMPLO for MIN (which is taking the larger of the two values and putting it in D).
    You could use some shorter variant of those, if you really want, but they are 7 chars so they fit your tabstop limit.

    That is the actual operation being done. Clamp.
  • jmgjmg Posts: 15,173
    cgracey wrote: »
    Really quick, does anyone remember what we were going to rename MIN/MAX/MINS/MAXS to?
    At which stage ? ;)
    - seems there were many choices, with CLAMP,TRIM being closest to what the opcode does, and shorter versions like FGE, FLE tolerated operator reversal, which matters in some existing P1 code.
    Some choices failed operator reversal, and confused even experienced programmers, so those are probably best avoided ?
    Personally, I prefer words over glyphs... less culture shock to new readers.
  • cgraceycgracey Posts: 14,152
    edited 2017-05-04 04:40
    ANDCB   d,s     WC
    ANDCNB  d,s     WC
    ANDBC   d,s
    ANDBNC  d,s
    
    ANDZB   d,s     WZ
    ANDZNB  d,s     WZ
    ANDBZ   d,s
    ANDBNZ  d,s
    
    That is what it would take to make it fit.

    Meanwhile, all I've ever needed to do is read or write a bit:
    BITC    d,s     WC
    
  • jmgjmg Posts: 15,173
    cgracey wrote: »
    jmg wrote: »
    cgracey wrote: »
    They were great, in their own domain, but they didn't fit syntactically. They felt like a separate processor architecture.
    In many ways they are a separate processor - boolean opcodes are always something of an ill fit to all others.
    Their operation is unique, but they are grouped, so that is fine.

    But those C and Z flags are expressed so differently between the two domains. It's too persnickety.
    I did not really see that.
    CF, ZF seemed more confusing than needed, whilst C,Z are the clearest possible, as you've shown in using those C and Z flags phrase in your post.

    The wc, wz are fine for suffix, as they do WRITE to those flags, and you could easily write wC wZ, if you wanted to more easily see Z & C everywhere...
    In the suffix form, there is still C and Z visible, they just have write tag added to them, as a prefix

  • cgraceycgracey Posts: 14,152
    Roy Eltham wrote: »
    Chip, I really like CLAMPHI for what is now MAX (which is taking the smaller of the two values and putting it in D) and CLAMPLO for MIN (which is taking the larger of the two values and putting it in D).
    You could use some shorter variant of those, if you really want, but they are 7 chars so they fit your tabstop limit.

    That is the actual operation being done. Clamp.

    What about signed versions?
  • jmgjmg Posts: 15,173
    edited 2017-05-04 05:03
    cgracey wrote: »
    ANDCB   d,s     WC
    ANDCNB  d,s     WC
    ANDBC   d,s
    ANDBNC  d,s
    
    ANDZB   d,s     WZ
    ANDZNB  d,s     WZ
    ANDBZ   d,s
    ANDBNZ  d,s
    
    That is what it would take to make it fit.
    Problem there is, I've got no idea what the final destination is, without reading it 4 times, and trying to remember what destinations are possible.
    The location for Source's and final Destination bounce around
    Seeing that code, I could try to write WC WZ, thinking that's fine, as it's Ok everywhere else...
    I could also expect WC to clone/copy a value of a bit, as that's what WC means elsewhere...
    eg
    CLRB  d,s  WC  
    NOTB  d,s  WC  
    
    reads as tho it acts on the bit and copies to C ? - but that's not what the silicon does, so this needs an error message...

    Then, there will be common typos ...
    ANDBC   d,s  WC
    ANDBNC  d,s  WC
    
    ANDZB   d,s   WZ
    ANDZNB  d,s   WZ
    ANDBZ   d,s   WZ
    
    Who can tell me, at a single glance, which of those is actually illegal ? (hint: some are)

    See the problems when you try to force it into one domain ? - the fundamentals are too different, and you instead create a sea of exceptions.

  • jmgjmg Posts: 15,173
    cgracey wrote: »
    What about signed versions?

    There was this post from the other thread.. (pg 11)

    cgracey wrote: »
    I like these, too, and they cover both signed and unsigned.

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


    but I got lost around which applied to PASM and which applied to Spin2 ?
  • Roy Eltham wrote: »
    Chip, I really like CLAMPHI for what is now MAX (which is taking the smaller of the two values and putting it in D) and CLAMPLO for MIN (which is taking the larger of the two values and putting it in D).
    You could use some shorter variant of those, if you really want, but they are 7 chars so they fit your tabstop limit.

    That is tihe actual operation being done. Clamp.

    @Roy, I usually like the way you are thinking, but have to disagree here again.

    clampHI for taking the smaller value? clampLO to take the bigger one? Isn't that the same mess we have already with MAX being the smaller value and MIN the bigger one?

    Just stop this whole CLAMPing mess and name it like in all other languages used. MAX for the bigger of two values and MIN for the smaller ones?

    why should a:= clampHI(a,b) be more readable then a:= MIN(a,b)

    In my not so humble opinion, @Chip messed this up BADLY in SPIN1 and PASM1. The complete concept of CLAMPing is just wrong and gives, besides confusion for anybody, no value at all.

    Forget all the CLAMPxx BS.

    The operation is not CLAMPHI but MIN. just name it like it is.

    And yes it will be different from PASM1 and SPIN1, and it will be good to be different because @Chip messed that up really badly in the P1. (Sorry @Chip, but it is true)

    Enjoy!

    Mike
  • cgraceycgracey Posts: 14,152
    it's a matter of perspective.
  • jmgjmg Posts: 15,173
    edited 2017-05-04 05:32
    msrobots wrote: »
    ...
    why should a:= clampHI(a,b) be more readable then a:= MIN(a,b)

    In my not so humble opinion, @Chip messed this up BADLY in SPIN1 and PASM1. The complete concept of CLAMPing is just wrong and gives, besides confusion for anybody, no value at all.

    Forget all the CLAMPxx BS.

    The operation is not CLAMPHI but MIN. just name it like it is.

    And yes it will be different from PASM1 and SPIN1, and it will be good to be different because @Chip messed that up really badly in the P1. (Sorry @Chip, but it is true)

    I would avoid having the same keyword, but flipped in 2 variants of the same language. (*shudders*)
    That means MIN and MAX are effectively tarnished, and best discarded.
    This is where FGE has an edge, it is clear the result is greater or equal to either operand aka Pick Higher Of
  • cgraceycgracey Posts: 14,152
    HILIM
    LOLIM
    HILIMS
    LOLIMS

    CLAMPL
    CLAMPH
    CLAMPLS
    CLAMPHS
  • Clamp is clamping to the given value. So it would take the smaller for the hi case, and larger for the lo case. You clamp to between your values. It's a common operation in graphics, and it's a single 3 operand instruction on GPUs and the like. Clamp( val, min, max) would clamp val to be between min and max.

    It makes sense to me.
  • jmgjmg Posts: 15,173
    Roy Eltham wrote: »
    Clamp is clamping to the given value. So it would take the smaller for the hi case, and larger for the lo case. You clamp to between your values. It's a common operation in graphics, and it's a single 3 operand instruction on GPUs and the like. Clamp( val, min, max) would clamp val to be between min and max.

    It makes sense to me.
    Yes, it makes sense as a 3 parameter function call. Is that the proposal now ?
    However, it is less sense for 2 operands that CLAMPLO would give the LARGER of 2 operands. Nothing about LO, hints at largest.
    CLAMPGE is more accurate.

  • msrobotsmsrobots Posts: 3,709
    edited 2017-05-04 05:54
    Exactly!

    CLAMP is a three operand instruction and a even useful one. To clamp something, you need a value to clamp (destination) and two values to clamp in between.

    A vise is a perfect example. if you have nothing to clamp in between its useless. And if the vise is missing one clamp its useless also.

    But since weeks we try to find nice words to describe 2 operand instructions commonly known as MIN or MAX with words like

    HILIM
    LOLIM
    HILIMS
    LOLIMS

    CLAMPL
    CLAMPH
    CLAMPLS
    CLAMPHS

    Really?

    It is just a matter of perspective. But clamping needs 3 operands, min/max just 2..
    Mike
  • cgraceycgracey Posts: 14,152
    Ay, ay, ay....

    FGE
    FLE
    SFGE
    SFLE
  • cgraceycgracey Posts: 14,152
    What about:

    FMIN
    FMAX
    FMINS
    FMAXS
  • jmgjmg Posts: 15,173
    edited 2017-05-04 06:11
    cgracey wrote: »
    Ay, ay, ay....
    FGE
    FLE
    SFGE
    SFLE
    Yes, seems that works for both usage forms seen in the field
    Elev := 1000 FGE Elev FLE 2000 
    // and also
    x FGE 5 FLE 10
    

    I'm not sure of the code sizes - are those going to create the same final code ?
    I prefer the first style, as it is very clear where the result lands, and even if you have no idea what FGE,FLE mean, the code order and GE and LE give big clues.
  • jmgjmg Posts: 15,173
    cgracey wrote: »
    What about:

    FMIN
    FMAX
    FMINS
    FMAXS
    ... that uses those tarnished keywords, as roots, (best avoided) .....

  • cgracey wrote: »
    What about:

    FMIN
    FMAX
    FMINS
    FMAXS

    yes, if FMIN returns the smaller value into the destination..

    Mike
  • jmgjmg Posts: 15,173
    msrobots wrote: »
    cgracey wrote: »
    What about:

    FMIN
    FMAX
    FMINS
    FMAXS

    yes, if FMIN returns the smaller value into the destination..

    Mike

    Under that rule, the above code becomes
    Elev := 1000 FMAX Elev FMIN 2000 
    
    Not quite a natural/easy scan, with MAX next to the MIN setpoint and MIN next to the max setpoint ?

  • msrobotsmsrobots Posts: 3,709
    edited 2017-05-04 06:48
    You are clamping again.

    My proposal is to get rid of the whole clamp concept.

    Min is minimum max is maximum

    fmax dest, source should give the larger value
    fmin dest, source should give the lesser one

    to clamp in Pasm you would do

    fmax elev,##1000 // get bigger value into elev
    fmin elev, ##2000 // get smaller value into elev

    clamp in SPIN would be

    Elev := clamp((1000, Elev, 2000)

    as most readable form

    better then

    Elev := 1000 !> Elev !< 2000
    or was it
    Elev := 1000 #> Elev #< 2000
    or was it
    Elev := 1000 #< Elev #> 2000
    or was it
    Elev := 1000 <# Elev ># 2000
    or
    Elev := 1000 FMAX Elev FMIN 2000

    GOD dmn.. Get the stupid manual again


    MIKE
  • The with ClampLo you are giving it the value to clamp and the value to clamp it to. For Lo you are giving it the mininum value of the clamp operation. So it returns either your input value if it's greater than the minimum, or it return the minimum you specified. It makes perfect sense.
    And vice versa for ClampHi.

    My first preference has already been rejected, I wanted min and max to just swap names, because that makes sense.
    Chip seems insistent on keeping the "limit min" & "limit max" concepts instead of just the normal MIN and MAX that everyone else in the world is uses to except him and other P1 PASM people (and most of them hate it).
    To me the ClampLo and ClampHi names fit what they do more if you keep the concept Chip is insisting on. I wish he would just swap the names and have them work like EVERYONE but him expects them to work.
  • why do they need the F prefix? Just call them MIN/MAX and MINS/MAXS, and make them work like everyone wants them to work instead of backwards like P1 PASM?
  • jmg, we are talking about the PASM instructions NOT spin.

    MAX D,(#)S
    MIN D,(#)S
    etc.
  • LIMGE or LIMHI
    LIMLE or LIMLO
    LIMSGE
    LIMSLE
  • cgraceycgracey Posts: 14,152
    I don't think we can suddenly make MIN into MAX and vice-versa. The connotations, apparently, conflict too much with Prop1 precedent.

    I think FGE/FLE names will have to do.
  • The Clamp function with 3 operands is always Clamp(val, min, max) so your example would be Clamp(Evel, 1000, 2000). You would be making things broken in completely different ways if you did it with the value to clamp as the middle parameter.

    And again, why put the dumb F on the beginning of all the PASM instructions for this?
  • jmgjmg Posts: 15,173
    edited 2017-05-04 06:59
    Roy Eltham wrote: »
    jmg, we are talking about the PASM instructions NOT spin.
    Oops, hard to tell sometimes, when just a list of words are provided....
    FGE
    FLE
    SFGE
    SFLE
    work fine as PASM2 mnemonics too....
    as too does
    CHO // Choose Higher Of
    CLO
    CHOS
    CLOS
    SCHO
    SCLO
    Roy Eltham wrote: »
    why do they need the F prefix? Just call them MIN/MAX and MINS/MAXS, and make them work like everyone wants them to work instead of backwards like P1 PASM?
    ... you have mentioned the reason right there...
    You cannot really have the same name used on two variant parts, yet meaning the opposite action.
    Anyone from the outside looking in, will just scratch their heads.

    Nicer would be some operand that can retro-fit into P1 ASM to fix it, so P1 ASM and P2 asm can become similar, and broken MAX can get deprecated / put out to pasture...
    FMAX is ok as it can mean Fixed Max, as well as 'Choose Higher Of', but my personal choice would be any name well clear of MAX,MIN
    GE and LE are already quite widely understood in the field, so make suitable roots.

Sign In or Register to comment.