sb-simd-avx:f64.4-reverse is broken

Bug #2012986 reported by ari pro
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Fix Released
Undecided
Unassigned

Bug Description

There are a handful of sb-simd functions defined in terms of undefined fake VOPs.

(require "SB-SIMD")
(loop for fn in (sb-simd-internals:filter-available-function-records #'sb-simd-internals:instruction-record-p)
      unless (fboundp (sb-simd-internals:instruction-record-vop fn))
 collect (sb-simd-internals:function-record-name fn))
=> (SB-SIMD::U64-FROM-F32
    SB-SIMD::U64-FROM-F64
    SB-SIMD::F32-RECIPROCAL
    SB-SIMD::F32-RSQRT
    SB-SIMD::F64-RECIPROCAL
    SB-SIMD::F64-RSQRT
    SB-SIMD-SSE2::F64.2-HSUM
    SB-SIMD-SSE2::F64.2-HPROD
    SB-SIMD-AVX:F64.4-REVERSE)

(sb-simd-avx:f64.4-reverse (sb-simd-avx:make-f64.4 1.0 2.0 3.0 4.0))
=>
debugger invoked on a UNDEFINED-FUNCTION @21A208E4 in thread
#<THREAD "main thread" RUNNING {1004858073}>:
  The function SB-SIMD-AVX::%F64.4-REVERSE is undefined.

Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
  0: [CONTINUE ] Retry calling SB-SIMD-AVX::%F64.4-REVERSE.
  1: [USE-VALUE ] Call specified function.
  2: [RETURN-VALUE ] Return specified values.
  3: [RETURN-NOTHING] Return zero values.
  4: [ABORT ] Exit debugger, returning to top level.

("undefined function" #<SIMD-PACK-256 1.0000000000000d+0 2.0000000000000d+0 3.0000000000000d+0 4.0000000000000d+0>)

There is a test named check-package for which checks for exported symbols with no attached definition in contrib/sb-simd/test-suite/test-suite.lisp, but it does not catch this type of error, because sb-simd-avx:f64.4-reverse is fbound.

sb-simd-avx:f64.4-reverse was originally defined in https://github.com/marcoheisig/sb-simd/blob/e2f6bbaf19701e7db2aee9a535a73e36df889e75/code/define-pseudo-vops.lisp#L110-L111 as
(sb-simd::define-pseudo-vop f64.4-reverse (a)
  (f64.4-permute (f64.4-permute2f128 a a 1) 5))

It was commented out in https://github.com/marcoheisig/sb-simd/commit/1c5b07d383d798e1c580e5680f699501cf60bb88 and deleted in https://github.com/marcoheisig/sb-simd/commit/b8ba0d3d1fd3f9cb7d1202c1d3a34bc2863be425 .

This patch adds the fake VOP
(define-fake-vop f64.4-reverse (x)
  (%f64.4-permute (%f64.4-permute128 x x #4r01) #4r11))
to contrib/sb-simd/code/define-fake-vops.lisp and changes the mnemonic in contrib/sb-simd/code/instruction-sets/avx.lisp from #:vpermilpd to nil to reflect that the :encoding is :fake-vop.

I left the :cost at 2, because f64.4-permute and f64.4-permute128 both have a cost of 1.

Note that an equivalent operation is currently used in https://github.com/sbcl/sbcl/blob/master/contrib/sb-simd/code/define-fake-vops.lisp#L906-L907

As for the other symbols, which are internal:

In contrib/sb-simd/code/instruction-sets/sse2.lisp:
SB-SIMD-SSE2::F64.2-HSUM and SB-SIMD-SSE2::F64.2-HPROD were added in the commit https://github.com/marcoheisig/sb-simd/commit/d0238545af9536decec87edc622f0f343852541e .
Their corresponding fake VOPs were defined in a commented-out section of code/define-horizontals.lisp in that commit:
https://github.com/marcoheisig/sb-simd/blob/d0238545af9536decec87edc622f0f343852541e/code/define-horizontals.lisp .
The file code/define-horizontals.lisp was deleted in
https://github.com/marcoheisig/sb-simd/commit/ac744b48387a62b876e000a5818a36cc401e20aa

This patch deletes those two symbols, since I believe they were intended to have been deleted along with the other -hsum and -hprod functions that used to exist for other instruction sets.

In contrib/sb-simd/code/instruction-sets/sb-simd.lisp, this patch comments out SB-SIMD::U64-FROM-F32, SB-SIMD::U64-FROM-F64, SB-SIMD::F32-RECIPROCAL, SB-SIMD::F32-RSQRT, SB-SIMD::F64-RECIPROCAL, and SB-SIMD::F64-RSQRT.

SB-SIMD::U64-FROM-F32 and SB-SIMD::U64-FROM-F64 were added in
https://github.com/marcoheisig/sb-simd/commit/892ecdda2a157b8ef6e6723dec796b2017b823d6
but as far as I can tell, they never had their fake VOPs implemented.

The fake VOPs for SB-SIMD::F32-RECIPROCAL, SB-SIMD::F32-RSQRT, SB-SIMD::F64-RECIPROCAL, and SB-SIMD::F64-RSQRT are commented-out in contrib/sb-simd/code/define-fake-vops.lisp

I added a test similar to the loop above called check-instruction-record-vops. It signals an error when it finds instructions with unbound instruction-record-vops, which can happen when the instruction-record VOP is not defined or when the contrib is built on a machine that doesn't support a particular instruction set that the host machine does support (see https://sourceforge.net/p/sbcl/mailman/message/37795412/). The test may need a better error message or a better name.

Revision history for this message
ari pro (aripro) wrote :
Revision history for this message
ari pro (aripro) wrote :
Changed in sbcl:
assignee: nobody → Marco Heisig (marco-heisig-h)
Revision history for this message
Marco Heisig (marco-heisig-h) wrote :

You are right, you found several remnants from the past that should either be removed, or modernized.

I am working on a solution for all of these that also incorporates your patch. Stay tuned.

Changed in sbcl:
status: New → Confirmed
Revision history for this message
Marco Heisig (marco-heisig-h) wrote :

The attached patch fixes this bug, removes a few exports with no attached definition, and adds a few exports for functions that I simply forgot in the initial release.

It includes all changes from Ari's patch.

Stas Boukarev (stassats)
Changed in sbcl:
status: Confirmed → Fix Committed
assignee: Marco Heisig (marco-heisig-h) → nobody
Changed in sbcl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.