Merge pull request #43 from status-im/fix_vcc_bitops2

fix bitops2 checkedScan and bitScan for vcc
This commit is contained in:
andri lim 2020-06-19 20:22:34 +07:00 committed by GitHub
commit 188230a368
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 4 deletions

View File

@ -34,6 +34,10 @@ build_script:
test_script:
- nimble test
- IF "%PLATFORM%" == "x86" CALL "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86
- IF "%PLATFORM%" == "x64" CALL "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64
- IF "%PLATFORM%" == "x64" CALL "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64
- nimble testvcc
deploy: off

1
.gitignore vendored
View File

@ -1 +1,2 @@
nimcache
*.exe

View File

@ -12,3 +12,7 @@ requires "nim >= 1.2.0"
task test, "Run all tests":
exec "nim c -r --threads:off tests/all_tests"
exec "nim c -r --threads:on -d:nimTypeNames tests/all_tests"
task testvcc, "Run all tests with vcc compiler":
exec "nim c -r --cc:vcc --threads:off tests/all_tests"
exec "nim c -r --cc:vcc --threads:on -d:nimTypeNames tests/all_tests"

View File

@ -253,12 +253,12 @@ elif defined(vcc) and useBuiltins:
template checkedScan(fnc: untyped, x: typed, def: typed): int =
var index{.noinit.}: culong
if fnc(index.addr, v) == 0: def
if fnc(index.addr, v).int == 0: def
else: index.int
template bitScan(fnc: untyped, x: typed): int =
var index{.noinit.}: culong
if fnc(index.addr, v) == 0: 0
if fnc(index.addr, v).int == 0: 0
else: index.int
func countOnesBuiltin(v: uint8|uint16|uint32): int = builtin_popcnt32(v.uint32).int
@ -266,8 +266,8 @@ elif defined(vcc) and useBuiltins:
when arch64:
builtin_popcnt64(v).int
else:
builtin_popcnt32((v and 0xFFFFFFFF'u64).uint32).int +
builtin_popcnt32((v shr 32'u64).uint32).int
builtin_popcnt32((v and 0xFFFFFFFF'u64).cint).int +
builtin_popcnt32((v shr 32'u64).cint).int
func firstOneBuiltin(v: uint8|uint16|uint32): int =
1 + checkedScan(bitScanForward, v.culong, -1)

4
tests/nim.cfg Normal file
View File

@ -0,0 +1,4 @@
vcc.exe = "cl.exe"
vcc.cpp.exe = "cl.exe"
vcc.linkerexe = "cl.exe"
vcc.cpp.linkerexe = "cl.exe"