mailing list of musl libc
 help / color / mirror / code / Atom feed
From: bobodog <8192542@qq.com>
To: musl <musl@lists.openwall.com>
Subject: [BUG][math]build musl with optimizing flags, some math functions are broken.
Date: Tue, 14 Oct 2014 14:43:44 +0800	[thread overview]
Message-ID: <tencent_367F8384572400D944A791F3@qq.com> (raw)
In-Reply-To: <tencent_5AACC3A475CC3D72346DE519@qq.com>

[-- Attachment #1: Type: text/plain, Size: 10126 bytes --]

HI, ALL:
       Here is the detail steps, and will show bugs.


1) enter the musl's source code
cd /home/jjj/test/musl/


2) pull the newest codes
git pull origin master


3) export some toolchains, (Sourcery CodeBench Lite arm-2013.05-23-arm-none-eabi-i686-pc-linux-gnu.tar.bz2‍)
export PATH=$PATH:/home/jjj/software/eclipse-kepler-for-arm-gtk-linux-x86_64/compiler/arm-2013.05/bin/


4) configure musl to arm target
CC=arm-none-eabi-gcc CFLAGS="-mcpu=cortex-a8 -mtune=cortex-a8 -march=armv7-a -mfpu=neon -ftree-vectorize -ffast-math -mfloat-abi=softfp" ./configure --target=arm --prefix=/home/jjj/test/musl/usr/local/musl/


5) compiler musl and install
make
make install


6) export REALGCC to arm linux toolchains
export REALGCC=arm-none-eabi-gcc


7) write test cases and save to test.c
#include <stdio.h>
#include <math.h>


int main(int argc, char ** argv)
{
	double n = 0.0;
	int i;


	for(i = 0; i < 20; i++)
	{
		n = n - 0.125;
		printf("ceil(%f) = %f, floor(%f) = %f, round(%f) = %f\n", n, ceil(n), n, floor(n), n, round(n));
	}


	return 0;
}


8) compile test cases
./tools/musl-gcc test.c -o test -static


9) file test, will showing: test: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, not stripped
file test


10) running test case using qemu-arm
qemu-arm test


11) result...
ceil(-0.125000) = 0.000000, floor(-0.125000) = -1.000000, round(-0.125000) = 0.000000
ceil(-0.250000) = 0.000000, floor(-0.250000) = -1.000000, round(-0.250000) = 0.000000
ceil(-0.375000) = 0.000000, floor(-0.375000) = -1.000000, round(-0.375000) = 0.000000
ceil(-0.500000) = 0.000000, floor(-0.500000) = -1.000000, round(-0.500000) = -0.500000
ceil(-0.625000) = 0.000000, floor(-0.625000) = -1.000000, round(-0.625000) = -0.625000
ceil(-0.750000) = 0.000000, floor(-0.750000) = -1.000000, round(-0.750000) = -0.750000
ceil(-0.875000) = 0.000000, floor(-0.875000) = -1.000000, round(-0.875000) = -0.875000
ceil(-1.000000) = -1.000000, floor(-1.000000) = -1.000000, round(-1.000000) = -1.000000
ceil(-1.125000) = -1.125000, floor(-1.125000) = -1.125000, round(-1.125000) = -1.125000
ceil(-1.250000) = -1.250000, floor(-1.250000) = -1.250000, round(-1.250000) = -1.250000
ceil(-1.375000) = -1.375000, floor(-1.375000) = -1.375000, round(-1.375000) = -1.375000
ceil(-1.500000) = -1.500000, floor(-1.500000) = -1.500000, round(-1.500000) = -1.500000
ceil(-1.625000) = -1.625000, floor(-1.625000) = -1.625000, round(-1.625000) = -1.625000
ceil(-1.750000) = -1.750000, floor(-1.750000) = -1.750000, round(-1.750000) = -1.750000
ceil(-1.875000) = -1.875000, floor(-1.875000) = -1.875000, round(-1.875000) = -1.875000
ceil(-2.000000) = -2.000000, floor(-2.000000) = -2.000000, round(-2.000000) = -2.000000
ceil(-2.125000) = -2.125000, floor(-2.125000) = -2.125000, round(-2.125000) = -2.125000
ceil(-2.250000) = -2.250000, floor(-2.250000) = -2.250000, round(-2.250000) = -2.250000
ceil(-2.375000) = -2.375000, floor(-2.375000) = -2.375000, round(-2.375000) = -2.375000
ceil(-2.500000) = -2.500000, floor(-2.500000) = -2.500000, round(-2.500000) = -2.500000‍



please some body to fix these bugs, optimizing flags is very important for embedded platform, ‍
____________________________
蒋建军                            
深圳市九鼎创展科技有限公司
地址:深圳市宝安区西乡街道宝源路宝安互联网产业基地A区7栋301
邮编:518101
手机:18665386306
电邮:8192542@qq.com
网站:http://www.9tripod.com

论坛:http://xboot.org
 


 




------------------ 原始邮件 ------------------
发件人: "8192542";<8192542@qq.com>;
发送时间: 2014年10月14日(星期二) 下午2:26
收件人: "musl"<musl@lists.openwall.com>; 

主题: RE:[musl ] [math] I Found math library's bug in ceil, floor, round functions, Using arm toolchains



HI, ALL
     I found basic math functions bug, include ceil ,floor, round ... when using arm toolchains.


Here is the patch file, just for ceil.c :


diff --git a/src/math/ceil.c b/src/math/ceil.c
index 22dc224..8634145 100644
--- a/src/math/ceil.c
+++ b/src/math/ceil.c
@@ -4,15 +4,16 @@ double ceil(double x)
 {
 	union {double f; uint64_t i;} u = {x};
 	int e = u.i >> 52 & 0x7ff;
+	uint64_t n = 0x1p52;
 	double_t y;
 
 	if (e >= 0x3ff+52 || x == 0)
 		return x;
 	/* y = int(x) - x, where int(x) is an integer neighbor of x */
 	if (u.i >> 63)
-		y = (double)(x - 0x1p52) + 0x1p52 - x;
+		y = (double)(x - n) + n - x;
 	else
-		y = (double)(x + 0x1p52) - 0x1p52 - x;
+		y = (double)(x + n) - n - x;
 	/* special case because of non-nearest rounding modes */
 	if (e <= 0x3ff-1) {
 		FORCE_EVAL(y);‍



To solve this problem, must define a variate:  uint64_t n = 0x1p52;
using n to instead of 0x1p52, then all result are correctly.‍


The compile flags:
MCFLAGS		:= -mcpu=cortex-a8 -mtune=cortex-a8 -march=armv7-a -mfpu=neon -ftree-vectorize -ffast-math -mfloat-abi=softfp‍


I belive, when using this flags, the bug will happen. any one tell me how to solve it. we need optimizing flags to compile musl libc.‍


Thanks Rich Felker's help!


------------------
____________________________
蒋建军                            
深圳市九鼎创展科技有限公司
地址:深圳市宝安区西乡街道宝源路宝安互联网产业基地A区7栋301
邮编:518101
手机:18665386306
电邮:8192542@qq.com
网站:http://www.9tripod.com

论坛:http://xboot.org
 


 




------------------ 原始邮件 ------------------
发件人: "8192542";<8192542@qq.com>;
发送时间: 2014年10月14日(星期二) 中午12:11
收件人: "musl"<musl@lists.openwall.com>; 
抄送: "musl"<musl@lists.openwall.com>; 
主题: 回复: [musl] 回复: [musl ] [math] The math library have some bugforceil,floor,round functioin, in arm mode



1) enter the musl's source code
cd /home/jjj/test/musl/


2) pull the newest codes
git pull origin master


3) export some toolchains
export PATH=$PATH:/home/jjj/9tripod/android_exynos4412_ics_rtm_v10/prebuilt/linux-x86/toolchain/arm-2009q3/bin/


4) configure musl to arm target
CC=arm-none-linux-gnueabi-gcc ./configure --target=arm --prefix=/home/jjj/test/musl/usr/local/musl/


5) compiler musl and install
make
make install


6) export REALGCC to arm linux toolchains
export REALGCC=arm-none-linux-gnueabi-gcc


7) write test cases and save to test.c
#include <stdio.h>
#include <math.h>


int main(int argc, char ** argv)
{
	double n = 0.0;
	int i;


	for(i = 0; i < 20; i++)
	{
		n = n - 0.125;
		printf("ceil(%f) = %f, floor(%f) = %f, round(%f) = %f\n", n, ceil(n), n, floor(n), n, round(n));
	}


	return 0;
}


8) compile test cases
./tools/musl-gcc test.c -o test -static


9) file test, will showing: test: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, not stripped
file test


10) running test case using qemu-arm
qemu-arm test


11) result...
ceil(-0.125000) = -0.000000, floor(-0.125000) = -1.000000, round(-0.125000) = -0.000000
ceil(-0.250000) = -0.000000, floor(-0.250000) = -1.000000, round(-0.250000) = -0.000000
ceil(-0.375000) = -0.000000, floor(-0.375000) = -1.000000, round(-0.375000) = -0.000000
ceil(-0.500000) = -0.000000, floor(-0.500000) = -1.000000, round(-0.500000) = -1.000000
ceil(-0.625000) = -0.000000, floor(-0.625000) = -1.000000, round(-0.625000) = -1.000000
ceil(-0.750000) = -0.000000, floor(-0.750000) = -1.000000, round(-0.750000) = -1.000000
ceil(-0.875000) = -0.000000, floor(-0.875000) = -1.000000, round(-0.875000) = -1.000000
ceil(-1.000000) = -1.000000, floor(-1.000000) = -1.000000, round(-1.000000) = -1.000000
ceil(-1.125000) = -1.000000, floor(-1.125000) = -2.000000, round(-1.125000) = -1.000000
ceil(-1.250000) = -1.000000, floor(-1.250000) = -2.000000, round(-1.250000) = -1.000000
ceil(-1.375000) = -1.000000, floor(-1.375000) = -2.000000, round(-1.375000) = -1.000000
ceil(-1.500000) = -1.000000, floor(-1.500000) = -2.000000, round(-1.500000) = -2.000000
ceil(-1.625000) = -1.000000, floor(-1.625000) = -2.000000, round(-1.625000) = -2.000000
ceil(-1.750000) = -1.000000, floor(-1.750000) = -2.000000, round(-1.750000) = -2.000000
ceil(-1.875000) = -1.000000, floor(-1.875000) = -2.000000, round(-1.875000) = -2.000000
ceil(-2.000000) = -2.000000, floor(-2.000000) = -2.000000, round(-2.000000) = -2.000000
ceil(-2.125000) = -2.000000, floor(-2.125000) = -3.000000, round(-2.125000) = -2.000000
ceil(-2.250000) = -2.000000, floor(-2.250000) = -3.000000, round(-2.250000) = -2.000000
ceil(-2.375000) = -2.000000, floor(-2.375000) = -3.000000, round(-2.375000) = -2.000000
ceil(-2.500000) = -2.000000, floor(-2.500000) = -3.000000, round(-2.500000) = -3.000000


Using qemu-arm, the result is correct. we will test in real hardware and review result, and find bug somewhere
‍




------------------
____________________________
蒋建军                            
深圳市九鼎创展科技有限公司
地址:深圳市宝安区西乡街道宝源路宝安互联网产业基地A区7栋301
邮编:518101
手机:18665386306
电邮:8192542@qq.com
网站:http://www.9tripod.com

论坛:http://xboot.org
 


 




------------------ 原始邮件 ------------------
发件人: "Rich Felker";<dalias@libc.org>;
发送时间: 2014年10月14日(星期二) 中午11:03
收件人: "bobodog"<8192542@qq.com>; 
抄送: "musl"<musl@lists.openwall.com>; 
主题: Re: [musl] 回复: [musl ] [math] The math library have some bugforceil,floor,round functioin, in arm mode



On Tue, Oct 14, 2014 at 10:51:58AM +0800, bobodog wrote:
> Test it in qemu-system-arm, with soft fp, realview-pb-a8 platform‍
> 
> we porting musl to our project, and just write test functions to
> test cases, i don't kown, how to test musl in origin test cases.

Can you show a complete test program with correct prototypes for
printf, ceil, floor, and round that exhibits the problem for you?

Rich

[-- Attachment #2: Type: text/html, Size: 21867 bytes --]

  reply	other threads:[~2014-10-14  6:43 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-14  2:17 [math] The math library have some bug for ceil,floor,round functioin, in arm mode bobodog
2014-10-14  2:42 ` Rich Felker
2014-10-14  2:51   ` 回复: [musl] [math] The math library have some bug forceil,floor,round " bobodog
2014-10-14  3:03     ` Rich Felker
2014-10-14  4:11       ` 回复: [musl] 回复: [musl ] [math] The math library have some bugforceil,floor,round " bobodog
2014-10-14  6:26         ` RE:[musl ] [math] I Found math library's bug in ceil, floor, round functions, Using arm toolchains bobodog
2014-10-14  6:43           ` bobodog [this message]
     [not found]             ` <tencent_07C7708762DD414A5A757808@qq.com>
2014-10-14 15:12               ` RE:[BUG][math]build musl with optimizing flags, some math functions are broken Rich Felker
2014-10-14 15:33               ` RE???[BUG][math]build " Szabolcs Nagy
2014-10-14  8:06           ` RE???[musl ] [math] I Found math library's bug in ceil, floor, round functions, Using arm toolchains Szabolcs Nagy
2014-10-14  3:04     ` 回复: [musl] The math library have some bug forceil,floor,round functioin, in arm mode bobodog

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tencent_367F8384572400D944A791F3@qq.com \
    --to=8192542@qq.com \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).