Emulating a hardware signed multiplier

Matthew Lai cyberfish at wecheer.com
Sun Oct 25 08:15:15 CET 2009


Integer literals are long by default (just like how floating point 
numbers are double by default).

Add a "LL" to the end of the literals.

Matthwe


Børge Strand-Bergesen wrote:
> Thanks Torbjörn,
>
> On my platform, sizeof(signed long long) is 8 (=64 bits), which should
> hold my assignments but not the 128-bit result. What comes as a bit of
> a surprise then is that the compiler says "warning: integer constant
> is too large for "long" type" about the "ax = 0x..." and "bx = 0x..."
> lines.
>
> Is this what I should expect, or should the signed long long hold
> 128-bit numbers and not complain about my 64-bit assignments? Or
> perhaps it is GCC 3.4.4 which is the issue.
>
> Here's my latest test code that produces the warnings:
>
> 	signed long long ax, bx, resultx;
> 	printf("%d\n", sizeof(signed long long));
> 	ax = 0x747262FA8DE38F37;
> 	bx = 0x4728AD47CE37F092;
> 	resultx = ax * bx;
> 	printf("%#32lllx\n", resultx);
> 	// Prints "              0x4b85d44d48dc3d5e"
>
>
>
> Borge
>
>
> On Sat, Oct 24, 2009 at 23:27, Torbjorn Granlund <tg at gmplib.org> wrote:
>   
>> 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
>>
>>     
> _______________________________________________
> gmp-discuss mailing list
> gmp-discuss at gmplib.org
> https://gmplib.org/mailman/listinfo/gmp-discuss
>   



More information about the gmp-discuss mailing list