KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I would like my C function to efficiently compute the high 64 bits of the product of two 64 bit signed ints. I know how to do this in x86-64 assembly, with imulq and pulling the result out of %rdx. But I'm at a loss for how to write this in C at all, let alone coax the compiler to do it efficiently. Does anyone have any suggestions for writing this in C? This is performance sensitive, so "manual methods" (like Russian Peasant, or bignum libraries) are out. This dorky inline assembly function I wrote works and is roughly the codegen I'm after: static long mull_hi(long inp1, long inp2) { long output = -1; __asm__("movq %[inp1], %%rax;" "imulq %[inp2];" "movq %%rdx, %[output];" : [output] "=r" (output) : [inp1] "r" (inp1), [inp2] "r" (inp2) :"%rax", "%rdx"); return output; }
Tags (comma-separated)
Save Edits
Cancel