Template BigNum implemented without runtime loops
Don Clugston
dac at nospam.com.au
Tue Dec 12 00:22:52 PST 2006
BCS wrote:
> I have implemented a arbitrary precision integer type using a struct and
> templates. Currently it supports ==, +, -, *, +=, -= and *=. It should
> be fairly efficient as it uses static foreaches and asm blocks to unroll
> all of the looping and conditionals.
>
> I haven't tested the multiplication much yet so it may well contain
> bugs. (If it doesn't I will be vary surprised)
>
> On my system DMD crashes for size > 73 (e.i. 73 * 32b = 2336b).
Of course, there's not much value in unrolling loops to that extent
(cache misses will cost you more than you'll gain by eliminating the
last couple of branch instructions).
However, the use of tuples and static foreach to enforce asm unrolling
is very cool. This ought to work with mixins as well as direct asm
instructions. I'd never found a way of mixing in multiple blocks of code
at the same level -- this technique will probably solve the problem.
(And it might be a way of doing very high performance expression
templates :-) ).
More information about the Digitalmars-d-announce
mailing list