changeset 809:eba3b87f3f84

Add some separate macros for 64/32 precision fixed point types.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 14 May 2014 21:28:14 +0300
parents f8126fa1df9b
children cbe263ad963c
files dmblitfunc.h dmlib.h dmscaledblit.h minijss/jmix_c_in.c minijss/jssmix.c tests/fptest.c tools/ppl.c
diffstat 7 files changed, 48 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/dmblitfunc.h	Tue May 13 18:18:10 2014 +0300
+++ b/dmblitfunc.h	Wed May 14 21:28:14 2014 +0300
@@ -15,7 +15,7 @@
 #define DM_BLITFUNC_SRC_TYPE Uint8
 #define DM_BLITFUNC_DST_TYPE Uint8
 
-#define DM_BLITFUNC_INNER *dp++ = sp[FP_GETH(xv)];
+#define DM_BLITFUNC_INNER *dp++ = sp[FP_GETH16(xv)];
 
 #include "dmscaledblit.h"
 
@@ -32,7 +32,7 @@
     if (src->format->palette == NULL || src->format->palette->ncolors < 256) return -2;	\
     pal = (Uint32 *) src->format->palette->colors;
 
-#define DM_BLITFUNC_INNER *dp++ = pal[sp[FP_GETH(xv)]];
+#define DM_BLITFUNC_INNER *dp++ = pal[sp[FP_GETH16(xv)]];
 
 #include "dmscaledblit.h"
 
@@ -44,7 +44,7 @@
 #define DM_BLITFUNC_SRC_TYPE Uint32
 #define DM_BLITFUNC_DST_TYPE Uint32
 #define DM_BLITFUNC_INIT
-#define DM_BLITFUNC_INNER *dp++ = sp[FP_GETH(xv)];
+#define DM_BLITFUNC_INNER *dp++ = sp[FP_GETH16(xv)];
 
 #include "dmscaledblit.h"
 
@@ -60,7 +60,7 @@
 #define DM_BLITFUNC_DST_TYPE Uint8
 
 #define DM_BLITFUNC_INNER \
-    *dp = sp[FP_GETH(xv)] ? sp[FP_GETH(xv)] : *dp; dp++;
+    *dp = sp[FP_GETH16(xv)] ? sp[FP_GETH16(xv)] : *dp; dp++;
 
 #include "dmscaledblit.h"
 
@@ -77,7 +77,7 @@
     pal = (DMRGBA32 *) src->format->palette->colors;
 
 #define DM_BLITFUNC_INNER \
-    const DMRGBA32 q = pal[sp[FP_GETH(xv)]]; \
+    const DMRGBA32 q = pal[sp[FP_GETH16(xv)]]; \
     dp->r += ((q.r - dp->r) * q.a) >> 8; \
     dp->g += ((q.g - dp->g) * q.a) >> 8; \
     dp->b += ((q.b - dp->b) * q.a) >> 8; \
@@ -124,7 +124,7 @@
         "packuswb    %%mm2,  %%mm1\n"		\
         "movd        %%mm1,  %0\n"		\
         : "=m" (*dp)				\
-        : "m" (*dp), "m" (sp[FP_GETH(xv)]), "m" (qpdmask), "m" (qpdrm)	\
+        : "m" (*dp), "m" (sp[FP_GETH16(xv)]), "m" (qpdmask), "m" (qpdrm)	\
         : "memory", "%mm1", "%mm2", "%mm3", "%mm4", "%mm5" ); dp++;
 
 #define DM_BLITFUNC_FINISH asm("emms\n");
@@ -134,7 +134,7 @@
 #define DM_BLITFUNC_SRC_TYPE DMRGBA32
 #define DM_BLITFUNC_DST_TYPE DMRGBA32
 #define DM_BLITFUNC_INNER \
-    const DMRGBA32 q = sp[FP_GETH(xv)]; \
+    const DMRGBA32 q = sp[FP_GETH16(xv)]; \
     dp->r += ((q.r - dp->r) * q.a) >> 8; \
     dp->g += ((q.g - dp->g) * q.a) >> 8; \
     dp->b += ((q.b - dp->b) * q.a) >> 8; \
@@ -154,7 +154,7 @@
 #define DM_BLITFUNC_INIT
 
 #define DM_BLITFUNC_INNER \
-    const DMRGBA32 q = sp[FP_GETH(xv)]; \
+    const DMRGBA32 q = sp[FP_GETH16(xv)]; \
     dp->r = (q.r * q.a + dp->r * dp->a) >> 8; \
     dp->g = (q.g * q.a + dp->g * dp->a) >> 8; \
     dp->b = (q.b * q.a + dp->b * dp->a) >> 8; \
@@ -214,7 +214,7 @@
         "packuswb    %%mm2,  %%mm1\n"		\
         "movd        %%mm1,  %0\n"		\
         : "=m" (*dp)				\
-        : "m" (*dp), "m" (sp[FP_GETH(xv)]), "m" (qpdmask), "m" (qpdrm)	\
+        : "m" (*dp), "m" (sp[FP_GETH16(xv)]), "m" (qpdmask), "m" (qpdrm)	\
         : "memory", "%mm1", "%mm2", "%mm3", "%mm4", "%mm5" ); dp++;
 
 #define DM_BLITFUNC_FINISH asm("emms\n");
@@ -224,7 +224,7 @@
 #define DM_BLITFUNC_SRC_TYPE DMRGBA32
 #define DM_BLITFUNC_DST_TYPE DMRGBA32
 #define DM_BLITFUNC_INNER \
-    const DMRGBA32 q = sp[FP_GETH(xv)]; \
+    const DMRGBA32 q = sp[FP_GETH16(xv)]; \
     const int a = (alpha * q.a) >> 8; \
     dp->r += ((q.r - dp->r) * a) >> 8; \
     dp->g += ((q.g - dp->g) * a) >> 8; \
@@ -245,7 +245,7 @@
 #define DM_BLITFUNC_SRC_TYPE Uint8
 #define DM_BLITFUNC_DST_TYPE Uint8
 #define DM_BLITFUNC_INNER \
-    const int q = sp[FP_GETH(xv)] + *dp; \
+    const int q = sp[FP_GETH16(xv)] + *dp; \
     *(dp++) = q < 256 ? q : 255;
 
 #include "dmscaledblit.h"
@@ -269,13 +269,13 @@
         "paddusb     %%mm2,  %%mm1\n"		\
         "movd        %%mm1,  %0\n"		\
         : "=m" (*dp)				\
-        : "m" (*dp), "m" (pal[sp[FP_GETH(xv)]])	\
+        : "m" (*dp), "m" (pal[sp[FP_GETH16(xv)]])	\
         : "memory", "%mm1", "%mm2" ); dp++;
 
 #define DM_BLITFUNC_FINISH asm("emms\n");
 #else
 #define DM_BLITFUNC_INNER \
-    const DMRGBA32 q = pal[sp[FP_GETH(xv)]]; \
+    const DMRGBA32 q = pal[sp[FP_GETH16(xv)]]; \
     const int qr = dp->r + q.r, qg = dp->g + q.g, qb = dp->b + q.b; \
     dp->r = qr < 256 ? qr : 255; \
     dp->g = qg < 256 ? qg : 255; \
@@ -302,7 +302,7 @@
         "paddusb     %%mm2,  %%mm1\n"		\
         "movd        %%mm1,  %0\n"		\
         : "=m" (*dp)				\
-        : "m" (*dp), "m" (sp[FP_GETH(xv)])	\
+        : "m" (*dp), "m" (sp[FP_GETH16(xv)])	\
         : "memory", "%mm1", "%mm2" ); dp++;
 
 #define DM_BLITFUNC_FINISH asm("emms\n");
@@ -310,7 +310,7 @@
 #define DM_BLITFUNC_SRC_TYPE DMRGBA32
 #define DM_BLITFUNC_DST_TYPE DMRGBA32
 #define DM_BLITFUNC_INNER \
-    const DMRGBA32 q = sp[FP_GETH(xv)]; \
+    const DMRGBA32 q = sp[FP_GETH16(xv)]; \
     const int qr = dp->r + q.r, qg = dp->g + q.g, qb = dp->b + q.b; \
     dp->r = qr < 256 ? qr : 255; \
     dp->g = qg < 256 ? qg : 255; \
--- a/dmlib.h	Tue May 13 18:18:10 2014 +0300
+++ b/dmlib.h	Wed May 14 21:28:14 2014 +0300
@@ -127,20 +127,24 @@
 #  define FP_SETH(a, k) a.w[0] = (k)
 #  define FP_SETL(a, k) a.w[1] = (k)
 #  define FP_SETHL(a, h, l) { a.w[0] = (h); a.w[1] = (l); }
-#  define FP_GETH(a) a.w[0]
-#  define FP_GETL(a) a.w[1]
+#  define FP_GETH32(a) a.w[0]
+#  define FP_GETL32(a) a.w[1]
+#  define FP_GETH16(a) a.w[0]
+#  define FP_GETL16(a) a.w[1]
 #elif (SDL_BYTEORDER == SDL_LIL_ENDIAN)
 #  define FP_SETH(a, k) a.w[1] = (k)
 #  define FP_SETL(a, k) a.w[0] = (k)
 #  define FP_SETHL(a, h, l) { a.w[1] = (h); a.w[0] = (l); }
-#  define FP_GETH(a) a.w[1]
-#  define FP_GETL(a) a.w[0]
+#  define FP_GETH32(a) a.w[1]
+#  define FP_GETL32(a) a.w[0]
+#  define FP_GETH16(a) a.w[1]
+#  define FP_GETL16(a) a.w[0]
 #else
 #  error Unsupported byte order!
 #endif
 
-#define FP_PRINTF(a)   printf("%.8x:%.8x", FP_GETH(a), FP_GETL(a))
-#define FP_PRINTF32(a) printf("%.4x:%.4x", FP_GETH(a), FP_GETL(a))
+#define FP_PRINTF64(a) printf("%.8x:%.8x", FP_GETH32(a), FP_GETL32(a))
+#define FP_PRINTF32(a) printf("%.4x:%.4x", FP_GETH16(a), FP_GETL16(a))
 
 #define FP_ADD(a, b) a.dw += b.dw
 #define FP_SUB(a, b) a.dw -= b.dw
--- a/dmscaledblit.h	Tue May 13 18:18:10 2014 +0300
+++ b/dmscaledblit.h	Wed May 14 21:28:14 2014 +0300
@@ -52,7 +52,7 @@
     DM_BLITFUNC_DST_TYPE * dp = ((DM_BLITFUNC_DST_TYPE *) dst->pixels) + (yr.v0 * dst->pitch) / DM_BLITFUNC_DST_BYTES + xr.v0;
     for (yc = yr.v0; yc < yr.v1; yc++)
     {
-        const DM_BLITFUNC_SRC_TYPE * sp = ((DM_BLITFUNC_SRC_TYPE *) src->pixels) + (FP_GETH(yv) * src->pitch) / DM_BLITFUNC_SRC_BYTES;
+        const DM_BLITFUNC_SRC_TYPE * sp = ((DM_BLITFUNC_SRC_TYPE *) src->pixels) + (FP_GETH16(yv) * src->pitch) / DM_BLITFUNC_SRC_BYTES;
         int xc;
 
 #ifdef DM_BLITFUNC_INNER_INIT
--- a/minijss/jmix_c_in.c	Tue May 13 18:18:10 2014 +0300
+++ b/minijss/jmix_c_in.c	Wed May 14 21:28:14 2014 +0300
@@ -4,7 +4,7 @@
  * (C) Copyright 2006-2007 Tecnic Software productions (TNSP)
  */
 
-//#define JMIXER_DEBUG fprintf(stderr, "[%.8x:%.8x / %.8x]: %d\n", FP_GETH(tmpPos), FP_GETL(tmpPos), endPos, sp[FP_GETH(tmpPos)]);
+//#define JMIXER_DEBUG fprintf(stderr, "[%.8x:%.8x / %.8x]: %d\n", FP_GETH32(tmpPos), FP_GETL32(tmpPos), endPos, sp[FP_GETH32(tmpPos)]);
 #define JMIXER_DEBUG
 #define JMIXER_ADDBUF_TYPE Sint32
 
@@ -14,9 +14,9 @@
 #define JMIXER_SAMPLE_TYPE Sint16
 #define JMIXER_INIT        
 #define JMIXER_FUNC \
-    const Sint32 vol = (FP_GETH(tmpVolume) * mixer->globalVol) / 256; \
+    const Sint32 vol = (FP_GETH32(tmpVolume) * mixer->globalVol) / 256; \
     memmove(&tl[0], &tl[1], 4 * sizeof(tl[0])); \
-    tl[4] = (((Sint32) sp[FP_GETH(tmpPos)]) * vol * 3 + tl[3] * 2 + tl[2] + tl[1] + tl[0]) / (256 * 8); *(ap++) += tl[4]; \
+    tl[4] = (((Sint32) sp[FP_GETH32(tmpPos)]) * vol * 3 + tl[3] * 2 + tl[2] + tl[1] + tl[0]) / (256 * 8); *(ap++) += tl[4]; \
 
 #define JMIXER_NAME        jvmMix_Mono_C_FW
 #define JMIXER_NEXT        FP_ADD(tmpPos, tmpDelta);
@@ -40,12 +40,12 @@
 #define JMIXER_INIT
 
 #define JMIXER_FUNC \
-    const Sint32 vol_l = (FP_GETH(tmpVolume) * mixer->globalVol) / 256, \
-                 vol_r = (FP_GETH(tmpVolume) * mixer->globalVol) / 256; \
+    const Sint32 vol_l = (FP_GETH32(tmpVolume) * mixer->globalVol) / 256, \
+                 vol_r = (FP_GETH32(tmpVolume) * mixer->globalVol) / 256; \
     memmove(&tl[0], &tl[1], 4 * sizeof(tl[0])); \
     memmove(&tr[0], &tr[1], 4 * sizeof(tr[0])); \
-    tl[4] = (((Sint32) sp[FP_GETH(tmpPos)]) * vol_l * 3 + tl[3] * 2 + tl[2] + tl[1] + tl[0]) / (256 * 8); *(ap++) += tl[4]; \
-    tr[4] = (((Sint32) sp[FP_GETH(tmpPos)]) * vol_r * 3 + tr[3] * 2 + tr[2] + tr[1] + tr[0]) / (256 * 8); *(ap++) += tr[4];
+    tl[4] = (((Sint32) sp[FP_GETH32(tmpPos)]) * vol_l * 3 + tl[3] * 2 + tl[2] + tl[1] + tl[0]) / (256 * 8); *(ap++) += tl[4]; \
+    tr[4] = (((Sint32) sp[FP_GETH32(tmpPos)]) * vol_r * 3 + tr[3] * 2 + tr[2] + tr[1] + tr[0]) / (256 * 8); *(ap++) += tr[4];
 
 #define JMIXER_NAME        jvmMix_Stereo_C_FW
 #define JMIXER_NEXT        FP_ADD(tmpPos, tmpDelta);
--- a/minijss/jssmix.c	Tue May 13 18:18:10 2014 +0300
+++ b/minijss/jssmix.c	Wed May 14 21:28:14 2014 +0300
@@ -324,13 +324,13 @@
             DBG("MIX_FW[%p : %d : ", ab, mixDone);
             if (chn->chFlags & jsfLooped)
             {
-                DBG("%d (%x)] {loop}\n", FP_GETH(chn->chLoopE), FP_GETH(chn->chLoopE));
+                DBG("%d (%x)] {loop}\n", FP_GETH32(chn->chLoopE), FP_GETH32(chn->chLoopE));
                 mixResult = mixer->jvmMixChannel_FW((void *) mixer, chn,
                     ab, mixDone, chn->chLoopE);
             }
             else
             {
-                DBG("%d (%x)]\n", FP_GETH(chn->chSize), FP_GETH(chn->chSize));
+                DBG("%d (%x)]\n", FP_GETH32(chn->chSize), FP_GETH32(chn->chSize));
                 mixResult = mixer->jvmMixChannel_FW((void *) mixer, chn,
                     ab, mixDone, chn->chSize);
             }
@@ -596,7 +596,7 @@
     int tmp;
 
     JSS_LOCK(mixer);
-    tmp = FP_GETH(mixer->channels[channel].chVolume);
+    tmp = FP_GETH32(mixer->channels[channel].chVolume);
     JSS_UNLOCK(mixer);
 
     return tmp;
@@ -616,7 +616,7 @@
     Sint32 tmp;
 
     JSS_LOCK(mixer);
-    tmp = FP_GETH(mixer->channels[channel].chPos);
+    tmp = FP_GETH32(mixer->channels[channel].chPos);
     JSS_UNLOCK(mixer);
 
     return tmp;
@@ -657,7 +657,7 @@
     int tmp;
 
     JSS_LOCK(mixer);
-    tmp = FP_GETH(mixer->channels[channel].chPanning);
+    tmp = FP_GETH32(mixer->channels[channel].chPanning);
     JSS_UNLOCK(mixer);
 
     return tmp;
--- a/tests/fptest.c	Tue May 13 18:18:10 2014 +0300
+++ b/tests/fptest.c	Wed May 14 21:28:14 2014 +0300
@@ -8,8 +8,8 @@
 {
     DMFixedPoint *q = (DMFixedPoint *) &dw;
 
-    printf("%-15s = ", str); FP_PRINTF(v); printf("\n");
-    printf("should be       = "); FP_PRINTF((*q)); printf("\n");
+    printf("%-15s = ", str); FP_PRINTF64(v); printf("\n");
+    printf("should be       = "); FP_PRINTF64((*q)); printf("\n");
 
     if (v.dw != dw)
     {
@@ -40,8 +40,8 @@
     
     printf(
     "sizeof(DMFixedPoint)      = %d bytes\n"
-    "sizeof(DMFixedPoint.dw    = %d bytes (should be %d)\n"
-    "sizeof(DMFixedPoint.w[0]  = %d bytes (should be %d)\n",
+    "sizeof(DMFixedPoint.dw)   = %d bytes (should be %d)\n"
+    "sizeof(DMFixedPoint.w[0]) = %d bytes (should be %d)\n",
     sizeof(a), sizeof(a.dw), FP_DW_SIZE,
     sizeof(a.w[0]), FP_W0_SIZE);
     
--- a/tools/ppl.c	Tue May 13 18:18:10 2014 +0300
+++ b/tools/ppl.c	Wed May 14 21:28:14 2014 +0300
@@ -261,9 +261,9 @@
     if (yh < 10 || chn == NULL)
         return;
 
-    int xc, ym = y0 + (y1 - y0) / 2, vol = FP_GETH(chn->chVolume);
+    int xc, ym = y0 + (y1 - y0) / 2, vol = FP_GETH32(chn->chVolume);
     int pitch = screen->pitch / sizeof(Uint32);
-    int len = FP_GETH(chn->chSize);
+    int len = FP_GETH32(chn->chSize);
     DMFixedPoint offs = chn->chPos;
     Uint32 coln = dmCol(0.0, 0.8, 0.0), colx = dmCol(1.0, 0, 0);
     Uint32 *pix = screen->pixels;
@@ -282,9 +282,9 @@
     {
         for (xc = x0 + 1; xc < x1 - 1; xc++)
         {
-            if (FP_GETH(offs) >= len)
+            if (FP_GETH32(offs) >= len)
                 break;
-            Sint16 val = ym + (data[FP_GETH(offs)] * yh * vol) / (65535 * 255);
+            Sint16 val = ym + (data[FP_GETH32(offs)] * yh * vol) / (65535 * 255);
             pix[xc + val * pitch] = coln;
             FP_ADD(offs, chn->chDeltaO);
         }
@@ -293,9 +293,9 @@
     {
         for (xc = x0 + 1; xc < x1 - 1; xc++)
         {
-            if (FP_GETH(offs) < 0)
+            if (FP_GETH32(offs) < 0)
                 break;
-            Sint16 val = ym + (data[FP_GETH(offs)] * yh * vol) / (65535 * 255);
+            Sint16 val = ym + (data[FP_GETH32(offs)] * yh * vol) / (65535 * 255);
             pix[xc + val * pitch] = coln;
             FP_SUB(offs, chn->chDeltaO);
         }