1658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat/*
2658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat * Copyright (C) 2013 The Android Open Source Project
3658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat * All rights reserved.
4658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat *
5658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat * Redistribution and use in source and binary forms, with or without
6658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat * modification, are permitted provided that the following conditions
7658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat * are met:
8658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat *  * Redistributions of source code must retain the above copyright
9658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat *    notice, this list of conditions and the following disclaimer.
10658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat *  * Redistributions in binary form must reproduce the above copyright
11658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat *    notice, this list of conditions and the following disclaimer in
12658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat *    the documentation and/or other materials provided with the
13658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat *    distribution.
14658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat *
15658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat * SUCH DAMAGE.
27658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat */
28658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat
29658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat#include <stdio.h>
30658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat#include <stdint.h>
313078b13b98ad8d29dcb2b7e3665c0c92944404a9Ashok Bhat#include <inttypes.h>
32658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat
33658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat#include "private/pixelflinger/ggl_fixed.h"
34658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat
35658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat// gglClampx() tests
36658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhatstruct gglClampx_test_t
37658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat{
38658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    GGLfixed input;
39658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    GGLfixed output;
40658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat};
41658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat
42658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok BhatgglClampx_test_t gglClampx_tests[] =
43658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat{
44658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {FIXED_ONE + 1, FIXED_ONE},
45658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {FIXED_ONE, FIXED_ONE},
46658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {FIXED_ONE - 1, FIXED_ONE - 1},
47658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {1, 1},
48658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {0, 0},
49658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {FIXED_MIN,0}
50658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat};
51658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat
52658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhatvoid gglClampx_test()
53658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat{
54658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    uint32_t i;
55658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat
56658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    printf("Testing gglClampx\n");
57658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    for(i = 0; i < sizeof(gglClampx_tests)/sizeof(gglClampx_test_t); ++i)
58658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {
59658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        gglClampx_test_t *test = &gglClampx_tests[i];
60658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        printf("Test input=0x%08x output=0x%08x :",
61658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat                test->input, test->output);
62658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        if(gglClampx(test->input) == test->output)
63658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat            printf("Passed\n");
64658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        else
65658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat            printf("Failed\n");
66658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    }
67658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat}
68658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat
69658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat// gglClz() tests
70658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhatstruct gglClz_test_t
71658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat{
72658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    GGLfixed input;
73658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    GGLfixed output;
74658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat};
75658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat
76658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok BhatgglClz_test_t gglClz_tests[] =
77658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat{
78658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {0, 32},
79658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {1, 31},
80658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {-1,0}
81658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat};
82658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat
83658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhatvoid gglClz_test()
84658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat{
85658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    uint32_t i;
86658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat
87658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    printf("Testing gglClz\n");
88658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    for(i = 0; i < sizeof(gglClz_tests)/sizeof(gglClz_test_t); ++i)
89658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {
90658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        gglClz_test_t *test = &gglClz_tests[i];
91658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        printf("Test input=0x%08x output=%2d :", test->input, test->output);
92658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        if(gglClz(test->input) == test->output)
93658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat            printf("Passed\n");
94658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        else
95658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat            printf("Failed\n");
96658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    }
97658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat}
98658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat
99658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat// gglMulx() tests
100658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhatstruct gglMulx_test_t
101658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat{
102658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    GGLfixed x;
103658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    GGLfixed y;
104658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    int      shift;
105658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat};
106658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat
107658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok BhatgglMulx_test_t gglMulx_tests[] =
108658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat{
109658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {1,1,1},
110658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {0,1,1},
111658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {FIXED_ONE,FIXED_ONE,16},
112658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {FIXED_MIN,FIXED_MAX,16},
113658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {FIXED_MAX,FIXED_MAX,16},
114658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {FIXED_MIN,FIXED_MIN,16},
115658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {FIXED_HALF,FIXED_ONE,16},
116658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {FIXED_MAX,FIXED_MAX,31},
117658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {FIXED_ONE,FIXED_MAX,31}
118658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat};
119658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat
120658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhatvoid gglMulx_test()
121658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat{
122658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    uint32_t i;
123658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    GGLfixed actual, expected;
124658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat
125658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    printf("Testing gglMulx\n");
126658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    for(i = 0; i < sizeof(gglMulx_tests)/sizeof(gglMulx_test_t); ++i)
127658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {
128658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        gglMulx_test_t *test = &gglMulx_tests[i];
129658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        printf("Test x=0x%08x y=0x%08x shift=%2d :",
130658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat                test->x, test->y, test->shift);
131658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        actual = gglMulx(test->x, test->y, test->shift);
132658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        expected =
133658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat          ((int64_t)test->x * test->y + (1 << (test->shift-1))) >> test->shift;
134658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    if(actual == expected)
135658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        printf(" Passed\n");
136658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    else
137658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        printf(" Failed Actual(0x%08x) Expected(0x%08x)\n",
138658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat               actual, expected);
139658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    }
140658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat}
141658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat// gglMulAddx() tests
142658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhatstruct gglMulAddx_test_t
143658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat{
144658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    GGLfixed x;
145658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    GGLfixed y;
146658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    int      shift;
147658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    GGLfixed a;
148658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat};
149658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat
150658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok BhatgglMulAddx_test_t gglMulAddx_tests[] =
151658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat{
152658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {1,2,1,1},
153658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {0,1,1,1},
154658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {FIXED_ONE,FIXED_ONE,16, 0},
155658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {FIXED_MIN,FIXED_MAX,16, FIXED_HALF},
156658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {FIXED_MAX,FIXED_MAX,16, FIXED_MIN},
157658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {FIXED_MIN,FIXED_MIN,16, FIXED_MAX},
158658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {FIXED_HALF,FIXED_ONE,16,FIXED_ONE},
159658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {FIXED_MAX,FIXED_MAX,31, FIXED_HALF},
160658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {FIXED_ONE,FIXED_MAX,31, FIXED_HALF}
161658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat};
162658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat
163658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhatvoid gglMulAddx_test()
164658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat{
165658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    uint32_t i;
166658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    GGLfixed actual, expected;
167658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat
168658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    printf("Testing gglMulAddx\n");
169658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    for(i = 0; i < sizeof(gglMulAddx_tests)/sizeof(gglMulAddx_test_t); ++i)
170658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {
171658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        gglMulAddx_test_t *test = &gglMulAddx_tests[i];
172658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        printf("Test x=0x%08x y=0x%08x shift=%2d a=0x%08x :",
173658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat                test->x, test->y, test->shift, test->a);
174658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        actual = gglMulAddx(test->x, test->y,test->a, test->shift);
175658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        expected = (((int64_t)test->x * test->y) >> test->shift) + test->a;
176658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat
177658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        if(actual == expected)
178658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat            printf(" Passed\n");
179658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        else
180658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat            printf(" Failed Actual(0x%08x) Expected(0x%08x)\n",
181658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat                    actual, expected);
182658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    }
183658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat}
184658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat// gglMulSubx() tests
185658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhatstruct gglMulSubx_test_t
186658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat{
187658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    GGLfixed x;
188658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    GGLfixed y;
189658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    int      shift;
190658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    GGLfixed a;
191658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat};
192658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat
193658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok BhatgglMulSubx_test_t gglMulSubx_tests[] =
194658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat{
195658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {1,2,1,1},
196658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {0,1,1,1},
197658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {FIXED_ONE,FIXED_ONE,16, 0},
198658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {FIXED_MIN,FIXED_MAX,16, FIXED_HALF},
199658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {FIXED_MAX,FIXED_MAX,16, FIXED_MIN},
200658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {FIXED_MIN,FIXED_MIN,16, FIXED_MAX},
201658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {FIXED_HALF,FIXED_ONE,16,FIXED_ONE},
202658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {FIXED_MAX,FIXED_MAX,31, FIXED_HALF},
203658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {FIXED_ONE,FIXED_MAX,31, FIXED_HALF}
204658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat};
205658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat
206658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhatvoid gglMulSubx_test()
207658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat{
208658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    uint32_t i;
209658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    GGLfixed actual, expected;
210658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat
211658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    printf("Testing gglMulSubx\n");
212658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    for(i = 0; i < sizeof(gglMulSubx_tests)/sizeof(gglMulSubx_test_t); ++i)
213658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {
214658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        gglMulSubx_test_t *test = &gglMulSubx_tests[i];
215658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        printf("Test x=0x%08x y=0x%08x shift=%2d a=0x%08x :",
216658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat                test->x, test->y, test->shift, test->a);
217658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        actual = gglMulSubx(test->x, test->y, test->a, test->shift);
218658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        expected = (((int64_t)test->x * test->y) >> test->shift) - test->a;
219658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat
220658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        if(actual == expected)
221658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat            printf(" Passed\n");
222658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        else
223658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat            printf(" Failed Actual(0x%08x) Expected(0x%08x)\n",
224658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat                actual, expected);
225658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    }
226658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat}
227658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat
228658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat// gglMulii() tests
229658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat
230658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhatstruct gglMulii_test_t
231658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat{
232658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    int32_t x;
233658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    int32_t y;
234658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat};
235658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat
236658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok BhatgglMulii_test_t gglMulii_tests[] =
237658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat{
238658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {1,INT32_MIN},
239658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {1,INT32_MAX},
240658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {0,INT32_MIN},
241658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {0,INT32_MAX},
242658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {INT32_MIN, INT32_MAX},
243658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {INT32_MAX, INT32_MIN},
244658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {INT32_MIN, INT32_MIN},
245658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {INT32_MAX, INT32_MAX}
246658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat};
247658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat
248658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhatvoid gglMulii_test()
249658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat{
250658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    uint32_t i;
251658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    int64_t actual, expected;
252658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat
253658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    printf("Testing gglMulii\n");
254658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    for(i = 0; i < sizeof(gglMulii_tests)/sizeof(gglMulii_test_t); ++i)
255658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    {
256658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        gglMulii_test_t *test = &gglMulii_tests[i];
257658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        printf("Test x=0x%08x y=0x%08x :", test->x, test->y);
258658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        actual = gglMulii(test->x, test->y);
259658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        expected = ((int64_t)test->x * test->y);
260658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat
261658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        if(actual == expected)
262658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat            printf(" Passed\n");
263658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat        else
2643078b13b98ad8d29dcb2b7e3665c0c92944404a9Ashok Bhat            printf(" Failed Actual(%" PRId64 ") Expected(%" PRId64 ")\n",
265658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat                    actual, expected);
266658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    }
267658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat}
268658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat
2693078b13b98ad8d29dcb2b7e3665c0c92944404a9Ashok Bhatint main(int /*argc*/, char** /*argv*/)
270658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat{
271658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    gglClampx_test();
272658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    gglClz_test();
273658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    gglMulx_test();
274658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    gglMulAddx_test();
275658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    gglMulSubx_test();
276658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    gglMulii_test();
277658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat    return 0;
278658f89dc5c418dbbc0c5d78f5861855b90ca8c9fAshok Bhat}
279