Recent

Author Topic: Integer maths > 16 bits  (Read 2436 times)

MathMan

  • Sr. Member
  • ****
  • Posts: 405
Re: Integer maths > 16 bits
« Reply #30 on: October 14, 2024, 07:19:26 pm »
...

In the interim, I've put this at the top of int128.pas to decouple the checks it uses internally from the rest of the project.

Code: Pascal  [Select][+][-]
  1. {$ifdef CHECK_INT128 }
  2.   {$rangechecks on}
  3.   {$overflowchecks on }
  4. {$else }
  5.   {$rangechecks off}
  6.   {$overflowchecks off }
  7. {$endif }
  8.  

I'd also note that I'm defining USE_FPC64 and USE_INT128 at the project level. I might remove the first of those after I've checked the situation on the RPi Pico etc., although that definitely won't be this week.

MarkMLl

My current estimate is ~4 weeks to integrate all we discussed so far

 - implement the missing signed stuff
 - replicate everything for the unchecked types
 - add DivMod, MulMod & PwrMod
 - tidy everything, improve comments & add a short manual

If I shuffle a bit and start with adding the unchecked unsigned type for +, -, *, div and mod I may be able to provide an interim around next week, fitting to your schedule. Pls let me know if you'd like to have that - otherwise I'll stick to the sequence above.

MathMan

MarkMLl

  • Hero Member
  • *****
  • Posts: 8045
Re: Integer maths > 16 bits
« Reply #31 on: October 14, 2024, 07:44:33 pm »
/Definitely/ stick to your own time. I've found a few glitches in my code which I'm in the middle of fixing (including one place where the compiler was going recursive on my 128-bit implementation of HexStr(), even if the parameter was cast to a qword) and will post an update over the next day or so, but after that I've got plenty else to get on with.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

MarkMLl

  • Hero Member
  • *****
  • Posts: 8045
Re: Integer maths > 16 bits
« Reply #32 on: October 16, 2024, 11:16:42 am »
Updated version attached. 16-, 32-, 64- and 128-bit words work, obviously turning off runtime checks and increasing the optimisation level (although the RTL I'm using is unoptimised) speeds things up:

Code: Text  [Select][+][-]
  1. $ time ./Hash16Demo-x86_64-linux
  2. Internal check: primality tests passed
  3. Internal check: passphrase hashing passed
  4. Difference: DD7B 1101110101111011 12
  5. real    0m0.001s
  6. user    0m0.001s
  7. sys     0m0.000s
  8.  
  9. $ time ./Hash32Demo-x86_64-linux
  10. Internal check: primality tests passed
  11. Internal check: passphrase hashing passed
  12. Difference: 8EBB1617 10001110101110110001011000010111 17
  13. real    0m0.001s
  14. user    0m0.001s
  15. sys     0m0.000s
  16.  
  17. $ time ./Hash64Demo-x86_64-linux
  18. Internal check: primality tests passed
  19. Internal check: passphrase hashing passed
  20. Difference: 4A450DE35FE54A5F 0100101001000101000011011110001101011111111001010100101001011111 34
  21. real    0m9.346s
  22. user    0m9.341s
  23. sys     0m0.004s
  24.  
  25. $ time ./Hash128Demo-x86_64-linux
  26. Internal check: primality tests passed
  27. Internal check: passphrase hashing passed
  28. Difference: F020AB06A60C27202257A1C7AEB1D5C9 11110000001000001010101100000110101001100000110000100111001000000010001001010111101000011100011110101110101100011101010111001001 56
  29. real    227m22.372s
  30. user    227m16.241s
  31. sys     0m1.208s
  32.  

If assertions are enabled there are internal tests of prime number handling, followed by hashing a short password and looking for the nearest prime: predictably, it is there that the time is being spent (and I am /not/ complaining about that, since the prime checker is fairly naive and there are obvious ways it could be improved).

If INTERNALTEST is defined and there are no commandline parameters the program will hash two passphrases and find the number of bits by which they differ (Hamming distance?) which is what's being displayed above; ideally that would be half the wordsize.

Contributed as test code with the hope that it is useful to somebody, or at least a source of mirth :-)

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018