summaryrefslogtreecommitdiffstats
path: root/libacc/tests/data/flops.c
blob: 40b1b283ef077395d4d6cf1f9e149d609ca8cd24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// Test floating point operations.

void unaryOps() {
    // Unary ops
    printf("-%g = %g\n", 1.1, -1.1);
    printf("!%g = %d\n", 1.2, !1.2);
    printf("!%g = %d\n", 0.0, !0.0);
}

void binaryOps() {
    printf("double op double:\n");
    printf("%g + %g = %g\n", 1.0, 2.0, 1.0 + 2.0);
    printf("%g - %g = %g\n", 1.0, 2.0, 1.0 - 2.0);
    printf("%g * %g = %g\n", 1.0, 2.0, 1.0 * 2.0);
    printf("%g / %g = %g\n", 1.0, 2.0, 1.0 / 2.0);

    printf("float op float:\n");
    printf("%g + %g = %g\n", 1.0f, 2.0f, 1.0f + 2.0f);
    printf("%g - %g = %g\n", 1.0f, 2.0f, 1.0f - 2.0f);
    printf("%g * %g = %g\n", 1.0f, 2.0f, 1.0f * 2.0f);
    printf("%g / %g = %g\n", 1.0f, 2.0f, 1.0f / 2.0f);

    printf("double op float:\n");
    printf("%g + %g = %g\n", 1.0, 2.0f, 1.0 + 2.0f);
    printf("%g - %g = %g\n", 1.0, 2.0f, 1.0 - 2.0f);
    printf("%g * %g = %g\n", 1.0, 2.0f, 1.0 * 2.0f);
    printf("%g / %g = %g\n", 1.0, 2.0f, 1.0 / 2.0f);

    printf("double op int:\n");
    printf("%g + %d = %g\n", 1.0, 2, 1.0 + 2);
    printf("%g - %d = %g\n", 1.0, 2, 1.0 - 2);
    printf("%g * %d = %g\n", 1.0, 2, 1.0 * 2);
    printf("%g / %d = %g\n", 1.0, 2, 1.0 / 2);

    printf("int op double:\n");
    printf("%d + %g = %g\n", 1, 2.0, 1 + 2.0);
    printf("%d - %g = %g\n", 1, 2.0, 1 - 2.0);
    printf("%d * %g = %g\n", 1, 2.0, 1 * 2.0);
    printf("%d / %g = %g\n", 1, 2.0, 1 / 2.0);
}

void comparisonTestdd(double a, double b) {
    printf("%g op %g: < %d   <= %d   == %d   >= %d   > %d   != %d\n",
           a, b, a < b, a <= b, a == b, a >= b, a > b, a != b);
}

void comparisonOpsdd() {
    printf("double op double:\n");
    comparisonTestdd(1.0, 2.0);
    comparisonTestdd(1.0, 1.0);
    comparisonTestdd(2.0, 1.0);
}


void comparisonTestdf(double a, float b) {
    printf("%g op %g: < %d   <= %d   == %d   >= %d   > %d   != %d\n",
           a, b, a < b, a <= b, a == b, a >= b, a > b, a != b);
}

void comparisonOpsdf() {
    printf("double op float:\n");
    comparisonTestdf(1.0, 2.0f);
    comparisonTestdf(1.0, 1.0f);
    comparisonTestdf(2.0, 1.0f);
}

void comparisonTestff(float a, float b) {
    printf("%g op %g: < %d   <= %d   == %d   >= %d   > %d   != %d\n",
           a, b, a < b, a <= b, a == b, a >= b, a > b, a != b);
}

void comparisonOpsff() {
    printf("float op float:\n");
    comparisonTestff(1.0f, 2.0f);
    comparisonTestff(1.0f, 1.0f);
    comparisonTestff(2.0f, 1.0f);
}

void comparisonTestid(int a, double b) {
    printf("%d op %g: < %d   <= %d   == %d   >= %d   > %d   != %d\n",
           a, b, a < b, a <= b, a == b, a >= b, a > b, a != b);
}

void comparisonOpsid() {
    printf("int op double:\n");
    comparisonTestid(1, 2.0);
    comparisonTestid(1, 1.0);
    comparisonTestid(2, 1.0);
}
void comparisonTestdi(double a, int b) {
    printf("%g op %d: < %d   <= %d   == %d   >= %d   > %d   != %d\n",
           a, b, a < b, a <= b, a == b, a >= b, a > b, a != b);
}

void comparisonOpsdi() {
    printf("double op int:\n");
    comparisonTestdi(1.0f, 2);
    comparisonTestdi(1.0f, 1);
    comparisonTestdi(2.0f, 1);
}

void comparisonOps() {
    comparisonOpsdd();
    comparisonOpsdf();
    comparisonOpsff();
    comparisonOpsid();
    comparisonOpsdi();
}

int branch(double d) {
    if (d) {
        return 1;
    }
    return 0;
}

void testBranching() {
    printf("branching: %d %d %d\n", branch(-1.0), branch(0.0), branch(1.0));
}

void testpassi(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k, int l) {
    printf("testpassi: %d %d %d %d %d %d %d %d %d %d %d %d\n", a, b, c, d, e, f, g, h, i, j, k, l);
}

void testpassf(float a, float b, float c, float d, float e, float f, float g, float h, float i, float j, float k, float l) {
    printf("testpassf: %g %g %g %g %g %g %g %g %g %g %g %g\n", a, b, c, d, e, f, g, h, i, j, k, l);
}

void testpassd(double a, double b, double c, double d, double e, double f, double g, double h, double i, double j, double k, double l) {
    printf("testpassd: %g %g %g %g %g %g %g %g %g %g %g %g\n", a, b, c, d, e, f, g, h, i, j, k, l);
}

void testpassidf(int i, double d, float f) {
    printf("testpassidf: %d %g %g\n", i, d, f);
}

void testParameterPassing() {
    float x;
    testpassi(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
    testpassf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
    testpassd(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
    testpassi(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f);
    testpassf(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f);
    testpassd(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f);
    testpassi(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0);
    testpassf(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0);
    testpassd(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0);
    testpassidf(1, 2.0, 3.0f);
}

int main() {
    unaryOps();
    binaryOps();
    comparisonOps();
    testBranching();
    testParameterPassing();
    return 0;
}