From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 In-Reply-To: References: <10afea42a3af8daf8abd3b8e8775850e@quanstro.net> <775b8d190908311851t701d860av587b7433bea29fcf@mail.gmail.com> Date: Tue, 1 Sep 2009 13:24:11 +1000 Message-ID: <775b8d190908312024q3a0167a0xf7f686a6f2408eb2@mail.gmail.com> From: Bruce Ellis To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [9fans] 8c vlong bug Topicbox-Message-UUID: 5dd09086-ead5-11e9-9d60-3106f5b1d025 will fix. On Tue, Sep 1, 2009 at 1:10 PM, Russ Cox wrote: >> temporarly out of time on this one. =A0it appears >> from the assembly output that 8c multiplies by >> 0 and not 1 when computing z a second time. >> nonetheless, i haven't yet seen the problem. > > not quite that simple. > it's a register allocation > (really register management) bug. > > On Mon, Aug 31, 2009 at 6:51 PM, Bruce Ellis wrote= : >> if it's my fault i'll fix it. it did screw up mod in a subtle way but >> that's been fixed. > > it looks like the cgen64 multiply case is > not managing the registers correctly > when AX is not where it expects. > more details for you: > > int three =3D 3; > int one =3D 1; > uvlong twelve =3D 12; > > /* ok */ > uvlong > mul1(void) > { > =A0 =A0 =A0 =A0return one * (twelve - three); > } > > TEXT =A0 =A0mul1+0(SB),0,$12 > =A0 =A0 =A0 =A0MOVL =A0 =A0three+0(SB),AX > =A0 =A0 =A0 =A0MOVL =A0 =A0AX,CX > =A0 =A0 =A0 =A0SARL =A0 =A0$31,CX > =A0 =A0 =A0 =A0// three is now in CX:AX > > =A0 =A0 =A0 =A0LEAL =A0 =A0twelve+0(SB),DX > =A0 =A0 =A0 =A0MOVL =A0 =A0(DX),BX > =A0 =A0 =A0 =A0SUBL =A0 =A0AX,BX > =A0 =A0 =A0 =A0MOVL =A0 =A04(DX),AX > =A0 =A0 =A0 =A0SBBL =A0 =A0CX,AX > =A0 =A0 =A0 =A0// twelve - three is now in AX:BX > =A0 =A0 =A0 =A0MOVL =A0 =A0AX,CX > =A0 =A0 =A0 =A0// twelve - three is now in CX:BX > > =A0 =A0 =A0 =A0MOVL =A0 =A0one+0(SB),AX > =A0 =A0 =A0 =A0MOVL =A0 =A0AX,DX > =A0 =A0 =A0 =A0SARL =A0 =A0$31,DX > =A0 =A0 =A0 =A0// one is now in DX:AX > > =A0 =A0 =A0 =A0// 64-bit multiply CX:BX * DX:AX -> DX:AX > =A0 =A0 =A0 =A0MOVL =A0 =A0CX,BP > =A0 =A0 =A0 =A0ORL =A0 =A0 DX,BP > =A0 =A0 =A0 =A0CMPL =A0 =A0BP,$0 > =A0 =A0 =A0 =A0JNE =A0 =A0 ,3(PC) > =A0 =A0 =A0 =A0MULL =A0 =A0BX, > =A0 =A0 =A0 =A0JMP =A0 =A0 ,8(PC) > =A0 =A0 =A0 =A0IMULL =A0 BX,DX > =A0 =A0 =A0 =A0MOVL =A0 =A0AX,BP > =A0 =A0 =A0 =A0IMULL =A0 CX,BP > =A0 =A0 =A0 =A0ADDL =A0 =A0DX,BP > =A0 =A0 =A0 =A0MOVL =A0 =A0BX,DX > =A0 =A0 =A0 =A0MULL =A0 =A0DX, > =A0 =A0 =A0 =A0ADDL =A0 =A0BP,DX > > =A0 =A0 =A0 =A0MOVL =A0 =A0.ret+0(FP),CX =A0 // probably LEAL > =A0 =A0 =A0 =A0MOVL =A0 =A0AX,(CX) > =A0 =A0 =A0 =A0MOVL =A0 =A0DX,4(CX) > =A0 =A0 =A0 =A0RET =A0 =A0 , > =A0 =A0 =A0 =A0RET =A0 =A0 , > > vs > > /* not ok */ > > uvlong > mul2(void) > { > =A0 =A0 =A0 =A0return (twelve - three) * one; > } > > TEXT =A0 =A0mul2+0(SB),0,$12 > =A0 =A0 =A0 =A0MOVL =A0 =A0one+0(SB),AX > =A0 =A0 =A0 =A0MOVL =A0 =A0AX,CX > =A0 =A0 =A0 =A0SARL =A0 =A0$31,CX > =A0 =A0 =A0 =A0MOVL =A0 =A0AX,BX > =A0 =A0 =A0 =A0// one is now in CX:BX > > =A0 =A0 =A0 =A0MOVL =A0 =A0three+0(SB),AX > =A0 =A0 =A0 =A0MOVL =A0 =A0AX,DX > =A0 =A0 =A0 =A0SARL =A0 =A0$31,DX > =A0 =A0 =A0 =A0// three is now in DX:AX > > =A0 =A0 =A0 =A0LEAL =A0 =A0twelve+0(SB),BP > =A0 =A0 =A0 =A0MOVL =A0 =A0(BP),SI > =A0 =A0 =A0 =A0SUBL =A0 =A0AX,SI > =A0 =A0 =A0 =A0MOVL =A0 =A04(BP),AX > =A0 =A0 =A0 =A0SBBL =A0 =A0DX,AX > =A0 =A0 =A0 =A0// twelve - three is now in AX:SI > > =A0 =A0 =A0 =A0// 64-bit multiply CX:BX * AX:SI > =A0 =A0 =A0 =A0// saving AX and DX so they can be reused. > =A0 =A0 =A0 =A0// DX doesn't even need saving. > =A0 =A0 =A0 =A0MOVL =A0 =A0AX,.safe+-4(SP) > =A0 =A0 =A0 =A0MOVL =A0 =A0DX,.safe+-8(SP) > =A0 =A0 =A0 =A0MOVL =A0 =A0SI,DX > > =A0 =A0 =A0 =A0// 8c is very confused at this point. > =A0 =A0 =A0 =A0// it is using AX for multiple purposes. > =A0 =A0 =A0 =A0MOVL =A0 =A0CX,AX > =A0 =A0 =A0 =A0ORL =A0 =A0 SI,AX > =A0 =A0 =A0 =A0CMPL =A0 =A0AX,$0 > =A0 =A0 =A0 =A0JNE =A0 =A0 ,4(PC) > =A0 =A0 =A0 =A0MOVL =A0 =A0BX,AX > =A0 =A0 =A0 =A0MULL =A0 =A0AX, > =A0 =A0 =A0 =A0JMP =A0 =A0 ,7(PC) > =A0 =A0 =A0 =A0IMULL =A0 BX,DX > =A0 =A0 =A0 =A0IMULL =A0 CX,AX > =A0 =A0 =A0 =A0ADDL =A0 =A0DX,AX > =A0 =A0 =A0 =A0MOVL =A0 =A0BX,DX > =A0 =A0 =A0 =A0MULL =A0 =A0DX, > =A0 =A0 =A0 =A0ADDL =A0 =A0AX,DX > > =A0 =A0 =A0 =A0// restore old AX DX now that multiply is over. > =A0 =A0 =A0 =A0// (forgot that multiply left result in DX:AX) > =A0 =A0 =A0 =A0MOVL =A0 =A0.safe+-4(SP),AX > =A0 =A0 =A0 =A0MOVL =A0 =A0.safe+-8(SP),DX > > =A0 =A0 =A0 =A0MOVL =A0 =A0.ret+0(FP),CX =A0 // probably LEAL > =A0 =A0 =A0 =A0MOVL =A0 =A0AX,(CX) > =A0 =A0 =A0 =A0MOVL =A0 =A0DX,4(CX) > =A0 =A0 =A0 =A0RET =A0 =A0 , > >