Skip to content

Instantly share code, notes, and snippets.

View marcoheisig's full-sized avatar

Marco Heisig marcoheisig

  • FAU Erlangen-Nürnberg
  • Germany
View GitHub Profile
@marcoheisig
marcoheisig / ccl-sequence-benchmarks.lisp
Created December 28, 2018 18:04
Sequence benchmarks (on CCL)
;;; Benchmark results:
(SICL-SEQUENCE::FIND-AUX 1 SHORT-LIST NIL #'EQL NIL 0 NIL NIL) 77.93 nanoseconds
(FIND 1 SHORT-LIST) 46.56 nanoseconds
(SICL-SEQUENCE::FIND-AUX 1 LONG-LIST NIL #'EQL NIL 0 NIL NIL) 90.53 microseconds
(FIND 1 LONG-LIST) 29.86 microseconds
(SICL-SEQUENCE::FIND-AUX 1 SHORT-VECTOR NIL #'EQL NIL 0 NIL NIL) 6.55 microseconds
(FIND 1 SHORT-VECTOR) 42.00 nanoseconds
(SICL-SEQUENCE::FIND-AUX 1 LONG-VECTOR NIL #'EQL NIL 0 NIL NIL) 124.40 microseconds
(FIND 1 LONG-VECTOR) 91.50 microseconds
@marcoheisig
marcoheisig / avx.lisp
Created December 12, 2018 15:23
AVX2
(cl:defpackage #:avx2
(:use :cl)
(:export #:d4+ #:d4* #:d4ref #:d4set))
(cl:in-package #:avx2)
(sb-c:defknown (d4+ d4*) ((sb-ext:simd-pack-256 double-float)
(sb-ext:simd-pack-256 double-float))
(sb-ext:simd-pack-256 double-float)
(sb-c:movable sb-c:flushable sb-c:always-translatable)
@marcoheisig
marcoheisig / simd-sum.lisp
Last active December 16, 2019 12:05
A demo of my WIP SIMD library: https://github.com/marcoheisig/sb-simd
(defun simd-sum (array &aux (n (array-total-size array)))
"Compute the sum of the elements of the supplied simple double-float ARRAY."
(declare (type (simple-array double-float 1) array)
(optimize speed (safety 0)))
(do ((index 0 (the (integer 0 #.(- array-total-size-limit 16)) (+ index 16)))
(acc1 (make-f64.4 0 0 0 0) (f64.4+ acc1 (f64.4-row-major-aref array (+ index 0))))
(acc2 (make-f64.4 0 0 0 0) (f64.4+ acc2 (f64.4-row-major-aref array (+ index 4))))
(acc3 (make-f64.4 0 0 0 0) (f64.4+ acc3 (f64.4-row-major-aref array (+ index 8))))
(acc4 (make-f64.4 0 0 0 0) (f64.4+ acc4 (f64.4-row-major-aref array (+ index 12)))))
((>= index (- n 16))
@marcoheisig
marcoheisig / list-iterators.lisp
Created January 7, 2020 12:22
Iterators can be surprisingly fast (on SBCL, when they are inlined)
(in-package #:cl-user)
(defpackage #:list-iterators
(:use #:cl))
(in-package #:list-iterators)
(declaim (inline make-read-iterator))
(defun make-read-iterator (list terminate)
(lambda ()
@marcoheisig
marcoheisig / sicl-debugger-performance.lisp
Last active January 22, 2020 17:40
What ist the cost of having one (correctly predicted) branch at the beginning of a function?
(in-package :cl-user)
(defmacro debug-defun (name lambda-list &body body)
(multiple-value-bind (forms decls doc)
(alexandria:parse-body body :documentation t)
`(progn
(declaim (notinline ,name))
(defun ,name (.debug-flag. ,@lambda-list)
,@(when doc (list doc))
,@decls
@marcoheisig
marcoheisig / fast-method-keyword-handling.lisp
Created February 24, 2020 15:07
The inline lambda created for a call to a generic function with keyword arguments and calls to call-next-method with arguments.
(lambda
(#:x-1 &key ((:y #:y-2) nil #:suppliedp-3) ((:z #:z-4) nil #:suppliedp-5))
(declare (ignorable #:x-1 #:y-2 #:suppliedp-3 #:z-4 #:suppliedp-5))
(let ((sealable-metaobjects::.gf. #'keyword-function))
(declare (ignorable sealable-metaobjects::.gf.))
(declare (sb-ext:disable-package-locks call-method))
(declare (sb-ext:disable-package-locks make-method))
(declare (sb-ext:disable-package-locks sb-pcl::check-applicable-keywords))
@marcoheisig
marcoheisig / quickload-all.lisp
Created April 19, 2020 10:26
Load all of Quicklisp, except systems that fail to load or systems that get stuck loading for longer than 20 seconds.
(defun quickload-all ()
(loop for system in (ql:provided-systems t) do
(ignore-errors
(trivial-timeout:with-timeout (20)
(ql:quickload (ql-dist:short-description system))))))
@marcoheisig
marcoheisig / typed-cells.lisp
Last active June 20, 2020 06:34
A possible safe implementation of typed cells for SICL.
(defun make-function-cell (value)
(check-type value function)
(values
(lambda () value)
(lambda (new-value)
(check-type new-value function)
(setf value new-value))))
;; In order to make typed cells as fast as cons cells,
;; the compiler has to be able to inline the first value returned by
@marcoheisig
marcoheisig / init.el
Last active January 14, 2021 16:16
Use Clouseau as the default inspector in Emacs.
;;;; Note: You should also put something like (ql:quickload :clouseau) in your initialization file.
(defun clouseau-inspect (string)
(interactive
(list (slime-read-from-minibuffer
"Inspect value (evaluated): "
(slime-sexp-at-point))))
(let ((inspector 'cl-user::*clouseau-inspector*))
(slime-eval-async
`(cl:progn
@marcoheisig
marcoheisig / alist-from-plist.lisp
Created February 17, 2021 12:02
A functional implementation of plist to alist conversion.
(defun alist-from-plist (plist)
(trivia:match plist
((list) '())
((list* (and key (type symbol)) value rest)
(list* (cons key value) (alist-from-plist rest)))
(_ (error "Not a plist:~%~S~%" plist))))