[3/3] vcomp: Implement _vcomp_reduction_{u,i}1 and add tests. (v2)

Sebastian Lackner sebastian at fds-team.de
Wed Sep 7 03:56:16 CDT 2016


Signed-off-by: Sebastian Lackner <sebastian at fds-team.de>
---
 dlls/vcomp/main.c           |   30 ++++++++++++++++++++++++++
 dlls/vcomp/tests/vcomp.c    |   49 ++++++++++++++++++++++++++++++++++++++++++++
 dlls/vcomp/vcomp.spec       |    4 +--
 dlls/vcomp100/vcomp100.spec |    4 +--
 dlls/vcomp110/vcomp110.spec |    4 +--
 dlls/vcomp120/vcomp120.spec |    4 +--
 dlls/vcomp140/vcomp140.spec |    4 +--
 dlls/vcomp90/vcomp90.spec   |    4 +--
 8 files changed, 91 insertions(+), 12 deletions(-)

diff --git a/dlls/vcomp/main.c b/dlls/vcomp/main.c
index a3a29db..ba7ead7 100644
--- a/dlls/vcomp/main.c
+++ b/dlls/vcomp/main.c
@@ -452,6 +452,36 @@ void CDECL _vcomp_atomic_xor_i1(char *dest, char val)
     do old = *dest; while (interlocked_cmpxchg8(dest, old ^ val, old) != old);
 }
 
+static void CDECL _vcomp_atomic_bool_and_i1(char *dest, char val)
+{
+    char old;
+    do old = *dest; while (interlocked_cmpxchg8(dest, old && val, old) != old);
+}
+
+static void CDECL _vcomp_atomic_bool_or_i1(char *dest, char val)
+{
+    char old;
+    do old = *dest; while (interlocked_cmpxchg8(dest, old ? old : (val != 0), old) != old);
+}
+
+void CDECL _vcomp_reduction_i1(unsigned int flags, char *dest, char val)
+{
+    static void (CDECL * const funcs[])(char *, char) =
+    {
+        _vcomp_atomic_add_i1,
+        _vcomp_atomic_add_i1,
+        _vcomp_atomic_mul_i1,
+        _vcomp_atomic_and_i1,
+        _vcomp_atomic_or_i1,
+        _vcomp_atomic_xor_i1,
+        _vcomp_atomic_bool_and_i1,
+        _vcomp_atomic_bool_or_i1,
+    };
+    unsigned int op = (flags >> 8) & 0xf;
+    op = min(op, sizeof(funcs)/sizeof(funcs[0]) - 1);
+    funcs[op](dest, val);
+}
+
 void CDECL _vcomp_atomic_add_i2(short *dest, short val)
 {
     interlocked_xchg_add16(dest, val);
diff --git a/dlls/vcomp/tests/vcomp.c b/dlls/vcomp/tests/vcomp.c
index 5911601..3ecbde6 100644
--- a/dlls/vcomp/tests/vcomp.c
+++ b/dlls/vcomp/tests/vcomp.c
@@ -103,8 +103,10 @@ static int   (CDECL   *p_vcomp_get_thread_num)(void);
 static void  (CDECL   *p_vcomp_leave_critsect)(CRITICAL_SECTION *critsect);
 static int   (CDECL   *p_vcomp_master_begin)(void);
 static void  (CDECL   *p_vcomp_master_end)(void);
+static void  (CDECL   *p_vcomp_reduction_i1)(unsigned int flags, char *dest, char val);
 static void  (CDECL   *p_vcomp_reduction_i2)(unsigned int flags, short *dest, short val);
 static void  (CDECL   *p_vcomp_reduction_i4)(unsigned int flags, int *dest, int val);
+static void  (CDECL   *p_vcomp_reduction_u1)(unsigned int flags, unsigned char *dest, unsigned char val);
 static void  (CDECL   *p_vcomp_reduction_u2)(unsigned int flags, unsigned short *dest, unsigned short val);
 static void  (CDECL   *p_vcomp_reduction_u4)(unsigned int flags, unsigned int *dest, unsigned int val);
 static void  (CDECL   *p_vcomp_sections_init)(int n);
@@ -348,8 +350,10 @@ static BOOL init_vcomp(void)
     VCOMP_GET_PROC(_vcomp_leave_critsect);
     VCOMP_GET_PROC(_vcomp_master_begin);
     VCOMP_GET_PROC(_vcomp_master_end);
+    VCOMP_GET_PROC(_vcomp_reduction_i1);
     VCOMP_GET_PROC(_vcomp_reduction_i2);
     VCOMP_GET_PROC(_vcomp_reduction_i4);
+    VCOMP_GET_PROC(_vcomp_reduction_u1);
     VCOMP_GET_PROC(_vcomp_reduction_u2);
     VCOMP_GET_PROC(_vcomp_reduction_u4);
     VCOMP_GET_PROC(_vcomp_sections_init);
@@ -1887,6 +1891,50 @@ static void test_atomic_double(void)
     }
 }
 
+static void test_reduction_integer8(void)
+{
+    struct
+    {
+        unsigned int flags;
+        char v1, v2, expected;
+    }
+    tests[] =
+    {
+        { 0x000,                            0x11,  0x77, -0x78 },
+        { VCOMP_REDUCTION_FLAGS_ADD,        0x11,  0x77, -0x78 },
+        { VCOMP_REDUCTION_FLAGS_MUL,        0x11,  0x77, -0x19 },
+        { VCOMP_REDUCTION_FLAGS_MUL,        0x11, -0x77,  0x19 },
+        { VCOMP_REDUCTION_FLAGS_AND,        0x11,  0x77,  0x11 },
+        { VCOMP_REDUCTION_FLAGS_OR,         0x11,  0x77,  0x77 },
+        { VCOMP_REDUCTION_FLAGS_XOR,        0x11,  0x77,  0x66 },
+        { VCOMP_REDUCTION_FLAGS_BOOL_AND,      1,     2,     1 },
+        { VCOMP_REDUCTION_FLAGS_BOOL_OR,       0,     2,     1 },
+        { 0x800,                               0,     2,     1 },
+        { 0x900,                               0,     2,     1 },
+        { 0xa00,                               0,     2,     1 },
+        { 0xb00,                               0,     2,     1 },
+        { 0xc00,                               0,     2,     1 },
+        { 0xd00,                               0,     2,     1 },
+        { 0xe00,                               0,     2,     1 },
+        { 0xf00,                               0,     2,     1 },
+    };
+    int i;
+
+    for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++)
+    {
+        char val = tests[i].v1;
+        p_vcomp_reduction_i1(tests[i].flags, &val, tests[i].v2);
+        ok(val == tests[i].expected, "test %d: expected val == %d, got %d\n", i, tests[i].expected, val);
+    }
+    for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++)
+    {
+        unsigned char val = tests[i].v1;
+        p_vcomp_reduction_u1(tests[i].flags, &val, tests[i].v2);
+        ok(val == (unsigned char)tests[i].expected,
+           "test %d: expected val == %u, got %u\n", i, (unsigned char)tests[i].expected, val);
+    }
+}
+
 static void test_reduction_integer16(void)
 {
     struct
@@ -2037,6 +2085,7 @@ START_TEST(vcomp)
     test_atomic_integer64();
     test_atomic_float();
     test_atomic_double();
+    test_reduction_integer8();
     test_reduction_integer16();
     test_reduction_integer32();
 
diff --git a/dlls/vcomp/vcomp.spec b/dlls/vcomp/vcomp.spec
index 85df49e..eb5f39c 100644
--- a/dlls/vcomp/vcomp.spec
+++ b/dlls/vcomp/vcomp.spec
@@ -73,13 +73,13 @@
 @ stub _vcomp_ordered_begin
 @ stub _vcomp_ordered_end
 @ stub _vcomp_ordered_loop_end
-@ stub _vcomp_reduction_i1
+@ cdecl _vcomp_reduction_i1(long ptr long)
 @ cdecl _vcomp_reduction_i2(long ptr long)
 @ cdecl _vcomp_reduction_i4(long ptr long)
 @ stub _vcomp_reduction_i8
 @ stub _vcomp_reduction_r4
 @ stub _vcomp_reduction_r8
-@ stub _vcomp_reduction_u1
+@ cdecl _vcomp_reduction_u1(long ptr long) _vcomp_reduction_i1
 @ cdecl _vcomp_reduction_u2(long ptr long) _vcomp_reduction_i2
 @ cdecl _vcomp_reduction_u4(long ptr long) _vcomp_reduction_i4
 @ stub _vcomp_reduction_u8
diff --git a/dlls/vcomp100/vcomp100.spec b/dlls/vcomp100/vcomp100.spec
index 49f5a1b..73543c1 100644
--- a/dlls/vcomp100/vcomp100.spec
+++ b/dlls/vcomp100/vcomp100.spec
@@ -73,13 +73,13 @@
 @ stub _vcomp_ordered_begin
 @ stub _vcomp_ordered_end
 @ stub _vcomp_ordered_loop_end
-@ stub _vcomp_reduction_i1
+@ cdecl _vcomp_reduction_i1(long ptr long) vcomp._vcomp_reduction_i1
 @ cdecl _vcomp_reduction_i2(long ptr long) vcomp._vcomp_reduction_i2
 @ cdecl _vcomp_reduction_i4(long ptr long) vcomp._vcomp_reduction_i4
 @ stub _vcomp_reduction_i8
 @ stub _vcomp_reduction_r4
 @ stub _vcomp_reduction_r8
-@ stub _vcomp_reduction_u1
+@ cdecl _vcomp_reduction_u1(long ptr long) vcomp._vcomp_reduction_u1
 @ cdecl _vcomp_reduction_u2(long ptr long) vcomp._vcomp_reduction_u2
 @ cdecl _vcomp_reduction_u4(long ptr long) vcomp._vcomp_reduction_u4
 @ stub _vcomp_reduction_u8
diff --git a/dlls/vcomp110/vcomp110.spec b/dlls/vcomp110/vcomp110.spec
index dd9537a..6fb3811 100644
--- a/dlls/vcomp110/vcomp110.spec
+++ b/dlls/vcomp110/vcomp110.spec
@@ -74,13 +74,13 @@
 @ stub _vcomp_ordered_begin
 @ stub _vcomp_ordered_end
 @ stub _vcomp_ordered_loop_end
-@ stub _vcomp_reduction_i1
+@ cdecl _vcomp_reduction_i1(long ptr long) vcomp._vcomp_reduction_i1
 @ cdecl _vcomp_reduction_i2(long ptr long) vcomp._vcomp_reduction_i2
 @ cdecl _vcomp_reduction_i4(long ptr long) vcomp._vcomp_reduction_i4
 @ stub _vcomp_reduction_i8
 @ stub _vcomp_reduction_r4
 @ stub _vcomp_reduction_r8
-@ stub _vcomp_reduction_u1
+@ cdecl _vcomp_reduction_u1(long ptr long) vcomp._vcomp_reduction_u1
 @ cdecl _vcomp_reduction_u2(long ptr long) vcomp._vcomp_reduction_u2
 @ cdecl _vcomp_reduction_u4(long ptr long) vcomp._vcomp_reduction_u4
 @ stub _vcomp_reduction_u8
diff --git a/dlls/vcomp120/vcomp120.spec b/dlls/vcomp120/vcomp120.spec
index dd9537a..6fb3811 100644
--- a/dlls/vcomp120/vcomp120.spec
+++ b/dlls/vcomp120/vcomp120.spec
@@ -74,13 +74,13 @@
 @ stub _vcomp_ordered_begin
 @ stub _vcomp_ordered_end
 @ stub _vcomp_ordered_loop_end
-@ stub _vcomp_reduction_i1
+@ cdecl _vcomp_reduction_i1(long ptr long) vcomp._vcomp_reduction_i1
 @ cdecl _vcomp_reduction_i2(long ptr long) vcomp._vcomp_reduction_i2
 @ cdecl _vcomp_reduction_i4(long ptr long) vcomp._vcomp_reduction_i4
 @ stub _vcomp_reduction_i8
 @ stub _vcomp_reduction_r4
 @ stub _vcomp_reduction_r8
-@ stub _vcomp_reduction_u1
+@ cdecl _vcomp_reduction_u1(long ptr long) vcomp._vcomp_reduction_u1
 @ cdecl _vcomp_reduction_u2(long ptr long) vcomp._vcomp_reduction_u2
 @ cdecl _vcomp_reduction_u4(long ptr long) vcomp._vcomp_reduction_u4
 @ stub _vcomp_reduction_u8
diff --git a/dlls/vcomp140/vcomp140.spec b/dlls/vcomp140/vcomp140.spec
index dd9537a..6fb3811 100644
--- a/dlls/vcomp140/vcomp140.spec
+++ b/dlls/vcomp140/vcomp140.spec
@@ -74,13 +74,13 @@
 @ stub _vcomp_ordered_begin
 @ stub _vcomp_ordered_end
 @ stub _vcomp_ordered_loop_end
-@ stub _vcomp_reduction_i1
+@ cdecl _vcomp_reduction_i1(long ptr long) vcomp._vcomp_reduction_i1
 @ cdecl _vcomp_reduction_i2(long ptr long) vcomp._vcomp_reduction_i2
 @ cdecl _vcomp_reduction_i4(long ptr long) vcomp._vcomp_reduction_i4
 @ stub _vcomp_reduction_i8
 @ stub _vcomp_reduction_r4
 @ stub _vcomp_reduction_r8
-@ stub _vcomp_reduction_u1
+@ cdecl _vcomp_reduction_u1(long ptr long) vcomp._vcomp_reduction_u1
 @ cdecl _vcomp_reduction_u2(long ptr long) vcomp._vcomp_reduction_u2
 @ cdecl _vcomp_reduction_u4(long ptr long) vcomp._vcomp_reduction_u4
 @ stub _vcomp_reduction_u8
diff --git a/dlls/vcomp90/vcomp90.spec b/dlls/vcomp90/vcomp90.spec
index 49f5a1b..73543c1 100644
--- a/dlls/vcomp90/vcomp90.spec
+++ b/dlls/vcomp90/vcomp90.spec
@@ -73,13 +73,13 @@
 @ stub _vcomp_ordered_begin
 @ stub _vcomp_ordered_end
 @ stub _vcomp_ordered_loop_end
-@ stub _vcomp_reduction_i1
+@ cdecl _vcomp_reduction_i1(long ptr long) vcomp._vcomp_reduction_i1
 @ cdecl _vcomp_reduction_i2(long ptr long) vcomp._vcomp_reduction_i2
 @ cdecl _vcomp_reduction_i4(long ptr long) vcomp._vcomp_reduction_i4
 @ stub _vcomp_reduction_i8
 @ stub _vcomp_reduction_r4
 @ stub _vcomp_reduction_r8
-@ stub _vcomp_reduction_u1
+@ cdecl _vcomp_reduction_u1(long ptr long) vcomp._vcomp_reduction_u1
 @ cdecl _vcomp_reduction_u2(long ptr long) vcomp._vcomp_reduction_u2
 @ cdecl _vcomp_reduction_u4(long ptr long) vcomp._vcomp_reduction_u4
 @ stub _vcomp_reduction_u8
-- 
2.9.0



More information about the wine-patches mailing list