Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <tencent_367F8384572400D944A791F3@qq.com>
Date: Tue, 14 Oct 2014 14:43:44 +0800
From: "bobodog" <8192542@...com>
To: "musl" <musl@...ts.openwall.com>
Subject: [BUG][math]build musl with optimizing flags, some math functions are broken.

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@...com
网站:http://www.9tripod.com

论坛:http://xboot.org
 


 




------------------ 原始邮件 ------------------
发件人: "8192542";<8192542@...com>;
发送时间: 2014年10月14日(星期二) 下午2:26
收件人: "musl"<musl@...ts.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@...com
网站:http://www.9tripod.com

论坛:http://xboot.org
 


 




------------------ 原始邮件 ------------------
发件人: "8192542";<8192542@...com>;
发送时间: 2014年10月14日(星期二) 中午12:11
收件人: "musl"<musl@...ts.openwall.com>; 
抄送: "musl"<musl@...ts.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@...com
网站:http://www.9tripod.com

论坛:http://xboot.org
 


 




------------------ 原始邮件 ------------------
发件人: "Rich Felker";<dalias@...c.org>;
发送时间: 2014年10月14日(星期二) 中午11:03
收件人: "bobodog"<8192542@...com>; 
抄送: "musl"<musl@...ts.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
Content of type "text/html" skipped

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.