68K bcopy, bzero (was Re: structure alignment question)

Chris Torek chris at umcp-cs.UUCP
Thu Oct 9 20:34:13 AEST 1986


In article <1023 at kuling.UUCP> thomas at kuling.UUCP (Thomas H{meenaho) writes:
>In sysV for the 68K this technique [word at a time copies] is used for
>bcopy inside the kernel.  bcopy is easier as one knows how many bytes
>are to be moved.  bzero is even smarter, it clears a set of registers
>and uses movem to copy them to memory.

I recently had occasion to write a bzero subroutine for a 68010 CPU
board (Heurikon CPU, part of McMob).  The original (monitor) code had
carefully arranged to use moveml's.  I was amused to discover that
the simpler code below runs at least four times faster.

This is, of course, due to the loop mode on the 68010.  The moveml
loop is no doubt faster on a 68000.  And *that* sort of thing is
why these belong in your support library in the first place!  (In
my case, I was *writing* the support library routine. . . .)

|
| C-callable subroutines
|

| bzero(addr, count) char *addr; int count;
| clear `count' bytes at location `addr'
_bzero:	.globl	_bzero
	moveq	#0,d0		| get a handy zero
	movl	sp@(4),a0	| grab addr
	movl	a0,d1		| test low bit.  btst sucks
	btst	#0,d1
	beqs	bzeven		| branch if even

				| make even:
	movb	d0,a0 at +		| clear one byte
	subql	#1,sp@(8)	| and adjust count

bzeven:
	movl	sp@(8),d1	| grab count
	asrl	#2,d1		| divide by four to get longwords
	beqs	bzlast		| and go handle last bytes if none
	subql	#1,d1		| adjust for dbra -1 crap
bzloop:	movl	d0,a0 at +		| clear one longword
	dbra	d1,bzloop	| and count it and repeat until d1=-1
	subl	#0x10000,d1	| decrement high word
	bges	bzloop		| if result is nonnegative, do it all again
bzlast:
	movw	sp@(0xa),d1	| restore (low word of) count
	andw	#3,d1		| need only low two bits
	subqw	#2,d1		| is it at least two?
	blts	bzl3
	movw	d0,a0 at +		| clear one word if so
bzl3:	btst	#0,d1		| need one last byte?
	beqs	bzret		| return if not
	movb	d0,a0@		| clear that last byte
bzret:	rts
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1516)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at mimsy.umd.edu



More information about the Comp.lang.c mailing list