Ah, also throw in the following:<br><div class="gmail_quote"><div> * (declare (not interrupts-enabled))</div><div><br></div><div>   This might be a big deal - when it's off, Gambit doesn't produce any hooks for stack overflow or thread system interrupts but executes your code according to a typical C model</div>


<div><br> * (declare (standard-bindings) (extended-bindings)) too?<div><br></div><div><br></div><div>What is the performance you get from Gambit now, and what kind of performance is it you want to get?</div><div><div class="h5">

<div><br><br><div class="gmail_quote">
2012/11/4 tcl super dude <span dir="ltr"><<a href="mailto:tcleval@gmail.com" target="_blank">tcleval@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<div>I assumed I could get a bit of performance improvement over min procedure because I don't do any branch. I' thought  min-integer to be at least close to gambit-c time. The problem is that those operations and a few more are performed thousands of times. Gambit loops are usually 2x slower than C, so I hoped I could improve some basic operations as I only perform them on integers. I don't Understand how a simple shift to extract the lower bits could make so much difference. Maybe if someone point me to the implementation of min and abs on gambit, I can understand the difference. I ve looked for these procedures on gambit's source but could not point it out.</div>



<div><br></div><div>I'll try to implement them using vectors and see what happens.</div><div><br></div><div>now compiled with (block):</div><div><br></div><div><br></div><div><div><div>abs:                                                                                                                                          </div>



<div>(time (let loop-i ((i 0)) (cond ((fx< i 100000) (set! result (abs i)) (loop-i (fx+ 1 i))))))                                                  </div><div>    2 ms real time                                                                                                                            </div>



<div>    3 ms cpu time (3 user, 0 system)                                                                                                          </div><div>    no collections                                                                                                                            </div>



<div>    no bytes allocated                                                                                                                        </div><div>    no minor faults                                                                                                                           </div>



<div>    no major faults                                                                                                                           </div><div>abs-integer:                                                                                                                                  </div>



<div>(time (let loop-j ((j 0)) (cond ((fx< j 100000) (set! result (abs-integer j)) (loop-j (fx+ 1 j))))))                                          </div></div><div>    19 ms real time                                                                                                                           </div>



<div>    20 ms cpu time (17 user, 3 system)                                                                                                        </div><div><div>    no collections                                                                                                                            </div>



<div>    no bytes allocated                                                                                                                        </div><div>    2 minor faults                                                                                                                            </div>



<div>    no major faults                                                                                                                           </div><div>min:                                                                                                                                          </div>



<div>(time (let loop-i ((i 0)) (cond ((fx< i 100000) (set! result (min i result)) (loop-i (fx+ 1 i))))))                                           </div><div>    2 ms real time                                                                                                                            </div>



<div>    3 ms cpu time (0 user, 3 system)                                                                                                          </div><div>    no collections                                                                                                                            </div>



<div>    no bytes allocated                                                                                                                        </div><div>    no minor faults</div><div>    no major faults</div><div>min-integer:</div>



<div>(time (let loop-j ((j 0)) (cond ((fx< j 100000) (set! result (min-integer j result)) (loop-j (fx+ 1 j))))))</div></div><div>    27 ms real time</div><div>    27 ms cpu time (27 user, 0 system)</div><div>
<div>    no collections</div>
<div>    no bytes allocated</div><div>    no minor faults</div><div>    no major faults</div><div><br></div><br></div><div><div><div class="gmail_quote">On Sun, Nov 4, 2012 at 5:15 PM, Mikael <span dir="ltr"><<a href="mailto:mikael.rcv@gmail.com" target="_blank">mikael.rcv@gmail.com</a>></span> wrote:<br>



<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>First, please add (declare (block)) and re-compile, this way Gambit won't need to re-look up the procedures in the global namespace that you call, on each invocation. Please report what kind of improvement you got with this.</div>





<div><br></div><div><br></div><div>Now just to make this round of emails complete:</div><div><br></div>What would be good/very good performance in your view?<div><br></div><div>Could you send jobs in some kind of batch format to C?<br>






<div><br></div><div>Note that Gambit-internal fxnum variables have a special encoding (the lowermost two(?) bits are object type identifier, which are shifted out when converting them to C int), this takes a little bit of time.</div>






<div><br></div><div>If for instance you make u32vectors/s32vectors/etc. [and send batch ops made on those to C to be performed etc.] then you can just read out the content of those vectors 'raw' in C, there's no interconversion there.</div>






<div><br></div><div>Brgds<br><br><div class="gmail_quote"><div><div>2012/11/4 tcl super dude <span dir="ltr"><<a href="mailto:tcleval@gmail.com" target="_blank">tcleval@gmail.com</a>></span><br></div></div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>


Hi everyone,<div><br></div><div>I have been working on an image processing library that I want to use on android. I know that performance is a bit of a problem on image processing, so I started to study some bit hacking to improve the performance on my integer operations.  My problem now is that I don't know why my c-lambdas take so much time to execute. All operations take constant time and there is no branching. Probably is some sort of conversion time between C types and GAMBIT types. I expected min-integer and abs-integer to be a lot faster than min and abs, respectively. Any help is appreciated. </div>







<div><br></div><div>URL REFERENCE: </div><div><a href="http://graphics.stanford.edu/~seander/bithacks.html#IntegerAbs" target="_blank">http://graphics.stanford.edu/~seander/bithacks.html#IntegerAbs</a></div><div><a href="http://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax" target="_blank">http://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax</a><br>







<br></div><div><br></div><div>MY ENVIRONMENT:</div><div>Linux casa 3.6.4-1-ARCH #1 SMP PREEMPT Mon Oct 29 15:13:56 CET 2012 i686 GNU/Linux</div><div><br></div><div><div>gcc -v</div><div>Using built-in specs.</div><div>COLLECT_GCC=gcc</div>







<div>COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-pc-linux-gnu/4.7.2/lto-wrapper</div><div>Target: i686-pc-linux-gnu</div><div>Configured with: /build/src/gcc-4.7.2/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=<a href="https://bugs.archlinux.org/" target="_blank">https://bugs.archlinux.org/</a> --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --enable-libstdcxx-time --enable-gnu-unique-object --enable-linker-build-id --with-ppl --enable-cloog-backend=isl --disable-ppl-version-check --disable-cloog-version-check --enable-lto --enable-gold --enable-ld=default --enable-plugin --with-plugin-ld=ld.gold --with-linker-hash-style=gnu --disable-multilib --disable-libssp --disable-build-with-cxx --disable-build-poststage1-with-cxx --enable-checking=release</div>







<div>Thread model: posix</div><div>gcc version 4.7.2 (GCC) </div></div><div><br></div><div><div>Gambit v4.6.6 (SINGLE HOST and GCC extensions enabled)</div></div><div><br></div><div><br></div><div>SCHEME CODE: compiled with ---> gambitc -exe   bithacks.scm</div>







<div><br></div><div>;; bithacks.scm</div><div><div><br></div><div><br></div><div>(declare</div><div> (not safe)</div><div> (fixnum)</div><div> (inline)</div><div> (inline-primitives))</div><div><br></div><div>;; INTEGER ABSOLUTE</div>







<div>(define abs-integer </div><div>  (c-lambda (int) int</div><div>    "// we want to find the absolute value of arg1</div><div>     int const mask = ___arg1 >> sizeof(int) * CHAR_BIT - 1;</div><div>     ___result = (___arg1 + mask) ^ mask;"))</div>







<div><br></div><div><br></div><div>(define min-integer</div><div>  (c-lambda (int int) int</div><div>    "// find the smaller of arg1 arg2</div><div>     ___result = ___arg2 ^ ((___arg1 ^ ___arg2) & -(___arg1 < ___arg2));"))</div>







<div><br></div><div>(define (test-abs)</div><div>  (let ((result 0))</div><div>    (begin</div><div>      (display "abs:\n")</div><div>      (time </div><div>       (let loop-i ((i 0))</div><div>         (cond ((fx< i 100000)</div>







<div>                (set! result (abs i))</div><div>                (loop-i (fx+ 1 i))))))</div><div>      (display "abs-integer:\n")</div><div>      (time</div><div>       (let loop-j ((j 0))</div><div>         (cond ((fx< j 100000)</div>







<div>                (set! result (abs-integer j))</div><div>                (loop-j (fx+ 1 j))))))))) </div><div><br></div><div>(define (test-min)</div><div>  (let ((result 0))</div><div>    (begin</div><div>      (display "min:\n")</div>







<div>      (time </div><div>       (let loop-i ((i 0))</div><div>         (cond ((fx< i 100000)</div><div>                (set! result (min i result))</div><div>                (loop-i (fx+ 1 i))))))</div><div>      (display "min-integer:\n")</div>







<div>      (time</div><div>       (let loop-j ((j 0))</div><div>         (cond ((fx< j 100000)</div><div>                (set! result (min-integer j result))</div><div>                (loop-j (fx+ 1 j))))))))) </div><div>







<br></div><div>;; run tests</div><div><br></div><div>(test-abs)</div><div>(test-min)</div></div><div><br></div><div>;;;;;;;;;;;;;;;;;;;;;; RESULTS;;;;;;;;;;;;;;;;;;;;;</div><div><br></div><div><div>abs:</div><div>(time (let loop-i ((i 0)) (cond ((fx< i 100000) (set! result (abs i)) (loop-i (fx+ 1 i))))))</div>







<div>    2 ms real time</div><div>    3 ms cpu time (3 user, 0 system)</div><div>    no collections</div><div>    no bytes allocated</div><div>    no minor faults</div><div>    no major faults</div><div>abs-integer:</div>







<div>(time (let loop-j ((j 0)) (cond ((fx< j 100000) (set! result (abs-integer j)) (loop-j (fx+ 1 j))))))</div><div>    22 ms real time</div><div>    23 ms cpu time (23 user, 0 system)</div><div>    no collections</div>







<div>    no bytes allocated</div><div>    2 minor faults</div><div>    no major faults</div><div>min:</div><div>(time (let loop-i ((i 0)) (cond ((fx< i 100000) (set! result (min i result)) (loop-i (fx+ 1 i))))))</div>






<div>
    2 ms real time</div><div>    3 ms cpu time (0 user, 3 system)</div><div>    no collections</div><div>    no bytes allocated</div><div>    no minor faults</div><div>    no major faults</div><div>min-integer:</div><div>







(time (let loop-j ((j 0)) (cond ((fx< j 100000) (set! result (min-integer j result)) (loop-j (fx+ 1 j))))))</div><div>    28 ms real time</div><div>    30 ms cpu time (27 user, 3 system)</div><div>    no collections</div>







<div>    no bytes allocated</div><div>    no minor faults</div><div>    no major faults</div></div><div><br></div>
<br></div></div>_______________________________________________<br>
Gambit-list mailing list<br>
<a href="mailto:Gambit-list@iro.umontreal.ca" target="_blank">Gambit-list@iro.umontreal.ca</a><br>
<a href="https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list" target="_blank">https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list</a><br>
<br></blockquote></div><br></div></div>
</blockquote></div><br></div></div></div>
<br>_______________________________________________<br>
Gambit-list mailing list<br>
<a href="mailto:Gambit-list@iro.umontreal.ca" target="_blank">Gambit-list@iro.umontreal.ca</a><br>
<a href="https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list" target="_blank">https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list</a><br>
<br></blockquote></div><br></div></div></div></div>
</div><br>