*BSD News Article 16039


Return to BSD News archive

Newsgroups: comp.os.386bsd.development
Path: sserve!newshost.anu.edu.au!munnari.oz.au!news.Hawaii.Edu!ames!agate!howland.reston.ans.net!europa.eng.gtefsd.com!fs7.ece.cmu.edu!crabapple.srv.cs.cmu.edu!cmaeda
From: cmaeda+@cs.cmu.edu (Christopher Maeda)
Subject: Re: assembly versions of bcopy, bcmp, memcpy, memmove, etc.
Message-ID: <C6zKz6.H1z.1@cs.cmu.edu>
Sender: news@cs.cmu.edu (Usenet News System)
Nntp-Posting-Host: ernst.mach.cs.cmu.edu
Organization: School of Computer Science, Carnegie Mellon
References: <CONKLIN.93May12163441@ngai.kaleida.com>
Date: Thu, 13 May 1993 22:25:53 GMT
Lines: 30

If you're inside a kernel, you want to be careful about alignment
since device drivers will use these functions and devices tend to be a
big source of unaligned addresses.

The reason you want to do aligned (doubleword) copies on an i386 is
that they are a lot faster.  You'll get better performance by getting
the copy aligned on a 32 bit boundary first and then doing an aligned
copy loop instead of just doing the whole copy loop with unaligned
addresses.  On a RISC cpu, you *have* to pay attention to alignment
because you use different load and store instructions for aligned and
unaligned access.

A good exercise is to measure your copy performance on the following
four cases:

	aligned -> aligned
	aligned -> unaligned
	unaligned -> aligned
	unaligned -> unaligned

Then instrument your kernel to see the relative frequencies of these
four cases.  On a mach 3.0 kernel running on a decstation 5000/200,
most copies are aligned->aligned.  However, there are a significant
number of unaligned->aligned copies, especially in the ethernet
driver.
-- 
Chris Maeda, Grad Student and RetroGrouch <cmaeda@cs.cmu.edu>
"A unix signature isn't a return address, it's the ASCII equivalent of
a black velvet clown painting. It's a rectangle of carets surrounding
a quote from a literary giant of weeniedom like Heinlein or Dr. Who."