{-# LANGUAGE MagicHash #-} module Example where import GHC.Exts import Data.Word import Data.Bits utf8LengthByLeader :: Word8 -> Int utf8LengthByLeader w = c `xor` I# (c# <=# 0#) where !c@(I# c#) = countLeadingZeros (complement w)