Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ repos:
stages: [manual] # Not automatically triggered, invoked via `pre-commit run --hook-stage manual clang-tidy`

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.22
rev: v0.16.1
hooks:
- id: ruff-check
args: [--fix]
Expand Down
178 changes: 88 additions & 90 deletions deps/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@
def generate_memory_config_header(target, source, env):
header_file_path = Path(str(target[0]))

header = []

header.append("// THIS FILE IS GENERATED. EDITS WILL BE LOST.")
header.append("")

header += """
// Copyright (C) 2015-2025 Jonathan Müller and foonathan/memory contributors
// SPDX-License-Identifier: Zlib

#ifndef FOONATHAN_MEMORY_IMPL_IN_CONFIG_HPP
#error "do not include this file directly, use config.hpp"
#endif

#include <cstddef>

//=== options ===//
// clang-format off
""".split("\n")
header = [
"// THIS FILE IS GENERATED. EDITS WILL BE LOST.",
"",
"",
"// Copyright (C) 2015-2025 Jonathan Müller and foonathan/memory contributors",
"// SPDX-License-Identifier: Zlib",
"",
"#ifndef FOONATHAN_MEMORY_IMPL_IN_CONFIG_HPP",
'#error "do not include this file directly, use config.hpp"',
"#endif",
"",
"#include <cstddef>",
"",
"//=== options ===//",
"// clang-format off",
"",
]

for key, val in env.config_data.items():
if isinstance(val, bool) and val:
Expand All @@ -40,78 +39,77 @@ def generate_memory_config_header(target, source, env):
def generate_memory_container_size_header(target, source, env):
header_file_path = Path(str(target[0]))

header = []

header.append("// THIS FILE IS GENERATED. EDITS WILL BE LOST.")
header.append("")

header += """
namespace detail
{
template <std::size_t Alignment>
struct alignment_type
{
using type = void;
static_assert(Alignment == Alignment);
};

template <>
struct alignment_type<1>
{
using type = char;
static_assert(alignof(type) == 1);
};

template <>
struct alignment_type<2>
{
using type = short;
static_assert(alignof(type) == 2);
};

template <>
struct alignment_type<4>
{
using type = int;
static_assert(alignof(type) == 4);
};

template <>
struct alignment_type<8>
{
using type = std::conditional_t<alignof(long) == 8, long, long double>;
static_assert(alignof(type) == 8);
};

template <>
struct alignment_type<16>
{
using type =
std::conditional_t<alignof(long double) == 16, long double, alignment_type<0>::type>;
};

template <std::size_t Alignment>
using alignment_type_t = alignment_type<Alignment>::type;

template <typename InitialType, typename T, bool SubtractTSize = true>
static consteval std::size_t calculate_node_size_by_type()
{
static_assert(!std::is_same<InitialType, T>::value && (sizeof(InitialType) != sizeof(T)));
static_assert(sizeof(T) > sizeof(InitialType));

return sizeof(T) - (SubtractTSize ? sizeof(InitialType) : 0);
}

template <std::size_t Alignment, typename T, bool SubtractTSize = true>
static consteval std::size_t calculate_node_size()
{
return calculate_node_size_by_type<alignment_type_t<Alignment>, T, SubtractTSize>();
}

template <std::size_t Alignment>
using allocator_type = std::allocator<alignment_type_t<Alignment>>;
}
""".split("\n")
header = [
"// THIS FILE IS GENERATED. EDITS WILL BE LOST.",
"",
"",
"namespace detail",
"{",
" template <std::size_t Alignment>",
" struct alignment_type",
" {",
" using type = void;",
" static_assert(Alignment == Alignment);",
" };",
"",
" template <>",
" struct alignment_type<1>",
" {",
" using type = char;",
" static_assert(alignof(type) == 1);",
" };",
"",
" template <>",
" struct alignment_type<2>",
" {",
" using type = short;",
" static_assert(alignof(type) == 2);",
" };",
"",
" template <>",
" struct alignment_type<4>",
" {",
" using type = int;",
" static_assert(alignof(type) == 4);",
" };",
"",
" template <>",
" struct alignment_type<8>",
" {",
" using type = std::conditional_t<alignof(long) == 8, long, long double>;",
" static_assert(alignof(type) == 8);",
" };",
"",
" template <>",
" struct alignment_type<16>",
" {",
" using type =",
" std::conditional_t<alignof(long double) == 16, long double, alignment_type<0>::type>;",
" };",
"",
" template <std::size_t Alignment>",
" using alignment_type_t = alignment_type<Alignment>::type;",
"",
" template <typename InitialType, typename T, bool SubtractTSize = true>",
" static consteval std::size_t calculate_node_size_by_type()",
" {",
" static_assert(!std::is_same<InitialType, T>::value && (sizeof(InitialType) != sizeof(T)));",
" static_assert(sizeof(T) > sizeof(InitialType));",
"",
" return sizeof(T) - (SubtractTSize ? sizeof(InitialType) : 0);",
" }",
"",
" template <std::size_t Alignment, typename T, bool SubtractTSize = true>",
" static consteval std::size_t calculate_node_size()",
" {",
" return calculate_node_size_by_type<alignment_type_t<Alignment>, T, SubtractTSize>();",
" }",
"",
" template <std::size_t Alignment>",
" using allocator_type = std::allocator<alignment_type_t<Alignment>>;",
"}",
"",
]

containers = {
"forward_list": [
Expand Down
10 changes: 5 additions & 5 deletions misc/scripts/exp_lut_generator.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python
import decimal
import os
import sys
from argparse import ArgumentParser
from math import e
from typing import List

BIT_COUNT = 64
MAX_VALUE = 2**BIT_COUNT
Expand All @@ -16,17 +16,17 @@
def generate_exp_lut(divisor_base: int, divisor_power: int, exp_base: decimal.Decimal):
divisor: int = divisor_base**divisor_power

exp_lut: List[int] = []
exp_lut: list[int] = []

for index in range(BIT_COUNT):
exponent: decimal.Decimal = (2**index) / divisor
value: int = int(decimal.Decimal(exp_base**exponent) * decimal.Decimal(divisor) + decimal.Decimal(0.5))
value: int = int(decimal.Decimal(exp_base**exponent) * decimal.Decimal(divisor) + decimal.Decimal("0.5"))
if value > MAX_VALUE:
break
exp_lut.append(value)

lut_identifier: str = (
f"{divisor_base}_{divisor_power}_EXP_{'e' if exp_base == e else ('%g' % exp_base).replace('.', 'p')}"
f"{divisor_base}_{divisor_power}_EXP_{'e' if exp_base == e else f'{exp_base:g}'.replace('.', 'p')}"
)
lut_size: int = len(exp_lut)

Expand Down Expand Up @@ -115,4 +115,4 @@ def generate_exp_lut(divisor_base: int, divisor_power: int, exp_base: decimal.De
args = parser.parse_args()

generate_exp_lut(args.base, args.power, args.exp)
exit(0)
sys.exit(0)
7 changes: 4 additions & 3 deletions misc/scripts/sin_lut_generator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
import decimal
import os
import sys
from argparse import ArgumentParser

DEFAULT_PRECISION = 16
Expand Down Expand Up @@ -71,7 +72,7 @@ def generate_sin_lut(precision: int, count_log2: int):
sin_value: decimal.Decimal = decimal_sin(angle) # sin(angle)
moved_sin: decimal.Decimal = sin_value * one
rounded_sin: int = (
int(moved_sin + decimal.Decimal(0.5)) if moved_sin > 0 else int(moved_sin - decimal.Decimal(0.5))
int(moved_sin + decimal.Decimal("0.5")) if moved_sin > 0 else int(moved_sin - decimal.Decimal("0.5"))
)
SinLut.append(rounded_sin)

Expand Down Expand Up @@ -149,7 +150,7 @@ def generate_sin_lut(precision: int, count_log2: int):

if args.precision < args.count:
print("ERROR: invalid count ", args.count, " - can't be greater than precision (", args.precision, ")")
exit(-1)
sys.exit(-1)
else:
generate_sin_lut(args.precision, args.count)
exit(0)
sys.exit(0)