# \[ANN\] cpu-features 0.1.0.0

**URL:** https://discourse.haskell.org/t/ann-cpu-features-0-1-0-0/11925
**Category:** Announcements
**Created:** [April 26, 2025, 7:03am UTC](https://discourse.haskell.org/t/ann-cpu-features-0-1-0-0/11925 "2025-04-26T07:03:01Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![aratamizuki](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/aratamizuki/32/1633_2.png) [@aratamizuki](https://discourse.haskell.org/u/aratamizuki)
#### Post date: [April 26, 2025, 7:03am UTC](https://discourse.haskell.org/t/ann-cpu-features-0-1-0-0/11925/1 "2025-04-26T07:03:01Z")

</div>

I’m happy to announce the release of [cpu-features 0.1.0.0](https://hackage.haskell.org/package/cpu-features-0.1.0.0).

This is a library to detect the features provided by the CPU running the Haskell program. It supports multiple architectures (x86/AArch64/RISC-V) and has no external dependency.

It has three interfaces: One that returns `Bool`:

```haskell
$ cabal repl --build-depends cpu-features
ghci> :m + System.CPUFeatures.X86
ghci> bAVX2
True
ghci> bFMA
True
ghci> bAVX10_2
False

```

One that uses type-level booleans:

```haskell
ghci> :m + System.CPUFeatures.X86.TypeBool
ghci> :k AVX2 -- type-level boolean
AVX2 :: Bool
ghci> :t sAVX2 -- SBool is the singleton type for Bool
sAVX2 :: SBool AVX2
ghci> :set -XMonoLocalBinds
ghci> (case sAVX2 of STrue -> "Yes"; SFalse -> "No") :: String
"Yes"

```

And finally, one that uses nullary constraints:

```haskell
ghci> :m + System.CPUFeatures.X86.Constraint
ghci> :k HasAVX2 -- nullary constraint
HasAVX2 :: Constraint
ghci> :t queryAVX2
queryAVX2 :: Maybe (Dict HasAVX2)
ghci> case queryAVX2 of Just Dict -> "Yes"; Nothing -> "No"
"Yes"

```

With the type-level interface, it becomes possible to annotate your function that it requires a specific CPU feature:

```haskell
someSpecializedImplementationForAVX2 :: HasAVX2 => SomeResult
someFallbackImplementation :: SomeResult

someUserCode = case queryAVX2 of
  Just Dict -> someSpecializedImplementationForAVX2
  Nothing -> someFallbackImplementation

```

Please report any bugs or feature requests on [the GitHub repo](https://github.com/minoki/haskell-cpu-features). Thank you for reading!

---

<div class="post-metadata">

### Author: ![supersven](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/supersven/32/3876_2.png) [@supersven](https://discourse.haskell.org/u/supersven)
#### Post date: [May 1, 2025, 7:49am UTC](https://discourse.haskell.org/t/ann-cpu-features-0-1-0-0/11925/2 "2025-05-01T07:49:39Z")

</div>

That’s interesting and might become very useful when SIMD primops get wider adoption (as you probably know, these rely on specific CPU features.) 👍

Some ideas for future features:

- In the GHC project we’re using an abandoned Python package to figure out CPU features for the testsuite ([testsuite/driver/cpuinfo.py · d99a617bf1c104760e53c294cbe0b6ea752cd242 · Glasgow Haskell Compiler / GHC · GitLab](https://gitlab.haskell.org/ghc/ghc/-/blob/d99a617bf1c104760e53c294cbe0b6ea752cd242/testsuite/driver/cpuinfo.py)). Have you considered to replace this?
- Have you considered to target more Tier-2 platforms, e.g. PowerPC?

---

<div class="post-metadata">

### Author: ![aratamizuki](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/aratamizuki/32/1633_2.png) [@aratamizuki](https://discourse.haskell.org/u/aratamizuki)
#### Post date: [May 4, 2025, 4:38am UTC](https://discourse.haskell.org/t/ann-cpu-features-0-1-0-0/11925/3 "2025-05-04T04:38:56Z")

</div>

Thanks!

As for the testsuite, I’m not sure if a Haskell package can be used there. So I don’t plan to replace it.

If there is demand for the platform, I would like to support it.
