Idea: "math coprocessor" using a cog
The thread "Multiplication on 24bits" gave me an idea, perhaps a bit radical, but let me share it with you.
Why not write a library of math/floating-point subroutines that fills a cog, and use that cog as a kind of "math co-processor".
Other cogs, or perhaps SPIN via some kind of calling routine, could use this "math co-processor" when needed, by feeding it the variables and the desired mathematical function (by placing them in a specified main ram locations) and then signaling the math cog it has work to do with a semaphore. When the "math cog" finishes his work he could place the result in the same variables, and signal he finished the calculations with another semaphore .
Mahjongg
Why not write a library of math/floating-point subroutines that fills a cog, and use that cog as a kind of "math co-processor".
Other cogs, or perhaps SPIN via some kind of calling routine, could use this "math co-processor" when needed, by feeding it the variables and the desired mathematical function (by placing them in a specified main ram locations) and then signaling the math cog it has work to do with a semaphore. When the "math cog" finishes his work he could place the result in the same variables, and signal he finished the calculations with another semaphore .
Mahjongg
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
John R.
Click here to see my Nomad Build Log
However, I propose something different than just linking a set of math objects with the rest of your assembler code, or Spin code.
The core of my idea comes from my understanding that you can use a cog, and some software, to create "virtual hardware".
I just propose to extend that idea to use a cog, and some software, to create a "virtual math co-processor".
Maybe the existing math object interface already works in a very similar way to my hypothetical "virtual co-processor", and my proposal has no practical merit. In that case I beg your pardon for my "harebrained" idea.
Mahjongg.
thanks.
Integer math is often called "fixed point" but that is somewhat a misnomer when applied to integer multiplication and division that involves implied fractions. The decimal point is decidedly not fixed, and part of the problem is to be sure it ends up where you want it. The problem of scaling and integer overflow must always be kept in mind.
Cam Thomson wrote the excellent floating point library in the object exchange and also (as Micromega) designed the uM-FPU coprocessor. In floating point, it is again kind of a misnomer from a certain perspective, because the decimal point is mostly in exactly the same place, and the exponent absorbs the scale factor. Because of its even handed treatment of positive and negative and a huge range of scale factors, I believe floating point is much more amenible to treatment as a library object.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com