Skip to content

Commit

Permalink
use fma
Browse files Browse the repository at this point in the history
  • Loading branch information
ericphanson committed Dec 4, 2023
1 parent d8735c8 commit 4fdeb67
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/samples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,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 @@ -373,7 +373,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 @@ -383,7 +383,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

0 comments on commit 4fdeb67

Please sign in to comment.