|
| 1 | +// ====------ onedpl_test_bfe.cpp------------------------ -*- 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 | +// |
| 8 | +// ===---------------------------------------------------------------------===// |
| 9 | +#include <oneapi/dpl/execution> |
| 10 | +#include "dpct/dpct.hpp" |
| 11 | +#include "dpct/dpl_utils.hpp" |
| 12 | +#include "dpct/dpl_extras/functional.h" |
| 13 | +#include <iostream> |
| 14 | + |
| 15 | +template<typename String, typename _T1, typename _T2> |
| 16 | +int ASSERT_EQUAL(String msg, _T1&& X, _T2&& Y) { |
| 17 | + if(X!=Y) { |
| 18 | + std::cout << "FAIL: " << msg << " - (" << X << "," << Y << ")" << std::endl; |
| 19 | + return 1; |
| 20 | + } |
| 21 | + return 0; |
| 22 | +} |
| 23 | + |
| 24 | +int test_passed(int failing_elems, std::string test_name) { |
| 25 | + if (failing_elems == 0) { |
| 26 | + std::cout << "PASS: " << test_name << std::endl; |
| 27 | + return 0; |
| 28 | + } |
| 29 | + return 1; |
| 30 | +} |
| 31 | + |
| 32 | +int main() { |
| 33 | + |
| 34 | + // used to detect failures |
| 35 | + int failed_tests = 0; |
| 36 | + int num_failing = 0; |
| 37 | + |
| 38 | + { |
| 39 | + std::uint8_t orig = 240; |
| 40 | + std::string test_name = "dpct::bfe test std::uint8_t"; |
| 41 | + //casting to uint32_t so that cout does not confuse with a char |
| 42 | + failed_tests += ASSERT_EQUAL(test_name, (::std::uint32_t)dpct::bfe(orig, 0, 4), 0); |
| 43 | + failed_tests += ASSERT_EQUAL(test_name, (::std::uint32_t)dpct::bfe(orig, 4, 4), 15); |
| 44 | + |
| 45 | + failed_tests += ASSERT_EQUAL(test_name, (::std::uint32_t)dpct::bfe(orig, 1, 6), 56); |
| 46 | + failed_tests += ASSERT_EQUAL(test_name, (::std::uint32_t)dpct::bfe(orig, 5, 3), 7); |
| 47 | + test_passed(failed_tests, test_name); |
| 48 | + } |
| 49 | + |
| 50 | + { |
| 51 | + std::uint16_t orig = 54444; |
| 52 | + std::string test_name = "dpct::bfe test std::uint16_t"; |
| 53 | + failed_tests += ASSERT_EQUAL(test_name, dpct::bfe(orig, 0, 8), 172); |
| 54 | + failed_tests += ASSERT_EQUAL(test_name, dpct::bfe(orig, 8, 8), 212); |
| 55 | + |
| 56 | + failed_tests += ASSERT_EQUAL(test_name, dpct::bfe(orig, 3, 12), 2709); |
| 57 | + failed_tests += ASSERT_EQUAL(test_name, dpct::bfe(orig, 1, 3), 6); |
| 58 | + test_passed(failed_tests, test_name); |
| 59 | + } |
| 60 | + |
| 61 | + { |
| 62 | + std::uint32_t orig = 123023024; |
| 63 | + std::string test_name = "dpct::bfe test std::uint32_t"; |
| 64 | + failed_tests += ASSERT_EQUAL(test_name, dpct::bfe(orig, 0, 8), 176); |
| 65 | + failed_tests += ASSERT_EQUAL(test_name, dpct::bfe(orig, 8, 8), 46); |
| 66 | + failed_tests += ASSERT_EQUAL(test_name, dpct::bfe(orig, 16, 8), 85); |
| 67 | + failed_tests += ASSERT_EQUAL(test_name, dpct::bfe(orig, 24, 8), 7); |
| 68 | + |
| 69 | + failed_tests += ASSERT_EQUAL(test_name, dpct::bfe(orig, 28, 4), 0); |
| 70 | + failed_tests += ASSERT_EQUAL(test_name, dpct::bfe(orig, 13, 10), 681); |
| 71 | + test_passed(failed_tests, test_name); |
| 72 | + } |
| 73 | + |
| 74 | + { |
| 75 | + std::uint64_t orig = 128765854343023024ULL; |
| 76 | + std::string test_name = "dpct::bfe test std::uint64_t"; |
| 77 | + failed_tests += ASSERT_EQUAL(test_name, dpct::bfe(orig, 0, 16), 51632); |
| 78 | + failed_tests += ASSERT_EQUAL(test_name, dpct::bfe(orig, 16, 16), 48976); |
| 79 | + failed_tests += ASSERT_EQUAL(test_name, dpct::bfe(orig, 32, 16), 30684); |
| 80 | + failed_tests += ASSERT_EQUAL(test_name, dpct::bfe(orig, 48, 16), 457); |
| 81 | + |
| 82 | + failed_tests += ASSERT_EQUAL(test_name, dpct::bfe(orig, 55, 4), 3); |
| 83 | + failed_tests += ASSERT_EQUAL(test_name, dpct::bfe(orig, 13, 13), 6790); |
| 84 | + test_passed(failed_tests, test_name); |
| 85 | + } |
| 86 | + |
| 87 | + std::cout << std::endl << failed_tests << " failing test(s) detected." << std::endl; |
| 88 | + if (failed_tests == 0) { |
| 89 | + return 0; |
| 90 | + } |
| 91 | + return 1; |
| 92 | +} |
0 commit comments