Emulating a hardware signed multiplier

Børge Strand-Bergesen borge.strand at gmail.com
Sun Oct 25 22:09:08 CET 2009


Gentlemen,

thanks to you I now have the math functionality I need to simulate the
hardware multiplier (knock on wood). The attached code seems to do the
trick.

Next I'll use some UART interface code and check if GMP and the FPGA
are in agreement, converting gmp_sprintf output to the product string
received from the UART.

Thanks,
Borge

On Sun, Oct 25, 2009 at 20:13, Børge Strand-Bergesen
<borge.strand at gmail.com> wrote:
> Pedro,
>
> most elegant. Thank you!
>
> Your predictions are right. I did a quick check. My FPGA interface
> prefers capital-letter hex without preceding 0x. And that prints
> beautifully. However, the %#016Zx drops "0x" at offset==0 and seems to
> use two less characters at offset>0. I assume this is a printf issue.
> The issue won't bother my application but I wouldn't mind knowing how
> to make it print correctly.
>
> Regards,
> Borge
>
>
> int main(void) {
>        mpz_t a, mask64, a_fpga;
>        int8_t offset;
>
>        mpz_init(a);
>        mpz_init_set_str(mask64, "FFFFFFFFFFFFFFFF", 16);
>        mpz_init(a_fpga);
>
>        for (offset=-10; offset<11; offset++) {
>                mpz_set_si(a, offset);
>                mpz_and(a_fpga, a, mask64);
>                gmp_printf("%3d, %016ZX, %#016Zx\n", offset, a_fpga, a_fpga); //
> FPGA interface uses capital hex and no "0x"
>        }
>
> /* Prints:
> -10, FFFFFFFFFFFFFFF6, 0xfffffffffffffff6
>  -9, FFFFFFFFFFFFFFF7, 0xfffffffffffffff7
>  -8, FFFFFFFFFFFFFFF8, 0xfffffffffffffff8
>  -7, FFFFFFFFFFFFFFF9, 0xfffffffffffffff9
>  -6, FFFFFFFFFFFFFFFA, 0xfffffffffffffffa
>  -5, FFFFFFFFFFFFFFFB, 0xfffffffffffffffb
>  -4, FFFFFFFFFFFFFFFC, 0xfffffffffffffffc
>  -3, FFFFFFFFFFFFFFFD, 0xfffffffffffffffd
>  -2, FFFFFFFFFFFFFFFE, 0xfffffffffffffffe
>  -1, FFFFFFFFFFFFFFFF, 0xffffffffffffffff
>  0, 0000000000000000, 0000000000000000
>  1, 0000000000000001, 0x00000000000001
>  2, 0000000000000002, 0x00000000000002
>  3, 0000000000000003, 0x00000000000003
>  4, 0000000000000004, 0x00000000000004
>  5, 0000000000000005, 0x00000000000005
>  6, 0000000000000006, 0x00000000000006
>  7, 0000000000000007, 0x00000000000007
>  8, 0000000000000008, 0x00000000000008
>  9, 0000000000000009, 0x00000000000009
>  10, 000000000000000A, 0x0000000000000a
> */
>
> }
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mac_test.c
Type: application/octet-stream
Size: 3750 bytes
Desc: not available
URL: <http://gmplib.org/list-archives/gmp-discuss/attachments/20091025/705b61e9/attachment.obj>


More information about the gmp-discuss mailing list