never executed always true always false
    1 {-# LANGUAGE LambdaCase #-}
    2 
    3 -- | Generating C symbol names emitted by the compiler.
    4 module GHC.CmmToAsm.CPrim
    5     ( atomicReadLabel
    6     , atomicWriteLabel
    7     , atomicRMWLabel
    8     , cmpxchgLabel
    9     , xchgLabel
   10     , popCntLabel
   11     , pdepLabel
   12     , pextLabel
   13     , bSwapLabel
   14     , bRevLabel
   15     , clzLabel
   16     , ctzLabel
   17     , word2FloatLabel
   18     ) where
   19 
   20 import GHC.Cmm.Type
   21 import GHC.Cmm.MachOp
   22 import GHC.Data.FastString
   23 import GHC.Utils.Outputable
   24 import GHC.Utils.Panic
   25 
   26 popCntLabel :: Width -> FastString
   27 popCntLabel = \case
   28   W8  -> fsLit "hs_popcnt8"
   29   W16 -> fsLit "hs_popcnt16"
   30   W32 -> fsLit "hs_popcnt32"
   31   W64 -> fsLit "hs_popcnt64"
   32   w   -> pprPanic "popCntLabel: Unsupported word width " (ppr w)
   33 
   34 pdepLabel :: Width -> FastString
   35 pdepLabel = \case
   36   W8  -> fsLit "hs_pdep8"
   37   W16 -> fsLit "hs_pdep16"
   38   W32 -> fsLit "hs_pdep32"
   39   W64 -> fsLit "hs_pdep64"
   40   w   -> pprPanic "pdepLabel: Unsupported word width " (ppr w)
   41 
   42 pextLabel :: Width -> FastString
   43 pextLabel = \case
   44   W8  -> fsLit "hs_pext8"
   45   W16 -> fsLit "hs_pext16"
   46   W32 -> fsLit "hs_pext32"
   47   W64 -> fsLit "hs_pext64"
   48   w   -> pprPanic "pextLabel: Unsupported word width " (ppr w)
   49 
   50 bSwapLabel :: Width -> FastString
   51 bSwapLabel = \case
   52   W16 -> fsLit "hs_bswap16"
   53   W32 -> fsLit "hs_bswap32"
   54   W64 -> fsLit "hs_bswap64"
   55   w   -> pprPanic "bSwapLabel: Unsupported word width " (ppr w)
   56 
   57 bRevLabel :: Width -> FastString
   58 bRevLabel = \case
   59   W8  -> fsLit "hs_bitrev8"
   60   W16 -> fsLit "hs_bitrev16"
   61   W32 -> fsLit "hs_bitrev32"
   62   W64 -> fsLit "hs_bitrev64"
   63   w   -> pprPanic "bRevLabel: Unsupported word width " (ppr w)
   64 
   65 clzLabel :: Width -> FastString
   66 clzLabel = \case
   67   W8  -> fsLit "hs_clz8"
   68   W16 -> fsLit "hs_clz16"
   69   W32 -> fsLit "hs_clz32"
   70   W64 -> fsLit "hs_clz64"
   71   w   -> pprPanic "clzLabel: Unsupported word width " (ppr w)
   72 
   73 ctzLabel :: Width -> FastString
   74 ctzLabel = \case
   75   W8  -> fsLit "hs_ctz8"
   76   W16 -> fsLit "hs_ctz16"
   77   W32 -> fsLit "hs_ctz32"
   78   W64 -> fsLit "hs_ctz64"
   79   w   -> pprPanic "ctzLabel: Unsupported word width " (ppr w)
   80 
   81 word2FloatLabel :: Width -> FastString
   82 word2FloatLabel = \case
   83   W32 -> fsLit "hs_word2float32"
   84   W64 -> fsLit "hs_word2float64"
   85   w   -> pprPanic "word2FloatLabel: Unsupported word width " (ppr w)
   86 
   87 atomicRMWLabel :: Width -> AtomicMachOp -> FastString
   88 atomicRMWLabel w amop = case amop of
   89   -- lots of boring cases, but we do it this way to get shared FastString
   90   -- literals (compared to concatening strings and allocating FastStrings at
   91   -- runtime)
   92   AMO_Add  -> case w of
   93     W8  -> fsLit "hs_atomic_add8"
   94     W16 -> fsLit "hs_atomic_add16"
   95     W32 -> fsLit "hs_atomic_add32"
   96     W64 -> fsLit "hs_atomic_add64"
   97     _   -> pprPanic "atomicRMWLabel: Unsupported word width " (ppr w)
   98   AMO_Sub  -> case w of
   99     W8  -> fsLit "hs_atomic_sub8"
  100     W16 -> fsLit "hs_atomic_sub16"
  101     W32 -> fsLit "hs_atomic_sub32"
  102     W64 -> fsLit "hs_atomic_sub64"
  103     _   -> pprPanic "atomicRMWLabel: Unsupported word width " (ppr w)
  104   AMO_And  -> case w of
  105     W8  -> fsLit "hs_atomic_and8"
  106     W16 -> fsLit "hs_atomic_and16"
  107     W32 -> fsLit "hs_atomic_and32"
  108     W64 -> fsLit "hs_atomic_and64"
  109     _   -> pprPanic "atomicRMWLabel: Unsupported word width " (ppr w)
  110   AMO_Nand  -> case w of
  111     W8  -> fsLit "hs_atomic_nand8"
  112     W16 -> fsLit "hs_atomic_nand16"
  113     W32 -> fsLit "hs_atomic_nand32"
  114     W64 -> fsLit "hs_atomic_nand64"
  115     _   -> pprPanic "atomicRMWLabel: Unsupported word width " (ppr w)
  116   AMO_Or  -> case w of
  117     W8  -> fsLit "hs_atomic_or8"
  118     W16 -> fsLit "hs_atomic_or16"
  119     W32 -> fsLit "hs_atomic_or32"
  120     W64 -> fsLit "hs_atomic_or64"
  121     _   -> pprPanic "atomicRMWLabel: Unsupported word width " (ppr w)
  122   AMO_Xor  -> case w of
  123     W8  -> fsLit "hs_atomic_xor8"
  124     W16 -> fsLit "hs_atomic_xor16"
  125     W32 -> fsLit "hs_atomic_xor32"
  126     W64 -> fsLit "hs_atomic_xor64"
  127     _   -> pprPanic "atomicRMWLabel: Unsupported word width " (ppr w)
  128 
  129 
  130 xchgLabel :: Width -> FastString
  131 xchgLabel = \case
  132   W8  -> fsLit "hs_xchg8"
  133   W16 -> fsLit "hs_xchg16"
  134   W32 -> fsLit "hs_xchg32"
  135   W64 -> fsLit "hs_xchg64"
  136   w   -> pprPanic "xchgLabel: Unsupported word width " (ppr w)
  137 
  138 cmpxchgLabel :: Width -> FastString
  139 cmpxchgLabel = \case
  140   W8  -> fsLit "hs_cmpxchg8"
  141   W16 -> fsLit "hs_cmpxchg16"
  142   W32 -> fsLit "hs_cmpxchg32"
  143   W64 -> fsLit "hs_cmpxchg64"
  144   w   -> pprPanic "cmpxchgLabel: Unsupported word width " (ppr w)
  145 
  146 atomicReadLabel :: Width -> FastString
  147 atomicReadLabel = \case
  148   W8  -> fsLit "hs_atomicread8"
  149   W16 -> fsLit "hs_atomicread16"
  150   W32 -> fsLit "hs_atomicread32"
  151   W64 -> fsLit "hs_atomicread64"
  152   w   -> pprPanic "atomicReadLabel: Unsupported word width " (ppr w)
  153 
  154 atomicWriteLabel :: Width -> FastString
  155 atomicWriteLabel = \case
  156   W8  -> fsLit "hs_atomicwrite8"
  157   W16 -> fsLit "hs_atomicwrite16"
  158   W32 -> fsLit "hs_atomicwrite32"
  159   W64 -> fsLit "hs_atomicwrite64"
  160   w   -> pprPanic "atomicWriteLabel: Unsupported word width " (ppr w)