Shop OBEX P1 Docs P2 Docs Learn Events
Article about math at propellerwiki — Parallax Forums

Article about math at propellerwiki

AleAle Posts: 2,363
edited 2008-08-04 16:27 in Propeller 1
Hei all.


I was busy these days writing an article about math at propeller.wikispaces.com/MATH. Deals with binary and BCD math on the propeller, with descriptions and code examples. I'd like some feedback so I thought I'd ask.

- what should I add (FFT will have a separate article with fully functional, and already written code).
- what is covered
- language use
- style

I particularly like the style I used so far, I hope you too.

**** PLEASE: do not edit the page. Let me do the additions (for the time being), so multiple changes do not conflict. ****


thanks in advance.

Ale

Comments

  • jazzedjazzed Posts: 11,803
    edited 2008-07-15 19:48
    Looks great so far.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • AleAle Posts: 2,363
    edited 2008-07-22 07:58
    Well, I completed a couple more small parts (division and square root: this last one can be improved as mentioned) and was (really) expecting a bit more comments... (Thanks jazzed!)

    The routines can be compacted, I think quite a bit, but they will lose readability, fast, and their purpose to illustrate how to implement them.
  • JavalinJavalin Posts: 892
    edited 2008-07-22 09:28
    looks good - only comment is that i'd space the flags more from the comment - people not familiar with Prop assembly would probably be confused.

    ie.

    add x,y wc, wz

    Appologies if you've covered it somewhere else!

    J
  • AleAle Posts: 2,363
    edited 2008-07-22 10:54
    The disclaimer at the beginning of the article says that people familiar with the prop assembler should read it wink.gif, but a couple of spaces can be easily added.
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2008-07-22 12:46
    It looks excellent, I'm moving house right now but will read it properly once done.

    Keep it up!

    An appreciative

    Graham
  • Nick McClickNick McClick Posts: 1,003
    edited 2008-07-22 17:59
    You can also use the log tables to calculate multiplication and division (i.e. LOG(ab)=LOG(a)+LOG(b)). On the end of the article you write 'Sinus' a few times. I think you mean Sine.

    Also, aren't the sine tables already in the rom map, too?

    Seems like the article was written just for me - someone who is learning assembly and doesn't already have expertise in binary math. A few other topics you could cover; Calculating Cos & Tan.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Concentrate on understanding the problem, not applying the tool
  • LeonLeon Posts: 7,620
    edited 2008-07-22 18:16
    'Sinus' is French or German for sine.

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
    Suzuki SV1000S motorcycle

    Post Edited (Leon) : 7/22/2008 6:23:50 PM GMT
  • AleAle Posts: 2,363
    edited 2008-07-22 18:22
    Nick:

    - The built-in tables are only useful to calculate using binary numbers and floating point with them is not exposed by me yet. (The float object (in Object Exchange) uses the tables because it uses a binary representation of floating point.) I marginally touch this so far, The tables are 12 or 13 bits of precision, so higher can be achieved with some more help.

    For BCD they are not useful ;-/, afaik.

    - The plan is to cover both BCD and binary, maybe a bit of linear algebra, too. Everyone loves 3D, I'll add them as soon as I write them, and have "lust" at writing them. Today I was optimizing the square root, I'm down to 70% or so of the current proposed routine (same algorithm).

    Thanks for the comments.

    Edit: and of course latin wink.gif
  • VIRANDVIRAND Posts: 656
    edited 2008-07-23 07:56
    Ale said...

    - what should I add (FFT will have a separate article with fully functional, and already written code).

    I will like to see the FFT code.
  • Cluso99Cluso99 Posts: 18,069
    edited 2008-07-23 12:39
    Ale: Great work roll.gif

    Is there a way to speedup Chip's multiply/divide/sqrt code in the Interpreter without adding too many more bytes (save some if possible)? I'm doing a faster RamInterpreter and this section will probably be the last bit I do, so any help would be appreciated.

    To set flags these should work (will test it when I have my development laptop on).
    ' $ = current address (i.e. address of this instruction) which saves giving the instruction a label
    

      mov $,$  wc nr 'c=1 because bit 31 --> 1
     
      mov $,#0 wc nr 'c=0 because bit 31 --> 0
     
      mov $,#0 wz nr 'z=1 because result --> 0
     
      mov $,#1 wz nr 'Z=0 because result --> 1
     
      mov $,#0 wc wz nr   ' c=0 z=1
     
      mov $,#1 wc wz nr   ' c=0 z=0
     
      cmpsub $,$ wc wz nr ' c=1 z=1 because destination = source
     
      mov $,$  wc wz nr   ' c=1 z=0
     
      
    

    ·
  • AleAle Posts: 2,363
    edited 2008-07-23 13:43
    Cluso your examples are just fantastic !
  • AleAle Posts: 2,363
    edited 2008-08-01 18:53
    I promised to add an article about FFT as part of my "MATH with the propeller", and today I added it: propeller.wikispaces.org/FFT

    The code was developed using the pPropellerSim that I also just updated to CVS (not yet a release). I can release some intermediate if someone needs it, but you can just as easily grab the source from the CVS repository,

    Producing that code may not seem much but it required quite a bit of patience and loads of help from the simulator (took me 3 days to debug, and part of the problem was that some instructions were not correctly simulated: rev, negxx and min/max)). Comparing to the C version for correctness was not exactly a walk in the park. I was thinking that a trace function (not the one that says how many times an instruction was fetched) but one that at certain point samples the status of some/all HUB/COG memory and outputs it to a file or displays it could be very helpful (I implemented that for the REV instruction to see if the permutations were correct, in a very simple way). I was thinking in adding something exactly like that, Comparing calculated data in bulk could be more efficient at spotting discrepancies that debugging step-by.-step when you do not know where it bombs.

    I hope it is useful for someone, just drop me a line smile.gif

    Ale

    Edit: The code in the math article will be updated with shorter and faster versions, that I already wrote and tested.

    Post Edited (Ale) : 8/1/2008 6:58:30 PM GMT
  • jazzedjazzed Posts: 11,803
    edited 2008-08-01 19:04
    Nice work Ale. Thought about adding an FFT graph on VGA/TV for a Prop .wav player?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • AleAle Posts: 2,363
    edited 2008-08-01 19:25
    I did that years ago for a CD player... like at the end of 94... too much programming sometimes help to achieve lousy grades wink.gif
    I have a breadboard with a prop, VGA out and a (too) fast ADC, I'll add it to it (512x384 bitmap) and post some photos.
  • jazzedjazzed Posts: 11,803
    edited 2008-08-01 19:30
    What's the frequency range?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Mike GreenMike Green Posts: 23,101
    edited 2008-08-01 19:31
    Probably the only way to speed up the multiply / divide / square root routines would be to "unroll the loop". This would trade space for time by eliminating the loop jump.
  • AleAle Posts: 2,363
    edited 2008-08-01 19:34
    @jazzed:The frequency range depends of the sampling frequency, so it will go from 0 to SPS/2 in SPS/(2*points) steps smile.gif, thanks !

    @Mike: Except for the sqrt, all multiplications are unrolled, but anyways there are ~ 22000 of them for 1024 points.
  • jazzedjazzed Posts: 11,803
    edited 2008-08-01 19:37
    So at the high end you might detect 10MHz ? I look forward to your pics.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • AleAle Posts: 2,363
    edited 2008-08-01 19:51
    If your sampling frequency is of 20MHz or greater, yes. My circuit only gets 2 Mega samples per second (2Msps).
  • AleAle Posts: 2,363
    edited 2008-08-04 16:27
    Well,

    I made the FFT work with a VGA output and all, so here are some photos. The input signal is the Horizontal sync (PA 17) sampled at 1 Msps, so the resolution is roughly 1 KHz per point, the driver outputs 512x384.

    Enjoy. burger.gifturn.gifyeah.gifsmilewinkgrin.gif

    Edit: Code added, add only VGA_512x384_Bitmap.spin... rename the .pas to spin and you are in business (maybe an AD9382 will help wink.gif)

    Post Edited (Ale) : 8/4/2008 4:36:17 PM GMT
Sign In or Register to comment.