No status flags

Most instruction set architectures have status flags, while ForwardCom has none. This makes the hardware more efficient and makes compiling simpler, as will be explained here.

Traditional instruction set architectures have two kinds of status flags: integer status flags that are used for conditional branching, and floating point status flags that are used for detecting exceptions, such as overflow and illegal operations.

Traditional integer flags are used for branches. For example, consider a branch like this

if (A > B) {
    // do something
}
This is typically coded with two instructions: A compare instruction that sets a flag depending on the result of the compare operation, and a conditional jump that reads the flag and jumps depending on the condition.

ForwardCom combines the compare operation and the conditional jump into a single instruction so that there is no flag in-between. The compare-and-conditional-jump instructions can work with signed and unsigned integers as well as floating-point operands. There are also instructions that add and jump if overflow, subtract and jump if zero, and test a specific bit and jump if it is set. There is even an instuction that can implement an ordinary for-loop by incrementing a loop counter, comparing it to an upper limit, and jump back if it is below the limit.

Traditional floating-point flags behave differently. Integer flags are volatile, which means that the value of a flag is overwritten as soon as a new value is assigned. Floating-point flags are not volatile, but sticky. This means that when a flag has been set, it remains set until it is explicitly cleared. Floating-point flags are used for handling exceptions, such as overflow, division by zero, invalid operation, etc. This makes it possible to check after a series of calculations whether any of the calculations has produced an exception. ForwardCom does not use status flags for this. Instead, the error status is propagating through a series of calculations, as described under Error handling in ForwardCom. The error will show as a NaN code in any results that depend on the result that caused an unwanted exception.

An important advantage of having no flags is that all instructions have only one output. It is acutally quite costly in terms of hardware resources to have multiple outputs from all arithmetic instructions. The hardware needs additional result buses and register write ports to handle the additional outputs. The costs of status flags were small in the earliest computers that executed all instructions serially, one by one. But modern high-end microprocessors can execute multiple instructions simultaneously, or out of order. The hardware keeps track of which inputs depend on which outputs so that no instruction will be executed until all the necessary input operands are ready. An out-of-order scheduler has a large number of internal temporary registers. Every time an instruction writes to a register, the hardware will assign a new temporary register to it. This is called register renaming. It is possible to have many different instances of the same logical register in flight at the same time, with different values in them. If we have two outputs from every instruction, then we have to double the number of temporary registers for storing the outputs. We also need more resources for keeping track of which input depends on which output.

A big problem with flags is that if you want to read a sticky flag, then it is necessary to interrupt the out-of-order processing. Since all preceding floating-point instructions can possibly change the flag, it is necessary to wait for all these instructions to finish before you can read the status flag. All subsequent instructions must also be postponed until the flag has been read. A software code that reads the floating-point status flags in order to check for exceptions will ruin the advantages of out-of-order execution. The costs of interrupting the out-of-order flow can be quite high because a modern CPU with out-of-order capabilities can have hundreds of instructions in flight at the same time. Current microprocessors are unable to check for software exceptions without breaking the out-of-order processing. Some systems are using traps (software interrupts) for detecting exceptions, but this is even more inefficient. Traps must occur in program order. This requires that all floating-point instructions which are executed out-of-order must be executed speculatively until the CPU is certain that no preceding instruction has caused an exception. ForwardCom avoids all these problems because any information about exceptions will propagate through subsequent calculations without interfering with any unrelated instructions. This does not interfere with out-of-order execution or parallel execution.

Another important advantage of a design without flags is that it simplifies compiling. The compiler does not have to deal with troublesome side effects where a flag set by one instruction can have undesired consequences for other parts of the code. An arithmetic instruction in a flagless design has no such side effects. The instruction affects only its own output register. The elimination of side effects makes compilation simpler and makes it possible for the compiler to optimize more efficiently.

The fact that ForwardCom has no status flags makes both hardware and software simpler and more efficient. Arithmetic instructions have only one output. This is particularly advantageous for processors with out-of-order capabilities because it reduces the number of temporary registers and the number of dependencies to check. It makes parallel processing and out-of-order processing more efficient and reliable and reduces power consumption.