www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - popcnt instruction

reply "Archibald" <archiblad fake-mail.org> writes:
Hello,
I need to use the "popcnt" processor instruction in a performance 
critical section.
Is there a way to do this in D?
Jun 24 2014
parent reply Justin Whear <justin economicmodeling.com> writes:
On Tue, 24 Jun 2014 16:34:42 +0000, Archibald wrote:

 Hello,
 I need to use the "popcnt" processor instruction in a performance
 critical section.
 Is there a way to do this in D?
D's inline assembler is described here: http://dlang.org/iasm.html
Jun 24 2014
parent reply "Rene Zwanenburg" <renezwanenburg gmail.com> writes:
On Tuesday, 24 June 2014 at 17:05:24 UTC, Justin Whear wrote:
 On Tue, 24 Jun 2014 16:34:42 +0000, Archibald wrote:

 Hello,
 I need to use the "popcnt" processor instruction in a 
 performance
 critical section.
 Is there a way to do this in D?
D's inline assembler is described here: http://dlang.org/iasm.html
There's also an intrinsic in core.bitop: http://dlang.org/library/core/bitop/popcnt.html
Jun 24 2014
parent reply "Archibald" <archibald fake-mail.org> writes:
On Tuesday, 24 June 2014 at 17:27:09 UTC, Rene Zwanenburg wrote:
 On Tuesday, 24 June 2014 at 17:05:24 UTC, Justin Whear wrote:
 On Tue, 24 Jun 2014 16:34:42 +0000, Archibald wrote:

 Hello,
 I need to use the "popcnt" processor instruction in a 
 performance
 critical section.
 Is there a way to do this in D?
D's inline assembler is described here: http://dlang.org/iasm.html
There's also an intrinsic in core.bitop: http://dlang.org/library/core/bitop/popcnt.html
Thanks for the answers. Unfortunately it seems like popcnt isn't supported by D's inline assembler. What if I import it as an external C function, will I get optimal performance?
Jun 24 2014
parent reply Justin Whear <justin economicmodeling.com> writes:
On Tue, 24 Jun 2014 19:44:52 +0000, Archibald wrote:

 Thanks for the answers.
 Unfortunately it seems like popcnt isn't supported by D's inline
 assembler.
 What if I import it as an external C function, will I get optimal
 performance?
DMD 2.065 seems to support it. What compiler are you using and what errors are you getting?
Jun 24 2014
parent reply Justin Whear <justin economicmodeling.com> writes:
Also, see: 
http://forum.dlang.org/thread/alirjgygnwpifkijxtjo forum.dlang.org
Jun 24 2014
parent "Archibald" <archibald fake-mail.org> writes:
On Tuesday, 24 June 2014 at 19:56:29 UTC, Justin Whear wrote:
 Also, see:
 http://forum.dlang.org/thread/alirjgygnwpifkijxtjo forum.dlang.org
"its not documented on the inline assembler page." That's why I thought it wasn't supported, it's not in the list of supported opcodes. Thanks for the help!
Jun 24 2014