Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29277 Discussions

Is there a way to MULTIPLY two integer(8) quantities?

WSinc
New Contributor I
889 Views

I know you can say Z = Int8(X) * int8(Y), or

Z=X*Y

if all quantities are typed integer(8), but

the result can potenially be longer than 64 bits.

What I would like to do is recover BOTH integer(8) words in that case.

I am now breaking the two integer(8) words into two parts each, and reconstructing the

product from the four combinations. This is a rather slow and cumbersome way of doing it, though.

Maybe it could be with assembly code? I think the Pentiums have that multiply in their instruction set (?)

Has anyone ever done this?

0 Kudos
4 Replies
TimP
Honored Contributor III
889 Views
You'll likely need to decide whether you want 32- or 64-bit mode, then check the CPU manuals to see if asm appears capable of better efficiency than your Fortran algorithm.
0 Kudos
Steven_L_Intel1
Employee
889 Views
The compiler does have intrinsics MULT_HIGH and MULT_LOW that do exactly what you want - but they are currently supported on IA-64 (Itanium) only. I think the instructions you want are only in one of the more recent SSE extensions to IA-32. I agree with Tim - it probably isn't really that much worse to do what you're doing now than to call C or assembly, and your code will run on more processors.
0 Kudos
WSinc
New Contributor I
889 Views

I did look at what was available, but it was only for Intel 64 CPUs.

Furthermore, the Fortran version did not return the upper 64 bits.

So, I will just coast along as before.

Thanks; Bill

PS: Did anyone ever determine why we somwtimes get a "drop dead" when we hit SUBMIT?

0 Kudos
jimdempseyatthecove
Honored Contributor III
889 Views

Bill,

I would recommend that you write a platform independent function interface with a platform dependent function. The function would have various incarnations for each platform and with one generic incarnation that works on all platforms. On an Intel64 platform the function call dispatches to assembly code that performs

RDX:RAX <- RAX * r/m64

Used

dest128 = Mul64x64(A64, B64)

destInteger16 = MulInteger8s(A8, B8)

call MulInteger8s(dest, A, B)

However you want to write the interface

This way you get portability and speed (when you have written the appropriate C or assembly function).

My 2 cents

Jim

0 Kudos
Reply