annotate src/libm/s_floor.c @ 5053:b5b42be9333c

Fixed bug #1026 Vittorio Giovara 2010-07-16 19:09:28 PDT i was reading SDL_renderer_gles and i noticed that every time we there is some gl call the gl state is modified with a couple of glEnableClientState()/glDisableClientState. While this is completely fine for desktops systems, this is a major performace kill on mobile devices, right where opengles is implemented. Normal practice in this case is to update the glstate once, keep it always the same and disable/enable other states only in very special occasions. On the web there's plenty of documentation (on the top of my head http://developer.apple.com/iphone/library/documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/Performance/Performance.html#//apple_ref/doc/uid/TP40008793-CH105-SW5 ) and i personally tried this. I modified my code and got a 10 fps boost, then modified SDL_render_gles and shifted from 40 fps to 50 fps alone -- considering that i started from ~30fps i got an 80% performance increase with this technique. I have attached a dif of my changes, hope that it will be included in mainstream.
author Sam Lantinga <slouken@libsdl.org>
date Wed, 19 Jan 2011 23:56:16 -0800
parents 9ac6f0782dd6
children
rev   line source
2758
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /* @(#)s_floor.c 5.1 93/09/24 */
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 /*
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 * ====================================================
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 *
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 * Developed at SunPro, a Sun Microsystems, Inc. business.
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 * Permission to use, copy, modify, and distribute this
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 * software is freely granted, provided that this notice
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9 * is preserved.
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 * ====================================================
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 */
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 #if defined(LIBM_SCCS) && !defined(lint)
3162
dc1eb82ffdaa Von: Thomas Zimmermann
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
14 static const char rcsid[] =
2758
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 "$NetBSD: s_floor.c,v 1.8 1995/05/10 20:47:20 jtc Exp $";
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 #endif
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18 /*
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 * floor(x)
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 * Return x rounded toward -inf to integral value
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 * Method:
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 * Bit twiddling.
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23 * Exception:
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 * Inexact flag raised if x not equal to floor(x).
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 */
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 #include "math.h"
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 #include "math_private.h"
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 #ifdef __STDC__
3337
9ac6f0782dd6 Fixed bug #814
Sam Lantinga <slouken@libsdl.org>
parents: 3162
diff changeset
31 static const double huge_val = 1.0e300;
2758
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 #else
3337
9ac6f0782dd6 Fixed bug #814
Sam Lantinga <slouken@libsdl.org>
parents: 3162
diff changeset
33 static double huge_val = 1.0e300;
2758
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 #endif
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 libm_hidden_proto(floor)
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 #ifdef __STDC__
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 double floor(double x)
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 #else
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 double floor(x)
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 double x;
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 #endif
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 {
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 int32_t i0, i1, j0;
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 u_int32_t i, j;
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 EXTRACT_WORDS(i0, i1, x);
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 if (j0 < 20) {
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 if (j0 < 0) { /* raise inexact if x != 0 */
3337
9ac6f0782dd6 Fixed bug #814
Sam Lantinga <slouken@libsdl.org>
parents: 3162
diff changeset
50 if (huge_val + x > 0.0) { /* return 0*sign(x) if |x|<1 */
2758
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 if (i0 >= 0) {
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 i0 = i1 = 0;
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 } else if (((i0 & 0x7fffffff) | i1) != 0) {
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 i0 = 0xbff00000;
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 i1 = 0;
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 }
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 }
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 } else {
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 i = (0x000fffff) >> j0;
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 if (((i0 & i) | i1) == 0)
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 return x; /* x is integral */
3337
9ac6f0782dd6 Fixed bug #814
Sam Lantinga <slouken@libsdl.org>
parents: 3162
diff changeset
62 if (huge_val + x > 0.0) { /* raise inexact flag */
2758
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 if (i0 < 0)
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 i0 += (0x00100000) >> j0;
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 i0 &= (~i);
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 i1 = 0;
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 }
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 }
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 } else if (j0 > 51) {
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 if (j0 == 0x400)
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 return x + x; /* inf or NaN */
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 else
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 return x; /* x is integral */
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 } else {
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 i = ((u_int32_t) (0xffffffff)) >> (j0 - 20);
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 if ((i1 & i) == 0)
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 return x; /* x is integral */
3337
9ac6f0782dd6 Fixed bug #814
Sam Lantinga <slouken@libsdl.org>
parents: 3162
diff changeset
78 if (huge_val + x > 0.0) { /* raise inexact flag */
2758
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 if (i0 < 0) {
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 if (j0 == 20)
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 i0 += 1;
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 else {
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 j = i1 + (1 << (52 - j0));
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2760
diff changeset
84 if (j < (u_int32_t) i1)
2758
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 i0 += 1; /* got a carry */
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 i1 = j;
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 }
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 }
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 i1 &= (~i);
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 }
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 }
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 INSERT_WORDS(x, i0, i1);
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 return x;
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 }
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 libm_hidden_def(floor)