packages feed

crackNum 3.9 → 3.10

raw patch · 4 files changed

+51/−22 lines, 4 files

Files

CHANGES.md view
@@ -1,7 +1,11 @@ * Hackage: <http://hackage.haskell.org/package/crackNum> * GitHub:  <http://github.com/LeventErkok/crackNum/> -* Latest Hackage released version: 3.9, 2024-02-23+* Latest Hackage released version: 3.10, 2024-03-01++### Version 3.10, 2024-03-01+  +  * More relaxed parsing for verilog input format  ### Version 3.9, 2024-02-23   
crackNum.cabal view
@@ -1,6 +1,6 @@ Cabal-version      : 2.2 Name               : crackNum-Version            : 3.9+Version            : 3.10 Synopsis           : Crack various integer and floating-point data formats Description        : Crack IEEE-754 float formats and arbitrary sized words and integers, showing the layout.                      .
src/CrackNum/Main.hs view
@@ -64,6 +64,11 @@ fpSize E5M2     = 8 fpSize E4M3     = 8 +kSize :: NKind -> Int+kSize (SInt  i)  = i+kSize (SWord i)  = i+kSize (SFloat f) = fpSize f+ -- | Rounding modes we support data RM = RNE  -- ^ Round nearest ties to even         | RNA  -- ^ Round nearest ties to away@@ -284,29 +289,47 @@                                                                                     , "Length must be an exact multiple of the element size."                                                                                     ] -                                              (decode, lanesInferred) <- case arg of-                                                                           '0':'x':_ -> pure (True, Nothing)-                                                                           '0':'b':_ -> pure (True, Nothing)-                                                                           _         -> case break (`elem` "'h") arg of-                                                                                          (pre@(_:_), '\'':'h':_)-                                                                                            | all isDigit pre -> (True,) <$> inferLanes (read pre)-                                                                                          _                   -> pure (False, Nothing)+                                              (decode, isVerilog, lanesInferred) <-+                                                        case arg of+                                                          '0':'x':_ -> pure (True, False, Nothing)+                                                          '0':'b':_ -> pure (True, False, Nothing)+                                                          _         -> case break (`elem` "'h") arg of+                                                                         (pre@(_:_), '\'':'h':_)+                                                                           | all isDigit pre -> (True, True, ) <$> inferLanes (read pre)+                                                                         _                   -> pure (False, False, Nothing)                                                let lanes                                                     | tryInfer = fromMaybe lanesGiven lanesInferred                                                     | True     = lanesGiven                                                if decode-                                                 then decodeAllLanes debug lanes kind    arg-                                                 else encodeLane     debug lanes kind rm arg+                                                 then decodeAllLanes isVerilog debug lanes kind    arg+                                                 else encodeLane               debug lanes kind rm arg -decodeAllLanes :: Bool -> Int -> NKind -> String -> IO ()-decodeAllLanes debug lanes kind arg = do+decodeAllLanes :: Bool -> Bool -> Int -> NKind -> String -> IO ()+decodeAllLanes isVerilog debug lanes kind arg = do    when (lanes < 0) $ die       ["Number of lanes must be non-negative. Got: " ++ show lanes] -   bits <- parseToBits arg+   unalteredBits <- parseToBits arg +   bits <- if not isVerilog+           then pure unalteredBits+           else do let needed = lanes * kSize kind+                       have   = length unalteredBits+                   case needed `compare` have of+                    EQ -> pure unalteredBits+                    LT -> -- we have too much, drop but only if they're all False:+                          let (pre, post) = splitAt (have - needed) unalteredBits+                          in if all not pre+                                then pure post+                                else die [ "Needed " ++ show needed ++ " bits, got " ++ show have ++ " bits, " ++ show (have - needed) ++ " extra bits."+                                         , "But these bits are not all zeros! So, dropping isn't safe."+                                         , "They are: " ++ map (\d -> if d then '1' else '0') pre+                                         ]+                    GT -> -- we don't have enough. Add enough bits to satisfy+                          pure $ replicate (needed - have) False ++ unalteredBits+    let l           = length bits        bitsPerLane = l `div` lanes @@ -329,6 +352,7 @@                                   decodeLane debug (if lanes == 1 then Nothing else Just i) curLaneBits kind                                   laneLoop (i-1) remBits    laneLoop (lanes - 1) bits+ -- | Kinds of numbers we understand data NKind = SInt   Int -- ^ Signed   integer of n bits            | SWord  Int -- ^ Unsigned integer of n bits
src/CrackNum/TestSuite.hs view
@@ -92,14 +92,15 @@             ,  i :: Double <- [240.01, 248, 419, 432]             ]           , testGroup "Decode" [-               gold "decode0" "-i4       0b0110"-            ,  gold "decode1" "-w4       0xE"-            ,  gold "decode2" "-f3+4     0b0111001"-            ,  gold "decode3" "-fbp      0x000F"-            ,  gold "decode4" "-fdp      0x8000000000000000"-            ,  gold "decode5" "-fhp      0x7c01"-            ,  gold "decode6" "-fhp  -l8 128'hffffffffffffffffbdffaaffdc71fc60"-             , gold "decode7" "-fe5m2    0b01111011"+              gold "decode0" "-i4       0b0110"+            , gold "decode1" "-w4       0xE"+            , gold "decode2" "-f3+4     0b0111001"+            , gold "decode3" "-fbp      0x000F"+            , gold "decode4" "-fdp      0x8000000000000000"+            , gold "decode5" "-fhp      0x7c01"+            , gold "decode6" "-fhp  -l8 128'hffffffffffffffffbdffaaffdc71fc60"+            , gold "decode7" "-fe5m2    0b01111011"+            , gold "decode8" "-w2 -rRNE 2\'h1"             ]           , testGroup "DecodeE4M3" [                gold ("decodeE4M3_" ++ show (if sign then (-val :: Int) else val))