summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2008-02-23 05:42:32 +0000
committerMatt Turner <mattst88@gmail.com>2008-02-23 05:42:32 +0000
commite510996901c57f36f226d0eec3c929fb8b69b8e0 (patch)
tree7fa347e74b00812c7fabf03476d4583c192ceea3
parent78002dcadcad1317a22277684e7f5675f568038c (diff)
Use inline-asm only with gcc. Add fallback for other compilers
git-svn-id: svn://mattst88.com/svn/glpong3d/trunk@19 4dd1920e-271a-0410-bca0-81b404a81564
-rw-r--r--Makefile50
-rw-r--r--glpong3d.c19
-rw-r--r--glpong3d.h2
3 files changed, 38 insertions, 33 deletions
diff --git a/Makefile b/Makefile
index c95d7ef..eed7203 100644
--- a/Makefile
+++ b/Makefile
@@ -1,26 +1,26 @@
-CC=gcc
-STRIP=strip
-WARN=-Wall -W -ansi -pedantic
-CFLAGS=-Os -pipe -std=c99 ${WARN}
-LDFLAGS=-Wl,-O1,-s
-INCLUDES=`sdl-config --cflags`
-LIBRARIES=`sdl-config --libs` -lSDL_image -lSDL_net -lGL -lGLU -lGLC
-EXT=.exe
-
-EXE=glpong3d${EXT}
-
-OBJS=glpong3d.o # ball.o paddle.o
-
-all: ${OBJS}
- ${CC} ${LDFLAGS} ${OBJS} -o ${EXE} ${LIBRARIES}
-
-clean:
- rm -f ${OBJS}
- rm -f ${EXE}
-
-rebuild: clean all
-remake: rebuild
-
-%.o: %.c
- ${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
+CC=gcc
+STRIP=strip
+WARN=-Wall -W -ansi -pedantic
+CFLAGS=-g -Os -pipe -std=c99 ${WARN}
+LDFLAGS=-Wl,-O1,-s
+INCLUDES=`sdl-config --cflags`
+LIBRARIES=`sdl-config --libs` -lSDL_image -lSDL_net -lGL -lGLU -lGLC
+EXT=.exe
+
+EXE=glpong3d${EXT}
+
+OBJS=glpong3d.o # ball.o paddle.o
+
+all: ${OBJS}
+ ${CC} ${LDFLAGS} ${OBJS} -o ${EXE} ${LIBRARIES}
+
+clean:
+ rm -f ${OBJS}
+ rm -f ${EXE}
+
+rebuild: clean all
+remake: rebuild
+
+%.o: %.c
+ ${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
diff --git a/glpong3d.c b/glpong3d.c
index a02a17f..c4739a8 100644
--- a/glpong3d.c
+++ b/glpong3d.c
@@ -451,18 +451,23 @@ void GLPong_CleanUp() {
}
-__inline__ unsigned int NextPow2(unsigned int value) {
+static __inline__ unsigned int
+NextPow2(unsigned int value) {
+#if (defined __i386__ || defined __amd64__ || defined __x86_64__) \
+ && (defined __GNUC__)
unsigned int x;
-#ifdef __i386__
- __asm("dec %1\n\t"
- "movl $2,%0\n\t"
- "bsr %1,%1\n\t"
- "shl %b1,%0\n\t"
+ __asm(
+ "dec %1 \n\t" /* so that if the number is a power of
+ * two we don't change it
+ */
+ "movl $2,%0 \n\t"
+ "bsr %1,%1 \n\t"
+ "shl %b1,%0 \n\t"
: "=r" (x)
: "c" (value)
);
#else
- x = 1;
+ unsigned int x = 0;
while (x < value) {
x *= 2;
}
diff --git a/glpong3d.h b/glpong3d.h
index b364f71..dafdee7 100644
--- a/glpong3d.h
+++ b/glpong3d.h
@@ -53,6 +53,6 @@ void GLPong_Move();
void GLPong_Collide(Ball_t * ball, const Paddle_t * paddle);
GLuint SDL_GL_SurfaceToTexture(SDL_Surface * surface);
-__inline__ unsigned int NextPow2(unsigned int value);
+static __inline__ unsigned int NextPow2(unsigned int value);
#endif