Top Banner
FRANZ INC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007
31

F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

Jan 12, 2016

Download

Documents

Cathleen Barker
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

FRANZ INC.

Optimizing and Debugging Programs in Allegro CL

By Duane Rettig

April, 2007

Page 2: F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

FRANZ INC.

Introduction

• Personal• Tutorial will become available via ftp• Some things available only in 8.1• Some concepts are from LUGM/1998

Page 3: F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

FRANZ INC.

Outline

• Debug• Low Level Hacks• Optimization

Page 4: F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

FRANZ INC.

Debug

• Zoom Niceties– [ run zoom.lisp]

• gdb/dbx/windbg interface– [ show manual demos]

Page 5: F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

FRANZ INC.

Low Level Hacks

• Intro: Structure of Allegro CL• “ll” functions• Lap code

Page 6: F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

FRANZ INC.

Structure of Allegro CLsrc/

c/*.crs/*.clcode/*.cl

compilecompile

asm*.s *.o*.fasl

cc

Page 7: F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

FRANZ INC.

Structure (cont)*.o

*.so ld

*.fasl

libacl*.so

lisp

lisp

(dumplisp)

running lisp

*.dxl

Page 8: F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

FRANZ INC.

Example rs code(def-runtime-q new-ratio (num den)

(let ((rat (q-allocate-heap-other #md-ratio-type-code

#md-ratio-size)))

(setf (ls md-ratio num rat) num)

(setf (ls md-ratio den rat) den)

rat))

Page 9: F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

FRANZ INC.

Example lisp ll code• [run “both-fixnum-p.lisp”]

Page 10: F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

FRANZ INC.

“ll” functions• [see ll-doc.html]

Page 11: F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

FRANZ INC.

Another ll example

• Some compiler-macros expand to ll funcs– [run char-code.lisp]

Page 12: F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

FRANZ INC.

Lap code

• comp::*hack-compiler-output*– [run hack-compiler-output.lisp]

• comp::*assemble-function-body*– [run assemble-function-body.lisp]

Page 13: F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

FRANZ INC.

Optimization

• Compilation• Boxing and unboxing• Read-line• Foreign types• Memcpy• String manipulation• Aligned pointers• Hashing• Runtime Analyzer

Page 14: F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

FRANZ INC.

Optimization Methodology

• Get it right first• Profile it

– The time macro– The Allegro CL Runtime Analyzer

• Hit the high cost items– Implementations– Algorithms

Page 15: F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

FRANZ INC.

Compilation

• Adding declarations to code• (declare (:explain :types :inlining))

– [run inlining-demos.lisp]

Page 16: F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

FRANZ INC.

Boxing and Unboxing

• Ensuring optimal unboxability– [run unboxing.lisp]

• Immediate args– [see immediate-args.html]

Page 17: F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

FRANZ INC.

read-line

• What's wrong with it?

Page 18: F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

FRANZ INC.

read-line

• It always conses!• What to do?

– read-line-into• Never conses• Must deal with overflowing lines

– simple-stream-read-line• Two modes

– implementation for read-line– similar to read-line, handling overflows

• [see read-line-test.html]

Page 19: F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

FRANZ INC.

memcpy

• memcpy-up• memcpy-down• [see memcpy-demo.html]

Page 20: F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

FRANZ INC.

String Manipulation

• string+ and the standard, with concatenate• [see string+.cl]

Page 21: F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

FRANZ INC.

Aligned Pointers

• Allow cons-free pointer manipulation• Pointers look like fixnums• Pointers must be aligned to:

– 32-bit: 4-byte boundaries– 64-bit: 8-byte boundaries

• [see “aligned.html”]

Page 22: F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

FRANZ INC.

Aligned Pointers (cont)

most-positive-fixnum

most-negative-fixnum

for 32-bit: signed fixnumunsigned

0

#x7ffffffc

#x80000000

0

#xfffffffc -1 (fix)

Page 23: F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

FRANZ INC.

Foreign types• (sorry, under construction):• Foreign-types aren't just for foreign-functions• We can combine disciplines

– [run mapped-aligned-ftype.lisp]

Page 24: F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

FRANZ INC.

Hashing

• :test extensions• :values [t] (may be nil or :weak)• :weak-keys [nil] (may be non-nil)• :hash-function [nil] (or fboundp symbol)

– must return• 24 bit value for 32-bit lisps• 32 bit value for 64-bit lisps

Page 25: F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

FRANZ INC.

Hashing

• Rehash-issues• excl::*default-rehash-size*• excl::*allocate-large-hash-table-vectors-in-old-space*• excl::convert-to-internal-fspec

– example of weak-key, sans-value hash-table• [run shared-cons-table.lisp]

Page 26: F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

FRANZ INC.

Hashing

• Hash tables are very efficient if hash codes are well-distributed

• excl::hash-table-stats– [run hash-table-stats.lisp]

Page 27: F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

FRANZ INC.

Runtime Analyzer

• (explain the name)• Always compile top-level test functions• Do not use time macro with profiler• Avoid simultaneous time/call-count profiles• When using time macro, beware of new

closures• Use prof:disassemble-profile

Page 28: F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

FRANZ INC.

•Time macro: extra closures

• This driver is not as simple as it looks!

(defun test-driver (n)

(time

(dotimes (i n)

(test-it)))

Page 29: F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

FRANZ INC.

•Time macro: avoiding extra closures

• Use this instead:

(defun test-driver (n)

(dotimes (i n)

(test-it))

(time (test-driver 1000000))

Page 30: F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

FRANZ INC.

disassemble-profile

• Provides sample hit counts and percentages• Multiple disassembles provide info similar to

call-graph• [show manual demo]

Page 31: F RANZ I NC. Optimizing and Debugging Programs in Allegro CL By Duane Rettig April, 2007.

FRANZ INC.

Thank You.