Issue #8358 has been updated by Anatol Pomozov.


I maintain ruby package in Linux Arch and our users reported an issue with it https://bugs.archlinux.org/task/39470

We compile 32-bit binaries for old machines (PentiumPro+ CPU). The old CPUs do not have SSE2 support, but we've found that our 32-bit kernels contain SSE2 operations.

~~~
$ objdump -d /usr/lib/libruby.so | grep movapd | head
2c743: 66 0f 28 c8 movapd %xmm0,%xmm1
2c7e5: 66 0f 28 9b 10 89 f4 movapd -0xb76f0(%ebx),%xmm3
2c800: 66 0f 28 f3 movapd %xmm3,%xmm6
2c808: 66 0f 28 fb movapd %xmm3,%xmm7
32676: 66 0f 28 c8 movapd %xmm0,%xmm1
765d5: 66 0f 28 8b 10 89 f4 movapd -0xb76f0(%ebx),%xmm1
~~~

After I reverted the whole sse2 block

~~~
-    AS_CASE(["$target"],
-       [*-darwin*], [
-           # doesn't seem necessary on Mac OS X
-       ],
-       [[i[4-6]86*]], [
-           RUBY_TRY_CFLAGS(-msse2 -mfpmath=sse, [
-               RUBY_APPEND_OPTION(XCFLAGS, -msse2 -mfpmath=sse)
-           ])
-            AS_CASE(["$XCFLAGS"],
-                [[*-msse2*]], [
-                    RUBY_TRY_CFLAGS(-mstackrealign, [
-                        RUBY_APPEND_OPTION(XCFLAGS, -mstackrealign)
-                    ])
-                ])
-       ]
-    )
~~~

i686 binaries do not contain sse2 operations anymore, x86_64 (64 bit binaries for newer CPU) contain sse2 as expected. Tests "make test" are passed.


Here are the compilation flags uses on Arch:

~~~
config.status: creating x86_64-linux-fake.rb
	CC = gcc
	LD = ld
	LDSHARED = gcc -shared
	CFLAGS = -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector --param=ssp-buffer-size=4 -fPIC 
	XCFLAGS = -D_FORTIFY_SOURCE=2 -fstack-protector -fno-strict-overflow -fvisibility=hidden -DRUBY_EXPORT
	CPPFLAGS = -D_FORTIFY_SOURCE=2   -I. -I.ext/include/x86_64-linux -I./include -I.
	DLDFLAGS = -Wl,-soname,libruby.so.2.1  -fstack-protector  
	SOLIBS = -lpthread -lgmp -ldl -lcrypt -lm  
~~~

Note to "-march=x86-64" it is for 64-bit builds, on 32-bit builds it is "-march=i686". I believe this flags are enough to tell gcc whether sse2 should be enabled. compiler (at least on Linux Arch) does not need additional sse2 compilation flags.

So my question: why to enable sse2 if the binary is compiled for i686 microarchitecture? "i686" is PentiumPro family that does not support sse2, sse2 is supported only starting from pentium4. See http://gcc.gnu.org/onlinedocs/gcc-4.8.2/gcc/i386-and-x86-64-Options.html#i386-and-x86-64-Options

----------------------------------------
Bug #8358: TestSprintf#test_float test failuer
https://bugs.ruby-lang.org/issues/8358#change-45846

* Author: Heesob Park
* Status: Assigned
* Priority: Immediate
* Assignee: Yui NARUSE
* Category: build
* Target version: current: 2.2.0
* ruby -v: ruby 2.1.0dev (2013-05-01) [i386-mingw32]
* Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN
----------------------------------------
I noticed TestSprintf#test_float
http://ci.rubyinstaller.org/job/ruby-trunk-x86-test-all/1287/console
  1) Failure:
TestSprintf#test_float [C:/Users/Worker/Jenkins/workspace/ruby-trunk-x86-build/test/ruby/test_sprintf.rb:193]:
[ruby-dev:42551].
<"0x1p+2"> expected but was
<"0x1p+1">.

This failure is due to r40404.

And Actually, this issue is almost same to bug #8299.
ruby_hdtoa function requires 53-bit precision 
but mingw32 compiler is 64-bit precision.

There are 2 possible workarounds.

1. adding  -msse2 -mfpmath=sse flag when compiling.
2. adding  _control87(_PC_53, _MCW_PC) when running.


---Files--------------------------------
0001-Properly-detect-platform-for-SSE2-instructions.patch (754 Bytes)


-- 
httsp://bugs.ruby-lang.org/