Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1Nh5Th-0002D0-3R for mharc-grub-devel@gnu.org; Mon, 15 Feb 2010 13:15:25 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Nh5Tf-0002Bj-1I for grub-devel@gnu.org; Mon, 15 Feb 2010 13:15:23 -0500 Received: from [140.186.70.92] (port=41160 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nh5Te-0002BK-Cr for grub-devel@gnu.org; Mon, 15 Feb 2010 13:15:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Nh5Tb-0002ly-FQ for grub-devel@gnu.org; Mon, 15 Feb 2010 13:15:22 -0500 Received: from mail-fx0-f215.google.com ([209.85.220.215]:65140) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Nh5Tb-0002lm-7W for grub-devel@gnu.org; Mon, 15 Feb 2010 13:15:19 -0500 Received: by fxm7 with SMTP id 7so5397733fxm.8 for ; Mon, 15 Feb 2010 10:15:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:from:date:x-google-sender-auth:message-id:subject:to:cc :content-type:content-transfer-encoding; bh=4xp0Owh+6WpPbFRBvIfZu9EUompPcni6KihqZS0OpdU=; b=mkfDMFnJT4kb+9PFYxtfTdK7N2PSbYtoyAKZ0IRW7IvGyO1jQ/ANdmQyqMrWmzesre OFPgDGJ3K0LAKNdPSRW15ste//fAh3azcHOACOD8i5Iwte0WP84J6mYAQRcFRbSPN7lQ 9iRJ9xjWu9Z2b/7j8vlQ9/RJ7OBDEN2aNdYSw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type :content-transfer-encoding; b=flWXhcdIhu1/tKMgyxN0PSpayPbei9zG2qGD686Z6lq/NN6z+32EjPa6pkNBPEk5lP a9Q6py2al7nndZOITNq5RLF8k0f24sAfHeV64jxnkDdi9oTgLHvCBo+nMfYDXIO4bNdK ThIE5WGmzU7t0ZBjiYOikgAl9FTbariwk5E1g= MIME-Version: 1.0 Sender: hramrach@gmail.com Received: by 10.239.135.82 with SMTP id c18mr555365hbc.73.1266257717200; Mon, 15 Feb 2010 10:15:17 -0800 (PST) In-Reply-To: <20100215090552.047346bf@svelte> References: <4B736F82.7010005@gmail.com> <4B742B70.3080303@gmail.com> <20100215090552.047346bf@svelte> From: Michal Suchanek Date: Mon, 15 Feb 2010 19:14:57 +0100 X-Google-Sender-Auth: 37f64831dc2c6946 Message-ID: To: Colin D Bennett Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: The development of GNU GRUB Subject: Re: [RFC] Framebuffer rotation patch, or why 'unsigned' fails us X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Feb 2010 18:15:23 -0000 On 15 February 2010 18:05, Colin D Bennett wrote: > On Sat, 13 Feb 2010 18:29:41 +0100 > Michal Suchanek wrote: > >> 2010/2/11 Vladimir '=CF=86-coder/phcoder' Serbinenko = : >> > Michal Suchanek wrote: >> >> 2010/2/11 Vladimir '=CF=86-coder/phcoder' Serbinenko >> >> : >> >> >> >>> Michal Suchanek wrote: >> >>> - =C2=A0 =C2=A0unsigned int x; >> >>> - =C2=A0 =C2=A0unsigned int y; >> >>> - =C2=A0 =C2=A0unsigned int width; >> >>> - =C2=A0 =C2=A0unsigned int height; >> >>> + =C2=A0 =C2=A0int x; >> >>> + =C2=A0 =C2=A0int y; >> >>> + =C2=A0 =C2=A0int width; >> >>> + =C2=A0 =C2=A0int height; >> >>> Why do you need negative values? >> >>> >> >> >> >> I don't need the negative values everywhere but this change was to >> >> align the typing so that casts are not required. >> >> >> >> >> > Perhaps few casts together with appropiate checks when casting is >> > better than potentially exposing the whole code to the values it's >> > not intended for. >> >> How is it exposed to more unwanted values than now? >> It uses the variables only to store the viewport dimensions and at >> most adds a border around it. The unsigned integer is able to >> represent values outside of the viewport as much as signed integers >> are, only signed integer can represent values outside of viewport in >> both directions. The unwanted values (if erroneously calculated which >> does not seem to be the case here) are clipped by the viewport >> clipping in video_fb. >> >> On the other hand, there would be more than a few casts as the >> variables are used multiple times and the interface now uses signed >> integers. > > I have to chime in on this one since I've learned the hard way that > 'unsigned' doesn't pull its weight in these use cases. =C2=A0Using unsign= ed > integer values in C when a lot of arithmetic is performed (as in > graphics programming) is really a nightmare. Well, maybe if you are a > grand master C programmer you would remember when you need to cast and > never make a mistake, but remember that there are us mere mortals who > would benefit by more logical and predictable code behavior. =C2=A0(I use > 'predictable' not in the sense that expressions involving both signed > and unsigned values are have an undefined result, but rather that it's > usually not the obvious result that the average C programmer would > expect at first glance. > > Certainly it would be nice if we could use the 'unsigned' qualifier to > enforce an invariant requiring only non-negative values be stored in > it (which it technically does, but it doesn't necessarily make the > result any more correct). =C2=A0It almost never really fixes the kind of > problems we'd like it to. =C2=A0We could easily try to store the result o= f a > subtraction that conceptually should produce a negative value into an > unsigned variable, and--OOPS!--we now have an enormous value instead of > a negative value. Not much better. =C2=A0More significant is code that > involves multiple operations such that the result of the entire > expression should be nonnegative, but it involves temporary negative > values in subexpressions such that the implicit signed-unsigned > conversion produces the "wrong" result (i.e., not what the programmer > intended even though the expression looks correct). > I started using negative integers because I need that rectangles overflowing to the top and left are not special and different from rectangles overflowing to the bottom and right as transforms might map the latter to the former. This also enhances the video interface so that drawing at negative position is representable in the arguments. Iit is then possible to blit a bitmap without first clipping the topleft part by just blitting at negative position which should make some operations easier to carry out. What is left unsigned is the framebuffer size in mode info and it indeed requires some casts and causes trouble. It made me change one of the transform routines to asymmetric types because it is used (almost) exclusively on the mode info structure. The members of mode_info should not ever become negative, though and the unsigned type is probably meant to make that clear. I can't say if making that clear outweights the possible issues when using the values in calculations. Thanks Michal