Emulating a hardware signed multiplier
Torbjorn Granlund
tg at gmplib.org
Sat Oct 24 23:27:38 CEST 2009
Børge Strand-Bergesen <borge.strand at gmail.com> writes:
I'm using GMP to write a C program that emulates a signed multiplier
that I have implement in an FPGA. The hardware multiplier uses various
hardware optimization, so I need to be confident in it before I put it
to its actual use. (MAC for digital cross-over filter.) I intend to
have GMP generate random input, send it on a UART to the hardware
multiplier, receive its result and compare that to the one GMP
calculated. If no flaws are found during a couple nights of this, the
hardware multiplier is quite likely holding up. My setup is Cygwin on
XP with GCC 3.4.4 and GMP 4.2.4-1 from a very recent Cygwin
repository.
Since you have GCC, I'd use its builtin "signed long long" type,
which works exactly like your hardware.
GMP internally uses sign-magnitude, which might make things more
complicated.
You might want to generate random numbers with GMP, though, since its
random number generators, such as mpz_rrandomb, is quote good for test
vector generations.
There is no direct way of assigning a signed long long type from a GMP
mpz_t variable. You might use two calls to mpz_get_ui with some
shifting.
--
Torbjörn
More information about the gmp-discuss
mailing list