deepstone

changeset 40:1fa939507d8b

fast floating point->int conversion
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 15 Sep 2017 05:00:37 +0300
parents f9b1ff21fd62
children 482f30e63462
files src/fixedp.h src/mglimpl.h src/scantmpl.h
diffstat 3 files changed, 11 insertions(+), 2 deletions(-) [+]
line diff
     1.1 --- a/src/fixedp.h	Mon Mar 10 17:28:28 2014 +0200
     1.2 +++ b/src/fixedp.h	Fri Sep 15 05:00:37 2017 +0300
     1.3 @@ -31,6 +31,12 @@
     1.4  extern const fixed fixed_tenth;
     1.5  extern const fixed fixed_255;*/
     1.6  
     1.7 +static __inline long cround64(double val)
     1.8 +{
     1.9 +	val += 6755399441055744.0;
    1.10 +	return *(long*)&val;
    1.11 +}
    1.12 +
    1.13  #ifdef DBG_USE_FLOAT
    1.14  /* ------- debug mode, use floating point -------- */
    1.15  #define FIXED_INT_PART(n)	((int)(n))
     2.1 --- a/src/mglimpl.h	Mon Mar 10 17:28:28 2014 +0200
     2.2 +++ b/src/mglimpl.h	Fri Sep 15 05:00:37 2017 +0300
     2.3 @@ -14,7 +14,8 @@
     2.4  #define ZTILE(x)			(((x) & ~ZTILE_MASK) >> ZTILE_SHIFT)
     2.5  #define ZTILE_OFFS(x)		((x) & ZTILE_MASK)
     2.6  
     2.7 -#define ROUND(x)	((x) >= 0.0 ? (x) + 0.5 : (x) - 0.5)
     2.8 +/*#define ROUND(x)	((x) >= 0.0 ? (x) + 0.5 : (x) - 0.5)*/
     2.9 +#define ROUND(x) cround64(x)
    2.10  
    2.11  
    2.12  typedef float mat4_t[16];
     3.1 --- a/src/scantmpl.h	Mon Mar 10 17:28:28 2014 +0200
     3.2 +++ b/src/scantmpl.h	Fri Sep 15 05:00:37 2017 +0300
     3.3 @@ -251,7 +251,9 @@
     3.4  #ifdef INTERP_DEPTH
     3.5  		long pix = (sline + x0 + i) - fb->pixels;
     3.6  #ifdef RAST_FLOAT
     3.7 -		unsigned short zval = (unsigned short)(z * USHRT_MAX);
     3.8 +		/*unsigned short zval = (unsigned short)(z * USHRT_MAX);*/
     3.9 +		float zn = z + 1.0;
    3.10 +		unsigned short zval = ((*(long*)&zn) & 0x7fffff) >> 7;
    3.11  #else
    3.12  		unsigned short zval = (unsigned short)((z >> 1) & 0xffff);
    3.13  #endif