Using RULES to improve OpenGLRaw

Andy Gill <[email protected]> Fri, 4 Dec 2009 11:07:47 -0600
Newsgroups gmane.comp.lang.haskell.hopengl
Message-ID <[email protected]>
We've been hacking on ChalkBoard, and there is this import  
optimization that we've added to our version of OpenGLRaw.  It make  
ChalkBoard run almost twice as fast. The problem was the conversions  
between GLfloat and regular floats was using realToFrac, which uses  
fromRational . toRational.

This can be fixed by using the GHC RULES. (inside the GHC specific  
part of includes/CTypes.h)

#define GHC_RULE(N,R) {-# RULES "N" R #-}

#define FLOATING_TYPE(T,C,S,B) \
newtype T = T B deriving (ARITHMETIC_CLASSES, FLOATING_CLASSES); \
INSTANCE_READ(T,B); \
INSTANCE_SHOW(T,B); \
INSTANCE_TYPEABLE0(T,C,S) ; \
GHC_RULE(realToFrac/a->T,realToFrac = \x -> T (realToFrac x)) ; \
GHC_RULE(realToFrac/T->a,realToFrac = \(T x) -> realToFrac x)

(the last two lines are the new lines)

We've asked for this change to be added to the office release of  
OpenGLRaw.

Cheers!

Andy & Kevin
----
Andy Gill, <[email protected]>
Assistant Professor
The University of Kansas, EECS Department
Information and Telecommunication Technology Center