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 widen(Int128)=BitIntgers.Int256 within FD #6

Conversation

NHDaly
Copy link
Member

@NHDaly NHDaly commented Dec 12, 2018

Remove allocations for FD{Int128} by switching to widen to Int256 instead of BigInt.

Adds a dependency on the BitIntegers package, but it seems worth it to me.

I'm merging this into #5, so that we can review them in two chunks.

@NHDaly NHDaly force-pushed the nhdaly-manual_mul_invcoeff-Int256 branch from 885a823 to 4465412 Compare December 12, 2018 02:22
@NHDaly
Copy link
Member Author

NHDaly commented Dec 12, 2018

Here are the benchmark results from this change -- the improvements are really big! :D

(The diff is relative to JuliaMath@1768c58.)

    Operation Values                
    *   /   +   div   identity  
Category Type time (ns) * % improvement time (ns) * % improvement time (ns) * % improvement time (ns) * % improvement time (ns) * % improvement
Int Int32 0.35 0% 3.91 -3% 0.35 0% 0.35 0% 0.35 0%
  Int64 0.35 0% 3.91 -4% 0.35 0% 0.35 0% 0.35 0%
  Int128 0.35 19% 13.45 -4% 0.35 0% 0.35 0% 0.35 0%
Float Float32 0.35 0% 0.35 0% 0.35 0% 2.57 4% 0.35 0%
  Float64 0.35 0% 0.35 0% 0.35 0% 2.67 -4% 0.35 0%
FixedDecimal FD{ Int32,2} 3.02 71% 10.25 -18% 0.35 0% 0.35 0% 0.35 0%
  FD{ Int64,2} 9.54 47% 22.88 -9% 0.35 0% 0.35 88% 0.35 0%
  FD{Int128,2} 73.46 99% 1366.20 90% 0.35 100% 0.35 100% 0.35 100%
Big BigFloat 93.60 -32% 167.97 -20% 52.76 -25% 193.86 -26% 0.35 0%
  BigInt 186.73 8% 553.34 -14% 174.12 5% 229.65 -15% 0.35 0%

* note: The time is truncated to a minimum of 0.345ns, which is the estimated time for a single clock cycle on my machine


# BitIntegers is missing iseven/isodd
# Prevent expensive calculation for Int256
Base.isodd(a::BitIntegers.Int256) = Base.isodd(a % Int) # only depends on the final bit! :)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used? If not consider removing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes it is. I've added a comment about why it's used. (_round_to_even calls iseven, which in turn calls isodd.)

import BitIntegers

# BitIntegers is missing unsigned(::Type{Int256})
Base.unsigned(x::T) where T<:BitIntegers.XBS = reinterpret(unsigned(T), x)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is XBS? eXtra Big Stick?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha i guess it's "eXtended Bit (integers) Signed". Blech!

But also, i just switched it to XBI, which is "eXtended Bit Integers", which is what I settled on in the PR i sent to that package: rfourquet/BitIntegers.jl#2

It's basically the super type for all the new integer types that package added.

I clarified that in the comments, and also added a TODO comment to delete these lines once the PRs on the base package are merged. Thanks! :)

@NHDaly
Copy link
Member Author

NHDaly commented Dec 13, 2018

(Just force-pushed after rebasing in the comments on #5)

@NHDaly NHDaly force-pushed the nhdaly-manual_mul_invcoeff-Int256 branch from 4465412 to 28994ea Compare December 13, 2018 19:03
@NHDaly
Copy link
Member Author

NHDaly commented Dec 13, 2018

(Back to you!) Thanks! :)

@ghost ghost force-pushed the nhdaly-manual_mul_invcoeff branch from f03145e to 6af05e0 Compare December 13, 2018 19:48
@NHDaly NHDaly force-pushed the nhdaly-manual_mul_invcoeff-Int256 branch 3 times, most recently from 3fcbff8 to 4043855 Compare December 13, 2018 21:58
@@ -505,6 +536,7 @@ Base.@pure function max_exp10(::Type{T}) where {T <: Integer}
end

max_exp10(::Type{BigInt}) = -1
@eval max_exp10(::Type{Int128}) = $(max_exp10(Int128))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment: force evaluation of max_exp10 at compile time ?

@NHDaly NHDaly force-pushed the nhdaly-manual_mul_invcoeff-Int256 branch from 54f865b to 747b628 Compare December 18, 2018 18:07
@ghost ghost changed the base branch from nhdaly-manual_mul_invcoeff to rai-manual_mul_invcoeff-Int256 December 18, 2018 18:14
@ghost ghost merged commit 747b628 into RelationalAI-oss:rai-manual_mul_invcoeff-Int256 Dec 18, 2018
@NHDaly NHDaly deleted the nhdaly-manual_mul_invcoeff-Int256 branch January 29, 2019 15:59
@NHDaly NHDaly restored the nhdaly-manual_mul_invcoeff-Int256 branch January 29, 2019 16:00
This pull request was closed.
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 this pull request may close these issues.

2 participants