Calling C compiler builtins -- it is fast!

2016-12-27 Thread Stefan_Salewski
Recently I read: 
[http://lemire.me/blog/2014/02/14/getting-good-performance-in-go-by-rewriting-parts-in-c](http://forum.nim-lang.org///lemire.me/blog/2014/02/14/getting-good-performance-in-go-by-rewriting-parts-in-c)/

So I thought it was time to try it in Nim:


import random
import times

# https://gcc.gnu.org/onlinedocs/gcc-4.5.3/gcc/Other-Builtins.html
# Nim/lib/system/arithm.nim
when sizeof(clong) == 8:
  proc popcount[T: int64|int](a: T): cint {.
importc: "__builtin_popcountl", nodecl, nosideeffect.}

proc test =
  var
s: array[1024, int]
c: cint
d: int
t: float
  
  for i in 0 .. s.high: s[i] = random(8) # = 3
  
  t = cpuTime()
  for i in s:
c += popcount(i)
  echo "Time for popcount(): ", cpuTime() - t
  echo c
  
  t = cpuTime()
  for i in s:
d += i
  echo "Time for add: ", cpuTime() - t
  echo d

test()



$ nim c -d:release pc.nim
$ ./pc
Time for popcount(): 3.989e-06
1492
Time for add: 1.024e-06
3449


Less than 4 ns for a popcount operation. 


Re: GTK 3.20 Nim wrapper

2016-12-27 Thread vlad1777d
again I missed a book )

Stefan_Salewski, it's good news =) I had some work several days, so I'll try to 
test it as soon as possible =) Thank you all =)


Re: Getting a segfault when testing my C wrapper on OS X

2016-12-27 Thread xomachine
First four cuchars of data may be looking like a regular pointer address. Have 
you performed a comparsion between first bytes of data(actual data, not a 
pointer) from the working test and bytes in this invalid pointer? It is not 
very likely but the data might be dereferenced somehow in the generated code.

As long as Nim directly translates to C before compilation, it would be useful 
to compare the generated C code from nimcache directory in both of the working 
mini-wrapper and the failing test to collect more clues.


Re: lib\wrappers\\pdcurses.nim(43, 10) error : cannot open windows

2016-12-27 Thread Krux02
It is hard to reproduce this error with this report. Can you say how you got 
this error? Nim version? Did you use aporia? If not which command line did you 
use to compile the program? What is your sourcecode that you compiled? And can 
you paste the entire output of the compiler?


lib\wrappers\\pdcurses.nim(43, 10) error : cannot open windows

2016-12-27 Thread henry75
when i begin start learn nim language , i write a cursers program, then the 
error present, i comment line 43 , but new error present. i not find the answer 
in doc page and forum ...

src file content

import pdcurses initscr();


Re: Chocolatey Package for Nim?

2016-12-27 Thread hcorion
Yeah, the chocolatey package is unmaintanied by a 3rd party and has been for a 
while. You could file to go through the process to take over the package.


Re: Getting a segfault when testing my C wrapper on OS X

2016-12-27 Thread def_pri_pub
Alright, I tried that and it does echo out a pointer address (e.g. 0xFFff08b7e).

Where this is getting kind of weird for me is that I have this raytracer that 
I'm working on that uses stb_image.h as well and it able to load an image on OS 
X without throwing a seg fault. The code for the mini-wrapper is here: 
[https://gitlab.com/define-private-public/PeterShirley-RayTracing-Nim/blob/7130281eee79c76be8e0c6ecb6dc36c99ab5aa52/book2/stb_image.nim](https://gitlab.com/define-private-public/PeterShirley-RayTracing-Nim/blob/7130281eee79c76be8e0c6ecb6dc36c99ab5aa52/book2/stb_image.nim)

The only major difference is that the wrapper in the ray tracer doesn't have 
the header file embedded directly in a .nim file, though that shouldn't matter.

I am really perplexed by this.