## Re: [Vxl-maintainers] fast floor function

 Re: [Vxl-maintainers] fast floor function From: Tom Vercauteren - 2008-10-01 14:07:12 ```Hi all, A couple of months ago, we discussed the possibility of adding some fast implementations of floor, ceil and round to vnl. Peter Vanroose introduced the API, reference implementations and some test cases for these functions. I was wondering whether any of the vnl developers would be interested in looking at that question once again and see if it would be feasible to make the next step: introducing the fast, platform-specific, implementations of these functions. This would be great for many ITK filters! Best regards, Tom Vercauteren On Wed, Aug 6, 2008 at 9:49 AM, Tom Vercauteren wrote: > For the specialists ease, I have put the code we use for the round, > floor and ceil below. > > Regards, > > Tom > > > > > On MSVC: > > > inline int vnl_math_rnd(double x) > { > int r; > x = 2*x+.5; > __asm { > fld x > fistp r > } > > return r>>1; > } > > inline int vnl_math_rnd(float x) > { > int r; > x = 2*x+.5f; > __asm { > fld x > fistp r > } > > return r>>1; > } > > inline int vnl_math_floor(double x) > { > int r; > x = 2*x-.5; > __asm { > fld x > fistp r > } > > return r>>1; > } > > inline int vnl_math_floor(float x) > { > int r; > x = 2*x-.5f; > __asm { > fld x > fistp r > } > > return r>>1; > } > > inline int vnl_math_ceil(double x) > { > int r; > x = -.5 - 2*x; > __asm { > fld x > fistp r > } > > return -(r>>1); > } > > inline int vnl_math_ceil(float x) > { > int r; > x = -.5f - 2*x; > __asm { > fld x > fistp r > } > > return -(r>>1); > } > > > > > > > On gcc: > > > inline int vnl_math_rnd(double x) > { > int r; > x = 2*x+.5; > __asm__ __volatile__ ("fistpl %0" : "=m"(r) : "t"(x) : "st"); > > return r>>1; > } > > inline int vnl_math_rnd(float x) > { > int r; > x = 2*x+.5f; > __asm__ __volatile__ ("fistpl %0" : "=m"(r) : "t"(x) : "st"); > > return r>>1; > } > > inline int vnl_math_floor(double x) > { > int r; > x = 2*x-.5; > __asm__ __volatile__ ("fistpl %0" : "=m"(r) : "t"(x) : "st"); > > return r>>1; > } > > inline int vnl_math_floor(float x) > { > int r; > x = 2*x-.5f; > __asm__ __volatile__ ("fistpl %0" : "=m"(r) : "t"(x) : "st"); > > return r>>1; > } > > inline int vnl_math_ceil(double x) > { > int r; > x = -.5 - 2*x; > __asm__ __volatile__ ("fistpl %0" : "=m"(r) : "t"(x) : "st"); > > return -(r>>1); > } > > inline int vnl_math_ceil(float x) > { > int r; > x = -.5f - 2*x; > __asm__ __volatile__ ("fistpl %0" : "=m"(r) : "t"(x) : "st"); > > return -(r>>1); > } > ```