Can I somehow use inline assembly in Haskell (similar to what GCC does for C)?
I want to compare my Haskell code to the reference implementation (ASM) and this seems the most straightforward way. I guess I could just call Haskell from C and use GCC inline assembly, but I’m still interested if I can do it the other way around.
(I’m on Linux/x86)
There are two ways:
Both solutions use inline assembly on the C side. The former is the most idiomatic. Here’s an example, from the rdtsc package:
cycles.h:
rdtsc.c:
rdtsc.h:
rdtsc.hs:
Finally: