The existing lanczos_weight() implementation naively follows the purely mathematical definition for the `x == 0` special case. However, the point of defining that special case is obviously to prevent division by zero in the general case formula. Unfortunately we are still doing some multiplications with `x` before we get to the division step, and our fpmath library loses precision during multiplication. This can lead to edge cases where `x` is not zero but `x_times_pi` later ends up being 0, which causes the division to throw an exception after all. (I guess we've just been lucky to not see this case in practice for now... it requires the output pixel coordinate to be extremely close to but not quite on the next input pixel coordinate, which may be rare in practice with our scaling algorithms.) This patch fixes the issue by implementing the special case later and checking if `x_times_pi` is zero instead. Note that as long as we pass this check, we can be confident that the division cannot fail even though fpdiv() also truncates the divisor: this is because `x_times_pi` was calculated from an fpmul() call with the constant fppi(), which has 34 significant bits. Even if x is the smallest possible non-zero value after scaling for multiplication, the result `x_times_pi` must still have 18 significant bits. That means it can be scaled down a further 16 bits for division without becoming zero. Also add a simple unit test forcing exactly this condition to ensure the code will not regress. Change-Id: I2f212ee5df38252e97ec55aba3d2d25320c4b102 Signed-off-by: Julius Werner <jwerner@chromium.org> Reviewed-on: https://review.coreboot.org/c/coreboot/+/87532 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Yu-Ping Wu <yupingso@google.com> Reviewed-by: Jakub "Kuba" Czapiga <czapiga@google.com> |
||
|---|---|---|
| .. | ||
| arch | ||
| bin | ||
| configs | ||
| crypto | ||
| curses | ||
| drivers | ||
| gdb | ||
| include | ||
| libc | ||
| libcbfs | ||
| liblz4 | ||
| liblzma | ||
| libpci | ||
| sample | ||
| tests | ||
| vboot | ||
| .gitignore | ||
| Doxyfile | ||
| Kconfig | ||
| LICENSE_GPL | ||
| LICENSES | ||
| Makefile | ||
| Makefile.mk | ||
| Makefile.payload | ||
| README | ||
-------------------------------------------------------------------------------
libpayload README
-------------------------------------------------------------------------------
libpayload is a minimal library to support standalone payloads
that can be booted with firmware like coreboot. It handles the setup
code, and provides common C library symbols such as malloc() and printf().
Note: This is _not_ a standard library for use with an operating system,
rather it's only useful for coreboot payload development!
See https://www.coreboot.org for details on coreboot.
Installation
------------
$ git clone https://review.coreboot.org/coreboot.git
$ cd coreboot/payloads/libpayload
$ make menuconfig
$ make
$ make install (optional, will install into ./install per default)
On x86 systems, libpayload will always be 32-bit even if your host OS runs
in 64-bit, so you might have to install the 32-bit libgcc version.
On Debian systems you'd do 'apt-get install gcc-multilib' for example.
Run 'make distclean' before switching boards. This command will remove
your current .config file, so you need 'make menuconfig' again or
'make defconfig' in order to set up configuration. Default configuration
is based on 'configs/defconfig'. See the configs/ directory for examples
of configuration.
Usage
-----
Here's an example of a very simple payload (hello.c) and how to build it:
#include <libpayload.h>
int main(void)
{
printf("Hello, world!\n");
return 0;
}
Building the payload using the 'lpgcc' compiler wrapper:
$ lpgcc -o hello.elf hello.c
Please see the sample/ directory for details.
Website and Mailing List
------------------------
The main website is https://www.coreboot.org/Libpayload.
For additional information, patches, and discussions, please join the
coreboot mailing list at https://www.coreboot.org/Mailinglist, where most
libpayload developers are subscribed.
Copyright and License
---------------------
See LICENSES.