forked from kimlaine/bootcamp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclang.h
64 lines (51 loc) · 2.51 KB
/
clang.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
58
59
60
61
62
63
64
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#pragma once
#if SEAL_COMPILER == SEAL_COMPILER_CLANG
// We require clang >= 5
#if (__clang_major__ < 5) || not defined(__cplusplus)
#error "SEAL requires __clang_major__ >= 5"
#endif
// Read in config.h
#include "seal/util/config.h"
// Are intrinsics enabled?
#ifdef SEAL_USE_INTRIN
#include <x86intrin.h>
#ifdef SEAL_USE___BUILTIN_CLZLL
#define SEAL_MSB_INDEX_UINT64(result, value) { \
*result = 63UL - static_cast<unsigned long>(__builtin_clzll(value)); \
}
#endif
#ifdef SEAL_USE___INT128
#define SEAL_MULTIPLY_UINT64_HW64(operand1, operand2, hw64) { \
*hw64 = static_cast<unsigned long long>( \
((static_cast<unsigned __int128>(operand1) \
* static_cast<unsigned __int128>(operand2)) >> 64)); \
}
#define SEAL_MULTIPLY_UINT64(operand1, operand2, result128) { \
unsigned __int128 product = static_cast<unsigned __int128>(operand1) * operand2;\
result128[0] = static_cast<unsigned long long>(product); \
result128[1] = static_cast<unsigned long long>(product >> 64); \
}
#define SEAL_DIVIDE_UINT128_UINT64(numerator, denominator, result) { \
unsigned __int128 n, q; \
n = (static_cast<unsigned __int128>(numerator[1]) << 64) | \
(static_cast<unsigned __int128>(numerator[0])); \
q = n / denominator; \
n -= q * denominator; \
numerator[0] = static_cast<std::uint64_t>(n); \
numerator[1] = static_cast<std::uint64_t>(n >> 64); \
quotient[0] = static_cast<std::uint64_t>(q); \
quotient[1] = static_cast<std::uint64_t>(q >> 64); \
}
#endif
#ifdef SEAL_USE__ADDCARRY_U64
#define SEAL_ADD_CARRY_UINT64(operand1, operand2, carry, result) _addcarry_u64( \
carry, operand1, operand2, result)
#endif
#ifdef SEAL_USE__SUBBORROW_U64
#define SEAL_SUB_BORROW_UINT64(operand1, operand2, borrow, result) _subborrow_u64( \
borrow, operand1, operand2, result)
#endif
#endif //SEAL_USE_INTRIN
#endif