Recent

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

MarkMLl

  • Hero Member
  • *****
  • Posts: 7616
Integer maths > 16 bits
« on: September 15, 2024, 04:08:09 pm »
What are the options for 32-, 64- and 128-bit five-function integer maths on devices like the RP2040 and arbitrary RISC-V targets, with minimal external dependencies?

Area of application is hash algorithms etc., with the assumption (please) that hardware support for these will not be available.

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

Thaddy

  • Hero Member
  • *****
  • Posts: 15638
  • Censorship about opinions does not belong here.
Re: Integer maths > 16 bits
« Reply #1 on: September 15, 2024, 07:29:52 pm »
All you need is rolls, shifts, and, or, xor, not and a byte array.
This stems from the olden days. Easiest if there are not signs involved.
If I smell bad code it usually is bad code and that includes my own code.

MarkMLl

  • Hero Member
  • *****
  • Posts: 7616
Re: Integer maths > 16 bits
« Reply #2 on: September 15, 2024, 07:52:54 pm »
Actually Thaddy, I need + -  * div mod and shr. I'm /entirely/ capable of writing them in assembler... I'd just rather not.

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

PascalDragon

  • Hero Member
  • *****
  • Posts: 5672
  • Compiler Developer
Re: Integer maths > 16 bits
« Reply #3 on: September 15, 2024, 09:01:22 pm »
What are the options for 32-, 64- and 128-bit five-function integer maths on devices like the RP2040 and arbitrary RISC-V targets, with minimal external dependencies?

At least 32- and 64-bit math should be fully supported at least if you compile the RTL using software floating point (assuming the processor in question does not support the operations in hardware). If hardware support is available then everything should work out fine if you simply compile for the target.

Only for 128-bit math I don't know right now whether we have some suitable unit already.

MarkMLl

  • Hero Member
  • *****
  • Posts: 7616
Re: Integer maths > 16 bits
« Reply #4 on: September 15, 2024, 09:47:37 pm »
Only for 128-bit math I don't know right now whether we have some suitable unit already.

ATM it's the 128-bit case that's most interesting, but I thought I'd build up gradually through the other types since they might not (by default at least) be implemented on small chips.

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

MathMan

  • Sr. Member
  • ****
  • Posts: 329
Re: Integer maths > 16 bits
« Reply #5 on: September 16, 2024, 08:02:56 am »
Hi MarkMLI,

Take a look at the attached. Though not fully fleshed - missing some stuff for signed integers - it may be a good starting point. External dependency - FPC has to provide support up to 64 bit types, which I understand from PascalDragons response can be assumed.

If you want/need to extend, then pls let me know. Maybe I can help.

Cheers,
MathMan
« Last Edit: September 16, 2024, 08:08:27 am by MathMan »

440bx

  • Hero Member
  • *****
  • Posts: 4524
Re: Integer maths > 16 bits
« Reply #6 on: September 16, 2024, 08:06:24 am »
MathMan, you got a typo in your signature/name.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

MathMan

  • Sr. Member
  • ****
  • Posts: 329
Re: Integer maths > 16 bits
« Reply #7 on: September 16, 2024, 08:09:42 am »
MathMan, you got a typo in your signature/name.

Thanks for the heads up - getting lazy with the internal spell checker routines  :D

MarkMLl

  • Hero Member
  • *****
  • Posts: 7616
Re: Integer maths > 16 bits
« Reply #8 on: September 16, 2024, 08:49:10 am »
Hi MarkMLI,

Take a look at the attached. Though not fully fleshed - missing some stuff for signed integers - it may be a good starting point. External dependency - FPC has to provide support up to 64 bit types, which I understand from PascalDragons response can be assumed.

If you want/need to extend, then pls let me know. Maybe I can help.

Cheers,
MathMan

Many thanks I'll look at that- not necessarily immediately, but definitely.

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