Logarithm with SSE, or switch to FPU?

前端 未结 2 1264
春和景丽
春和景丽 2021-01-12 00:31

I\'m doing some statistics calculations. I need them to be fast, so I rewrote most of it to use SSE. I\'m pretty much new to it, so I was wondering what the right approach h

2条回答
  •  感情败类
    2021-01-12 01:23

    There is no SSE instruction that implements a logarithm function. However, there's also no single x86 instruction that performs a generic logarithm either. If you're thinking about using a logarithm function like log or log10 from the C standard library, it's worth taking a look at the implementation that is used in an open-source library like libc. You can easily roll your own logarithm approximation that operates across all elements in an SSE register.

    Such a function is often implemented using a polynomial approximation that is valid within some accuracy specification over a certain region of input arguments, such as a Taylor series. You can then take advantage of logarithm properties to wrap a generic input argument into the acceptable input range for your logarithm routine. In addition, you can parameterize the base of the logarithm by taking advantage of the property:

    log_y(x) = log_a(x) / log_a(y)
    

    Where a is the base of the logarithm routine that you created.

提交回复
热议问题