on master help sign in
153d2b3iko
Data/Binary/Bits/Get.hs+23
@@ -60,6 +60,7 @@ module Data.Binary.Bits.Get
60
60
61 -- ** Get bytes
61 -- ** Get bytes
62 , getBool
62 , getBool
63+ , getBool#
63 , getWord8
64 , getWord8
64 , getWord16
65 , getWord16
65 , getWord32
66 , getWord32
@@ -114,6 +115,8 @@ import Control.Applicative
114import Control.Monad (when,foldM_)
115import Control.Monad (when,foldM_)
115
116
116import Prelude as P
117import Prelude as P
118+import GHC.Word
119+import GHC.Base (uncheckedShiftLWord8#, wordToWord8#, Int (..), andWord8#, Word8#, (-#), Int#, xorI#, eqWord8#, TYPE)
117
120
118-- $bitget
121-- $bitget
119-- Parse bits using a monad.
122-- Parse bits using a monad.
@@ -182,6 +185,18 @@ readBool (S bs o bo) = case bo of
182 LL -> testBit (unsafeHead bs) o
185 LL -> testBit (unsafeHead bs) o
183 LB -> testBit (unsafeHead bs) o
186 LB -> testBit (unsafeHead bs) o
184
187
188+-- | Read a single bit
189+readBool# :: S -> Int
190+readBool# (S bs (I# o) bo) = case bo of
191+ BB -> testBit# (7# -# o)
192+ BL -> testBit# (7# -# o)
193+ LL -> testBit# o
194+ LB -> testBit# o
195+ where
196+ !(W8# w) = unsafeHead bs
197+ testBit# n = I# (((w `andWord8#` (wordToWord8# 1## `uncheckedShiftLWord8#` n)) `eqWord8#` wordToWord8# 0##) `xorI#` 1#)
198+
199+
185-- | Extract a range of bits from (ws :: ByteString)
200-- | Extract a range of bits from (ws :: ByteString)
186--
201--
187-- Constraint: 8 * (length ws -1 ) < o+n <= 8 * length ws
202-- Constraint: 8 * (length ws -1 ) < o+n <= 8 * length ws
@@ -363,6 +378,10 @@ isEmpty = B $ \ (S bs o bo) -> if B.null bs
363getBool :: BitGet Bool
378getBool :: BitGet Bool
364getBool = block bool
379getBool = block bool
365
380
381+-- | Get 1 bit as a 'Bool'.
382+getBool# :: BitGet Int
383+getBool# = block bool#
384+
366-- | Get @n@ bits as a 'Word8'. @n@ must be within @[0..8]@.
385-- | Get @n@ bits as a 'Word8'. @n@ must be within @[0..8]@.
367getWord8 :: Int -> BitGet Word8
386getWord8 :: Int -> BitGet Word8
368getWord8 n = block (word8 n)
387getWord8 n = block (word8 n)
@@ -438,6 +457,10 @@ block (Block i p) = do
438bool :: Block Bool
457bool :: Block Bool
439bool = Block 1 readBool
458bool = Block 1 readBool
440
459
460+-- | Read a 1 bit 'Bool'.
461+bool# :: Block Int
462+bool# = Block 1 readBool#
463+
441-- | Read @n@ bits as a 'Word8'. @n@ must be within @[0..8]@.
464-- | Read @n@ bits as a 'Word8'. @n@ must be within @[0..8]@.
442word8 :: Int -> Block Word8
465word8 :: Int -> Block Word8
443word8 n = Block n (readWordChecked 8 n)
466word8 n = Block n (readWordChecked 8 n)
flake.locknew file+59
@@ -0,0 +1,59 @@
1+{
2+ "nodes": {
3+ "flake-utils": {
4+ "inputs": {
5+ "systems": "systems"
6+ },
7+ "locked": {
8+ "lastModified": 1731533236,
9+ "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
10+ "owner": "numtide",
11+ "repo": "flake-utils",
12+ "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
13+ "type": "github"
14+ },
15+ "original": {
16+ "id": "flake-utils",
17+ "type": "indirect"
18+ }
19+ },
20+ "nixpkgs": {
21+ "locked": {
22+ "lastModified": 1737469691,
23+ "narHash": "sha256-nmKOgAU48S41dTPIXAq0AHZSehWUn6ZPrUKijHAMmIk=",
24+ "owner": "NixOS",
25+ "repo": "nixpkgs",
26+ "rev": "9e4d5190a9482a1fb9d18adf0bdb83c6e506eaab",
27+ "type": "github"
28+ },
29+ "original": {
30+ "id": "nixpkgs",
31+ "ref": "nixos-unstable",
32+ "type": "indirect"
33+ }
34+ },
35+ "root": {
36+ "inputs": {
37+ "flake-utils": "flake-utils",
38+ "nixpkgs": "nixpkgs"
39+ }
40+ },
41+ "systems": {
42+ "locked": {
43+ "lastModified": 1681028828,
44+ "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
45+ "owner": "nix-systems",
46+ "repo": "default",
47+ "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
48+ "type": "github"
49+ },
50+ "original": {
51+ "owner": "nix-systems",
52+ "repo": "default",
53+ "type": "github"
54+ }
55+ }
56+ },
57+ "root": "root",
58+ "version": 7
59+}
flake.nixnew file+24
@@ -0,0 +1,24 @@
1+{
2+ inputs = {
3+ nixpkgs.url = "nixpkgs/nixos-unstable";
4+ flake-utils.url = "flake-utils";
5+ };
6+
7+ outputs = { self, flake-utils, nixpkgs }:
8+ let
9+ supportedSystems =
10+ [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" "aarch64-linux" ];
11+ compilerVersion = "966";
12+ in flake-utils.lib.eachSystem supportedSystems (system:
13+ let pkgs = import nixpkgs { inherit system; };
14+ in {
15+ devShells.default = pkgs.mkShell {
16+ buildInputs = with pkgs; [
17+ haskell.compiler."ghc${compilerVersion}"
18+ (pkgs.haskell-language-server.override {
19+ supportedGhcVersions = [ compilerVersion ];
20+ })
21+ ];
22+ };
23+ });
24+}
stack.yaml+1−2
@@ -17,8 +17,7 @@
17#
17#
18# resolver: ./custom-snapshot.yaml
18# resolver: ./custom-snapshot.yaml
19# resolver: https://example.com/snapshots/2018-01-01.yaml
19# resolver: https://example.com/snapshots/2018-01-01.yaml
20−resolver:
20+resolver: lts-22.43
21− url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/6.yaml
22
21
23# User packages to be built.
22# User packages to be built.
24# Various formats can be used as shown in the example below.
23# Various formats can be used as shown in the example below.
stack.yaml.lock+4−5
@@ -6,8 +6,7 @@
6packages: []
6packages: []
7snapshots:
7snapshots:
8- completed:
8- completed:
9− sha256: 2e7d4a730d8eb5373b2d383fac84efcf7c81e3b7a5fce71b4c2e19a1768f25a6
9+ sha256: 08bd13ce621b41a8f5e51456b38d5b46d7783ce114a50ab604d6bbab0d002146
10− size: 640239
10+ size: 720271
11− url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/6.yaml
11+ url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/43.yaml
12− original:
12+ original: lts-22.43
13− url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/6.yaml