Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 15 Apr 1997 21:30:05 -0400
From:      "David S. Miller" <davem@jenolan.rutgers.edu>
To:        ccsanady@nyx.pr.mcs.net
Cc:        hackers@FreeBSD.ORG
Subject:   Re: inline asm question..
Message-ID:  <199704160130.VAA01790@jenolan.caipgeneral>
In-Reply-To: <199704150943.EAA03061@nyx.pr.mcs.net> (message from Chris Csanady on Tue, 15 Apr 1997 04:43:37 -0500)

next in thread | previous in thread | raw e-mail | index | archive | help
   Date: Tue, 15 Apr 1997 04:43:37 -0500
   From: Chris Csanady <ccsanady@nyx.pr.mcs.net>

   All I wanted to do was to make the below inline function generate the
   following code.  (It is a piece from one of Van Jacobsons mails..)  I
   realize this is for sparc, but it really doesnt matter..

       /* NB - ocadd is an inline gcc assembler function */
       cksum = ocadd(ocadd(ocadd(ocadd(cksum, seq), ack), flg), sum);


       addcc %l3,%o0,%o3
       addxcc %l4,%o3,%o3
       addxcc %l2,%o3,%o3
       addxcc %l0,%o3,%o3

static __inline__ unsigned int ocadd1(unsigned int sum, unsigned int addend)
{
	unsigned int ret;

	__asm__ __volatile__("addcc	%1, %2, %0"
			     : "=r" (ret)
			     : "r" (sum), "r" (addend));
	return ret;
}

static __inline__ unsigned int ocadd(unsigned int sum, unsigned int addend)
{
	unsigned int ret;

	__asm__ __volatile__("addxcc	%1, %2, %0"
			     : "=r" (ret)
			     : "r" (sum), "r" (addend));
	return ret;
}

cksum = ocadd(ocadd(ocadd(ocadd1(cksum, seq), ack), flg), sum);

something like that...

Then make sure you compile using gcc and don't specify any options
which disable function inlining or __asm__ directives...

(BTW: as you can see Jacobsons code could not have possibly
output that sequence of instructions as it is, simply because there is
no way just one ocadd() function could have output both "addcc"
and "addxcc" by magically knowing if it was the first invocation in a
series or not)

---------------------------------------------////
Yow! 11.26 MB/s remote host TCP bandwidth & ////
199 usec remote TCP latency over 100Mb/s   ////
ethernet.  Beat that!                     ////
-----------------------------------------////__________  o
David S. Miller, davem@caip.rutgers.edu /_____________/ / // /_/ ><



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199704160130.VAA01790>