Compare commits
4 Commits
7bba3c559b
...
0dcca10559
Author | SHA1 | Date | |
---|---|---|---|
0dcca10559 | |||
b63a5cceda | |||
2bab5c9d2c | |||
a41ca50404 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,5 +1,8 @@
|
|||||||
compile_commands.json
|
compile_commands.json
|
||||||
core
|
core
|
||||||
|
/.ccls-cache/
|
||||||
|
/test/test/
|
||||||
|
/test/cutest/
|
||||||
# created when building
|
# created when building
|
||||||
/bin/
|
/bin/
|
||||||
/obj/
|
/obj/
|
||||||
|
21
Makefile
21
Makefile
@@ -1,6 +1,6 @@
|
|||||||
# brlib Makefile - GNU make only
|
# brlib Makefile - GNU make only
|
||||||
#
|
#
|
||||||
# Copyright (C) 2021-2023 Bruno Raoult ("br")
|
# Copyright (C) 2021-2024 Bruno Raoult ("br")
|
||||||
# Licensed under the GNU General Public License v3.0 or later.
|
# Licensed under the GNU General Public License v3.0 or later.
|
||||||
# Some rights reserved. See COPYING.
|
# Some rights reserved. See COPYING.
|
||||||
#
|
#
|
||||||
@@ -38,8 +38,8 @@ DLIB := $(addsuffix .so, $(LIBDIR)/lib$(LIB)) # dynamic lib
|
|||||||
DEP_FN := $(SRC_FN) $(LIBSRC_FN)
|
DEP_FN := $(SRC_FN) $(LIBSRC_FN)
|
||||||
DEP := $(addprefix $(DEPDIR)/,$(DEP_FN:.c=.d))
|
DEP := $(addprefix $(DEPDIR)/,$(DEP_FN:.c=.d))
|
||||||
|
|
||||||
TESTSRC := $(wildcard $(TESTDIR)/*.c)
|
TEST := $(wildcard $(TESTDIR)/*.c)
|
||||||
TEST_FN := $(notdir $(TESTSRC))
|
TEST_FN := $(notdir $(TEST))
|
||||||
BIN := $(addprefix $(BINDIR)/,$(TEST_FN:.c=))
|
BIN := $(addprefix $(BINDIR)/,$(TEST_FN:.c=))
|
||||||
|
|
||||||
##################################### emacs projectile/ccls dirs & files
|
##################################### emacs projectile/ccls dirs & files
|
||||||
@@ -80,16 +80,17 @@ CFLAGS := $(strip $(CFLAGS))
|
|||||||
##################################### archiver/linker/dependency flags
|
##################################### archiver/linker/dependency flags
|
||||||
ARFLAGS := rcs
|
ARFLAGS := rcs
|
||||||
LDFLAGS := -L$(LIBDIR)
|
LDFLAGS := -L$(LIBDIR)
|
||||||
|
LIBS := -l$(LIB)
|
||||||
DEPFLAGS = -MMD -MP -MF $(DEPDIR)/$*.d
|
DEPFLAGS = -MMD -MP -MF $(DEPDIR)/$*.d
|
||||||
|
|
||||||
##################################### General targets
|
##################################### General targets
|
||||||
.PHONY: all compile clean cleanall cleanallall
|
.PHONY: all compile test clean cleanall cleanallall ccls bear
|
||||||
|
|
||||||
all: libs
|
all: libs
|
||||||
|
|
||||||
compile: objs
|
compile: objs
|
||||||
|
|
||||||
test: testbins
|
test: tests
|
||||||
|
|
||||||
clean: cleandep cleanobj cleanlib cleanbin
|
clean: cleandep cleanobj cleanlib cleanbin
|
||||||
|
|
||||||
@@ -100,7 +101,7 @@ cleanallall: cleanall cleanemacs
|
|||||||
# setup emacs projectile/ccls
|
# setup emacs projectile/ccls
|
||||||
emacs: emacs-setup
|
emacs: emacs-setup
|
||||||
# update compile-commands.json
|
# update compile-commands.json
|
||||||
ccls: $(CCLSCMDS)
|
ccls bear: $(CCLSCMDS)
|
||||||
|
|
||||||
##################################### cleaning functions
|
##################################### cleaning functions
|
||||||
# rmfiles - deletes a list of files in a directory if they exist.
|
# rmfiles - deletes a list of files in a directory if they exist.
|
||||||
@@ -205,10 +206,9 @@ $(SLIB): $(OBJ) | $(LIBDIR)
|
|||||||
@$(AR) $(ARFLAGS) $@ $? > /dev/null
|
@$(AR) $(ARFLAGS) $@ $? > /dev/null
|
||||||
|
|
||||||
##################################### tests
|
##################################### tests
|
||||||
.PHONY: testbins cleanbin cleanbindir
|
.PHONY: tests cleanbin cleanbindir
|
||||||
|
|
||||||
testbins: $(BIN)
|
tests: libs $(BIN)
|
||||||
echo $^
|
|
||||||
|
|
||||||
cleanbin:
|
cleanbin:
|
||||||
$(call rmfiles,$(TARGET),binary)
|
$(call rmfiles,$(TARGET),binary)
|
||||||
@@ -216,6 +216,9 @@ cleanbin:
|
|||||||
cleanbindir:
|
cleanbindir:
|
||||||
$(call rmdir,$(BINDIR),binaries)
|
$(call rmdir,$(BINDIR),binaries)
|
||||||
|
|
||||||
|
$(BINDIR)/%: $(TESTDIR)/%.c | $(BINDIR)
|
||||||
|
$(CC) $(CPPFLAGS) $(CFLAGS) $< $(LDFLAGS) $(LIBS) -o $@
|
||||||
|
|
||||||
##################################### pre-processed (.i) and assembler (.s) output
|
##################################### pre-processed (.i) and assembler (.s) output
|
||||||
%.i: %.c
|
%.i: %.c
|
||||||
@echo generating $@
|
@echo generating $@
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/* bits.h - bits functions.
|
/* bitops.h - bits functions.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2021-2022 Bruno Raoult ("br")
|
* Copyright (C) 2021-2024 Bruno Raoult ("br")
|
||||||
* Licensed under the GNU General Public License v3.0 or later.
|
* Licensed under the GNU General Public License v3.0 or later.
|
||||||
* Some rights reserved. See COPYING.
|
* Some rights reserved. See COPYING.
|
||||||
*
|
*
|
||||||
@@ -44,6 +44,26 @@ void print_bitops_impl(void);
|
|||||||
/* count set bits: 10101000 -> 3
|
/* count set bits: 10101000 -> 3
|
||||||
* ^ ^ ^
|
* ^ ^ ^
|
||||||
*/
|
*/
|
||||||
|
#if __has_builtin(__builtin_popcountll)
|
||||||
|
#define ___popcount64_native(n) __builtin_popcountll(n)
|
||||||
|
#endif
|
||||||
|
#if __has_builtin(__builtin_popcount)
|
||||||
|
#define ___popcount32_native(n) __builtin_popcount(n)
|
||||||
|
#endif
|
||||||
|
#define ___popcount_emulated(n) ({ \
|
||||||
|
int ___count = 0; \
|
||||||
|
while (n) { \
|
||||||
|
___count++; \
|
||||||
|
n &= (n - 1); \
|
||||||
|
} \
|
||||||
|
___count; })
|
||||||
|
|
||||||
|
#ifdef ___popcount64_native
|
||||||
|
#define ppcount64(n) ___popcount64_native(n)
|
||||||
|
#else
|
||||||
|
#define ppcount64(n) ___popcount_emulated(n)
|
||||||
|
#endif
|
||||||
|
|
||||||
static __always_inline int popcount64(u64 n)
|
static __always_inline int popcount64(u64 n)
|
||||||
{
|
{
|
||||||
# if __has_builtin(__builtin_popcountll)
|
# if __has_builtin(__builtin_popcountll)
|
@@ -1,6 +1,6 @@
|
|||||||
/* br.h - misc macros.
|
/* br.h - misc macros.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2021-2022 Bruno Raoult ("br")
|
* Copyright (C) 2021-2024 Bruno Raoult ("br")
|
||||||
* Licensed under the GNU General Public License v3.0 or later.
|
* Licensed under the GNU General Public License v3.0 or later.
|
||||||
* Some rights reserved. See COPYING.
|
* Some rights reserved. See COPYING.
|
||||||
*
|
*
|
||||||
|
@@ -20,9 +20,6 @@
|
|||||||
* can somehow continue operating, perhaps with reduced functionality,
|
* can somehow continue operating, perhaps with reduced functionality,
|
||||||
* it's probably not BUG-worthy.
|
* it's probably not BUG-worthy.
|
||||||
*
|
*
|
||||||
* If you're tempted to BUG(), think again: is completely giving up
|
|
||||||
* really the *only* solution? There are usually better options, where
|
|
||||||
* users don't need to reboot ASAP and can mostly shut down cleanly.
|
|
||||||
*/
|
*/
|
||||||
#define BUG() do { \
|
#define BUG() do { \
|
||||||
fprintf(stderr, "BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
|
fprintf(stderr, "BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
|
||||||
@@ -32,9 +29,8 @@
|
|||||||
#define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)
|
#define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* WARN(), WARN_ON(), WARN_ON_ONCE, and so on can be used to report
|
* WARN(), WARN_ON(), WARN_ON_ONCE, and so on can be used to report significant
|
||||||
* significant kernel issues that need prompt attention if they should ever
|
* issues that need prompt attention if they should ever appear at runtime.
|
||||||
* appear at runtime.
|
|
||||||
*
|
*
|
||||||
* Do not use these macros when checking for invalid external inputs
|
* Do not use these macros when checking for invalid external inputs
|
||||||
* (e.g. invalid system call arguments, or invalid data coming from
|
* (e.g. invalid system call arguments, or invalid data coming from
|
||||||
@@ -50,6 +46,7 @@
|
|||||||
#define __WARN() do { \
|
#define __WARN() do { \
|
||||||
fprintf(stderr, "WARNING: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
|
fprintf(stderr, "WARNING: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define __WARN_printf(arg...) do { \
|
#define __WARN_printf(arg...) do { \
|
||||||
vfprintf(stderr, arg); \
|
vfprintf(stderr, arg); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/* debug.h - debug/log management.
|
/* debug.h - debug/log management.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2021-2023 Bruno Raoult ("br")
|
* Copyright (C) 2021-2024 Bruno Raoult ("br")
|
||||||
* Licensed under the GNU General Public License v3.0 or later.
|
* Licensed under the GNU General Public License v3.0 or later.
|
||||||
* Some rights reserved. See COPYING.
|
* Some rights reserved. See COPYING.
|
||||||
*
|
*
|
||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#include <br.h>
|
#include <br.h>
|
||||||
|
|
||||||
@@ -27,12 +26,64 @@
|
|||||||
|
|
||||||
#ifdef DEBUG_DEBUG
|
#ifdef DEBUG_DEBUG
|
||||||
|
|
||||||
void debug_init(int level, FILE *stream, bool flush);
|
/**
|
||||||
|
* debug_level_set - get debug level.
|
||||||
|
* @level: integer debug level.
|
||||||
|
*
|
||||||
|
* @Return: void.
|
||||||
|
*/
|
||||||
void debug_level_set(int level);
|
void debug_level_set(int level);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* debug_level_get - get debug level.
|
||||||
|
*
|
||||||
|
* @Return: current level debug (integer).
|
||||||
|
*/
|
||||||
int debug_level_get(void);
|
int debug_level_get(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* debug_stream_set - set debug output stream.
|
||||||
|
* @stream: (FILE *) output stream
|
||||||
|
*
|
||||||
|
* @Return: void.
|
||||||
|
*/
|
||||||
void debug_stream_set(FILE *stream);
|
void debug_stream_set(FILE *stream);
|
||||||
long long debug_timer_elapsed(void);
|
|
||||||
|
/**
|
||||||
|
* debug_flush_set - set debug flush option.
|
||||||
|
* @flush: boolean, if true, flush after each output.
|
||||||
|
*
|
||||||
|
* @Return: void.
|
||||||
|
*/
|
||||||
void debug_flush_set(bool flush);
|
void debug_flush_set(bool flush);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* debug_init - init debug module.
|
||||||
|
* @level: debug level (integer).
|
||||||
|
* @stream: (FILE *) output stream
|
||||||
|
* @flush: boolean, if true, flush after each output.
|
||||||
|
*
|
||||||
|
* @Return: void.
|
||||||
|
*/
|
||||||
|
void debug_init(int level, FILE *stream, bool flush);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* debug_timer_elapsed - get current elapsed debug timer value.
|
||||||
|
*
|
||||||
|
* @Return: long long, timer elapsed.
|
||||||
|
*/
|
||||||
|
long long debug_timer_elapsed(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* debug - log function.
|
||||||
|
* @level: log level
|
||||||
|
* @timestamp: boolean, print timestamp if true
|
||||||
|
* @indent: indent level (2 spaces each)
|
||||||
|
* @src: source file/func name (or NULL)
|
||||||
|
* @line: line number
|
||||||
|
*
|
||||||
|
* @Return: void.
|
||||||
|
*/
|
||||||
void _printf debug(int level, bool timestamp,
|
void _printf debug(int level, bool timestamp,
|
||||||
int indent, const char *src,
|
int indent, const char *src,
|
||||||
int line, const char *fmt, ...);
|
int line, const char *fmt, ...);
|
||||||
|
@@ -9,8 +9,9 @@
|
|||||||
(C) 2002 Nadia Yvette Chambers, IBM */
|
(C) 2002 Nadia Yvette Chambers, IBM */
|
||||||
|
|
||||||
#include <asm/bitsperlong.h>
|
#include <asm/bitsperlong.h>
|
||||||
#include "bits.h"
|
|
||||||
#include "br.h"
|
#include "br.h"
|
||||||
|
#include "bitops.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The "GOLDEN_RATIO_PRIME" is used in ifs/btrfs/brtfs_inode.h and
|
* The "GOLDEN_RATIO_PRIME" is used in ifs/btrfs/brtfs_inode.h and
|
||||||
|
@@ -7,8 +7,6 @@
|
|||||||
#ifndef _BR_LIST_SORT_H
|
#ifndef _BR_LIST_SORT_H
|
||||||
#define _BR_LIST_SORT_H
|
#define _BR_LIST_SORT_H
|
||||||
|
|
||||||
//#include <linux/types.h>
|
|
||||||
|
|
||||||
struct list_head;
|
struct list_head;
|
||||||
|
|
||||||
typedef int __attribute__((nonnull(2,3))) (*list_cmp_func_t)(void *,
|
typedef int __attribute__((nonnull(2,3))) (*list_cmp_func_t)(void *,
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/* pjwhash-inline.h - PJW hash function, inline version.
|
/* pjwhash-inline.h - PJW hash function, inline version.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2021-2022 Bruno Raoult ("br")
|
* Copyright (C) 2021-2024 Bruno Raoult ("br")
|
||||||
* Licensed under the GNU General Public License v3.0 or later.
|
* Licensed under the GNU General Public License v3.0 or later.
|
||||||
* Some rights reserved. See COPYING.
|
* Some rights reserved. See COPYING.
|
||||||
*
|
*
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
#ifndef _PJWHASH_INLINE_H
|
#ifndef _PJWHASH_INLINE_H
|
||||||
#define _PJWHASH_INLINE_H
|
#define _PJWHASH_INLINE_H
|
||||||
|
|
||||||
#include "bits.h"
|
#include "br.h"
|
||||||
|
|
||||||
#define THREE_QUARTERS ((int) ((BITS_PER_INT * 3) / 4))
|
#define THREE_QUARTERS ((int) ((BITS_PER_INT * 3) / 4))
|
||||||
#define ONE_EIGHTH ((int) (BITS_PER_INT / 8))
|
#define ONE_EIGHTH ((int) (BITS_PER_INT / 8))
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/* pjwhash.h - PJW hash function, extern version.
|
/* pjwhash.h - PJW hash function, extern version.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2021-2022 Bruno Raoult ("br")
|
* Copyright (C) 2021-2024 Bruno Raoult ("br")
|
||||||
* Licensed under the GNU General Public License v3.0 or later.
|
* Licensed under the GNU General Public License v3.0 or later.
|
||||||
* Some rights reserved. See COPYING.
|
* Some rights reserved. See COPYING.
|
||||||
*
|
*
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
#ifndef _PJWHASH_H
|
#ifndef _PJWHASH_H
|
||||||
#define _PJWHASH_H
|
#define _PJWHASH_H
|
||||||
|
|
||||||
#include "bits.h"
|
#include "br.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* unsigned int pjwhash - PJW hash function
|
* unsigned int pjwhash - PJW hash function
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/* pool.h - A simple memory pool manager.
|
/* pool.h - A simple memory pool manager.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2021-2022 Bruno Raoult ("br")
|
* Copyright (C) 2021-2024 Bruno Raoult ("br")
|
||||||
* Licensed under the GNU General Public License v3.0 or later.
|
* Licensed under the GNU General Public License v3.0 or later.
|
||||||
* Some rights reserved. See COPYING.
|
* Some rights reserved. See COPYING.
|
||||||
*
|
*
|
||||||
@@ -16,8 +16,9 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include "br.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "bits.h"
|
|
||||||
|
|
||||||
#define POOL_NAME_LENGTH (16) /* max name length including trailing \0 */
|
#define POOL_NAME_LENGTH (16) /* max name length including trailing \0 */
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/* struct-group.h - mirrored structure macros.
|
/* struct-group.h - mirrored structure macros.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2021-2022 Bruno Raoult ("br")
|
* Copyright (C) 2021-2024 Bruno Raoult ("br")
|
||||||
* Licensed under the GNU General Public License v3.0 or later.
|
* Licensed under the GNU General Public License v3.0 or later.
|
||||||
* Some rights reserved. See COPYING.
|
* Some rights reserved. See COPYING.
|
||||||
*
|
*
|
||||||
|
30
scripts/env.sh
Executable file
30
scripts/env.sh
Executable file
@@ -0,0 +1,30 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# env.sh - set environment for brchess developer.
|
||||||
|
#
|
||||||
|
# Copyright (C) 2023 Bruno Raoult ("br")
|
||||||
|
# Licensed under the GNU General Public License v3.0 or later.
|
||||||
|
# Some rights reserved. See COPYING.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License along with this
|
||||||
|
# program. If not, see <https://www.gnu.org/licenses/gpl-3.0-standalone.html>.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later <https://spdx.org/licenses/GPL-3.0-or-later.html>
|
||||||
|
#
|
||||||
|
# USAGE: source env.sh [arg]
|
||||||
|
#
|
||||||
|
# This file will actually be sourced if it was never sourced in current bash
|
||||||
|
# environment.
|
||||||
|
|
||||||
|
if [[ ! -v _BRLIB_ENV_ ]]; then
|
||||||
|
export _BRLIB_ENV_=1 BRLIB_ROOT LD_LIBRARY_PATH
|
||||||
|
BRLIB_SCRIPTDIR=$(realpath -L "$(dirname "${BASH_SOURCE[0]}")")
|
||||||
|
BRLIB_ROOT=$(realpath -L "$(dirname "${BASH_SOURCE[0]}")/..")
|
||||||
|
BRLIB_LIBDIR="$BRLIB_ROOT/lib"
|
||||||
|
BRLIB_BINDIR="$BRLIB_ROOT/bin"
|
||||||
|
LD_LIBRARY_PATH="${BRLIB_LIBDIR}${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
|
||||||
|
PATH="$PATH:$BRLIB_BINDIR:$BRLIB_SCRIPTDIR"
|
||||||
|
#printf "R=%s L=%s LD=%s\n" "$BRLIB_ROOT" "$BRLIB_DIR" "$LD_LIBRARY_PATH"
|
||||||
|
unset BRLIB_LIBDIR BRLIB_BINDIR BRLIB_SCRIPTDIR
|
||||||
|
printf "brlib environment complete.\n"
|
||||||
|
fi
|
@@ -1,6 +1,6 @@
|
|||||||
/* bits.c - information about bitops implementation.
|
/* bitops.c - information about bitops implementation.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2021-2022 Bruno Raoult ("br")
|
* Copyright (C) 2021-2024 Bruno Raoult ("br")
|
||||||
* Licensed under the GNU General Public License v3.0 or later.
|
* Licensed under the GNU General Public License v3.0 or later.
|
||||||
* Some rights reserved. See COPYING.
|
* Some rights reserved. See COPYING.
|
||||||
*
|
*
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "bits.h"
|
#include "bitops.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
void print_bitops_impl(void)
|
void print_bitops_impl(void)
|
19
src/debug.c
19
src/debug.c
@@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
/* debug.c - debug/log management
|
/* debug.c - debug/log management
|
||||||
*
|
*
|
||||||
* Copyright (C) 2021-2023 Bruno Raoult ("br")
|
* Copyright (C) 2021-2024 Bruno Raoult ("br")
|
||||||
* Licensed under the GNU General Public License v3.0 or later.
|
* Licensed under the GNU General Public License v3.0 or later.
|
||||||
* Some rights reserved. See COPYING.
|
* Some rights reserved. See COPYING.
|
||||||
*
|
*
|
||||||
@@ -26,10 +27,6 @@ static int level = 0; /* output log when < level */
|
|||||||
static int flush = false; /* force flush after logs */
|
static int flush = false; /* force flush after logs */
|
||||||
static FILE *stream = NULL; /* stream to use */
|
static FILE *stream = NULL; /* stream to use */
|
||||||
|
|
||||||
/**
|
|
||||||
* debug_level_set() - set debug level.
|
|
||||||
* @_level: debug level (integer).
|
|
||||||
*/
|
|
||||||
void debug_level_set(int _level)
|
void debug_level_set(int _level)
|
||||||
{
|
{
|
||||||
level = _level;
|
level = _level;
|
||||||
@@ -38,10 +35,6 @@ void debug_level_set(int _level)
|
|||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* debug_level_get() - get debug level.
|
|
||||||
* @return: current level debug (integer).
|
|
||||||
*/
|
|
||||||
int debug_level_get(void)
|
int debug_level_get(void)
|
||||||
{
|
{
|
||||||
return level;
|
return level;
|
||||||
@@ -87,14 +80,6 @@ long long debug_timer_elapsed(void)
|
|||||||
return (timer.tv_sec * NANOSEC + timer.tv_nsec) - timer_start;
|
return (timer.tv_sec * NANOSEC + timer.tv_nsec) - timer_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* debug() - log function
|
|
||||||
* @lev: log level
|
|
||||||
* @timestamp: boolean, print timestamp if true
|
|
||||||
* @indent: indent level (2 spaces each)
|
|
||||||
* @src: source file/func name (or NULL)
|
|
||||||
* @line: line number
|
|
||||||
*/
|
|
||||||
void debug(int lev, bool timestamp, int indent, const char *src,
|
void debug(int lev, bool timestamp, int indent, const char *src,
|
||||||
int line, const char *fmt, ...)
|
int line, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
|
@@ -3,9 +3,9 @@
|
|||||||
/*
|
/*
|
||||||
* Taken from linux kernel: lib/list_sort.c
|
* Taken from linux kernel: lib/list_sort.c
|
||||||
*/
|
*/
|
||||||
|
#include "br.h"
|
||||||
#include "list_sort.h"
|
#include "list_sort.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "bits.h"
|
|
||||||
#include "likely.h"
|
#include "likely.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/* pjwhash.c - PJW hash function.
|
/* pjwhash.c - PJW hash function.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2021-2022 Bruno Raoult ("br")
|
* Copyright (C) 2021-2024 Bruno Raoult ("br")
|
||||||
* Licensed under the GNU General Public License v3.0 or later.
|
* Licensed under the GNU General Public License v3.0 or later.
|
||||||
* Some rights reserved. See COPYING.
|
* Some rights reserved. See COPYING.
|
||||||
*
|
*
|
||||||
@@ -13,8 +13,5 @@
|
|||||||
|
|
||||||
#define _pjw_inline extern
|
#define _pjw_inline extern
|
||||||
|
|
||||||
//#include "bits.h"
|
|
||||||
//extern unsigned int pjwhash (const void* key, uint length);
|
|
||||||
|
|
||||||
#include "pjwhash.h"
|
#include "pjwhash.h"
|
||||||
#include "pjwhash-inline.h"
|
#include "pjwhash-inline.h"
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/* pool.c - A simple pool manager.
|
/* pool.c - A simple pool manager.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2021-2022 Bruno Raoult ("br")
|
* Copyright (C) 2021-2024 Bruno Raoult ("br")
|
||||||
* Licensed under the GNU General Public License v3.0 or later.
|
* Licensed under the GNU General Public License v3.0 or later.
|
||||||
* Some rights reserved. See COPYING.
|
* Some rights reserved. See COPYING.
|
||||||
*
|
*
|
||||||
@@ -17,10 +17,10 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include "br.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "pool.h"
|
#include "pool.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "bits.h"
|
|
||||||
|
|
||||||
void pool_stats(pool_t *pool)
|
void pool_stats(pool_t *pool)
|
||||||
{
|
{
|
||||||
|
46
test/bitops-test.c
Normal file
46
test/bitops-test.c
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
/* bits.c - bitops testing.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2024 Bruno Raoult ("br")
|
||||||
|
* Licensed under the GNU General Public License v3.0 or later.
|
||||||
|
* Some rights reserved. See COPYING.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this
|
||||||
|
* program. If not, see <https://www.gnu.org/licenses/gpl-3.0-standalone.html>.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later <https://spdx.org/licenses/GPL-3.0-or-later.html>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "br.h"
|
||||||
|
#include "bitops.h"
|
||||||
|
// #include "cutest/CuTest.h"
|
||||||
|
|
||||||
|
static void test_popcount()
|
||||||
|
{
|
||||||
|
u32 t32[] = { 0x0, 0x88000101, 0xffffffff };
|
||||||
|
u64 t64[] = { 0x0ll, 0x8880000000000101LL, 0xffffffffffffffffll };
|
||||||
|
|
||||||
|
for (uint i = 0; i < sizeof(t32); ++i) {
|
||||||
|
printf("popcount 32 (%#x): ", t32[i]);
|
||||||
|
# ifdef ___popcount32_native
|
||||||
|
printf("native:%d ", ___popcount32_native(t32[i]));
|
||||||
|
# endif
|
||||||
|
printf("emulated:%d\n", ___popcount_emulated(t32[i]));
|
||||||
|
}
|
||||||
|
for (uint i = 0; i < sizeof(t64); ++i) {
|
||||||
|
printf("popcount 64 (%#lx): ", t64[i]);
|
||||||
|
# ifdef ___popcount64_native
|
||||||
|
printf("native:%d ", ___popcount64_native(t64[i]));
|
||||||
|
# endif
|
||||||
|
printf("emulated:%d\n", ___popcount_emulated(t64[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test_popcount();
|
||||||
|
exit(0);
|
||||||
|
}
|
@@ -1,6 +1,9 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "bits.h"
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "br.h"
|
||||||
#include "pool.h"
|
#include "pool.h"
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
struct d {
|
struct d {
|
||||||
u16 data1;
|
u16 data1;
|
||||||
@@ -19,7 +22,7 @@ int main(int ac, char**av)
|
|||||||
char ccur='z';
|
char ccur='z';
|
||||||
struct d *elt;
|
struct d *elt;
|
||||||
|
|
||||||
debug_init(3);
|
debug_init(3, stderr, true);
|
||||||
log_f(1, "%s: sizeof(d)=%lu sizeof(*d)=%lu off=%lu\n", *av, sizeof(elt),
|
log_f(1, "%s: sizeof(d)=%lu sizeof(*d)=%lu off=%lu\n", *av, sizeof(elt),
|
||||||
sizeof(*elt), offsetof(struct d, list));
|
sizeof(*elt), offsetof(struct d, list));
|
||||||
|
|
Reference in New Issue
Block a user