Reputation: 629
The following code should work at Linux. I want port the following code to Visual Studio 2008, but I am not very familiar with asm code. Could you help me?
#include <stdint.h>
static inline uint32_t log2(const uint32_t x) {
uint32_t y;
asm ( "\tbsr %1, %0\n"
: "=r"(y)
: "r" (x)
);
return y;
}
Upvotes: 1
Views: 328
Reputation:
GCC uses the AT&T syntax. MSVC uses Intel syntax. That function would look something like this (compiles with MSVC 2010 /16.00.40219.01
, but I see no reason why it would fail on 2008):
static inline uint32_t log2(const uint32_t x) {
uint32_t y;
__asm {
bsr eax, x
mov y, eax
}
return y;
}
Upvotes: 2