How to divide two 64-bit numbers in Linux Kernel?

后端 未结 4 1891
面向向阳花
面向向阳花 2021-01-17 17:01

Some code that rounds up the division to demonstrate (C-syntax):

#define SINT64 long long int
#define SINT32 long int

SINT64 divRound(SINT64 dividend, SINT6         


        
4条回答
  •  孤独总比滥情好
    2021-01-17 17:11

    I don't think (at least can't find a way to make) Chris' answer work in this case because do_div() actually changes the dividend in-place. Getting the absolute value implies a temporary variable whose value will change the way I require but can't be passed out of my __divdi3() override.

    I don't see a way around the parameter-by-value signature of __divdi3() at this point except to mimic the technique used by do_div().

    It might seem like I'm bending over backwards here and should just come up with an algorithm to do the 64-bit/32-bit division I actually need. The added complication here though is that I have a bunch of numerical code using the '/' operator and would need to go through that code and replace every '/' with my function calls.

    I'm getting desperate enough to do just that though.

    Thanks for any follow-up, Chad

提交回复
热议问题