2Dグラフィックスの場合、関数を最適化する必要がありますが、SBCLではSBCLが算術演算をインライン化できないというコメントがたくさんあります。私はあらゆる種類の宣言を試みましたが、コンパイラを満足させるようには見えません。簡単な例を次に示します。Common Lisp:SBCLの関数の最適化
(defun test-floor (x div)
(declare (type single-float x)
(type (signed-byte 64) div)
(optimize (speed 3)))
(floor x div))
以下の4つの注釈を示します。私は床が組み込み関数なので完全に失われています。私はSBCLでコンパイラのヒントを適切に与える方法に関する情報やチュートリアルを見つけようとしましたが、適切な情報を見つけられなかったので、どんな情報も非常に高く評価されます!残念ながら、Common Lispでの最適化は私にとっては非常に未知の領域です。 LinuxマシンでSBCL 1.3.20を使用しています。
; file: /tmp/file595dqU
; in: defun test-floor
; (FLOOR CL-FLOCKS::X CL-FLOCKS::DIV)
; --> MULTIPLE-VALUE-BIND MULTIPLE-VALUE-CALL TRUNCATE LET*
; ==>
; (SB-KERNEL:%UNARY-TRUNCATE/SINGLE-FLOAT (/ SB-C::X SB-C::F))
;
; note: forced to do full call
; unable to do inline float truncate (cost 5) because:
; The result is a (values integer &optional), not a (values
; (signed-byte 64) &rest
; t).
; --> MULTIPLE-VALUE-BIND MULTIPLE-VALUE-CALL TRUNCATE LET* VALUES - *
; ==>
; (SB-KERNEL:%SINGLE-FLOAT SB-C::RES)
;
; note: forced to do full call
; unable to do inline float coercion (cost 5) because:
; The first argument is a integer, not a (signed-byte 64).
; --> MULTIPLE-VALUE-BIND MULTIPLE-VALUE-CALL FUNCTION IF VALUES 1-
; ==>
; (- SB-C::TRU 1)
;
; note: forced to do generic-- (cost 10)
; unable to do inline fixnum arithmetic (cost 1) because:
; The first argument is a integer, not a fixnum.
; The result is a (values integer &optional), not a (values fixnum &rest t).
; unable to do inline fixnum arithmetic (cost 2) because:
; The first argument is a integer, not a fixnum.
; The result is a (values integer &optional), not a (values fixnum &rest t).
; etc.
; --> MULTIPLE-VALUE-BIND MULTIPLE-VALUE-CALL FUNCTION IF VALUES
; ==>
; (+ REM SB-C::DIVISOR)
;
; note: doing signed word to integer coercion (cost 20) from div, for:
; the second argument of generic-+
;
; compilation unit finished
; printed 4 notes
CL-USER>
これは非常に合理的なようです、ありがとう!結果が64ビットの範囲を超えないことをコンパイラに伝える方法はありますか?または、コアダンプの答えに示唆されているようにffloorを使用する方が効率的でしょうか? –
まだ何も見つかりませんでした –