5 ms·
> CPU designers could create a design where an xor instruction was faster than a sub instruction. However that would mean that sub would take at least two clock
by saagarjha 8y ago
> CPU designers could create a design where an xor instruction was faster than a sub instruction. However that would mean that sub would take at least two clock cycles, since instruction lengths are integer cycle counts. Unless this modification let them at least double the clock speed it would be a net loss. It’s better to make xor take just as long as sub. You can’t make an xor instruction take, say, 0.6 cycles. But feel free to try.
Earlier, the article says that the process can perform four instructions per cycle. Just to confirm, this isn't normally referred to as taking "0.25 cycles per instruction", right?
- wongarsu 8y agoThere is some parallelism within in each CPU core so it can do four additions each cycle. But those don't happen after each other, they happen simultaniously. From an eagle eye's view it can look like 0.25 cycles per instruction, so on a higher abstraction level that's a valid view on it. But in reality they start and end at the same time each takes one cycle.
- rayiner 8y agoThe Intel manuals sometimes use that as a shorthand, but no, it’s usually not. The difference is between throughout and latency. You can process four independent instructions per cycle in parallel (if none depend on the results of the others), but the results of a given instruction will take at least one cycle to be available for the next instruction that uses it as an input. (It takes 9 months to make a baby even though you can make more than one at a time.)
- Sean1708 8y ago> You can process four independent instructions per cycle in parallel is this down to pipelining, or is that separate?
- gpderetta 8y agoActual redundant hardware. There are multiple ALUs for example (although not all equal), multiple load/store units. But the bottleneck that prevents of going wider than 4 is often the rename up to 4 registers per clock.
- jcranmer 8y agoModern processors are superscalar. What this means is that you have multiple independent execution units that can be scheduled each cycle. On Skylake, for instance, the execution units are: Port 0: int ALU, FP ALU, vector ALU, integer multiply/divide, branch Port 1: int ALU, FP ALU, vector ALU Port 2: Load unit Port 3: Load unit Port 4: Store unit Port 5: integer ALU, vector ALU Port 6: integer ALU, branch Port 7: Store unit [address component] Every instruction (or, more accurately, every micro-op; instructions don't exist at this point) can get scheduled onto one of these ports if that port has the capability to process it. Of course, there's also a limitation on the abilities of the instruction decode unit on how many instructions it can decode and convert into micro-ops each cycle.
- brucedawson 8y agoPipelining is necessary is well, but super-scalar is the key ingredient here - parallelism. Pipelining means that instruction fetch, decode, execution, and retirement are done in separate stages, each one taking at least one cycle. Super-scalar/parallelism means that there are multiple units for all of these stages so the CPU can fetch many instructions in parallel, decode many instructions in parallel, etc. The cool/critical thing here is that many Intel CPUs can execute three XOR instructions in parallel but can retire four. Because the CPU recognizes XOR of an instruction with itself as a special case it skips the execution stage and can then process four per cycle. Or, more likely in real code, the execution units are available for other instructions to use.
- a1369209993 8y agoStrictly speaking pipelining isn't actually necessary, it's just hard to imagine why you'd bother with superscalar execution without first exhausting the relatively-lower-hanging-fruit of pipelining.
- jcranmer 8y agoThe time instructions take are usually boiled down to two metrics: reciprocal throughput (you can issue 1 instruction of this type every N cycles), and latency (an instruction can use the result of this instruction N cycles after it executes). Latency is necessarily an integer number of cycles, but reciprocal throughput can be less than 1 if there are multiple execution ports in a superscalar machine. For example, the latency of a multiply instruction is usually about 3-4 cycles. But the reciprocal throughput is generally 1 (or 0.5 if you have two multiply units)--the execution unit is pipelined to allow a new input every cycle.