• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

daisytuner / sdfglib / 20623854511

31 Dec 2025 05:23PM UTC coverage: 39.635% (-0.08%) from 39.712%
20623854511

Pull #421

github

web-flow
Merge d9a9f51a5 into 3b72c335e
Pull Request #421: Extend tensor library nodes with primitive type support and refactor CMathNode to use enums

14997 of 49248 branches covered (30.45%)

Branch coverage included in aggregate %.

247 of 620 new or added lines in 52 files covered. (39.84%)

37 existing lines in 4 files now uncovered.

12875 of 21074 relevant lines covered (61.09%)

89.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

45.35
/include/sdfg/data_flow/library_nodes/math/cmath/cmath_node.h
1
#pragma once
2

3
#include "sdfg/data_flow/library_nodes/math/math_node.h"
4
#include "sdfg/types/type.h"
5

6
#include "sdfg/codegen/dispatchers/block_dispatcher.h"
7
#include "sdfg/serializer/json_serializer.h"
8
#include "sdfg/symbolic/symbolic.h"
9

10
namespace sdfg {
11
namespace math {
12
namespace cmath {
13

14
inline data_flow::LibraryNodeCode LibraryNodeType_CMath("CMath");
15
inline data_flow::LibraryNodeCode LibraryNodeType_CMath_Deprecated("Intrinsic");
16

17
/**
18
 * @enum CMathFunction
19
 * @brief Enumeration of C math library functions
20
 */
21
enum class CMathFunction {
22
    // Trigonometric functions
23
    sin,
24
    cos,
25
    tan,
26
    asin,
27
    acos,
28
    atan,
29
    atan2,
30

31
    // Hyperbolic functions
32
    sinh,
33
    cosh,
34
    tanh,
35
    asinh,
36
    acosh,
37
    atanh,
38

39
    // Exponential and logarithmic functions
40
    exp,
41
    exp2,
42
    exp10,
43
    expm1,
44
    log,
45
    log10,
46
    log2,
47
    log1p,
48

49
    // Power functions
50
    pow,
51
    sqrt,
52
    cbrt,
53
    hypot,
54

55
    // Error and gamma functions
56
    erf,
57
    erfc,
58
    tgamma,
59
    lgamma,
60

61
    // Rounding and remainder functions
62
    fabs,
63
    ceil,
64
    floor,
65
    trunc,
66
    round,
67
    lround,
68
    llround,
69
    roundeven,
70
    nearbyint,
71
    rint,
72
    lrint,
73
    llrint,
74
    fmod,
75
    remainder,
76

77
    // Floating-point manipulation functions
78
    frexp,
79
    ldexp,
80
    modf,
81
    scalbn,
82
    scalbln,
83
    ilogb,
84
    logb,
85
    nextafter,
86
    nexttoward,
87
    copysign,
88

89
    // Minimum, maximum, difference functions
90
    fmax,
91
    fmin,
92
    fdim,
93

94
    // Other functions
95
    fma
96
};
97

98
/**
99
 * @brief Get arity of CMathFunction enum
100
 * @param func The CMathFunction enum value
101
 * @return The arity of the enum as a size_t
102
 */
103
constexpr size_t cmath_function_to_arity(CMathFunction func) {
372✔
104
    switch (func) {
372!
105
        case CMathFunction::sin:
106
            return 1;
8✔
107
        case CMathFunction::cos:
108
            return 1;
4✔
109
        case CMathFunction::tan:
110
            return 1;
4✔
111
        case CMathFunction::asin:
112
            return 1;
4✔
113
        case CMathFunction::acos:
114
            return 1;
12✔
115
        case CMathFunction::atan:
116
            return 1;
4✔
117
        case CMathFunction::atan2:
118
            return 2;
6✔
119
        case CMathFunction::sinh:
120
            return 1;
4✔
121
        case CMathFunction::cosh:
122
            return 1;
4✔
123
        case CMathFunction::tanh:
124
            return 1;
12✔
125
        case CMathFunction::asinh:
126
            return 1;
4✔
127
        case CMathFunction::acosh:
128
            return 1;
4✔
129
        case CMathFunction::atanh:
130
            return 1;
4✔
131
        case CMathFunction::exp:
132
            return 1;
30✔
133
        case CMathFunction::exp2:
134
            return 1;
4✔
135
        case CMathFunction::exp10:
136
            return 1;
4✔
137
        case CMathFunction::expm1:
138
            return 1;
4✔
139
        case CMathFunction::log:
140
            return 1;
4✔
141
        case CMathFunction::log10:
142
            return 1;
4✔
143
        case CMathFunction::log2:
144
            return 1;
4✔
145
        case CMathFunction::log1p:
146
            return 1;
4✔
147
        case CMathFunction::pow:
148
            return 2;
18✔
149
        case CMathFunction::sqrt:
150
            return 1;
12✔
151
        case CMathFunction::cbrt:
152
            return 1;
4✔
153
        case CMathFunction::hypot:
154
            return 2;
6✔
155
        case CMathFunction::erf:
156
            return 1;
12✔
157
        case CMathFunction::erfc:
158
            return 1;
4✔
159
        case CMathFunction::tgamma:
160
            return 1;
4✔
161
        case CMathFunction::lgamma:
162
            return 1;
4✔
163
        case CMathFunction::fabs:
164
            return 1;
12✔
165
        case CMathFunction::ceil:
166
            return 1;
4✔
167
        case CMathFunction::floor:
168
            return 1;
4✔
169
        case CMathFunction::trunc:
170
            return 1;
4✔
171
        case CMathFunction::round:
172
            return 1;
4✔
173
        case CMathFunction::lround:
NEW
174
            return 1;
×
175
        case CMathFunction::llround:
NEW
176
            return 1;
×
177
        case CMathFunction::roundeven:
NEW
178
            return 1;
×
179
        case CMathFunction::nearbyint:
180
            return 1;
4✔
181
        case CMathFunction::rint:
182
            return 1;
4✔
183
        case CMathFunction::lrint:
NEW
184
            return 1;
×
185
        case CMathFunction::llrint:
NEW
186
            return 1;
×
187
        case CMathFunction::fmod:
188
            return 2;
6✔
189
        case CMathFunction::remainder:
190
            return 2;
6✔
191
        case CMathFunction::frexp:
192
            return 2;
6✔
193
        case CMathFunction::ldexp:
194
            return 2;
6✔
195
        case CMathFunction::modf:
196
            return 1;
4✔
197
        case CMathFunction::scalbn:
198
            return 1;
4✔
199
        case CMathFunction::scalbln:
200
            return 1;
4✔
201
        case CMathFunction::ilogb:
202
            return 1;
4✔
203
        case CMathFunction::logb:
204
            return 1;
4✔
205
        case CMathFunction::nextafter:
206
            return 2;
6✔
207
        case CMathFunction::nexttoward:
208
            return 2;
6✔
209
        case CMathFunction::copysign:
210
            return 2;
6✔
211
        case CMathFunction::fmax:
212
            return 2;
54✔
213
        case CMathFunction::fmin:
214
            return 2;
18✔
215
        case CMathFunction::fdim:
216
            return 2;
6✔
217
        case CMathFunction::fma:
NEW
218
            return 3;
×
NEW
219
    }
×
220
}
372✔
221

222
/**
223
 * @brief Convert CMathFunction enum to function name stem (without type suffix)
224
 * @param func The CMathFunction enum value
225
 * @return The function name stem as a string
226
 */
227
constexpr const char* cmath_function_to_stem(CMathFunction func) {
3✔
228
    switch (func) {
3!
229
        case CMathFunction::sin:
NEW
230
            return "sin";
×
231
        case CMathFunction::cos:
NEW
232
            return "cos";
×
233
        case CMathFunction::tan:
NEW
234
            return "tan";
×
235
        case CMathFunction::asin:
NEW
236
            return "asin";
×
237
        case CMathFunction::acos:
NEW
238
            return "acos";
×
239
        case CMathFunction::atan:
NEW
240
            return "atan";
×
241
        case CMathFunction::atan2:
NEW
242
            return "atan2";
×
243
        case CMathFunction::sinh:
NEW
244
            return "sinh";
×
245
        case CMathFunction::cosh:
NEW
246
            return "cosh";
×
247
        case CMathFunction::tanh:
NEW
248
            return "tanh";
×
249
        case CMathFunction::asinh:
NEW
250
            return "asinh";
×
251
        case CMathFunction::acosh:
NEW
252
            return "acosh";
×
253
        case CMathFunction::atanh:
NEW
254
            return "atanh";
×
255
        case CMathFunction::exp:
256
            return "exp";
1✔
257
        case CMathFunction::exp2:
NEW
258
            return "exp2";
×
259
        case CMathFunction::exp10:
NEW
260
            return "exp10";
×
261
        case CMathFunction::expm1:
NEW
262
            return "expm1";
×
263
        case CMathFunction::log:
NEW
264
            return "log";
×
265
        case CMathFunction::log10:
NEW
266
            return "log10";
×
267
        case CMathFunction::log2:
NEW
268
            return "log2";
×
269
        case CMathFunction::log1p:
NEW
270
            return "log1p";
×
271
        case CMathFunction::pow:
NEW
272
            return "pow";
×
273
        case CMathFunction::sqrt:
NEW
274
            return "sqrt";
×
275
        case CMathFunction::cbrt:
NEW
276
            return "cbrt";
×
277
        case CMathFunction::hypot:
NEW
278
            return "hypot";
×
279
        case CMathFunction::erf:
NEW
280
            return "erf";
×
281
        case CMathFunction::erfc:
NEW
282
            return "erfc";
×
283
        case CMathFunction::tgamma:
NEW
284
            return "tgamma";
×
285
        case CMathFunction::lgamma:
NEW
286
            return "lgamma";
×
287
        case CMathFunction::fabs:
NEW
288
            return "fabs";
×
289
        case CMathFunction::ceil:
NEW
290
            return "ceil";
×
291
        case CMathFunction::floor:
NEW
292
            return "floor";
×
293
        case CMathFunction::trunc:
NEW
294
            return "trunc";
×
295
        case CMathFunction::round:
NEW
296
            return "round";
×
297
        case CMathFunction::lround:
NEW
298
            return "lround";
×
299
        case CMathFunction::llround:
NEW
300
            return "llround";
×
301
        case CMathFunction::roundeven:
NEW
302
            return "roundeven";
×
303
        case CMathFunction::nearbyint:
NEW
304
            return "nearbyint";
×
305
        case CMathFunction::rint:
NEW
306
            return "rint";
×
307
        case CMathFunction::lrint:
NEW
308
            return "lrint";
×
309
        case CMathFunction::llrint:
NEW
310
            return "llrint";
×
311
        case CMathFunction::fmod:
NEW
312
            return "fmod";
×
313
        case CMathFunction::remainder:
NEW
314
            return "remainder";
×
315
        case CMathFunction::frexp:
NEW
316
            return "frexp";
×
317
        case CMathFunction::ldexp:
NEW
318
            return "ldexp";
×
319
        case CMathFunction::modf:
NEW
320
            return "modf";
×
321
        case CMathFunction::scalbn:
NEW
322
            return "scalbn";
×
323
        case CMathFunction::scalbln:
NEW
324
            return "scalbln";
×
325
        case CMathFunction::ilogb:
NEW
326
            return "ilogb";
×
327
        case CMathFunction::logb:
NEW
328
            return "logb";
×
329
        case CMathFunction::nextafter:
NEW
330
            return "nextafter";
×
331
        case CMathFunction::nexttoward:
NEW
332
            return "nexttoward";
×
333
        case CMathFunction::copysign:
NEW
334
            return "copysign";
×
335
        case CMathFunction::fmax:
336
            return "fmax";
2✔
337
        case CMathFunction::fmin:
NEW
338
            return "fmin";
×
339
        case CMathFunction::fdim:
NEW
340
            return "fdim";
×
341
        case CMathFunction::fma:
NEW
342
            return "fma";
×
NEW
343
    }
×
344
}
3✔
345

346
CMathFunction string_to_cmath_function(const std::string& name);
347

348
/**
349
 * @brief Get the correct C math intrinsic name for a given function and primitive type
350
 *
351
 * Returns the appropriate intrinsic function name based on the primitive type:
352
 * - Float: adds 'f' suffix (e.g., "fmax" -> "fmaxf")
353
 * - Double: uses base name (e.g., "fmax" -> "fmax")
354
 * - Long Double/X86_FP80: adds 'l' suffix (e.g., "fmax" -> "fmaxl")
355
 *
356
 * @param func The CMathFunction enum value
357
 * @param prim_type The primitive type to generate the intrinsic for
358
 * @return The correct intrinsic function name
359
 */
360
inline std::string get_cmath_intrinsic_name(CMathFunction func, types::PrimitiveType prim_type) {
3✔
361
    std::string base_name = cmath_function_to_stem(func);
3!
362

363
    switch (prim_type) {
3!
364
        case types::PrimitiveType::Float:
365
            return base_name + "f";
2!
366
        case types::PrimitiveType::Double:
367
            return base_name;
1✔
368
        case types::PrimitiveType::X86_FP80:
369
        case types::PrimitiveType::FP128:
370
        case types::PrimitiveType::PPC_FP128:
NEW
371
            return base_name + "l";
×
372
        case types::PrimitiveType::Half:
373
        case types::PrimitiveType::BFloat:
374
            // Half and BFloat are typically promoted to float for C math operations
375
            // as there are no standard Half/BFloat intrinsics in C math library
NEW
376
            return base_name + "f";
×
377
        default:
NEW
378
            throw InvalidSDFGException("Unsupported primitive type for C math intrinsic name generation.");
×
379
    }
380
}
3✔
381

382
class CMathNode : public math::MathNode {
383
private:
384
    CMathFunction function_;
385
    types::PrimitiveType primitive_type_;
386

387
public:
388
    CMathNode(
389
        size_t element_id,
390
        const DebugInfo& debug_info,
391
        const graph::Vertex vertex,
392
        data_flow::DataFlowGraph& parent,
393
        CMathFunction function,
394
        types::PrimitiveType primitive_type
395
    );
396

397
    CMathFunction function() const;
398
    types::PrimitiveType primitive_type() const;
399
    std::string name() const;
400

401
    void validate(const Function& function) const override;
402

403
    symbolic::SymbolSet symbols() const override;
404

405
    void replace(const symbolic::Expression old_expression, const symbolic::Expression new_expression) override;
406

407
    bool expand(builder::StructuredSDFGBuilder& builder, analysis::AnalysisManager& analysis_manager) override {
×
408
        return false;
×
409
    };
410

411
    std::unique_ptr<data_flow::DataFlowNode>
412
    clone(size_t element_id, const graph::Vertex vertex, data_flow::DataFlowGraph& parent) const override;
413

414
    virtual symbolic::Expression flop() const override;
415
};
416

417
class CMathNodeSerializer : public serializer::LibraryNodeSerializer {
418
public:
419
    nlohmann::json serialize(const data_flow::LibraryNode& library_node) override;
420

421
    data_flow::LibraryNode& deserialize(
422
        const nlohmann::json& j, builder::StructuredSDFGBuilder& builder, structured_control_flow::Block& parent
423
    ) override;
424
};
425

426
class CMathNodeDispatcher : public codegen::LibraryNodeDispatcher {
427
public:
428
    CMathNodeDispatcher(
429
        codegen::LanguageExtension& language_extension,
430
        const Function& function,
431
        const data_flow::DataFlowGraph& data_flow_graph,
432
        const CMathNode& node
433
    );
434

435
    void dispatch_code(
436
        codegen::PrettyPrinter& stream,
437
        codegen::PrettyPrinter& globals_stream,
438
        codegen::CodeSnippetFactory& library_snippet_factory
439
    ) override;
440
};
441

442
} // namespace cmath
443
} // namespace math
444
} // namespace sdfg
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc