diff mbox

[v3] libstdc++/54869

Message ID 50743B33.5040502@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Oct. 9, 2012, 2:56 p.m. UTC
HI,

apparently simd_fast_mersenne_twister_engine is designed (so far) for 
little endian targets only.

Patch sanity checked x86_64-linux (with the __BYTE_ORDER__ == 
__ORDER_LITTLE_ENDIAN__ checks artificially altered to return false too)

Thanks,
Paolo.

///////////////////////
2012-10-09  Paolo Carlini  <paolo.carlini@oracle.com>

	PR libstdc++/54869
	* include/ext/random (simd_fast_mersenne_twister_engine): Provide
	only for little endian targets.
	* include/ext/random.tcc: Likewise.
	* config/cpu/i486/opt/ext/opt_random.h: Likewise.
	* testsuite/lib/libstdc++.exp (check_v3_target_little_endian): Add.
	* testsuite/lib/dg-options.exp (dg-require-little-endian): Add.
	* testsuite/ext/random/simd_fast_mersenne_twister_engine/
	operators/equal.cc: Use the latter.
	* testsuite/ext/random/simd_fast_mersenne_twister_engine/
	operators/serialize.cc: Likewise.
	* testsuite/ext/random/simd_fast_mersenne_twister_engine/
	operators/inequal.cc: Likewise.
	* testsuite/ext/random/simd_fast_mersenne_twister_engine/
	cons/copy.cc: Likewise.
	* testsuite/ext/random/simd_fast_mersenne_twister_engine/
	cons/seed1.cc: Likewise.
	* testsuite/ext/random/simd_fast_mersenne_twister_engine/
	cons/seed2.cc: Likewise.
	* testsuite/ext/random/simd_fast_mersenne_twister_engine/
	cons/default.cc: Likewise.
	* testsuite/ext/random/simd_fast_mersenne_twister_engine/
	cons/seed_seq.cc: Likewise.

Comments

Rainer Orth Oct. 9, 2012, 3:04 p.m. UTC | #1
Paolo Carlini <paolo.carlini@oracle.com> writes:

> apparently simd_fast_mersenne_twister_engine is designed (so far) for
> little endian targets only.
>
> Patch sanity checked x86_64-linux (with the __BYTE_ORDER__ ==
> __ORDER_LITTLE_ENDIAN__ checks artificially altered to return false too)

Isn't this too much?  As described in the PR, only
ext/random/simd_fast_mersenne_twister_engine/cons/default.cc was failing.

	Rainer
Paolo Carlini Oct. 9, 2012, 3:11 p.m. UTC | #2
On 10/09/2012 05:04 PM, Rainer Orth wrote:
> Paolo Carlini <paolo.carlini@oracle.com> writes:
>
>> apparently simd_fast_mersenne_twister_engine is designed (so far) for
>> little endian targets only.
>>
>> Patch sanity checked x86_64-linux (with the __BYTE_ORDER__ ==
>> __ORDER_LITTLE_ENDIAN__ checks artificially altered to return false too)
> Isn't this too much?  As described in the PR, only
> ext/random/simd_fast_mersenne_twister_engine/cons/default.cc was failing.
Isn't. Uli clearly explained that the engine is designed for little 
endian. Indeed, if default.cc fails, it means something is very, very, 
seriously broken.

Paolo.
diff mbox

Patch

Index: testsuite/ext/random/simd_fast_mersenne_twister_engine/operators/equal.cc
===================================================================
--- testsuite/ext/random/simd_fast_mersenne_twister_engine/operators/equal.cc	(revision 192245)
+++ testsuite/ext/random/simd_fast_mersenne_twister_engine/operators/equal.cc	(working copy)
@@ -1,10 +1,11 @@ 
 // { dg-options "-std=c++0x" }
 // { dg-require-cstdint "" }
+// { dg-require-little-endian "" }
 //
 // 2008-11-24  Edward M. Smith-Rowland <3dw4rd@verizon.net>
 // 2012-08-28  Ulrich Drepper  <drepper@gmail.com>, adapted for SFMT
 //
-// Copyright (C) 2008, 2009, 2012 Free Software Foundation, Inc.
+// Copyright (C) 2008-2012 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
Index: testsuite/ext/random/simd_fast_mersenne_twister_engine/operators/serialize.cc
===================================================================
--- testsuite/ext/random/simd_fast_mersenne_twister_engine/operators/serialize.cc	(revision 192245)
+++ testsuite/ext/random/simd_fast_mersenne_twister_engine/operators/serialize.cc	(working copy)
@@ -1,10 +1,11 @@ 
 // { dg-options "-std=c++0x" }
 // { dg-require-cstdint "" }
+// { dg-require-little-endian "" }
 //
 // 2008-11-24  Edward M. Smith-Rowland <3dw4rd@verizon.net>
 // 2012-08-28  Ulrich Drepper  <drepper@gmail.com>, adapted for SFMT
 //
-// Copyright (C) 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
+// Copyright (C) 2008-2012 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
Index: testsuite/ext/random/simd_fast_mersenne_twister_engine/operators/inequal.cc
===================================================================
--- testsuite/ext/random/simd_fast_mersenne_twister_engine/operators/inequal.cc	(revision 192245)
+++ testsuite/ext/random/simd_fast_mersenne_twister_engine/operators/inequal.cc	(working copy)
@@ -1,10 +1,11 @@ 
 // { dg-options "-std=c++0x" }
 // { dg-require-cstdint "" }
+// { dg-require-little-endian "" }
 //
 // 2010-03-16  Paolo Carlini  <paolo.carlini@oracle.com>
 // 2012-08-28  Ulrich Drepper  <drepper@gmail.com>, adapted for SFMT
 //
-// Copyright (C) 2010, 2012 Free Software Foundation, Inc.
+// Copyright (C) 2010-2012 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
Index: testsuite/ext/random/simd_fast_mersenne_twister_engine/cons/copy.cc
===================================================================
--- testsuite/ext/random/simd_fast_mersenne_twister_engine/cons/copy.cc	(revision 192245)
+++ testsuite/ext/random/simd_fast_mersenne_twister_engine/cons/copy.cc	(working copy)
@@ -1,10 +1,11 @@ 
 // { dg-options "-std=c++0x" }
 // { dg-require-cstdint "" }
+// { dg-require-little-endian "" }
 //
 // 2010-02-16  Paolo Carlini  <paolo.carlini@oracle.com>
 // 2012-08-28  Ulrich Drepper  <drepper@gmail.com>, adapted for SFMT
 //
-// Copyright (C) 2010, 2012 Free Software Foundation, Inc.
+// Copyright (C) 2010-2012 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
Index: testsuite/ext/random/simd_fast_mersenne_twister_engine/cons/seed1.cc
===================================================================
--- testsuite/ext/random/simd_fast_mersenne_twister_engine/cons/seed1.cc	(revision 192245)
+++ testsuite/ext/random/simd_fast_mersenne_twister_engine/cons/seed1.cc	(working copy)
@@ -1,10 +1,11 @@ 
 // { dg-options "-std=c++0x" }
 // { dg-require-cstdint "" }
+// { dg-require-little-endian "" }
 //
 // 2008-11-24  Edward M. Smith-Rowland <3dw4rd@verizon.net>
 // 2012-08-28  Ulrich Drepper  <drepper@gmail.com>, adapted for SFMT
 //
-// Copyright (C) 2008, 2009, 2010, 2012 Free Software Foundation, Inc.
+// Copyright (C) 2008-2012 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
Index: testsuite/ext/random/simd_fast_mersenne_twister_engine/cons/seed2.cc
===================================================================
--- testsuite/ext/random/simd_fast_mersenne_twister_engine/cons/seed2.cc	(revision 192245)
+++ testsuite/ext/random/simd_fast_mersenne_twister_engine/cons/seed2.cc	(working copy)
@@ -1,10 +1,11 @@ 
 // { dg-options "-std=c++0x" }
 // { dg-require-cstdint "" }
+// { dg-require-little-endian "" }
 //
 // 2008-11-24  Edward M. Smith-Rowland <3dw4rd@verizon.net>
 // 2012-08-28  Ulrich Drepper  <drepper@gmail.com>, adapted for SFMT
 //
-// Copyright (C) 2008, 2009, 2010, 2012 Free Software Foundation, Inc.
+// Copyright (C) 2008-2012 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
Index: testsuite/ext/random/simd_fast_mersenne_twister_engine/cons/default.cc
===================================================================
--- testsuite/ext/random/simd_fast_mersenne_twister_engine/cons/default.cc	(revision 192245)
+++ testsuite/ext/random/simd_fast_mersenne_twister_engine/cons/default.cc	(working copy)
@@ -1,10 +1,11 @@ 
 // { dg-options "-std=c++0x" }
 // { dg-require-cstdint "" }
+// { dg-require-little-endian "" }
 //
 // 2008-11-24  Edward M. Smith-Rowland <3dw4rd@verizon.net>
 // 2012-08-28  Ulrich Drepper  <drepper@gmail.com>, adapted for SFMT
 //
-// Copyright (C) 2008, 2009, 2010, 2012 Free Software Foundation, Inc.
+// Copyright (C) 2008-2012 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
Index: testsuite/ext/random/simd_fast_mersenne_twister_engine/cons/seed_seq.cc
===================================================================
--- testsuite/ext/random/simd_fast_mersenne_twister_engine/cons/seed_seq.cc	(revision 192245)
+++ testsuite/ext/random/simd_fast_mersenne_twister_engine/cons/seed_seq.cc	(working copy)
@@ -1,10 +1,11 @@ 
 // { dg-options "-std=c++0x" }
 // { dg-require-cstdint "" }
+// { dg-require-little-endian "" }
 //
 // 2010-02-01  Paolo Carlini  <paolo.carlini@oracle.com>
 // 2012-08-28  Ulrich Drepper  <drepper@gmail.com>, adapted for SFMT
 //
-// Copyright (C) 2010, 2012 Free Software Foundation, Inc.
+// Copyright (C) 2010-2012 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
Index: testsuite/lib/dg-options.exp
===================================================================
--- testsuite/lib/dg-options.exp	(revision 192245)
+++ testsuite/lib/dg-options.exp	(working copy)
@@ -206,6 +206,15 @@ 
     return
 }
 
+proc dg-require-little-endian { args } {
+    if { ![ check_v3_target_little_endian ] } {
+        upvar dg-do-what dg-do-what
+        set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
+        return
+    }
+    return
+}
+
 proc add_options_for_no_pch { flags } {
     # This forces any generated and possibly included PCH to be invalid.
     return "-D__GLIBCXX__=99999999"
Index: testsuite/lib/libstdc++.exp
===================================================================
--- testsuite/lib/libstdc++.exp	(revision 192245)
+++ testsuite/lib/libstdc++.exp	(working copy)
@@ -1736,6 +1736,57 @@ 
     return $et_static_libstdcxx
 }
 
+proc check_v3_target_little_endian { } {
+    global cxxflags
+    global DEFAULT_CXXFLAGS
+    global et_little_endian
 
+    global tool
 
+    if { ![info exists et_little_endian_target_name] } {
+        set et_little_endian_target_name ""
+    }
+
+    # If the target has changed since we set the cached value, clear it.
+    set current_target [current_target_name]
+    if { $current_target != $et_little_endian_target_name } {
+        verbose "check_v3_target_little_endian: `$et_little_endian_target_name'" 2
+        set et_little_endian_target_name $current_target
+        if [info exists et_little_endian] {
+            verbose "check_v3_target_little_endian: removing cached result" 2
+            unset et_little_endian
+        }
+    }
+
+    if [info exists et_little_endian] {
+        verbose "check_v3_target_little_endian: using cached result" 2
+    } else {
+        set et_little_endian 0
+	
+        set src little_endian[pid].cc
+
+        set f [open $src "w"]
+        puts $f "#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__"
+        puts $f "#  error Not little endian"
+        puts $f "#endif"
+        close $f
+
+        set cxxflags_saved $cxxflags
+        set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror"
+
+        set lines [v3_target_compile $src /dev/null preprocess ""]
+        set cxxflags $cxxflags_saved
+        file delete $src
+
+        if [string match "" $lines] {
+            # No error message, preprocessing succeeded.
+            set et_little_endian 1
+        } else {
+            verbose "check_v3_target_little_endian: compilation failed" 2
+        }
+    }
+    verbose "check_v3_target_little_endian: $et_little_endian" 2
+    return $et_little_endian
+}
+
 set additional_prunes ""
Index: config/cpu/i486/opt/ext/opt_random.h
===================================================================
--- config/cpu/i486/opt/ext/opt_random.h	(revision 192245)
+++ config/cpu/i486/opt/ext/opt_random.h	(working copy)
@@ -32,6 +32,8 @@ 
 
 #pragma GCC system_header
 
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+
 #ifdef __SSE2__
 
 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
@@ -133,4 +135,6 @@ 
 
 #endif // __SSE2__
 
+#endif // __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+
 #endif // _EXT_OPT_RANDOM_H
Index: include/ext/random
===================================================================
--- include/ext/random	(revision 192245)
+++ include/ext/random	(working copy)
@@ -47,6 +47,8 @@ 
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+
   /* Mersenne twister implementation optimized for vector operations.
    *
    * Reference: http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/
@@ -380,6 +382,7 @@ 
 					    0x3bd2b64bU, 0x0c64b1e4U>
     sfmt216091_64;
 
+#endif // __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
 
   /**
    * @brief A beta continuous distribution for random numbers.
Index: include/ext/random.tcc
===================================================================
--- include/ext/random.tcc	(revision 192245)
+++ include/ext/random.tcc	(working copy)
@@ -37,6 +37,7 @@ 
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
 
   template<typename _UIntType, size_t __m,
 	   size_t __pos1, size_t __sl1, size_t __sl2,
@@ -402,6 +403,7 @@ 
       return __is;
     }
 
+#endif // __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
 
   /**
    * Iteration method due to M.D. J<o:>hnk.