Subject: Re: VAX code generation problem wrt IPSEC?
To: Johnny Billquist <>
From: Olaf Seibert <>
List: current-users
Date: 11/12/2001 14:36:59
On Mon 12 Nov 2001 at 13:10:41 +0100, Olaf Seibert wrote:
> The more I look at the assembly, the more it seems to differ from the
> source. But I did generate it by changing the -c into -S in the output
> of make -n, so it ought to be ok.

Ok, so I did look at the wrong sources. I thought as much. The correct
ones are at /usr/src/sys/arch/vax/vax/in_cksum.c .

So, looking into the same loop, I see

                while ((mlen -= 32) >= 0) {
                         * Add with carry 16 words and fold in the last carry
                         * by adding a 0 with carry.
                        ADDL;   ADWC;   ADWC;   ADWC;
                        ADWC;   ADWC;   ADWC;   ADWC;
                mlen += 32;

with these definitions:

#define Asm     __asm __volatile
#define ADDL    Asm("addl2 (%2)+,%0" : "=r" (sum) : "0" (sum), "r" (w))
#define ADWC    Asm("adwc  (%2)+,%0" : "=r" (sum) : "0" (sum), "r" (w))
#define ADDC    Asm("adwc     $0,%0" : "=r" (sum) : "0" (sum))

and now the problem is obvious: in ADDL and ADWC w is only declared an
input operand, not an input-output operand. So when not optimizing, it
is reloaded every time, and when optimizing, it works only by accident
because the compiler thinks it isn't being modified.

I haven't done much with gcc's extended asm, but I think this should do
the trick (2 spaces eliminated to stay within 80 columns):

#define ADDL    Asm("addl2 (%1)+,%0": "=r" (sum), "=r" (w): "0" (sum), "1" (w))
#define ADWC    Asm("adwc  (%1)+,%0": "=r" (sum), "=r" (w): "0" (sum), "1" (w))

but I'll have to check that when I get home again.

Also swapping sum and w to be in the same order as in the instruction
seems aesthetically better to me:

#define ADDL    Asm("addl2 (%0)+,%1": "=r" (w), "=r" (sum): "0" (w), "1" (sum))
#define ADWC    Asm("adwc  (%0)+,%1": "=r" (w), "=r" (sum): "0" (w), "1" (sum))

___ Olaf 'Rhialto' Seibert - rhialto@polder --They that can give up essential 
\X/ --liberty to purchase a little temporary safety
--------------deserve neither liberty or safety. - Benjamin Franklin, 1759
---People will accept your ideas much more readily if you tell them that
---Benjamin Franklin said it first. - Unknown