freenode/#sbcl - IRC Chatlog
Search
4:03:43
aeth
So I use structs to hold arrays of a known, fixed length in typed slots so I can get around most bounds checking, but every now and then bounds checking does seem to show up in areas where literally everything is known.
4:04:38
aeth
In the most recent case of this, as soon as I added call to a FORMAT with one of the values the 8 bounds checks went away, which is odd.
4:06:13
aeth
I can link to that function but it's basically unreadable because I use a macro to create with-accessors-style symbol-macrolet bindings of multiple-value accessors because it composes very well.
4:06:17
aeth
https://gitlab.com/zombie-raptor/zombie-raptor/blob/84cd311f3158e576429e6c904eb4d1e7ed87098e/physics/physics.lisp#L110-125
4:08:13
aeth
Essentially, the issue is with rotation. It doesn't trust its completely known dimensions. The symbol rotation there is probably expanding to (values (aref (rotation-rotation rotation) id 0) ... (aref (rotation-rotation rotation) id 3))
4:08:49
aeth
(I say probably because there might be a local gensym binding to the rotation array rather than accessing the struct 4 times)
4:09:21
aeth
This is, to the best of my knowledge, the only place where the compiler fails to remove bounds checks on this sort of data structure.
4:10:35
aeth
I thought that it might be due to the large composition of multiple-value-calls, but then I added a (format t "~S~%" rotation) (which, of course, will only print the first value) and all of the bounds checks went away and now I'm confused.
4:12:43
aeth
The bounds checking also goes away if I (multiple-value-call #'format t "~S ~S ~S ~S~%" rotation)
4:13:55
aeth
The bounds checking also goes away if I just put rotation (which presumably does nothing and is probably optimized away) above the unless.
4:25:01
aeth
I'll try to see if I can find a simple test case because this is really weird. So far I can't make a simpler test case where I can insert unnecessary bounds checking.
4:35:15
aeth
Okay, this is what's going on: (defun foo (v w) (declare ((simple-array single-float (42 3)) v) ((simple-array single-float (42 3)) w)) (setf (array-row-of-3 v 7) (array-row-of-3 w 7)) v)
4:36:42
aeth
SBCL for some reason is okay with me setting an array row from multiple values or retrieving the elements of an array row into multiple values, but does not like the combination of the two. (well, the bounds check removal, at least)
4:39:14
aeth
The version with 1D arrays is 47 bytes vs the 266 bytes of the array version. (defun foo (v w) (declare ((simple-array single-float (3)) v) ((simple-array single-float (3)) w)) (setf (array-of-3 v) (array-of-3 w)) v)
4:48:50
aeth
The only relevant functions are the array/array-row accessors here: https://gitlab.com/zombie-raptor/zombie-raptor/blob/8a4b73227b616fe621e5651d4096e965f4552e2c/util/array.lisp
10:37:48
phoe
I try to call the profiler the way described in 15.2.1 of http://www.sbcl.org/manual/ - without allocation.
10:53:26
stassats
aeth: you need to provide a proper test case, as i'm not going to deal with whatever define-function is