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

For each line integration #974

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
60a5660
Added ANSI control characters
jeremybarnes Jan 13, 2025
1194092
Patch in missing clang12 typeids for half
jeremybarnes Jan 13, 2025
f1607bb
Begin adding bselect/brank functions
jeremybarnes Jan 13, 2025
05b416f
vm: roundUpToPageSize, test fix
jeremybarnes Jan 13, 2025
a1d4762
Value Description genericism improvements, comparisons
jeremybarnes Jan 13, 2025
88aa054
(NEEDS TEST) Command Expression paranthesis, improvements
jeremybarnes Jan 13, 2025
1719be1
EnvOption: from anything string constructible (TRIVIAL)
jeremybarnes Jan 13, 2025
fb5cd57
Moved ostream_* back into namespace std (TRIVIAL)
jeremybarnes Jan 13, 2025
b5fb088
Extra tests for utils functionality (TRIVIAL)
jeremybarnes Jan 13, 2025
0178dac
possibly_dynamic_buffer spans (TRIVIAL)
jeremybarnes Jan 13, 2025
5a364e2
for_each_line improved blocking/compressor support
jeremybarnes Jan 13, 2025
a065792
WUP: filter_streams, for_each_line improvements; no boost::iostreams
jeremybarnes Jan 16, 2025
ef211ad
SQUASH filter_streams, boost (2)
jeremybarnes Jan 17, 2025
415e2dd
FIXUP boost iostreams
jeremybarnes Jan 17, 2025
6de35ef
FIXUP missing type_info for half (un-break Linux)
jeremybarnes Jan 17, 2025
dcb08cc
Fix crashes when converting exceptions to std::exception (TRIVIAL)
jeremybarnes Jan 17, 2025
57157a4
Python virtualenv fixups (TRIVIAL)
jeremybarnes Jan 17, 2025
0b17ed9
FIXUP osx code signing
jeremybarnes Jan 17, 2025
fef24b2
FIXUP code signing
jeremybarnes Jan 17, 2025
b5ff590
FIXUP boost iostreams
jeremybarnes Jan 17, 2025
9233380
SQUASH filter_streams, boost (3)
jeremybarnes Jan 17, 2025
389fbf6
SQUASH filter_streams, for_each_line (4)
jeremybarnes Jan 18, 2025
5872ffa
SQUASH for_each_line testing/fixes (5)
jeremybarnes Jan 20, 2025
7b9a516
Added scoreboard task to track parallel execution of a sequence of tasks
jeremybarnes Jan 20, 2025
7c008b4
SQUASH for_each_line testing/fixes (6)
jeremybarnes Jan 20, 2025
8054745
SQUASH for_each_line (7)
jeremybarnes Jan 25, 2025
f8bb6cc
SQUASH for_each_line (8)
jeremybarnes Jan 25, 2025
149d7fa
FIXUP vfs files
jeremybarnes Jan 31, 2025
444e432
SQUASH for_each_line (8)
jeremybarnes Jan 31, 2025
58c8c53
SQUASH for_each_line (9)
jeremybarnes Jan 31, 2025
e68f382
SQUASH for_each_line (10)
jeremybarnes Feb 1, 2025
f35e511
SQUASH for_each_line (11)
jeremybarnes Feb 1, 2025
b2876a0
SQUASH for_each_line (12)
jeremybarnes Feb 1, 2025
bda8334
SQUASH for_each_line (13)
jeremybarnes Feb 3, 2025
2cfb2ef
SQUASH for_each_line (14)
jeremybarnes Feb 4, 2025
df516a1
TODO: fix this bug: make for_each_line_test SANITIZERS=address
jeremybarnes Feb 4, 2025
d1d7cf8
Undo ThreadPool ASAN bug trigger
jeremybarnes Feb 4, 2025
fbf23ab
SQUASH for_each_line (14)
jeremybarnes Feb 4, 2025
ec503c2
SQUASH for_each_line (15)
jeremybarnes Feb 4, 2025
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
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ find_package(Boost REQUIRED COMPONENTS
unit_test_framework
regex
date_time
python312
system
iostreams
)

include_directories(${CMAKE_CURRENT_SOURCE_DIR})
Expand Down
39 changes: 39 additions & 0 deletions arch/ansi.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* ansi.cc -*- C++ -*-
Jeremy Barnes, 21 February 2007
Copyright (c) 2007 Jeremy Barnes. All rights reserved.
This file is part of MLDB. Copyright 2015 mldb.ai inc. All rights reserved.

ANSI escape codes for pretty-printing on terminals.
*/

#include "ansi.h"
#include <cstdlib>

// From c standard library
extern "C" {
int isatty(int);
}


namespace MLDB {
namespace ansi {

static bool get_ansi_colors_enabled()
{
std::string ansi_colors_env = ::getenv("NO_COLOR") ? ::getenv("NO_COLOR") : "AUTO";

if (ansi_colors_env == "NEVER") {
return true;
}
else if (ansi_colors_env == "AUTO") {
return ::isatty(0);
}
else {
return false;
}
}

const bool enable_ansi = get_ansi_colors_enabled();

} // namespace ansi
} // namespace MLDB
45 changes: 45 additions & 0 deletions arch/ansi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* ansi.h -*- C++ -*-
Jeremy Barnes, 21 February 2007
Copyright (c) 2007 Jeremy Barnes. All rights reserved.
This file is part of MLDB. Copyright 2015 mldb.ai inc. All rights reserved.

ANSI escape codes for pretty-printing on terminals.
*/


#pragma once

#include <iostream>

namespace MLDB {
namespace ansi {

extern const bool enable_ansi;

#define ANSI_CODE(name, sequence) \
static constexpr const char ansi_color_##name [] = "\u001b" sequence "m\0"; \
inline std::ostream & name(std::ostream & stream) { if (enable_ansi) stream << ansi_color_##name; return stream; } \
inline const char * ansi_str_##name() { return enable_ansi ? ansi_color_##name : ""; }

ANSI_CODE(reset, "[0");
ANSI_CODE(bold, "[1");
ANSI_CODE(underline, "[4");
ANSI_CODE(reversed, "[7");

#define ANSI_COLOR(name, sequence) \
ANSI_CODE(name, "[3" sequence) \
ANSI_CODE(bright_##name, "[3" sequence ";1") \
ANSI_CODE(bg_##name, "[4" sequence) \
ANSI_CODE(bg_bright_##name, "[4" sequence ";1")

ANSI_COLOR(black, "0");
ANSI_COLOR(red, "1");
ANSI_COLOR(green, "2");
ANSI_COLOR(yellow, "3");
ANSI_COLOR(blue, "4");
ANSI_COLOR(magenta, "5");
ANSI_COLOR(cyan, "6");
ANSI_COLOR(white, "7");

} // namespace ansi
} // namespace MLDB
5 changes: 3 additions & 2 deletions arch/arch.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ LIBARCH_SOURCES := \
file_functions.cc \
wait_on_address.cc \
wakeup_fd.cc \
thread_specific.cc

thread_specific.cc \
ansi.cc \
missing_typeids.cc \

ifeq ($(ARCH),x86_64)
LIBARCH_SOURCES += simd_vector_avx.cc
Expand Down
33 changes: 33 additions & 0 deletions arch/atomic_min_max.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// public domain

#pragma once

#include <atomic>

namespace MLDB {

template<typename T, typename T2>
void atomic_min(std::atomic<T> & val, T2 other)
{
T current = val.load(std::memory_order_relaxed);
for (;;) {
if (other >= current)
return;
if (val.compare_exchange_weak(current, other, std::memory_order_relaxed))
return;
}
}

template<typename T, typename T2>
void atomic_max(std::atomic<T> & val, T2 other)
{
T current = val.load(std::memory_order_relaxed);
for (;;) {
if (other <= current)
return;
if (val.compare_exchange_weak(current, other, std::memory_order_relaxed))
return;
}
}

} // namespace MLDB
29 changes: 29 additions & 0 deletions arch/bit_range_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <stdint.h>
#include <algorithm>
#include <atomic>
#include <bit>


namespace MLDB {
Expand Down Expand Up @@ -355,6 +356,34 @@ MLDB_ALWAYS_INLINE signed long long fixup_extract(signed long long e, shift_t bi
return sign_extend(e, bits);
}

// Index of the nth set bit
// https://stackoverflow.com/questions/7669057/find-nth-set-bit-in-an-int
//__attribute__((target("default")))
inline uint64_t nthSetBit(uint64_t v, unsigned n)
{
if (n > (unsigned)__builtin_popcountll(v)/* std::popcount(v) */)
return 0;

for (unsigned i=0; n > 0 && i<n; i++) {
v &= v-1; // remove the least significant bit
}
return v & ~(v-1); // extract the least significant bit
}

#if 0
__attribute__((target("bmi2")))
inline uint64_t nthSetBit(uint64_t x, unsigned n)
{
return _pdep_u64(1ULL << n, x);
}
#endif

inline int nthSetBitIndex(uint64_t x, unsigned n)
{
uint64_t bit = nthSetBit(x, n);
return bit == 0 ? -1 : std::countr_zero(bit);
}

/*****************************************************************************/
/* MEM_BUFFER */
/*****************************************************************************/
Expand Down
14 changes: 14 additions & 0 deletions arch/missing_typeids.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <typeinfo>
#include <iostream>

#ifdef __clang__
#ifdef __APPLE__
// Sometimes the typeinfo node for _Float16 is missing (llvm on OSX, at least)
// Create it here if that's the case
struct HalfTypeInfo: public std::type_info {
HalfTypeInfo(): std::type_info("Dh") {};
};

HalfTypeInfo _ZTIDF16_ __attribute__((__weak__));
#endif /* __APPLE__ */
#endif /* __clang__ */
3 changes: 2 additions & 1 deletion arch/rtti_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ const void * is_convertible(const std::type_info & from_type,
//cerr << "could upcast" << endl;
return ur.dst_ptr;
}

return nullptr;

//cerr << "couldn't upcast" << endl;

//const char * adj_ptr = (const char *)obj;
Expand Down
28 changes: 28 additions & 0 deletions arch/testing/bit_range_ops_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -453,3 +453,31 @@ BOOST_AUTO_TEST_CASE(testExtraBits)
BOOST_CHECK_EQUAL(data[1], MINUS1);
}
}

BOOST_AUTO_TEST_CASE(nth_bit_index)
{
BOOST_CHECK_EQUAL(nthSetBit(1, 0), 1);
BOOST_CHECK_EQUAL(nthSetBit(2, 0), 2);
BOOST_CHECK_EQUAL(nthSetBit(4, 0), 4);

BOOST_CHECK_EQUAL(nthSetBit(1, 1), 0);
BOOST_CHECK_EQUAL(nthSetBit(2, 1), 0);
BOOST_CHECK_EQUAL(nthSetBit(4, 1), 0);

BOOST_CHECK_EQUAL(nthSetBit(7, 0), 1);
BOOST_CHECK_EQUAL(nthSetBit(7, 1), 2);
BOOST_CHECK_EQUAL(nthSetBit(7, 2), 4);
BOOST_CHECK_EQUAL(nthSetBit(7, 3), 0);

BOOST_CHECK_EQUAL(nthSetBit(0, 64), 0);
BOOST_CHECK_EQUAL(nthSetBit(1, 64), 0);
BOOST_CHECK_EQUAL(nthSetBit(std::numeric_limits<uint64_t>::max(), 64), 0);

for (int i = 0; i < 63; ++i) {
BOOST_CHECK_EQUAL(nthSetBitIndex(1ULL<<i, 0), i);
BOOST_CHECK_EQUAL(nthSetBitIndex(1ULL<<i, 1), -1);
BOOST_CHECK_EQUAL(nthSetBitIndex(std::numeric_limits<uint64_t>::max(), i), i);
}
BOOST_CHECK_EQUAL(nthSetBitIndex(2, 0), 1);
BOOST_CHECK_EQUAL(nthSetBitIndex(3, 1), 1);
}
10 changes: 1 addition & 9 deletions arch/testing/vm_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "mldb/utils/vector_utils.h"
#include "mldb/arch/exception_handler.h"
#include "mldb/base/scope.h"
#include "mldb/arch/info.h"

#include <boost/test/unit_test.hpp>
#include <iostream>
Expand All @@ -30,15 +31,6 @@ using namespace std;

using boost::unit_test::test_suite;

// Copied from utils/info.cc due to not being able to include utils lib
size_t num_open_files()
{
size_t result = 0;
for (auto entry: std::filesystem::directory_iterator("/proc/self/fd"))
++result;
return result;
}

void test_function()
{
cerr << "hello" << endl;
Expand Down
12 changes: 12 additions & 0 deletions arch/vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ constexpr int page_offset_mask = page_size - 1;

static const size_t page_num_mask = ~(size_t)page_offset_mask;

// Takes the given number of bytes and rounds up to the multiple of page size
// that fits it all in.
inline size_t roundUpToPageSize(size_t mem)
{
return (mem + page_size - 1) / page_size * page_size;
}

inline size_t roundDownToPageSize(size_t mem)
{
return ssize_t(mem - page_size + 1) / page_size * page_size;
}

struct Pagemap_Entry {

// Note that this just looks at the pfn. The other flags might change
Expand Down
2 changes: 2 additions & 0 deletions base/base.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
LIBBASE_SOURCES := \
parse_context.cc \
thread_pool.cc \
compute_context.cc \
parallel.cc \
optimized_path.cc \
hex_dump.cc \
../types/string.cc \
iostream_adaptors.cc \

LIBBASE_LINK := \
arch \
Expand Down
Loading