CLIB COG and how to do a CMPEXCH?
ImageCraft
Posts: 348
I was talking to someone about floating point code for the Prop and the thread in the forum about fast sqrt makes me thinking: we can put a bunch of library code in another COG and use a semaphore mechanism to activate it, e.g. that COG would be executing something like
forever
if (state == LIBCOG_START)
{
state = LIBCOG_BUSY
<invoke some function>
state = LIBCOG_FINISH
}
The function will be invoked by some sort of ID, probably a jump table index. "state" and parameters live in HUB RAM of course.
The library function mechanism for these functions then become
if (state == LIBCOG_IDLE)
{
state = LIBCOG_RESERVE
<write parameters and function code>
state = LIBCOG_START
while (state != LIBCOG_FINISH)
;
<get result>
state = LIBCOG_IDLE
}
A problem is implementing the equivalence of CMPEXCH using LOCKs to modify "state." Fro all you Propeller heads, any idea?
***
So at the cost of using another COG, we get full native speed on these functions.
***
As for the actual functions
I can think of
- low level FP primitives, pack, unpack, add, sub, etc.
- strcpy/memcpy etc.
- sqrt
I have yet to look at the sin/cos/trig support in the Propeller ROM, but we will probably put the wrapper functions there too.
forever
if (state == LIBCOG_START)
{
state = LIBCOG_BUSY
<invoke some function>
state = LIBCOG_FINISH
}
The function will be invoked by some sort of ID, probably a jump table index. "state" and parameters live in HUB RAM of course.
The library function mechanism for these functions then become
if (state == LIBCOG_IDLE)
{
state = LIBCOG_RESERVE
<write parameters and function code>
state = LIBCOG_START
while (state != LIBCOG_FINISH)
;
<get result>
state = LIBCOG_IDLE
}
A problem is implementing the equivalence of CMPEXCH using LOCKs to modify "state." Fro all you Propeller heads, any idea?
***
So at the cost of using another COG, we get full native speed on these functions.
***
As for the actual functions
I can think of
- low level FP primitives, pack, unpack, add, sub, etc.
- strcpy/memcpy etc.
- sqrt
I have yet to look at the sin/cos/trig support in the Propeller ROM, but we will probably put the wrapper functions there too.
Comments
In the case of a library like this that might be used by any of several other cogs, you do need to use LOCKxxx.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.