[gambit-list] Call for brains!

Tomas Möre tomas.o.more at gmail.com
Wed May 21 09:15:52 EDT 2014


Hello!

If you feel like taking on a little challenge read on!

I am currently working on a gambit UI kit that is
containing glfw and OpenGL

(It will be open source and free)

It will also be native to gambit, so no weird hocus pokus required!
Well a little bit of black magic and sacrificial of virgins is always
needed to get things to run properly...

(The result will hopefully be better then my so called jokes)


Since modern OpenGL requires some hefty matrix math I need to make a matrix
math library.
Since I want this to be multi platform compatible and easy to use even in
the interpreter. I have to do all this in scheme.
(Except we're forced to allocate the the scheme binary vectors in c to make
them not move during garbage collection)

But back to business!
I've made the following macro and procedure to test matrix multiplication

(To test simply copy paste into interpreter)

But as you will se on the test i've added on the last row of code this is a
pretty "slow" procedure.

The question is, How do you make this quicker?

Thank you for reading this long! :)

!!!! warning "ugly" code
#######################CODE START############################

;; because the multiplication of matricies require a ton of commands we
make a macro! :D

;; the macro requires the nr of columns and the number of rows and the
current position of both column and row

(define-macro  (f32-mat*-elem columns rows column-pos row-pos first-vector
second-vector)

  (let ((result '()))

    (let loop ((i 0))

      (set! result (cons  `(##fl* (##f32vector-ref ,first-vector  ,(fx+
row-pos i))

                                  (##f32vector-ref ,second-vector ,(fx+
column-pos (* i columns)))

                                  ) result))

      (if (not (eq? i rows)) (loop (+ i 1)))

      )

    (set! result (reverse result))

    `(##fl+ , at result)

    ))

;; multiplies two matricites of the dimetions 4x4 into one

(define (f32mat4* first-vector second-vector)

  (f32vector ;;-still

   (f32-mat*-elem 4 4 0 0 first-vector second-vector)  (f32-mat*-elem 4 4 1
0 first-vector second-vector) (f32-mat*-elem 4 4 2 0 first-vector
second-vector) (f32-mat*-elem 4 4 3 0 first-vector second-vector)

   (f32-mat*-elem 4 4 0 1 first-vector second-vector)  (f32-mat*-elem 4 4 1
1 first-vector second-vector) (f32-mat*-elem 4 4 2 1 first-vector
second-vector) (f32-mat*-elem 4 4 3 1 first-vector second-vector)

   (f32-mat*-elem 4 4 0 2 first-vector second-vector)  (f32-mat*-elem 4 4 1
2 first-vector second-vector) (f32-mat*-elem 4 4 2 2 first-vector
second-vector) (f32-mat*-elem 4 4 3 2 first-vector second-vector)

   (f32-mat*-elem 4 4 0 3 first-vector second-vector)  (f32-mat*-elem 4 4 1
3 first-vector second-vector) (f32-mat*-elem 4 4 2 3 first-vector
second-vector) (f32-mat*-elem 4 4 3 3 first-vector second-vector)

   ))


(define x (f32vector 1. 2. 3. 4. 1. 2. 3. 4. 1. 2. 3. 4. 1. 2. 3. 4.))

(define y (f32vector 1. 2. 3. 4. 1. 2. 3. 4. 1. 2. 3. 4. 1. 2. 3. 4.))


(time (let loop ((i 1000)) (f32mat4* x y) (if (not (eq? i 0)) (loop (- i 1
)))))
####################### CODE END ####################################
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20140521/a5d2a962/attachment.htm>


More information about the Gambit-list mailing list