Jump to content

julkas

Members
  • Content Count

    44
  • Joined

  • Last visited

Everything posted by julkas

  1. julkas

    Multiple two UInt64 modulo

    Thanks all for replies. Please see question - https://www.quora.com/What-are-the-10-biggest-prime-numbers-below-2-64 Here is my last solution - https://ideone.com/oO83MV Can you do it faster using only Miller Rabin test? If - yes,, provide your solution. BTW - My pure Object Pascal implementation is here - https://github.com/JulStrat/primesieve-pas/blob/mult/mult/modar.pas
  2. julkas

    PyPy support

    Any plans for PyPy JIT compiler support? Best regards.
  3. julkas

    Multiple two UInt64 modulo

    OK. Please provide example of a, b, m (m <> 0) where my last solution is wrong.
  4. julkas

    Multiple two UInt64 modulo

    I like portable code. But sometimes I need fast ASM Intel 64-bit Object Pascal implementation.
  5. julkas

    Multiple two UInt64 modulo

    Revised - program mulmod; {$IF Defined(FPC)}{$MODE Delphi}{$ASMMODE Intel}{$ENDIF} function MulModASM(a, b: UInt64; m: UInt64): UInt64; label CHECK_B, MUL_MOD; asm MOV RCX, m MOV RAX, a CMP RAX, RCX JB CHECK_B XOR RDX, RDX DIV RCX MOV RAX, RDX CHECK_B: MOV R8, RAX MOV RAX, b CMP RAX, RCX JB MUL_MOD XOR RDX, RDX DIV RCX MOV RAX, RDX MUL_MOD: XOR RDX, RDX MUL R8 DIV RCX MOV @Result, RDX end; var a, b, m: UInt64; begin m := $FFFFFFFFFFFFFFFF; a := 3; b := m - 1; WriteLn(a, ' ', b, ' ', m); WriteLn(' ASM - ', MulModASM(a, b, m)); WriteLn(' ASM - ', MulModASM(3, 12, 9)); WriteLn(' ASM - ', MulModASM(m, m, 9)); WriteLn('Pascal - ', (a * b) mod m); WriteLn('Pascal - ', (m * m) mod 9); end.
  6. julkas

    Multiple two UInt64 modulo

    ZZZ! My initial solution has bug - we must first reduce a and b modulo m.
  7. I have created Rosetta code entry for Object Pascal - http://www.rosettacode.org/wiki/Pseudo-random_numbers/Splitmix64#Object_Pascal
  8. Domain of application - number theory algorithms (Pollard Rho, Brent, ...)
  9. For testing see - https://github.com/lemire/testingRNG It's open source code, you can improve it or open issue. Pascal version - https://github.com/JulStrat/primesieve-pas/blob/mult/mult/prng.pas
  10. Windows Vista 32bit, CPU - Intel E2200 $ time mult/prng_t.exe 3907851 values < 72057594037927935 real 0m14.730s user 0m0.000s sys 0m0.062s
  11. Here is my SplitMix64. I think it's good starting point. Online - https://ideone.com/MCiSXd program rand; {$IF Defined(FPC)}{$MODE Delphi}{$ENDIF} {$INLINE ON} {$Q-}{$R-} uses SysUtils; type TSplitMix64 = record state: UInt64; procedure Init(seed: UInt64); inline; function Next(): UInt64; inline; end; procedure TSplitMix64.Init(seed: UInt64); begin state := seed; end; function TSplitMix64.Next(): UInt64; begin Inc(state, $9e3779b97f4a7c15); Result := state; Result := (Result xor (Result shr 30)) * $bf58476d1ce4e5b9; Result := (Result xor (Result shr 27)) * $94d049bb133111eb; Result := Result xor (Result shr 31); end; const check: UInt64 = $FFFFFFFFFFFFFFFF shr 8; var r: TSplitMix64; x: UInt64; i, c: integer; begin r.Init(UInt64(GetTickCount()) * UInt64(GetTickCount())); for i := 0 to 1000000000 do begin x := r.Next(); if x < check then Inc(c); end; WriteLn(c, ' values < ', check); for i := 0 to 1000 do WriteLn(r.Next()); end.
  12. Good. May be I will start with Lehmer’s generator or http://prng.di.unimi.it/splitmix64.c
  13. Random(MaxInt) generates values only from the interval [0, 2147483646]. So you will never got random UInt64 value x, where Lo(x) or Hi(x) are from the interval [2147483647, 4294967295]
  14. I don't know much about PRNG. I just found xoroshiro128starstar - http://prng.di.unimi.it/. What you think about? program rand; {$IF Defined(FPC)}{$MODE Delphi}{$ENDIF} {$INLINE ON} var seed: array[0..1] of uint64; function rotl(x: uint64; k: integer): uint64; inline; begin Result := (x shl k) or (x shr (64 - k)); end; function xoroshiro128starstar(): uint64; var s0, s1: uint64; begin s0 := seed[0]; s1 := seed[1]; Result := rotl(s0 * 5, 7) * 9; s1 := s1 xor s0; seed[0] := rotl(s0, 24) xor s1 xor (s1 shl 16); // a, b seed[1] := rotl(s1, 37); // c end; var i: integer; begin seed[0] := 3; seed[1] := 1000000007; for i := 1 to 1000 do WriteLn(xoroshiro128starstar()); end. Online link - https://ideone.com/cB6zSa Thanks for replies.
  15. julkas

    [Souce code]

    Good projects! 👍
  16. julkas

    GLAD loader for Delphi

    GL/GLES/EGL/GLX/WGL Loader-Generator support for Delphi, FPC is here - https://github.com/Dav1dde/glad. Tested with Delphi CE, FPC 3.0.4. Examples: https://github.com/Dav1dde/glad/tree/master/example/pascal https://github.com/JulStrat/glad/tree/master/example/pascal. If you have problems - open issue on https://github.com/JulStrat/glad or send me mail.
  17. julkas

    GLAD loader for Delphi

    You can find more info about GLAD and other loaders here - https://www.khronos.org/opengl/wiki/OpenGL_Loading_Library
×