Skip to content

Instantly share code, notes, and snippets.

@mayerrobert
mayerrobert / mandel-arry.lisp
Last active January 27, 2024 07:36
Mandelbrot with terminal I/O
;;;; Mandelbrot with terminal I/O
;;;
;;; An attempt to write code that can be optimized by sbcl.
;;; Note that this is not a serious benchmark, most time is spent in I/O,
;;; it is mostly for looking at the resulting disassembly.
;;;
;;; from: https://demo.sourceprobe.com/github.com/sourceprobe/mandelbrot_lisp/mandel.lisp
(deftype window-dimension () `(integer 0 ,most-positive-fixnum))
@mayerrobert
mayerrobert / 1-issue.lisp
Last active April 26, 2023 04:17
SBCL 2.3.3 optimizer issue
;;; It seems that this file shows two issues with sbcl:
;;;
;;; (1) sbcl sometimes doesn't find optimization opportunities,
;;; it seems only SIMD code is affected.
;;; (2) Specifying ':fill-pointer nil' to 'make-array'
;;; seems to make a difference, i.e. specifying ':fill-pointer nil'
;;; (which doesn't make sense) considerably improves the generated code.
;;;
;;; Note how the hot loop starting at Windows:L10/ linux:L12 contains a lot of unneccessary
;;; "MOV [RBP-72], RCX" and "MOV RCX, [RBP-72]" instructions, or "MOV [RBP-48], RAX" twice in a row,
@mayerrobert
mayerrobert / mmult-simd.lisp
Last active July 22, 2023 21:40
Matrix multiplication optimization experiments with SB-SIMD
;;;; Matrix multiplication optimization experiments
;;;
;;; This file contains functions to multiply two matrices written in Common Lisp.
;;;
;;; DISCLAIMER: while this code has some tests it might contains bugs,
;;; I made it to experiment with SBCL's SIMD support.
;;;
;;; All functions use the naive nested loop algorithm which is O(n^3).
;;; This file contains 5 functions with various optimizations
;;; that should be portable Common Lisp and 5 functions that use sbcl's SB-SIMD.
@mayerrobert
mayerrobert / aoc2022-day10.lisp
Last active December 31, 2022 15:29
AOC 2022 day 10 in Common Lisp, code golf style
;;;; AOC 2022 day 10 in Common Lisp,
;;;; based on https://www.reddit.com/r/adventofcode/comments/zhjfo4/2022_day_10_solutions/izmspl7/
#| (mostly) original Python:
from itertools import accumulate
f = lambda x: int(x) if x[-1].isdigit() else 0
xs = [*map(f, open('day10.txt').read().split())]