Changes between Version 19 and Version 20 of SIMD


Ignore:
Timestamp:
Nov 11, 2011 7:22:57 PM (3 years ago)
Author:
duncan
Comment:

add primitives

Legend:

Unmodified
Added
Removed
Modified
  • SIMD

    v19 v20  
    264264The native-sized vector types are distinct types from the explicit-sized vector types, not type aliases for the corresponding explicit-sized vector. This is to support and encourage portable code. 
    265265 
     266== Vector operations == 
     267 
     268The following operations on vectors will be supported. They will need to be implemented at the Haskell/core primop layer, Cmm MachOp layer and optional support in the code generators. 
     269 
     270Extracting and inserting vector elements: 
     271{{{ 
     272extractInt<w>Vec<m>#   :: Int<w>Vec<m>#  -> Int# -> Int# 
     273extractWord<w>Vec<m>#  :: Word<w>Vec<m># -> Int# -> Word# 
     274extractFloatVec#       :: FloatVec<m>#   -> Int# -> Float# 
     275extractDoubleVec#      :: DoubleVec<m>#  -> Int# -> Double# 
     276}}} 
     277{{{ 
     278insertInt<w>Vec<m>#   :: Int<w>Vec<m>#  -> Int# -> Int#    -> Int<w>Vec<m># 
     279insertWord<w>Vec<m>#  :: Word<w>Vec<m># -> Int# -> Word#   -> Word<w>Vec<m># 
     280insertFloatVec#       :: FloatVec<m>#   -> Int# -> Float#  -> FloatVec<m># 
     281insertDoubleVec#      :: DoubleVec<m>#  -> Int# -> Double# -> DoubleVec<m># 
     282}}} 
     283Vector shuffle: 
     284{{{ 
     285shuffleInt<w>Vec<m>ToVec<m'>  :: Int<w>Vec<m>#  -> Int32Vec<m'>#    -> Int<w>Vec<m'># 
     286}}} 
     287For the fixed size vectors (not native size) we may also want to add pack/unpack functions like: 
     288{{{ 
     289unpackInt<w>Vec4# :: Int<w>Vec4# -> (# Int#, Int#, Int#, Int# #) 
     290packInt<w>Vec4#   :: (# Int#, Int#, Int#, Int# #) -> Int<w>Vec4# 
     291}}} 
     292 
     293In the following, `<t>` ranges over `Int<w>`, `Word<w>`, `Float`, `Double`. 
     294 
     295Arithmetic operations: 
     296{{{ 
     297plus<t>Vec<m>#, minus<t>Vec<m>#, 
     298times<t>Vec<m>#, quot<t>Vec<m>#, rem<t>Vec<m># :: <t>Vec<m># -> <t>Vec<m># -> <t>Vec<m># 
     299 
     300negate<t>Vec<m># :: <t>Vec<m># -> <t>Vec<m># 
     301}}} 
     302Logic operations: 
     303{{{ 
     304andInt<w>Vec<m>#, orInt<w>Vec<m>#, xorInt<w>Vec<m>#    :: Int<w>Vec<m>#  -> Int<w>Vec<m>#  -> Int<w>Vec<m># 
     305andWord<w>Vec<m>#, orWord<w>Vec<m>#, xorWord<w>Vec<m># :: Word<w>Vec<m># -> Word<w>Vec<m># -> Word<w>Vec<m># 
     306 
     307notInt<w>Vec<m>#  :: Int<w>Vec<m>#  -> Int<w>Vec<m># 
     308notWord<w>Vec<m># :: Word<w>Vec<m># -> Word<w>Vec<m># 
     309 
     310shiftLInt<w>Vec<m>#,  shiftRAInt<w>Vec<m>#  :: Int<w>Vec<m>#  -> Word# -> Int<w>Vec<m># 
     311ShiftLWord<w>Vec<m>#, ShiftRLWord<w>Vec<m># :: Word<w>Vec<m># -> Word# -> Word<w>Vec<m># 
     312}}} 
     313Comparison: 
     314{{{ 
     315cmp<eq,ne,gt,gt,lt,le>Int<w>Vec<m>#  :: Int<w>Vec<m>#  -> Int<w>Vec<m>#  -> Word<w>Vec<m># 
     316cmp<eq,ne,gt,gt,lt,le>Word<w>Vec<m># :: Word<w>Vec<m># -> Word<w>Vec<m># -> Word<w>Vec<m># 
     317}}} 
     318Note that LLVM does not yet support the comparison operations. 
     319 
     320TODO: 
     321 * conversion sign/width operations, e.g. Word <-> Int, Word8 <-> Word16 etc. 
     322 * conversion fp operations, e.g. Float <-> Int 
     323Should also consider: 
     324 * vector constants, at least at Cmm level 
     325 * replicating a scalar to a vector 
     326 * AVX also suppports a bunch of interesting things: 
     327   * permute, shuffle, "blend", masked moves. 
     328   * min, max within a vector 
     329   * average 
     330   * horizontal add/sub 
     331   * shift whole vector left/right by n bytes 
     332   * gather (but not scatter) of 32, 64bit int and fp from memory (base + vector of offsets) 
     333 
     334=== Int/Word size wrinkle === 
     335 
     336Note that there is a wrinkle with the 32 and 64 bit int and word types. For example, the types for the extract functions should be: 
     337{{{ 
     338extractInt32Vec<m>#  :: Int32Vec#  -> Int# -> INT32 
     339extractInt64Vec<m>#  :: Int64Vec#  -> Int# -> INT64 
     340extractWord32Vec<m># :: Word32Vec# -> Int# -> WORD32 
     341extractWord64Vec<m># :: Word64Vec# -> Int# -> WORD64 
     342}}} 
     343where `INT32`, `INT64`, `INT64`, `WORD64` are CPP macros that expand in a arch-dependent way to the types Int#/Int64# and Word#/Word64#. 
     344 
     345To describe this in the primop definition we might want something like: 
     346{{{ 
     347primop   IntAddOp <w,m,t>    "extractWord<w>Vec<m>#"    Dyadic 
     348  Word<w>Vec<m># -> Int# -> <t> 
     349  with <w, m, t> in <8, 2,Word#>,<8, 4,Word#>,<8, 8,Word#>,<8, 16,Word#>,<8, 32,Word#>, 
     350                    <16,2,Word#>,<16,4,Word#>,<16,8,Word#>,<16,16,Word#>, 
     351                    <32,2,WORD32>,<32,4,WORD32>,<32,8,WORD32>, 
     352                    <64,2,WORD64>,<64,4,WORD64> 
     353                    <"",2,WORD>,<"",4,WORD>  
     354}}} 
     355 
     356To iron out this wrinkle we would need the whole family of primitve types: Int8#, Int16#, Int32# etc whereas currently only the native register sized Int# type is provided, plus a primitive Int64# type is provided on 32bit systems. 
     357 
    266358== Data Parallel Haskell layer == 
    267359