Hi.

As I mentionned in a previous post, I would have liked to have a "relaxed" 
fetch_and_add, which also works on Windows. Such a method only exists starting 
with Windows 8 (interlockedExchangeAddNoFence64), which I thought was too 
limiting; there are still people out there with Windows 7 that I might want to 
"target" (anything below that is uninteresting). It seems that to be able to 
use interlockedExchangeAddNoFence64() "conditionally" on Windows 8+, I would 
either have to build a "Windows 8" version, and a "Windows 7" version, or put 
the code in a dynamically loaded DLL. This felt like an overkill for just one 
single function. Also, it would have meant using interlockedExchangeAdd64() 
(with fence) instead on Windows 7, which was also stupid, since it's a CPU 
feature, not an OS one.

So I searched and found out that it's basically trivial to implement under 
Intel, as defined in 
[Wikipedia](https://en.wikipedia.org/wiki/Fetch-and-add#x86_implementation) All 
you need is a "lock; xaddl %0, %1". So I set out to try to do the same in Nim, 
but it failed to compile. So I tried the Nim example for ASM usage, and it also 
failed to compile:
    
    
    {.push stackTrace:off.}
    proc addInt(a, b: int): int =
      # a in eax, and b in edx
      asm """
          mov eax, `a`
          add eax, `b`
          jno theEnd
          call `raiseOverflow`
        theEnd:
      """
    {.pop.}
    

Which produces:
    
    
    cl.exe /c /nologo /Z7 /IC:\nim-0.17.2\lib /Fo...atomiks.obj ...atomiks.c
    geth_atomiks.c
    ...atomiks.c(44): error C4235: nonstandard extension used: '__asm' keyword 
not supported on this architecture
    ...atomiks.c(45): error C2065: 'mov': undeclared identifier
    ...atomiks.c(45): error C2146: syntax error: missing ';' before identifier 
'eax'
    

Searching for "error C4235: nonstandard extension used: '__asm' keyword not 
supported on this architecture", I read in several places things like "Inline 
asm on 64bit development is not a supported scenario ...".

So, basically, since x86 apps are dying out, and (almost) nobody owns a 32-bit 
Windows anymore, ASM on Windows is dead? Or am I missing something?

By now, I think that giving up on Windows 7 is probably the rational thing to 
do; anything else is overkill. 

Reply via email to