philj@tekig5.PEN.TEK.COM (Phil Jansen) (09/26/89)
Hi there. I need to learn how to use the THINK C assembler.
I have two pieces of code which I think should do the same thing, but they
don't. One section is written in C, and the other uses asm{ }.
Can somebody tell me what is different? It's not obvious from the assembler
documentation (???) how to use it. How can I get the asm code to match what
the C code does? Is it worth it (save ~30% in speed)?
Has anyone seen a writeup of how to mix THINK C and assembler?
Thanks
Phil Jansen
Here's my code ( C first [C works], then asm [asm code broken] )
---------------------------------------------------------------
#define BUFFSIZE 2048 /* MUST be a power of 2 */
#define BUFFMASK ( (BUFFSIZE*0x10000) - 1 )
#define NEXTLOC(x) ( (x) & BUFFMASK ) /* get next location (wrap) */
/* When in context, the declarations are like:
register int val, *buf;
register unsigned long int bp, inc;
bp and inc represent fixed point numbers (0x00010000 is 1.0)
*/
/* C CODE HERE: */
#define ADDTONE(val, buf, bp, inc) val+= buf[(bp>>16)];\
bp = NEXTLOC(bp + inc);
/* ASM CODE HERE */
#define asmADDTONE(val, buf, bp, inc) asm { /* BROKEN */ \
move.l bp, d0\
swap d0\
andi.l #0x0000ffff,d0 /* bp>>16 */\
add.l buf,d0\
move.l d0,a0 /* a0 = buf + (bp>>16) */\
move.b (a0),d0 /* d0 = buf[bp>>16] */\
add.w d0,val /* val += (a0) */\
\
move.l bp,d0\
add.l inc,d0 /* bp + inc */\
andi.l #BUFFMASK, d0 /* bp + inc & no overflow */\
move.l d0,bp /* save bp again */\
};
--------------------------------
Thanks for your help.
--
If you repeat things often enough, they become true.
Phil Jansen If you repeat things often enough, they become true.
philj@tekig5.pen.tek.com If you repeat things often enough, they become true.
pepke@loligo (Eric Pepke) (09/26/89)
In article <4841@tekig5.PEN.TEK.COM> philj@tekig5.PEN.TEK.COM (Phil Jansen) writes: >/* ASM CODE HERE */ >#define asmADDTONE(val, buf, bp, inc) asm { /* BROKEN */ \ > move.l bp, d0\ > swap d0\ > andi.l #0x0000ffff,d0 /* bp>>16 */\ > add.l buf,d0\ > move.l d0,a0 /* a0 = buf + (bp>>16) */\ > move.b (a0),d0 /* d0 = buf[bp>>16] */\ > add.w d0,val /* val += (a0) */\ There's one problem right there. C knows when something is a pointer to an integer or another type that is larger than a character and scales up the arithmetic accordingly. Your "add.l buf,d0" line only increases buf by d0 character positions, not d0 integer positions. Eric Pepke INTERNET: pepke@gw.scri.fsu.edu Supercomputer Computations Research Institute MFENET: pepke@fsu Florida State University SPAN: scri::pepke Tallahassee, FL 32306-4052 BITNET: pepke@fsu