Hi Folks,
I've posted this on the forums, but things have dried up there and I
really need to get this figured out.
I've put out the business fires, so I can get back to the fun side of
this stuff. I've dug through the new API/SDK info and I'm still a bit
lost as to the "How's" of RB plugin creation. I was able to build a
couple of the OS X samples, but they assume you're working with very
basic operations and already understand the types defined in the plugins
versus the types in a normal C program or library.
I've got some math code that we've made very fast in C, but I can't get
a grip on what RB types apply to what C types.
Here's my main function code that would be turned into a plugin and
called from within an RB app, Requiring 3 memoryblocks of 64 unsigned
shorts and returning the results by modifying the 3rd memoryblock's
contents:
-----------------------------
void modular_exp(unsigned short *base, unsigned short *power, unsigned short
*result) {
unsigned short z, sqr[BIGNUM_SHORTS], exp[BIGNUM_SHORTS];
int i;
for(i=0; i<BIGNUM_SHORTS; i++) {
result[i] = one[i];
exp[i] = power[i];
}
modular_product(base, one, sqr);
for(;;) {
if (exp[0] & 1)
montgomery_reduction(sqr, result, result);
z = 0;
for(i=0; i<BIGNUM_SHORTS-1; i++) {
exp[i] = (exp[i] >> 1) | ((exp[i+1] & 1) << 15);
z |= exp[i];
}
exp[BIGNUM_SHORTS-1] >>= 1;
z |= exp[BIGNUM_SHORTS-1];
if (z == 0)
break;
montgomery_reduction(sqr, sqr, sqr);
}
modular_product(result, rp, result);
}
REALmethodDefinition ModularExpdefn = {
(REALproc) modular_exp, nil,
"ModularExp(base As MemoryBlock, power As MemoryBlock, ByRef result As
MemoryBlock)",
REALconsoleSafe
};
void PluginEntry(void)
{
REALRegisterMethod(&ModularExpdefn);
}
-------------------------------------------
Recently, Tim Hare recommended that I change the calling convention to
use this:
void ModularExp(REALmemoryBlock base, REALmemoryBlock power, REALmemoryBlock
result)
{
short *mbase, *mpower, *mresult;
mbase = (short *) REALMemoryBlockGetPtr(base);
mpower = (short *) REALMemoryBlockGetPtr(power);
mresult = (short *) REALMemoryBlockGetPtr(result);
modular_exp(mbase, mpower, mresult);
}
REALmethodDefinition ModularExpdefn = {
(REALproc) ModularExp, nil,
"ModularExp(base As MemoryBlock, power As MemoryBlock, ByRef result As
MemoryBlock)",
REALconsoleSafe
};
---------------------------
However, the result is that the plugin crashes on the attempt to copy the
contents of an internal array into the mresult array (MemoryBlock).
Anyone have guidance on how to get the three arrays of unsigned shorts
(MemoryBlocks in the RB project) passed into the plugin so that the third
memoryblock is mutable?
Thanks,
Tim
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>