News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Extended Precision Integer Arithmetic

Started by Biterider, March 24, 2024, 05:41:37 AM

Previous topic - Next topic

Biterider

Hi
As mentioned in this thread https://masm32.com/board/index.php?topic=11767.0, the Microsoft assembler sources were the initial impetus for creating a whole bunch of extended precision integer arithmetic procedures. Since there are so many, the underlying code is written so that it can be compiled for 32 and/or 64 bit using the same core code. The naming convention changed several times until I found a solution that made sense and could be extended in the future. I also followed the frequently used INTEL argument order: target, source, source...
It looks like this:

[sign][Result Size][Argument 1 Size] [Argument 2 Size][Math Operation]

[sign] = "s" for signed and "u" for unsigned
[Size] = "d" for DWORD, "q" for QWORD, "o" for OWORD (XMMWORD) and "y" for YWORD (YMMWORD)

E.g:
  • soqqMul: is the name of a signed multiplication of 2 QWORDs whose product is an OWORD.
  • uoyoDivRem: is the name of an unsigned division with remainder procedure of a YWORD (YMMWORD) by an OWORD (XMMWORD) whose quotient and remainder are OWORDs (XMMWORDs).
  • uoShl: is the name of an unsigned shift left operation on an OWORD.


List of prototypes:
sqqqDiv proto :SDWORD, :SDWORD, :SDWORD, :SDWORD
sqqqMul proto :SDWORD, :SDWORD, :SDWORD, :SDWORD
sqqqDivRem proto :SDWORD, :SDWORD, :SDWORD, :SDWORD
sqqqRem proto :SDWORD, :SDWORD, :SDWORD, :SDWORD
sqShl proto
sqShr proto
sqoqDivRem proto :SDWORD, :SDWORD, :SDWORD, :SDWORD, :SDWORD, :SDWORD
soqqMul proto :SDWORD, :SDWORD, :SDWORD, :SDWORD

uqqqDiv proto :DWORD, :DWORD, :DWORD, :DWORD
uqqqMul proto :DWORD, :DWORD, :DWORD, :DWORD
uqqqDivRem proto :DWORD, :DWORD, :DWORD, :DWORD
uqqqRem proto :DWORD, :DWORD, :DWORD, :DWORD
uqShl proto
uqShr proto
uqoqDivRem proto :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
uoqqMul proto :DWORD, :DWORD, :DWORD, :DWORD

soooDiv proto :SQWORD, :SQWORD, :SQWORD, :SQWORD
soooMul proto :SQWORD, :SQWORD, :SQWORD, :SQWORD
soooDivRem proto :SQWORD, :SQWORD, :SQWORD, :SQWORD
soooRem proto :SQWORD, :SQWORD, :SQWORD, :SQWORD
soShl proto
soShr proto
soyoDivRem proto :SQWORD, :SQWORD, :SQWORD, :SQWORD, :SQWORD, :SQWORD
syooMul proto :SQWORD, :SQWORD, :SQWORD, :SQWORD

uoooDiv proto :QWORD, :QWORD, :QWORD, :QWORD
uoooMul proto :QWORD, :QWORD, :QWORD, :QWORD
uoooDivRem proto :QWORD, :QWORD, :QWORD, :QWORD
uoooRem proto :QWORD, :QWORD, :QWORD, :QWORD
uoShl proto
uoShr proto
uoyoDivRem proto :QWORD, :QWORD, :QWORD, :QWORD, :QWORD, :QWORD
uyooMul proto :QWORD, :QWORD, :QWORD, :QWORD

MulDiv64 proto :SQWORD, :SQWORD, :SQWORD

For ObjAsm users, bitness-neutral equates covering possible cases are also included.

All procedures are included in the ObjMem library.
The sources are freely available on GitHub here https://github.com/ObjAsm/ObjAsm-C.2/tree/master/Code/ObjMem  :thumbsup:

Regards, Biterider

Biterider

Hi
I forgot to mention that in the procs where the arithmetic operation can overflow, the OF is set to allow you to handle this on return from the procedure.
Programmatically, a JO of .if OVERFLOW? after the procedure call will do the trick.

Regards, Biterider