From owner-cvs-all@FreeBSD.ORG Sun Mar 18 02:56:02 2007 Return-Path: X-Original-To: cvs-all@freebsd.org Delivered-To: cvs-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 42B1116A400; Sun, 18 Mar 2007 02:56:02 +0000 (UTC) (envelope-from imp@bsdimp.com) Received: from harmony.bsdimp.com (vc4-2-0-87.dsl.netrack.net [199.45.160.85]) by mx1.freebsd.org (Postfix) with ESMTP id 0161613C455; Sun, 18 Mar 2007 02:56:01 +0000 (UTC) (envelope-from imp@bsdimp.com) Received: from localhost (localhost [127.0.0.1]) by harmony.bsdimp.com (8.13.4/8.13.4) with ESMTP id l2I2sFNU018437; Sat, 17 Mar 2007 19:54:15 -0700 (MST) (envelope-from imp@bsdimp.com) Date: Sat, 17 Mar 2007 20:54:18 -0600 (MDT) Message-Id: <20070317.205418.179961042.imp@bsdimp.com> To: jroberson@chesapeake.net From: "M. Warner Losh" In-Reply-To: <20070317121427.H560@10.0.0.1> References: <20070317110821.I560@10.0.0.1> <200703172100.13218.max@love2party.net> <20070317121427.H560@10.0.0.1> X-Mailer: Mew version 4.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.0 (harmony.bsdimp.com [127.0.0.1]); Sat, 17 Mar 2007 20:54:16 -0600 (MDT) Cc: max@love2party.net, jeff@freebsd.org, src-committers@freebsd.org, cvs-all@freebsd.org, cvs-src@freebsd.org Subject: Re: cvs commit: src/sys/kern sched_ule.c X-BeenThere: cvs-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: CVS commit messages for the entire tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 18 Mar 2007 02:56:02 -0000 In message: <20070317121427.H560@10.0.0.1> Jeff Roberson writes: : : On Sat, 17 Mar 2007, Max Laier wrote: : : > On Saturday 17 March 2007 20:09, Jeff Roberson wrote: : >> Any language lawyers care to comment on this? : > : > I find this strange. According to the spec "(Decrementing is equivalent : > to subtracting 1.)", but "pri = --pri % RQ_NQS;" will behave like you : > expect, while "pri = (pri - 1) % RQ_NQS;" clearly didn't. : : I noticed this as well. : : When you do --pri, pri is promoted to int for the math and then demoted : back to char wich truncates the value. Subsequently this value is used : in the % operation, which gives the expected results. : : When you do pri - 1 the intermediate result is promoted to a signed int : which doesn't yield the result you'd like when you mod with 64. (pri - 1u) % 64 is likely what you want. That way the (pri - 1u) turns out to be unsigned because it is (unsigned - unsigned) % signed. which winds up being unsigned % signed. The - 1 version is (unsigned - signed) % signed, which breaks down to signed % signed, which yields the strange result that you saw. (unsigned char)(pri - 1) % 64 is another way to fry this fish. Warner