[Xquartz-changes] xserver: Branch 'for-keith' - 3 commits

Jeremy Huddleston jeremyhu at freedesktop.org
Mon Oct 17 23:49:17 PDT 2011


Rebased ref, commits from common ancestor:
commit b0ec25bc2c131c98907a9d9cd95b884826bb5cf9
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Sat Oct 30 14:55:06 2010 -0700

    configure.ac: Add -fno-strict-aliasing to CFLAGS
    
    This should force the server to have -fno-strict-aliasing even once it
    is removed from the warning flags.
    
    See: https://bugs.freedesktop.org/show_bug.cgi?id=31238
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Gaetan Nadon <memsize at videotron.ca>

diff --git a/configure.ac b/configure.ac
index 67a6836..2918435 100644
--- a/configure.ac
+++ b/configure.ac
@@ -87,6 +87,12 @@ XORG_PROG_RAWCPP
 # easier overrides at build time.
 XSERVER_CFLAGS='$(CWARNFLAGS)'
 
+dnl Explicitly add -fno-strict-aliasing since this option should disappear
+dnl from util-macros CWARNFLAGS
+if  test "x$GCC" = xyes ; then
+    XSERVER_CFLAGS="$XSERVER_CFLAGS -fno-strict-aliasing"
+fi
+
 dnl Check for dtrace program (needed to build Xserver dtrace probes)
 dnl Also checks for <sys/sdt.h>, since some Linux distros have an 
 dnl ISDN trace program named dtrace
commit 597dc64eeafe5a2b80d2c2b70c4fee0f7344202e
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Oct 12 09:59:38 2011 +0100

    test: fix input test
    
    The test was memsetting the wrong thing, this fixes make check in my tinderbox.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/test/input.c b/test/input.c
index 950350f..a483957 100644
--- a/test/input.c
+++ b/test/input.c
@@ -1309,17 +1309,17 @@ static void dix_get_master(void)
     SpriteInfoRec ptr_sprite, kbd_sprite;
     SpriteInfoRec floating_sprite;
 
-    memset(&vcp, 0, sizeof(DeviceIntRec));
-    memset(&vck, 0, sizeof(DeviceIntRec));
-    memset(&ptr, 0, sizeof(DeviceIntRec));
-    memset(&kbd, 0, sizeof(DeviceIntRec));
-    memset(&floating, 0, sizeof(DeviceIntRec));
-
-    memset(&vcp_sprite, 0, sizeof(DeviceIntRec));
-    memset(&vck_sprite, 0, sizeof(DeviceIntRec));
-    memset(&ptr_sprite, 0, sizeof(DeviceIntRec));
-    memset(&kbd_sprite, 0, sizeof(DeviceIntRec));
-    memset(&floating_sprite, 0, sizeof(DeviceIntRec));
+    memset(&vcp, 0, sizeof(vcp));
+    memset(&vck, 0, sizeof(vck));
+    memset(&ptr, 0, sizeof(ptr));
+    memset(&kbd, 0, sizeof(kbd));
+    memset(&floating, 0, sizeof(floating));
+
+    memset(&vcp_sprite, 0, sizeof(vcp_sprite));
+    memset(&vck_sprite, 0, sizeof(vck_sprite));
+    memset(&ptr_sprite, 0, sizeof(ptr_sprite));
+    memset(&kbd_sprite, 0, sizeof(kbd_sprite));
+    memset(&floating_sprite, 0, sizeof(floating_sprite));
 
     vcp.type = MASTER_POINTER;
     vck.type = MASTER_KEYBOARD;
commit 6cafd1b84da38052b1c4f1fc07c08e569e5ab949
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Wed Oct 5 15:02:52 2011 -0700

    dix: add utility functions for double to/fro FP1616/FP3232 conversion
    
    Co-authored-by: Jeremy Huddleston <jeremyhu at apple.com>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Mark Kettenis <kettenis at openbsd.org>

diff --git a/dix/inpututils.c b/dix/inpututils.c
index eeae2a7..5c76361 100644
--- a/dix/inpututils.c
+++ b/dix/inpututils.c
@@ -767,3 +767,66 @@ input_option_set_value(InputOption *opt, const char *value)
     if (value)
         opt->value = strdup(value);
 }
+
+
+/* FP1616/FP3232 conversion functions.
+ * Fixed point types are encoded as signed integral and unsigned frac. So any
+ * negative number -n.m is encoded as floor(n) + (1 - 0.m).
+ */
+double
+fp1616_to_double(FP1616 in)
+{
+    double ret;
+
+    ret  = (double)(in >> 16);
+    ret += (double)(in & 0xffff) * (1.0 / (1UL << 16)); /* Optimized: ldexp((double)(in & 0xffff), -16); */
+    return ret;
+}
+
+double
+fp3232_to_double(FP3232 in)
+{
+    double ret;
+    ret  = (double)in.integral;
+    ret += (double)in.frac * (1.0 / (1ULL << 32)); /* Optimized: ldexp((double)in.frac, -32); */
+    return ret;
+}
+
+
+FP1616
+double_to_fp1616(double in)
+{
+    FP1616 ret;
+    int32_t integral;
+    double tmp;
+    uint32_t frac_d;
+
+    tmp = floor(in);
+    integral = (int32_t)tmp;
+
+    tmp = (in - integral) * (1UL << 16); /* Optimized: ldexp(in - integral, 16) */
+    frac_d = (uint16_t)tmp;
+
+    ret = integral << 16;
+    ret |= frac_d & 0xffff;
+    return ret;
+}
+
+FP3232
+double_to_fp3232(double in)
+{
+    FP3232 ret;
+    int32_t integral;
+    double tmp;
+    uint32_t frac_d;
+
+    tmp = floor(in);
+    integral = (int32_t)tmp;
+
+    tmp = (in - integral) * (1ULL << 32); /* Optimized: ldexp(in - integral, 32) */
+    frac_d = (uint32_t)tmp;
+
+    ret.integral = integral;
+    ret.frac = frac_d;
+    return ret;
+}
diff --git a/include/inpututils.h b/include/inpututils.h
index 47e242d..2832ed5 100644
--- a/include/inpututils.h
+++ b/include/inpututils.h
@@ -30,6 +30,7 @@
 #define INPUTUTILS_H
 
 #include "input.h"
+#include <X11/extensions/XI2proto.h>
 
 struct _ValuatorMask {
     int8_t      last_bit; /* highest bit set in mask */
@@ -40,4 +41,9 @@ struct _ValuatorMask {
 extern void verify_internal_event(const InternalEvent *ev);
 extern void init_device_event(DeviceEvent *event, DeviceIntPtr dev, Time ms);
 
+FP3232 double_to_fp3232(double in);
+FP1616 double_to_fp1616(double in);
+double fp1616_to_double(FP1616 in);
+double fp3232_to_double(FP3232 in);
+
 #endif
diff --git a/test/input.c b/test/input.c
index afc4d4d..950350f 100644
--- a/test/input.c
+++ b/test/input.c
@@ -1462,9 +1462,139 @@ static void input_option_test(void)
     assert(list == NULL);
 }
 
+static void
+_test_double_fp16_values(double orig_d)
+{
+    FP1616 first_fp16, final_fp16;
+    double final_d;
+
+    if (orig_d > 0x7FFF) {
+        printf("Test out of range\n");
+        assert(0);
+    }
+
+    first_fp16 = double_to_fp1616(orig_d);
+    final_d = fp1616_to_double(first_fp16);
+    final_fp16 = double_to_fp1616(final_d);
+
+    /* {
+     *    char first_fp16_s[64];
+     *    char final_fp16_s[64];
+     *    snprintf(first_fp16_s, sizeof(first_fp16_s), "%d + %u * 2^-16", (first_fp16 & 0xffff0000) >> 16, first_fp16 & 0xffff);
+     *    snprintf(final_fp16_s, sizeof(final_fp16_s), "%d + %u * 2^-16", (final_fp16 & 0xffff0000) >> 16, final_fp16 & 0xffff);
+     *
+     *    printf("FP16: original double: %f first fp16: %s, re-encoded double: %f, final fp16: %s\n", orig_d, first_fp16_s, final_d, final_fp16_s);
+     * }
+     */
+    /* since we lose precision, we only do rough range testing */
+    assert(final_d > orig_d - 0.1);
+    assert(final_d < orig_d + 0.1);
+
+    assert(memcmp(&first_fp16, &final_fp16, sizeof(FP1616)) == 0);
+
+    if (orig_d > 0)
+        _test_double_fp16_values(-orig_d);
+}
+
+static void
+_test_double_fp32_values(double orig_d)
+{
+    FP3232 first_fp32, final_fp32;
+    double final_d;
+
+    if (orig_d > 0x7FFFFFFF) {
+        printf("Test out of range\n");
+        assert(0);
+    }
+
+    first_fp32 = double_to_fp3232(orig_d);
+    final_d = fp3232_to_double(first_fp32);
+    final_fp32 = double_to_fp3232(final_d);
+
+    /* {
+     *     char first_fp32_s[64];
+     *     char final_fp32_s[64];
+     *     snprintf(first_fp32_s, sizeof(first_fp32_s), "%d + %u * 2^-32", first_fp32.integral, first_fp32.frac);
+     *     snprintf(final_fp32_s, sizeof(final_fp32_s), "%d + %u * 2^-32", first_fp32.integral, final_fp32.frac);
+     *
+     *     printf("FP32: original double: %f first fp32: %s, re-encoded double: %f, final fp32: %s\n", orig_d, first_fp32_s, final_d, final_fp32_s);
+     * }
+     */
+
+    /* since we lose precision, we only do rough range testing */
+    assert(final_d > orig_d - 0.1);
+    assert(final_d < orig_d + 0.1);
+
+    assert(memcmp(&first_fp32, &final_fp32, sizeof(FP3232)) == 0);
+
+    if (orig_d > 0)
+        _test_double_fp32_values(-orig_d);
+}
+
+static void
+dix_double_fp_conversion(void)
+{
+    uint32_t i;
+    printf("Testing double to FP1616/FP3232 conversions\n");
+
+    _test_double_fp16_values(0);
+    for (i = 1; i < 0x7FFF; i <<= 1) {
+        double val;
+
+        val = i;
+        _test_double_fp16_values(val);
+        _test_double_fp32_values(val);
+
+        /* and some pseudo-random floating points */
+        val = i - 0.00382;
+        _test_double_fp16_values(val);
+        _test_double_fp32_values(val);
+
+        val = i + 0.00382;
+        _test_double_fp16_values(val);
+        _test_double_fp32_values(val);
+
+        val = i + 0.05234;
+        _test_double_fp16_values(val);
+        _test_double_fp32_values(val);
+
+        val = i + 0.12342;
+        _test_double_fp16_values(val);
+        _test_double_fp32_values(val);
+
+        val = i + 0.27583;
+        _test_double_fp16_values(val);
+        _test_double_fp32_values(val);
+
+        val = i + 0.50535;
+        _test_double_fp16_values(val);
+        _test_double_fp32_values(val);
+
+        val = i + 0.72342;
+        _test_double_fp16_values(val);
+        _test_double_fp32_values(val);
+
+        val = i + 0.80408;
+        _test_double_fp16_values(val);
+        _test_double_fp32_values(val);
+    }
+
+    for (i = 0x7FFFF; i < 0x7FFFFFFF; i <<= 1) {
+        _test_double_fp32_values(i);
+        /* and a few more random floating points, obtained
+         * by faceplanting into the numpad repeatedly */
+        _test_double_fp32_values(i + 0.010177);
+        _test_double_fp32_values(i + 0.213841);
+        _test_double_fp32_values(i + 0.348720);
+        _test_double_fp32_values(i + 0.472020);
+        _test_double_fp32_values(i + 0.572020);
+        _test_double_fp32_values(i + 0.892929);
+    }
+}
 
 int main(int argc, char** argv)
 {
+    dix_double_fp_conversion();
     dix_input_valuator_masks();
     dix_input_attributes();
     dix_init_valuators();


More information about the Xquartz-changes mailing list