luv

Workshop wiki

z-fiber-benchmark.lisp

luft/z-fiber-benchmark.lisp

system luft/z-fiber-benchmark · 78 definitions · on GitHub

CPU experiments for full-height luft occupancy fibers.

defpackage#:luft.z-fiber-benchmark
:use#:cl
:export#:available-kernel-families#:run-z-fiber-benchmark
in-package#:luft.z-fiber-benchmark
defconstant+fiber-words+4
defconstant+direction-count+6
defconstant+plus-x+0
defconstant+minus-x+1
defconstant+plus-y+2
defconstant+minus-y+3
defconstant+plus-z+4
defconstant+minus-z+5
defconstant+u64-mask+#xffffffffffffffff
defconstant+low-63-mask+#x7fffffffffffffff
defconstant+low-62-mask+#x3fffffffffffffff
defstruct
air-workspace
:constructor%make-air-workspace
reachable-areachable-bcell-queuerun-offsetsrun-startsrun-endsrun-ownersrun-reachedrun-queue
reachable-areachable-bcell-queuerun-offsetsrun-startsrun-endsrun-ownersrun-reachedrun-queue
deftypeu64-vector
'
simple-array
unsigned-byte64
defstruct
fiber-case
:constructor%make-fiber-case
widthpatternstrideoccupancysolid-counttotal-runsmaximum-runsoutputair-workspace
width0:typefixnum:read-onlyt
pattern:terrain:typekeyword:read-onlyt
stride0:typefixnum:read-onlyt
occupancy
:typeu64-vector:read-onlyt
solid-count0:typefixnum
total-runs0:typefixnum:read-onlyt
maximum-runs0:typefixnum:read-onlyt
output
:typeu64-vector:read-onlyt
air-workspacenil:typeair-workspace
defstruct
atmosphere-edit-case
:constructor%make-atmosphere-edit-case
casexyzair-run
casenil:typefiber-case:read-onlyt
x0:typefixnum:read-onlyt
y0:typefixnum:read-onlyt
z0:typefixnum:read-onlyt
air-run0:typefixnum:read-onlyt
defstructfiber-sample
width0:typefixnum
pattern:terrain:typekeyword
phase:surface-scalar:typekeyword
simd-family:scalar:typekeyword
index0:typefixnum
iterations1:typefixnum
fiber-count0:typefixnum
solid-count0:typefixnum
run-count0:typefixnum
air-run-count0:typefixnum
face-count0:typefixnum
elapsed-seconds0d0:typedouble-float
bytes-consed0:typeinteger
gc-seconds0d0:typedouble-float
garbage-collections0:typefixnum
defuninput-base
stridelocal-xlocal-y
declare
typefixnumstridelocal-xlocal-y
optimize
speed3
safety0
*+fiber-words+
+local-x
*local-ystride
defunoutput-base
declare
typefixnumwidthxy
optimize
speed3
safety0
defunoccupancy-word
occupancybasez
declare
typefixnumbasez
optimize
speed3
safety0
arefoccupancy
+base
ashz-6
defunsolid-bit-p
occupancybasez
declare
typefixnumbasez
optimize
speed3
safety0
and
<=0z
logbitp
logandz63
occupancy-wordoccupancybasez
defunterrain-height
xy
max8
min230
round
+112d0
*31d0
sin
/
+x
*0.31d0y
17d0
*19d0
cos
/
-y
*0.23d0x
29d0
defunarchitecture-solid-p
xyz
let
floor-z
*16
or
<z4
=zfloor-z
and
<
modx12
2
<z
+floor-z12
and
<
mody14
2
<z
+floor-z9
and
<
mod
+xy
31
2
<=32z191
defuncave-solid-p
xyz
and
or
<z8
>
+
sin
/x5d0
cos
/y7d0
sin
/z4d0
-0.35d0
defunpattern-solid-p
patternxyz
ecasepattern
:solidt
:terrain
:architecture
:caves
:checkerboard
evenp
+xyz
defunmake-fiber-occupancy
widthpattern
let*
stride
occupancy
make-array
*stridestride+fiber-words+
:element-type'
unsigned-byte64
:initial-element0
origin-x128
origin-y128
solid-count0
dotimes
local-ystride
dotimes
local-xstride
let
base
input-basestridelocal-xlocal-y
x
+origin-x
1-local-x
y
+origin-y
1-local-y
dotimes
let
bits0
dotimes
bit64
let
z
+bit
*64word
when
setfbits
logiorbits
ash1bit
when
and
<=1local-xwidth
<=1local-ywidth
incfsolid-count
setf
arefoccupancy
+baseword
bits
valuesoccupancystridesolid-count
defunfiber-run-count-scan
occupancybase
declare
typefixnumbase
optimize
speed3
safety0
let
runs1
previous
if
solid-bit-poccupancybase0
10
declare
typefixnumrunsprevious
loopforzfixnumfrom1belowluft:+top-z+forbitfixnum=
if
solid-bit-poccupancybasez
10
unless
=bitprevious
do
incfruns
setfpreviousbit
runs
defunfiber-run-count-bits
occupancybase
declare
typefixnumbase
optimize
speed3
safety0
let
transitions0
declare
typefixnumtransitions
dotimes
let*
bits
arefoccupancy
+baseword
internal-mask
incftransitions
logcount
logandinternal-mask
logxorbits
ashbits-1
when
<word3
unless
=
ldb
byte163
bits
ldb
byte10
arefoccupancy
+baseword1
incftransitions
1+transitions
defunoccupancy-run-statistics
occupancystridewidth
let
total0
maximum0
declare
typefixnumtotalmaximum
dotimes
dotimes
let
runs
fiber-run-count-bitsoccupancy
input-basestride
1+x
1+y
incftotalruns
setfmaximum
maxmaximumruns
valuestotalmaximum
defunmake-air-workspace
occupancystride

Index every maximal empty Z interval in every haloed fiber.

let*
fiber-count
*stridestride
run-offsets
make-array
1+fiber-count
:element-type'fixnum
starts
make-array64:element-type'
unsigned-byte8
:adjustablet:fill-pointer0
ends
make-array64:element-type'
unsigned-byte8
:adjustablet:fill-pointer0
owners
make-array64:element-type'fixnum:adjustablet:fill-pointer0
dotimes
fiberfiber-count
setf
arefrun-offsetsfiber
lengthstarts
let
z0
loopwhiledo
if
solid-bit-poccupancybasez
incfz
let
startz
loopwhiledo
incfz
vector-push-extendstartstarts
vector-push-extend
1-z
ends
vector-push-extendfiberowners
setf
arefrun-offsetsfiber-count
lengthstarts
let
run-count
lengthstarts
%make-air-workspace
make-array
lengthoccupancy
:element-type'
unsigned-byte64
:initial-element0
make-array
lengthoccupancy
:element-type'
unsigned-byte64
:initial-element0
make-array
*fiber-countluft:+top-z+
:element-type'fixnum
run-offsets
coercestarts'
simple-array
unsigned-byte8
coerceends'
simple-array
unsigned-byte8
coerceowners'
simple-arrayfixnum
make-arrayrun-count:element-type'bit:initial-element0
make-arrayrun-count:element-type'fixnum
defunmake-fiber-case
widthpattern
check-typewidth
integer1256
unless
memberpattern'
:solid:terrain:architecture:caves:checkerboard
error"Unknown Z-fiber benchmark pattern ~S."pattern
multiple-value-bind
occupancystridesolid-count
multiple-value-bind
total-runsmaximum-runs
%make-fiber-casewidthpatternstrideoccupancysolid-counttotal-runsmaximum-runs
make-array:element-type'
unsigned-byte64
:initial-element0
make-air-workspaceoccupancystride
defunwrite-vertical-masks
occupancyinput-baseoutputoutput-base
declare
typeu64-vectoroccupancyoutput
optimize
speed3
safety0
dotimes
let*
solid
arefoccupancy
previous
if
pluspword
arefoccupancy
0
next
if
arefoccupancy
0
above
logior
ashsolid-1
ash
logandnext1
63
below
logand+u64-mask+
logior
ashsolid1
ldb
byte163
previous
setf
logandsolid
lognotabove
logandsolid
lognotbelow
output
defunsurface-masks-scalar
case
let
width
fiber-case-widthcase
stride
fiber-case-stridecase
occupancy
fiber-case-occupancycase
output
fiber-case-outputcase
declare
typefixnumwidthstride
typeu64-vectoroccupancyoutput
optimize
speed3
safety0
dotimes
dotimes
let*
declare
typefixnuminput-baseoutput-baserightleftfrontback
dotimes
let
solid
arefoccupancy
setf
logandsolid
lognot
arefoccupancy
+rightword
logandsolid
lognot
arefoccupancy
+leftword
logandsolid
lognot
arefoccupancy
+frontword
logandsolid
lognot
arefoccupancy
+backword
output
defmacrodefine-simd-surface-kernel
namepackagelanes
flet
sym
name
internnamepackage
let
aref-wide
sym
formatnil"U64.~D-AREF"lanes
and-wide
sym
formatnil"U64.~D-AND"lanes
not-wide
sym
formatnil"U64.~D-NOT"lanes
`
defun,name
case
let
width
fiber-case-widthcase
stride
fiber-case-stridecase
occupancy
fiber-case-occupancycase
output
fiber-case-outputcase
declare
typefixnumwidthstride
typeu64-vectoroccupancyoutput
optimize
speed3
safety0
dotimes
dotimes
let*
declare
typefixnuminput-baseoutput-baserightleftfrontback
loopforwordfixnumfrom0below+fiber-words+by,lanesforsolid=
,aref-wideoccupancy
do
setf
,and-widesolid
,not-wide
,aref-wideoccupancy
+rightword
,and-widesolid
,not-wide
,aref-wideoccupancy
+leftword
,and-widesolid
,not-wide
,aref-wideoccupancy
+frontword
,and-widesolid
,not-wide
,aref-wideoccupancy
+backword
output
#+x86-64
define-simd-surface-kernelsurface-masks-avx2#:sb-simd-avx24
#+x86-64
define-simd-surface-kernelsurface-masks-sse2#:sb-simd-sse22
#+arm64 (define-simd-surface-kernel surface-masks-neon #:sb-simd-neon 2)
defuninstruction-set-available-p
name
sb-simd-internals:instruction-set-available-p
sb-simd-internals:find-instruction-setname
defunavailable-kernel-families

Return the runnable Z-fiber kernels, fastest first.

append#+x86-64#+x86-64#+arm64(and (instruction-set-available-p :neon) '(:neon))'
:scalar
defunfastest-simd-family
find-if
lambda
family
not
eqfamily:scalar
defunsurface-kernel
family
ecasefamily#+x86-64
:avx2#'surface-masks-avx2
#+x86-64
:sse2#'surface-masks-sse2
#+arm64(:neon #'surface-masks-neon)
declaim
defunset-output-bit
outputbasedirectionz
declare
typefixnumbasedirectionz
optimize
speed3
safety0
let
index
+base
ashz-6
setf
arefoutputindex
logior
arefoutputindex
ash1
logandz63
defunsurface-masks-cell-scan
case

Slow per-cell oracle for the bit-fiber surface masks.

let
width
fiber-case-widthcase
stride
fiber-case-stridecase
occupancy
fiber-case-occupancycase
output
fiber-case-outputcase
declare
typefixnumwidthstride
typeu64-vectoroccupancyoutput
optimize
speed3
safety0
filloutput0
output

Camera-connected air is a different question from the complete boundary. The complete boundary includes sealed caves. These kernels seed the air containing a camera above the center fiber, discover only that component, and then write the solid faces incident to it. AIR-CELL is the obvious oracle, AIR-BITS propagates directly through the four-word fibers, and AIR-RUNS traverses maximal empty Z intervals joined by horizontal overlap.

defunreachable-bit-p
reachablefiberz
declare
typefixnumfiberz
optimize
speed3
safety0
logbitp
logandz63
arefreachable
+
ashz-6
defunmark-reachable-bit
reachablefiberz
declare
typefixnumfiberz
optimize
speed3
safety0
let
index
+
ashz-6
setf
arefreachableindex
logior
arefreachableindex
ash1
logandz63
defuncamera-air-seed
case

Return the center fiber's top air cell, or NIL when the camera is obstructed.

let*
stride
fiber-case-stridecase
center
floorstride2
fiber
+center
*centerstride
if
solid-bit-p
fiber-case-occupancycase
basez
valuesnilnil
valuesfiberz
defunwrite-reachable-range
reachablefiberlowhigh
declare
typefixnumfiberlowhigh
optimize
speed3
safety0
let
first-word
ashlow-6
last-word
ashhigh-6
loopforwordfixnumfromfirst-wordtolast-wordforword-lowfixnum=
*word64
forlocal-lowfixnum=
max0
-lowword-low
forlocal-highfixnum=
min63
-highword-low
formask=
logand+u64-mask+
-
ash1
1+local-high
ash1local-low
do
setf
arefreachable
+baseword
logior
arefreachable
+baseword
mask
reachable
defunwrite-camera-boundary
casereachable

Write solid faces incident to reachable air into case's output buffer.

let
width
fiber-case-widthcase
stride
fiber-case-stridecase
occupancy
fiber-case-occupancycase
output
fiber-case-outputcase
declare
typefixnumwidthstride
typeu64-vectoroccupancyreachableoutput
optimize
speed3
safety0
dotimes
dotimes
let*
declare
typefixnuminput-baseoutput-baserightleftfrontback
dotimes
let*
solid
arefoccupancy
air
arefreachable
previous
if
pluspword
arefreachable
0
next
if
arefreachable
0
air-above
logior
ashair-1
ash
logandnext1
63
air-below
logand+u64-mask+
logior
ashair1
ldb
byte163
previous
setf
logandsolid
arefreachable
+rightword
logandsolid
arefreachable
+leftword
logandsolid
arefreachable
+frontword
logandsolid
arefreachable
+backword
logandsolidair-above
logandsolidair-below
output
defunwrite-camera-boundary-cell-scan
casereachable

Slow, direct oracle for the packed camera-boundary writer.

let
width
fiber-case-widthcase
stride
fiber-case-stridecase
occupancy
fiber-case-occupancycase
output
fiber-case-outputcase
declare
typefixnumwidthstride
typeu64-vectoroccupancyreachableoutput
optimize
speed3
safety0
filloutput0
dotimes
dotimes
output
defuncamera-boundary-cell-flood
case

Reference breadth-first search over individual empty cells.

let*
stride
fiber-case-stridecase
fiber-count
*stridestride
occupancy
fiber-case-occupancycase
workspace
fiber-case-air-workspacecase
reachable
air-workspace-reachable-aworkspace
queue
air-workspace-cell-queueworkspace
head0
tail0
declare
typefixnumstridefiber-countheadtail
typeu64-vectoroccupancyreachable
type
simple-arrayfixnum
queue
optimize
speed3
safety0
fillreachable0
labels
visit
fiberz
declare
typefixnumfiberz
when
and
<=0fiber
<fiberfiber-count
<=0z
not
reachable-bit-preachablefiberz
mark-reachable-bitreachablefiberz
setf
arefqueuetail
incftail
multiple-value-bind
seed-fiberseed-z
whenseed-fiber
visitseed-fiberseed-z
loopwhile
<headtail
forpackedfixnum=
arefqueuehead
do
incfhead
multiple-value-bind
fiberz
declare
typefixnumfiberz
let
x
modfiberstride
declare
typefixnumx
when
pluspx
visit
1-fiber
z
when
<x
1-stride
visit
1+fiber
z
when
>=fiberstride
visit
-fiberstride
z
when
<fiber
-fiber-countstride
visit
+fiberstride
z
when
pluspz
visitfiber
1-z
when
visitfiber
1+z
defuncamera-boundary-bit-waves
case

Propagate reachable air through packed masks one cell per fixed-point wave.

let*
stride
fiber-case-stridecase
fiber-count
*stridestride
occupancy
fiber-case-occupancycase
workspace
fiber-case-air-workspacecase
source
air-workspace-reachable-aworkspace
destination
air-workspace-reachable-bworkspace
declare
typefixnumstridefiber-count
typeu64-vectoroccupancysourcedestination
optimize
speed3
safety0
fillsource0
filldestination0
multiple-value-bind
seed-fiberseed-z
whenseed-fiber
mark-reachable-bitsourceseed-fiberseed-z
loop
let
changednil
dotimes
fiberfiber-count
let
x
modfiberstride
declare
typefixnumbasex
dotimes
let*
index
+baseword
current
arefsourceindex
previous
if
pluspword
arefsource
1-index
0
next
if
arefsource
1+index
0
neighbors
logiorcurrent
logand+u64-mask+
logior
ashcurrent1
ldb
byte163
previous
logior
ashcurrent-1
ash
logandnext1
63
if
pluspx
arefsource
0
if
<x
1-stride
arefsource
0
if
>=fiberstride
arefsource
-index
0
if
<fiber
-fiber-countstride
arefsource
+index
0
new
logandvalidneighbors
lognot
arefoccupancyindex
setf
arefdestinationindex
new
unless
=newcurrent
setfchangedt
unlesschanged
rotatefsourcedestination
defuncamera-boundary-run-flood
case

Flood maximal air intervals; horizontal overlap is the adjacency test.

let*
stride
fiber-case-stridecase
workspace
fiber-case-air-workspacecase
offsets
air-workspace-run-offsetsworkspace
starts
air-workspace-run-startsworkspace
ends
air-workspace-run-endsworkspace
owners
air-workspace-run-ownersworkspace
reached
air-workspace-run-reachedworkspace
queue
air-workspace-run-queueworkspace
reachable
air-workspace-reachable-aworkspace
head0
tail0
declare
typefixnumstrideheadtail
type
simple-arrayfixnum
offsetsownersqueue
type
simple-array
unsigned-byte8
startsends
typesimple-bit-vectorreached
optimize
speed3
safety0
fillreached0
fillreachable0
labels
admit
declare
typefixnumrun
when
zerop
sbitreachedrun
setf
sbitreachedrun
1
arefqueuetail
run
incftail
visit-fiber
neighborlowhigh
declare
typefixnumneighborlowhigh
loopforrunfixnumfrom
arefoffsetsneighbor
below
arefoffsets
1+neighbor
when
>
arefstartsrun
high
do
loop-finish
when
>=
arefendsrun
low
do
admitrun
multiple-value-bind
seed-fiberseed-z
whenseed-fiber
loopforrunfixnumfrom
arefoffsetsseed-fiber
below
arefoffsets
1+seed-fiber
when
<=
arefstartsrun
seed-z
arefendsrun
do
admitrun
loop-finish
loopwhile
<headtail
forrunfixnum=
arefqueuehead
forfiberfixnum=
arefownersrun
forlowfixnum=
arefstartsrun
forhighfixnum=
arefendsrun
do
incfhead
let
x
modfiberstride
declare
typefixnumx
when
pluspx
visit-fiber
1-fiber
lowhigh
when
<x
1-stride
visit-fiber
1+fiber
lowhigh
when
>=fiberstride
visit-fiber
-fiberstride
lowhigh
when
<fiber
-
*stridestride
stride
visit-fiber
+fiberstride
lowhigh
dotimes
run
lengthstarts
when
=1
sbitreachedrun
write-reachable-rangereachable
arefownersrun
arefstartsrun
arefendsrun

Maintaining the atmosphere chain is cheap when an edit is known not to change the component topology. The benchmark below repeatedly removes and restores one exposed terrain cell. Only that cell and its six solid neighbors can gain or lose boundary faces. Arbitrary edits still require dynamic-connectivity machinery or the full rebuild used here as an oracle.

defunset-packed-bit
wordsindexvalue
declare
typefixnumindex
typebooleanvalue
optimize
speed3
safety0
let*
word
ashindex-6
mask
ash1
logandindex63
setf
arefwordsword
ifvalue
logior
arefwordsword
mask
logand
arefwordsword
lognotmask
defunset-output-bit-value
outputbasedirectionzvalue
declare
typefixnumbasedirectionz
typebooleanvalue
optimize
speed3
safety0
set-packed-bitoutput
+
*64base
*direction+fiber-words+64
z
value
defunreachable-cell-p
caselocal-xlocal-yz
declare
typefiber-casecase
typefixnumlocal-xlocal-yz
optimize
speed3
safety0
and
<=0z
let*
stride
fiber-case-stridecase
fiber
+local-x
*local-ystride
reachable
air-workspace-reachable-a
fiber-case-air-workspacecase
reachable-bit-preachablefiberz
defunrefresh-atmosphere-cell-faces
casexyz

Refresh every camera-air face owned by one central-domain cell.

declare
typefiber-casecase
typefixnumxyz
optimize
speed3
safety0
let
width
fiber-case-widthcase
when
let*
local-x
1+x
local-y
1+y
input
input-base
fiber-case-stridecase
local-xlocal-y
solid
solid-bit-p
fiber-case-occupancycase
inputz
output
fiber-case-outputcase
declare
typefixnumlocal-xlocal-yinputoutput-base
typebooleansolid
case
defuntoggle-edit-occupancy
edit

Toggle edit's voxel and return true when its new state is solid.

let*
case
atmosphere-edit-case-caseedit
x
atmosphere-edit-case-xedit
y
atmosphere-edit-case-yedit
z
atmosphere-edit-case-zedit
base
input-base
fiber-case-stridecase
1+x
1+y
occupancy
fiber-case-occupancycase
was-solid
solid-bit-poccupancybasez
word
+base
ashz-6
mask
ash1
logandz63
declare
typefiber-casecase
typefixnumxyzbaseword
typebooleanwas-solid
optimize
speed3
safety0
setf
arefoccupancyword
logxor
arefoccupancyword
mask
ifwas-solid
decf
fiber-case-solid-countcase
incf
fiber-case-solid-countcase
notwas-solid
defunmake-atmosphere-edit-case

Make a terrain case whose edit removes and restores one exposed cell.

let*
base
input-base
fiber-case-stridecase
1+x
1+y
occupancy
fiber-case-occupancycase
z
loopforcandidatefixnumdownfromto0when
solid-bit-poccupancybasecandidate
returncandidate
unless
andz
not
solid-bit-poccupancybase
1+z
error"No exposed terrain edit cell in ~D-wide case."width
let*
workspace
fiber-case-air-workspacecase
offsets
air-workspace-run-offsetsworkspace
fiber
+
1+x
*
1+y
fiber-case-stridecase
air-run
loopforrunfixnumfrom
arefoffsetsfiber
below
arefoffsets
1+fiber
when
<=
aref
air-workspace-run-startsworkspace
run
1+z
aref
air-workspace-run-endsworkspace
run
returnrun
unlessair-run
error"No atmosphere run above edit cell (~D,~D,~D)."xyz
%make-atmosphere-edit-casecasexyzair-run
defunmaintain-atmosphere-surface-edit
edit

Toggle a topology-preserving surface cell and update its boundary locally.

let*
case
atmosphere-edit-case-caseedit
x
atmosphere-edit-case-xedit
y
atmosphere-edit-case-yedit
z
atmosphere-edit-case-zedit
stride
fiber-case-stridecase
fiber
+
1+x
*
1+y
stride
reachable
air-workspace-reachable-a
fiber-case-air-workspacecase
declare
typefiber-casecase
typefixnumxyzstridefiber
typebooleannow-solid
optimize
speed3
safety0
setf
aref
air-workspace-run-starts
fiber-case-air-workspacecase
atmosphere-edit-case-air-runedit
ifnow-solid
1+z
z
set-packed-bitreachable
notnow-solid
fiber-case-outputcase
defunrebuild-atmosphere-after-edit
edit

Toggle edit, rebuild the air-run index, and rediscover the atmosphere.

let
case
atmosphere-edit-case-caseedit
setf
fiber-case-air-workspacecase
make-air-workspace
fiber-case-occupancycase
fiber-case-stridecase
defunoutput-face-count
output
declare
optimize
speed3
safety0
loopforwordacrossoutputsum
logcountword
defuncopy-output
case
let*
source
fiber-case-outputcase
copy
make-array
lengthsource
:element-type'
unsigned-byte64
replacecopysource
copy
defunvalidate-case
case
let*
cell-output
scalar-output
simd-families
camera-cell-output
unless
equalpcell-outputscalar-output
error"Cell and scalar-fiber masks disagree for ~D-wide ~(~A~)."
fiber-case-widthcase
fiber-case-patterncase
dolist
simd-familysimd-families
funcall
surface-kernelsimd-family
case
unless
equalpscalar-output
fiber-case-outputcase
error"Scalar and ~A masks disagree for ~D-wide ~(~A~)."simd-family
fiber-case-widthcase
fiber-case-patterncase
unless
equalpcamera-cell-output
fiber-case-outputcase
error"Cell and bit-wave camera boundaries disagree for ~D-wide ~(~A~)."
fiber-case-widthcase
fiber-case-patterncase
unless
equalpcamera-cell-output
fiber-case-outputcase
error"Cell and air-run camera boundaries disagree for ~D-wide ~(~A~)."
fiber-case-widthcase
fiber-case-patterncase
dotimes
y
fiber-case-widthcase
dotimes
x
fiber-case-widthcase
let
base
input-base
fiber-case-stridecase
1+x
1+y
unless
=
fiber-run-count-scan
fiber-case-occupancycase
base
fiber-run-count-bits
fiber-case-occupancycase
base
error"Run counters disagree at (~D,~D) for ~(~A~)."xy
fiber-case-patterncase
values
output-face-countscalar-output
output-face-countcamera-cell-output
simd-families
defparameter+benchmark-phases+'
:runs-scan:runs-bits:surface-cell:surface-scalar:surface-simd:air-cell:air-bits:air-runs
defparameter+atmosphere-edit-phases+'
:air-edit-maintain:air-edit-rebuild
defuncamera-air-phase-p
phase
memberphase'
:air-cell:air-bits:air-runs
defunphase-zone
phase
ecasephase
:runs-scan:luft/z-fiber/runs-scan
:runs-bits:luft/z-fiber/runs-bits
:surface-cell:luft/z-fiber/surface-cell
:surface-scalar:luft/z-fiber/surface-scalar
:surface-simd:luft/z-fiber/surface-simd
:air-cell:luft/z-fiber/camera-air-cell
:air-bits:luft/z-fiber/camera-air-bits
:air-runs:luft/z-fiber/camera-air-runs
:air-edit-maintain:luft/z-fiber/atmosphere-edit-maintain
:air-edit-rebuild:luft/z-fiber/atmosphere-edit-rebuild
defuncount-runs-with
let
total0
width
fiber-case-widthcase
stride
fiber-case-stridecase
occupancy
fiber-case-occupancycase
declare
typefixnumtotalwidthstride
dotimes
ywidthtotal
dotimes
incftotal
funcallfunctionoccupancy
input-basestride
1+x
1+y
defuninvoke-phase
casephasesimd-family
luv:with-cpu-trace-zone
:tracy-value
fiber-case-solid-countcase
setf*z-fiber-benchmark-sink*
ecasephase
:surface-cell
:surface-scalar
:surface-simd
aref
funcall
surface-kernelsimd-family
case
0
:air-cell
:air-bits
:air-runs
defuncalibrate-iterations
casephasesimd-family
loopwithiterationsfixnum=1withtarget-seconds=0.025d0do
let
observation
luv:make-runtime-observation
luv:with-runtime-observation
observation
dotimes
indexiterations
declare
ignoreindex
invoke-phasecasephasesimd-family
when
or
>=
luv:runtime-observation-elapsed-secondsobservation
target-seconds
>=iterations1048576
returniterations
setfiterations
min1048576
*2iterations
defunmeasure-phase
casephasesimd-familysample-countwarmup-countstreamface-count
formatstream" ~18A "phase
force-outputstream
dotimes
indexwarmup-count
declare
ignoreindex
write-char#\wstream
force-outputstream
invoke-phasecasephasesimd-family
let
iterations
calibrate-iterationscasephasesimd-family
formatstream" x~D "iterations
force-outputstream
sb-ext:gc:fullt
let
samples
make-arraysample-count
dotimes
write-char#\.stream
force-outputstream
let
observation
luv:make-runtime-observation
luv:with-runtime-observation
observation
dotimes
iterationiterations
declare
ignoreiteration
invoke-phasecasephasesimd-family
setf
arefsamplesindex
make-fiber-sample:width
fiber-case-widthcase
:pattern
fiber-case-patterncase
:phasephase:simd-familysimd-family:indexindex:iterationsiterations:fiber-count
*
fiber-case-widthcase
fiber-case-widthcase
:solid-count
fiber-case-solid-countcase
:run-count
fiber-case-total-runscase
:air-run-count
length
air-workspace-run-starts
fiber-case-air-workspacecase
:face-countface-count:elapsed-seconds
/
luv:runtime-observation-elapsed-secondsobservation
iterations
:bytes-consed
round
/
luv:runtime-observation-bytes-consedobservation
iterations
:gc-seconds
/
luv:runtime-observation-gc-secondsobservation
iterations
:garbage-collections
luv:runtime-observation-garbage-collectionsobservation
terpristream
samples
defuninvoke-atmosphere-edit-phase
editphase
setf*z-fiber-benchmark-sink*
aref
ecasephase
:air-edit-maintain
:air-edit-rebuild
0
defuncalibrate-atmosphere-edit-iterations
widthphase
loopwithiterationsfixnum=1withtarget-seconds=0.025d0do
let
observation
luv:make-runtime-observation
luv:with-runtime-observation
observation
dotimes
indexiterations
declare
ignoreindex
when
or
>=
luv:runtime-observation-elapsed-secondsobservation
target-seconds
>=iterations1048576
returniterations
setfiterations
min1048576
*2iterations
defunmeasure-atmosphere-edit-phase
widthphasesample-countwarmup-countstream
formatstream" ~18A "phase
force-outputstream
let
dotimes
indexwarmup-count
declare
ignoreindex
write-char#\wstream
force-outputstream
let
formatstream" x~D "iterations
force-outputstream
sb-ext:gc:fullt
let
samples
make-arraysample-count
dotimes
write-char#\.stream
force-outputstream
let*
case
atmosphere-edit-case-caseedit
face-count
output-face-count
fiber-case-outputcase
air-run-count
length
air-workspace-run-starts
fiber-case-air-workspacecase
observation
luv:make-runtime-observation
luv:with-runtime-observation
observation
luv:with-cpu-trace-zone
:tracy-valueiterations
dotimes
iterationiterations
declare
ignoreiteration
setf
arefsamplesindex
make-fiber-sample:widthwidth:pattern:terrain:phasephase:simd-family:scalar:indexindex:iterationsiterations:fiber-count:solid-count
fiber-case-solid-countcase
:run-count
fiber-case-total-runscase
:air-run-countair-run-count:face-countface-count:elapsed-seconds
/
luv:runtime-observation-elapsed-secondsobservation
iterations
:bytes-consed
round
/
luv:runtime-observation-bytes-consedobservation
iterations
:gc-seconds
/
luv:runtime-observation-gc-secondsobservation
iterations
:garbage-collections
luv:runtime-observation-garbage-collectionsobservation
terpristream
samples
defunpercentile
valuesfraction
let*
sorted
sort
copy-seqvalues
#'<
index
round
*fraction
1-
lengthsorted
arefsortedindex
defunsample-elapsed-milliseconds
*1000d0
fiber-sample-elapsed-secondssample
defunprint-phase-summary
casephasesamplesstream
let
milliseconds
map'vector#'sample-elapsed-millisecondssamples
bytes
map'vector#'fiber-sample-bytes-consedsamples
if
formatstream" p50 ~,1F ns/edit p95 ~,1F ns/edit ~,3F KiB/edit~%"
*1d6
percentilemilliseconds0.50d0
*1d6
percentilemilliseconds0.95d0
/
percentilebytes0.50d0
1024d0
formatstream" p50 ~,4F ms p95 ~,4F ms ~,3F ns/fiber ~,3F KiB~%"
percentilemilliseconds0.50d0
percentilemilliseconds0.95d0
*1d6
percentilemilliseconds0.50d0
/
*
fiber-case-widthcase
fiber-case-widthcase
/
percentilebytes0.50d0
1024d0
defunwrite-csv-header
stream
formatstream"width,pattern,phase,simd_family,sample,iterations,fibers,cells,solid_cells,runs,air_runs,faces,output_bytes,elapsed_ms,allocated_bytes,gc_ms,batch_gc_count~%"
defunwrite-sample-csv
samplestream
formatstream"~D,~(~A~),~(~A~),~(~A~),~D,~D,~D,~D,~D,~D,~D,~D,~D,~,6F,~D,~,6F,~D~%"
fiber-sample-widthsample
fiber-sample-patternsample
fiber-sample-phasesample
fiber-sample-simd-familysample
fiber-sample-indexsample
fiber-sample-iterationssample
fiber-sample-fiber-countsample
*
fiber-sample-fiber-countsample
luft:+top-z+
fiber-sample-solid-countsample
fiber-sample-run-countsample
fiber-sample-air-run-countsample
fiber-sample-face-countsample
*
fiber-sample-fiber-countsample
+direction-count++fiber-words+8
fiber-sample-bytes-consedsample
*1000d0
fiber-sample-gc-secondssample
fiber-sample-garbage-collectionssample
defunrun-z-fiber-benchmark
&key
widths'
1632
patterns'
:solid:terrain:architecture:caves:checkerboard
warmup-count3
csv-pathname#P"build/luft-z-fiber-benchmark.csv"
stream*standard-output*

Benchmark Z-fiber extraction, camera air, and maintained surface edits.

check-typesample-count
integer1*
check-typewarmup-count
integer0*
let
csv-pathname
merge-pathnamescsv-pathname
all-samplesnil
unlesssimd-family
error"No native SIMD family is available; found ~S."
formatstream"LUFT Z fibers: kernels ~{~(~A~)~^, ~}; benchmarking ~A.~%"simd-family
ensure-directories-existcsv-pathname
with-open-file
csvcsv-pathname:direction:output:if-exists:supersede:if-does-not-exist:create
dolist
widthwidths
dolist
patternpatterns
formatstream"~&Building ~Dx~D full-height ~(~A~) fibers...~%"widthwidthpattern
force-outputstream
let
multiple-value-bind
face-countcamera-face-countvalidated-families
declare
ignorevalidated-families
formatstream" ~:D solids, ~:D faces (~:D camera-air), ~:D runs (~,2F/fiber, max ~D), ~:D halo air runs; exact masks~%"
fiber-case-solid-countcase
face-countcamera-face-count
fiber-case-total-runscase
/
fiber-case-total-runscase
fiber-case-maximum-runscase
length
air-workspace-run-starts
fiber-case-air-workspacecase
dolist
let*
phase-face-count
ifcamera-face-countface-count
samples
measure-phasecasephasesimd-familysample-countwarmup-countstreamphase-face-count
print-phase-summarycasephasesamplesstream
loopforsampleacrosssamplesdo
pushsampleall-samples
force-outputcsv
when
member:terrainpatterns
dolist
widthwidths
let*
case
atmosphere-edit-case-caseedit
formatstream"~&Maintaining ~Dx~D terrain atmosphere boundary at (~D,~D,~D)...~%"widthwidth
atmosphere-edit-case-xedit
atmosphere-edit-case-yedit
atmosphere-edit-case-zedit
force-outputstream
dolist
let
print-phase-summarycasephasesamplesstream
loopforsampleacrosssamplesdo
pushsampleall-samples
force-outputcsv
formatstream"~&Wrote ~:D samples to ~A~%"
lengthall-samples
csv-pathname
values
coerce
nreverseall-samples
'vector
csv-pathname