Home > Mobile >  Are variables of type .double stored on two registers?
Are variables of type .double stored on two registers?

Time:09-10

When I declare an integer I use the directive ".word", which has 32 bits, and if I'm correct that's also the size of a register in the mips architecture.

Now, to my understanding, a ".double" should be 64 bits. Does that mean that when I load the variable into a register (lwc1), that it actually stores on two registers, like an array; or are the registers on the coprocessor twice as big?

CodePudding user response:

Does that mean that when I load the variable into a register (lwc1), that it actually stores on two registers, like an array; or are the registers on the coprocessor twice as big?

Note that the instruction should be ldc1, lwc1 is for loading a 32-bit float.

But anyway: maybe. At the ISA level (the level that you experience when working in assembly), a double precision number is stored in two consecutive registers. Only even-numbered registers are valid to specify as target or source of a double precision operation, the odd-numbered register following it is implicitly used as well. In that sense, double precision floats are stored on two registers like an array.

On the other hand, that doesn't necessarily mean that that's a good description of how the hardware works. There are different ways to implement the same ISA. One of the ways is to literally have a monolithic array of 32 32-bit FPU registers, and literally read 2 consecutive registers from the same array for every source operand and write the result to 2 consecutive registers. But that requires doubling the number of read ports and write ports of the register file, if double precision operations are supported at the same throughput as single precision operations.

A more likely solution is implementing two banks of registers, an even bank and an odd bank, to halve the number of read ports and write ports per bank compared to the "monolithic array" configuration. It doesn't change the total number of ports, but splitting them up like that is useful: adding more ports to an SRAM array is relatively expensive, more expensive than dealing with two banks (which isn't free either since single-precision operands need to be able to come out of either bank, but that's not as bad). That way a double precision value is still stored across two registers, but not like an array, but like two entries with the same index in two separate arrays.

There are more ways to implement it. Using 64-bit registers (as you also suggested) and selecting one half of them for single-precision operands is also an option, somewhat annoying when performing a write.

  • Related