Arthur J. O'Dwyer says...
You know, Richard, I was *trying* to defuse the situation.
Anyway, the point is that Paul (AFAICT) writes code for Pentiums.
As is evidenced by the feedback I get for
http://bstring.sf.net/ from people
who use Linux and Mac OS X. I have a bunch of stuff on my website about
Pentiums in my assembly pages. And __int64 is a MSVC/WATCOM-ism, not a
"Pentiumism". Linux on Pentium and Borland C people are likely to have as many
objections with my use of it as anyone else.
The OP was clearly writing DOS or Windows code, and my response was clearly
directed at the OP, not anyone else. I was trying to tell the OP that this is
not a group where algorithms or performance can be sensibly discussed. The
fact that *I* am posting and reading this newsgroup is a complete fluke, and so
I was trying to indicate to the OP should probably broaden his/her horizons
when seeking those kind of answers.
[...] It
seems to be "what he does." It is slightly unreasonable to expect
Paul to re-write the Pentium code on his website -- which /is/ *mostly*
portable C code -- every time he wants to give an example of how
something could be done in (*completely* portable) C.
No, I would prefer to write portable code, because my occasional use of
"Pentium code" is limited to when I can't find a realistic way to do without,
or when I am really just analyzing a Pentium (or one of its clones.) Writing
"Pentium-C" is tantamount to writing assembly -- and I do it sometimes, but its
not because I have some aversion to writing portable code.
It's not good to post code that isn't portable -- especially if it's
unportable enough to actually refuse to compile on many implementations --
in comp.lang.c. But Paul certainly added to the discussion, and it would be
fairly trivial to "portabilize" his code when or if the OP needed it.
No its not, or I would have done so. For example, I've now changed it to code
that will *compile* portably, but will not *function* optimally. On platforms
that don't have a 64 bit integer, the code will produce incorrect results. In
fact, because of the way it was written, it will actually fail using the native
compilers on Sparc, MIPS, PA-RISC and Alpha even though *ALL* those CPUs have
64bit integers with all the right ALUs.
[...] All that was required, IMHO, was a little note: "__int64 is not
standard C. Replace it with some type that has 64 or more bits of integer
precision on your system."
Well, that's what I started with. There still a note there.
Given a suitably Turing-complete programming language, *everything* is a
performance concern. ;-) In this case, one portable alternative would be to
compute the "widening multiply" in halves (most significant and least
significant 32-bit sections).
And how will that help the fact that there is also a shortening divide in
there?
A bignum divide that I have written on top of a bignum multiply is 98 lines
with a big while-loop around most of it. And that's only because I realized
that you could use FP approximations to sneakily perform the estimation step.
Of course, its a modulo divide so there's probably a better approach, but
either way its not going to be very pretty.
That's the alternative to the 1-line divide in the source I showed.
I would have brought this up earlier, but people in this newsgroup have enough
trouble understanding widening multiplies, I didn't think bringing this up was
exactly going to register with anyone.
[...] I don't know how you would do this in C, but I assure you it can be
done.
Its algebra:
((a<<16) + b) * ((c<<16) + d) == ((a*c)<<32) + ((a*d + b*c)<<16) + b*d
I'm the last person that needs to be assured that this can be done.
Richard, in his flamboyant way, suggests bignums.
No -- in his *hyppocritical* way, he suggest bignums. Making bignums portable
is tantamount to reducing it to the Turing machine that you suggested tongue
in cheek. At some point you have to stop and recognize when a programming
language has failed you, and in the case of ANSI C, bignum-like issues show it
for all its inadequacies.
I think I get it, and I know why you used __int64 in the first place.
You do? You seemed to have missed the shortening divide that's in there.
[...] I merely think that you should have given a slightly larger nod to
portability before posting the code in a group dedicated to *portable* code.
<OT> Does gcc have C99's type int64_t (or whatever it really is)? </OT>
Who cares? C99 is *far* less portable than anything I've written.