Simplified: a CPU is just a bunch of states instructions that modify those states external stuff
Mittwoch, 10. Oktober 12
This is beautifully implemented as functions inside a State Monad: type MicrocodeMonad = State (Regs Word32)
add :: Reg -> Word32 -> Microcode ()
add reg i = do v <- readreg reg writereg reg (v + i)
cmpxchg :: Reg -> Word32 -> Microcode ()
cmpxchg r1 r2 = do eax <- readreg EAX v1 <- readreg r1 v2 <- readreg r2 if eax == v1 then writereg r1 v2 else writereg' EAX v1 Mittwoch, 10. Oktober 12 Just for fun, we want to parallelize the CPU add eax, ecx add ebx, 2 add eax, ecx add ebx, 2 add eax, 2 add eax, 2 add ebx, ecx add ebx, ecx add eax, 2 add ebx, ecx add eax, 2 add ebx, ecx add eax, ebx
add eax, ebx
We need to find out which registers an instruction affects
But isnt all that information in the Microcode already?
Mittwoch, 10. Oktober 12
Generalized Combination An instruction consists of different parts (readreg, writereg, ...), combined to bigger parts Combine register access maps (boolean fields which are ored) of these parts But (>>=) does not combine parts: (>>=) :: m a -> (a -> m b) -> m b
We rather need: ? :: f a b -> f b c -> f a c
Mittwoch, 10. Oktober 12
Its not a Monad, its an Arrow! data Microcode a b = Microcode { ins :: Regs Bool, outs :: Regs Bool, code :: (a, Regs Word32) -> (b, Regs Word32) } instance Arrow Microcode where ...