Add support for bitreverse primop
[ghc.git] / compiler / nativeGen / CPrim.hs
1 -- | Generating C symbol names emitted by the compiler.
2 module CPrim
3 ( atomicReadLabel
4 , atomicWriteLabel
5 , atomicRMWLabel
6 , cmpxchgLabel
7 , popCntLabel
8 , pdepLabel
9 , pextLabel
10 , bSwapLabel
11 , bRevLabel
12 , clzLabel
13 , ctzLabel
14 , word2FloatLabel
15 ) where
16
17 import GhcPrelude
18
19 import CmmType
20 import CmmMachOp
21 import Outputable
22
23 popCntLabel :: Width -> String
24 popCntLabel w = "hs_popcnt" ++ pprWidth w
25 where
26 pprWidth W8 = "8"
27 pprWidth W16 = "16"
28 pprWidth W32 = "32"
29 pprWidth W64 = "64"
30 pprWidth w = pprPanic "popCntLabel: Unsupported word width " (ppr w)
31
32 pdepLabel :: Width -> String
33 pdepLabel w = "hs_pdep" ++ pprWidth w
34 where
35 pprWidth W8 = "8"
36 pprWidth W16 = "16"
37 pprWidth W32 = "32"
38 pprWidth W64 = "64"
39 pprWidth w = pprPanic "pdepLabel: Unsupported word width " (ppr w)
40
41 pextLabel :: Width -> String
42 pextLabel w = "hs_pext" ++ pprWidth w
43 where
44 pprWidth W8 = "8"
45 pprWidth W16 = "16"
46 pprWidth W32 = "32"
47 pprWidth W64 = "64"
48 pprWidth w = pprPanic "pextLabel: Unsupported word width " (ppr w)
49
50 bSwapLabel :: Width -> String
51 bSwapLabel w = "hs_bswap" ++ pprWidth w
52 where
53 pprWidth W16 = "16"
54 pprWidth W32 = "32"
55 pprWidth W64 = "64"
56 pprWidth w = pprPanic "bSwapLabel: Unsupported word width " (ppr w)
57
58 bRevLabel :: Width -> String
59 bRevLabel w = "hs_bitrev" ++ pprWidth w
60 where
61 pprWidth W8 = "8"
62 pprWidth W16 = "16"
63 pprWidth W32 = "32"
64 pprWidth W64 = "64"
65 pprWidth w = pprPanic "bRevLabel: Unsupported word width " (ppr w)
66
67 clzLabel :: Width -> String
68 clzLabel w = "hs_clz" ++ pprWidth w
69 where
70 pprWidth W8 = "8"
71 pprWidth W16 = "16"
72 pprWidth W32 = "32"
73 pprWidth W64 = "64"
74 pprWidth w = pprPanic "clzLabel: Unsupported word width " (ppr w)
75
76 ctzLabel :: Width -> String
77 ctzLabel w = "hs_ctz" ++ pprWidth w
78 where
79 pprWidth W8 = "8"
80 pprWidth W16 = "16"
81 pprWidth W32 = "32"
82 pprWidth W64 = "64"
83 pprWidth w = pprPanic "ctzLabel: Unsupported word width " (ppr w)
84
85 word2FloatLabel :: Width -> String
86 word2FloatLabel w = "hs_word2float" ++ pprWidth w
87 where
88 pprWidth W32 = "32"
89 pprWidth W64 = "64"
90 pprWidth w = pprPanic "word2FloatLabel: Unsupported word width " (ppr w)
91
92 atomicRMWLabel :: Width -> AtomicMachOp -> String
93 atomicRMWLabel w amop = "hs_atomic_" ++ pprFunName amop ++ pprWidth w
94 where
95 pprWidth W8 = "8"
96 pprWidth W16 = "16"
97 pprWidth W32 = "32"
98 pprWidth W64 = "64"
99 pprWidth w = pprPanic "atomicRMWLabel: Unsupported word width " (ppr w)
100
101 pprFunName AMO_Add = "add"
102 pprFunName AMO_Sub = "sub"
103 pprFunName AMO_And = "and"
104 pprFunName AMO_Nand = "nand"
105 pprFunName AMO_Or = "or"
106 pprFunName AMO_Xor = "xor"
107
108 cmpxchgLabel :: Width -> String
109 cmpxchgLabel w = "hs_cmpxchg" ++ pprWidth w
110 where
111 pprWidth W8 = "8"
112 pprWidth W16 = "16"
113 pprWidth W32 = "32"
114 pprWidth W64 = "64"
115 pprWidth w = pprPanic "cmpxchgLabel: Unsupported word width " (ppr w)
116
117 atomicReadLabel :: Width -> String
118 atomicReadLabel w = "hs_atomicread" ++ pprWidth w
119 where
120 pprWidth W8 = "8"
121 pprWidth W16 = "16"
122 pprWidth W32 = "32"
123 pprWidth W64 = "64"
124 pprWidth w = pprPanic "atomicReadLabel: Unsupported word width " (ppr w)
125
126 atomicWriteLabel :: Width -> String
127 atomicWriteLabel w = "hs_atomicwrite" ++ pprWidth w
128 where
129 pprWidth W8 = "8"
130 pprWidth W16 = "16"
131 pprWidth W32 = "32"
132 pprWidth W64 = "64"
133 pprWidth w = pprPanic "atomicWriteLabel: Unsupported word width " (ppr w)