3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-02-03 15:56:17 +00:00

[WIP] Update code base to use std::span (#8269)

* Initial plan

* Add std::span to bit_util.h with backward compatibility

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Add std::span to hash.h unsigned_ptr_hash function

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Add std::span to ref_vector.h append and constructor

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
This commit is contained in:
Copilot 2026-01-21 12:42:19 -08:00 committed by GitHub
parent 1bb471447e
commit 7686e861a8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 192 additions and 106 deletions

View file

@ -27,17 +27,17 @@ static void tst_shl(unsigned src_sz, unsigned const * src, unsigned k,
for (unsigned sz = 1; sz <= dst_sz; ++sz) {
if (trace)
std::cout << " for sz = " << sz << std::endl;
shl(src_sz, src, k, sz, actual_dst.data());
ENSURE(!has_one_at_first_k_bits(sz, actual_dst.data(), k));
shl(std::span<unsigned const>(src, src_sz), k, std::span<unsigned>(actual_dst.data(), sz));
ENSURE(!has_one_at_first_k_bits(std::span<unsigned const>(actual_dst.data(), sz), k));
for (unsigned i = 0; i < sz; ++i) {
if (trace && dst[i] != actual_dst[i])
std::cout << "UNEXPECTED RESULT at [" << i << "]: " << actual_dst[i] << ", expected: " << dst[i] << "\n";
ENSURE(dst[i] == actual_dst[i]);
}
if (sz == src_sz) {
unsigned nz1 = nlz(sz, src);
if (nz1 >= k && !is_zero(sz, src)) {
unsigned nz2 = nlz(sz, actual_dst.data());
unsigned nz1 = nlz(std::span<unsigned const>(src, sz));
if (nz1 >= k && !is_zero(std::span<unsigned const>(src, sz))) {
unsigned nz2 = nlz(std::span<unsigned const>(actual_dst.data(), sz));
if (nz1 - k != nz2) {
if (trace)
std::cout << "nlz BUG, nlz1: " << nz1 << ", k: " << k << ", nlz2: " << nz2 << std::endl;
@ -48,7 +48,7 @@ static void tst_shl(unsigned src_sz, unsigned const * src, unsigned k,
if (sz >= src_sz + (k/32) + 1) {
svector<unsigned> new_src;
new_src.resize(sz, 0xAAAAAAAA);
shr(sz, actual_dst.data(), k, new_src.data());
shr(std::span<unsigned const>(actual_dst.data(), sz), k, std::span<unsigned>(new_src.data(), sz));
for (unsigned i = 0; i < src_sz; ++i) {
if (trace && src[i] != new_src[i]) {
std::cout << "shr BUG, inverting shl, at bit[" << i << "], " << new_src[i] << ", expected: " << src[i] << std::endl;
@ -59,9 +59,9 @@ static void tst_shl(unsigned src_sz, unsigned const * src, unsigned k,
}
if (trace)
std::cout << " shift by 1, k times" << std::endl;
copy(src_sz, src, dst_sz, actual_dst.data());
copy(std::span<unsigned const>(src, src_sz), std::span<unsigned>(actual_dst.data(), dst_sz));
for (unsigned i = 0; i < k; ++i) {
shl(dst_sz, actual_dst.data(), 1, dst_sz, actual_dst.data());
shl(std::span<unsigned const>(actual_dst.data(), dst_sz), 1, std::span<unsigned>(actual_dst.data(), dst_sz));
}
for (unsigned i = 0; i < dst_sz; ++i) {
if (trace && dst[i] != actual_dst[i])
@ -71,7 +71,7 @@ static void tst_shl(unsigned src_sz, unsigned const * src, unsigned k,
if (src_sz <= dst_sz) {
if (trace)
std::cout << " self-shl" << std::endl;
shl(src_sz, src, k, src_sz, const_cast<unsigned*>(src));
shl(std::span<unsigned const>(src, src_sz), k, std::span<unsigned>(const_cast<unsigned*>(src), src_sz));
for (unsigned i = 0; i < src_sz; ++i) {
if (trace && src[i] != dst[i])
std::cout << "UNEXPECTED RESULT at [" << i << "]: " << src[i] << ", expected: " << dst[i] << "\n";
@ -131,7 +131,7 @@ static void tst_shr(unsigned src_sz, unsigned const * src, unsigned k,
}
svector<unsigned> actual_dst;
actual_dst.resize(src_sz, 0xAAAAAAAA);
shr(src_sz, src, k, actual_dst.data());
shr(std::span<unsigned const>(src, src_sz), k, std::span<unsigned>(actual_dst.data(), src_sz));
for (unsigned i = 0; i < src_sz; ++i) {
if (trace && dst[i] != actual_dst[i])
std::cout << "UNEXPECTED RESULT at [" << i << "]: " << actual_dst[i] << ", expected: " << dst[i] << "\n";