Shop OBEX P1 Docs P2 Docs Learn Events
PASM math... — Parallax Forums

PASM math...

potatoheadpotatohead Posts: 10,261
edited 2010-08-24 08:56 in Propeller 1
I know there is a post on the wiki, but I don't think I understand it very well yet.

What I need to do is calculate a delay value based on the system clock, or compute timing constants at key times, something like:

i := (CLKFREQ / 10) * duration + CNT


(however fast --don't care)

x = x / y

and x = x * y.

Both with 32 bit results and operands. These are for general case setup / init tasks, mostly to enable PASM to be built up binary blob style. I realize the multiply will overflow, but I don't think it's a problem at this point. For most all the cases I'm thinking of, one operand will be considerably smaller than 32 bits.

Comments

  • potatoheadpotatohead Posts: 10,261
    edited 2010-08-21 23:14
    Well, this is in the Prop Manual, V1.1

    don't post, until I crash on that. Thanks!!
  • potatoheadpotatohead Posts: 10,261
    edited 2010-08-22 19:14
    While I'm doing battle with the math, I thought I would post these up. Absolutely great binary number references:

    http://mathforum.org/library/drmath/view/54375.html

    This kind of thing makes me very happy :)

    I think I've got the math right, but now need to code up some test cases to vet it. Division is a PITA, when range is a consideration...
  • max72max72 Posts: 1,155
    edited 2010-08-23 00:01
    I didnt' try it, but it could work.. why not checking the Pbasic generated code?
    You know... standing on the giant's shoulders...

    Massimo
  • potatoheadpotatohead Posts: 10,261
    edited 2010-08-23 06:55
    Why not?

    Well, I started with the simple multiply and divide routines found in the Prop Tool and Wiki. Chips math module in the Pnut interpreter is another potential target.

    Most all of what I've done uses simple math, or a lookup, or some specific multiply / divide case. Those things can be done with shifts, rotates, adds, and the occasional clever trick, and are something one works out for that task.

    So it's a weak spot, and something I've wanted to get a better handle on. With math, I find it best to do it on paper, then start working through the process on a computer.

    There is the performing of the computation, then there is actually understanding how to use the result obtained, and finally scale vs number of bits vs precision. It's hard to get a good feel for whether or not those things are properly balanced for the task at hand.
  • K2K2 Posts: 693
    edited 2010-08-23 10:59
    I like to understand things as I go along, too. The "pseudo-division" and "pseudo-multiplication" that were used in the HP-35 are very understandable and work well, particularly where speed is not of the essence.


    Edit: This is the document I was thinking of --> www.jacques-laporte.org/Meggitt_62.pdf
  • potatoheadpotatohead Posts: 10,261
    edited 2010-08-23 11:33
    That document is great. Thank you for linking it.
  • rosco_pcrosco_pc Posts: 468
    edited 2010-08-23 18:31
    I remembered that cessnapilot had some post about fast math routines:

    Division: http://forums.parallax.com/showthread.php?t=114807
    Multiplication: http://forums.parallax.com/showthread.php?t=114911
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2010-08-24 08:56
    Here are PASM routines I did way back when (they should still work). It does all the basic math in PASM. Pretty much all of them require the values to be placed in par1 and par2 before the routine is called. The result is placed in ret_val before it returns. This isn't the fastest method to do things (a few extra assignments because of it), but it makes them very easy to work with.
Sign In or Register to comment.