-
Notifications
You must be signed in to change notification settings - Fork 12
/
common.h
65 lines (54 loc) · 1.49 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
58
59
60
61
62
63
64
65
/*
* Copyright (c) 2024 The mlkem-native project authors
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef COMMON_H
#define COMMON_H
/*
* C90 does not have the inline compiler directive yet.
* We don't use it in C90 builds.
* However, in that case the compiler warns about some inline functions in
* header files not being used in every compilation unit that includes that
* header. To work around it we silence that warning in that case using
* __attribute__((unused)).
*/
/* Do not use inline for C90 builds*/
#if !defined(inline)
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
#define INLINE inline
#define ALWAYS_INLINE __attribute__((always_inline))
#elif defined(_MSC_VER)
#define INLINE __inline
#define ALWAYS_INLINE __forceinline
#else
#define INLINE __attribute__((unused))
#define ALWAYS_INLINE
#endif
#else
#define INLINE inline
#define ALWAYS_INLINE __attribute__((always_inline))
#endif
/*
* C90 does not have the restrict compiler directive yet.
* We don't use it in C90 builds.
*/
#if !defined(restrict)
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
#define RESTRICT restrict
#else
#define RESTRICT
#endif
#else
#define RESTRICT restrict
#endif
#define DEFAULT_ALIGN 32
#if defined(_WIN32)
#define ALIGN __declspec(align(DEFAULT_ALIGN))
#define asm __asm
#else
#define asm __asm__
#define ALIGN __attribute__((aligned(DEFAULT_ALIGN)))
#endif
#define MLKEM_CONCAT_(left, right) left##right
#define MLKEM_CONCAT(left, right) MLKEM_CONCAT_(left, right)
#endif