implement extmul operation

This commit is contained in:
Ilya Rezvov
2023-09-24 19:20:21 -06:00
parent 22198d8d76
commit ac2a326f18
4 changed files with 66 additions and 1 deletions
+38
View File
@@ -1428,6 +1428,11 @@ eval budget store inst FunctionInstance { funcType, moduleInstance, code = Funct
_ -> error "impossible due to validation"
in
return $ Done ctx { stack = VV128 r : rest }
step ctx@EvalCtx{ stack = (VV128 v:rest) } (IUnOp (BS128 _) IPopcnt) =
let r = ByteArray.byteArrayFromList @Word8
$ (fromIntegral . popCount) . ByteArray.indexByteArray @Word8 v <$> [0..15]
in
return $ Done ctx { stack = VV128 r : rest }
step ctx@EvalCtx{ stack = (VV128 v2:VV128 v1:rest) } (IBinOp (BS128 shape) IAdd) =
let r = case shape of
I8x16 -> lanewise @Word8 shape v1 v2 (+)
@@ -1454,6 +1459,39 @@ eval budget store inst FunctionInstance { funcType, moduleInstance, code = Funct
_ -> error "impossible due to validation"
in
return $ Done ctx { stack = VV128 r : rest }
step ctx@EvalCtx{ stack = (VV128 v2:VV128 v1:rest) } (IBinOp (BS128 shape) (IExtMul signed high)) =
let count = case shape of
I16x8 -> 8
I32x4 -> 4
I64x2 -> 2
_ -> error "impossible due to validation"
in
let proto = if high then [1,3..2*(count - 1) + 1] else [0,2..2 *(count-1)] in
let r = case shape of
I16x8 ->
let op = if signed
then \a b -> asWord16 $ fromIntegral (asInt8 a) * fromIntegral (asInt8 b)
else \a b -> fromIntegral a * fromIntegral b
in
ByteArray.byteArrayFromListN count
$ zipWith op (ByteArray.indexByteArray v1 <$> proto) (ByteArray.indexByteArray v2 <$> proto)
I32x4 ->
let op = if signed
then \a b -> asWord32 $ fromIntegral (asInt16 a) * fromIntegral (asInt16 b)
else \a b -> fromIntegral a * fromIntegral b
in
ByteArray.byteArrayFromListN count
$ zipWith op (ByteArray.indexByteArray v1 <$> proto) (ByteArray.indexByteArray v2 <$> proto)
I64x2 ->
let op = if signed
then \a b -> asWord64 $ fromIntegral (asInt32 a) * fromIntegral (asInt32 b)
else \a b -> fromIntegral a * fromIntegral b
in
ByteArray.byteArrayFromListN count
$ zipWith op (ByteArray.indexByteArray v1 <$> proto) (ByteArray.indexByteArray v2 <$> proto)
_ -> error "impossible due to validation"
in
return $ Done ctx { stack = VV128 r : rest }
step ctx@EvalCtx{ stack = (VV128 v2:VV128 v1:rest) } (IBinOp (BS128 shape) IAddSatU) =
let r = case shape of
I8x16 -> lanewise @Word8 shape v1 v2 $ \a b ->