> It is mainly about how the code to lmul and ldiv or any thing like does
are
> referenced by other funciton in other segments... I understand that those
> functions are on the runtime lib I included in t he first segment, but how
> do i make other funcitons in the rest of the segmentes to performs this
> multiplications and division correctlye..
For a multi-segment application, you use a special version of the startup
library, generally MSL Runtime Palm OS (2i).Lib. This startup library goes
at the beginning of the first segment. It contains several long math
functions. For example, there is a function __lmul__ which multiplies two
32-bit integers. The compiler generates calls to these functions when you
write code like:
UIn32 a; b; c;
a = b * c;
Short (16-bit) math won't generate calls to these functions; it'll generate
68000 instructions that do the math directly. The compiler generates calls
to a long math function when it needs (or thinks it needs) long math to do
index calculations. For example, code like this will produce a call to
__lmul__:
typedef struct {Char first[5]; Char last[5];} NameType;
NameType name, *nameP;
UInt16 index;
name = nameP[index];
If you declared nameP as:
NameType nameP[10];
the compiler would know that short math was adequate. Or you could do the
indexing manually, ensuring that the appropriate types are being used at all
stages of the calculation. With some understanding of how the compiler
works, you can prevent the compiler from generating calls to the long math
functions, making your code run faster, and eliminating the constraints on
how the code is organized that result from such calls.
Another function that's in the startup library is __wswtch__. The compiler
generates calls to this function when you use a switch statement with a 16
bit argument, at least under some circumstances. I don't know the details.
You can avoid such calls by using if statements rather than switch
statements - not pretty, but it works.
You can call functions in the startup library from other segments. I'm not
sure how this works, but I know I've done it successfully. It probably uses
a jump table at the beginning of each segment. If you're using the Small
code model, which I recommend, all calls in the first segment must be within
32K of the function being called. Since these functions are at the beginning
of the startup library, which is at the beginning of the segment, and these
functions are tiny, you have about 32K of space in which to put such code.
If my theory about how intersegment calls to startup functions is correct,
the same 32K limit applies to other segments as well.
I'm not really an expert on compiler stuff; this is all just my
understanding based on using CodeWarrior. Perhaps a real expert can
enlighten us. :) If you haven't checked out the "link map" feature of
CodeWarrior, I recommend doing so. You can learn a lot by looking at the
link map and disassembling the compiled code.
--
Danny @ Palm
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/