views:

108

answers:

3

i'm trying to write a program that solves the rsa challenge (yes i have interesting goals) and currently i don't have a 64 bit linux box and i don't really wanna spend my time writing a program that doesn't have a chance to ever finish. so while i can do some assembler programming, i would prefer using C++. however, i would also be interested in how to use inline assembly to do the same thing. the plan here is to use the 16 64 bit general purpose registers and the 128 bit sse registers to do (really really long) integer math. so any help on how to do that would be greatly appreciated.

+1  A: 

All modern compillers are very good at reusing all available registers to produce the fastest possible code.

Especially Intel C++ and GCC3 - they often create code unbeatable manually.

BTW, check out this: http://stackoverflow.com/questions/1295452/why-does-msvc-not-support-inline-assembly-for-amd64-and-itanium-targets

BarsMonster
the point here is that i can't use variables since i want to do math with 300+ digit numbers. or rather i want to multiply two numbers with up to 512 binary digits, so a 64 bit integer doesn't quite get me anywhere close.
xyious
So? Use 8 of them. That's exactly why you want a compiler that's good at using the available registers, because you need so many of them.
MSalters
+2  A: 

Based on your comment to BarsMonsters anser, you don't need to get closer to the CPU, you need a large integer library.

One option is gmp, which includes arbitrary integer arithmetic. It has good algorithms for things like multiplying large integers, and a good compiler will do a better job of optimising this than most people.

The main issue that might make you look for an alternative is that it supports variable precision arithmetic, which may be an overhead you'd rather avoid if you know for sure that your numbers have at most 512 binary digits. Even so, you probably want to look at algorithms more than low-level tricks (long multiplication may already be a bad choice at that size), and I'm pretty confident you'll be better off letting the compiler do your optimisation.

My advice - spend your time doing the things that require human intelligence, not the things that a machine can do far more consistently and a billion times faster.

And if you really can optimise machine code better than a compiler can, download LLVM and implement that logic as an optimisation pass so we can all get the benefit ;-)

Steve314
i'm not sure if you're familiar with the rsa challenge, but my approach to the thing differs from the recently successful ones. either way i multiply 2 numbers and then compare the result to the number i want to factor. the number i want to factor has around 750 binary digits.either way, gmp looks promising, just not sure how if there's a way to use it in visual studio.
xyious
It's supposed to be portable C code in a portable C++ wrapper. I haven't used it yet myself - by fluke, it's something I downloaded recently but haven't got around to using yet - but I'd be surprised if you can't use it.
Steve314
there actually is a port that is supposed to work with visual studio and i'm trying it out right now.... need yasm for it but after installing that the solution loads without problems (sorry but that's as far is i got so far).link: http://www.mpir.org/
xyious
+1  A: 

If you want to just do some precission math, you would better try Intel C++ compiler and use it's math lib, it very powerfull and overoptimized. Same for Boost math library. This might cut your work by 90% :-) They do support arbitrary precission numbers.

BarsMonster