Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 17 Mar 2007 20:54:18 -0600 (MDT)
From:      "M. Warner Losh" <imp@bsdimp.com>
To:        jroberson@chesapeake.net
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
Message-ID:  <20070317.205418.179961042.imp@bsdimp.com>
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>

next in thread | previous in thread | raw e-mail | index | archive | help
In message: <20070317121427.H560@10.0.0.1>
            Jeff Roberson <jroberson@chesapeake.net> 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070317.205418.179961042.imp>