3 ms·
C doesn't check for overflows.. I also disagree with "shifting around stuff across registers and memory all the time". An "average" function doesn't really hav
by gens 10y ago
C doesn't check for overflows..
I also disagree with "shifting around stuff across registers and memory all the time". An "average" function doesn't really have all that many variables and x86 has 8 GP registers (16 on amd64). You don't even have to declare variables, you just take a register (and/or a location in memory) and use it as you wish.
I'm now sitting here thinking what can be done in C that would end up being a lot of instructions, and i can't think of anything. Going over an array does not, neither does recursion (recursion is just syntactic sugar in the end). What else.. i can't think of anything. Macros ? But macros are cheating in this comparison (not to mention that the flat assembler has actual macros, that are extremely powerful)
- userbinator 10y agoC doesn't check for overflows.. This is one of the things where (x86) Asm is definitely easier: divide overflows naturally cause an exception which will get handled automatically, and add/subtract/multiply overflows can be checked with one extra (JO or JC) instruction. In C, this is all undefined behaviour. I'm now sitting here thinking what can be done in C that would end up being a lot of instructions, and i can't think of anything. Crypto algorithms come to mind, but like you said, macros can take care of that easily... and on this page is an AES-256 CFB implementation in Asm that is around the same size of source as others in C (but much smaller binary): http://reimagery.com/fsfd/encrypt.htm http://reimagery.com/fsfd/encrypt.htm