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

PredatorCZ / PreCore / 461

pending completion
461

push

github-actions-ci

PredatorCZ
update readme

3204 of 6096 relevant lines covered (52.56%)

354.05 hits per line

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

66.67
/include/spike/util/supercore.hpp
1
/*  Supercore, mostly detectors/macros
2

3
    Copyright 2018-2023 Lukas Cone
4

5
    Licensed under the Apache License, Version 2.0 (the "License");
6
    you may not use this file except in compliance with the License.
7
    You may obtain a copy of the License at
8

9
        http://www.apache.org/licenses/LICENSE-2.0
10

11
    Unless required by applicable law or agreed to in writing, software
12
    distributed under the License is distributed on an "AS IS" BASIS,
13
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
    See the License for the specific language governing permissions and
15
    limitations under the License.
16
*/
17

18
#pragma once
19

20
#include "detail/sc_architecture.hpp"
21
#include <iterator>
22

23
#if defined(__cplusplus) || defined(c_plusplus)
24

25
static constexpr uint8 atohLUT[] = {
26
    "................................................"
27
    "\x0\x1\x2\x3\x4\x5\x6\x7\x8\x9.......\xa\xb\xc\xd\xe\xf..................."
28
    ".......\xa\xb\xc\xd\xe\xf"};
29

30
static_assert(atohLUT[uint8('0')] == 0);
31
static_assert(atohLUT[uint8('9')] == 9);
32
static_assert(atohLUT[uint8('a')] == 10);
33
static_assert(atohLUT[uint8('f')] == 15);
34
static_assert(atohLUT[uint8('A')] == 10);
35
static_assert(atohLUT[uint8('F')] == 15);
36

37
template <size_t n> constexpr uint32 CompileFourCC(const char (&input)[n]) {
38
  uint32 retVal = 0;
39
  for (size_t i = 0; i < sizeof(retVal); i++) {
40
    const uint32 tmp = input[i];
41
    retVal |= tmp << (8 * i);
42
  }
43

44
  return retVal;
45
}
46

47
static_assert(CompileFourCC("ABCD") == 0x44434241);
48

49
constexpr size_t GetPadding(size_t value, size_t alignment) {
50
  const size_t mask = alignment - 1;
51
  const size_t result = value & mask;
52

53
  return !result ? 0 : (alignment - result);
54
}
55

56
static_assert(GetPadding(7, 8) == 1);
57
static_assert(GetPadding(7, 16) == 9);
58

59
constexpr float GetFraction(size_t numBits) {
60
  return 1.f / static_cast<float>((1ULL << numBits) - 1);
61
}
62

63
template <typename type> constexpr bool IsPow2(type input) {
64
  return !(input & (input - 1));
65
}
66

67
namespace es {
68
static inline void Print(const char *data) { printf("%s", data); }
370✔
69
static inline void Print(const char8_t *data) {
70
  printf("%s", reinterpret_cast<const char *>(data));
71
}
72

73
template <class cnt, class iterType>
74
bool IsEnd(const cnt &container, const iterType &iter) {
75
  using std::end;
76
  return end(container) == iter;
77
}
78

79
template <class sview>
80
sview SkipStartWhitespace(sview input, bool inclNewLine = false) noexcept {
81
  while (!input.empty() &&
1,530✔
82
         (input[0] == ' ' || input[0] == '\t' ||
1,514✔
83
          (inclNewLine && (input[0] == '\n' || input[0] == '\r'))))
×
84
    input.remove_prefix(1);
85

86
  return input;
87
}
88

89
template <class sview>
90
sview SkipEndWhitespace(sview input, bool inclNewLine = false) noexcept {
91
  while (!input.empty() &&
207✔
92
         (input.back() == ' ' || input.back() == '\t' ||
198✔
93
          (inclNewLine && (input.back() == '\n' || input.back() == '\r'))))
×
94
    input.remove_suffix(1);
95

96
  return input;
97
}
98

99
template <class sview>
100
sview TrimWhitespace(sview input, bool inclNewLine = false) noexcept {
88✔
101
  input = SkipStartWhitespace(input, inclNewLine);
102
  return SkipEndWhitespace(input, inclNewLine);
88✔
103
}
104

105
template <class C> void Dispose(C &item) { auto removed = std::move(item); }
2✔
106

1✔
107
template <size_t size> struct TypeFromSize { typedef std::false_type type; };
1✔
108
template <> struct TypeFromSize<1> { typedef uint8 type; };
×
109
template <> struct TypeFromSize<2> { typedef uint16 type; };
×
110
template <> struct TypeFromSize<4> { typedef uint32 type; };
×
111
template <> struct TypeFromSize<8> { typedef uint64 type; };
112

113
template <class, template <class...> class Op, class... Args>
114
struct detector_ : std::false_type {};
115

116
template <template <class...> class Op, class... Args>
117
struct detector_<std::void_t<Op<Args...>>, Op, Args...> : std::true_type {};
118

119
template <template <class...> class Op, class... Args>
120
using is_detected = detector_<void, Op, Args...>;
121

122
template <template <class...> class Op, class... Args>
123
constexpr bool is_detected_v = is_detected<Op, Args...>::value;
124

125
} // namespace es
126

127
#endif
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

© 2025 Coveralls, Inc