Orphaned Response
rs at mirror.UUCP
rs at mirror.UUCP
Fri Mar 28 00:21:00 AEST 1986
A friend of mine recently did what you want. We were running UniPlus
SysV on a 68000. He was doing image compression and needed to sample
every n'th bit in a source, writing it out as the m'th bit in the
destination. The 68000 "test bit specified by register X" was too
slow, and he also wanted to unroll the loops. As I remember, the code
went something like this:
typedef int (*PFI)();
typedef short WORD;
extern char *malloc();
PFI
generate(count)
int count;
{
WORD *base;
WORD *p;
base = p = malloc(sub_size);
*p++ = prolog; /* he had the actual */
*p++ = prolog; /* hex words of the */
while (--count >= 0) {
*p++ = test_bit; /* code here, not these */
*p++ = branch_if_zero .+2; /* "mnemonics" */
*p++ = mv 0,(a0);
*p++ = skip;
*p++ = mv 1,(a0);
*p++ = decrement and branch if non-zero .-5;
}
*p++ = epilog;
*p++ = return;
return((PFI)base);
}
Then, in the main routine he had something like this:
PFI *p, generate();
p =generate(5);
(*p)();
I may have a cast or two slightly wrong, but the basic principle
is sound. (Well, it worked, at any rate; I don't know how sound
the basic principle really is :-)
--
Rich $alz {mit-eddie, ihnp4!inmet, wjh12, cca, datacube}!mirror!rs
Mirror Systems 2067 Massachusetts Avenue Cambridge, MA, 02140
Telephone: 6,176,610,777
More information about the Comp.lang.c
mailing list