Skip to content

Commit

Permalink
fix e5m2 encoding and more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LeventErkok committed Feb 21, 2024
1 parent 693b3fa commit e5c251f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
16 changes: 16 additions & 0 deletions Golds/decode7.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Arguments: -fe5m2 0b01111011
Exit code: ExitSuccess
Satisfiable. Model:
DECODED = 57000 :: E5M2
7 65432 10
S -E5-- S2
Binary layout: 0 11110 11
Hex layout: 7B
Precision: 5 exponent bits, 2 significand bits
Sign: Positive
Exponent: 15 (Stored: 30, Bias: 15)
Classification: FP_NORMAL
Binary: 0b1.11p15
Octal: 0o1.6p15
Decimal: 57000
Hex: 0xep12
18 changes: 18 additions & 0 deletions Golds/encode16.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Arguments: -fe5m2 2.5
Exit code: ExitSuccess
Satisfiable. Model:
ENCODED = 2.5 :: E5M2
7 65432 10
S -E5-- S2
Binary layout: 0 10000 01
Hex layout: 41
Precision: 5 exponent bits, 2 significand bits
Sign: Positive
Exponent: 1 (Stored: 16, Bias: 15)
Classification: FP_NORMAL
Binary: 0b1.01p1
Octal: 0o2.4
Decimal: 2.5
Hex: 0x2.8
Rounding mode: RNE: Round nearest ties to even.
Note: Conversion from "2.5" was exact. No rounding happened.
2 changes: 1 addition & 1 deletion src/CrackNum/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ fixE5M2Type res = case res of
_ -> print res
where fixType :: String -> String
fixType s

Check warning on line 464 in src/CrackNum/Main.hs

View workflow job for this annotation

GitHub Actions / hlint

Suggestion in fixE5M2Type in module Main: Use otherwise ▫︎ Found: "fixType s\n | any (`isInfixOf` s) [\"ENCODED\", \"DECODED\"]\n = takeWhile (/= ':') s ++ \":: E5M2\"\n | True = s" ▫︎ Perhaps: "fixType s\n | any (`isInfixOf` s) [\"ENCODED\", \"DECODED\"]\n = takeWhile (/= ':') s ++ \":: E5M2\"\n | otherwise = s"
| "DECODED" `isInfixOf` s
| any (`isInfixOf` s) ["ENCODED", "DECODED"]
= takeWhile (/= ':') s ++ ":: E5M2"
| True
= s
Expand Down
16 changes: 9 additions & 7 deletions src/CrackNum/TestSuite.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,17 @@ tests = testGroup "CrackNum" [
, gold "encode13" "-fsp inf"
, gold "encode14" "-fsp infinity"
, gold "encode15" "-fsp nan"
, gold "encode16" "-fe5m2 2.5"
]
, 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 "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"
]
, testGroup "DecodeE4M3" [
gold ("decodeE4M3_" ++ show (if sign then (-val :: Int) else val))
Expand Down

0 comments on commit e5c251f

Please sign in to comment.