2007-11-06 Tomas Frydrych <tf@o-hand.com>

* clutter/clutter-fixed.h:
	Added CLUTTER_SQRTI_ARG_MAX, CLUTTER_SQRTI_5_PERCENT,
	CLUTTER_SQRTI_10_PERCENT expressing clutter_sqrti limits.
	Stripped trailing whitespace.

        * clutter/clutter-fixed.c:
	(clutter_sqrti):
	Updated documentation, stripped trailing whitespace.

        * clutter/clutter-behaviour-path.c:
	(node_distance):
	Use clib sqrt if clutter_sqrti() precission would be worse than
	10%.
	Stripped trailing whitespace.
This commit is contained in:
Tomas Frydrych 2007-11-06 15:46:23 +00:00
parent 9461dd216b
commit 3b07be19ba
4 changed files with 141 additions and 71 deletions

View File

@ -1,3 +1,20 @@
2007-11-06 Tomas Frydrych <tf@o-hand.com>
* clutter/clutter-fixed.h:
Added CLUTTER_SQRTI_ARG_MAX, CLUTTER_SQRTI_5_PERCENT,
CLUTTER_SQRTI_10_PERCENT expressing clutter_sqrti limits.
Stripped trailing whitespace.
* clutter/clutter-fixed.c:
(clutter_sqrti):
Updated documentation, stripped trailing whitespace.
* clutter/clutter-behaviour-path.c:
(node_distance):
Use clib sqrt if clutter_sqrti() precission would be worse than
10%.
Stripped trailing whitespace.
2007-11-06 Emmanuele Bassi <ebassi@openedhand.com> 2007-11-06 Emmanuele Bassi <ebassi@openedhand.com>
* clutter/clutter-layout.h: Add commodity macros to test for * clutter/clutter-layout.h: Add commodity macros to test for

View File

@ -117,18 +117,28 @@ static gint
node_distance (const ClutterKnot *begin, node_distance (const ClutterKnot *begin,
const ClutterKnot *end) const ClutterKnot *end)
{ {
gint t;
g_return_val_if_fail (begin != NULL, 0); g_return_val_if_fail (begin != NULL, 0);
g_return_val_if_fail (end != NULL, 0); g_return_val_if_fail (end != NULL, 0);
if (clutter_knot_equal (begin, end)) if (clutter_knot_equal (begin, end))
return 0; return 0;
#if 1 t = (end->x - begin->x) * (end->x - begin->x) +
return clutter_sqrti ((end->x - begin->x) * (end->x - begin->x) + (end->y - begin->y) * (end->y - begin->y);
(end->y - begin->y) * (end->y - begin->y));
/*
* If we are using limited precision sqrti implementation, fallback on
* clib sqrt if the precission would be less than 10%
*/
#if INT_MAX > CLUTTER_SQRTI_ARG_10_PERCENT
if (t <= CLUTTER_SQRTI_ARG_10_PERCENT)
return clutter_sqrti (t);
else
return CLUTTER_FLOAT_TO_INT(sqrt(t));
#else #else
return CLUTTER_FLOAT_TO_INT(sqrt((end->x - begin->x) * (end->x - begin->x) + return clutter_sqrti (t);
(end->y - begin->y) * (end->y - begin->y)));
#endif #endif
} }

View File

@ -608,7 +608,9 @@ clutter_sqrtx (ClutterFixed x)
* *
* This function is about 10x faster than clib sqrt() on x86, and (this is * This function is about 10x faster than clib sqrt() on x86, and (this is
* not a typo!) more than 800x faster on ARM without FPU. It's error is < 5% * not a typo!) more than 800x faster on ARM without FPU. It's error is < 5%
* for arguments < 132 and < 10% for arguments < 5591. * for arguments < #CLUTTER_SQRTI_ARG_5_PERCENT and < 10% for arguments <
* #CLUTTER_SQRTI_ARG_10_PERCENT. The maximum argument that can be passed to
* this function is CLUTTER_SQRTI_ARG_MAX.
* *
* Return value: integer square root. * Return value: integer square root.
* *

View File

@ -316,6 +316,47 @@ ClutterFixed clutter_tani (ClutterAngle angle);
*/ */
#define clutter_cosi(angle) (clutter_sini ((angle) + 256)) #define clutter_cosi(angle) (clutter_sini ((angle) + 256))
/**
* CLUTTER_SQRTI_ARG_MAX
*
* Maximum argument that can be passed to #clutter_sqrti function.
*
* Since: 0.6
*/
#ifndef __SSE2__
#define CLUTTER_SQRTI_ARG_MAX 0x3fffff
#else
#define CLUTTER_SQRTI_ARG_MAX INT_MAX
#endif
/**
* CLUTTER_SQRTI_ARG_5_PERCENT
*
* Maximum argument that can be passed to #clutter_sqrti for which the
* resulting error is < 5%
*
* Since: 0.6
*/
#ifndef __SSE2__
#define CLUTTER_SQRTI_ARG_5_PERCENT 131
#else
#define CLUTTER_SQRTI_ARG_5_PERCENT INT_MAX
#endif
/**
* CLUTTER_SQRTI_ARG_10_PERCENT
*
* Maximum argument that can be passed to #clutter_sqrti for which the
* resulting error is < 10%
*
* Since: 0.6
*/
#ifndef __SSE2__
#define CLUTTER_SQRTI_ARG_10_PERCENT 5590
#else
#define CLUTTER_SQRTI_ARG_10_PERCENT INT_MAX
#endif
ClutterFixed clutter_sqrtx (ClutterFixed x); ClutterFixed clutter_sqrtx (ClutterFixed x);
gint clutter_sqrti (gint x); gint clutter_sqrti (gint x);