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

Optimizing multiplication for Normed #174

Closed
kimikage opened this issue Jan 25, 2020 · 1 comment · Fixed by #213
Closed

Optimizing multiplication for Normed #174

kimikage opened this issue Jan 25, 2020 · 1 comment · Fixed by #213

Comments

@kimikage
Copy link
Collaborator

The current implementation of multiplication for Normed uses floating point arithmetic.

The following three points are important in adding checked_mul:

  1. Unlike checked_add/checked_sub, FixedPoint multiplication and rawtype multiplication are different.
  2. N0f8, N0f16 and so on, do not cause overflow in multiplication.
  3. Float-->Normed conversion code may throw an exception.

Therefore, the optimization for at least N0f8 and N0f16 is important.

@kimikage
Copy link
Collaborator Author

See also: #125 (comment)

However, reducing the bit width (i.e. use of UInt16) may be advantageous for SIMD loops.

function Base.:*(x::N0f8, y::N0f8)
    m = UInt16(x.i) * UInt16(y.i)
    z = m + ((m + 0x80) >> 0x8) + 0x80
    reinterpret(N0f8, unsafe_trunc(UInt8, z >> 0x8))
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant