←back to thread

79 points ingve | 1 comments | | HN request time: 0.205s | source
Show context
tom_ ◴[] No.42477165[source]
It's always been a mystery to me why people put up with this stuff. Adding strings to the assembler output is fine if you want to assemble some unsupported instruction, and a useful getout clause. But as the only option, it sucks, and it's no fun if you want to insert more than 1 instruction.

I used CodeWarrior for PowerPC about 15 years ago, and its inline assembler was very easy to use. No markup required, and you didn't even have to really understand the ABI. Write a C function, add "register" to the parameters, put register variables inside the function, add an asm block inside it, then do your worst. It'd track variable liveness to allocate registers, and rearrange instructions to lengthen dependency chains. Any problems, you'd get an error. Very nice.

replies(5): >>42477331 #>>42477671 #>>42477682 #>>42479166 #>>42487770 #
1. mystified5016 ◴[] No.42487770[source]
Sometimes you genuinely know better than the compiler. Not often, but sometimes.

I'm an embedded developer and recently for work I had to do inline assembly. The function was there or four lines of C, two nested for loops. The runtime cost of the C is 200-300 cycles.

I rewrote the function in assembly using features particular to my CPU and brought the runtime cost to 90 cycles with no loops.

In this application, the 60% runtime reduction was worth the week it took to engineer.