Email or username:

Password:

Forgot your password?
Top-level
Ken Shirriff

Shifting is useful in programming, sliding bits to the left or right with the "<<" or ">>" operators. But it takes a lot of hardware to do this efficiently. Older x86 processors could only shift one position at a time, looping to shift multiple positions. The 386 fixed this. 2/11

10 comments
Ken Shirriff

A barrel shifter uses a matrix of switches to select where each input bit ends up, as this Wikipedia diagram shows. Each diagonal control line selects a particular shift amount. But for a 32-bit processor, the matrix becomes very large. 3/11

Ken Shirriff

The 386 uses a hybrid approach: a smaller matrix shifts, but only by a multiple of 4 bits. A second circuit applies a shift of 0 to 3 bits. In combination, the circuits shift by an arbitrary amount. This approach saves circuitry. 4/11

Ken Shirriff

Here's how the 386's barrel shifter looks on the die. Two values enter at the bottom from the registers and are latched. The shift matrix is in the middle with diagonal control lines selecting the shift. Above, a circuit shifts by 0 to 3 positions, producing the output. 5/11

Ken Shirriff

At each position in the matrix, a transistor is the switch between an input line and an output line. This photo shows eight of the tiny transistors. 6/11

Ken Shirriff

This photo shows part of the shift matrix with the sloping polysilicon control lines (green) and transistors (dark boxes). The diagram shows how three of the control lines are wired. 7/11

Ken Shirriff

This circuit shifts from 0 to 3 bits. It passes the input bit straight through or sends it two positions to the right. Next, it passes that bit straight through or passes it one position to the right. Thus each bit is shifted right 0 to 3 positions. 8/11

Ken Shirriff

At the input to the shifter, latch circuits hold the two input words from the register file. The circuit can also swap the two values. The photos show the circuit on the die. Left shows the metal layers; right shows the underlying silicon with the transistors. 9/11

Ken Shirriff

There are complications, of course. The matrix outputs 37 bits, not 32, for reasons. Supporting bytes and 16-bit shifts needs more circuitry as does rotating through the carry. For more on the 386's barrel shifter, see my blog post: righto.com/2023/12/386-barrel- 10/11

Joshua Barretto

@kenshirriff I love this. Such a simple solution, but somehow still very pleasing.

Go Up