flat assembler
Message board for the users of flat assembler.

flat assembler > Main > Compute 10^n/10 using only 1 register with 2 instructions

Goto page Previous  1, 2, 3
Author
Thread Post new topic Reply to topic
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16618
Location: In your JS exploiting you and your system
Tomasz Grysztar wrote:
What is especially nice about truncated 2-adic arithmetics is that you can use it to perform several operations on rational numbers, and as long as you know that the final result is going to be an integer in 32-bit range, you know that result is going to be precise. You need such additional knowledge because just by looking at the lowest 32 bits of 2-adic result you are not able to tell an integer from a fraction.
I understand the 2-adic thing much better now. Thanks for the explanations.

I find them to be very interesting.

I also wonder if it could be "faster" (hehe, whatever that means) when computing a division to make the divide loop very efficient for only a fixed numerator of 1 and when the loop is done multiply by the final numerator. Pseudo code
Code:
 mov B,divisor
 compute A = 1/B ;efficient single purpose loop
 return A * numerator ;using imul    
Post 29 Jan 2019, 09:49
View user's profile Send private message Visit poster's website Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 1420
Amazing thread, should be made a sticky, I don't want it lost. Maybe in some useful tricks section or so Wink

Maybe we should have a thread with such code tricks, possibly in more languages (I have in constexpr C++ also, computing the constant itself fully at compile-time, zero overhead there). Then we can link this thread and others from there so it's not lost, and only that thread be made sticky.

Tomasz Grysztar wrote:
Well, except that B needs to be odd, but if it's even you can start with shifting both A and B right in parallel until B becomes odd
What if A is 1? Shifting it right would make it zero, so it's clearly wrong.
Post 29 Jan 2019, 12:40
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7288
Location: Kraków, Poland
Furs wrote:
What if A is 1? Shifting it right would make it zero, so it's clearly wrong.
Yes, this is the "underflow" condition in my function, which is treated as invalid input (sets CF to 1). We lose any bits that go too far right. But this can be handled in general by shifting the entire working space left by a sufficient number of digits (p-adic numbers always extend only finitely to the right, so you should be able to find some upper bound for your set of calculations). Then it becomes similar to fixed-point arithmetics.
Post 29 Jan 2019, 13:06
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.