forked from preda/gpuowl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.h
57 lines (40 loc) · 1.22 KB
/
common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright Mihai Preda.
#pragma once
#include "log.h"
#include <cstdint>
#include <string>
#include <vector>
using u8 = uint8_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f128 = __float128;
static_assert(sizeof(u8) == 1, "size u8");
static_assert(sizeof(u32) == 4, "size u32");
static_assert(sizeof(u64) == 8, "size u64");
using namespace std;
namespace std::filesystem{};
namespace fs = std::filesystem;
string hex(u64 x);
string rstripNewline(string s);
using Words = vector<u32>;
inline u64 res64(const Words& words) { return words.empty() ? 0 : ((u64(words[1]) << 32) | words[0]); }
inline Words makeWords(u32 E, u32 value) {
Words ret((E-1)/32 +1);
ret[0] = value;
return ret;
}
inline u32 roundUp(u32 x, u32 multiple) { return ((x - 1) / multiple + 1) * multiple; }
u32 crc32(const void* data, size_t size);
inline u32 crc32(const std::vector<u32>& words) { return crc32(words.data(), sizeof(words[0]) * words.size()); }
std::string formatBound(u32 b);
template<typename To, typename From> To as(From from) {
union Pun {
Pun(const From& f) : from{f} {}
From from;
To to;
static_assert(sizeof(To) == sizeof(From));
};
return Pun{from}.to;
}