Skip to content

Commit cd5b199

Browse files
committed
Merge remote-tracking branch 'upstream/dev' into unsigned-signed
2 parents ef5e84f + f015a94 commit cd5b199

22 files changed

Lines changed: 1959 additions & 106 deletions

.github/workflows/regression-tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
name: sdist
7070
path: dist
7171

72-
- uses: actions/setup-python@v6.2.0
72+
- uses: actions/setup-python@v6.3.0
7373
with:
7474
python-version: ${{matrix.python-version}}
7575
allow-prereleases: true

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
steps:
3333
- uses: actions/checkout@v7
3434

35-
- uses: actions/setup-python@v6.2.0
35+
- uses: actions/setup-python@v6.3.0
3636
with:
3737
python-version: "3.13"
3838

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ repos:
1616
- id: check-toml
1717
- id: check-added-large-files
1818
- repo: https://github.com/henryiii/validate-pyproject-schema-store
19-
rev: "2026.06.14"
19+
rev: "2026.06.26"
2020
hooks:
2121
- id: validate-pyproject
2222
- repo: https://github.com/codespell-project/codespell
@@ -26,7 +26,7 @@ repos:
2626
additional_dependencies:
2727
- tomli
2828
- repo: https://github.com/astral-sh/ruff-pre-commit
29-
rev: "v0.15.18"
29+
rev: "v0.15.20"
3030
hooks:
3131
- id: "ruff"
3232
args:
@@ -51,7 +51,7 @@ repos:
5151
exclude: "^src/cocotb/share/include/(sv_vpi|vhpi|vpi)_user(_ext)?.h"
5252
types_or: [c, c++]
5353
- repo: https://github.com/astral-sh/uv-pre-commit
54-
rev: 0.11.23
54+
rev: 0.11.25
5555
hooks:
5656
- id: uv-lock
5757

cpp/CMakeLists.txt

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,71 @@ target_include_directories(coconext PUBLIC
1414
target_compile_features(coconext PUBLIC cxx_std_20)
1515
set_target_properties(coconext PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
1616

17-
# On macOS the install name is @rpath-relative so a preloaded image
18-
# satisfies the dependency by install-name match rather than by search path.
19-
# Looks like RPATH, is actually not.
17+
# Needed for MacOS.
2018
set_target_properties(coconext PROPERTIES
2119
MACOSX_RPATH TRUE
2220
INSTALL_NAME_DIR "@rpath")
2321

24-
install(TARGETS coconext
22+
# -- libgpi --------------------------------------------------------------------
23+
#
24+
# This is some CMake to pull in libgpi since cocotb doesn't provide a CMake
25+
# package yet.
26+
27+
# Use cocotb_tools.config to get libgpi binary dir and include dir
28+
execute_process(
29+
COMMAND ${Python_EXECUTABLE} -c
30+
"from cocotb_tools.config import libs_dir, share_dir; print(libs_dir); print(share_dir / 'include')"
31+
OUTPUT_VARIABLE _coconext_cocotb_paths
32+
OUTPUT_STRIP_TRAILING_WHITESPACE
33+
COMMAND_ERROR_IS_FATAL ANY)
34+
string(REPLACE "\n" ";" _coconext_cocotb_paths "${_coconext_cocotb_paths}")
35+
list(GET _coconext_cocotb_paths 0 COCOTB_LIBS_DIR)
36+
list(GET _coconext_cocotb_paths 1 COCOTB_INCLUDE_DIR)
37+
38+
# Create a CMake target for libgpi. cocotb installs libgpi as .so on every platform except Windows (including MacOS).
39+
if(WIN32)
40+
set(_coconext_libgpi_suffix ".dll")
41+
else()
42+
set(_coconext_libgpi_suffix ".so")
43+
endif()
44+
add_library(cocotb_gpi SHARED IMPORTED)
45+
set_target_properties(cocotb_gpi PROPERTIES
46+
IMPORTED_LOCATION "${COCOTB_LIBS_DIR}/libgpi${_coconext_libgpi_suffix}"
47+
INTERFACE_INCLUDE_DIRECTORIES "${COCOTB_INCLUDE_DIR}")
48+
49+
# -- libcoconext_gpi -----------------------------------------------------------
50+
#
51+
# For parts of the library that have a dependency on libgpi and a running
52+
# simulation, e.g. handles and GPI triggers.
53+
54+
add_library(coconext_gpi SHARED
55+
src/sim_objects.cpp
56+
)
57+
set_target_properties(coconext_gpi PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
58+
target_link_libraries(coconext_gpi
59+
PRIVATE
60+
cocotb_gpi
61+
PUBLIC
62+
coconext)
63+
64+
# Needed for MacOS.
65+
set_target_properties(coconext_gpi PROPERTIES
66+
MACOSX_RPATH TRUE
67+
INSTALL_NAME_DIR "@rpath")
68+
69+
# RPATH to the current dir to pick up libcoconext.
70+
if(APPLE)
71+
set(_coconext_origin "@loader_path")
72+
else()
73+
set(_coconext_origin "$ORIGIN")
74+
endif()
75+
set_target_properties(coconext_gpi PROPERTIES
76+
INSTALL_RPATH "${_coconext_origin}"
77+
BUILD_RPATH "${_coconext_origin}")
78+
79+
# -- install -------------------------------------------------------------------
80+
81+
install(TARGETS coconext coconext_gpi
2582
EXPORT coconextTargets
2683
LIBRARY DESTINATION coconext/lib
2784
RUNTIME DESTINATION coconext/lib
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef COCONEXT_SIM_OBJECTS_HPP
2+
#define COCONEXT_SIM_OBJECTS_HPP
3+
4+
namespace coconext::sim_objects {
5+
6+
bool has_registered_impl() noexcept;
7+
8+
} // namespace coconext::sim_objects
9+
10+
#endif // COCONEXT_SIM_OBJECTS_HPP

cpp/include/coconext/types.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "./types/logic_array.hpp"
1111
#include "./types/range.hpp"
1212
#include "./types/resize_mode.hpp"
13+
#include "./types/reverse.hpp"
1314
#include "./types/signed.hpp"
1415
#include "./types/unsigned.hpp"
1516
#include "./types/vector.hpp"

cpp/include/coconext/types/range.hpp

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -156,28 +156,17 @@ struct Range {
156156
}
157157

158158
friend constexpr bool operator==(Range const& lhs, Range const& rhs) noexcept {
159-
auto left_len = lhs.length();
160-
if (left_len != rhs.length()) {
161-
return false;
162-
}
163-
if (left_len == 0) {
164-
// lengths are equal and all zero-length ranges are equal
165-
return true;
166-
}
167-
if (lhs.left != rhs.left) {
168-
// lengths are equal and >= 1, so if left endpoints differ the
169-
// ranges cannot be equal
170-
return false;
171-
}
172-
// If left endpoints are equal and lengths are equal, then right
173-
// endpoint and direction must be the same for length >= 2 cases. If
174-
// length is 1, then the direction and right endpoint do not matter,
175-
// since the range only contains one value and that's the left endpoint
176-
// we already checked.
177-
return true;
159+
return lhs.left == rhs.left && lhs.right == rhs.right
160+
&& lhs.direction == rhs.direction;
178161
}
179162
};
180163

164+
constexpr Range reverse(Range const& r) noexcept {
165+
return Range{
166+
r.right, r.direction == Direction::TO ? Direction::DOWNTO : Direction::TO, r.left
167+
};
168+
}
169+
181170
// more optimal implementation of std::ranges::find for Range
182171
constexpr Range::iterator find(Range const& range, Range::value_type value) {
183172
if (range.direction == Direction::TO) {
@@ -221,18 +210,9 @@ struct std::formatter<coconext::types::Range> {
221210
template <>
222211
struct std::hash<coconext::types::Range> {
223212
size_t operator()(coconext::types::Range const& range) const noexcept {
224-
// if a == a then hash(a) == hash(a), so we have to force all 0 and 1
225-
// length ranges to have repeatable hashes.
226-
auto const len = range.length();
227-
if (len == 0) {
228-
return hash<size_t>{}(0);
229-
} else if (len == 1) {
230-
return hash<coconext::types::Range::value_type>{}(range.left);
231-
} else {
232-
return coconext::types::detail::hash_combine(
233-
range.left, range.right, range.direction
234-
);
235-
}
213+
return coconext::types::detail::hash_combine(
214+
range.left, range.right, range.direction
215+
);
236216
}
237217
};
238218

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#ifndef COCONEXT_REVERSE_HPP
2+
#define COCONEXT_REVERSE_HPP
3+
4+
#include <algorithm>
5+
#include <coconext/types/array.hpp>
6+
#include <coconext/types/array_base.hpp>
7+
#include <coconext/types/range.hpp>
8+
#include <coconext/types/vector.hpp>
9+
#include <ranges>
10+
11+
namespace coconext::types {
12+
13+
template <typename T, Range R>
14+
constexpr detail::Array<T, reverse(R)> reverse(detail::Array<T, R> const& a) {
15+
detail::Array<T, reverse(R)> result;
16+
std::ranges::reverse_copy(a, result.begin());
17+
return result;
18+
}
19+
20+
template <typename T>
21+
Vector<T> reverse(Vector<T> const& v) {
22+
Vector<T> result(reverse(v.range()));
23+
std::ranges::reverse_copy(v, result.begin());
24+
return result;
25+
}
26+
27+
template <typename ArrayT>
28+
Vector<std::ranges::range_value_t<ArrayT>> reverse(ArraySlice<ArrayT> const& s) {
29+
Vector<std::ranges::range_value_t<ArrayT>> result(reverse(s.range()));
30+
std::ranges::reverse_copy(s, result.begin());
31+
return result;
32+
}
33+
34+
template <typename ArrayT, Range R>
35+
constexpr detail::Array<std::ranges::range_value_t<ArrayT>, reverse(R)> reverse(
36+
StaticArraySlice<ArrayT, R> const& s
37+
) {
38+
detail::Array<std::ranges::range_value_t<ArrayT>, reverse(R)> result;
39+
std::ranges::reverse_copy(s, result.begin());
40+
return result;
41+
}
42+
43+
} // namespace coconext::types
44+
45+
#endif // COCONEXT_REVERSE_HPP

cpp/src/sim_objects.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <coconext/sim_objects.hpp>
2+
#include <gpi.h>
3+
4+
namespace coconext::sim_objects {
5+
6+
bool has_registered_impl() noexcept { return ::gpi_has_registered_impl(); }
7+
8+
} // namespace coconext::sim_objects

0 commit comments

Comments
 (0)