Upgrade to Pro — share decks privately, control downloads, hide ads and more …

What have the architects ever done for us?

What have the architects ever done for us?

This is a lightning talk slide deck from a talk I gave at dotgo.eu 2015. I talked about building a functional simulator using go, and some of the challenges that brings, as a prop to talk about architecture evolution.

I had just 4 minutes on stage at the Theatre de Paris, in front of 600+ (well fed) gophers.

Matt Horsnell

November 09, 2015
Tweet

Other Decks in Programming

Transcript

  1. I'm not a software engineer
 ... but I write software

    daily
 
 I'm not a hardware engineer?
 ... I rarely write RTL
 
 I'm actually an architect
 ... defining the instruction set - HW/SW interface SOME CONTEXT 1
  2. ELF loader Memory CPU CPU CPU CACHES CACHES CACHES CPU

    DEVICES DEVICES DEVICES DEVICES CACHES I/O Terminal Entry Binary Command
 Line Args SIMULATION 3
  3. Read Instruction Decode Execute Write Reg/Mem Update PC Extract Fields

    Read Reg/Mem core piece of functional simulators speed is important, but ...
 so is readable, extendable code
 
 challenges:
 
 large frequently accessed decode table
 
 clean interface for the many instructions forms DECODE/EXECUTE LOOP 4
  4. ANONYMOUS FUNCTIONS AND CLOSURES go makes handling functions trivial
 -

    integral to my decode/execute loop use closures to provide a clean/uniform interface
 
 hide all of the differences within surrounding function one interface for executing any instruction form Closure Anonymous Function Anonymous Function Closure ADD EOR 5
  5. BASIC BLOCKS simple interfaces make complex algorithms simple
 
 programs

    are mostly linear
 - until we hit a {br, jmp, ret}
 - linear chunks a.k.a "basic blocks"
 
 surprised by performance from a "clean" implementation
 - 25-50x slowdown over native // Execute a basic block
 for _, v := range bb {
 v.Executor(c)
 } 0x00400de8 .... ldr w4, [x2] #4
 0x00400dec .... movz w3, #0xa121
 0x00400df0 .... add w1, w1, #0x1
 0x00400df4 .... movk w3, #0x7, lsl #16
 0x00400df8 .... eor w4, w1, w4
 0x00400dfc .... cmp w1, w3
 0x00400e00 .... eor w19, w19, w4
 0x00400e04 .... b.ne 400de8 <main+0x150> 6
  6. SIMULATING SIMD SIMD (e.g. AVX/NEON) allow a single instruction to

    operate on multiple elements of wide registers
 
 
 used in go runtime & stdlib for performance
 
 
 simulating them feels ugly
 - need reflect & unsafe func Get8bSlice(v []uint64) []uint8 {
 length := len(v) * 8
 b := *(*[]uint8)(unsafe.Pointer(&v))
 (*reflect.SliceHeader)(unsafe.Pointer(&b)).Cap = length
 (*reflect.SliceHeader)(unsafe.Pointer(&b)).Len = length
 return b
 } 0 127 V0 V0.2D V0.4S V0.8H V0.16B 7
  7. FINALLY compile & runtime performance stdlib, tools & dep-free binaries

    grokkable code, months later super helpful/inclusive community @maver
 [email protected] Gopher wrench image - credit Renee French Software Hardware Architecture 8