Title: ECE1724F Presentation
1ECE1724F Presentation
- C A Language for High-Level, Efficient, and
Machine-Independent Dynamic Code Generation
Dawson R. Engler, Wilson C. Hsieh and M. Frans
Kaashoek
Madhusudan Raman
October 23, 2002
2Outline
- Motivation - Why?
- Objectives - What?
- Methodology - How?
- Performance - How much?
- Future Work - Now what?
- Conclusions - So what?
3Motivation Why?
- Tradeoffs
- Portability
- Ease of Programming
- Efficiency
- Tackle all three - How?
- Build on ANSI C
- Add-on to highly evolved language
4Objectives What?
- Portable, Easy
- Extend on ANSI C
- Strict superset
- Flexible specification of dynamic code
- Unknown parameters of functions
- Efficiency
- Shift most costs to compile time
- Static typing
5Methodology How?
- 'C Language
- Constructs
- Similar to Function Pointers
- Unary operators
- Standard library
- Type Specifications
- Runtime Constructed Function Calls
6The Operator
- Specify dynamically generated code
- No nesting
- Lexical Scoping
- "Capture" static variables
- Type-checking at compile time
- Cannot transfer control outside backquote
7Cspec Types
- Type of a dynamic code specification
- Evaluation type - dynamic value of code
- Compile returns a void function pointer
- Cast into appropriate type
8vspec Types
- Variable Specification
- Dynamically generated lvalue
- Evaluation type - type of lvalue
- Statically type lvalue
- Instruction selection at compile time
9vspec Types
- Initialization
- Param - used to create parameter for function
- Local - Reserve space, allocate register
- Void - generic vspec type
- Incorporated vspec
- Used as a variable
- both lvalue, rvalue
- Functions taking runtime-determined arguments
10Other Operators
- The _at_ Operator
- Combination of dynamic code specifications
- "dereferences" cspecs and vspecs
- returns evaluation type of operand
- The Operator
- Incorporate Runtime Constants
- Evaluates operand at specification time
11Example 1Runtime Constants
- Hardcode relatively constant values
- Generic hash function
- Table size, scatter, normalize - computed at
runtime - Function specialized for hte, scatter, norm
12hptr mk_hash(struct ht ht) int vspec val
param(0, TC_I) void cspec hc hc struct
hte hte hte (ht-gthte)(_at_valht-gtscatter)/ht
-gtnorm while(hte hte-gtval ! _at_val) hte
hte-gtnext return hte return (hptr)
compile(hc, TC_P)
13Example 2Matrix Dot Product
- Runtime Characteristics
- Large numbers of zeroes
- Small integers
- Code for each row used n times
- Easy to recoup dynamic code generation costs
- Encode row values as immediates
- Function eliminating multiplication by zero
14void cspec mkdot(int row, int n) int k, cspec
sum, vspec col col (int vspec) param(0,
TC_P) sum '0 for(k0kltnk) if(rowk
sum '(_at_sum (_at_col)k rowk) re
turn 'return _at_sum
15Performance How Much?
- 'C Compiler
- Prototype, so non-optimal
- Sparc 10
- Integer divide and multiply in software
16Matrix Scaling
- Multiplication, Division Reduce to Adds and
Shifts - Constant Loop Bounds Encode at runtime
17Matrix Scaling Performance
- 1024 X 1024 Matrix
- Scaled Up by integers 1, 2.. 1024
18Compiling Interpreter
- Compile, then execute freq. code
- TinyC - recursive-descent compiling interpreter
- Test Candidates
- C
- gcc-O2
- Tree-Interpreter
- Translate TinyC into abstract syntax trees
- Recursively Evaluate
19Compiling Interpreter Performance
- 30th Fibonacci number computed
- C slower than gcc
- Within 10 of hand-optimized
- Much faster than Tree-Interpreter
20Future Work Now What?
- Scope for improvement
- Language Extensions
- C Compiler Improvements
21Language Extensions
- Partial signatures
- Prevent code explosions
- Specify permutations of args
- Generate multiple functions simultaneously
- Full generality???
- Parameterize Code Fragments
- Nameless functions
- Increased modularity
22Compiler extensions
- Excuse for low performance now?
- Optimizations
- Instruction scheduling
- Peephole Optimizations
- Templates and vcode?????
- Improvement of one order magnitude expected
23Conclusions So What?
- Achieved
- Somewhat increased efficiency
- Portability
- Need better compiler
- Not easy to use
- Successful overall