
Hi John,
popCnt64# = let x = x in x
It represents "bottom, or undefined, or infinite loop" [1].
(Almost primitives can't be represented with Haskell language.)
In your case, It's good to use FFI call [2] like as Sylvain's nice code.
If you dig GHC compiler's primitives, followings [3][4] may be useful.
[1] https://www.fpcomplete.com/blog/2015/02/primitive-haskell
[2]
https://downloads.haskell.org/~ghc/master/users-guide/ffi-chap.html#primitiv...
[3] https://ghc.haskell.org/trac/ghc/wiki/Commentary/PrimOps
[4] http://www.well-typed.com/blog/2014/06/understanding-the-realworld/
Cheers,
Takenobu
2016-03-23 10:10 GMT+09:00 Sylvain Henry
Hi,
You can also test your primop with a foreign primop.
See here for an example of assembly code (calling cpuid):
https://github.com/hsyl20/ViperVM/blob/master/src/lib/ViperVM/Arch/X86_64/cp...
And here for the Haskell part with the foreign primop that calls the assembly code:
https://github.com/hsyl20/ViperVM/blob/master/src/lib/ViperVM/Arch/X86_64/Cp...
Cheers, Sylvain
On 23/03/2016 02:07, rahulmutt@gmail.com wrote:
Hi John,
ghc-prim is just a stub package generated for the purpose of documentation. All primops are defined in a low level language called Cmm in GHC. If you want to make it even faster, you'll need to learn Cmm and update the definition in GHC. If you want to a specialized implementation for x86 systems, you may need to modify the NCG (Native Code Generator) which requires a knowledge of assembly language.
Hope that helps! Rahul Muttineni
Sent from my BlackBerry 10 smartphone. *From: *John Ky *Sent: *Wednesday 23 March 2016 4:40 AM *To: *The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell *Reply To: *The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell *Subject: *[Haskell-beginners] let x = x in x (GHC.Prim)
Hello Haskellers,
I'm trying to write a faster popCount function for x86 systems.
I tried cloning the ghc-prim package and repurposing it for my own needs, but it isn't working as hoped.
In particular, popCnt64# was implemented in GHC.Prim as:
popCnt64# = let x = x in x
Which shouldn't terminate. Yet when I call it, it magically finds the C implementation in hs_popcnt64 and returns the correct value.
My cloned project doesn't behave that way. Instead it doesn't terminate as I would expect.
Anyone know what's happening here, if there is a way to make this work or tell me if I'm going about this completely the wrong way?
Cheers,
-John
_______________________________________________ Beginners mailing listBeginners@haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners