[llvm-dev] double to unsigned char cast

Jay K via llvm-dev llvm-dev at lists.llvm.org
Wed Apr 4 23:49:33 PDT 2018


wrt https://github.com/mono/mono/commit/fb91fce5d339bb9ffe507588f5bc1d8d6f244d9b


This doesn't seem right to me.
Both of these should have the and 0xff.

$ cat /s/1.c
unsigned char f1 (double i)
{
        return (unsigned char)i;
}

unsigned char f2 (double i)
{
        return (unsigned char)(int)i;
}

$ clang --version

Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

$ clang -arch arm64 -O2 -S -c /s/1.c && more 1.s

_f1:
        fcvtzs  w0, d0
        ret

_f2:
        fcvtzs  w8, d0
        and     w0, w8, #0xff
        ret

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180405/652a038c/attachment.html>


More information about the llvm-dev mailing list