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

Replace floating point sizing formula in stack with integer operations. #1321

Merged
merged 2 commits into from
Jul 5, 2023
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
5 changes: 0 additions & 5 deletions lib/fft.dx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ def odd_sized_palindrome(mid:a, seq:n=>a) -> ((n `Either` () `Either` n)=>a) giv
Right () -> mid
Right i -> seq[i]

def nextpow2(x:Nat) -> Nat =
case is_power_of_2 x of
True -> natlog2 x
False -> 1 + natlog2 x

'## Inner FFT functions

data FTDirection =
Expand Down
8 changes: 6 additions & 2 deletions lib/prelude.dx
Original file line number Diff line number Diff line change
Expand Up @@ -2241,6 +2241,11 @@ def natlog2(x:Nat) -> Nat =
False
unsafe_nat_diff(tmp, 1) -- TODO: something less horrible

def nextpow2(x:Nat) -> Nat =
case is_power_of_2 x of
True -> natlog2 x
False -> 1 + natlog2 x

def general_integer_power(
times:(a,a)->a,
one:a, base:a,
Expand Down Expand Up @@ -2477,8 +2482,7 @@ struct Stack(h:Heap, a|Data) =

def ensure_size_at_least(req_size:Nat) -> {State h} () =
if req_size > self.buf_size() then
-- TODO: maybe this should use integer arithmetic?
new_buf_size = f_to_n $ 2.0 `pow` (ceil $ log2 $ n_to_f req_size)
new_buf_size = intpow2 $ nextpow2 req_size
buf = self.unsafe_get_buffer()
logical_size = self.size()
cur_data = get $ unsafe_coerce(to=Ref(h, Fin logical_size => a), buf)
Expand Down