File: GB_AxB_compare_factory.c

package info (click to toggle)
suitesparse 1%3A7.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 254,920 kB
  • sloc: ansic: 1,134,743; cpp: 46,133; makefile: 4,875; fortran: 2,087; java: 1,826; sh: 996; ruby: 725; python: 495; asm: 371; sed: 166; awk: 44
file content (242 lines) | stat: -rw-r--r-- 6,917 bytes parent folder | download | duplicates (2)
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
//------------------------------------------------------------------------------
// GB_AxB_compare_factory.c: switch factory for C=A*B with comparator ops
//------------------------------------------------------------------------------

// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2025, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

//------------------------------------------------------------------------------

// A template file #include'd in GB_AxB_factory.c, which calls 50 or 55
// semirings, with 5 monoids (lor, land, eq, lxor, any) and 10 or 11 types (the
// 10 real, non-boolean times, plus boolean).

// The multiply operator is a comparator: EQ, NE, GT, LT, GE, LE.
// z=f(x,y): x and x are either boolean or non-boolean.  z is boolean.

// Since z is boolean, the only monoids available are OR, AND, XOR, EQ, and
// ANY.  All the other four (max==plus==or, min==times==and) are redundant.
// Those opcodes have been renamed, and handled by the OR and AND workers
// defined here.

// There is one special case to consider.  For boolean x, y, and z, the
// function z=NE(x,y) is the same as z=XOR(x,y).  If z is boolean, the multiply
// operator NE has already been renamed XOR by GB_AxB_semiring_builtin, and
// thus NE will never use the boolean case, below.  Thus it is removed with the
// #ifndef GB_NO_BOOLEAN, resulting in 50 semirings for the NE muliply
// operator.

#if defined (GxB_NO_BOOL)
#define GB_CASE_BOOL(op)
#else
#define GB_CASE_BOOL(op) \
    case GB_BOOL_code:   GB_AxB_WORKER (op, GB_MNAME, _bool  )
#endif

#if defined (GxB_NO_INT8)
#define GB_CASE_INT8(op)
#else
#define GB_CASE_INT8(op) \
    case GB_INT8_code:   GB_AxB_WORKER (op, GB_MNAME, _int8  )
#endif

#if defined (GxB_NO_INT16)
#define GB_CASE_INT16(op)
#else
#define GB_CASE_INT16(op) \
    case GB_INT16_code:  GB_AxB_WORKER (op, GB_MNAME, _int16 )
#endif

#if defined (GxB_NO_INT32)
#define GB_CASE_INT32(op)
#else
#define GB_CASE_INT32(op) \
    case GB_INT32_code:  GB_AxB_WORKER (op, GB_MNAME, _int32 )
#endif

#if defined (GxB_NO_INT64)
#define GB_CASE_INT64(op)
#else
#define GB_CASE_INT64(op) \
    case GB_INT64_code:  GB_AxB_WORKER (op, GB_MNAME, _int64 )
#endif

#if defined (GxB_NO_UINT8)
#define GB_CASE_UINT8(op)
#else
#define GB_CASE_UINT8(op) \
    case GB_UINT8_code:  GB_AxB_WORKER (op, GB_MNAME, _uint8 )
#endif

#if defined (GxB_NO_UINT16)
#define GB_CASE_UINT16(op)
#else
#define GB_CASE_UINT16(op) \
    case GB_UINT16_code: GB_AxB_WORKER (op, GB_MNAME, _uint16)
#endif

#if defined (GxB_NO_UINT32)
#define GB_CASE_UINT32(op)
#else
#define GB_CASE_UINT32(op) \
    case GB_UINT32_code: GB_AxB_WORKER (op, GB_MNAME, _uint32)
#endif

#if defined (GxB_NO_UINT64)
#define GB_CASE_UINT64(op)
#else
#define GB_CASE_UINT64(op) \
    case GB_UINT64_code: GB_AxB_WORKER (op, GB_MNAME, _uint64)
#endif

#if defined (GxB_NO_FP32)
#define GB_CASE_FP32(op)
#else
#define GB_CASE_FP32(op) \
    case GB_FP32_code:   GB_AxB_WORKER (op, GB_MNAME, _fp32  )
#endif

#if defined (GxB_NO_FP64)
#define GB_CASE_FP64(op)
#else
#define GB_CASE_FP64(op) \
    case GB_FP64_code:   GB_AxB_WORKER (op, GB_MNAME, _fp64  )
#endif

ASSERT (zcode == GB_BOOL_code) ;
{

    // C = A*B where C is boolean, but A and B are non-boolean.
    // The result of the compare(A,B) operation is boolean.
    // There are 4 monoids available: OR, AND, XOR, EQ

    switch (add_binop_code)
    {

        case GB_LOR_binop_code     : 

            switch (xcode)
            {
                #ifndef GB_NO_BOOLEAN
                GB_CASE_BOOL   (_lor)
                #endif
                GB_CASE_INT8   (_lor)
                GB_CASE_INT16  (_lor)
                GB_CASE_INT32  (_lor)
                GB_CASE_INT64  (_lor)
                GB_CASE_UINT8  (_lor)
                GB_CASE_UINT16 (_lor)
                GB_CASE_UINT32 (_lor)
                GB_CASE_UINT64 (_lor)
                GB_CASE_FP32   (_lor)
                GB_CASE_FP64   (_lor)
                default: ;
            }
            break ;

        case GB_LAND_binop_code    : 

            switch (xcode)
            {
                // 10 real, non-boolean types, plus boolean
                #ifndef GB_NO_BOOLEAN
                GB_CASE_BOOL   (_land)
                #endif
                GB_CASE_INT8   (_land)
                GB_CASE_INT16  (_land)
                GB_CASE_INT32  (_land)
                GB_CASE_INT64  (_land)
                GB_CASE_UINT8  (_land)
                GB_CASE_UINT16 (_land)
                GB_CASE_UINT32 (_land)
                GB_CASE_UINT64 (_land)
                GB_CASE_FP32   (_land)
                GB_CASE_FP64   (_land)
                default: ;
            }
            break ;

        case GB_LXOR_binop_code    : 

            switch (xcode)
            {
                #ifndef GB_NO_BOOLEAN
                GB_CASE_BOOL   (_lxor)
                #endif
                GB_CASE_INT8   (_lxor)
                GB_CASE_INT16  (_lxor)
                GB_CASE_INT32  (_lxor)
                GB_CASE_INT64  (_lxor)
                GB_CASE_UINT8  (_lxor)
                GB_CASE_UINT16 (_lxor)
                GB_CASE_UINT32 (_lxor)
                GB_CASE_UINT64 (_lxor)
                GB_CASE_FP32   (_lxor)
                GB_CASE_FP64   (_lxor)
                default: ;
            }
            break ;

        case GB_EQ_binop_code    : 

            switch (xcode)
            {
                #ifndef GB_NO_BOOLEAN
                GB_CASE_BOOL   (_eq)
                #endif
                GB_CASE_INT8   (_eq)
                GB_CASE_INT16  (_eq)
                GB_CASE_INT32  (_eq)
                GB_CASE_INT64  (_eq)
                GB_CASE_UINT8  (_eq)
                GB_CASE_UINT16 (_eq)
                GB_CASE_UINT32 (_eq)
                GB_CASE_UINT64 (_eq)
                GB_CASE_FP32   (_eq)
                GB_CASE_FP64   (_eq)
                default: ;
            }
            break ;

        #ifndef GB_NO_ANY_MONOID
        case GB_ANY_binop_code    : 

            switch (xcode)
            {
                #ifndef GB_NO_BOOLEAN
                GB_CASE_BOOL   (_any)
                #endif
                GB_CASE_INT8   (_any)
                GB_CASE_INT16  (_any)
                GB_CASE_INT32  (_any)
                GB_CASE_INT64  (_any)
                GB_CASE_UINT8  (_any)
                GB_CASE_UINT16 (_any)
                GB_CASE_UINT32 (_any)
                GB_CASE_UINT64 (_any)
                GB_CASE_FP32   (_any)
                GB_CASE_FP64   (_any)
                default: ;
            }
            break ;
        #endif

        default: ;
    }
}

#undef GB_NO_BOOLEAN
#undef GB_MNAME

#undef GB_CASE_BOOL
#undef GB_CASE_INT8
#undef GB_CASE_INT16
#undef GB_CASE_INT32
#undef GB_CASE_INT64
#undef GB_CASE_UINT8
#undef GB_CASE_UINT16
#undef GB_CASE_UINT32
#undef GB_CASE_UINT64
#undef GB_CASE_FP32
#undef GB_CASE_FP64