Port-i386 archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: curcpu() and curlwp()



[Christos, quoting David Laight]
>>            (*(struct cpu_info * const *)offsetof(struct cpu_info, 
>> ci_curlwp)));
>> I think it should be:
>>      "m" (((const struct cpu_info *)0)->ci_curlwp)

> I think that if offsetof() produces suboptimal code, it should be
> fixed, not expanded in place differently.

I would agree.  But, as David said...

>> The generated code is probably identical, but the inferences are
>> different.

...the difference is not the generated code and its optimality, but the
conceptual thing the code is expressing.

Consider the following, which (assuming a not totally brain-dead
compiler, and given "void foo(int);") produce bit-identical code:

foo((int)M_PI);

foo(ICMP6_TIME_EXCEEDED);

foo(D_TTY);

(given "int shifts[] = { 2, 4, 16 };")
foo(sizeof(shifts)/sizeof(shifts[0]));

foo(ESRCH);

foo(3); /* first fd above stdin/stdout/stderr */

#define MAX_RETRIES 3
foo(MAX_RETRIES);

#define LG_PAGE_SIZE 12 /* this hardware uses 4k pages */
#define LG_DEVBLK_SIZE 9 /* the drive uses half-k blocks */
foo(LG_PAGE_SIZE-LG_DEVBLK_SIZE);

But the implications, the concepts they are expressing, differ wildly,
and writing one of them when meaning one of the others could quite
rightly be called a bug.  Even though it'll work fine.

/~\ The ASCII                             Mouse
\ / Ribbon Campaign
 X  Against HTML                mouse%rodents-montreal.org@localhost
/ \ Email!           7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B


Home | Main Index | Thread Index | Old Index