by api · 5y ago · 0 comments
Intel has shown that you can just store the sizes of instructions in a new cache (in their new architecture) for example.
But even then: it shouldn't be much more than O(n) work / O(log(n)) depth to determine the length of an instruction. Once lengths are known, you can perform parallel instruction decoding rather easily.
Ex: given "Instruction at X, X+1, X+5, and X+10", decode the instructions. Well, simple. Just shove a decoder at X, X+1, X+5, and X+10. 4 instructions, decoded in parallel.
Even with "Dynamic" length (ex: X, X+4, X+6, and X+7 afterwards), its clear how to process these 4 instructions in parallel. Really not a problem IMO.
--------
So solving the length thing is a bit harder to see, but clearly could be implemented as a parallel-regex (which is O(n) work and O(log(n)) depth).
I seriously doubt that decoding is really a problem. I'd expect that Apple just has made many small efficiency gains across the chip, especially the uncore.
I'm personally looking at the L1 / L2 cache hierarchies more so than anything on this Apple chip.
Consider Intel has a more or less infinite amount of money and they don't seem to be able to do that. And they have tried (I even had an Atom-based Android phone for a while).
If you want an easy way to build a reorder buffer, you'll need to push every instruction in a structure that fits, IIRC, 15 bytes, which is the longest x86 instruction possible (for now - mwahahaha). This alone will make it twice as large as a similar arm64 one. Now factor in that the dependencies between instructions are defined in bits that can pretty much be all over the place in those 15 bytes and you end up with a nightmare most engineers would consider suicide before having to work on it.
Look, I started programming in GPUs a year or two ago. I've begun to "think in parallel", and now I'm beginning to see all sorts of efficient patterns all over the place.
The actual CPU-architects have known about kogge-stone carry-lookahead longer than I have. I'm still a newbie to this mindset of parallel computations... but I enjoy reading the papers on PDEP / PEXT / other parallel structures these CPU designers are doing (and these structures have gross implications to how GPU code should be structured).
But I've had enough practice with Kogge-stone / Carry-lookahead / Prefix-sum / scan pattern (yeah, its __all__ the same parallelism), and this pattern has been well published since the 1970s. I have to assume that engineers know about this stuff.
Instruction length decoding is very clearly a kogge-stone pattern / prefix sum / scan problem to me. Now, I'm not a chip architect and maybe there's some weird fanout / chip level thing going on that my ignorance is keeping me out of... but... based on my understanding of parallel systems + very, very common patterns well known to that community, I'd expect that chip-designers would just Kogge-stone their way out of this decoding problem.
-------
Like, I'm coming in from the reverse here. I suddenly realized that chip-designers have incredibly active minds about the layout and structure of parallel computing mechanisms, and have now taken an interest in studying some CPU-level parallelism techniques to apply to my GPU code.
The CPU-designers are way ahead of us in "parallel thinking". I'm a visitor to their subject, they do this stuff for breakfast every day. They have to see the Kogge-stone solution to the decoding problem. If not, they've thought of something better.
I'll help ya out. Kogge-Stone is the paper from March 1972 that states that ANY recurrence relation "x_i = f(b_i, g(a_i, x_i-1))" can be parallelized, as long as f and g satisfy distributive and associative-like properties, "executing in time proportional to log2(n)" (aka: O(log2(n)), but this paper was probably before O-notation was popular).
The if the Kogge-Stone algorithm is executed sequentially, time is proportional to n.
https://ntrl.ntis.gov/NTRL/dashboard/searchResults/titleDeta...
As you can see, Kogge-Stone can efficiently parallelize (aka: execute O(log2(N)) depth, O(N) total-work) a wide variety of recurrence relationships that initially seem sequential.
-----------
GPU programmers know this pattern as prefix-sum. In CPU-architecture books, its called Kogge-Stone.
----------
Maybe this will help? Lets say "1" is "this byte is a start-of-instruction" and "0" is "this is not the start-of-instruction".
For example: "1 0 0 1 0 1 1 0" would contain instructions at i_0, i_3, i_5, and i_6.
Now prefix_sum(1 0 0 1 0 1 1 0) == (1, 1, 1, 2, 2, 3, 4, 4)
f = 1 0 0 1 0 1 1 0
g = 1 1 1 2 2 3 4 4
idx = 0 1 2 3 4 5 6 7
So lets say we have 4-parallel decoders. Decoder #1 gets index 0, 1, 2. Decoder#2 gets byte 3 and 4. Decoder#3 gets byte 5, decoder #4 gets byte 6 and 7.See how that works? Just Kogge-Stone it up.
----------'
I assert that "f" itself can also be computed using Kogge Stone, but maybe splitting it up like this is easier? Or will I also have to prove "f" for yall to see it?
L1 $I cache is already read-only / Harvard architecture. There's only two states here: size == unknown, and size == known. This is a simple size = 0 (default), and size=X (where X is the known size of the instruction) situation.
x86 architecture states that if you write to those instructions, you need to flush L1 cache (ex: JIT Java) before the state is updated. L1 instructions are non-cohesive, so it isn't very hard. Upon the flush, set sizes back to 0 and you're done.
PDEP / PEXT are single-clock tick instructions and are far more complex than what I'm proposing here. As is AESRound.
I think you're underestimating the number of gates you can put in parallel and execute in a single stage of the pipeline. 64-bit PDEP / PEXT are more complicated than say... a 64-byte parallel adder in terms of depth. (PDEP / PEXT need both a butterfly circuit forward + inverse butterfly back + a decoder in parallel. 64-byte prefix sum is just one butterfly forward).
You look at instruction X+2, and "size cache" says "size 4", which allows you to look at instruction X+6 in parallel. Finally, you look at instruction X+10, and it says "size 8", which ends with +18 as where the instruction pointer ends.
This was sequentially described at first, but the parallel version is called Prefix Sum: https://en.wikipedia.org/wiki/Prefix_sum . This allows you to take a set of sums (like say 0, 2, 4, 8) and in parallel, figure out [2, 6, 10, 18], with 18 being the new location of the instruction pointer, and [0, 2, 6, 10] being the 4 instructions you process this clock tick.
A parallel adder across say, 32-bytes would be able to perform this prefix sum very quickly, probably within a clock tick. These sorts of parallel structures (aka: butterfly circuits) are extremely common in practice, your carry-lookahead adders need them, as well as PDEP / PEXT. Intel's single-cycle PDEP/PEXT is way more complicated than what I'm proposing here, I kid you not. (Seriously, the dude who decided to make single-clock cycle PDEP/PEXT or single-clock cycle AESRound would have spent more time than the size-cache that Intel is now using on instruction decoding)
The 80s was a time of research and experimentation, occasionally getting pretty wild. Intel had an «object-oriented» CPU, iAPX 432, which has slightly faster than immediately flopped. And they also had a hybrid RISC/VLIW design (i860) that could be outperform every other design out there – if the stars up in the sky would converge in the right space and time sequence, and the compiler could bundle instructions up efficiently.
Intel also had a very good i960 RISC design. Which was, in fact, so good that the boys with MBA over at Intel have got stumped not knowing what to do with it and chickened out (i960 was considered as a x86 replacement for a time and the future would look quite different from today).
Motorola was flirting with CPU's for a long while as well, but never took them seriously enough to see them through to the end as a serious business, for defence contracts and the field radio equipment (and later mobile phones) were their two major cash cows.
By the way, Motorola also had cool DSP designs with the true Harvard architecture with multiple data buses, and a single 3 operand instruction, e.g. «ADD A, B, C» could transfer A, B, C using three separate data buses – simultaneously. Data transfers were insanely fast.
INMOS got busy building transputers that could be «grown» infinitely (theoretically) into a gigantic computing «thing», and were programmed in Occam, with no assembly language even being available for the chip. They did not get anywhere.
The Japanese built the Smalltalk VM byte codes into a Katana processor, and were mulling over the idea of doing the same for Prolog. Prolog and AI started getting really big back then until both faded into obscurity for a couple of decades.
There was no shortage of great designs and ideas, but no-one had an idea of what the future of personal computing was going to be, therefore everyone was hedging varying bets. Digital had great hardware but they bet on minicomputers and snobbishly continued to ignore PC's until it was too late. They actually missed the server market boat as well as, by the time when they arrived, the bed had already become crowded with new lovers, and only the ones who had more money could win.
RISC vendors were riding the wave out with servers and workstations, until around the mid-aughts, when Intel finally ramped up the production of cheap and dirty Pentium 4 CPU's that could be used in a simple SMP set up, and Google / Facebook were quick to proceed with building out their own server farms filled with cheap and disposable commodity x86 blades. It quickly became too expensive for vertically integrated RISC vendors to keep their own CPU design teams on the payroll. One by one, the RISC vendors have all, too, gradually faded into obscurity.
One thing that absolutely sucked back them was that nearly no one could afford any of those amazing toys, unless it was a business with a fat budget. You could read, but you could not touch most of them. The documentation was gorgeous, though, and also prepared by professional technical writers in Adobe FrameMaker. Now, I can spin up a VM in a public cloud with a custom built TPU (or, NPU) within a few moments, use for as long as I have to, and I won't have to leave my own desk chair and it will be mine for as long as I can afford paying for it.
All of that has left one with pretty much one living CISC fossil and multiple off-shots of the load-and-store architecture, of which RISC is one.