Skip to content

Commit

Permalink
Include changes made to <hybrid/bitset.h> by deeon
Browse files Browse the repository at this point in the history
  • Loading branch information
GrieferAtWork committed Mar 17, 2024
1 parent 5d949db commit 9f0679a
Show file tree
Hide file tree
Showing 9 changed files with 478 additions and 118 deletions.
4 changes: 4 additions & 0 deletions kos/.clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ ForEachMacros:
- BSEARCH_RANGE
- BSEARCH_RANGE_EX
- BSEARCH_EX
- bitset_foreach
- bitset_nforeach
- __hybrid_bitset_foreach
- __hybrid_bitset_nforeach
- PCI_FOREACH_DEVICE
- PCI_FOREACH_DEVICE_CLASS
- __STATIC_IF
Expand Down
2 changes: 2 additions & 0 deletions kos/cpp.hint
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,10 @@
// <hybrid/bitset.h>
#define __hybrid_bitset_decl(x,n) x[n]
#define __hybrid_bitset_foreach(x,y,z) for(;;)
#define __hybrid_bitset_nforeach(x,y,z,a) for(;;)
#define bitset_decl(x,n) x[n]
#define bitset_foreach(x,y,z) for(;;)
#define bitset_nforeach(x,y,z,a) for(;;)



Expand Down
2 changes: 2 additions & 0 deletions kos/include/compiler/msvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,9 @@ void __builtin_va_end(__builtin_va_list &__ap);
#define __GCC_HAS_WARNING_Wunreachable_code _xS(4702)
#define __GCC_HAS_WARNING_Wmaybe_uninitialized _xS(4701 4703)
#define __GCC_HAS_WARNING_Wcast_function_type _xS(4054 4152)
#if _MSC_VER >= 1500
#define __GCC_HAS_WARNING_MSconditional_expression_is_constant _xS(4127)
#endif /* _MSC_VER >= 1500 */
#define __GCC_HAS_WARNING_Wdiv_by_zero _xS(4723 4724)
#define __GCC_HAS_WARNING_Winvalid_offsetof _xS(4597 4749 4842)
#define __GCC_HAS_WARNING_Woverflow _xS(4056 4178 4340 4427 4756 4757)
Expand Down
18 changes: 18 additions & 0 deletions kos/include/hybrid/__atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -1155,4 +1155,22 @@ template<class T> typename ::__intern::____INTELLISENSE_enableif< ::__intern::__
#define __GCC_ATOMIC_POINTER_LOCK_FREE __HYBRID_ATOMIC_LOCKFREE(__SIZEOF_POINTER__)
#endif /* !__GCC_ATOMIC_POINTER_LOCK_FREE */

/* Atomic bitset operations. */
#ifdef __GUARD_HYBRID___BITSET_H
#define __hybrid_bitset_atomic_set(self, bitno) __hybrid_atomic_or(&(self)[__HYBRID_BITSET_WORD(bitno)], __HYBRID_BITSET_MASK(bitno), __ATOMIC_SEQ_CST)
#define __hybrid_bitset_atomic_clear(self, bitno) __hybrid_atomic_and(&(self)[__HYBRID_BITSET_WORD(bitno)], ~__HYBRID_BITSET_MASK(bitno), __ATOMIC_SEQ_CST)
#define __hybrid_bitset_atomic_flip(self, bitno) __hybrid_atomic_xor(&(self)[__HYBRID_BITSET_WORD(bitno)], __HYBRID_BITSET_MASK(bitno), __ATOMIC_SEQ_CST)
#define __hybrid_bitset_atomic_fetchset(self, bitno) (__hybrid_atomic_fetchor(&(self)[__HYBRID_BITSET_WORD(bitno)], __HYBRID_BITSET_MASK(bitno), __ATOMIC_SEQ_CST) & __HYBRID_BITSET_MASK(bitno))
#define __hybrid_bitset_atomic_fetchclear(self, bitno) (__hybrid_atomic_fetchand(&(self)[__HYBRID_BITSET_WORD(bitno)], ~__HYBRID_BITSET_MASK(bitno), __ATOMIC_SEQ_CST) & __HYBRID_BITSET_MASK(bitno))
#define __hybrid_bitset_atomic_fetchflip(self, bitno) (__hybrid_atomic_fetchxor(&(self)[__HYBRID_BITSET_WORD(bitno)], __HYBRID_BITSET_MASK(bitno), __ATOMIC_SEQ_CST) & __HYBRID_BITSET_MASK(bitno))
#ifdef __GUARD_HYBRID_BITSET_H
#define bitset_atomic_set(self, bitno) __hybrid_bitset_atomic_set(self, bitno)
#define bitset_atomic_clear(self, bitno) __hybrid_bitset_atomic_clear(self, bitno)
#define bitset_atomic_flip(self, bitno) __hybrid_bitset_atomic_flip(self, bitno)
#define bitset_atomic_fetchset(self, bitno) __hybrid_bitset_atomic_fetchset(self, bitno)
#define bitset_atomic_fetchclear(self, bitno) __hybrid_bitset_atomic_fetchclear(self, bitno)
#define bitset_atomic_fetchflip(self, bitno) __hybrid_bitset_atomic_fetchflip(self, bitno)
#endif /* __GUARD_HYBRID_BITSET_H */
#endif /* __GUARD_HYBRID___BITSET_H */

#endif /* !__GUARD_HYBRID___ATOMIC_H */
499 changes: 389 additions & 110 deletions kos/include/hybrid/__bitset.h

Large diffs are not rendered by default.

60 changes: 55 additions & 5 deletions kos/include/hybrid/bitset.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ __DECL_BEGIN
#define _BITSET_WORD_BITS __HYBRID_BITSET_WORD_BITS /* 8: # of bits in a bitset_t-word */
#define _BITSET_WORD_BMSK __HYBRID_BITSET_WORD_BMSK /* 7: # of bits in a bitset_t-word minus 1 */
#define _BITSET_WORD_SHFT __HYBRID_BITSET_WORD_SHFT /* 3: log2(_BITSET_BITS) */
#define _BITSET_BYTE(bitno) __HYBRID_BITSET_BYTE(bitno) /* Index of `bitno' in `bitset_t[]' */
#define _BITSET_WORD(bitno) __HYBRID_BITSET_WORD(bitno) /* Index of `bitno' in `bitset_t[]' */
#define _BITSET_MASK(bitno) __HYBRID_BITSET_MASK(bitno) /* Mask for `bitno' in `bitset_t[]' */
#define BITSET_LENGTHOF(n_bits) __HYBRID_BITSET_LENGTHOF(n_bits) /* Length of `bitset_t[]' for `n_bits' bits */
#define BITSET_SIZEOF(n_bits) __HYBRID_BITSET_SIZEOF(n_bits) /* Size (in bytes) of `bitset_t[]' for `n_bits' bits */
Expand Down Expand Up @@ -85,6 +85,30 @@ __ATTR_PURE __ATTR_WUNUSED __ATTR_NONNULL((1)) __SIZE_TYPE__ bitset_ffc(bitset_t
* its index. If no such bit exists, return some value `>= n_bits'. */
__ATTR_PURE __ATTR_WUNUSED __ATTR_NONNULL((1)) __SIZE_TYPE__ bitset_ffs(bitset_t const *self, __SIZE_TYPE__ n_bits);

/* Find the last bitno within [0, n_bits) that is off and return
* its index. If no such bit exists, return some value `>= n_bits'. */
__ATTR_PURE __ATTR_WUNUSED __ATTR_NONNULL((1)) __SIZE_TYPE__ bitset_flc(bitset_t const *self, __SIZE_TYPE__ n_bits);

/* Find the last bitno within [0, n_bits) that is on and return
* its index. If no such bit exists, return some value `>= n_bits'. */
__ATTR_PURE __ATTR_WUNUSED __ATTR_NONNULL((1)) __SIZE_TYPE__ bitset_fls(bitset_t const *self, __SIZE_TYPE__ n_bits);

/* Find the first bitno within [minbitno,maxbitno] that is on and return
* its index. If no such bit exists, return some value `> maxbitno'. */
__ATTR_PURE __ATTR_WUNUSED __ATTR_NONNULL((1)) __SIZE_TYPE__ bitset_nffs(bitset_t const *self, __SIZE_TYPE__ minbitno, __SIZE_TYPE__ maxbitno);

/* Find the first bitno within [minbitno,maxbitno] that is off and return
* its index. If no such bit exists, return some value `> maxbitno'. */
__ATTR_PURE __ATTR_WUNUSED __ATTR_NONNULL((1)) __SIZE_TYPE__ bitset_nffc(bitset_t const *self, __SIZE_TYPE__ minbitno, __SIZE_TYPE__ maxbitno);

/* Find the last bitno within [minbitno,maxbitno] that is on and return
* its index. If no such bit exists, return some value `> maxbitno'. */
__ATTR_PURE __ATTR_WUNUSED __ATTR_NONNULL((1)) __SIZE_TYPE__ bitset_nfls(bitset_t const *self, __SIZE_TYPE__ minbitno, __SIZE_TYPE__ maxbitno);

/* Find the last bitno within [minbitno,maxbitno] that is off and return
* its index. If no such bit exists, return some value `> maxbitno'. */
__ATTR_PURE __ATTR_WUNUSED __ATTR_NONNULL((1)) __SIZE_TYPE__ bitset_nflc(bitset_t const *self, __SIZE_TYPE__ minbitno, __SIZE_TYPE__ maxbitno);

/* Check if the bitset contains any 1-elements */
__ATTR_PURE __ATTR_WUNUSED __ATTR_NONNULL((1)) __BOOL bitset_anyset(bitset_t const *self, __SIZE_TYPE__ n_bits);

Expand All @@ -103,11 +127,17 @@ __ATTR_PURE __ATTR_WUNUSED __ATTR_NONNULL((1)) __SIZE_TYPE__ bitset_popcount(bit
/* Returns the # of 1-bits within the given range */
__ATTR_PURE __ATTR_WUNUSED __ATTR_NONNULL((1)) __SIZE_TYPE__ bitset_npopcount(bitset_t const *self, __SIZE_TYPE__ minbitno, __SIZE_TYPE__ maxbitno);

/* Count-leading-zeroes (undefined when `self' doesn't contain any set bits) */
__ATTR_PURE __ATTR_WUNUSED __ATTR_NONNULL((1)) __SIZE_TYPE__ bitset_clz(bitset_t const *__restrict self);
/* Count-leading-zeroes (returns ">= n_bits" when `self' doesn't contain any set bits) */
__ATTR_PURE __ATTR_WUNUSED __ATTR_NONNULL((1)) __SIZE_TYPE__ bitset_clz(bitset_t const *__restrict self, __SIZE_TYPE__ n_bits);

/* Count-trailing-zeroes (undefined when `self' doesn't contain any set bits) */
/* Count-trailing-zeroes (returns ">= n_bits" when `self' doesn't contain any set bits) */
__ATTR_PURE __ATTR_WUNUSED __ATTR_NONNULL((1)) __SIZE_TYPE__ bitset_ctz(bitset_t const *__restrict self, __SIZE_TYPE__ n_bits);

/* Count-leading-zeroes (hard undefined behavior when `self' doesn't contain any set bits) */
__ATTR_PURE __ATTR_WUNUSED __ATTR_NONNULL((1)) __SIZE_TYPE__ bitset_rawclz(bitset_t const *__restrict self, __SIZE_TYPE__ n_bits);

/* Count-trailing-zeroes (hard undefined behavior when `self' doesn't contain any set bits) */
__ATTR_PURE __ATTR_WUNUSED __ATTR_NONNULL((1)) __SIZE_TYPE__ bitset_rawctz(bitset_t const *__restrict self);
#else /* __INTELLISENSE__ */
#define bitset_t __hybrid_bitset_t
#define bitset_test(self, bitno) __hybrid_bitset_test(self, bitno)
Expand All @@ -123,14 +153,22 @@ __ATTR_PURE __ATTR_WUNUSED __ATTR_NONNULL((1)) __SIZE_TYPE__ bitset_ctz(bitset_t
#define bitset_ffs_i(self, n_bits, p_value) __hybrid_bitset_ffs_i(self, n_bits, p_value)
#define bitset_ffc(self, n_bits) __hybrid_bitset_ffc(self, n_bits)
#define bitset_ffs(self, n_bits) __hybrid_bitset_ffs(self, n_bits)
#define bitset_flc(self, n_bits) __hybrid_bitset_flc(self, n_bits)
#define bitset_fls(self, n_bits) __hybrid_bitset_fls(self, n_bits)
#define bitset_nffc(self, minbitno, maxbitno) __hybrid_bitset_nffc(self, minbitno, maxbitno)
#define bitset_nffs(self, minbitno, maxbitno) __hybrid_bitset_nffs(self, minbitno, maxbitno)
#define bitset_nflc(self, minbitno, maxbitno) __hybrid_bitset_nflc(self, minbitno, maxbitno)
#define bitset_nfls(self, minbitno, maxbitno) __hybrid_bitset_nfls(self, minbitno, maxbitno)
#define bitset_anyset(self, n_bits) __hybrid_bitset_anyset(self, n_bits)
#define bitset_allset(self, n_bits) __hybrid_bitset_allset(self, n_bits)
#define bitset_nanyset(self, minbitno, maxbitno) __hybrid_bitset_nanyset(self, minbitno, maxbitno)
#define bitset_nallset(self, minbitno, maxbitno) __hybrid_bitset_nallset(self, minbitno, maxbitno)
#define bitset_popcount(self, n_bits) __hybrid_bitset_popcount(self, n_bits)
#define bitset_npopcount(self, minbitno, maxbitno) __hybrid_bitset_npopcount(self, minbitno, maxbitno)
#define bitset_clz(self) __hybrid_bitset_clz(self)
#define bitset_clz(self, n_bits) __hybrid_bitset_clz(self, n_bits)
#define bitset_ctz(self, n_bits) __hybrid_bitset_ctz(self, n_bits)
#define bitset_rawclz(self, n_bits) __hybrid_bitset_rawclz(self, n_bits)
#define bitset_rawctz(self) __hybrid_bitset_rawctz(self)
#endif /* !__INTELLISENSE__ */

/* >> size_t bitno;
Expand All @@ -141,6 +179,18 @@ __ATTR_PURE __ATTR_WUNUSED __ATTR_NONNULL((1)) __SIZE_TYPE__ bitset_ctz(bitset_t
* >> } */
#define bitset_foreach(bitno, self, n_bits) \
__hybrid_bitset_foreach(bitno, self, n_bits)
#define bitset_nforeach(bitno, self, minbitno, maxbitno) \
__hybrid_bitset_nforeach(bitno, self, minbitno, maxbitno)

/* Atomic bitset operations. */
#ifdef __GUARD_HYBRID___ATOMIC_H
#define bitset_atomic_set(self, bitno) __hybrid_bitset_atomic_set(self, bitno)
#define bitset_atomic_clear(self, bitno) __hybrid_bitset_atomic_clear(self, bitno)
#define bitset_atomic_flip(self, bitno) __hybrid_bitset_atomic_flip(self, bitno)
#define bitset_atomic_fetchset(self, bitno) __hybrid_bitset_atomic_fetchset(self, bitno)
#define bitset_atomic_fetchclear(self, bitno) __hybrid_bitset_atomic_fetchclear(self, bitno)
#define bitset_atomic_fetchflip(self, bitno) __hybrid_bitset_atomic_fetchflip(self, bitno)
#endif /* __GUARD_HYBRID___ATOMIC_H */

__DECL_END
#endif /* __CC__ */
Expand Down
4 changes: 2 additions & 2 deletions kos/include/sys/bitstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ __NOTHROW_NCX(__PRIVATE_bit_ffs)(bitstr_t const *__restrict __self, __SIZE_TYPE_
#define bit_popcount(self, nbits) __hybrid_bitset_popcount(self, nbits)

/* Count-leading-zeroes (undefined when `self' doesn't contain any set bits) */
#define bit_clz(self) (unsigned int)__hybrid_bitset_clz(self)
#define bit_clz(self, nbits) (unsigned int)__hybrid_bitset_rawclz(self, nbits)

/* Count-trailing-zeroes (undefined when `self' doesn't contain any set bits) */
#define bit_ctz(self, nbits) (unsigned int)__hybrid_bitset_ctz(self, nbits)
#define bit_ctz(self) (unsigned int)__hybrid_bitset_rawctz(self)
#endif /* __USE_KOS */

__DECL_END
Expand Down
5 changes: 5 additions & 0 deletions kos/src/_verify/include-everything.h
Original file line number Diff line number Diff line change
Expand Up @@ -694,12 +694,14 @@ incdir("");
#include <hybrid/__atomic.h>
#include <hybrid/__bit.h>
#include <hybrid/__bitfield.h>
#include <hybrid/__bitset.h>
#include <hybrid/__byteswap.h>
#include <hybrid/__debug-alignment.h>
#include <hybrid/__minmax.h>
#include <hybrid/__overflow.h>
#include <hybrid/__pointer.h>
#include <hybrid/__rotate.h>
#include <hybrid/__string.h>
#include <hybrid/__unaligned.h>
#include <hybrid/__va_size.h>
#include <hybrid/__wordbits.h>
Expand All @@ -708,6 +710,7 @@ incdir("");
#include <hybrid/altint.h>
#include <hybrid/atomic.h>
#include <hybrid/bit.h>
#include <hybrid/bitset.h>
#include <hybrid/byteorder.h>
#include <hybrid/byteswap.h>
#include <hybrid/compiler.h>
Expand Down Expand Up @@ -767,6 +770,8 @@ incdir("");
#include <kos/bits/debugtrap.h>
#include <kos/bits/except-compiler.h>
#include <kos/bits/except-handler.h>
#include <kos/bits/except-register-state-helpers.h>
#include <kos/bits/except-register-state.h>
#include <kos/bits/except.h>
#include <kos/bits/exception_data.h>
#include <kos/bits/exception_info.h>
Expand Down
2 changes: 1 addition & 1 deletion kos/src/libregex
Submodule libregex updated 1 files
+2 −2 regcomp.c

0 comments on commit 9f0679a

Please sign in to comment.