Re: __ucmpdi2

From: Peter Samuelson (peter@cadcamlab.org)
Date: Wed Sep 20 2000 - 08:27:18 EST


[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/



This archive was generated by hypermail 2b29 : Sat Sep 23 2000 - 21:00:23 EST