From mboxrd@z Thu Jan 1 00:00:00 1970 From: tlaronde@polynum.com Date: Thu, 22 Apr 2010 19:36:40 +0200 To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Message-ID: <20100422173640.GA4148@polynum.com> References: <20100422152953.GA616@polynum.com> <20100422170358.80B9D5B73@mail.bitblocks.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20100422170358.80B9D5B73@mail.bitblocks.com> User-Agent: Mutt/1.4.2.3i Subject: Re: [9fans] BUG!!! in Plan9 compiler! Topicbox-Message-UUID: 0bab4c1e-ead6-11e9-9d60-3106f5b1d025 On Thu, Apr 22, 2010 at 10:03:58AM -0700, Bakul Shah wrote: > > What is the type of x1 and x2? Can you show an actual C code > fragment? Don't worry about it being complete. Just the half() All are "integer" (in WEB -> Pascal ->) #define integer long The half() macro is only this: #define half(x) ((x) >> 1) (Changing it to (x)/2 changes nothing: I have tried). All are signed and long type (i.e. for 32 bits). This is scaled integers calculus. And if you want the full story, here is the listing generated (this is from the translator, so it is from a style point of view, ugly; specially tracking what is a block for if or else is not obvious from sight. But it is short. I have put a comment on the branch where the problem arises): #define integer long typedef integer scaled; #define half(x) ((x) >> 1) void makemoves ( scaled xx0 , scaled xx1 , scaled xx2 , scaled xx3 , scaled yy0 , scaled yy1 , scaled yy2 , scaled yy3 , smallnumber xicorr , smallnumber etacorr ) {/* 22 30 10 */ integer x1, x2, x3, m, r, y1, y2, y3, n, s, l ; integer q, t, u, x2a, x3a, y2a, y3a ; if ( ( xx3 < xx0 ) || ( yy3 < yy0 ) ) confusion ( 109 ) ; l = 16 ; bisectptr = 0 ; x1 = xx1 - xx0 ; x2 = xx2 - xx1 ; x3 = xx3 - xx2 ; if ( xx0 >= xicorr ) r = ( xx0 - xicorr ) % 65536L ; else r = 65535L - ( ( - (integer) xx0 + xicorr - 1 ) % 65536L ) ; m = ( xx3 - xx0 + r ) / 65536L ; y1 = yy1 - yy0 ; y2 = yy2 - yy1 ; y3 = yy3 - yy2 ; if ( yy0 >= etacorr ) s = ( yy0 - etacorr ) % 65536L ; else s = 65535L - ( ( - (integer) yy0 + etacorr - 1 ) % 65536L ) ; n = ( yy3 - yy0 + s ) / 65536L ; if ( ( xx3 - xx0 >= 268435456L ) || ( yy3 - yy0 >= 268435456L ) ) { x1 = half ( x1 + xicorr ) ; x2 = half ( x2 + xicorr ) ; x3 = half ( x3 + xicorr ) ; r = half ( r + xicorr ) ; y1 = half ( y1 + etacorr ) ; y2 = half ( y2 + etacorr ) ; y3 = half ( y3 + etacorr ) ; s = half ( s + etacorr ) ; l = 15 ; } while ( true ) { lab22: if ( m == 0 ) while ( n > 0 ) { incr ( moveptr ) ; move [ moveptr ] = 1 ; decr ( n ) ; } else if ( n == 0 ) move [ moveptr ] = move [ moveptr ] + m ; else if ( m + n == 2 ) { r = twotothe [ l ] - r ; s = twotothe [ l ] - s ; while ( l < 30 ) { x3a = x3 ; x2a = half ( x2 + x3 + xicorr ) ; x2 = half ( x1 + x2 + xicorr ) ; x3 = half ( x2 + x2a + xicorr ) ; t = x1 + x2 + x3 ; r = r + r - xicorr ; y3a = y3 ; y2a = half ( y2 + y3 + etacorr ) ; y2 = half ( y1 + y2 + etacorr ) ; y3 = half ( y2 + y2a + etacorr ) ; u = y1 + y2 + y3 ; s = s + s - etacorr ; if ( t < r ) if ( u < s ) { x1 = x3 ; x2 = x2a ; x3 = x3a ; r = r - t ; y1 = y3 ; y2 = y2a ; y3 = y3a ; s = s - u ; } else { { incr ( moveptr ) ; move [ moveptr ] = 2 ; } goto lab30 ; } else if ( u < s ) { { incr ( move [ moveptr ] ) ; incr ( moveptr ) ; move [ moveptr ] = 1 ; } goto lab30 ; } incr ( l ) ; } r = r - xicorr ; s = s - etacorr ; if ( abvscd ( x1 + x2 + x3 , s , y1 + y2 + y3 , r ) - xicorr >= 0 ) { incr ( move [ moveptr ] ) ; incr ( moveptr ) ; move [ moveptr ] = 1 ; } else { incr ( moveptr ) ; move [ moveptr ] = 2 ; } lab30: ; } else { /* This is where the problem arises */ incr ( l ) ; bisectstack [ bisectptr + 10 ] = l ; bisectstack [ bisectptr + 2 ] = x3 ; bisectstack [ bisectptr + 1 ] = half ( x2 + x3 + xicorr ) ; x2 = half ( x1 + x2 + xicorr ) ; x3 = half ( x2 + bisectstack [ bisectptr + 1 ] + xicorr ) ; bisectstack [ bisectptr ] = x3 ; r = r + r + xicorr ; t = x1 + x2 + x3 + r ; q = bdiv ( t , l ) ; bisectstack [ bisectptr + 3 ] = bmod ( t , l ) ; bisectstack [ bisectptr + 4 ] = m - q ; m = q ; bisectstack [ bisectptr + 7 ] = y3 ; bisectstack [ bisectptr + 6 ] = half ( y2 + y3 + etacorr ) ; y2 = half ( y1 + y2 + etacorr ) ; y3 = half ( y2 + bisectstack [ bisectptr + 6 ] + etacorr ) ; bisectstack [ bisectptr + 5 ] = y3 ; s = s + s + etacorr ; u = y1 + y2 + y3 + s ; q = bdiv ( u , l ) ; bisectstack [ bisectptr + 8 ] = bmod ( u , l ) ; bisectstack [ bisectptr + 9 ] = n - q ; n = q ; bisectptr = bisectptr + 11 ; goto lab22 ; } if ( bisectptr == 0 ) goto lab10 ; bisectptr = bisectptr - 11 ; x1 = bisectstack [ bisectptr ] ; x2 = bisectstack [ bisectptr + 1 ] ; x3 = bisectstack [ bisectptr + 2 ] ; r = bisectstack [ bisectptr + 3 ] ; m = bisectstack [ bisectptr + 4 ] ; y1 = bisectstack [ bisectptr + 5 ] ; y2 = bisectstack [ bisectptr + 6 ] ; y3 = bisectstack [ bisectptr + 7 ] ; s = bisectstack [ bisectptr + 8 ] ; n = bisectstack [ bisectptr + 9 ] ; l = bisectstack [ bisectptr + 10 ] ; } lab10: ; } -- Thierry Laronde http://www.kergis.com/ Key fingerprint = 0FF7 E906 FBAF FE95 FD89 250D 52B1 AE95 6006 F40C