diff options
| author | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2025-09-10 21:02:24 +0200 |
|---|---|---|
| committer | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2025-09-10 21:02:24 +0200 |
| commit | 3c9538c708bd5833a83d19a266e84503c72b4628 (patch) | |
| tree | a795b13aada7bdce8043cc75a266761396408327 /core | |
| parent | 1c648126c73d01e6bce368bd8a55dbb89f0f2369 (diff) | |
Change the way math/big constants are initialized
Diffstat (limited to 'core')
| -rw-r--r-- | core/math/big/common.odin | 13 | ||||
| -rw-r--r-- | core/math/big/helpers.odin | 19 |
2 files changed, 12 insertions, 20 deletions
diff --git a/core/math/big/common.odin b/core/math/big/common.odin index 5428b00ee..22655293f 100644 --- a/core/math/big/common.odin +++ b/core/math/big/common.odin @@ -15,22 +15,11 @@ import "base:intrinsics" */ /* - ========================== TUNABLES ========================== - - `initialize_constants` returns `#config(MUL_KARATSUBA_CUTOFF, _DEFAULT_MUL_KARATSUBA_CUTOFF)` - and we initialize this cutoff that way so that the procedure is used and called, - because it handles initializing the constants ONE, ZERO, MINUS_ONE, NAN and INF. - - `initialize_constants` also replaces the other `_DEFAULT_*` cutoffs with custom compile-time values if so `#config`ured. - -*/ - -/* There is a bug with DLL globals. They don't get set. To allow tests to run we add `-define:MATH_BIG_EXE=false` to hardcode the cutoffs for now. */ when #config(MATH_BIG_EXE, true) { - MUL_KARATSUBA_CUTOFF := initialize_constants() + MUL_KARATSUBA_CUTOFF := _DEFAULT_MUL_KARATSUBA_CUTOFF SQR_KARATSUBA_CUTOFF := _DEFAULT_SQR_KARATSUBA_CUTOFF MUL_TOOM_CUTOFF := _DEFAULT_MUL_TOOM_CUTOFF SQR_TOOM_CUTOFF := _DEFAULT_SQR_TOOM_CUTOFF diff --git a/core/math/big/helpers.odin b/core/math/big/helpers.odin index 569f0b810..9ee35c45a 100644 --- a/core/math/big/helpers.odin +++ b/core/math/big/helpers.odin @@ -778,13 +778,14 @@ int_from_bytes_little_python :: proc(a: ^Int, buf: []u8, signed := false, alloca */ INT_ONE, INT_ZERO, INT_MINUS_ONE, INT_INF, INT_MINUS_INF, INT_NAN := &Int{}, &Int{}, &Int{}, &Int{}, &Int{}, &Int{} -@(init, private) -_init_constants :: proc "contextless" () { - initialize_constants() -} +@(private) +constant_allocator: runtime.Allocator -initialize_constants :: proc "contextless" () -> (res: int) { +@(init, private) +initialize_constants :: proc "contextless" () { context = runtime.default_context() + constant_allocator = context.allocator + internal_int_set_from_integer( INT_ZERO, 0); INT_ZERO.flags = {.Immutable} internal_int_set_from_integer( INT_ONE, 1); INT_ONE.flags = {.Immutable} internal_int_set_from_integer(INT_MINUS_ONE, -1); INT_MINUS_ONE.flags = {.Immutable} @@ -796,15 +797,17 @@ initialize_constants :: proc "contextless" () -> (res: int) { internal_int_set_from_integer( INT_NAN, 1); INT_NAN.flags = {.Immutable, .NaN} internal_int_set_from_integer( INT_INF, 1); INT_INF.flags = {.Immutable, .Inf} internal_int_set_from_integer(INT_MINUS_INF, -1); INT_MINUS_INF.flags = {.Immutable, .Inf} - - return _DEFAULT_MUL_KARATSUBA_CUTOFF } /* Destroy constants. Optional for an EXE, as this would be called at the very end of a process. */ -destroy_constants :: proc() { +@(fini, private) +destroy_constants :: proc "contextless" () { + context = runtime.default_context() + context.allocator = constant_allocator + internal_destroy(INT_ONE, INT_ZERO, INT_MINUS_ONE, INT_INF, INT_MINUS_INF, INT_NAN) } |