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

use fma in decoding #148

Merged
merged 4 commits into from
Jan 26, 2024
Merged
Changes from 3 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
6 changes: 3 additions & 3 deletions src/samples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ end
"""
decode(sample_resolution_in_unit, sample_offset_in_unit, sample_data)

Return `sample_resolution_in_unit .* sample_data .+ sample_offset_in_unit`.
Return `fma.(sample_resolution_in_unit, sample_data, sample_offset_in_unit)`.

If:

Expand All @@ -379,7 +379,7 @@ function decode(sample_resolution_in_unit, sample_offset_in_unit, sample_data)
if sample_data isa AbstractArray
isone(sample_resolution_in_unit) && iszero(sample_offset_in_unit) && return sample_data
end
return sample_resolution_in_unit .* sample_data .+ sample_offset_in_unit
return fma.(sample_resolution_in_unit, sample_data, sample_offset_in_unit)
end

"""
Expand All @@ -389,7 +389,7 @@ Similar to `decode(sample_resolution_in_unit, sample_offset_in_unit, sample_data
write decoded values to `result_storage` rather than allocating new storage.
"""
function decode!(result_storage, sample_resolution_in_unit, sample_offset_in_unit, sample_data)
f = x -> sample_resolution_in_unit * x + sample_offset_in_unit
f = x -> fma(sample_resolution_in_unit, x, sample_offset_in_unit)
return broadcast!(f, result_storage, sample_data)
end

Expand Down
Loading