I think the PNut download has a file called spin2_operators.txt in it -- I've attached for convenience. I made this cheat sheet for myself.
Spin Operators
a New/changed operator in P2
b Behavioral change in P2
P2 P1 Description
-----------------------------------------------------------------
++ (pre) ++ Pre-increment
-- (pre) -- Pre-decrement
?? (pre) ? ab XORO32, iterate and return pseudo-random
++ (post) ++ Post-increment
-- (post) -- Post-decrement
!! (post) Post-logical NOT
! (post) Post-bitwise NOT
\ (post) Post-set
~ (post) ~ Post-set to 0
~~ (post) !! Post-set to -1
! ! Bitwise NOT, 1's complement
- - Negation, 2's complement
abs || a Absolute value
encod >| ab Encode MSB, 31..0
decod |< a Decode, 1 << (x & $1F)
bmask Bitmask, (2 << (x & $1F)) - 1
ones Count ones
sqrt Square root of unsigned x
qlog Unsigned to logarithm
qexp Logarithm to unsigned
>> >> Shift right, insert 0's
<< << Shift left, insert 0's
sar ~> a Shift right, insert MSB's
ror -> a Rotate right
rol <- a Rotate left
rev >< a Reverse y LSBs of x and zero-extend
zerox Zero-extend above bit y
signx ~, ~~ ab Sign-extend from bit y
& & Bitwise AND
^ ^ Bitwise XOR
| | Bitwise OR
* * Signed multiply
/ / Signed divide, return quotient
+/ Unsigned divide, return quotient
// // Signed divide, return remainder
+// Unsigned divide, return remainder
sca Unsigned scale (x * y) >> 32
scas ** a Signed scale (x * y) >> 30
frac Unsigned fraction {x, 32'b0} / y
+ + Add
- - Subtract
#> #> Ensure x => y, signed
<# <# Ensure x <= y, signed
addbits Make bitfield, (x & $1F) | (y & $1F) << 5
addpins Make pinfield, (x & $3F) | (y & $1F) << 6
< < Signed less than (returns 0 or -1)
+< Unsigned less than (returns 0 or -1)
<= =< a Signed less than or equal (returns 0 or -1)
+<= Unsigned less than or equal (returns 0 or -1)
== == Equal (returns 0 or -1)
<> <> Not equal (returns 0 or -1)
>= => a Signed greater than or equal (returns 0 or -1)
+>= Unsigned greater than or equal (returns 0 or -1)
> > Signed greater than (returns 0 or -1)
+> Unsigned greater than (returns 0 or -1)
<=> Signed comparison (<,=,> returns -1,0,1)
!!, not not Logical NOT (x == 0, returns 0 or -1)
&&, and and Logical AND (x <> 0 AND y <> 0, returns 0 or -1)
^^, xor xor Logical XOR (x <> 0 XOR y <> 0, returns 0 or -1)
||, or or Logical OR (x <> 0 OR y <> 0, returns 0 or -1)
? : If x <> 0 then choose y, else choose z
:= := a Set var(s) to x
P2: v1,v2,... := x,y,... ' set v1 to x, v2 to y, etc. '_' = ignore
Complex math functions
---------------------------------------------------------------------------------------------------
x, y := rotxy(x,y,t) Rotate cartesian (x,y) by t and assign resultant (x,y)
x, t := xypol(x,y) Convert cartesian (x,y) to polar and assign resultant (r,t)
x, y := polxy(r,t) Convert polar (r,t) to cartesian and assign resultant (x,y)
This is from the P1 manual:
** --or-- **= Multiply and return upper 32 bits (signed); p 153
Is there anything equivalent in P2 ?
eg from P1 if z ** z > m converted to P2 ?
~ Sign-extend from bit 7 (~X) {or post-clear to 0 (X~); p 156}. Pre only eg Y := ~X + 25
Page 156 in P1 Manual: "When you need to perform further calculations with those byte-sized values, use the Sign-Extend 7 operator to convert the number into the proper 32-bit signed integer form. "
P2 Solution for Pre ~ ?
data := data <- 8 ' puts the 8MSB to the 8LSB
data := ~data ' extend sign
change to:
data := data <- 8 ' puts the 8MSB to the 8LSB
data := data SIGNX 7 ' extend sign
Compiles ok but not tested.
Thanks Jon.
@JonnyMac Good morning Jon. At 5:30am on BBC World I listened to Bill Gates. Great to get information from someone who is believable!
This thread is about converting someone else's code from P1 to P2. Thank you for your "Spin Operators" list which is most helpful. I believe this was prepared while converting your own code. With my work I have not used a list of known differences but have simply proceeded by Compile, find error, search for info in P1 Manual, search for info in Chips P2 documents, change syntax, save, compile etc on and on.
The assumptions are that chip's Pnut compiler is 100% perfect. Chip's documents are 100% complete. That if the code compiles it is 100% correct. Although I am always interested in improved code, for the moment I wish to convert from P1 to P2 in the shortest time possible and complete my document of the most used code differences.
Without your help I would be stuck. Many thanks for helping me.
The challenge of this moment is the jmpret. So I will continue searching for info. Hoping that I don't fall asleep sitting upright! Yes I am old...
Kevin.
You and I have different feelings about Mr. Gates -- will leave that right there.
Chip published the operators list. When I ran into a difference I went through it to make my cheat-sheet so that I could get a handle on what changed, and what's new. Most of my conversions go pretty smoothly now; I know what too look for and to remember the niggly things like () on functions without parameters, and explicitly naming return the return variable for methods that do return a value.
The assumptions are that chip's Pnut compiler is 100% perfect. Chip's documents are 100% complete.
You shouldn't. As bugs are reported Chip is knocking them down. At the same time, he is fleshing out initial documentation. I don't know, but it's likely Jeff Martin will take Chip's documentation and humanize it in the form of a P2 manual (he did a nice job on the P1 manual).
The biggest change from P1 to P2 is on the PASM side. I think the P1 had about 60 instructions -- the P2 has over 350. There has been commentary on JMPRET by some of the advanced members. I've written one program that used it, and that had to do with a specialty UART which is no longer a problem with smart pins.
Remember, the P2 isn't officially released yet. We're all working with engineering samples. Parallax is letting us get a jump on others, and we can help Parallax by pointing out problem spots.
Comments
I think the PNut download has a file called spin2_operators.txt in it -- I've attached for convenience. I made this cheat sheet for myself.
** --or-- **= Multiply and return upper 32 bits (signed); p 153
Is there anything equivalent in P2 ?
eg from P1 if z ** z > m converted to P2 ?
I'm using SCAS here because the P1 doesn't do unsigned multiplying or dividing.
I need to update my cheat sheet -- ** is not something I ever used.
On P2, SCA is equivalent to **. So "z ** z" would become "z SCA z".
Page 156 in P1 Manual: "When you need to perform further calculations with those byte-sized values, use the Sign-Extend 7 operator to convert the number into the proper 32-bit signed integer form. "
P2 Solution for Pre ~ ?
Spin1: Spin2: The parenthesis may not be needed, but I think they add clarity.
Keep in mind, too, that Chip is updating the initial online documentation -- you may want to bookmark this lin:
https://docs.google.com/document/d/16qVkmA6Co5fUNKJHF6pBfGfDupuRwDtf-wyieh_fbqw/edit
data := ~data ' extend sign
change to:
data := data <- 8 ' puts the 8MSB to the 8LSB
data := data SIGNX 7 ' extend sign
Compiles ok but not tested.
Thanks Jon.
BTW... ...translates to:
This thread is about converting someone else's code from P1 to P2. Thank you for your "Spin Operators" list which is most helpful. I believe this was prepared while converting your own code. With my work I have not used a list of known differences but have simply proceeded by Compile, find error, search for info in P1 Manual, search for info in Chips P2 documents, change syntax, save, compile etc on and on.
The assumptions are that chip's Pnut compiler is 100% perfect. Chip's documents are 100% complete. That if the code compiles it is 100% correct. Although I am always interested in improved code, for the moment I wish to convert from P1 to P2 in the shortest time possible and complete my document of the most used code differences.
Without your help I would be stuck. Many thanks for helping me.
The challenge of this moment is the jmpret. So I will continue searching for info. Hoping that I don't fall asleep sitting upright! Yes I am old...
Kevin.
Chip published the operators list. When I ran into a difference I went through it to make my cheat-sheet so that I could get a handle on what changed, and what's new. Most of my conversions go pretty smoothly now; I know what too look for and to remember the niggly things like () on functions without parameters, and explicitly naming return the return variable for methods that do return a value.
You shouldn't. As bugs are reported Chip is knocking them down. At the same time, he is fleshing out initial documentation. I don't know, but it's likely Jeff Martin will take Chip's documentation and humanize it in the form of a P2 manual (he did a nice job on the P1 manual).
The biggest change from P1 to P2 is on the PASM side. I think the P1 had about 60 instructions -- the P2 has over 350. There has been commentary on JMPRET by some of the advanced members. I've written one program that used it, and that had to do with a specialty UART which is no longer a problem with smart pins.
Remember, the P2 isn't officially released yet. We're all working with engineering samples. Parallax is letting us get a jump on others, and we can help Parallax by pointing out problem spots.