[PATCH] D62088: [compiler-rt][builtins] Scaled Integer log10()

Leonard Chan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 5 11:17:00 PDT 2019


leonardchan added a comment.

In D62088#1523994 <https://reviews.llvm.org/D62088#1523994>, @saugustine wrote:

> The number is the argument count plus one for return value. So this function should be named
>
> __log10scaleddi3


Done and clang-formated

In D62088#1531310 <https://reviews.llvm.org/D62088#1531310>, @rjmccall wrote:

> In D62088#1531309 <https://reviews.llvm.org/D62088#1531309>, @leonardchan wrote:
>
> > In D62088#1522446 <https://reviews.llvm.org/D62088#1522446>, @rjmccall wrote:
> >
> > > I don't review compiler-rt patches generally.  Can you explain what would actually use this function?  Is there supposed to be a new Clang builtin for it?
> >
> >
> > We will be using this as part of our WLAN library which represents energy units (decibels and watts) as scaled integers that we have custom classes for. Converting between these units and adding decibels mathematically involves using log10(). Currently, we just use float log10 and casting, but would like to use this for scaled integers and eventually fixed point types. The idea is that this would be a new clang builtin that we could use instead of a floating point log10().
>
>
> Okay.  Will you need a signed variant of this?  Is using a 64-bit argument reasonable for all targets, or should there be 32-bit and 64-bit (and maybe eventually 128-bit) variants?


I don't think we need a signed version since ideally all inputs to log functions should be non-negative, otherwise the result is imaginary. This could also be reasonably extended to support other sizes. I only chose a 64 bit size for now since it's the largest type we use and any other types could be resized/rescaled into this. For 128-bit, this would be a little more tricky since the algorithm depends on wide multiplication (which we kinda do through `x = (__uint128_t)x * x >> scale;`), although I can't seem to find an existing compiler-rt multiplication function that does this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62088/new/

https://reviews.llvm.org/D62088





More information about the llvm-commits mailing list