<div dir="ltr"><div>Hi John,</div><div><br></div><div>> popCnt64# = let x = x in x</div><div><br></div><div>It represents "bottom, or undefined, or infinite loop" [1].</div><div>(Almost primitives can't be represented with Haskell language.)</div><div><br></div><div><br></div><div>In your case, It's good to use FFI call [2] like as Sylvain's nice code.</div><div><br></div><div>If you dig GHC compiler's primitives, followings [3][4] may be useful.</div><div><br></div><div><br></div><div>[1] <a href="https://www.fpcomplete.com/blog/2015/02/primitive-haskell">https://www.fpcomplete.com/blog/2015/02/primitive-haskell</a></div><div>[2] <a href="https://downloads.haskell.org/~ghc/master/users-guide/ffi-chap.html#primitive-imports">https://downloads.haskell.org/~ghc/master/users-guide/ffi-chap.html#primitive-imports</a></div><div>[3] <a href="https://ghc.haskell.org/trac/ghc/wiki/Commentary/PrimOps">https://ghc.haskell.org/trac/ghc/wiki/Commentary/PrimOps</a></div><div>[4] <a href="http://www.well-typed.com/blog/2014/06/understanding-the-realworld/">http://www.well-typed.com/blog/2014/06/understanding-the-realworld/</a></div><div><br></div><div>Cheers,</div><div>Takenobu</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-03-23 10:10 GMT+09:00 Sylvain Henry <span dir="ltr"><<a href="mailto:sylvain@haskus.fr" target="_blank">sylvain@haskus.fr</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
Hi,<br>
<br>
You can also test your primop with a foreign primop.<br>
<br>
See here for an example of assembly code (calling cpuid):<br>
<a href="https://github.com/hsyl20/ViperVM/blob/master/src/lib/ViperVM/Arch/X86_64/cpuid.c" target="_blank">https://github.com/hsyl20/ViperVM/blob/master/src/lib/ViperVM/Arch/X86_64/cpuid.c</a><br>
<br>
And here for the Haskell part with the foreign primop that calls the
assembly code:<br>
<a href="https://github.com/hsyl20/ViperVM/blob/master/src/lib/ViperVM/Arch/X86_64/Cpuid.hs#L56" target="_blank">https://github.com/hsyl20/ViperVM/blob/master/src/lib/ViperVM/Arch/X86_64/Cpuid.hs#L56</a><br>
<br>
Cheers,<br>
Sylvain<div><div class="h5"><br>
<br>
<div>On 23/03/2016 02:07,
<a href="mailto:rahulmutt@gmail.com" target="_blank">rahulmutt@gmail.com</a> wrote:<br>
</div>
</div></div><blockquote type="cite"><div><div class="h5">
<div style="width:100%;font-size:initial;font-family:Calibri,'Slate Pro',sans-serif,sans-serif;color:rgb(31,73,125);text-align:initial;background-color:rgb(255,255,255)">Hi
John,</div>
<div style="width:100%;font-size:initial;font-family:Calibri,'Slate Pro',sans-serif,sans-serif;color:rgb(31,73,125);text-align:initial;background-color:rgb(255,255,255)"><br>
</div>
<div style="width:100%;font-size:initial;font-family:Calibri,'Slate Pro',sans-serif,sans-serif;color:rgb(31,73,125);text-align:initial;background-color:rgb(255,255,255)">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.</div>
<div style="width:100%;font-size:initial;font-family:Calibri,'Slate Pro',sans-serif,sans-serif;color:rgb(31,73,125);text-align:initial;background-color:rgb(255,255,255)"><br>
</div>
<div style="width:100%;font-size:initial;font-family:Calibri,'Slate Pro',sans-serif,sans-serif;color:rgb(31,73,125);text-align:initial;background-color:rgb(255,255,255)">Hope
that helps!</div>
<div style="width:100%;font-size:initial;font-family:Calibri,'Slate Pro',sans-serif,sans-serif;color:rgb(31,73,125);text-align:initial;background-color:rgb(255,255,255)">Rahul
Muttineni</div>
<div style="width:100%;font-size:initial;font-family:Calibri,'Slate Pro',sans-serif,sans-serif;color:rgb(31,73,125);text-align:initial;background-color:rgb(255,255,255)"><br style="display:initial">
</div>
<div style="font-size:initial;font-family:Calibri,'Slate Pro',sans-serif,sans-serif;color:rgb(31,73,125);text-align:initial;background-color:rgb(255,255,255)">Sent from my BlackBerry 10 smartphone.</div>
<table style="background-color:white;border-spacing:0px" width="100%">
<tbody>
<tr>
<td colspan="2" style="font-size:initial;text-align:initial;background-color:rgb(255,255,255)">
<div>
<div><b>From: </b>John Ky</div>
<div><b>Sent: </b>Wednesday 23 March 2016 4:40 AM</div>
<div><b>To: </b>The Haskell-Beginners Mailing List -
Discussion of primarily beginner-level topics related
to Haskell</div>
<div><b>Reply To: </b>The Haskell-Beginners Mailing
List - Discussion of primarily beginner-level topics
related to Haskell</div>
<div><b>Subject: </b>[Haskell-beginners] let x = x in x
(GHC.Prim)</div>
</div>
</td>
</tr>
</tbody>
</table>
<br>
<div>
<div dir="ltr">Hello Haskellers,
<div><br>
</div>
<div>I'm trying to write a faster popCount function for x86
systems.<br>
</div>
<div><br>
</div>
<div>I tried cloning the ghc-prim package and repurposing it
for my own needs, but it isn't working as hoped.</div>
<div><br>
</div>
<div>In particular, popCnt64# was implemented in GHC.Prim as:</div>
<div><br>
</div>
<div>popCnt64# = let x = x in x<br>
</div>
<div><br>
</div>
<div>Which shouldn't terminate. Yet when I call it, it
magically finds the C implementation in hs_popcnt64 and
returns the correct value.</div>
<div><br>
</div>
<div>My cloned project doesn't behave that way. Instead it
doesn't terminate as I would expect.</div>
<div><br>
</div>
<div>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?</div>
<div><br>
</div>
<div>Cheers,</div>
<div><br>
</div>
<div>-John</div>
<div><br>
</div>
</div>
<br>
</div>
<br>
<fieldset></fieldset>
<br>
</div></div><pre>_______________________________________________
Beginners mailing list
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a>
</pre>
</blockquote>
<br>
</div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>