🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c
Article #9524

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

#9524
From: Chris Torek
Date: Thu, 09 Oct 1986 10:34
56 lines
2710 bytes
In article <1023@kuling.UUCP> thomas@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@+		| 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@+		| 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@+		| 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@umcp-cs		ARPA:	chris@mimsy.umd.edu
Technical Details
Message-ID: <3766@umcp-cs.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!umcp-cs!chris
References: <101@hcx1.UUCP> <7363@sun.uucp> <696@mips.UUCP> <7447@sun.uucp> <1023@kuling.UUCP>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!umcp-cs!chris
From: chris@umcp-cs.UUCP (Chris Torek)
Newsgroups: net.lang.c
Subject: Re: 68K bcopy, bzero (was Re: structure alignment question)
Message-ID: <3766@umcp-cs.UUCP>
Date: Thu, 9-Oct-86 06:34:13 EDT
Article-I.D.: umcp-cs.3766
Posted: Thu Oct  9 06:34:13 1986
Date-Received: Thu, 9-Oct-86 08:30:53 EDT
References: <101@hcx1.UUCP> <7363@sun.uucp> <696@mips.UUCP> <7447@sun.uucp> <1023@kuling.UUCP>
Organization: Computer Sci. Dept, U of Maryland, College Park, MD
Lines: 56
Summary: movem is slower than movl+dbra