Pete Zaitcev wrote:

On Mon, 12 Jan 2004 22:04:16 +0100 (MET)
[EMAIL PROTECTED] wrote:


   > So everybody who does not want to know how integers are represented
   > on the current architecture writes
   >     start = p[0] + (p[1] << 8) + (p[2] << 16) + (p[3] << 24);
   > And it just works.

   Really, do you think your statement is better, clearer, or less
   error-prone than this:

start = get_be32(p);


I have been arguing that casts are bad. If get_le32(p) does not
involve a cast but is just an abbreviation of what I wrote above,
then of course I do not object.


Both work in kernel, because Linux guarantees processing of alignment traps and emulation of unaligned access. But I really dislike when people abuse this property of kernel. It's not intended for routine use.


Are you sure?


I ask this, because I recently ported a user space application to work on an ARM processor, and the hard work was to correct all the places where the application was using unaligned accesses. If they were not corrected, the application would give wrong results.

From what I gathered the reasoning behind this behavior was:

1 - we can let the kernel trap and correct all unaligned accesses. This way applications (and the kernel itself) would run slower but with no other problems.

2 - we can let the kernel just "count" unaligned accesses and let developers correct the code until the counter reads always zero in any situation. This way the applications will be cleaner and faster.

I think I read somewhere that the kernel developers went for the second option, with which I personally agree, by the way.

Although it gave me some trouble to fix everything, the application in the end got improvements for x86 too, because although x86 does unaligned accesses, it pays a performance penalty to do so.


-- Paulo Marques Software Development Department - Restinfor, Lda. Phone: +351 252 290600, Fax: +351 252 290601 Web: www.grupopie.com

"In a world without walls and fences who needs windows and gates?"



-------------------------------------------------------
This SF.net email is sponsored by: Perforce Software.
Perforce is the Fast Software Configuration Management System offering
advanced branching capabilities and atomic changes on 50+ platforms.
Free Eval! http://www.perforce.com/perforce/loadprog.html
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to