110 likes | 239 Views
Question. Consider the following MIPS interrupt_handler .ktext 0x80000080 interrupt_handler: addi $sp, $sp, -8 sw $t0, 0($sp) # save $t0 sw $t1, 4($sp) # save $t1 ... lw $t0, 0($sp) # restore $t0
E N D
Question • Consider the following MIPS interrupt_handler .ktext 0x80000080 interrupt_handler: addi $sp, $sp, -8 sw $t0, 0($sp) # save $t0 sw $t1, 4($sp) # save $t1 ... lw $t0, 0($sp) # restore $t0 lw $t1, 4($sp) # restore $t1 addi $sp, $sp, 8 ... Why don’t we use the stack to save and restore registers? Answer: Because the stack may be corrupted, e.g. $sp may not be correctly set
ISA Proc #1 Proc #2 Software Instruction Set Architecture (ISA) • The ISA is the interface between hardware and software. • The ISA serves as an abstraction layer between the HW and SW • Software doesn’t need to know how the processor is implemented • Any processor that implements the ISA appears equivalent • An ISA enables processor innovation without changing software • This is how Intel has made billions of dollars. • Before ISAs, software was re-written/re-compiled for each new machine.
A little ISA history • 1964: IBM System/360, the first computer family • IBM wanted to sell a range of machines that ran the same software • 1960’s, 1970’s: Complex Instruction Set Computer (CISC) era • Much assembly programming, compiler technology immature • Simple machine implementations • Complex instructions simplified programming, little impact on design • 1980’s: Reduced Instruction Set Computer (RISC) era • Most programming in high-level languages, mature compilers • Aggressive machine implementations • Simpler, cleaner ISA’s facilitated pipelining, high clock frequencies • 1990’s: Post-RISC era • ISA complexity largely relegated to non-issue • CISC and RISC chips use same techniques (pipelining, superscalar, ..) • ISA compatibility outweighs any RISC advantage in general purpose • Embedded processors prefer RISC for lower power, cost • 2000’s: ??? EPIC? Dynamic Translation? Just more x86?
Comparing x86 and MIPS • Much more is similar than different. • Both use registers and have byte-addressable memories • Same basic types of instructions (arithmetic, branches, memory) • A few of the differences • Fewer registers: 8 (vs. 32 for MIPS) • 2-register instruction formats (vs. 3-register format for MIPS) • Greater reliance on the stack, which is part of the architecture • Additional, complex addressing modes • Variable-length instruction encoding (vs. fixed 32-bit length for MIPS)
%eax %edx %ecx %ebx %esi %edi %esp %ebp x86 Registers • Few, and special purpose • 8 integer registers • two used only for stack • not all instructions can use all registers • Little room for temporary values • x86 uses “two-address code” • op x, y # y = y op x • Rarely can the compiler fit everything in registers • Stack is used much more heavily, so it is architected (not just a convention) • The esp register is the stack pointer • Explicit push and pop instructions
Memory Operands • Most instructions can include a memory operand addl -8(%ebp), %eax # equivalent MIPS code: # lw $t0, -8($ebp) # add $eax, $eax, $t0 • MIPS supports just one addressing mode: offset($reg) refers to Mem[$reg + offset] • X86 supports complex addressing modes: offset(%rb,%ri,scale) refers to Mem[%rb + %ri*scale + offset]
Address Computation Examples %edx 0xf000 %ecx 0x100
Variable Length Instructions 08048344 <sum>: 8048344: 55 push %ebp 8048345: 89 e5 mov %esp,%ebp 8048347: 8b 4d 08 mov 0x8(%ebp),%ecx 804834a: ba 01 00 00 00 mov $0x1,%edx • Instructions range in size from 1 to 17 bytes • Commonly used instructions are short (think compression) • In general, x86 has smaller code than MIPS • Many different instruction formats, plus pre-fixes, post-fixes • Harder to decode for the machine • Typical exam question: How does _____________ depend on the complexity of the ISA?
Why did Intel win? x86 won because it was the first 16-bit chip by two years. • IBM put it in PCs because there was no competing choice • Rest is inertia and “financial feedback” • x86 is most difficult ISA to implement for high performance, but • Because Intel sells the most processors ... • It has the most money ... • Which it uses to hire more and better engineers ... • Which is uses to maintain competitive performance ... • And given equal performance, compatibility wins ... • So Intel sells the most processors.
The SPIMbot Design Process Key Idea: Iterative Refinement • Build simplest possible implementation • Does it meet criteria? If so, stop. Else, what can be improved? • Generate ideas on how to improve it • Select best ideas, based on benefit/cost • Modify implementation based on best ideas • Goto step 2. It is very tempting to go straight to an “optimized” solution. Pitfalls: • You never get anything working • Incomplete problem knowledge leads to selection of wrong optimizations With iterative refinement, you can stop at any time! Result is optimal for time invested. Understand Requirements Implement Evaluate/ Analyze Prioritize/ Select Brainstorm
The basic bot: MP 3 • Playing field divided into 400 “sectors”, tokens placed at random [Part 2(b)] Issue a scan request to sector (p, q) and set scanning • While scanning is set, loop • When scanning gets cleared, scan next sector [Part 2(c)] When a scan-interrupt occurs, process scan result • Processing as in MP 2 • If tokens found, set a timer-interrupt, otherwise clearscanning [Part 2(d)] When a timer-interrupt occurs, drive to pick up tokens • When finished, clear scanning doScans empty scan scanning = 0 issue scan scanning = 1 scan interrupt tokens found set timer int. timer interrupt: pick up tokens picked all tokens scanning = 0