This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;; 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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; 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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;; 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;; 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())] |