Community
cancel
Showing results for
Did you mean:
Beginner
45 Views

## GMP Performance of multiplication vs squaring?

I did some performance tests with multiplication.
There is no dedicated operation for squaring, and multiplication does not seem to detect squaring situations (identical operands for multiplication)

It should be expected that a dedicated implementation of squaring provides a significant performance benefit.
(at least this is my experience with own implementations of grammar school multiplication, Karatsuba, FFT).

Questions:
- is there a hidden feature in MKL/GMP for optimized squaring?
- are there plans for future versions of MKL to improve squaring?

3 Replies
Black Belt
45 Views
Sorry, Vladimir is correct -- I misunderstood the question and, therefore, my posting should be removed.

I do not know how to erase a posting, so I edited the posting, removed the irrelevant content and substituted this retraction.

New Contributor III
45 Views
Franz,

Thank you for your interest in our library and particularly in its multi-precision functionality.

In one of our future versions there will be a significant speed-up of multiplication, including the squaring case.

We do not encourage using any undocumented "hidden features" of MKL. If you feel that some feature is missing, please do not hesitate to submit a feature request through premier.intel.com.

Best regards,
New Contributor III
45 Views
Quoting mecej4
Please give some examples. Here is a counterexample (with default precision -- did you mean to exclude this case?) :

1. subroutinesub(x,y)
2. real,intent(in)::x
3. real,intent(out)::y
4. y=x*x
5. return
6. endsubroutinesub
`[fortran]subroutine sub(x,y)real, intent(in) :: xreal, intent(out) :: yy=x*xreturnend subroutine sub[/fortran]`
compiles to

1. moveax,DWORDPTR[4+esp]
2. movedx,DWORDPTR[8+esp]
3. movssxmm0,DWORDPTR[eax]
4. mulssxmm0,xmm0
5. movssDWORDPTR[edx],xmm0
6. ret
`[bash]    mov       eax, DWORD PTR [4+esp]    mov       edx, DWORD PTR [8+esp]    movss     xmm0, DWORD PTR [eax]    mulss     xmm0, xmm0    movss     DWORD PTR [edx], xmm0    ret[/bash]`
and, to me, it seems clear that 'mulss xmm0,xmm0' captures the essence of 'square the operand'.

This "counterexample" is not quite relevant to the subject of this thread since the original question was about multi-precision integer arithmetic.

Best regards,