BigInt module (SSE2)

Share your advanced PureBasic knowledge/code with the community.
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: BigInt module (SSE2)

Post by walbus »

Great !
User avatar
Crusiatus Black
Enthusiast
Enthusiast
Posts: 389
Joined: Mon May 12, 2008 1:25 pm
Location: The Netherlands
Contact:

Re: BigInt module (SSE2)

Post by Crusiatus Black »

My apologies for the bump. On Linux (Mint x64) and PureBasic 5.42 x64 BigInt operations stall execution (it stops). When LoadValue is called.

Code: Select all

      Debug "loading value...."
      BigInt::LoadValue(*n, *RandN, ByteSize, #True)
      Debug "loaded value..."
*RandN is just a buffer with random memory.

The exact same code works perfectly fine on Windows x64 and x86.

Scratch that, it was caused by a stack corruption in another library. When isolated, this code runs fine.
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: BigInt module (SSE2)

Post by wilbert »

Crusiatus Black wrote:Scratch that, it was caused by a stack corruption in another library. When isolated, this code runs fine.
That explains why I couldn't replicate the problem.
Anyway, glad to hear it works fine after all :)
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Crusiatus Black
Enthusiast
Enthusiast
Posts: 389
Joined: Mon May 12, 2008 1:25 pm
Location: The Netherlands
Contact:

Re: BigInt module (SSE2)

Post by Crusiatus Black »

wilbert wrote:
Crusiatus Black wrote:Scratch that, it was caused by a stack corruption in another library. When isolated, this code runs fine.
That explains why I couldn't replicate the problem.
Anyway, glad to hear it works fine after all :)
Ah sorry, I didn't mean to give you unnecessary work. Now for me a challenge, how to find the stack issue that only occurs on Linux...
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: BigInt module (SSE2)

Post by wilbert »

Crusiatus Black wrote:Ah sorry, I didn't mean to give you unnecessary work. Now for me a challenge, how to find the stack issue that only occurs on Linux...
No problem and good luck with tracking down the stack issue.
It can be difficult sometimes to solve something which is only happening on one OS.
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Crusiatus Black
Enthusiast
Enthusiast
Posts: 389
Joined: Mon May 12, 2008 1:25 pm
Location: The Netherlands
Contact:

Re: BigInt module (SSE2)

Post by Crusiatus Black »

wilbert wrote:
Crusiatus Black wrote:Ah sorry, I didn't mean to give you unnecessary work. Now for me a challenge, how to find the stack issue that only occurs on Linux...
No problem and good luck with tracking down the stack issue.
It can be difficult sometimes to solve something which is only happening on one OS.
Thank you! Yes, the purifier told me about the stack issue on Linux, however on Windows the purifier is quiet.

The programming life is a magical life.
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!
User avatar
NicknameFJ
User
User
Posts: 90
Joined: Tue Mar 17, 2009 6:36 pm
Location: Germany

Re: BigInt module (SSE2)

Post by NicknameFJ »

Hello Wilbert,

first I wish you a happy new year 2018.

Thank you for sharing your BigInt-Lib.

Maybe I´am doing something wrong with it, maybe there is an error in it.

Run this short prg and it will crash with an Stack Overflow Error. I´m on Windows 10 with PB 5.61 x64.

It is always wenn the result of a^b mod(c) is zero. The same happens when using the ModMul-Funktion and the result of a * b mod(c) is zero too. I think the error is in your procedure divmod_private procedure because this proc is called in both; if I comment the call of divmod_privat out, sure the result ist wrong when doing so, but no crash at all.

Maybe I´m doing something wrong with it. In this case it would be nice when you can tell me what I´m doing wrong.

Maybe you can take a look because I don´t understand your great code so I can not fix it by myself.

Thank you

NicknameFJ

Code: Select all

IncludeFile "O:\Includes\BigInt\BigInt.pbi" 

Define.BigInt::BigInt X, A, B, C


BigInt::SetValue(A,12)
BiGInt::SetValue(B,13)
BiGInt::SetValue(C,27)


BIGInt::ModPow(X,A,B,C)
PS: Sorry for my weird english, but english is not my native language.



Image
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: BigInt module (SSE2)

Post by wilbert »

NicknameFJ wrote:Maybe I´am doing something wrong with it, maybe there is an error in it.

Run this short prg and it will crash with an Stack Overflow Error. I´m on Windows 10 with PB 5.61 x64.
I made a small change to the module code in the first post.
Can you check if it works fine now ?
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
NicknameFJ
User
User
Posts: 90
Joined: Tue Mar 17, 2009 6:36 pm
Location: Germany

Re: BigInt module (SSE2)

Post by NicknameFJ »

Hello wilbert,

after a few short tests it seems to work fine.


Thank you very very much for your answer and for fixing it so fast.

When we ever met tell me that you are wilbert and I will spend you one beer, or two, or three ..... :D


NicknameFJ
PS: Sorry for my weird english, but english is not my native language.



Image
User avatar
Michael Vogel
Addict
Addict
Posts: 2677
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: BigInt module (SSE2)

Post by Michael Vogel »

Great stuff, thanks to wilbert and little john!

Combining the Radi and BigInt modules allow wonderful calculations, like the old calculator precision test to repeat x^2 26 times starting with the value 1.0000001

Code: Select all

z=Radi::MaxDestDigits(BigInt::#BigIntBits,2,10)
Debug "A binary number with "+Str(BigInt::#BigIntBits)+" digits has up To "+Str(z)+" decimal digits"

z=z/2
BigInt::SetValue(n1,10000001)
For i=1 To 26
	BigInt::Multiply(n1, n1)
	s.s=Left(Radi::Hex2Dec(BigInt::GetHex(n1)),z)
	BigInt::SetHexValue(n1,Radi::Dec2Hex(s))
Next i

Debug Radi::Hex2Dec(BigInt::GetHex(n1))
User avatar
CELTIC88
Enthusiast
Enthusiast
Posts: 154
Joined: Thu Sep 17, 2015 3:39 pm

Re: BigInt module (SSE2)

Post by CELTIC88 »

Wonderful. :shock:
interested in Cybersecurity..
jack
Addict
Addict
Posts: 1336
Joined: Fri Apr 25, 2003 11:10 pm

Re: BigInt module (SSE2)

Post by jack »

hello wilbert :)
do you have a non-asm version?
could be useful for trying out on the C back-end
btw, I came across this document about arbitrary precision arithmetic algorithms with test-code in fortran https://ia800403.us.archive.org/10/item ... 9.5911.pdf
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: BigInt module (SSE2)

Post by wilbert »

jack wrote: Tue Dec 21, 2021 6:23 pm hello wilbert :)
do you have a non-asm version?
Sorry, I don't.
At the time I didn't think about the possibility of PB running on something other than x86 / x64.
Windows (x64)
Raspberry Pi OS (Arm64)
AZJIO
Addict
Addict
Posts: 1360
Joined: Sun May 14, 2017 1:48 am

Re: BigInt module (SSE2)

Post by AZJIO »

I added this to the help file (ru)
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: BigInt module (SSE2)

Post by Kwai chang caine »

Useful funstion
Works here :D
121FA000A3723A57C24A442FE55618CF
1234567890ABCDEF
Thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
Post Reply