Skip to content

Commit

Permalink
math64.h: Add mul_s64_u64_shr()
Browse files Browse the repository at this point in the history
This function is needed for KVM's nested virtualization. The nested TSC
scaling implementation requires multiplying the signed TSC offset with
the unsigned TSC multiplier.

Signed-off-by: Ilias Stamatis <ilstam@amazon.com>
Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
Message-Id: <20210526184418.28881-2-ilstam@amazon.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
Ilias Stamatis authored and Paolo Bonzini committed Jun 17, 2021
1 parent d501f74 commit 605a140
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions include/linux/math64.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define _LINUX_MATH64_H

#include <linux/types.h>
#include <linux/math.h>
#include <vdso/math64.h>
#include <asm/div64.h>

Expand Down Expand Up @@ -234,6 +235,24 @@ static inline u64 mul_u64_u64_shr(u64 a, u64 b, unsigned int shift)

#endif

#ifndef mul_s64_u64_shr
static inline u64 mul_s64_u64_shr(s64 a, u64 b, unsigned int shift)
{
u64 ret;

/*
* Extract the sign before the multiplication and put it back
* afterwards if needed.
*/
ret = mul_u64_u64_shr(abs(a), b, shift);

if (a < 0)
ret = -((s64) ret);

return ret;
}
#endif /* mul_s64_u64_shr */

#ifndef mul_u64_u32_div
static inline u64 mul_u64_u32_div(u64 a, u32 mul, u32 divisor)
{
Expand Down

0 comments on commit 605a140

Please sign in to comment.