[PATCH xserver] Fix FP3232 related issues.

Michel Dänzer michel at daenzer.net
Tue Oct 4 08:25:53 PDT 2011


From: Michel Dänzer <michel.daenzer at amd.com>

Make check has been broken since commit
f32c827d513c44f07e1d0fbcc0c96cef18c9a4d9 ('Input: Fix frac calculation on
[Raw]DeviceEvent conversion').

* Use floor() instead of trunc() in order to achieve the inverse of

	FP3232.integral + FP3232.frac / (1ULL << 32)

  even for negative floating point numbers.
* Use (1ULL << 32) instead of (1 << 16) * (1 << 16) in order to save one
  floating point multiplication.
* Fix up test code.

Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
---
 Xi/xiquerydevice.c                |   10 ++++++----
 dix/eventconvert.c                |   12 ++++++------
 test/xi2/protocol-eventconvert.c  |   12 ++++++------
 test/xi2/protocol-xiquerydevice.c |    4 ++--
 4 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/Xi/xiquerydevice.c b/Xi/xiquerydevice.c
index 9961d1b..fb70357 100644
--- a/Xi/xiquerydevice.c
+++ b/Xi/xiquerydevice.c
@@ -351,8 +351,9 @@ ListValuatorInfo(DeviceIntPtr dev, xXIValuatorInfo* info, int axisnumber,
     info->min.frac = 0;
     info->max.integral = v->axes[axisnumber].max_value;
     info->max.frac = 0;
-    info->value.integral = (int)v->axisVal[axisnumber];
-    info->value.frac = (int)(v->axisVal[axisnumber] * (1 << 16) * (1 << 16));
+    info->value.integral = floor(v->axisVal[axisnumber]);
+    info->value.frac = (v->axisVal[axisnumber] - info->value.integral) *
+        (1ULL << 32);
     info->resolution = v->axes[axisnumber].resolution;
     info->number = axisnumber;
     info->mode = valuator_get_mode(dev, axisnumber);
@@ -402,8 +403,9 @@ ListScrollInfo(DeviceIntPtr dev, xXIScrollInfo *info, int axisnumber)
             ErrorF("[Xi] Unknown scroll type %d. This is a bug.\n", axis->scroll.type);
             break;
     }
-    info->increment.integral = (int)axis->scroll.increment;
-    info->increment.frac = (unsigned int)(axis->scroll.increment * (1UL << 16) * (1UL << 16));
+    info->increment.integral = floor(axis->scroll.increment);
+    info->increment.frac = (axis->scroll.increment - info->increment.integral) *
+        (1ULL << 32);
     info->sourceid = v->sourceid;
 
     info->flags = 0;
diff --git a/dix/eventconvert.c b/dix/eventconvert.c
index f9aafa5..3fc29e3 100644
--- a/dix/eventconvert.c
+++ b/dix/eventconvert.c
@@ -633,9 +633,9 @@ eventToDeviceEvent(DeviceEvent *ev, xEvent **xi)
         if (BitIsOn(ev->valuators.mask, i))
         {
             SetBit(ptr, i);
-            axisval->integral = trunc(ev->valuators.data[i]);
+            axisval->integral = floor(ev->valuators.data[i]);
             axisval->frac = (ev->valuators.data[i] - axisval->integral) *
-                            (1 << 16) * (1 << 16);
+                            (1ULL << 32);
             axisval++;
         }
     }
@@ -678,13 +678,13 @@ eventToRawEvent(RawDeviceEvent *ev, xEvent **xi)
         if (BitIsOn(ev->valuators.mask, i))
         {
             SetBit(ptr, i);
-            axisval->integral = trunc(ev->valuators.data[i]);
+            axisval->integral = floor(ev->valuators.data[i]);
             axisval->frac = (ev->valuators.data[i] - axisval->integral) *
-                            (1 << 16) * (1 << 16);
-            axisval_raw->integral = trunc(ev->valuators.data_raw[i]);
+                            (1ULL << 32);
+            axisval_raw->integral = floor(ev->valuators.data_raw[i]);
             axisval_raw->frac =
                 (ev->valuators.data_raw[i] - axisval_raw->integral) *
-                  (1 << 16) * (1 << 16);
+                  (1ULL << 32);
             axisval++;
             axisval_raw++;
         }
diff --git a/test/xi2/protocol-eventconvert.c b/test/xi2/protocol-eventconvert.c
index bfa23b5..fc82747 100644
--- a/test/xi2/protocol-eventconvert.c
+++ b/test/xi2/protocol-eventconvert.c
@@ -104,8 +104,8 @@ static void test_values_XIRawEvent(RawDeviceEvent *in, xXIRawEvent *out,
             value = (FP3232*)(((unsigned char*)&out[1]) + out->valuators_len * 4);
             value += nvals;
 
-            vi.integral = trunc(in->valuators.data[i]);
-            vi.frac = in->valuators.data[i] - vi.integral;
+            vi.integral = floor(in->valuators.data[i]);
+            vi.frac = (in->valuators.data[i] - vi.integral) * (1ULL << 32);
 
             vo.integral = value->integral;
             vo.frac = value->frac;
@@ -120,8 +120,8 @@ static void test_values_XIRawEvent(RawDeviceEvent *in, xXIRawEvent *out,
 
             raw_value = value + bits_set;
 
-            vi.integral = trunc(in->valuators.data_raw[i]);
-            vi.frac = in->valuators.data_raw[i] - vi.integral;
+            vi.integral = floor(in->valuators.data_raw[i]);
+            vi.frac = (in->valuators.data_raw[i] - vi.integral) * (1ULL << 32);
 
             vo.integral = raw_value->integral;
             vo.frac = raw_value->frac;
@@ -390,8 +390,8 @@ static void test_values_XIDeviceEvent(DeviceEvent *in, xXIDeviceEvent *out,
             {
                 FP3232 vi, vo;
 
-                vi.integral = trunc(in->valuators.data[i]);
-                vi.frac = (in->valuators.data[i] - vi.integral) * (1UL << 32);
+                vi.integral = floor(in->valuators.data[i]);
+                vi.frac = (in->valuators.data[i] - vi.integral) * (1ULL << 32);
 
                 vo = *values;
 
diff --git a/test/xi2/protocol-xiquerydevice.c b/test/xi2/protocol-xiquerydevice.c
index 63d725f..370d4d0 100644
--- a/test/xi2/protocol-xiquerydevice.c
+++ b/test/xi2/protocol-xiquerydevice.c
@@ -214,8 +214,8 @@ static void reply_XIQueryDevice_data(ClientPtr client, int len, char *data, void
 
                             assert(si->increment.integral == si->number);
                             /* FIXME: frac testing with float/FP issues? */
-                            assert(si->increment.frac > 0.3  * (1UL << 32));
-                            assert(si->increment.frac < 0.6  * (1UL << 32));
+                            assert(si->increment.frac > 0.3 * (1ULL << 32));
+                            assert(si->increment.frac < 0.6 * (1ULL << 32));
                         }
 
                     }
-- 
1.7.6.3



More information about the xorg-devel mailing list