# Volk: \_\_cpuid\_count() for MSVC

**URL:** <https://www.ruby-forum.com/t/volk-cpuid-count-for-msvc/243275>\
**Category:** GNU Radio\
**Created:** [September 7, 2015, 4:33pm UTC](https://www.ruby-forum.com/t/volk-cpuid-count-for-msvc/243275 "2015-09-07T16:33:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [September 7, 2015, 4:33pm UTC](https://www.ruby-forum.com/t/volk-cpuid-count-for-msvc/243275/1 "2015-09-07T16:33:08Z")

</div>

I noticed since last time (a year ago) I tried building  
Volk using MSVC v16, the volk\_cpu.tmp.c now uses the  
gcc-centric function ‘\_\_cpuid\_count()’ which MSVC doesn’t  
have.

I’m not really sure if the below patch is correct. But I  
assume (from looking at gcc 5.1’s source) that the ECX should  
be loaded with the ‘count’ value. So could it be patched into  
something like this?

— a/volk/tmpl/volk\_cpu.tmpl.c 2015-09-01 13:52:53  
+++ b/volk\_cpu.tmpl.c 2015-09-07 13:44:25  
@@ -71,8 +71,16 @@

static inline unsigned int cpuid\_count\_x86\_bit(unsigned int level,  
unsigned int count, unsigned int reg, unsigned int  
bit) {  
#if defined(VOLK\_CPU\_x86)

- #if defined(\_MSC\_VER) && defined(HAVE\_INTRIN\_H)
- 

```
 int regs[4];

```

- 

```
 __cpuidex(regs, level, count);

```

- #elif defined( **GNUC** )  
unsigned int regs[4];  
\_\_cpuid\_count(level, count, regs[0], regs[1], regs[2], regs[3]);
- #else
- 

```
 #error No __cpuid()!

```

- #endif  
return regs[reg] \>\> bit & 0x01;  
#else  
return 0;

* * *

Just to let you know.

The docs on MSVC’s \_\_cpuidex() is here:  
[\_\_cpuid, \_\_cpuidex | Microsoft Learn](https://msdn.microsoft.com/en-us/library/vstudio/hskdteyh(v=vs.100).aspx)

–  
–gv
