Node:Floating point, Previous:Hints, Up:Hints



Floating point

How should you deal with floating point values? Should you use the same stack as for integers/pointers, or a different one? This section discusses this issue with a view on execution speed.

The simpler approach is to use a separate floating-point stack. This allows you to choose FP value size without considering the size of the integers/pointers, and you avoid a number of performance problems. The main downside is that this needs an FP stack pointer (and that may not fit in the register file on the 386 arhitecture, costing some performance, but comparatively little if you take the other option into account). If you use a separate FP stack (with stack pointer fp), using an fpTOS is helpful on most machines, but some spill the fpTOS register into memory, and fpTOS should not be used there.

The other approach is to share one stack (pointed to by, say, sp) between integer/pointer and floating-point values. This is ok if you do not use spTOS. If you do use spTOS, the compiler has to decide whether to put that variable into an integer or a floating point register, and the other type of operation becomes quite expensive on most machines (because moving values between integer and FP registers is quite expensive). If a value of one type has to be synthesized out of two values of the other type (double types), things are even more interesting.

One way around this problem would be to not use the spTOS supported by Vmgen, but to use explicit top-of-stack variables (one for integers, one for FP values), and having a kind of accumulator+stack architecture (e.g., Ocaml bytecode uses this approach); however, this is a major change, and it's ramifications are not completely clear.