tools include: Add an initial math64.h
authorRob Herring <robh@kernel.org>
Wed, 14 Apr 2021 15:54:09 +0000 (10:54 -0500)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 15 Apr 2021 19:38:02 +0000 (16:38 -0300)
commit2fc83c2cd77703cfcfc1ffaa092614fb1f837292
tree89f326cf79bb774df2d36ed699dc41684cdb1d75
parent2e1daee14e67fbf9b27280b974e2c680a22cabea
tools include: Add an initial math64.h

Add an initial math64.h similar to linux/math64.h with functions
mul_u64_u64_div64() and mul_u64_u32_shr(). This isn't a direct copy of
include/linux/math64.h as that doesn't define mul_u64_u64_div64().

Implementation was written by Peter Zilkstra based on linux/math64.h
and div64.h[1]. The original implementation was not optimal on arm64 as
__int128 division is not optimal with a call out to __udivti3, so I
dropped the __int128 variant of mul_u64_u64_div64().

[1] https://lore.kernel.org/lkml/20200322101848.GF2452@worktop.programming.kicks-ass.net/

Signed-off-by: Rob Herring <robh@kernel.org>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Itaru Kitayama <itaru.kitayama@gmail.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Will Deacon <will@kernel.org>
Link: http://lore.kernel.org/lkml/20210414155412.3697605-2-robh@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/include/linux/math64.h [new file with mode: 0644]