cb424d7448
verify-patch-sanity.py validates every active recipe .patch has internally- consistent hunk line counts — catching the 'malformed patch at line N' failure at commit/CI/preflight time instead of hours into a cook. This cycle hit that class three times (qtwaylandscanner, sddm, xwayland), each only discovered when cookbook tried to apply the patch. Running it across the repo found 29 latent malformed patches (validated against GNU patch: e.g. relibc/P3-sysv-ipc reproduces 'malformed patch at line 22'). They were harmless only because they sit in vendored recipes (baked, not re- applied) — but would fail on any version-bump re-derivation. --fix recounts the hunk headers (body untouched) and repaired all 29. Wired into build-preflight.sh (Phase 1.0D) and redbear-ci.yml, with a unit test (test-patch-sanity.sh). Skips archived/legacy trees and unvalidatable formats (empty placeholders, bare-@@ git hunks).
70 lines
2.2 KiB
C++
70 lines
2.2 KiB
C++
//===-- Shared/Utils.h - Target independent OpenMP target RTL -- C++ ------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Routines and classes used to provide useful functionalities for the host and
|
|
// the device.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef OMPTARGET_SHARED_UTILS_H
|
|
#define OMPTARGET_SHARED_UTILS_H
|
|
|
|
#include <stdint.h>
|
|
|
|
namespace utils {
|
|
|
|
/// Return the difference (in bytes) between \p Begin and \p End.
|
|
template <typename Ty = char>
|
|
auto getPtrDiff(const void *End, const void *Begin) {
|
|
return reinterpret_cast<const Ty *>(End) -
|
|
reinterpret_cast<const Ty *>(Begin);
|
|
}
|
|
|
|
/// Return \p Ptr advanced by \p Offset bytes.
|
|
template <typename Ty1, typename Ty2> Ty1 *advancePtr(Ty1 *Ptr, Ty2 Offset) {
|
|
return (Ty1 *)(const_cast<char *>((const char *)(Ptr)) + Offset);
|
|
}
|
|
|
|
/// Return \p V aligned "upwards" according to \p Align.
|
|
template <typename Ty1, typename Ty2> inline Ty1 alignPtr(Ty1 V, Ty2 Align) {
|
|
return reinterpret_cast<Ty1>(((uintptr_t(V) + Align - 1) / Align) * Align);
|
|
}
|
|
|
|
/// Round up \p V to a \p Boundary.
|
|
template <typename Ty> inline Ty roundUp(Ty V, Ty Boundary) {
|
|
return alignPtr(V, Boundary);
|
|
}
|
|
|
|
/// Return the first bit set in \p V.
|
|
inline uint32_t ffs(uint32_t V) {
|
|
static_assert(sizeof(int) == sizeof(uint32_t), "type size mismatch");
|
|
return __builtin_ffs(V);
|
|
}
|
|
|
|
/// Return the first bit set in \p V.
|
|
inline uint32_t ffs(uint64_t V) {
|
|
static_assert(sizeof(long) == sizeof(uint64_t), "type size mismatch");
|
|
return __builtin_ffsl(V);
|
|
}
|
|
|
|
/// Return the number of bits set in \p V.
|
|
inline uint32_t popc(uint32_t V) {
|
|
static_assert(sizeof(int) == sizeof(uint32_t), "type size mismatch");
|
|
return __builtin_popcount(V);
|
|
}
|
|
|
|
/// Return the number of bits set in \p V.
|
|
inline uint32_t popc(uint64_t V) {
|
|
static_assert(sizeof(long) == sizeof(uint64_t), "type size mismatch");
|
|
return __builtin_popcountl(V);
|
|
}
|
|
|
|
} // namespace utils
|
|
|
|
#endif // OMPTARGET_SHARED_UTILS_H
|