Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 30 Nov 2000 17:09:01 +1100 (EST)
From:      Bruce Evans <bde@zeta.org.au>
To:        Julian Elischer <julian@elischer.org>
Cc:        current@FreeBSD.ORG
Subject:   Re: slight improvement in locore.s?
Message-ID:  <Pine.BSF.4.21.0011301650450.4214-100000@besplex.bde.org>
In-Reply-To: <3A2525DD.3D1E8D5A@elischer.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 29 Nov 2000, Julian Elischer wrote:

> Bruce Evans wrote:
> > 
> > On Thu, 23 Nov 2000, Julian Elischer wrote:
> > 
> > > locore.s includes:
> > > #define ALLOCPAGES(foo) \
> > >         movl    R(physfree), %esi ; \
> > >         movl    $((foo)*PAGE_SIZE), %eax ; \
> > >         addl    %esi, %eax ; \
> > >         movl    %eax, R(physfree) ; \
> > >         movl    %esi, %edi ; \
> > >         movl    $((foo)*PAGE_SIZE),%ecx ; \
> > >         xorl    %eax,%eax ; \
> > >         cld ; \
> > >         rep ; \
> > >         stosb
> > >
> > >
> > > might it be a very slight optimisation to change this to:
> > > #define ALLOCPAGES(foo) \
> > >         movl    R(physfree), %esi ; \
> > >         movl    $((foo)*PAGE_SIZE), %eax ; \
> > >         movl    %eax, %ecx ; \
> > >         addl    %esi, %eax ; \
> > >         movl    %eax, R(physfree) ; \
> > >         movl    %esi, %edi ; \
> > >         xorl    %eax,%eax ; \
> > >         cld ; \
> > >         rep ; \
> > >         stosb
> > 
> > This can be improved more (3 instructions) by not loading physfree into
> > the wrong register, and depending on stosb to increment the register,
> 
> so your assembly code would look like? (just curious).

This is completely untested:

#define ALLOCPAGES(foo) \
	movl    R(physfree),%edi ;		\
	movl    $(foo)*PAGE_SIZE,%ecx ;		\
	movl	%edi,%esi;			\
	xorl    %eax,%eax ;			\
	cld ;					\
	rep ;					\
	stosb ;					\
	movl    %edi,R(physfree)

I wouldn't write it like this if either space or time efficiency were
important.

> > but it should be written in C anyway.  A relocation macro like R()
> > should work just as well in C as in asm.  In C, the above is:
> > 
> >         bzero(R(physfree), (foo) * PAGE_SIZE);
> >         R(physfree) += (foo) * PAGE_SIZE);
> >         return (R(physfree));   /* In unusual as well as wrong reg %esi. */

Oops, this should return the original value of physfree.  %esi is used to
hold this value, so it is not "wrong".  Setting it takes one instruction, so
my version is only 2 instructions shorter.

Bruce



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0011301650450.4214-100000>