added perf_start/perf_end assembly macros
authorJohn Tsiombikas <nuclear@member.fsf.org>
Sun, 11 Feb 2018 08:05:49 +0000 (10:05 +0200)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Sun, 11 Feb 2018 08:05:49 +0000 (10:05 +0200)
GNUmakefile
Makefile.dj
src/gfxutil.c
src/greets.c
src/util.h

index d6c67d1..830297d 100644 (file)
@@ -1,5 +1,5 @@
 src = $(wildcard src/*.c) $(wildcard src/sdl/*.c)
-obj = $(src:.c=.o)
+obj = $(src:.c=.o) $(asmsrc:.asm=.o)
 dep = $(obj:.o=.d)
 bin = demo
 
@@ -29,8 +29,8 @@ mikmod:
 
 .PHONY: cleanlibs
 cleanlibs:
-       $(MAKE) -C libs/imago -f Makefile.dj clean
-       $(MAKE) -C libs/oldmik -f Makefile.dj clean
+       $(MAKE) -C libs/imago clean
+       $(MAKE) -C libs/mikmod clean
 
 .PHONY: clean
 clean:
index 0f152b7..764ad9d 100644 (file)
@@ -1,4 +1,5 @@
 src = $(wildcard src/*.c) $(wildcard src/dos/*.c)
+asmsrc = $(wildcard src/*.asm)
 obj = $(src:.c=.cof)
 dep = $(obj:.cof=.dep)
 bin = demo.exe
index cb51780..b82a612 100644 (file)
@@ -149,20 +149,21 @@ void draw_line(int x0, int y0, int x1, int y1, unsigned short color)
                int sum = sptr[0] * (rad + 1); \
                int count = (rad * 2 + 1) << 8; \
                int midsize = w - rad * 2; \
+               int firstpix = sptr[0]; \
                int lastpix = sptr[pstep * (w - 1)]; \
                /* add up the contributions for the -1 pixel */ \
                for(j=0; j<rad; j++) { \
                        sum += sptr[pstep * j]; \
                } \
                /* first part adding sptr[rad] and subtracting sptr[0] */ \
-               for(j=0; j<rad + 1; j++) { \
-                       sum += (int)sptr[pstep * rad] - (int)sptr[0]; \
+               for(j=0; j<=rad; j++) { \
+                       sum += (int)sptr[pstep * rad] - firstpix; \
                        sptr += pstep; \
                        *dptr = scale * sum / count; \
                        dptr += pstep; \
                } \
                /* middle part adding sptr[rad] and subtracting sptr[-(rad+1)] */ \
-               for(j=0; j<midsize - 1; j++) { \
+               for(j=1; j<midsize; j++) { \
                        sum += (int)sptr[pstep * rad] - (int)sptr[-(rad + 1) * pstep]; \
                        sptr += pstep; \
                        *dptr = scale * sum / count; \
index 0ad90a1..57f85e8 100644 (file)
@@ -25,6 +25,8 @@ void wait_vsync(void);
 
 #define RAND_FIELD_MAX 0.7
 
+#define BLUR_RAD       5
+
 #define PCOUNT         4000
 #define MAX_LIFE       7.0f
 #define PALPHA         1.0f
@@ -231,8 +233,12 @@ static void draw(void)
                }
        }
 
-#define BLUR_RAD       5
+       /*perf_start();*/
        blur_grey_horiz(prev_smokebuf, cur_smokebuf, fb_width, fb_height, BLUR_RAD, 240);
+       /*
+       perf_end();
+       printf("blur perf: %lu\n", (unsigned long)perf_interval_count);
+       */
        blur_grey_vert(cur_smokebuf, prev_smokebuf, fb_width, fb_height, BLUR_RAD, 240);
        swap_smoke_buffers();
 
index eb3773d..f8ae175 100644 (file)
@@ -24,4 +24,55 @@ static INLINE int32_t cround64(double val)
        return *(int32_t*)&val;
 }
 
+uint32_t perf_start_count, perf_interval_count;
+
+#ifdef __WATCOMC__
+void perf_start(void);
+#pragma aux perf_start = \
+       "rdtsc" \
+       "mov [perf_start_count], eax" \
+       modify[eax edx];
+
+void perf_end(void);
+#pragma aux perf_end = \
+       "rdtsc" \
+       "sub eax, [perf_start_count]" \
+       "mov [perf_interval_count], eax" \
+       modify [eax edx];
+#endif
+
+#ifdef __GNUC__
+#define perf_start()  asm volatile ( \
+       "rdtsc\n" \
+       "mov %%eax, %0\n" \
+       : "=m"(perf_start_count) :: "%eax", "%edx")
+
+#define perf_end() asm volatile ( \
+       "rdtsc\n" \
+       "sub %1, %%eax\n" \
+       "mov %%eax, %0\n" \
+       : "=m"(perf_interval_count) \
+       : "m"(perf_start_count) \
+       : "%eax", "%edx")
+#endif
+
+#ifdef _MSC_VER
+#define perf_start() \
+       do { \
+               __asm { \
+                       rdtsc \
+                       mov [perf_start_count], eax \
+               } \
+       } while(0)
+
+#define perf_end() \
+       do { \
+               __asm { \
+                       rdtsc \
+                       sub eax, [perf_start_count] \
+                       mov [perf_interval_count], eax \
+               } \
+       } while(0)
+#endif
+
 #endif /* UTIL_H_ */