lkml.org 
[lkml]   [2000]   [Sep]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: __ucmpdi2
From

[Jeremy Higdon]
> Is there a little FAQ of C constructions you should not use if you
> are writing kernel code? It took a little doing to figure out that
> it was the switch that was causing trouble and not the shifts and
> arithmetic operations, and I'd like to avoid that in the future :-).

Here are some of the big ones:

* 64-bit division. Most such is by powers of two so you can use shifts
instead. Probably the compiler should optimize this case
automatically, but gcc doesn't, currently.

* floating point. Use fixed point integers. Floating point registers
(at least on i386) are not saved/restored in the right places
(because doing so is very expensive on some CPUs), so you'll clobber
someone else's context.

* MMX. See floating point.

* excess stack usage. The kernel stack is very very small, so don't
waste it. Large automatic arrays are BAD. Use globals or dynamic
allocation.

* C++ exceptions, run-time types (RTTI) and other
features-of-the-month. Stick to C and you'll be OK.

* global variables initialized to 0. Not necessary, as uninitialized
globals are zeroed automatically, and that way they don't take up
space in the on-disk image. This is a concern for embedded systems.

Also make sure to read Documentation/CodingStyle for, well, coding style.

Peter
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 12:39    [W:0.093 / U:7.120 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site