Shop OBEX P1 Docs P2 Docs Learn Events
Why does Float32 need its own cog? — Parallax Forums

Why does Float32 need its own cog?

Joel RosenzweigJoel Rosenzweig Posts: 52
edited 2008-04-11 05:55 in Propeller 1
I've been using Float32 for a while without getting too deep into how it works. I know that it allocates and uses an additional cog above and beyond the one that it is launched in. This was OK, but now after some modifications to my project, I have run out of cogs and need one back. smile.gif I took a look at the Float32 code, and fundamentally, I don't quite understand why it is using an extra cog in the first place since all the computation is serialized. When a Float32 function is called, my calling routine is forced to wait for a result from Float32, so it can't go ahead an execute more code in parallel. And upon inspection of the Float32 code, it uses the primary cog to submit an instruction to that second cog and then it uses a repeat until loop waiting for the answer to be returned from a second cog. Given that the first cog is just spinning waiting on a result from the second cog, why isn't the actual computation done in the same first cog? I'm sure there's a good reason for it, but it's not obvious why the second cog is needed. Ultimately, I am still looking for a way to call my Float routines without requiring the use of a second cog. I'm using the multiply, divide, add, subtract, FFloat, sin and cos functions.

I appreciate that I could convert all the computation to fixed point arithmetic, but that's not something I've looked at too closely yet. If that's the only solution, I'll do that, but I prefer to keep it simple and keep the computations working with native float data types so that it's easier for me to work with. If someone has a tutorial on converting floating point expressions to fixed point expressions, I'd be happy to read up.

Thanks,
Joel-

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-04-11 05:55
    Because it is assembly code. You cannot mix assembly code and spin on the same cog. If you want to run it in the same cog you can use FloatMath but you will pay the price with it being much slower.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
Sign In or Register to comment.