View Single Post
Old 05 March 2013, 05:24   #9
NovaCoder
Registered User
NovaCoder's Avatar
 
Join Date: Sep 2007
Location: Melbourne/Australia
Posts: 3,444
I used some DoomAttack ASM for my port of BOOM BTW, I'll see if I can dig out the relevant parts for you.

Ok, I used this from m_fixed.h

Code:
typedef int fixed_t;


static __inline__ fixed_t FixedMul(fixed_t eins, fixed_t zwei) {
#ifndef version060

	__asm __volatile
	("muls.l %1,%1:%0 \n\t"
	 "move %1,%0 \n\t"
	 "swap %0 "
					 
	  : "=d" (eins), "=d" (zwei)
	  : "0" (eins), "1" (zwei)
	);

	return eins;

#else
	__asm __volatile
	("fmove.l	%0,fp0 \n\t"
	 "fmul.l	%2,fp0 \n\t"
	 "fmul.x	fp7,fp0 \n\t"
	 "fmove.l	fp0,%0"
					 
	  : "=d" (eins)
	  : "0" (eins), "d" (zwei)
	  : "fp0"
	);

	return eins;
#endif
}



static __inline__ fixed_t FixedDiv(fixed_t eins, fixed_t zwei) {
	__asm __volatile

#ifndef version060
	("move.l	%0,d3\n\t"
	 "swap      %0\n\t"
	 "move.w    %0,d2\n\t"
	 "ext.l		d2\n\t"
	 "clr.w		%0\n\t"
	 "tst.l		%1\n\t"
	 "jeq		3f\n\t"
	 "divs.l	%1,d2:%0\n\t"
	 "jvc		1f\n"

	 "3: eor.l %1,d3\n\t"
	 "jmi       2f\n\t"
	 "move.l	#0x7FFFFFFF,%0\n\t"
	 "jra		1f\n"

	 "2: move.l #0x80000000,%0\n"
	 "1:\n"
	 
	 : "=d" (eins), "=d" (zwei)
	 : "0" (eins), "1" (zwei)
	 : "d2","d3"
	);
#else
	("tst.l		%1\n\t"
	 "jne		1f\n\t"

	 "eor.l		 %1,%0\n\t"
	 "jmi       2f\n\t"
	 "move.l	#0x7FFFFFFF,%0\n\t"
	 "jra		9f\n"

	 "2: move.l #0x80000000,%0\n\t"
     "jra		9f\n"
     
	 "1: fmove.l %0,fp0 \n\t"
	 "fdiv.l	%2,fp0 \n\t"
	 "fmul.x		fp6,fp0 \n\t"
	 "fmove.l	fp0,%0\n"

	 "9:\n"
	 
	 : "=d" (eins)
	 : "0" (eins), "d" (zwei)
	 : "fp0"
	);
#endif
	return eins;
}

static __inline__ int ULongDiv(int eins,int zwei)
{
	__asm __volatile
	(
		"divul.l %2,%0:%0\n\t"
		
		: "=d" (eins)
		: "0" (eins), "d" (zwei)
	);

	return eins;
}
Used here for example:
Code:
//
// I_GetTime
//
static long startTime = 0;

int  I_GetTime (void) {
	static struct timeval tp;
	
	GetSysTime(&tp);
	
    return (tp.tv_secs) * TICRATE + ULongDiv(tp.tv_micro * TICRATE, 1000000);
}
I originally used the 030 versions then swapped to 060 later on, both seemed to work ok. If you decide to use the 060 versions you need to do some addition setup (check out the DoomAttack source for details).

I code with gcc BTW, you might have to make some changes if you use something else.

Last edited by NovaCoder; 05 March 2013 at 05:31.
NovaCoder is offline  
 
Page generated in 0.14115 seconds with 9 queries