Better clang_cl support (#12896)

This commit is contained in:
cooldome 2019-12-13 12:12:04 +00:00 • committed by GitHub
commit 777c9ad0ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,6 +11,7 @@
{.push stackTrace:off, profiler:off.} {.push stackTrace:off, profiler:off.}
const someGcc = defined(gcc) or defined(llvm_gcc) or defined(clang) const someGcc = defined(gcc) or defined(llvm_gcc) or defined(clang)
const someVcc = defined(vcc) or defined(clang_cl)
type type
AtomType* = SomeNumber|pointer|ptr|char|bool AtomType* = SomeNumber|pointer|ptr|char|bool
@ -163,7 +164,7 @@ when someGcc and hasThreadSupport:
## ignore this parameter. ## ignore this parameter.
template fence*() = atomicThreadFence(ATOMIC_SEQ_CST) template fence*() = atomicThreadFence(ATOMIC_SEQ_CST)
elif defined(vcc) and hasThreadSupport: elif someVcc and hasThreadSupport:
type AtomMemModel* = distinct cint type AtomMemModel* = distinct cint
const const
@ -217,7 +218,7 @@ else:
proc atomicInc*(memLoc: var int, x: int = 1): int = proc atomicInc*(memLoc: var int, x: int = 1): int =
when someGcc and hasThreadSupport: when someGcc and hasThreadSupport:
result = atomicAddFetch(memLoc.addr, x, ATOMIC_RELAXED) result = atomicAddFetch(memLoc.addr, x, ATOMIC_RELAXED)
elif defined(vcc) and hasThreadSupport: elif someVcc and hasThreadSupport:
result = addAndFetch(memLoc.addr, x) result = addAndFetch(memLoc.addr, x)
inc(result, x) inc(result, x)
else: else:
@ -230,14 +231,14 @@ proc atomicDec*(memLoc: var int, x: int = 1): int =
result = atomicSubFetch(memLoc.addr, x, ATOMIC_RELAXED) result = atomicSubFetch(memLoc.addr, x, ATOMIC_RELAXED)
else: else:
result = atomicAddFetch(memLoc.addr, -x, ATOMIC_RELAXED) result = atomicAddFetch(memLoc.addr, -x, ATOMIC_RELAXED)
elif defined(vcc) and hasThreadSupport: elif someVcc and hasThreadSupport:
result = addAndFetch(memLoc.addr, -x) result = addAndFetch(memLoc.addr, -x)
dec(result, x) dec(result, x)
else: else:
dec(memLoc, x) dec(memLoc, x)
result = memLoc result = memLoc
when defined(vcc): when someVcc:
when defined(cpp): when defined(cpp):
proc interlockedCompareExchange64(p: pointer; exchange, comparand: int64): int64 proc interlockedCompareExchange64(p: pointer; exchange, comparand: int64): int64
{.importcpp: "_InterlockedCompareExchange64(static_cast<NI64 volatile *>(#), #, #)", header: "<intrin.h>".} {.importcpp: "_InterlockedCompareExchange64(static_cast<NI64 volatile *>(#), #, #)", header: "<intrin.h>".}
@ -321,7 +322,7 @@ else:
# XXX is this valid for 'int'? # XXX is this valid for 'int'?
when (defined(x86) or defined(amd64)) and defined(vcc): when (defined(x86) or defined(amd64)) and someVcc:
proc cpuRelax* {.importc: "YieldProcessor", header: "<windows.h>".} proc cpuRelax* {.importc: "YieldProcessor", header: "<windows.h>".}
elif (defined(x86) or defined(amd64)) and (someGcc or defined(bcc)): elif (defined(x86) or defined(amd64)) and (someGcc or defined(bcc)):
proc cpuRelax* {.inline.} = proc cpuRelax* {.inline.} =