Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GHI #35 Add std implementation #36

Merged
merged 54 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
b669bf9
GHI #35 Add config check for alignof function
doodspav Oct 29, 2024
ba7901d
GHI #35 Implement stdalign.h/c
doodspav Oct 29, 2024
e09f478
GHI #35 Add config checks for restrict keyword
doodspav Oct 29, 2024
30592ab
GHI #35 Add restrict.h macro
doodspav Oct 29, 2024
86b17da
GHI #35 Add string.h/c in stdlib (just memcpy for now)
doodspav Oct 29, 2024
473947c
GHI #35 Minor qualifier/comment fixes
doodspav Oct 29, 2024
397d113
GHI #35 Set up the base for wrapped
doodspav Oct 29, 2024
b69b308
GHI #35 Minor comment fix
doodspav Oct 29, 2024
76fe688
GHI #35 Check to make sure commit signing works
doodspav Oct 29, 2024
8edabbf
GHI #35 It works. Undo last change
doodspav Oct 29, 2024
7cefb21
GHI #35 Add empty std impl
doodspav Oct 29, 2024
7c9ec6b
GHI #35 Rename opts to options
doodspav Oct 29, 2024
d8d85ae
GHI #35 Implement fallback for std
doodspav Oct 29, 2024
3d6970b
GHI #35 Add static_assert
doodspav Oct 29, 2024
ab7035f
GHI #35 Add wrapped macros for direct load and store
doodspav Oct 30, 2024
485ead4
GHI #35 Add wrapped macro for direct explicit
doodspav Oct 30, 2024
a9ffbfc
GHI #35 Add wrapped macro for direct cmpxchg
doodspav Oct 30, 2024
8246dce
GHI #35 Add wrapped macro for direct bit test/modify
doodspav Oct 30, 2024
9d7e447
GHI #35 Add wrapped macro for direct fetch
doodspav Oct 30, 2024
206386a
GHI #35 Add wrapped macro for direct fetch noarg
doodspav Oct 30, 2024
6adbcb0
GHI #35 Add wrapped macro for direct void
doodspav Oct 30, 2024
7dbc939
GHI #35 Add wrapped macro for direct void noarg
doodspav Oct 30, 2024
7190620
GHI #35 Add config check for <stdatomic.h>
doodspav Oct 30, 2024
feffb5e
GHI #35 Add config check for _Atomic
doodspav Oct 30, 2024
d1276bb
GHI #35 Fix direct macro names
doodspav Oct 30, 2024
766aeab
GHI #35 Add comment
doodspav Oct 30, 2024
243ff72
GHI #35 Add type param to all do_ macros in direct
doodspav Oct 30, 2024
d8fccc8
GHI #35 Define all direct ops in std impl
doodspav Oct 30, 2024
a8f032e
GHI #35 Define create functions for std impl and fix some mistakes
doodspav Oct 30, 2024
4e7e9cf
GHI #35 Implement all direct functionality for std impl
doodspav Oct 30, 2024
3694227
GHI #35 Flip rank order in std impl
doodspav Oct 30, 2024
b060e85
GHI #35 Remove scratch and temp
doodspav Oct 30, 2024
598a6bd
GHI #35 Improve direct docs
doodspav Oct 30, 2024
65f9452
GHI #35 Add cmpxchg wrapped with store
doodspav Oct 30, 2024
a70391f
GHI #35 Add exchange to cmpxchg wrapped
doodspav Oct 30, 2024
80a7eb6
GHI #35 Add cmpxchg_strong to cmpxchg wrapped
doodspav Oct 31, 2024
c5cf0eb
GHI #35 Minor tidying up
doodspav Oct 31, 2024
5cc96d4
GHI #35 Add bit-test-modify to wrapped cmpxchg
doodspav Oct 31, 2024
2d416d4
GHI #35 Add bit-test-modify ops to std impl (using cmpxchg)
doodspav Oct 31, 2024
047a5ba
GHI #35 Add define fetch ops to wrapped cmpxchg
doodspav Oct 31, 2024
2383b51
GHI #35 Add define fetch noarg ops to wrapped cmpxchg
doodspav Oct 31, 2024
c6ee31a
GHI #35 Add define void ops to wrapped cmpxchg
doodspav Oct 31, 2024
890090f
GHI #35 Add define void noarg ops to wrapped cmpxchg
doodspav Oct 31, 2024
674e6a9
GHI #35 Add binary not to std impl
doodspav Oct 31, 2024
9f2856d
GHI #35 Add missing paren to assert
doodspav Oct 31, 2024
9d377e2
GHI #35 Add arithmetic neg to std impl
doodspav Oct 31, 2024
7374624
GHI #35 Add -Wno-unused-local-typedef and /wd4668
doodspav Oct 31, 2024
d562c57
GHI #35 Add -Wno-unused-local-typedef to ansi flags
doodspav Oct 31, 2024
f4352bf
GHI #35 Improve COMPILER_HAS_ATOMIC check
doodspav Oct 31, 2024
2a5301a
GHI #35 Improve COMPILER_HAS_ATOMIC check further
doodspav Oct 31, 2024
d317f8f
GHI #35 Remove align from transaction (unnecessary)
doodspav Nov 1, 2024
03bc69f
GHI #35 Fix defines if stdatomic is supported but nothing is lock free
doodspav Nov 11, 2024
f84fa77
GHI #35 Update comment [[skip ci]]
doodspav Nov 11, 2024
bc39986
GHI #35 Disable CI jobs to build, test, and cover code
doodspav Nov 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:

jobs:
test-native:
if: false
strategy:
matrix:
# verbose labels make things easier to read in GitHub Actions
Expand Down Expand Up @@ -55,6 +56,7 @@ jobs:
architecture: ${{ matrix.architecture }}

test-qemu:
if: false
strategy:
matrix:
# architecture gets converted to triple
Expand Down Expand Up @@ -133,6 +135,7 @@ jobs:
skip_llvm: ${{ matrix.skip_llvm == true }}

publish-results:
if: false
runs-on: ubuntu-latest
needs:
- test-native
Expand Down
8 changes: 4 additions & 4 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"name": "_patomic-ci-flags-ansi-gnu",
"hidden": true,
"cacheVariables": {
"CMAKE_C_FLAGS": "-Wall -Wextra -Werror -Wpedantic -Wno-unused-function -Wno-atomic-alignment",
"CMAKE_C_FLAGS": "-Wall -Wextra -Werror -Wpedantic -Wno-unused-function -Wno-atomic-alignment -Wno-unused-local-typedef",
"CMAKE_C_STANDARD": "90"
}
},
Expand Down Expand Up @@ -94,23 +94,23 @@
"name": "_patomic-ci-flags-warning-clang",
"hidden": true,
"cacheVariables": {
"CMAKE_C_FLAGS_INIT": "-Weverything -Werror -Wpedantic -Wno-c++98-compat -Wno-covered-switch-default -Wno-padded -Wno-unused-function -Wno-atomic-alignment -Wno-poison-system-directories -Wno-reserved-identifier -Wno-documentation-unknown-command",
"CMAKE_C_FLAGS_INIT": "-Weverything -Werror -Wpedantic -Wno-c++98-compat -Wno-covered-switch-default -Wno-padded -Wno-unused-function -Wno-atomic-alignment -Wno-poison-system-directories -Wno-reserved-identifier -Wno-documentation-unknown-command -Wno-unused-local-typedef",
"CMAKE_CXX_FLAGS_INIT": "-Wall -Wextra -Werror -Wpedantic -Wno-c++17-attribute-extensions"
}
},
{
"name": "_patomic-ci-flags-warning-gcc",
"hidden": true,
"cacheVariables": {
"CMAKE_C_FLAGS_INIT": "-Wall -Wextra -Werror -Wpedantic -Wshadow -Wcast-align -Wconversion -Wsign-conversion -Wnull-dereference -Wdouble-promotion -Wstrict-prototypes -Wmisleading-indentation -Wduplicated-branches -Wlogical-op -Wdeclaration-after-statement -Wno-unused-function",
"CMAKE_C_FLAGS_INIT": "-Wall -Wextra -Werror -Wpedantic -Wshadow -Wcast-align -Wconversion -Wsign-conversion -Wnull-dereference -Wdouble-promotion -Wstrict-prototypes -Wmisleading-indentation -Wduplicated-branches -Wlogical-op -Wdeclaration-after-statement -Wno-unused-function -Wno-unused-local-typedef",
"CMAKE_CXX_FLAGS_INIT": "-Wall -Wextra -Werror -Wpedantic"
}
},
{
"name": "_patomic-ci-flags-warning-msvc",
"hidden": true,
"cacheVariables": {
"CMAKE_C_FLAGS_INIT": "/permissive- /volatile:iso /Wall /WX /wd4464 /wd4132 /wd4820 /wd4127 /wd5045 /wd4710 /wd4711 /wd4668",
"CMAKE_C_FLAGS_INIT": "/permissive- /volatile:iso /Wall /WX /wd4464 /wd4132 /wd4820 /wd4127 /wd5045 /wd4710 /wd4711 /wd4668 /wd4146",
"CMAKE_CXX_FLAGS_INIT": "/permissive- /volatile:iso /W4 /WX"
}
},
Expand Down
92 changes: 92 additions & 0 deletions cmake/check/HasFunction.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
# | COMPILER_HAS_BUILTIN_UNREACHABLE | '__builtin_unreachable(void)' is available as a function |
# | COMPILER_HAS_WCHAR_FWIDE | '<wchar.h>' header is available and makes 'fwide(FILE*, int)' available as a function |
# | COMPILER_HAS_WCHAR_FWPRINTF | '<wchar.h>' header is available and makes 'fwprintf(FILE*, const wchar_t*, ...)' available as a function |
# | COMPILER_HAS_C23_ALIGNOF | 'alignof(T)' is available as a function |
# | COMPILER_HAS_C23_ALIGNOF_EXTN | '__extension__ alignof(T)' is available as a function |
# | COMPILER_HAS_C11_ALIGNOF | '_Alignof(T)' is available as a function |
# | COMPILER_HAS_C11_ALIGNOF_EXTN | '__extension__ _Alignof(T)' is available as a function |
# | COMPILER_HAS_MS_ALIGNOF | '__alignof(T)' is available as a function |
# | COMPILER_HAS_MS_ALIGNOF_EXTN | '__extension__ __alignof(T)' is available as a function |
# | COMPILER_HAS_GNU_ALIGNOF | '__alignof__(T)' is available as a function |
# | COMPILER_HAS_GNU_ALIGNOF_EXTN | '__extension__ __alignof__(T)' is available as a function |
# -----------------------------------------------------------------------------------------------------------------------------------------------


Expand Down Expand Up @@ -55,3 +63,87 @@ check_c_source_compiles_or_zero(
WILL_FAIL_IF_ANY_NOT
${COMPILER_HAS_WCHAR_H}
)

# 'alignof(T)' is available as a function
check_c_source_compiles_or_zero(
SOURCE
"int main(void) { return (int) alignof(int); }"
OUTPUT_VARIABLE
COMPILER_HAS_C23_ALIGNOF
)

# '__extension__ alignof(T)' is available as a function
check_c_source_compiles_or_zero(
SOURCE
"int main(void) { return (int) __extension__ alignof(int); }"
OUTPUT_VARIABLE
COMPILER_HAS_C23_ALIGNOF_EXTN
WILL_SUCCEED_IF_ALL
${COMPILER_HAS_C23_ALIGNOF}
${COMPILER_HAS_EXTN}
WILL_FAIL_IF_ANY_NOT
${COMPILER_HAS_EXTN}
)

# '_Alignof(T)' is available as a function
check_c_source_compiles_or_zero(
SOURCE
"int main(void) { return (int) _Alignof(int); }"
OUTPUT_VARIABLE
COMPILER_HAS_C11_ALIGNOF
)

# '__extension__ _Alignof(T)' is available as a function
check_c_source_compiles_or_zero(
SOURCE
"int main(void) { return (int) __extension__ _Alignof(int); }"
OUTPUT_VARIABLE
COMPILER_HAS_C11_ALIGNOF_EXTN
WILL_SUCCEED_IF_ALL
${COMPILER_HAS_C11_ALIGNOF}
${COMPILER_HAS_EXTN}
WILL_FAIL_IF_ANY_NOT
${COMPILER_HAS_EXTN}
)

# '__alignof(T)' is available as a function
check_c_source_compiles_or_zero(
SOURCE
"int main(void) { return (int) __alignof(int); }"
OUTPUT_VARIABLE
COMPILER_HAS_MS_ALIGNOF
)

# '__extension__ __alignof(T)' is available as a function
check_c_source_compiles_or_zero(
SOURCE
"int main(void) { return (int) __extension__ __alignof(int); }"
OUTPUT_VARIABLE
COMPILER_HAS_MS_ALIGNOF_EXTN
WILL_SUCCEED_IF_ALL
${COMPILER_HAS_MS_ALIGNOF}
${COMPILER_HAS_EXTN}
WILL_FAIL_IF_ANY_NOT
${COMPILER_HAS_EXTN}
)

# '__alignof__(T)' is available as a function
check_c_source_compiles_or_zero(
SOURCE
"int main(void) { return (int) __alignof__(int); }"
OUTPUT_VARIABLE
COMPILER_HAS_GNU_ALIGNOF
)

# '__extension__ __alignof__(T)' is available as a function
check_c_source_compiles_or_zero(
SOURCE
"int main(void) { return (int) __extension__ __alignof__(int); }"
OUTPUT_VARIABLE
COMPILER_HAS_GNU_ALIGNOF_EXTN
WILL_SUCCEED_IF_ALL
${COMPILER_HAS_GNU_ALIGNOF}
${COMPILER_HAS_EXTN}
WILL_FAIL_IF_ANY_NOT
${COMPILER_HAS_EXTN}
)
22 changes: 16 additions & 6 deletions cmake/check/HasHeader.cmake
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
# ---- Has Header ----

# ----------------------------------------------------------
# | Variable | Check |
# |=======================|================================|
# | COMPILER_HAS_STDINT_H | <stdint.h> header is available |
# | COMPILER_HAS_WCHAR_H | <wchar.h> header is available |
# ----------------------------------------------------------
# ----------------------------------------------------------------
# | Variable | Check |
# |==========================|===================================|
# | COMPILER_HAS_STDATOMIC_H | <stdatomic.h> header is available |
# | COMPILER_HAS_STDINT_H | <stdint.h> header is available |
# | COMPILER_HAS_WCHAR_H | <wchar.h> header is available |
# ----------------------------------------------------------------


# <stdatomic.h> header is available
check_c_source_compiles_or_zero(
SOURCE
"#include <stdatomic.h> \n\
int main(void) {}"
OUTPUT_VARIABLE
COMPILER_HAS_STDATOMIC_H
)

# <stdint.h> header is available
check_c_source_compiles_or_zero(
SOURCE
Expand Down
67 changes: 62 additions & 5 deletions cmake/check/HasKeyword.cmake
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# ---- Has Keyword ----

# ----------------------------------------------------------------------
# | Variable | Check |
# |========================|===========================================|
# | COMPILER_HAS_EXTN | '__extension__' is available as a keyword |
# ----------------------------------------------------------------------
# -------------------------------------------------------------------------
# | Variable | Check |
# |===========================|===========================================|
# | COMPILER_HAS_EXTN | '__extension__' is available as a keyword |
# | COMPILER_HAS_RESTRICT | 'restrict' is available as a keyword |
# | COMPILER_HAS_MS_RESTRICT | '__restrict' is available as a keyword |
# | COMPILER_HAS_GNU_RESTRICT | '__restrict__' is available as a keyword |
# | COMPILER_HAS_ATOMIC | '_Atomic' is available as a keyword |
# -------------------------------------------------------------------------


# '__extension__' is available as a keyword
Expand All @@ -14,3 +18,56 @@ check_c_source_compiles_or_zero(
OUTPUT_VARIABLE
COMPILER_HAS_EXTN
)

# 'restrict' is available as a keyword
check_c_source_compiles_or_zero(
SOURCE
"static int get(const int *const restrict p) { return *p; } \n\
int main(void) { int x = 0; return get(&x); }"
OUTPUT_VARIABLE
COMPILER_HAS_RESTRICT
)

# '__restrict' is available as a keyword
check_c_source_compiles_or_zero(
SOURCE
"static int get(const int *const __restrict p) { return *p; } \n\
int main(void) { int x = 0; return get(&x); }"
OUTPUT_VARIABLE
COMPILER_HAS_MS_RESTRICT
)

# '__restrict__' is available as a keyword
check_c_source_compiles_or_zero(
SOURCE
"static int get(const int *const __restrict__ p) { return *p; } \n\
int main(void) { int x = 0; return get(&x); }"
OUTPUT_VARIABLE
COMPILER_HAS_GNU_RESTRICT
)

# '_Atomic' is available as a keyword
check_c_source_compiles_or_zero(
SOURCE
"#include <stdatomic.h> \n\
int main(void) { \n\
static const _Atomic(unsigned char) a1; \n\
static const _Atomic(unsigned short) a2; \n\
static const _Atomic(unsigned int) a3; \n\
static const _Atomic(unsigned long) a4; \n\
const volatile _Atomic(unsigned char) *const p1 = &a1; \n\
const volatile _Atomic(unsigned short) *const p2 = &a2; \n\
const volatile _Atomic(unsigned int) *const p3 = &a3; \n\
const volatile _Atomic(unsigned long) *const p4 = &a4; \n\
unsigned long sum = 0; \n\
sum += (unsigned long) atomic_load(p1); \n\
sum += (unsigned long) atomic_load(p2); \n\
sum += (unsigned long) atomic_load(p3); \n\
sum += (unsigned long) atomic_load(p4); \n\
return (int) sum; \n\
}"
OUTPUT_VARIABLE
COMPILER_HAS_ATOMIC
WILL_FAIL_IF_ANY_NOT
${COMPILER_HAS_STDATOMIC_H}
)
Loading