views:

442

answers:

2

I need to use the popcnt instruction in a project that is compiled using Visual Stdio 2005
The intrinsic __popcnt() only works with VS2008 and the compiler doesn't seem to recognize the instruction even when I write in a __asm {} block.

Is there any way to do this?

+3  A: 

Okay, this is a wild guess thing but ... assuming you've set up VS2005 like this to do assembly language, then you could get a hold of the SSE4.1 manual from Intel and code a macro for each SSE4.1 opcode that you needed as per this thread at masm32.com (which discusses a similar issue w.r.t. SSE2.)

For example, here's some code out of one of the downloads from the masm32 link:

;SSE2 macros for MASM 6.14 by daydreamer aka Magnus Svensson

ADDPD MACRO M1,M2
    db 066h
    ADDPS M1,M2
ENDM

ADDSD MACRO M1,M2
    DB 0F2H
    ADDPS M1,M2
ENDM
boost
+2  A: 

As a small note, you can use __emit to put bytes into __asm blocks in VC++. This is easier in a lot of cases than linking with masm produced objects. I used this in the past when SSE3 was new (and the opcodes were not supported in VS 2003).

All of the opcodes are well documented by Intel.

jheriko