[mlir][linalg] Fix dim(iter_arg) canonicalization
[llvm-project.git] / libc / fuzzing / math / SingleInputSingleOutputDiff.h
blob8c1e4b0d0290ed5c7f1f99c4f4a60460f07f8ac4
1 //===-- Template to diff single-input-single-output functions ---*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_FUZZING_MATH_SINGLE_INPUT_SINGLE_OUTPUT_DIFF_H
10 #define LLVM_LIBC_FUZZING_MATH_SINGLE_INPUT_SINGLE_OUTPUT_DIFF_H
12 #include "fuzzing/math/Compare.h"
13 #include "src/__support/FPUtil/FPBits.h"
15 #include <math.h>
16 #include <stddef.h>
17 #include <stdint.h>
19 template <typename T> using SingleInputSingleOutputFunc = T (*)(T);
21 template <typename T>
22 void SingleInputSingleOutputDiff(SingleInputSingleOutputFunc<T> func1,
23 SingleInputSingleOutputFunc<T> func2,
24 const uint8_t *data, size_t size) {
25 if (size < sizeof(T))
26 return;
28 T x = *reinterpret_cast<const T *>(data);
30 T result1 = func1(x);
31 T result2 = func2(x);
33 if (!ValuesEqual(result1, result2))
34 __builtin_trap();
37 template <typename T1, typename T2>
38 using SingleInputSingleOutputWithSideEffectFunc = T1 (*)(T1, T2 *);
40 template <typename T1, typename T2>
41 void SingleInputSingleOutputWithSideEffectDiff(
42 SingleInputSingleOutputWithSideEffectFunc<T1, T2> func1,
43 SingleInputSingleOutputWithSideEffectFunc<T1, T2> func2,
44 const uint8_t *data, size_t size) {
45 if (size < sizeof(T1))
46 return;
48 T1 x = *reinterpret_cast<const T1 *>(data);
49 T2 sideEffect1, sideEffect2;
51 T1 result1 = func1(x, &sideEffect1);
52 T1 result2 = func2(x, &sideEffect2);
54 if (!ValuesEqual(result1, result2))
55 __builtin_trap();
57 if (!ValuesEqual(sideEffect1, sideEffect2))
58 __builtin_trap();
61 #endif // LLVM_LIBC_FUZZING_MATH_SINGLE_INPUT_SINGLE_OUTPUT_DIFF_H