mailing list of musl libc
 help / color / mirror / code / Atom feed
* [math] The math library have some bug for ceil,floor,round functioin, in arm mode
@ 2014-10-14  2:17 bobodog
  2014-10-14  2:42 ` Rich Felker
  0 siblings, 1 reply; 11+ messages in thread
From: bobodog @ 2014-10-14  2:17 UTC (permalink / raw)
  To: musl

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

HI,ALL
         We use musl in arm process, but found some bugs about math library,  x86 process is ok!


         Here the test result:
         1) In ARM mode: (the result is wrong)


[    9.235921][kernel/command/cmd-test.c:44] ceil(-0.125000) = 0.000000, floor(-0.125000) = -1.000000, round(-0.125000) = 0.000000
[    9.238523][kernel/command/cmd-test.c:44] ceil(-0.250000) = 0.000000, floor(-0.250000) = -1.000000, round(-0.250000) = 0.000000
[    9.239770][kernel/command/cmd-test.c:44] ceil(-0.375000) = 0.000000, floor(-0.375000) = -1.000000, round(-0.375000) = 0.000000
[    9.241081][kernel/command/cmd-test.c:44] ceil(-0.500000) = 0.000000, floor(-0.500000) = -1.000000, round(-0.500000) = -0.500000
[    9.242361][kernel/command/cmd-test.c:44] ceil(-0.625000) = 0.000000, floor(-0.625000) = -1.000000, round(-0.625000) = -0.625000
[    9.243637][kernel/command/cmd-test.c:44] ceil(-0.750000) = 0.000000, floor(-0.750000) = -1.000000, round(-0.750000) = -0.750000
[    9.244879][kernel/command/cmd-test.c:44] ceil(-0.875000) = 0.000000, floor(-0.875000) = -1.000000, round(-0.875000) = -0.875000
[    9.246183][kernel/command/cmd-test.c:44] ceil(-1.000000) = -1.000000, floor(-1.000000) = -1.000000, round(-1.000000) = -1.000000
[    9.247457][kernel/command/cmd-test.c:44] ceil(-1.125000) = -1.125000, floor(-1.125000) = -1.125000, round(-1.125000) = -1.125000
[    9.248333][kernel/command/cmd-test.c:44] ceil(-1.250000) = -1.250000, floor(-1.250000) = -1.250000, round(-1.250000) = -1.250000
[    9.249303][kernel/command/cmd-test.c:44] ceil(-1.375000) = -1.375000, floor(-1.375000) = -1.375000, round(-1.375000) = -1.375000
[    9.250456][kernel/command/cmd-test.c:44] ceil(-1.500000) = -1.500000, floor(-1.500000) = -1.500000, round(-1.500000) = -1.500000
[    9.251730][kernel/command/cmd-test.c:44] ceil(-1.625000) = -1.625000, floor(-1.625000) = -1.625000, round(-1.625000) = -1.625000
[    9.252975][kernel/command/cmd-test.c:44] ceil(-1.750000) = -1.750000, floor(-1.750000) = -1.750000, round(-1.750000) = -1.750000
[    9.254272][kernel/command/cmd-test.c:44] ceil(-1.875000) = -1.875000, floor(-1.875000) = -1.875000, round(-1.875000) = -1.875000
[    9.255563][kernel/command/cmd-test.c:44] ceil(-2.000000) = -2.000000, floor(-2.000000) = -2.000000, round(-2.000000) = -2.000000
[    9.256813][kernel/command/cmd-test.c:44] ceil(-2.125000) = -2.125000, floor(-2.125000) = -2.125000, round(-2.125000) = -2.125000
[    9.257610][kernel/command/cmd-test.c:44] ceil(-2.250000) = -2.250000, floor(-2.250000) = -2.250000, round(-2.250000) = -2.250000
[    9.258029][kernel/command/cmd-test.c:44] ceil(-2.375000) = -2.375000, floor(-2.375000) = -2.375000, round(-2.375000) = -2.375000
[    9.259500][kernel/command/cmd-test.c:44] ceil(-2.500000) = -2.500000, floor(-2.500000) = -2.500000, round(-2.500000) = -2.500000
‍

         2) In X86 mode: (the result is correct)
[    3.790000][kernel/command/cmd-test.c:44] ceil(-0.125000) = 0.000000, floor(-0.125000) = -1.000000, round(-0.125000) = 0.000000
[    3.790000][kernel/command/cmd-test.c:44] ceil(-0.250000) = 0.000000, floor(-0.250000) = -1.000000, round(-0.250000) = 0.000000
[    3.790000][kernel/command/cmd-test.c:44] ceil(-0.375000) = 0.000000, floor(-0.375000) = -1.000000, round(-0.375000) = 0.000000
[    3.790000][kernel/command/cmd-test.c:44] ceil(-0.500000) = 0.000000, floor(-0.500000) = -1.000000, round(-0.500000) = -1.000000
[    3.790000][kernel/command/cmd-test.c:44] ceil(-0.625000) = 0.000000, floor(-0.625000) = -1.000000, round(-0.625000) = -1.000000
[    3.790000][kernel/command/cmd-test.c:44] ceil(-0.750000) = 0.000000, floor(-0.750000) = -1.000000, round(-0.750000) = -1.000000
[    3.790000][kernel/command/cmd-test.c:44] ceil(-0.875000) = 0.000000, floor(-0.875000) = -1.000000, round(-0.875000) = -1.000000
[    3.790000][kernel/command/cmd-test.c:44] ceil(-1.000000) = -1.000000, floor(-1.000000) = -1.000000, round(-1.000000) = -1.000000
[    3.790000][kernel/command/cmd-test.c:44] ceil(-1.125000) = -1.000000, floor(-1.125000) = -2.000000, round(-1.125000) = -1.000000
[    3.790000][kernel/command/cmd-test.c:44] ceil(-1.250000) = -1.000000, floor(-1.250000) = -2.000000, round(-1.250000) = -1.000000
[    3.790000][kernel/command/cmd-test.c:44] ceil(-1.375000) = -1.000000, floor(-1.375000) = -2.000000, round(-1.375000) = -1.000000
[    3.790000][kernel/command/cmd-test.c:44] ceil(-1.500000) = -1.000000, floor(-1.500000) = -2.000000, round(-1.500000) = -2.000000
[    3.790000][kernel/command/cmd-test.c:44] ceil(-1.625000) = -1.000000, floor(-1.625000) = -2.000000, round(-1.625000) = -2.000000
[    3.790000][kernel/command/cmd-test.c:44] ceil(-1.750000) = -1.000000, floor(-1.750000) = -2.000000, round(-1.750000) = -2.000000
[    3.790000][kernel/command/cmd-test.c:44] ceil(-1.875000) = -1.000000, floor(-1.875000) = -2.000000, round(-1.875000) = -2.000000
[    3.790000][kernel/command/cmd-test.c:44] ceil(-2.000000) = -2.000000, floor(-2.000000) = -2.000000, round(-2.000000) = -2.000000
[    3.790000][kernel/command/cmd-test.c:44] ceil(-2.125000) = -2.000000, floor(-2.125000) = -3.000000, round(-2.125000) = -2.000000
[    3.790000][kernel/command/cmd-test.c:44] ceil(-2.250000) = -2.000000, floor(-2.250000) = -3.000000, round(-2.250000) = -2.000000
[    3.790000][kernel/command/cmd-test.c:44] ceil(-2.375000) = -2.000000, floor(-2.375000) = -3.000000, round(-2.375000) = -2.000000
[    3.790000][kernel/command/cmd-test.c:44] ceil(-2.500000) = -2.000000, floor(-2.500000) = -3.000000, round(-2.500000) = -3.000000


        The test code:
int test(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;
}‍


       May be rint trunc have same problem. this is supper big bug!!!


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

论坛:http://xboot.org

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [math] The math library have some bug for ceil,floor,round functioin, in arm mode
  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
  0 siblings, 1 reply; 11+ messages in thread
From: Rich Felker @ 2014-10-14  2:42 UTC (permalink / raw)
  To: bobodog; +Cc: musl

On Tue, Oct 14, 2014 at 10:17:34AM +0800, bobodog wrote:
> HI,ALL
>          We use musl in arm process, but found some bugs about math library,  x86 process is ok!

I can't reproduce this issue. Are you using soft (arm) or hard (armhf)
float based target?

>         The test code:
> int test(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;
> }‍

Is this the whole test program? I don't see a main function or any
#include directives. Compiling it with gcc -Dtest=main results in:

foo.c:10:17: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
foo.c:10:78: warning: incompatible implicit declaration of built-in function ‘ceil’ [enabled by default]
foo.c:10:90: warning: incompatible implicit declaration of built-in function ‘floor’ [enabled by default]
foo.c:10:103: warning: incompatible implicit declaration of built-in function ‘round’ [enabled by default]

These warnings should all be treated as errors; calling a function
with variadic arguments (printf) or a function that returns a floating
point type without a valid declaration/prototype is a serious error
and will not work.

Rich


^ permalink raw reply	[flat|nested] 11+ messages in thread

* 回复: [musl] [math] The math library have some bug forceil,floor,round functioin, in arm mode
  2014-10-14  2:42 ` Rich Felker
@ 2014-10-14  2:51   ` bobodog
  2014-10-14  3:03     ` Rich Felker
  2014-10-14  3:04     ` 回复: [musl] The math library have some bug forceil,floor,round functioin, in arm mode bobodog
  0 siblings, 2 replies; 11+ messages in thread
From: bobodog @ 2014-10-14  2:51 UTC (permalink / raw)
  To: musl; +Cc: musl

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

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.


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

论坛:http://xboot.org
 


 




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



On Tue, Oct 14, 2014 at 10:17:34AM +0800, bobodog wrote:
> HI,ALL
>          We use musl in arm process, but found some bugs about math library,  x86 process is ok!

I can't reproduce this issue. Are you using soft (arm) or hard (armhf)
float based target?

>         The test code:
> int test(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;
> }‍

Is this the whole test program? I don't see a main function or any
#include directives. Compiling it with gcc -Dtest=main results in:

foo.c:10:17: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
foo.c:10:78: warning: incompatible implicit declaration of built-in function ‘ceil’ [enabled by default]
foo.c:10:90: warning: incompatible implicit declaration of built-in function ‘floor’ [enabled by default]
foo.c:10:103: warning: incompatible implicit declaration of built-in function ‘round’ [enabled by default]

These warnings should all be treated as errors; calling a function
with variadic arguments (printf) or a function that returns a floating
point type without a valid declaration/prototype is a serious error
and will not work.

Rich

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: 回复: [musl] [math] The math library have some bug forceil,floor,round functioin, in arm mode
  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  3:04     ` 回复: [musl] The math library have some bug forceil,floor,round functioin, in arm mode bobodog
  1 sibling, 1 reply; 11+ messages in thread
From: Rich Felker @ 2014-10-14  3:03 UTC (permalink / raw)
  To: bobodog; +Cc: musl

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* 回复: [musl] The math library have some bug forceil,floor,round functioin, in arm mode
  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  3:04     ` bobodog
  1 sibling, 0 replies; 11+ messages in thread
From: bobodog @ 2014-10-14  3:04 UTC (permalink / raw)
  To: musl; +Cc: musl

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

I check the musl git repo, found one commit: 


d1a2ead878c27ac4ec600740320f8b76e1f961e9‍
math: rewrite rounding functions (ceil, floor, trunc, round, rint)‍


The old version of ceil and floor functions are tests ok in arm mode.
Here the some old codes:


static const double huge = 1.0e300;


double ceil(double x)
{
	int32_t i0,i1,j0;
	uint32_t i,j;


	EXTRACT_WORDS(i0, i1, x);
	// FIXME signed shift
	j0 = ((i0>>20)&0x7ff) - 0x3ff;
	if (j0 < 20) {
		if (j0 < 0) {
			 /* raise inexact if x != 0 */
			if (huge+x > 0.0) {
				if (i0 < 0) {
					i0 = 0x80000000;
					i1=0;
				} else if ((i0|i1) != 0) {
					i0=0x3ff00000;
					i1=0;
				}
			}
		} else {
			i = 0x000fffff>>j0;
			if (((i0&i)|i1) == 0) /* x is integral */
				return x;
			/* raise inexact flag */
			if (huge+x > 0.0) {
				if (i0 > 0)
					i0 += 0x00100000>>j0;
				i0 &= ~i;
				i1 = 0;
			}
		}
	} else if (j0 > 51) {
		if (j0 == 0x400)  /* inf or NaN */
			return x+x;
		return x;         /* x is integral */
	} else {
		i = (uint32_t)0xffffffff>>(j0-20);
		if ((i1&i) == 0)
			return x; /* x is integral */
		/* raise inexact flag */
		if (huge+x > 0.0) {
			if (i0 > 0) {
				if (j0 == 20)
					i0 += 1;
				else {
					j = i1 + (1<<(52-j0));
					if (j < i1)  /* got a carry */
						i0 += 1;
					i1 = j;
				}
			}
			i1 &= ~i;
		}
	}
	INSERT_WORDS(x, i0, i1);
	return x;
}‍



The old code test in x86 mode passed!


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

论坛:http://xboot.org
 


 




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



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.


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

论坛:http://xboot.org
 


 




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



On Tue, Oct 14, 2014 at 10:17:34AM +0800, bobodog wrote:
> HI,ALL
>          We use musl in arm process, but found some bugs about math library,  x86 process is ok!

I can't reproduce this issue. Are you using soft (arm) or hard (armhf)
float based target?

>         The test code:
> int test(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;
> }‍

Is this the whole test program? I don't see a main function or any
#include directives. Compiling it with gcc -Dtest=main results in:

foo.c:10:17: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
foo.c:10:78: warning: incompatible implicit declaration of built-in function ‘ceil’ [enabled by default]
foo.c:10:90: warning: incompatible implicit declaration of built-in function ‘floor’ [enabled by default]
foo.c:10:103: warning: incompatible implicit declaration of built-in function ‘round’ [enabled by default]

These warnings should all be treated as errors; calling a function
with variadic arguments (printf) or a function that returns a floating
point type without a valid declaration/prototype is a serious error
and will not work.

Rich

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* 回复: [musl] 回复: [musl ] [math] The math library have some bugforceil,floor,round functioin, in arm mode
  2014-10-14  3:03     ` Rich Felker
@ 2014-10-14  4:11       ` bobodog
  2014-10-14  6:26         ` RE:[musl ] [math] I Found math library's bug in ceil, floor, round functions, Using arm toolchains bobodog
  0 siblings, 1 reply; 11+ messages in thread
From: bobodog @ 2014-10-14  4:11 UTC (permalink / raw)
  To: musl; +Cc: musl

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

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: 7807 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* RE:[musl ] [math] I Found math library's bug in ceil, floor, round functions, Using arm toolchains
  2014-10-14  4:11       ` 回复: [musl] 回复: [musl ] [math] The math library have some bugforceil,floor,round " bobodog
@ 2014-10-14  6:26         ` bobodog
  2014-10-14  6:43           ` [BUG][math]build musl with optimizing flags, some math functions are broken bobodog
  2014-10-14  8:06           ` RE???[musl ] [math] I Found math library's bug in ceil, floor, round functions, Using arm toolchains Szabolcs Nagy
  0 siblings, 2 replies; 11+ messages in thread
From: bobodog @ 2014-10-14  6:26 UTC (permalink / raw)
  To: musl

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

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: 14206 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [BUG][math]build musl with optimizing flags, some math functions are broken.
  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
       [not found]             ` <tencent_07C7708762DD414A5A757808@qq.com>
  2014-10-14  8:06           ` RE???[musl ] [math] I Found math library's bug in ceil, floor, round functions, Using arm toolchains Szabolcs Nagy
  1 sibling, 1 reply; 11+ messages in thread
From: bobodog @ 2014-10-14  6:43 UTC (permalink / raw)
  To: musl

[-- 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 --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: RE???[musl ] [math] I Found math library's bug in ceil, floor, round functions, Using arm toolchains
  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           ` [BUG][math]build musl with optimizing flags, some math functions are broken bobodog
@ 2014-10-14  8:06           ` Szabolcs Nagy
  1 sibling, 0 replies; 11+ messages in thread
From: Szabolcs Nagy @ 2014-10-14  8:06 UTC (permalink / raw)
  To: musl

* bobodog <8192542@qq.com> [2014-10-14 14:26:01 +0800]:
> 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.???
> 

this is not necessary (and possibly makes things slower)
in c99 the difference must not be observable, your compiler is broken if it is

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

never ever -ffast-math

if you use that flag all bets are off

> 
> 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.???
> 

when compiling libc dont use that flag

otherwise you can use it but i strongly suggest not to,
unless you are fully aware of the consequences


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: RE:[BUG][math]build musl with optimizing flags, some math functions are broken.
       [not found]             ` <tencent_07C7708762DD414A5A757808@qq.com>
@ 2014-10-14 15:12               ` Rich Felker
  2014-10-14 15:33               ` RE???[BUG][math]build " Szabolcs Nagy
  1 sibling, 0 replies; 11+ messages in thread
From: Rich Felker @ 2014-10-14 15:12 UTC (permalink / raw)
  To: bobodog; +Cc: musl

On Tue, Oct 14, 2014 at 03:09:45PM +0800, bobodog wrote:
> Further confirmation, the problem is -ffast-math flag, just remove
> this flag, all tests passed, please fix this bug, the openbsd's msun
> math library, have not any problem with this flags.

This is not a bug. The documented purpose of the -ffast-math flag is
to unconstrain the compiler from having to provide correct results for
floating point math operation, in hopes of producing faster code. It
is documented as:

    Sets -fno-math-errno, -funsafe-math-optimizations,
    -ffinite-math-only, -fno-rounding-math, -fno-signaling-nans and
    -fcx-limited-range. This option causes the preprocessor macro
    __FAST_MATH__ to be defined.

    This option is not turned on by any -O option besides -Ofast since
    it can result in incorrect output for programs that depend on an
    exact implementation of IEEE or ISO rules/specifications for math
    functions. It may, however, yield faster code for programs that do
    not require the guarantees of these specifications.

(Source: https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html)

The patches you provided are not valid; they simply cause
perturbations in the compiler's output that makes the functions happen
to work for your particular version of GCC and CFLAGS. But there is no
reason they should make it work. The problem is -ffast-math. The only
way to implement the math part of the standard library that's
compatible with -ffast-math would be to write the whole thing using
explicit soft-float, which would be very slow.

Just remove -ffast-math and the problem should go away.

Note that -mfpu=neon may also break some things in the standard
library, and it will not help. There are no functions in the standard
library which benefit from vectorization of floating point math. The
breakage from using neon should be much smaller (probably limited to
cases of denormal arguments) but you're not gaining anything by using
it, so it would make sense to remove that too.

There is nothing wrong with using -ffast-math or -mfpu=neon to compile
your _applications_ as long as those applications don't need
rigorously correct math results. But these options should not be used
for compiling the standard library.

Rich


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: RE???[BUG][math]build musl with optimizing flags, some math functions are broken.
       [not found]             ` <tencent_07C7708762DD414A5A757808@qq.com>
  2014-10-14 15:12               ` RE:[BUG][math]build " Rich Felker
@ 2014-10-14 15:33               ` Szabolcs Nagy
  1 sibling, 0 replies; 11+ messages in thread
From: Szabolcs Nagy @ 2014-10-14 15:33 UTC (permalink / raw)
  To: musl

* bobodog <8192542@qq.com> [2014-10-14 15:09:45 +0800]:
> Further confirmation, the problem is -ffast-math flag, just remove this flag, all tests passed, please fix this bug, the openbsd's msun math library, have not any problem with this flags.
> 

how did you verify that openbsd "have not any problem with this flag" ?

(without looking at your methodology i can guarantee that openbsd
msun math library is completely broken with gcc -ffast-math too

unless openbsd explicitly disabled this option in their compiler..
they maintain their own compiler so they can implement -ffast-math
as a no-op, but a modern unpatched gcc with -ffast-math breaks all
math functions which depend on exact ieee arithmetics)


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2014-10-14 15:33 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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           ` [BUG][math]build musl with optimizing flags, some math functions are broken bobodog
     [not found]             ` <tencent_07C7708762DD414A5A757808@qq.com>
2014-10-14 15:12               ` RE:[BUG][math]build " 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

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).