Why are CPU registers fast to access?

前端 未结 6 1862
离开以前
离开以前 2021-02-12 15:09

Register variables are a well-known way to get fast access (register int i). But why are registers on the top of hierarchy (registers, cache, main memory, secondary

6条回答
  •  孤城傲影
    2021-02-12 15:42

    Registers are circuits which are literally wired directly to the ALU, which contains the circuits for arithmetic. Every clock cycle, the register unit of the CPU core can feed a half-dozen or so variables into the other circuits. Actually, the units within the datapath (ALU, etc.) can feed data to each other directly, via the bypass network, which in a way forms a hierarchy level above registers — but they still use register-numbers to address each other. (The control section of a fully pipelined CPU dynamically maps datapath units to register numbers.)

    The register keyword in C does nothing useful and you shouldn't use it. The compiler decides what variables should be in registers and when.

提交回复
热议问题