# HG changeset patch # User John Tsiombikas # Date 1505440837 -10800 # Node ID 1fa939507d8b86ec80b9b1f35be07545544f361e # Parent f9b1ff21fd62ef9331fd66f2f3e4f05c2058e38f fast floating point->int conversion diff -r f9b1ff21fd62 -r 1fa939507d8b src/fixedp.h --- a/src/fixedp.h Mon Mar 10 17:28:28 2014 +0200 +++ b/src/fixedp.h Fri Sep 15 05:00:37 2017 +0300 @@ -31,6 +31,12 @@ extern const fixed fixed_tenth; extern const fixed fixed_255;*/ +static __inline long cround64(double val) +{ + val += 6755399441055744.0; + return *(long*)&val; +} + #ifdef DBG_USE_FLOAT /* ------- debug mode, use floating point -------- */ #define FIXED_INT_PART(n) ((int)(n)) diff -r f9b1ff21fd62 -r 1fa939507d8b src/mglimpl.h --- a/src/mglimpl.h Mon Mar 10 17:28:28 2014 +0200 +++ b/src/mglimpl.h Fri Sep 15 05:00:37 2017 +0300 @@ -14,7 +14,8 @@ #define ZTILE(x) (((x) & ~ZTILE_MASK) >> ZTILE_SHIFT) #define ZTILE_OFFS(x) ((x) & ZTILE_MASK) -#define ROUND(x) ((x) >= 0.0 ? (x) + 0.5 : (x) - 0.5) +/*#define ROUND(x) ((x) >= 0.0 ? (x) + 0.5 : (x) - 0.5)*/ +#define ROUND(x) cround64(x) typedef float mat4_t[16]; diff -r f9b1ff21fd62 -r 1fa939507d8b src/scantmpl.h --- a/src/scantmpl.h Mon Mar 10 17:28:28 2014 +0200 +++ b/src/scantmpl.h Fri Sep 15 05:00:37 2017 +0300 @@ -251,7 +251,9 @@ #ifdef INTERP_DEPTH long pix = (sline + x0 + i) - fb->pixels; #ifdef RAST_FLOAT - unsigned short zval = (unsigned short)(z * USHRT_MAX); + /*unsigned short zval = (unsigned short)(z * USHRT_MAX);*/ + float zn = z + 1.0; + unsigned short zval = ((*(long*)&zn) & 0x7fffff) >> 7; #else unsigned short zval = (unsigned short)((z >> 1) & 0xffff); #endif