Re: Assembler versus ANSI C
From: Thomas Pornin (pornin_at_nerim.net)
Date: 07/31/03
- Next message: Simon Johnson: "Re: Is RC4 a good choice?"
- Previous message: Jonas T: "Reversible permutation?"
- In reply to: George Joseph: "Assembler versus ANSI C"
- Next in thread: JS: "Re: Assembler versus ANSI C"
- Reply: JS: "Re: Assembler versus ANSI C"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Thu, 31 Jul 2003 12:34:50 +0000 (UTC)
According to George Joseph <george.joseph@student.up.ac.za>:
> So must I write the PKC algos in C or assembler?
You must write them in whatever language which will allow you to
produce a _correct_ implementation (yielding the expected result and
not crashing when submitted a flawed input) with a cpu/power/whatever
consumption and a development time which are adequate for your needs.
If you are after correctness and a short development time, you should
use an existing "big integer" library, which will handle the grunt
work of modular exponentiation and other similar operations. Chances
are that such a library will include a fully hand-optimized assembly
implementation for the most often encountered architecture (the PC-x86),
with very good performance.
If you do wish to implement your own set of big integer functions,
then the choice between C and assembly depends upon the target
architecture, and your exact needs (development speed, computation
speed, maintainability of the implementation, provable correctness...).
What can be said is the following:
-- C will improve maintainability (it is possible and even easy to
write unreadable C code, but it is easier to write readable C code than
readable assembly code -- if you can write readable assembly, you could
have written readable C with less effort).
-- On RISC architectures (Sparc, Alpha, PowerPC,...), careful C code can
achieve almost the same efficiency than hand-optimized assembly. On those
platforms, C is the way to go (with regards to assembly).
-- On the PC (Intel x86 or compatible), the instruction set is too weird
for the C compiler to perform a really good job, so you can usually get
much better performance with assembly (especially if you fiddle with the
exotic units such as MMX or SSE); you might expect up to three times the
speed by using assembly. But it is not an easy task, and in a deployed
application, it is rarely worth the effort.
-- Assembly is not portable. The most optimized C implementations will
not be portable either (for instance, they will be tuned for some
specific integer length matching the register length on the target
architecture), but it is possible to write a decent and highly portable
big integer library in ANSI C. Performance will not be the highest
possible, but will still be more than enough for most applications.
--Thomas Pornin
- Next message: Simon Johnson: "Re: Is RC4 a good choice?"
- Previous message: Jonas T: "Reversible permutation?"
- In reply to: George Joseph: "Assembler versus ANSI C"
- Next in thread: JS: "Re: Assembler versus ANSI C"
- Reply: JS: "Re: Assembler versus ANSI C"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|
|