Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 443140
Collapse All | Expand All

(-).gitattributes (-13 lines)
Lines 1-13 Link Here
1
.git*            export-ignore
2
3
*.bat.in        -crlf
4
*.bin           -crlf
5
*.gmo           -crlf
6
*.sh             crlf=input
7
config.*         crlf=input
8
configure        crlf=input
9
fixproto         crlf=input
10
gccbug.in        crlf=input
11
genmultilib      crlf=input
12
mklibgcc.in      crlf=input
13
sort-protos      crlf=input
(-)CMakeLists.txt (-1 / +2 lines)
Lines 29-35 Link Here
29
SET(GCCXML_ADD_TESTS 1)
29
SET(GCCXML_ADD_TESTS 1)
30
30
31
# Build GCC and GCC_XML.
31
# Build GCC and GCC_XML.
32
SUBDIRS(GCC GCC_XML)
32
ADD_SUBDIRECTORY(GCC)
33
ADD_SUBDIRECTORY(GCC_XML)
33
34
34
# Use CPack to build a redistributable installer
35
# Use CPack to build a redistributable installer
35
INCLUDE("${CMAKE_CURRENT_SOURCE_DIR}/gccxmlCPack.cmake")
36
INCLUDE("${CMAKE_CURRENT_SOURCE_DIR}/gccxmlCPack.cmake")
(-)GCC/.gitattributes (-1 lines)
Line 1 Link Here
1
*               -whitespace
(-)GCC/config_cmake/CMakeLists.txt (-3 / +3 lines)
Lines 178-184 Link Here
178
CHECK_INCLUDE_FILE(alloca.h HAVE_ALLOCA_H)
178
CHECK_INCLUDE_FILE(alloca.h HAVE_ALLOCA_H)
179
CHECK_INCLUDE_FILE(fcntl.h HAVE_FCNTL_H)
179
CHECK_INCLUDE_FILE(fcntl.h HAVE_FCNTL_H)
180
CHECK_INCLUDE_FILE(limits.h HAVE_LIMITS_H)
180
CHECK_INCLUDE_FILE(limits.h HAVE_LIMITS_H)
181
CHECK_INCLUDE_FILE(machine/hal_sysinfo.h HAVE_MACHINE/HAL_SYSINFO_H)
181
CHECK_INCLUDE_FILE(machine/hal_sysinfo.h HAVE_MACHINE_HAL_SYSINFO_H)
182
CHECK_INCLUDE_FILE(malloc.h HAVE_MALLOC_H)
182
CHECK_INCLUDE_FILE(malloc.h HAVE_MALLOC_H)
183
CHECK_INCLUDE_FILE(sys/file.h HAVE_SYS_FILE_H)
183
CHECK_INCLUDE_FILE(sys/file.h HAVE_SYS_FILE_H)
184
CHECK_INCLUDE_FILE(sys/mman.h HAVE_SYS_MMAN_H)
184
CHECK_INCLUDE_FILE(sys/mman.h HAVE_SYS_MMAN_H)
Lines 701-707 Link Here
701
ENDIF(MINGW)
701
ENDIF(MINGW)
702
SET(GCC_EXECUTED_PLATFORM_SCRIPT)
702
SET(GCC_EXECUTED_PLATFORM_SCRIPT)
703
IF(GCC_USE_PLATFORM_SCRIPT)
703
IF(GCC_USE_PLATFORM_SCRIPT)
704
  FIND_PROGRAM(GCC_SH sh /bin/sh c:/msys/1.0/bin/sh.exe)
704
  FIND_PROGRAM(GCC_SH NAMES sh PATHS /bin c:/msys/1.0/bin NO_CMAKE_FIND_ROOT_PATH )
705
  MARK_AS_ADVANCED(GCC_SH)
705
  MARK_AS_ADVANCED(GCC_SH)
706
  IF(GCC_SH)
706
  IF(GCC_SH)
707
    EXEC_PROGRAM(${GCC_SH}
707
    EXEC_PROGRAM(${GCC_SH}
Lines 721-727 Link Here
721
IF(EXISTS "${GCCCONFIG_BINARY_DIR}/gcc_platform.cmake")
721
IF(EXISTS "${GCCCONFIG_BINARY_DIR}/gcc_platform.cmake")
722
  INCLUDE("${GCCCONFIG_BINARY_DIR}/gcc_platform.cmake")
722
  INCLUDE("${GCCCONFIG_BINARY_DIR}/gcc_platform.cmake")
723
ELSE(EXISTS "${GCCCONFIG_BINARY_DIR}/gcc_platform.cmake")
723
ELSE(EXISTS "${GCCCONFIG_BINARY_DIR}/gcc_platform.cmake")
724
  MESSAGE(FATAL_ERROR "Cannot find gcc_platform.cmake.")
724
  MESSAGE(FATAL_ERROR "Cannot find '${GCCCONFIG_BINARY_DIR}/gcc_platform.cmake'")
725
ENDIF(EXISTS "${GCCCONFIG_BINARY_DIR}/gcc_platform.cmake")
725
ENDIF(EXISTS "${GCCCONFIG_BINARY_DIR}/gcc_platform.cmake")
726
726
727
IF(extra_modes)
727
IF(extra_modes)
(-)GCC/gcc/CMakeLists.txt (-1 / +1 lines)
Lines 31-37 Link Here
31
IF(EXISTS "${GCCCONFIG_BINARY_DIR}/gcc_platform.cmake")
31
IF(EXISTS "${GCCCONFIG_BINARY_DIR}/gcc_platform.cmake")
32
  INCLUDE("${GCCCONFIG_BINARY_DIR}/gcc_platform.cmake")
32
  INCLUDE("${GCCCONFIG_BINARY_DIR}/gcc_platform.cmake")
33
ELSE(EXISTS "${GCCCONFIG_BINARY_DIR}/gcc_platform.cmake")
33
ELSE(EXISTS "${GCCCONFIG_BINARY_DIR}/gcc_platform.cmake")
34
  MESSAGE(FATAL_ERROR "Cannot find gcc_platform.cmake.")
34
  MESSAGE(FATAL_ERROR "Cannot find '${GCCCONFIG_BINARY_DIR}/gcc_platform.cmake'")
35
ENDIF(EXISTS "${GCCCONFIG_BINARY_DIR}/gcc_platform.cmake")
35
ENDIF(EXISTS "${GCCCONFIG_BINARY_DIR}/gcc_platform.cmake")
36
36
37
# Default the target-machine variables that were not explicitly set.
37
# Default the target-machine variables that were not explicitly set.
(-)GCC/gcc/cp/.gitattributes (-1 lines)
Line 1 Link Here
1
xml.c            whitespace=tab-in-indent,trailing-space
(-)GCC_XML/GXFront/CMakeLists.txt (-7 / +7 lines)
Lines 9-15 Link Here
9
9
10
TARGET_LINK_LIBRARIES(gccxml gxsys)
10
TARGET_LINK_LIBRARIES(gccxml gxsys)
11
11
12
ADD_DEPENDENCIES(gccxml vcInstallPatch)
12
IF(TARGET vcInstallPatch)
13
  ADD_DEPENDENCIES(gccxml vcInstallPatch)
14
ENDIF()
13
15
14
# If we are inside a project that is building gccxml_cc1plus for us,
16
# If we are inside a project that is building gccxml_cc1plus for us,
15
# add the dependency to build it first.
17
# add the dependency to build it first.
Lines 19-26 Link Here
19
21
20
#-----------------------------------------------------------------------------
22
#-----------------------------------------------------------------------------
21
# Generate documentation.
23
# Generate documentation.
22
GET_TARGET_PROPERTY(GCCXML_EXE gccxml LOCATION)
23
24
MAKE_DIRECTORY(${GCCXML_BINARY_DIR}/doc)
24
MAKE_DIRECTORY(${GCCXML_BINARY_DIR}/doc)
25
25
26
ADD_CUSTOM_TARGET(documentation ALL DEPENDS
26
ADD_CUSTOM_TARGET(documentation ALL DEPENDS
Lines 31-52 Link Here
31
ADD_DEPENDENCIES(documentation gccxml)
31
ADD_DEPENDENCIES(documentation gccxml)
32
32
33
ADD_CUSTOM_COMMAND(OUTPUT ${GCCXML_BINARY_DIR}/doc/gccxml.1
33
ADD_CUSTOM_COMMAND(OUTPUT ${GCCXML_BINARY_DIR}/doc/gccxml.1
34
  COMMAND ${GCCXML_EXE} --man > ${GCCXML_BINARY_DIR}/doc/gccxml.1
34
  COMMAND gccxml --man > ${GCCXML_BINARY_DIR}/doc/gccxml.1
35
  DEPENDS gccxml
35
  DEPENDS gccxml
36
  )
36
  )
37
37
38
ADD_CUSTOM_COMMAND(OUTPUT ${GCCXML_BINARY_DIR}/doc/gccxml.txt
38
ADD_CUSTOM_COMMAND(OUTPUT ${GCCXML_BINARY_DIR}/doc/gccxml.txt
39
  COMMAND ${GCCXML_EXE} --help > ${GCCXML_BINARY_DIR}/doc/gccxml.txt
39
  COMMAND gccxml --help > ${GCCXML_BINARY_DIR}/doc/gccxml.txt
40
  DEPENDS gccxml
40
  DEPENDS gccxml
41
  )
41
  )
42
42
43
ADD_CUSTOM_COMMAND(OUTPUT ${GCCXML_BINARY_DIR}/doc/gccxml.html
43
ADD_CUSTOM_COMMAND(OUTPUT ${GCCXML_BINARY_DIR}/doc/gccxml.html
44
  COMMAND ${GCCXML_EXE} --help-html > ${GCCXML_BINARY_DIR}/doc/gccxml.html
44
  COMMAND gccxml --help-html > ${GCCXML_BINARY_DIR}/doc/gccxml.html
45
  DEPENDS gccxml
45
  DEPENDS gccxml
46
  )
46
  )
47
47
48
ADD_CUSTOM_COMMAND(OUTPUT ${GCCXML_BINARY_DIR}/doc/Copyright.txt
48
ADD_CUSTOM_COMMAND(OUTPUT ${GCCXML_BINARY_DIR}/doc/Copyright.txt
49
  COMMAND ${GCCXML_EXE} --copyright > ${GCCXML_BINARY_DIR}/doc/Copyright.txt
49
  COMMAND gccxml --copyright > ${GCCXML_BINARY_DIR}/doc/Copyright.txt
50
  DEPENDS gccxml
50
  DEPENDS gccxml
51
  )
51
  )
52
52
(-)GCC_XML/GXFront/gxDocumentation.cxx (-7 lines)
Lines 547-559 Link Here
547
  gxDocumentationPrintManSection(os, gxDocumentationMetaInfo);
547
  gxDocumentationPrintManSection(os, gxDocumentationMetaInfo);
548
  os << ".SH COPYRIGHT\n";
548
  os << ".SH COPYRIGHT\n";
549
  gxDocumentationPrintManSection(os, gxDocumentationCopyright);
549
  gxDocumentationPrintManSection(os, gxDocumentationCopyright);
550
  os << ".SH MAILING LIST\n";
551
  os << "For help and discussion about using gccxml, a mailing list is\n"
552
     << "provided at\n"
553
     << ".B gccxml@www.gccxml.org.\n"
554
     << "Please first read the full documentation at\n"
555
     << ".B http://www.gccxml.org\n"
556
     << "before posting questions to the list.\n";
557
  os << ".SH AUTHOR\n"
550
  os << ".SH AUTHOR\n"
558
     << "This manual page was generated by \"gccxml --man\".\n";
551
     << "This manual page was generated by \"gccxml --man\".\n";
559
}
552
}
(-)GCC_XML/Support/GCC/.gitattributes (-1 lines)
Line 1 Link Here
1
*               -whitespace
(-)GCC_XML/Support/GCC/4.9/bits/c++config.h (+11 lines)
Line 0 Link Here
1
#ifdef __LONG_DOUBLE_128__
2
/* Avoid using inline namespace not supported by GCC 4.2 */
3
#undef __LONG_DOUBLE_128__
4
#include_next <bits/c++config.h>
5
#define __LONG_DOUBLE_128__ 1
6
#else
7
#include_next <bits/c++config.h>
8
#endif
9
10
/* GCC 4.2 parser does not support __int128 */
11
#undef _GLIBCXX_USE_INT128
(-)GCC_XML/Support/GCC/4.9/bits/stl_algo.h (+5514 lines)
Line 0 Link Here
1
// Algorithm implementation -*- C++ -*-
2
3
// Copyright (C) 2001-2014 Free Software Foundation, Inc.
4
//
5
// This file is part of the GNU ISO C++ Library.  This library is free
6
// software; you can redistribute it and/or modify it under the
7
// terms of the GNU General Public License as published by the
8
// Free Software Foundation; either version 3, or (at your option)
9
// any later version.
10
11
// This library is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
// GNU General Public License for more details.
15
16
// Under Section 7 of GPL version 3, you are granted additional
17
// permissions described in the GCC Runtime Library Exception, version
18
// 3.1, as published by the Free Software Foundation.
19
20
// You should have received a copy of the GNU General Public License and
21
// a copy of the GCC Runtime Library Exception along with this program;
22
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23
// <http://www.gnu.org/licenses/>.
24
25
/*
26
 *
27
 * Copyright (c) 1994
28
 * Hewlett-Packard Company
29
 *
30
 * Permission to use, copy, modify, distribute and sell this software
31
 * and its documentation for any purpose is hereby granted without fee,
32
 * provided that the above copyright notice appear in all copies and
33
 * that both that copyright notice and this permission notice appear
34
 * in supporting documentation.  Hewlett-Packard Company makes no
35
 * representations about the suitability of this software for any
36
 * purpose.  It is provided "as is" without express or implied warranty.
37
 *
38
 *
39
 * Copyright (c) 1996
40
 * Silicon Graphics Computer Systems, Inc.
41
 *
42
 * Permission to use, copy, modify, distribute and sell this software
43
 * and its documentation for any purpose is hereby granted without fee,
44
 * provided that the above copyright notice appear in all copies and
45
 * that both that copyright notice and this permission notice appear
46
 * in supporting documentation.  Silicon Graphics makes no
47
 * representations about the suitability of this software for any
48
 * purpose.  It is provided "as is" without express or implied warranty.
49
 */
50
51
/** @file bits/stl_algo.h
52
 *  This is an internal header file, included by other library headers.
53
 *  Do not attempt to use it directly. @headername{algorithm}
54
 */
55
56
#ifndef _STL_ALGO_H
57
#define _STL_ALGO_H 1
58
59
#include <cstdlib>             // for rand
60
#include <bits/algorithmfwd.h>
61
#include <bits/stl_heap.h>
62
#include <bits/stl_tempbuf.h>  // for _Temporary_buffer
63
#include <bits/predefined_ops.h>
64
65
#if __cplusplus >= 201103L
66
#include <random>     // for std::uniform_int_distribution
67
#endif
68
69
// See concept_check.h for the __glibcxx_*_requires macros.
70
71
namespace std _GLIBCXX_VISIBILITY(default)
72
{
73
_GLIBCXX_BEGIN_NAMESPACE_VERSION
74
75
  /// Swaps the median value of *__a, *__b and *__c under __comp to *__result
76
  template<typename _Iterator, typename _Compare>
77
    void
78
    __move_median_to_first(_Iterator __result,_Iterator __a, _Iterator __b,
79
			   _Iterator __c, _Compare __comp)
80
    {
81
      if (__comp(__a, __b))
82
	{
83
	  if (__comp(__b, __c))
84
	    std::iter_swap(__result, __b);
85
	  else if (__comp(__a, __c))
86
	    std::iter_swap(__result, __c);
87
	  else
88
	    std::iter_swap(__result, __a);
89
	}
90
      else if (__comp(__a, __c))
91
	std::iter_swap(__result, __a);
92
      else if (__comp(__b, __c))
93
	std::iter_swap(__result, __c);
94
      else
95
	std::iter_swap(__result, __b);
96
    }
97
98
  /// This is an overload used by find algos for the Input Iterator case.
99
  template<typename _InputIterator, typename _Predicate>
100
    inline _InputIterator
101
    __find_if(_InputIterator __first, _InputIterator __last,
102
	      _Predicate __pred, input_iterator_tag)
103
    {
104
      while (__first != __last && !__pred(__first))
105
	++__first;
106
      return __first;
107
    }
108
109
  /// This is an overload used by find algos for the RAI case.
110
  template<typename _RandomAccessIterator, typename _Predicate>
111
    _RandomAccessIterator
112
    __find_if(_RandomAccessIterator __first, _RandomAccessIterator __last,
113
	      _Predicate __pred, random_access_iterator_tag)
114
    {
115
      typename iterator_traits<_RandomAccessIterator>::difference_type
116
	__trip_count = (__last - __first) >> 2;
117
118
      for (; __trip_count > 0; --__trip_count)
119
	{
120
	  if (__pred(__first))
121
	    return __first;
122
	  ++__first;
123
124
	  if (__pred(__first))
125
	    return __first;
126
	  ++__first;
127
128
	  if (__pred(__first))
129
	    return __first;
130
	  ++__first;
131
132
	  if (__pred(__first))
133
	    return __first;
134
	  ++__first;
135
	}
136
137
      switch (__last - __first)
138
	{
139
	case 3:
140
	  if (__pred(__first))
141
	    return __first;
142
	  ++__first;
143
	case 2:
144
	  if (__pred(__first))
145
	    return __first;
146
	  ++__first;
147
	case 1:
148
	  if (__pred(__first))
149
	    return __first;
150
	  ++__first;
151
	case 0:
152
	default:
153
	  return __last;
154
	}
155
    }
156
157
  template<typename _Iterator, typename _Predicate>
158
    inline _Iterator
159
    __find_if(_Iterator __first, _Iterator __last, _Predicate __pred)
160
    {
161
      return __find_if(__first, __last, __pred,
162
		       std::__iterator_category(__first));
163
    }
164
165
  /// Provided for stable_partition to use.
166
  template<typename _InputIterator, typename _Predicate>
167
    inline _InputIterator
168
    __find_if_not(_InputIterator __first, _InputIterator __last,
169
		  _Predicate __pred)
170
    {
171
      return std::__find_if(__first, __last,
172
			    __gnu_cxx::__ops::__negate(__pred),
173
			    std::__iterator_category(__first));
174
    }
175
176
  /// Like find_if_not(), but uses and updates a count of the
177
  /// remaining range length instead of comparing against an end
178
  /// iterator.
179
  template<typename _InputIterator, typename _Predicate, typename _Distance>
180
    _InputIterator
181
    __find_if_not_n(_InputIterator __first, _Distance& __len, _Predicate __pred)
182
    {
183
      for (; __len; --__len, ++__first)
184
	if (!__pred(__first))
185
	  break;
186
      return __first;
187
    }
188
189
  // set_difference
190
  // set_intersection
191
  // set_symmetric_difference
192
  // set_union
193
  // for_each
194
  // find
195
  // find_if
196
  // find_first_of
197
  // adjacent_find
198
  // count
199
  // count_if
200
  // search
201
202
  template<typename _ForwardIterator1, typename _ForwardIterator2,
203
	   typename _BinaryPredicate>
204
    _ForwardIterator1
205
    __search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
206
	     _ForwardIterator2 __first2, _ForwardIterator2 __last2,
207
	     _BinaryPredicate  __predicate)
208
    {
209
      // Test for empty ranges
210
      if (__first1 == __last1 || __first2 == __last2)
211
	return __first1;
212
213
      // Test for a pattern of length 1.
214
      _ForwardIterator2 __p1(__first2);
215
      if (++__p1 == __last2)
216
	return std::__find_if(__first1, __last1,
217
		__gnu_cxx::__ops::__iter_comp_iter(__predicate, __first2));
218
219
      // General case.
220
      _ForwardIterator2 __p;
221
      _ForwardIterator1 __current = __first1;
222
223
      for (;;)
224
	{
225
	  __first1 =
226
	    std::__find_if(__first1, __last1,
227
		__gnu_cxx::__ops::__iter_comp_iter(__predicate, __first2));
228
229
	  if (__first1 == __last1)
230
	    return __last1;
231
232
	  __p = __p1;
233
	  __current = __first1;
234
	  if (++__current == __last1)
235
	    return __last1;
236
237
	  while (__predicate(__current, __p))
238
	    {
239
	      if (++__p == __last2)
240
		return __first1;
241
	      if (++__current == __last1)
242
		return __last1;
243
	    }
244
	  ++__first1;
245
	}
246
      return __first1;
247
    }
248
249
  // search_n
250
251
  /**
252
   *  This is an helper function for search_n overloaded for forward iterators.
253
  */
254
  template<typename _ForwardIterator, typename _Integer,
255
	   typename _UnaryPredicate>
256
    _ForwardIterator
257
    __search_n_aux(_ForwardIterator __first, _ForwardIterator __last,
258
		   _Integer __count, _UnaryPredicate __unary_pred,
259
		   std::forward_iterator_tag)
260
    {
261
      __first = std::__find_if(__first, __last, __unary_pred);
262
      while (__first != __last)
263
	{
264
	  typename iterator_traits<_ForwardIterator>::difference_type
265
	    __n = __count;
266
	  _ForwardIterator __i = __first;
267
	  ++__i;
268
	  while (__i != __last && __n != 1 && __unary_pred(__i))
269
	    {
270
	      ++__i;
271
	      --__n;
272
	    }
273
	  if (__n == 1)
274
	    return __first;
275
	  if (__i == __last)
276
	    return __last;
277
	  __first = std::__find_if(++__i, __last, __unary_pred);
278
	}
279
      return __last;
280
    }
281
282
  /**
283
   *  This is an helper function for search_n overloaded for random access
284
   *  iterators.
285
  */
286
  template<typename _RandomAccessIter, typename _Integer,
287
	   typename _UnaryPredicate>
288
    _RandomAccessIter
289
    __search_n_aux(_RandomAccessIter __first, _RandomAccessIter __last,
290
		   _Integer __count, _UnaryPredicate __unary_pred,
291
		   std::random_access_iterator_tag)
292
    {
293
      typedef typename std::iterator_traits<_RandomAccessIter>::difference_type
294
	_DistanceType;
295
296
      _DistanceType __tailSize = __last - __first;
297
      _DistanceType __remainder = __count;
298
299
      while (__remainder <= __tailSize) // the main loop...
300
	{
301
	  __first += __remainder;
302
	  __tailSize -= __remainder;
303
	  // __first here is always pointing to one past the last element of
304
	  // next possible match.
305
	  _RandomAccessIter __backTrack = __first; 
306
	  while (__unary_pred(--__backTrack))
307
	    {
308
	      if (--__remainder == 0)
309
	        return (__first - __count); // Success
310
	    }
311
	  __remainder = __count + 1 - (__first - __backTrack);
312
	}
313
      return __last; // Failure
314
    }
315
316
  template<typename _ForwardIterator, typename _Integer,
317
           typename _UnaryPredicate>
318
    _ForwardIterator
319
    __search_n(_ForwardIterator __first, _ForwardIterator __last,
320
	       _Integer __count,
321
	       _UnaryPredicate __unary_pred)
322
    {
323
      if (__count <= 0)
324
	return __first;
325
326
      if (__count == 1)
327
	return std::__find_if(__first, __last, __unary_pred);
328
329
      return std::__search_n_aux(__first, __last, __count, __unary_pred,
330
				 std::__iterator_category(__first));
331
    }
332
333
  // find_end for forward iterators.
334
  template<typename _ForwardIterator1, typename _ForwardIterator2,
335
	   typename _BinaryPredicate>
336
    _ForwardIterator1
337
    __find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
338
	       _ForwardIterator2 __first2, _ForwardIterator2 __last2,
339
	       forward_iterator_tag, forward_iterator_tag,
340
	       _BinaryPredicate __comp)
341
    {
342
      if (__first2 == __last2)
343
	return __last1;
344
345
      _ForwardIterator1 __result = __last1;
346
      while (1)
347
	{
348
	  _ForwardIterator1 __new_result
349
	    = std::__search(__first1, __last1, __first2, __last2, __comp);
350
	  if (__new_result == __last1)
351
	    return __result;
352
	  else
353
	    {
354
	      __result = __new_result;
355
	      __first1 = __new_result;
356
	      ++__first1;
357
	    }
358
	}
359
    }
360
361
  // find_end for bidirectional iterators (much faster).
362
  template<typename _BidirectionalIterator1, typename _BidirectionalIterator2,
363
	   typename _BinaryPredicate>
364
    _BidirectionalIterator1
365
    __find_end(_BidirectionalIterator1 __first1,
366
	       _BidirectionalIterator1 __last1,
367
	       _BidirectionalIterator2 __first2,
368
	       _BidirectionalIterator2 __last2,
369
	       bidirectional_iterator_tag, bidirectional_iterator_tag,
370
	       _BinaryPredicate __comp)
371
    {
372
      // concept requirements
373
      __glibcxx_function_requires(_BidirectionalIteratorConcept<
374
				  _BidirectionalIterator1>)
375
      __glibcxx_function_requires(_BidirectionalIteratorConcept<
376
				  _BidirectionalIterator2>)
377
378
      typedef reverse_iterator<_BidirectionalIterator1> _RevIterator1;
379
      typedef reverse_iterator<_BidirectionalIterator2> _RevIterator2;
380
381
      _RevIterator1 __rlast1(__first1);
382
      _RevIterator2 __rlast2(__first2);
383
      _RevIterator1 __rresult = std::__search(_RevIterator1(__last1), __rlast1,
384
					      _RevIterator2(__last2), __rlast2,
385
					      __comp);
386
387
      if (__rresult == __rlast1)
388
	return __last1;
389
      else
390
	{
391
	  _BidirectionalIterator1 __result = __rresult.base();
392
	  std::advance(__result, -std::distance(__first2, __last2));
393
	  return __result;
394
	}
395
    }
396
397
  /**
398
   *  @brief  Find last matching subsequence in a sequence.
399
   *  @ingroup non_mutating_algorithms
400
   *  @param  __first1  Start of range to search.
401
   *  @param  __last1   End of range to search.
402
   *  @param  __first2  Start of sequence to match.
403
   *  @param  __last2   End of sequence to match.
404
   *  @return   The last iterator @c i in the range
405
   *  @p [__first1,__last1-(__last2-__first2)) such that @c *(i+N) ==
406
   *  @p *(__first2+N) for each @c N in the range @p
407
   *  [0,__last2-__first2), or @p __last1 if no such iterator exists.
408
   *
409
   *  Searches the range @p [__first1,__last1) for a sub-sequence that
410
   *  compares equal value-by-value with the sequence given by @p
411
   *  [__first2,__last2) and returns an iterator to the __first
412
   *  element of the sub-sequence, or @p __last1 if the sub-sequence
413
   *  is not found.  The sub-sequence will be the last such
414
   *  subsequence contained in [__first1,__last1).
415
   *
416
   *  Because the sub-sequence must lie completely within the range @p
417
   *  [__first1,__last1) it must start at a position less than @p
418
   *  __last1-(__last2-__first2) where @p __last2-__first2 is the
419
   *  length of the sub-sequence.  This means that the returned
420
   *  iterator @c i will be in the range @p
421
   *  [__first1,__last1-(__last2-__first2))
422
  */
423
  template<typename _ForwardIterator1, typename _ForwardIterator2>
424
    inline _ForwardIterator1
425
    find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
426
	     _ForwardIterator2 __first2, _ForwardIterator2 __last2)
427
    {
428
      // concept requirements
429
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
430
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
431
      __glibcxx_function_requires(_EqualOpConcept<
432
	    typename iterator_traits<_ForwardIterator1>::value_type,
433
	    typename iterator_traits<_ForwardIterator2>::value_type>)
434
      __glibcxx_requires_valid_range(__first1, __last1);
435
      __glibcxx_requires_valid_range(__first2, __last2);
436
437
      return std::__find_end(__first1, __last1, __first2, __last2,
438
			     std::__iterator_category(__first1),
439
			     std::__iterator_category(__first2),
440
			     __gnu_cxx::__ops::__iter_equal_to_iter());
441
    }
442
443
  /**
444
   *  @brief  Find last matching subsequence in a sequence using a predicate.
445
   *  @ingroup non_mutating_algorithms
446
   *  @param  __first1  Start of range to search.
447
   *  @param  __last1   End of range to search.
448
   *  @param  __first2  Start of sequence to match.
449
   *  @param  __last2   End of sequence to match.
450
   *  @param  __comp    The predicate to use.
451
   *  @return The last iterator @c i in the range @p
452
   *  [__first1,__last1-(__last2-__first2)) such that @c
453
   *  predicate(*(i+N), @p (__first2+N)) is true for each @c N in the
454
   *  range @p [0,__last2-__first2), or @p __last1 if no such iterator
455
   *  exists.
456
   *
457
   *  Searches the range @p [__first1,__last1) for a sub-sequence that
458
   *  compares equal value-by-value with the sequence given by @p
459
   *  [__first2,__last2) using comp as a predicate and returns an
460
   *  iterator to the first element of the sub-sequence, or @p __last1
461
   *  if the sub-sequence is not found.  The sub-sequence will be the
462
   *  last such subsequence contained in [__first,__last1).
463
   *
464
   *  Because the sub-sequence must lie completely within the range @p
465
   *  [__first1,__last1) it must start at a position less than @p
466
   *  __last1-(__last2-__first2) where @p __last2-__first2 is the
467
   *  length of the sub-sequence.  This means that the returned
468
   *  iterator @c i will be in the range @p
469
   *  [__first1,__last1-(__last2-__first2))
470
  */
471
  template<typename _ForwardIterator1, typename _ForwardIterator2,
472
	   typename _BinaryPredicate>
473
    inline _ForwardIterator1
474
    find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
475
	     _ForwardIterator2 __first2, _ForwardIterator2 __last2,
476
	     _BinaryPredicate __comp)
477
    {
478
      // concept requirements
479
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
480
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
481
      __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
482
	    typename iterator_traits<_ForwardIterator1>::value_type,
483
	    typename iterator_traits<_ForwardIterator2>::value_type>)
484
      __glibcxx_requires_valid_range(__first1, __last1);
485
      __glibcxx_requires_valid_range(__first2, __last2);
486
487
      return std::__find_end(__first1, __last1, __first2, __last2,
488
			     std::__iterator_category(__first1),
489
			     std::__iterator_category(__first2),
490
			     __gnu_cxx::__ops::__iter_comp_iter(__comp));
491
    }
492
493
#if __cplusplus >= 201103L
494
  /**
495
   *  @brief  Checks that a predicate is true for all the elements
496
   *          of a sequence.
497
   *  @ingroup non_mutating_algorithms
498
   *  @param  __first   An input iterator.
499
   *  @param  __last    An input iterator.
500
   *  @param  __pred    A predicate.
501
   *  @return  True if the check is true, false otherwise.
502
   *
503
   *  Returns true if @p __pred is true for each element in the range
504
   *  @p [__first,__last), and false otherwise.
505
  */
506
  template<typename _InputIterator, typename _Predicate>
507
    inline bool
508
    all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
509
    { return __last == std::find_if_not(__first, __last, __pred); }
510
511
  /**
512
   *  @brief  Checks that a predicate is false for all the elements
513
   *          of a sequence.
514
   *  @ingroup non_mutating_algorithms
515
   *  @param  __first   An input iterator.
516
   *  @param  __last    An input iterator.
517
   *  @param  __pred    A predicate.
518
   *  @return  True if the check is true, false otherwise.
519
   *
520
   *  Returns true if @p __pred is false for each element in the range
521
   *  @p [__first,__last), and false otherwise.
522
  */
523
  template<typename _InputIterator, typename _Predicate>
524
    inline bool
525
    none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
526
    { return __last == _GLIBCXX_STD_A::find_if(__first, __last, __pred); }
527
528
  /**
529
   *  @brief  Checks that a predicate is false for at least an element
530
   *          of a sequence.
531
   *  @ingroup non_mutating_algorithms
532
   *  @param  __first   An input iterator.
533
   *  @param  __last    An input iterator.
534
   *  @param  __pred    A predicate.
535
   *  @return  True if the check is true, false otherwise.
536
   *
537
   *  Returns true if an element exists in the range @p
538
   *  [__first,__last) such that @p __pred is true, and false
539
   *  otherwise.
540
  */
541
  template<typename _InputIterator, typename _Predicate>
542
    inline bool
543
    any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
544
    { return !std::none_of(__first, __last, __pred); }
545
546
  /**
547
   *  @brief  Find the first element in a sequence for which a
548
   *          predicate is false.
549
   *  @ingroup non_mutating_algorithms
550
   *  @param  __first  An input iterator.
551
   *  @param  __last   An input iterator.
552
   *  @param  __pred   A predicate.
553
   *  @return   The first iterator @c i in the range @p [__first,__last)
554
   *  such that @p __pred(*i) is false, or @p __last if no such iterator exists.
555
  */
556
  template<typename _InputIterator, typename _Predicate>
557
    inline _InputIterator
558
    find_if_not(_InputIterator __first, _InputIterator __last,
559
		_Predicate __pred)
560
    {
561
      // concept requirements
562
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
563
      __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
564
	      typename iterator_traits<_InputIterator>::value_type>)
565
      __glibcxx_requires_valid_range(__first, __last);
566
      return std::__find_if_not(__first, __last,
567
				__gnu_cxx::__ops::__pred_iter(__pred));
568
    }
569
570
  /**
571
   *  @brief  Checks whether the sequence is partitioned.
572
   *  @ingroup mutating_algorithms
573
   *  @param  __first  An input iterator.
574
   *  @param  __last   An input iterator.
575
   *  @param  __pred   A predicate.
576
   *  @return  True if the range @p [__first,__last) is partioned by @p __pred,
577
   *  i.e. if all elements that satisfy @p __pred appear before those that
578
   *  do not.
579
  */
580
  template<typename _InputIterator, typename _Predicate>
581
    inline bool
582
    is_partitioned(_InputIterator __first, _InputIterator __last,
583
		   _Predicate __pred)
584
    {
585
      __first = std::find_if_not(__first, __last, __pred);
586
      return std::none_of(__first, __last, __pred);
587
    }
588
589
  /**
590
   *  @brief  Find the partition point of a partitioned range.
591
   *  @ingroup mutating_algorithms
592
   *  @param  __first   An iterator.
593
   *  @param  __last    Another iterator.
594
   *  @param  __pred    A predicate.
595
   *  @return  An iterator @p mid such that @p all_of(__first, mid, __pred)
596
   *           and @p none_of(mid, __last, __pred) are both true.
597
  */
598
  template<typename _ForwardIterator, typename _Predicate>
599
    _ForwardIterator
600
    partition_point(_ForwardIterator __first, _ForwardIterator __last,
601
		    _Predicate __pred)
602
    {
603
      // concept requirements
604
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
605
      __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
606
	      typename iterator_traits<_ForwardIterator>::value_type>)
607
608
      // A specific debug-mode test will be necessary...
609
      __glibcxx_requires_valid_range(__first, __last);
610
611
      typedef typename iterator_traits<_ForwardIterator>::difference_type
612
	_DistanceType;
613
614
      _DistanceType __len = std::distance(__first, __last);
615
      _DistanceType __half;
616
      _ForwardIterator __middle;
617
618
      while (__len > 0)
619
	{
620
	  __half = __len >> 1;
621
	  __middle = __first;
622
	  std::advance(__middle, __half);
623
	  if (__pred(*__middle))
624
	    {
625
	      __first = __middle;
626
	      ++__first;
627
	      __len = __len - __half - 1;
628
	    }
629
	  else
630
	    __len = __half;
631
	}
632
      return __first;
633
    }
634
#endif
635
636
  template<typename _InputIterator, typename _OutputIterator,
637
	   typename _Predicate>
638
    _OutputIterator
639
    __remove_copy_if(_InputIterator __first, _InputIterator __last,
640
		     _OutputIterator __result, _Predicate __pred)
641
    {
642
      for (; __first != __last; ++__first)
643
	if (!__pred(__first))
644
	  {
645
	    *__result = *__first;
646
	    ++__result;
647
	  }
648
      return __result;
649
    }
650
651
  /**
652
   *  @brief Copy a sequence, removing elements of a given value.
653
   *  @ingroup mutating_algorithms
654
   *  @param  __first   An input iterator.
655
   *  @param  __last    An input iterator.
656
   *  @param  __result  An output iterator.
657
   *  @param  __value   The value to be removed.
658
   *  @return   An iterator designating the end of the resulting sequence.
659
   *
660
   *  Copies each element in the range @p [__first,__last) not equal
661
   *  to @p __value to the range beginning at @p __result.
662
   *  remove_copy() is stable, so the relative order of elements that
663
   *  are copied is unchanged.
664
  */
665
  template<typename _InputIterator, typename _OutputIterator, typename _Tp>
666
    inline _OutputIterator
667
    remove_copy(_InputIterator __first, _InputIterator __last,
668
		_OutputIterator __result, const _Tp& __value)
669
    {
670
      // concept requirements
671
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
672
      __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
673
	    typename iterator_traits<_InputIterator>::value_type>)
674
      __glibcxx_function_requires(_EqualOpConcept<
675
	    typename iterator_traits<_InputIterator>::value_type, _Tp>)
676
      __glibcxx_requires_valid_range(__first, __last);
677
678
      return std::__remove_copy_if(__first, __last, __result,
679
	__gnu_cxx::__ops::__iter_equals_val(__value));
680
    }
681
682
  /**
683
   *  @brief Copy a sequence, removing elements for which a predicate is true.
684
   *  @ingroup mutating_algorithms
685
   *  @param  __first   An input iterator.
686
   *  @param  __last    An input iterator.
687
   *  @param  __result  An output iterator.
688
   *  @param  __pred    A predicate.
689
   *  @return   An iterator designating the end of the resulting sequence.
690
   *
691
   *  Copies each element in the range @p [__first,__last) for which
692
   *  @p __pred returns false to the range beginning at @p __result.
693
   *
694
   *  remove_copy_if() is stable, so the relative order of elements that are
695
   *  copied is unchanged.
696
  */
697
  template<typename _InputIterator, typename _OutputIterator,
698
	   typename _Predicate>
699
    inline _OutputIterator
700
    remove_copy_if(_InputIterator __first, _InputIterator __last,
701
		   _OutputIterator __result, _Predicate __pred)
702
    {
703
      // concept requirements
704
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
705
      __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
706
	    typename iterator_traits<_InputIterator>::value_type>)
707
      __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
708
	    typename iterator_traits<_InputIterator>::value_type>)
709
      __glibcxx_requires_valid_range(__first, __last);
710
711
      return std::__remove_copy_if(__first, __last, __result,
712
				   __gnu_cxx::__ops::__pred_iter(__pred));
713
    }
714
715
#if __cplusplus >= 201103L
716
  /**
717
   *  @brief Copy the elements of a sequence for which a predicate is true.
718
   *  @ingroup mutating_algorithms
719
   *  @param  __first   An input iterator.
720
   *  @param  __last    An input iterator.
721
   *  @param  __result  An output iterator.
722
   *  @param  __pred    A predicate.
723
   *  @return   An iterator designating the end of the resulting sequence.
724
   *
725
   *  Copies each element in the range @p [__first,__last) for which
726
   *  @p __pred returns true to the range beginning at @p __result.
727
   *
728
   *  copy_if() is stable, so the relative order of elements that are
729
   *  copied is unchanged.
730
  */
731
  template<typename _InputIterator, typename _OutputIterator,
732
	   typename _Predicate>
733
    _OutputIterator
734
    copy_if(_InputIterator __first, _InputIterator __last,
735
	    _OutputIterator __result, _Predicate __pred)
736
    {
737
      // concept requirements
738
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
739
      __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
740
	    typename iterator_traits<_InputIterator>::value_type>)
741
      __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
742
	    typename iterator_traits<_InputIterator>::value_type>)
743
      __glibcxx_requires_valid_range(__first, __last);
744
745
      for (; __first != __last; ++__first)
746
	if (__pred(*__first))
747
	  {
748
	    *__result = *__first;
749
	    ++__result;
750
	  }
751
      return __result;
752
    }
753
754
  template<typename _InputIterator, typename _Size, typename _OutputIterator>
755
    _OutputIterator
756
    __copy_n(_InputIterator __first, _Size __n,
757
	     _OutputIterator __result, input_iterator_tag)
758
    {
759
      if (__n > 0)
760
	{
761
	  while (true)
762
	    {
763
	      *__result = *__first;
764
	      ++__result;
765
	      if (--__n > 0)
766
		++__first;
767
	      else
768
		break;
769
	    }
770
	}
771
      return __result;
772
    }
773
774
  template<typename _RandomAccessIterator, typename _Size,
775
	   typename _OutputIterator>
776
    inline _OutputIterator
777
    __copy_n(_RandomAccessIterator __first, _Size __n,
778
	     _OutputIterator __result, random_access_iterator_tag)
779
    { return std::copy(__first, __first + __n, __result); }
780
781
  /**
782
   *  @brief Copies the range [first,first+n) into [result,result+n).
783
   *  @ingroup mutating_algorithms
784
   *  @param  __first  An input iterator.
785
   *  @param  __n      The number of elements to copy.
786
   *  @param  __result An output iterator.
787
   *  @return  result+n.
788
   *
789
   *  This inline function will boil down to a call to @c memmove whenever
790
   *  possible.  Failing that, if random access iterators are passed, then the
791
   *  loop count will be known (and therefore a candidate for compiler
792
   *  optimizations such as unrolling).
793
  */
794
  template<typename _InputIterator, typename _Size, typename _OutputIterator>
795
    inline _OutputIterator
796
    copy_n(_InputIterator __first, _Size __n, _OutputIterator __result)
797
    {
798
      // concept requirements
799
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
800
      __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
801
	    typename iterator_traits<_InputIterator>::value_type>)
802
803
      return std::__copy_n(__first, __n, __result,
804
			   std::__iterator_category(__first));
805
    }
806
807
  /**
808
   *  @brief Copy the elements of a sequence to separate output sequences
809
   *         depending on the truth value of a predicate.
810
   *  @ingroup mutating_algorithms
811
   *  @param  __first   An input iterator.
812
   *  @param  __last    An input iterator.
813
   *  @param  __out_true   An output iterator.
814
   *  @param  __out_false  An output iterator.
815
   *  @param  __pred    A predicate.
816
   *  @return   A pair designating the ends of the resulting sequences.
817
   *
818
   *  Copies each element in the range @p [__first,__last) for which
819
   *  @p __pred returns true to the range beginning at @p out_true
820
   *  and each element for which @p __pred returns false to @p __out_false.
821
  */
822
  template<typename _InputIterator, typename _OutputIterator1,
823
	   typename _OutputIterator2, typename _Predicate>
824
    pair<_OutputIterator1, _OutputIterator2>
825
    partition_copy(_InputIterator __first, _InputIterator __last,
826
		   _OutputIterator1 __out_true, _OutputIterator2 __out_false,
827
		   _Predicate __pred)
828
    {
829
      // concept requirements
830
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
831
      __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator1,
832
	    typename iterator_traits<_InputIterator>::value_type>)
833
      __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator2,
834
	    typename iterator_traits<_InputIterator>::value_type>)
835
      __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
836
	    typename iterator_traits<_InputIterator>::value_type>)
837
      __glibcxx_requires_valid_range(__first, __last);
838
      
839
      for (; __first != __last; ++__first)
840
	if (__pred(*__first))
841
	  {
842
	    *__out_true = *__first;
843
	    ++__out_true;
844
	  }
845
	else
846
	  {
847
	    *__out_false = *__first;
848
	    ++__out_false;
849
	  }
850
851
      return pair<_OutputIterator1, _OutputIterator2>(__out_true, __out_false);
852
    }
853
#endif
854
855
  template<typename _ForwardIterator, typename _Predicate>
856
    _ForwardIterator
857
    __remove_if(_ForwardIterator __first, _ForwardIterator __last,
858
		_Predicate __pred)
859
    {
860
      __first = std::__find_if(__first, __last, __pred);
861
      if (__first == __last)
862
        return __first;
863
      _ForwardIterator __result = __first;
864
      ++__first;
865
      for (; __first != __last; ++__first)
866
        if (!__pred(__first))
867
          {
868
            *__result = _GLIBCXX_MOVE(*__first);
869
            ++__result;
870
          }
871
      return __result;
872
    }
873
874
  /**
875
   *  @brief Remove elements from a sequence.
876
   *  @ingroup mutating_algorithms
877
   *  @param  __first  An input iterator.
878
   *  @param  __last   An input iterator.
879
   *  @param  __value  The value to be removed.
880
   *  @return   An iterator designating the end of the resulting sequence.
881
   *
882
   *  All elements equal to @p __value are removed from the range
883
   *  @p [__first,__last).
884
   *
885
   *  remove() is stable, so the relative order of elements that are
886
   *  not removed is unchanged.
887
   *
888
   *  Elements between the end of the resulting sequence and @p __last
889
   *  are still present, but their value is unspecified.
890
  */
891
  template<typename _ForwardIterator, typename _Tp>
892
    inline _ForwardIterator
893
    remove(_ForwardIterator __first, _ForwardIterator __last,
894
	   const _Tp& __value)
895
    {
896
      // concept requirements
897
      __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
898
				  _ForwardIterator>)
899
      __glibcxx_function_requires(_EqualOpConcept<
900
	    typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
901
      __glibcxx_requires_valid_range(__first, __last);
902
903
      return std::__remove_if(__first, __last,
904
		__gnu_cxx::__ops::__iter_equals_val(__value));
905
    }
906
907
  /**
908
   *  @brief Remove elements from a sequence using a predicate.
909
   *  @ingroup mutating_algorithms
910
   *  @param  __first  A forward iterator.
911
   *  @param  __last   A forward iterator.
912
   *  @param  __pred   A predicate.
913
   *  @return   An iterator designating the end of the resulting sequence.
914
   *
915
   *  All elements for which @p __pred returns true are removed from the range
916
   *  @p [__first,__last).
917
   *
918
   *  remove_if() is stable, so the relative order of elements that are
919
   *  not removed is unchanged.
920
   *
921
   *  Elements between the end of the resulting sequence and @p __last
922
   *  are still present, but their value is unspecified.
923
  */
924
  template<typename _ForwardIterator, typename _Predicate>
925
    inline _ForwardIterator
926
    remove_if(_ForwardIterator __first, _ForwardIterator __last,
927
	      _Predicate __pred)
928
    {
929
      // concept requirements
930
      __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
931
				  _ForwardIterator>)
932
      __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
933
	    typename iterator_traits<_ForwardIterator>::value_type>)
934
      __glibcxx_requires_valid_range(__first, __last);
935
936
      return std::__remove_if(__first, __last,
937
			      __gnu_cxx::__ops::__pred_iter(__pred));
938
    }
939
940
  template<typename _ForwardIterator, typename _BinaryPredicate>
941
    _ForwardIterator
942
    __adjacent_find(_ForwardIterator __first, _ForwardIterator __last,
943
		    _BinaryPredicate __binary_pred)
944
    {
945
      if (__first == __last)
946
	return __last;
947
      _ForwardIterator __next = __first;
948
      while (++__next != __last)
949
	{
950
	  if (__binary_pred(__first, __next))
951
	    return __first;
952
	  __first = __next;
953
	}
954
      return __last;
955
    }
956
957
  template<typename _ForwardIterator, typename _BinaryPredicate>
958
    _ForwardIterator
959
    __unique(_ForwardIterator __first, _ForwardIterator __last,
960
	     _BinaryPredicate __binary_pred)
961
    {
962
      // Skip the beginning, if already unique.
963
      __first = std::__adjacent_find(__first, __last, __binary_pred);
964
      if (__first == __last)
965
	return __last;
966
967
      // Do the real copy work.
968
      _ForwardIterator __dest = __first;
969
      ++__first;
970
      while (++__first != __last)
971
	if (!__binary_pred(__dest, __first))
972
	  *++__dest = _GLIBCXX_MOVE(*__first);
973
      return ++__dest;
974
    }
975
976
  /**
977
   *  @brief Remove consecutive duplicate values from a sequence.
978
   *  @ingroup mutating_algorithms
979
   *  @param  __first  A forward iterator.
980
   *  @param  __last   A forward iterator.
981
   *  @return  An iterator designating the end of the resulting sequence.
982
   *
983
   *  Removes all but the first element from each group of consecutive
984
   *  values that compare equal.
985
   *  unique() is stable, so the relative order of elements that are
986
   *  not removed is unchanged.
987
   *  Elements between the end of the resulting sequence and @p __last
988
   *  are still present, but their value is unspecified.
989
  */
990
  template<typename _ForwardIterator>
991
    inline _ForwardIterator
992
    unique(_ForwardIterator __first, _ForwardIterator __last)
993
    {
994
      // concept requirements
995
      __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
996
				  _ForwardIterator>)
997
      __glibcxx_function_requires(_EqualityComparableConcept<
998
		     typename iterator_traits<_ForwardIterator>::value_type>)
999
      __glibcxx_requires_valid_range(__first, __last);
1000
1001
      return std::__unique(__first, __last,
1002
			   __gnu_cxx::__ops::__iter_equal_to_iter());
1003
    }
1004
1005
  /**
1006
   *  @brief Remove consecutive values from a sequence using a predicate.
1007
   *  @ingroup mutating_algorithms
1008
   *  @param  __first        A forward iterator.
1009
   *  @param  __last         A forward iterator.
1010
   *  @param  __binary_pred  A binary predicate.
1011
   *  @return  An iterator designating the end of the resulting sequence.
1012
   *
1013
   *  Removes all but the first element from each group of consecutive
1014
   *  values for which @p __binary_pred returns true.
1015
   *  unique() is stable, so the relative order of elements that are
1016
   *  not removed is unchanged.
1017
   *  Elements between the end of the resulting sequence and @p __last
1018
   *  are still present, but their value is unspecified.
1019
  */
1020
  template<typename _ForwardIterator, typename _BinaryPredicate>
1021
    inline _ForwardIterator
1022
    unique(_ForwardIterator __first, _ForwardIterator __last,
1023
           _BinaryPredicate __binary_pred)
1024
    {
1025
      // concept requirements
1026
      __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
1027
				  _ForwardIterator>)
1028
      __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
1029
		typename iterator_traits<_ForwardIterator>::value_type,
1030
		typename iterator_traits<_ForwardIterator>::value_type>)
1031
      __glibcxx_requires_valid_range(__first, __last);
1032
1033
      return std::__unique(__first, __last,
1034
			   __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
1035
    }
1036
1037
  /**
1038
   *  This is an uglified
1039
   *  unique_copy(_InputIterator, _InputIterator, _OutputIterator,
1040
   *              _BinaryPredicate)
1041
   *  overloaded for forward iterators and output iterator as result.
1042
  */
1043
  template<typename _ForwardIterator, typename _OutputIterator,
1044
	   typename _BinaryPredicate>
1045
    _OutputIterator
1046
    __unique_copy(_ForwardIterator __first, _ForwardIterator __last,
1047
		  _OutputIterator __result, _BinaryPredicate __binary_pred,
1048
		  forward_iterator_tag, output_iterator_tag)
1049
    {
1050
      // concept requirements -- iterators already checked
1051
      __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
1052
	  typename iterator_traits<_ForwardIterator>::value_type,
1053
	  typename iterator_traits<_ForwardIterator>::value_type>)
1054
1055
      _ForwardIterator __next = __first;
1056
      *__result = *__first;
1057
      while (++__next != __last)
1058
	if (!__binary_pred(__first, __next))
1059
	  {
1060
	    __first = __next;
1061
	    *++__result = *__first;
1062
	  }
1063
      return ++__result;
1064
    }
1065
1066
  /**
1067
   *  This is an uglified
1068
   *  unique_copy(_InputIterator, _InputIterator, _OutputIterator,
1069
   *              _BinaryPredicate)
1070
   *  overloaded for input iterators and output iterator as result.
1071
  */
1072
  template<typename _InputIterator, typename _OutputIterator,
1073
	   typename _BinaryPredicate>
1074
    _OutputIterator
1075
    __unique_copy(_InputIterator __first, _InputIterator __last,
1076
		  _OutputIterator __result, _BinaryPredicate __binary_pred,
1077
		  input_iterator_tag, output_iterator_tag)
1078
    {
1079
      // concept requirements -- iterators already checked
1080
      __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
1081
	  typename iterator_traits<_InputIterator>::value_type,
1082
	  typename iterator_traits<_InputIterator>::value_type>)
1083
1084
      typename iterator_traits<_InputIterator>::value_type __value = *__first;
1085
      *__result = __value;
1086
      while (++__first != __last)
1087
	if (!__binary_pred(__first, __value))
1088
	  {
1089
	    __value = *__first;
1090
	    *++__result = __value;
1091
	  }
1092
      return ++__result;
1093
    }
1094
1095
  /**
1096
   *  This is an uglified
1097
   *  unique_copy(_InputIterator, _InputIterator, _OutputIterator,
1098
   *              _BinaryPredicate)
1099
   *  overloaded for input iterators and forward iterator as result.
1100
  */
1101
  template<typename _InputIterator, typename _ForwardIterator,
1102
	   typename _BinaryPredicate>
1103
    _ForwardIterator
1104
    __unique_copy(_InputIterator __first, _InputIterator __last,
1105
		  _ForwardIterator __result, _BinaryPredicate __binary_pred,
1106
		  input_iterator_tag, forward_iterator_tag)
1107
    {
1108
      // concept requirements -- iterators already checked
1109
      __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
1110
	  typename iterator_traits<_ForwardIterator>::value_type,
1111
	  typename iterator_traits<_InputIterator>::value_type>)
1112
      *__result = *__first;
1113
      while (++__first != __last)
1114
	if (!__binary_pred(__result, __first))
1115
	  *++__result = *__first;
1116
      return ++__result;
1117
    }
1118
1119
  /**
1120
   *  This is an uglified reverse(_BidirectionalIterator,
1121
   *                              _BidirectionalIterator)
1122
   *  overloaded for bidirectional iterators.
1123
  */
1124
  template<typename _BidirectionalIterator>
1125
    void
1126
    __reverse(_BidirectionalIterator __first, _BidirectionalIterator __last,
1127
	      bidirectional_iterator_tag)
1128
    {
1129
      while (true)
1130
	if (__first == __last || __first == --__last)
1131
	  return;
1132
	else
1133
	  {
1134
	    std::iter_swap(__first, __last);
1135
	    ++__first;
1136
	  }
1137
    }
1138
1139
  /**
1140
   *  This is an uglified reverse(_BidirectionalIterator,
1141
   *                              _BidirectionalIterator)
1142
   *  overloaded for random access iterators.
1143
  */
1144
  template<typename _RandomAccessIterator>
1145
    void
1146
    __reverse(_RandomAccessIterator __first, _RandomAccessIterator __last,
1147
	      random_access_iterator_tag)
1148
    {
1149
      if (__first == __last)
1150
	return;
1151
      --__last;
1152
      while (__first < __last)
1153
	{
1154
	  std::iter_swap(__first, __last);
1155
	  ++__first;
1156
	  --__last;
1157
	}
1158
    }
1159
1160
  /**
1161
   *  @brief Reverse a sequence.
1162
   *  @ingroup mutating_algorithms
1163
   *  @param  __first  A bidirectional iterator.
1164
   *  @param  __last   A bidirectional iterator.
1165
   *  @return   reverse() returns no value.
1166
   *
1167
   *  Reverses the order of the elements in the range @p [__first,__last),
1168
   *  so that the first element becomes the last etc.
1169
   *  For every @c i such that @p 0<=i<=(__last-__first)/2), @p reverse()
1170
   *  swaps @p *(__first+i) and @p *(__last-(i+1))
1171
  */
1172
  template<typename _BidirectionalIterator>
1173
    inline void
1174
    reverse(_BidirectionalIterator __first, _BidirectionalIterator __last)
1175
    {
1176
      // concept requirements
1177
      __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<
1178
				  _BidirectionalIterator>)
1179
      __glibcxx_requires_valid_range(__first, __last);
1180
      std::__reverse(__first, __last, std::__iterator_category(__first));
1181
    }
1182
1183
  /**
1184
   *  @brief Copy a sequence, reversing its elements.
1185
   *  @ingroup mutating_algorithms
1186
   *  @param  __first   A bidirectional iterator.
1187
   *  @param  __last    A bidirectional iterator.
1188
   *  @param  __result  An output iterator.
1189
   *  @return  An iterator designating the end of the resulting sequence.
1190
   *
1191
   *  Copies the elements in the range @p [__first,__last) to the
1192
   *  range @p [__result,__result+(__last-__first)) such that the
1193
   *  order of the elements is reversed.  For every @c i such that @p
1194
   *  0<=i<=(__last-__first), @p reverse_copy() performs the
1195
   *  assignment @p *(__result+(__last-__first)-1-i) = *(__first+i).
1196
   *  The ranges @p [__first,__last) and @p
1197
   *  [__result,__result+(__last-__first)) must not overlap.
1198
  */
1199
  template<typename _BidirectionalIterator, typename _OutputIterator>
1200
    _OutputIterator
1201
    reverse_copy(_BidirectionalIterator __first, _BidirectionalIterator __last,
1202
		 _OutputIterator __result)
1203
    {
1204
      // concept requirements
1205
      __glibcxx_function_requires(_BidirectionalIteratorConcept<
1206
				  _BidirectionalIterator>)
1207
      __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
1208
		typename iterator_traits<_BidirectionalIterator>::value_type>)
1209
      __glibcxx_requires_valid_range(__first, __last);
1210
1211
      while (__first != __last)
1212
	{
1213
	  --__last;
1214
	  *__result = *__last;
1215
	  ++__result;
1216
	}
1217
      return __result;
1218
    }
1219
1220
  /**
1221
   *  This is a helper function for the rotate algorithm specialized on RAIs.
1222
   *  It returns the greatest common divisor of two integer values.
1223
  */
1224
  template<typename _EuclideanRingElement>
1225
    _EuclideanRingElement
1226
    __gcd(_EuclideanRingElement __m, _EuclideanRingElement __n)
1227
    {
1228
      while (__n != 0)
1229
	{
1230
	  _EuclideanRingElement __t = __m % __n;
1231
	  __m = __n;
1232
	  __n = __t;
1233
	}
1234
      return __m;
1235
    }
1236
1237
  /// This is a helper function for the rotate algorithm.
1238
  template<typename _ForwardIterator>
1239
    void
1240
    __rotate(_ForwardIterator __first,
1241
	     _ForwardIterator __middle,
1242
	     _ForwardIterator __last,
1243
	     forward_iterator_tag)
1244
    {
1245
      if (__first == __middle || __last  == __middle)
1246
	return;
1247
1248
      _ForwardIterator __first2 = __middle;
1249
      do
1250
	{
1251
	  std::iter_swap(__first, __first2);
1252
	  ++__first;
1253
	  ++__first2;
1254
	  if (__first == __middle)
1255
	    __middle = __first2;
1256
	}
1257
      while (__first2 != __last);
1258
1259
      __first2 = __middle;
1260
1261
      while (__first2 != __last)
1262
	{
1263
	  std::iter_swap(__first, __first2);
1264
	  ++__first;
1265
	  ++__first2;
1266
	  if (__first == __middle)
1267
	    __middle = __first2;
1268
	  else if (__first2 == __last)
1269
	    __first2 = __middle;
1270
	}
1271
    }
1272
1273
   /// This is a helper function for the rotate algorithm.
1274
  template<typename _BidirectionalIterator>
1275
    void
1276
    __rotate(_BidirectionalIterator __first,
1277
	     _BidirectionalIterator __middle,
1278
	     _BidirectionalIterator __last,
1279
	      bidirectional_iterator_tag)
1280
    {
1281
      // concept requirements
1282
      __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<
1283
				  _BidirectionalIterator>)
1284
1285
      if (__first == __middle || __last  == __middle)
1286
	return;
1287
1288
      std::__reverse(__first,  __middle, bidirectional_iterator_tag());
1289
      std::__reverse(__middle, __last,   bidirectional_iterator_tag());
1290
1291
      while (__first != __middle && __middle != __last)
1292
	{
1293
	  std::iter_swap(__first, --__last);
1294
	  ++__first;
1295
	}
1296
1297
      if (__first == __middle)
1298
	std::__reverse(__middle, __last,   bidirectional_iterator_tag());
1299
      else
1300
	std::__reverse(__first,  __middle, bidirectional_iterator_tag());
1301
    }
1302
1303
  /// This is a helper function for the rotate algorithm.
1304
  template<typename _RandomAccessIterator>
1305
    void
1306
    __rotate(_RandomAccessIterator __first,
1307
	     _RandomAccessIterator __middle,
1308
	     _RandomAccessIterator __last,
1309
	     random_access_iterator_tag)
1310
    {
1311
      // concept requirements
1312
      __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
1313
				  _RandomAccessIterator>)
1314
1315
      if (__first == __middle || __last  == __middle)
1316
	return;
1317
1318
      typedef typename iterator_traits<_RandomAccessIterator>::difference_type
1319
	_Distance;
1320
      typedef typename iterator_traits<_RandomAccessIterator>::value_type
1321
	_ValueType;
1322
1323
      _Distance __n = __last   - __first;
1324
      _Distance __k = __middle - __first;
1325
1326
      if (__k == __n - __k)
1327
	{
1328
	  std::swap_ranges(__first, __middle, __middle);
1329
	  return;
1330
	}
1331
1332
      _RandomAccessIterator __p = __first;
1333
1334
      for (;;)
1335
	{
1336
	  if (__k < __n - __k)
1337
	    {
1338
	      if (__is_pod(_ValueType) && __k == 1)
1339
		{
1340
		  _ValueType __t = _GLIBCXX_MOVE(*__p);
1341
		  _GLIBCXX_MOVE3(__p + 1, __p + __n, __p);
1342
		  *(__p + __n - 1) = _GLIBCXX_MOVE(__t);
1343
		  return;
1344
		}
1345
	      _RandomAccessIterator __q = __p + __k;
1346
	      for (_Distance __i = 0; __i < __n - __k; ++ __i)
1347
		{
1348
		  std::iter_swap(__p, __q);
1349
		  ++__p;
1350
		  ++__q;
1351
		}
1352
	      __n %= __k;
1353
	      if (__n == 0)
1354
		return;
1355
	      std::swap(__n, __k);
1356
	      __k = __n - __k;
1357
	    }
1358
	  else
1359
	    {
1360
	      __k = __n - __k;
1361
	      if (__is_pod(_ValueType) && __k == 1)
1362
		{
1363
		  _ValueType __t = _GLIBCXX_MOVE(*(__p + __n - 1));
1364
		  _GLIBCXX_MOVE_BACKWARD3(__p, __p + __n - 1, __p + __n);
1365
		  *__p = _GLIBCXX_MOVE(__t);
1366
		  return;
1367
		}
1368
	      _RandomAccessIterator __q = __p + __n;
1369
	      __p = __q - __k;
1370
	      for (_Distance __i = 0; __i < __n - __k; ++ __i)
1371
		{
1372
		  --__p;
1373
		  --__q;
1374
		  std::iter_swap(__p, __q);
1375
		}
1376
	      __n %= __k;
1377
	      if (__n == 0)
1378
		return;
1379
	      std::swap(__n, __k);
1380
	    }
1381
	}
1382
    }
1383
1384
  /**
1385
   *  @brief Rotate the elements of a sequence.
1386
   *  @ingroup mutating_algorithms
1387
   *  @param  __first   A forward iterator.
1388
   *  @param  __middle  A forward iterator.
1389
   *  @param  __last    A forward iterator.
1390
   *  @return  Nothing.
1391
   *
1392
   *  Rotates the elements of the range @p [__first,__last) by 
1393
   *  @p (__middle - __first) positions so that the element at @p __middle
1394
   *  is moved to @p __first, the element at @p __middle+1 is moved to
1395
   *  @p __first+1 and so on for each element in the range
1396
   *  @p [__first,__last).
1397
   *
1398
   *  This effectively swaps the ranges @p [__first,__middle) and
1399
   *  @p [__middle,__last).
1400
   *
1401
   *  Performs
1402
   *   @p *(__first+(n+(__last-__middle))%(__last-__first))=*(__first+n)
1403
   *  for each @p n in the range @p [0,__last-__first).
1404
  */
1405
  template<typename _ForwardIterator>
1406
    inline void
1407
    rotate(_ForwardIterator __first, _ForwardIterator __middle,
1408
	   _ForwardIterator __last)
1409
    {
1410
      // concept requirements
1411
      __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
1412
				  _ForwardIterator>)
1413
      __glibcxx_requires_valid_range(__first, __middle);
1414
      __glibcxx_requires_valid_range(__middle, __last);
1415
1416
      std::__rotate(__first, __middle, __last,
1417
		    std::__iterator_category(__first));
1418
    }
1419
1420
  /**
1421
   *  @brief Copy a sequence, rotating its elements.
1422
   *  @ingroup mutating_algorithms
1423
   *  @param  __first   A forward iterator.
1424
   *  @param  __middle  A forward iterator.
1425
   *  @param  __last    A forward iterator.
1426
   *  @param  __result  An output iterator.
1427
   *  @return   An iterator designating the end of the resulting sequence.
1428
   *
1429
   *  Copies the elements of the range @p [__first,__last) to the
1430
   *  range beginning at @result, rotating the copied elements by 
1431
   *  @p (__middle-__first) positions so that the element at @p __middle
1432
   *  is moved to @p __result, the element at @p __middle+1 is moved
1433
   *  to @p __result+1 and so on for each element in the range @p
1434
   *  [__first,__last).
1435
   *
1436
   *  Performs 
1437
   *  @p *(__result+(n+(__last-__middle))%(__last-__first))=*(__first+n)
1438
   *  for each @p n in the range @p [0,__last-__first).
1439
  */
1440
  template<typename _ForwardIterator, typename _OutputIterator>
1441
    inline _OutputIterator
1442
    rotate_copy(_ForwardIterator __first, _ForwardIterator __middle,
1443
                _ForwardIterator __last, _OutputIterator __result)
1444
    {
1445
      // concept requirements
1446
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1447
      __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
1448
		typename iterator_traits<_ForwardIterator>::value_type>)
1449
      __glibcxx_requires_valid_range(__first, __middle);
1450
      __glibcxx_requires_valid_range(__middle, __last);
1451
1452
      return std::copy(__first, __middle,
1453
                       std::copy(__middle, __last, __result));
1454
    }
1455
1456
  /// This is a helper function...
1457
  template<typename _ForwardIterator, typename _Predicate>
1458
    _ForwardIterator
1459
    __partition(_ForwardIterator __first, _ForwardIterator __last,
1460
		_Predicate __pred, forward_iterator_tag)
1461
    {
1462
      if (__first == __last)
1463
	return __first;
1464
1465
      while (__pred(*__first))
1466
	if (++__first == __last)
1467
	  return __first;
1468
1469
      _ForwardIterator __next = __first;
1470
1471
      while (++__next != __last)
1472
	if (__pred(*__next))
1473
	  {
1474
	    std::iter_swap(__first, __next);
1475
	    ++__first;
1476
	  }
1477
1478
      return __first;
1479
    }
1480
1481
  /// This is a helper function...
1482
  template<typename _BidirectionalIterator, typename _Predicate>
1483
    _BidirectionalIterator
1484
    __partition(_BidirectionalIterator __first, _BidirectionalIterator __last,
1485
		_Predicate __pred, bidirectional_iterator_tag)
1486
    {
1487
      while (true)
1488
	{
1489
	  while (true)
1490
	    if (__first == __last)
1491
	      return __first;
1492
	    else if (__pred(*__first))
1493
	      ++__first;
1494
	    else
1495
	      break;
1496
	  --__last;
1497
	  while (true)
1498
	    if (__first == __last)
1499
	      return __first;
1500
	    else if (!bool(__pred(*__last)))
1501
	      --__last;
1502
	    else
1503
	      break;
1504
	  std::iter_swap(__first, __last);
1505
	  ++__first;
1506
	}
1507
    }
1508
1509
  // partition
1510
1511
  /// This is a helper function...
1512
  /// Requires __len != 0 and !__pred(*__first),
1513
  /// same as __stable_partition_adaptive.
1514
  template<typename _ForwardIterator, typename _Predicate, typename _Distance>
1515
    _ForwardIterator
1516
    __inplace_stable_partition(_ForwardIterator __first,
1517
			       _Predicate __pred, _Distance __len)
1518
    {
1519
      if (__len == 1)
1520
	return __first;
1521
      _ForwardIterator __middle = __first;
1522
      std::advance(__middle, __len / 2);
1523
      _ForwardIterator __left_split =
1524
	std::__inplace_stable_partition(__first, __pred, __len / 2);
1525
      // Advance past true-predicate values to satisfy this
1526
      // function's preconditions.
1527
      _Distance __right_len = __len - __len / 2;
1528
      _ForwardIterator __right_split =
1529
	std::__find_if_not_n(__middle, __right_len, __pred);
1530
      if (__right_len)
1531
	__right_split = std::__inplace_stable_partition(__middle,
1532
							__pred,
1533
							__right_len);
1534
      std::rotate(__left_split, __middle, __right_split);
1535
      std::advance(__left_split, std::distance(__middle, __right_split));
1536
      return __left_split;
1537
    }
1538
1539
  /// This is a helper function...
1540
  /// Requires __first != __last and !__pred(__first)
1541
  /// and __len == distance(__first, __last).
1542
  ///
1543
  /// !__pred(__first) allows us to guarantee that we don't
1544
  /// move-assign an element onto itself.
1545
  template<typename _ForwardIterator, typename _Pointer, typename _Predicate,
1546
	   typename _Distance>
1547
    _ForwardIterator
1548
    __stable_partition_adaptive(_ForwardIterator __first,
1549
				_ForwardIterator __last,
1550
				_Predicate __pred, _Distance __len,
1551
				_Pointer __buffer,
1552
				_Distance __buffer_size)
1553
    {
1554
      if (__len <= __buffer_size)
1555
	{
1556
	  _ForwardIterator __result1 = __first;
1557
	  _Pointer __result2 = __buffer;
1558
	  // The precondition guarantees that !__pred(__first), so
1559
	  // move that element to the buffer before starting the loop.
1560
	  // This ensures that we only call __pred once per element.
1561
	  *__result2 = _GLIBCXX_MOVE(*__first);
1562
	  ++__result2;
1563
	  ++__first;
1564
	  for (; __first != __last; ++__first)
1565
	    if (__pred(__first))
1566
	      {
1567
		*__result1 = _GLIBCXX_MOVE(*__first);
1568
		++__result1;
1569
	      }
1570
	    else
1571
	      {
1572
		*__result2 = _GLIBCXX_MOVE(*__first);
1573
		++__result2;
1574
	      }
1575
	  _GLIBCXX_MOVE3(__buffer, __result2, __result1);
1576
	  return __result1;
1577
	}
1578
      else
1579
	{
1580
	  _ForwardIterator __middle = __first;
1581
	  std::advance(__middle, __len / 2);
1582
	  _ForwardIterator __left_split =
1583
	    std::__stable_partition_adaptive(__first, __middle, __pred,
1584
					     __len / 2, __buffer,
1585
					     __buffer_size);
1586
	  // Advance past true-predicate values to satisfy this
1587
	  // function's preconditions.
1588
	  _Distance __right_len = __len - __len / 2;
1589
	  _ForwardIterator __right_split =
1590
	    std::__find_if_not_n(__middle, __right_len, __pred);
1591
	  if (__right_len)
1592
	    __right_split =
1593
	      std::__stable_partition_adaptive(__right_split, __last, __pred,
1594
					       __right_len,
1595
					       __buffer, __buffer_size);
1596
	  std::rotate(__left_split, __middle, __right_split);
1597
	  std::advance(__left_split, std::distance(__middle, __right_split));
1598
	  return __left_split;
1599
	}
1600
    }
1601
1602
  template<typename _ForwardIterator, typename _Predicate>
1603
    _ForwardIterator
1604
    __stable_partition(_ForwardIterator __first, _ForwardIterator __last,
1605
		       _Predicate __pred)
1606
    {
1607
      __first = std::__find_if_not(__first, __last, __pred);
1608
1609
      if (__first == __last)
1610
	return __first;
1611
1612
      typedef typename iterator_traits<_ForwardIterator>::value_type
1613
	_ValueType;
1614
      typedef typename iterator_traits<_ForwardIterator>::difference_type
1615
	_DistanceType;
1616
1617
      _Temporary_buffer<_ForwardIterator, _ValueType> __buf(__first, __last);
1618
      if (__buf.size() > 0)
1619
	return
1620
	  std::__stable_partition_adaptive(__first, __last, __pred,
1621
					   _DistanceType(__buf.requested_size()),
1622
					   __buf.begin(),
1623
					   _DistanceType(__buf.size()));
1624
      else
1625
	return
1626
	  std::__inplace_stable_partition(__first, __pred,
1627
					  _DistanceType(__buf.requested_size()));
1628
    }
1629
1630
  /**
1631
   *  @brief Move elements for which a predicate is true to the beginning
1632
   *         of a sequence, preserving relative ordering.
1633
   *  @ingroup mutating_algorithms
1634
   *  @param  __first   A forward iterator.
1635
   *  @param  __last    A forward iterator.
1636
   *  @param  __pred    A predicate functor.
1637
   *  @return  An iterator @p middle such that @p __pred(i) is true for each
1638
   *  iterator @p i in the range @p [first,middle) and false for each @p i
1639
   *  in the range @p [middle,last).
1640
   *
1641
   *  Performs the same function as @p partition() with the additional
1642
   *  guarantee that the relative ordering of elements in each group is
1643
   *  preserved, so any two elements @p x and @p y in the range
1644
   *  @p [__first,__last) such that @p __pred(x)==__pred(y) will have the same
1645
   *  relative ordering after calling @p stable_partition().
1646
  */
1647
  template<typename _ForwardIterator, typename _Predicate>
1648
    inline _ForwardIterator
1649
    stable_partition(_ForwardIterator __first, _ForwardIterator __last,
1650
		     _Predicate __pred)
1651
    {
1652
      // concept requirements
1653
      __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
1654
				  _ForwardIterator>)
1655
      __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
1656
	    typename iterator_traits<_ForwardIterator>::value_type>)
1657
      __glibcxx_requires_valid_range(__first, __last);
1658
1659
      return std::__stable_partition(__first, __last,
1660
				     __gnu_cxx::__ops::__pred_iter(__pred));
1661
    }
1662
1663
  /// This is a helper function for the sort routines.
1664
  template<typename _RandomAccessIterator, typename _Compare>
1665
    void
1666
    __heap_select(_RandomAccessIterator __first,
1667
		  _RandomAccessIterator __middle,
1668
		  _RandomAccessIterator __last, _Compare __comp)
1669
    {
1670
      std::__make_heap(__first, __middle, __comp);
1671
      for (_RandomAccessIterator __i = __middle; __i < __last; ++__i)
1672
	if (__comp(__i, __first))
1673
	  std::__pop_heap(__first, __middle, __i, __comp);
1674
    }
1675
1676
  // partial_sort
1677
1678
  template<typename _InputIterator, typename _RandomAccessIterator,
1679
	   typename _Compare>
1680
    _RandomAccessIterator
1681
    __partial_sort_copy(_InputIterator __first, _InputIterator __last,
1682
			_RandomAccessIterator __result_first,
1683
			_RandomAccessIterator __result_last,
1684
			_Compare __comp)
1685
    {
1686
      typedef typename iterator_traits<_InputIterator>::value_type
1687
	_InputValueType;
1688
      typedef iterator_traits<_RandomAccessIterator> _RItTraits;
1689
      typedef typename _RItTraits::difference_type _DistanceType;
1690
1691
      if (__result_first == __result_last)
1692
	return __result_last;
1693
      _RandomAccessIterator __result_real_last = __result_first;
1694
      while (__first != __last && __result_real_last != __result_last)
1695
	{
1696
	  *__result_real_last = *__first;
1697
	  ++__result_real_last;
1698
	  ++__first;
1699
	}
1700
      
1701
      std::__make_heap(__result_first, __result_real_last, __comp);
1702
      while (__first != __last)
1703
	{
1704
	  if (__comp(__first, __result_first))
1705
	    std::__adjust_heap(__result_first, _DistanceType(0),
1706
			       _DistanceType(__result_real_last
1707
					     - __result_first),
1708
			       _InputValueType(*__first), __comp);
1709
	  ++__first;
1710
	}
1711
      std::__sort_heap(__result_first, __result_real_last, __comp);
1712
      return __result_real_last;
1713
    }
1714
1715
  /**
1716
   *  @brief Copy the smallest elements of a sequence.
1717
   *  @ingroup sorting_algorithms
1718
   *  @param  __first   An iterator.
1719
   *  @param  __last    Another iterator.
1720
   *  @param  __result_first   A random-access iterator.
1721
   *  @param  __result_last    Another random-access iterator.
1722
   *  @return   An iterator indicating the end of the resulting sequence.
1723
   *
1724
   *  Copies and sorts the smallest N values from the range @p [__first,__last)
1725
   *  to the range beginning at @p __result_first, where the number of
1726
   *  elements to be copied, @p N, is the smaller of @p (__last-__first) and
1727
   *  @p (__result_last-__result_first).
1728
   *  After the sort if @e i and @e j are iterators in the range
1729
   *  @p [__result_first,__result_first+N) such that i precedes j then
1730
   *  *j<*i is false.
1731
   *  The value returned is @p __result_first+N.
1732
  */
1733
  template<typename _InputIterator, typename _RandomAccessIterator>
1734
    inline _RandomAccessIterator
1735
    partial_sort_copy(_InputIterator __first, _InputIterator __last,
1736
		      _RandomAccessIterator __result_first,
1737
		      _RandomAccessIterator __result_last)
1738
    {
1739
      typedef typename iterator_traits<_InputIterator>::value_type
1740
	_InputValueType;
1741
      typedef typename iterator_traits<_RandomAccessIterator>::value_type
1742
	_OutputValueType;
1743
      typedef typename iterator_traits<_RandomAccessIterator>::difference_type
1744
	_DistanceType;
1745
1746
      // concept requirements
1747
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
1748
      __glibcxx_function_requires(_ConvertibleConcept<_InputValueType,
1749
				  _OutputValueType>)
1750
      __glibcxx_function_requires(_LessThanOpConcept<_InputValueType,
1751
				                     _OutputValueType>)
1752
      __glibcxx_function_requires(_LessThanComparableConcept<_OutputValueType>)
1753
      __glibcxx_requires_valid_range(__first, __last);
1754
      __glibcxx_requires_valid_range(__result_first, __result_last);
1755
1756
      return std::__partial_sort_copy(__first, __last,
1757
				      __result_first, __result_last,
1758
				      __gnu_cxx::__ops::__iter_less_iter());
1759
    }
1760
1761
  /**
1762
   *  @brief Copy the smallest elements of a sequence using a predicate for
1763
   *         comparison.
1764
   *  @ingroup sorting_algorithms
1765
   *  @param  __first   An input iterator.
1766
   *  @param  __last    Another input iterator.
1767
   *  @param  __result_first   A random-access iterator.
1768
   *  @param  __result_last    Another random-access iterator.
1769
   *  @param  __comp    A comparison functor.
1770
   *  @return   An iterator indicating the end of the resulting sequence.
1771
   *
1772
   *  Copies and sorts the smallest N values from the range @p [__first,__last)
1773
   *  to the range beginning at @p result_first, where the number of
1774
   *  elements to be copied, @p N, is the smaller of @p (__last-__first) and
1775
   *  @p (__result_last-__result_first).
1776
   *  After the sort if @e i and @e j are iterators in the range
1777
   *  @p [__result_first,__result_first+N) such that i precedes j then
1778
   *  @p __comp(*j,*i) is false.
1779
   *  The value returned is @p __result_first+N.
1780
  */
1781
  template<typename _InputIterator, typename _RandomAccessIterator,
1782
	   typename _Compare>
1783
    inline _RandomAccessIterator
1784
    partial_sort_copy(_InputIterator __first, _InputIterator __last,
1785
		      _RandomAccessIterator __result_first,
1786
		      _RandomAccessIterator __result_last,
1787
		      _Compare __comp)
1788
    {
1789
      typedef typename iterator_traits<_InputIterator>::value_type
1790
	_InputValueType;
1791
      typedef typename iterator_traits<_RandomAccessIterator>::value_type
1792
	_OutputValueType;
1793
      typedef typename iterator_traits<_RandomAccessIterator>::difference_type
1794
	_DistanceType;
1795
1796
      // concept requirements
1797
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
1798
      __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
1799
				  _RandomAccessIterator>)
1800
      __glibcxx_function_requires(_ConvertibleConcept<_InputValueType,
1801
				  _OutputValueType>)
1802
      __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
1803
				  _InputValueType, _OutputValueType>)
1804
      __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
1805
				  _OutputValueType, _OutputValueType>)
1806
      __glibcxx_requires_valid_range(__first, __last);
1807
      __glibcxx_requires_valid_range(__result_first, __result_last);
1808
1809
      return std::__partial_sort_copy(__first, __last,
1810
				      __result_first, __result_last,
1811
				__gnu_cxx::__ops::__iter_comp_iter(__comp));
1812
    }
1813
1814
  /// This is a helper function for the sort routine.
1815
  template<typename _RandomAccessIterator, typename _Compare>
1816
    void
1817
    __unguarded_linear_insert(_RandomAccessIterator __last,
1818
			      _Compare __comp)
1819
    {
1820
      typename iterator_traits<_RandomAccessIterator>::value_type
1821
	__val = _GLIBCXX_MOVE(*__last);
1822
      _RandomAccessIterator __next = __last;
1823
      --__next;
1824
      while (__comp(__val, __next))
1825
	{
1826
	  *__last = _GLIBCXX_MOVE(*__next);
1827
	  __last = __next;
1828
	  --__next;
1829
	}
1830
      *__last = _GLIBCXX_MOVE(__val);
1831
    }
1832
1833
  /// This is a helper function for the sort routine.
1834
  template<typename _RandomAccessIterator, typename _Compare>
1835
    void
1836
    __insertion_sort(_RandomAccessIterator __first,
1837
		     _RandomAccessIterator __last, _Compare __comp)
1838
    {
1839
      if (__first == __last) return;
1840
1841
      for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
1842
	{
1843
	  if (__comp(__i, __first))
1844
	    {
1845
	      typename iterator_traits<_RandomAccessIterator>::value_type
1846
		__val = _GLIBCXX_MOVE(*__i);
1847
	      _GLIBCXX_MOVE_BACKWARD3(__first, __i, __i + 1);
1848
	      *__first = _GLIBCXX_MOVE(__val);
1849
	    }
1850
	  else
1851
	    std::__unguarded_linear_insert(__i,
1852
				__gnu_cxx::__ops::__val_comp_iter(__comp));
1853
	}
1854
    }
1855
1856
  /// This is a helper function for the sort routine.
1857
  template<typename _RandomAccessIterator, typename _Compare>
1858
    inline void
1859
    __unguarded_insertion_sort(_RandomAccessIterator __first,
1860
			       _RandomAccessIterator __last, _Compare __comp)
1861
    {
1862
      for (_RandomAccessIterator __i = __first; __i != __last; ++__i)
1863
	std::__unguarded_linear_insert(__i,
1864
				__gnu_cxx::__ops::__val_comp_iter(__comp));
1865
    }
1866
1867
  /**
1868
   *  @doctodo
1869
   *  This controls some aspect of the sort routines.
1870
  */
1871
  enum { _S_threshold = 16 };
1872
1873
  /// This is a helper function for the sort routine.
1874
  template<typename _RandomAccessIterator, typename _Compare>
1875
    void
1876
    __final_insertion_sort(_RandomAccessIterator __first,
1877
			   _RandomAccessIterator __last, _Compare __comp)
1878
    {
1879
      if (__last - __first > int(_S_threshold))
1880
	{
1881
	  std::__insertion_sort(__first, __first + int(_S_threshold), __comp);
1882
	  std::__unguarded_insertion_sort(__first + int(_S_threshold), __last,
1883
					  __comp);
1884
	}
1885
      else
1886
	std::__insertion_sort(__first, __last, __comp);
1887
    }
1888
1889
  /// This is a helper function...
1890
  template<typename _RandomAccessIterator, typename _Compare>
1891
    _RandomAccessIterator
1892
    __unguarded_partition(_RandomAccessIterator __first,
1893
			  _RandomAccessIterator __last,
1894
			  _RandomAccessIterator __pivot, _Compare __comp)
1895
    {
1896
      while (true)
1897
	{
1898
	  while (__comp(__first, __pivot))
1899
	    ++__first;
1900
	  --__last;
1901
	  while (__comp(__pivot, __last))
1902
	    --__last;
1903
	  if (!(__first < __last))
1904
	    return __first;
1905
	  std::iter_swap(__first, __last);
1906
	  ++__first;
1907
	}
1908
    }
1909
1910
  /// This is a helper function...
1911
  template<typename _RandomAccessIterator, typename _Compare>
1912
    inline _RandomAccessIterator
1913
    __unguarded_partition_pivot(_RandomAccessIterator __first,
1914
				_RandomAccessIterator __last, _Compare __comp)
1915
    {
1916
      _RandomAccessIterator __mid = __first + (__last - __first) / 2;
1917
      std::__move_median_to_first(__first, __first + 1, __mid, __last - 1,
1918
				  __comp);
1919
      return std::__unguarded_partition(__first + 1, __last, __first, __comp);
1920
    }
1921
1922
  template<typename _RandomAccessIterator, typename _Compare>
1923
    inline void
1924
    __partial_sort(_RandomAccessIterator __first,
1925
		   _RandomAccessIterator __middle,
1926
		   _RandomAccessIterator __last,
1927
		   _Compare __comp)
1928
    {
1929
      std::__heap_select(__first, __middle, __last, __comp);
1930
      std::__sort_heap(__first, __middle, __comp);
1931
    }
1932
1933
  /// This is a helper function for the sort routine.
1934
  template<typename _RandomAccessIterator, typename _Size, typename _Compare>
1935
    void
1936
    __introsort_loop(_RandomAccessIterator __first,
1937
		     _RandomAccessIterator __last,
1938
		     _Size __depth_limit, _Compare __comp)
1939
    {
1940
      while (__last - __first > int(_S_threshold))
1941
	{
1942
	  if (__depth_limit == 0)
1943
	    {
1944
	      std::__partial_sort(__first, __last, __last, __comp);
1945
	      return;
1946
	    }
1947
	  --__depth_limit;
1948
	  _RandomAccessIterator __cut =
1949
	    std::__unguarded_partition_pivot(__first, __last, __comp);
1950
	  std::__introsort_loop(__cut, __last, __depth_limit, __comp);
1951
	  __last = __cut;
1952
	}
1953
    }
1954
1955
  // sort
1956
1957
  template<typename _RandomAccessIterator, typename _Compare>
1958
    inline void
1959
    __sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
1960
	   _Compare __comp)
1961
    {
1962
      if (__first != __last)
1963
	{
1964
	  std::__introsort_loop(__first, __last,
1965
				std::__lg(__last - __first) * 2,
1966
				__comp);
1967
	  std::__final_insertion_sort(__first, __last, __comp);
1968
	}
1969
    }
1970
1971
  template<typename _RandomAccessIterator, typename _Size, typename _Compare>
1972
    void
1973
    __introselect(_RandomAccessIterator __first, _RandomAccessIterator __nth,
1974
		  _RandomAccessIterator __last, _Size __depth_limit,
1975
		  _Compare __comp)
1976
    {
1977
      while (__last - __first > 3)
1978
	{
1979
	  if (__depth_limit == 0)
1980
	    {
1981
	      std::__heap_select(__first, __nth + 1, __last, __comp);
1982
	      // Place the nth largest element in its final position.
1983
	      std::iter_swap(__first, __nth);
1984
	      return;
1985
	    }
1986
	  --__depth_limit;
1987
	  _RandomAccessIterator __cut =
1988
	    std::__unguarded_partition_pivot(__first, __last, __comp);
1989
	  if (__cut <= __nth)
1990
	    __first = __cut;
1991
	  else
1992
	    __last = __cut;
1993
	}
1994
      std::__insertion_sort(__first, __last, __comp);
1995
    }
1996
1997
  // nth_element
1998
1999
  // lower_bound moved to stl_algobase.h
2000
2001
  /**
2002
   *  @brief Finds the first position in which @p __val could be inserted
2003
   *         without changing the ordering.
2004
   *  @ingroup binary_search_algorithms
2005
   *  @param  __first   An iterator.
2006
   *  @param  __last    Another iterator.
2007
   *  @param  __val     The search term.
2008
   *  @param  __comp    A functor to use for comparisons.
2009
   *  @return An iterator pointing to the first element <em>not less
2010
   *           than</em> @p __val, or end() if every element is less
2011
   *           than @p __val.
2012
   *  @ingroup binary_search_algorithms
2013
   *
2014
   *  The comparison function should have the same effects on ordering as
2015
   *  the function used for the initial sort.
2016
  */
2017
  template<typename _ForwardIterator, typename _Tp, typename _Compare>
2018
    inline _ForwardIterator
2019
    lower_bound(_ForwardIterator __first, _ForwardIterator __last,
2020
		const _Tp& __val, _Compare __comp)
2021
    {
2022
      typedef typename iterator_traits<_ForwardIterator>::value_type
2023
	_ValueType;
2024
2025
      // concept requirements
2026
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2027
      __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2028
				  _ValueType, _Tp>)
2029
      __glibcxx_requires_partitioned_lower_pred(__first, __last,
2030
						__val, __comp);
2031
2032
      return std::__lower_bound(__first, __last, __val,
2033
				__gnu_cxx::__ops::__iter_comp_val(__comp));
2034
    }
2035
2036
  template<typename _ForwardIterator, typename _Tp, typename _Compare>
2037
    _ForwardIterator
2038
    __upper_bound(_ForwardIterator __first, _ForwardIterator __last,
2039
		  const _Tp& __val, _Compare __comp)
2040
    {
2041
      typedef typename iterator_traits<_ForwardIterator>::difference_type
2042
	_DistanceType;
2043
2044
      _DistanceType __len = std::distance(__first, __last);
2045
2046
      while (__len > 0)
2047
	{
2048
	  _DistanceType __half = __len >> 1;
2049
	  _ForwardIterator __middle = __first;
2050
	  std::advance(__middle, __half);
2051
	  if (__comp(__val, __middle))
2052
	    __len = __half;
2053
	  else
2054
	    {
2055
	      __first = __middle;
2056
	      ++__first;
2057
	      __len = __len - __half - 1;
2058
	    }
2059
	}
2060
      return __first;
2061
    }
2062
2063
  /**
2064
   *  @brief Finds the last position in which @p __val could be inserted
2065
   *         without changing the ordering.
2066
   *  @ingroup binary_search_algorithms
2067
   *  @param  __first   An iterator.
2068
   *  @param  __last    Another iterator.
2069
   *  @param  __val     The search term.
2070
   *  @return  An iterator pointing to the first element greater than @p __val,
2071
   *           or end() if no elements are greater than @p __val.
2072
   *  @ingroup binary_search_algorithms
2073
  */
2074
  template<typename _ForwardIterator, typename _Tp>
2075
    inline _ForwardIterator
2076
    upper_bound(_ForwardIterator __first, _ForwardIterator __last,
2077
		const _Tp& __val)
2078
    {
2079
      typedef typename iterator_traits<_ForwardIterator>::value_type
2080
	_ValueType;
2081
2082
      // concept requirements
2083
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2084
      __glibcxx_function_requires(_LessThanOpConcept<_Tp, _ValueType>)
2085
      __glibcxx_requires_partitioned_upper(__first, __last, __val);
2086
2087
      return std::__upper_bound(__first, __last, __val,
2088
				__gnu_cxx::__ops::__val_less_iter());
2089
    }
2090
2091
  /**
2092
   *  @brief Finds the last position in which @p __val could be inserted
2093
   *         without changing the ordering.
2094
   *  @ingroup binary_search_algorithms
2095
   *  @param  __first   An iterator.
2096
   *  @param  __last    Another iterator.
2097
   *  @param  __val     The search term.
2098
   *  @param  __comp    A functor to use for comparisons.
2099
   *  @return  An iterator pointing to the first element greater than @p __val,
2100
   *           or end() if no elements are greater than @p __val.
2101
   *  @ingroup binary_search_algorithms
2102
   *
2103
   *  The comparison function should have the same effects on ordering as
2104
   *  the function used for the initial sort.
2105
  */
2106
  template<typename _ForwardIterator, typename _Tp, typename _Compare>
2107
    inline _ForwardIterator
2108
    upper_bound(_ForwardIterator __first, _ForwardIterator __last,
2109
		const _Tp& __val, _Compare __comp)
2110
    {
2111
      typedef typename iterator_traits<_ForwardIterator>::value_type
2112
	_ValueType;
2113
2114
      // concept requirements
2115
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2116
      __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2117
				  _Tp, _ValueType>)
2118
      __glibcxx_requires_partitioned_upper_pred(__first, __last,
2119
						__val, __comp);
2120
2121
      return std::__upper_bound(__first, __last, __val,
2122
				__gnu_cxx::__ops::__val_comp_iter(__comp));
2123
    }
2124
2125
  template<typename _ForwardIterator, typename _Tp,
2126
	   typename _CompareItTp, typename _CompareTpIt>
2127
    pair<_ForwardIterator, _ForwardIterator>
2128
    __equal_range(_ForwardIterator __first, _ForwardIterator __last,
2129
		  const _Tp& __val,
2130
		  _CompareItTp __comp_it_val, _CompareTpIt __comp_val_it)
2131
    {
2132
      typedef typename iterator_traits<_ForwardIterator>::difference_type
2133
	_DistanceType;
2134
2135
      _DistanceType __len = std::distance(__first, __last);
2136
2137
      while (__len > 0)
2138
	{
2139
	  _DistanceType __half = __len >> 1;
2140
	  _ForwardIterator __middle = __first;
2141
	  std::advance(__middle, __half);
2142
	  if (__comp_it_val(__middle, __val))
2143
	    {
2144
	      __first = __middle;
2145
	      ++__first;
2146
	      __len = __len - __half - 1;
2147
	    }
2148
	  else if (__comp_val_it(__val, __middle))
2149
	    __len = __half;
2150
	  else
2151
	    {
2152
	      _ForwardIterator __left
2153
		= std::__lower_bound(__first, __middle, __val, __comp_it_val);
2154
	      std::advance(__first, __len);
2155
	      _ForwardIterator __right
2156
		= std::__upper_bound(++__middle, __first, __val, __comp_val_it);
2157
	      return pair<_ForwardIterator, _ForwardIterator>(__left, __right);
2158
	    }
2159
	}
2160
      return pair<_ForwardIterator, _ForwardIterator>(__first, __first);
2161
    }
2162
2163
  /**
2164
   *  @brief Finds the largest subrange in which @p __val could be inserted
2165
   *         at any place in it without changing the ordering.
2166
   *  @ingroup binary_search_algorithms
2167
   *  @param  __first   An iterator.
2168
   *  @param  __last    Another iterator.
2169
   *  @param  __val     The search term.
2170
   *  @return  An pair of iterators defining the subrange.
2171
   *  @ingroup binary_search_algorithms
2172
   *
2173
   *  This is equivalent to
2174
   *  @code
2175
   *    std::make_pair(lower_bound(__first, __last, __val),
2176
   *                   upper_bound(__first, __last, __val))
2177
   *  @endcode
2178
   *  but does not actually call those functions.
2179
  */
2180
  template<typename _ForwardIterator, typename _Tp>
2181
    inline pair<_ForwardIterator, _ForwardIterator>
2182
    equal_range(_ForwardIterator __first, _ForwardIterator __last,
2183
		const _Tp& __val)
2184
    {
2185
      typedef typename iterator_traits<_ForwardIterator>::value_type
2186
	_ValueType;
2187
2188
      // concept requirements
2189
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2190
      __glibcxx_function_requires(_LessThanOpConcept<_ValueType, _Tp>)
2191
      __glibcxx_function_requires(_LessThanOpConcept<_Tp, _ValueType>)
2192
      __glibcxx_requires_partitioned_lower(__first, __last, __val);
2193
      __glibcxx_requires_partitioned_upper(__first, __last, __val);      
2194
2195
      return std::__equal_range(__first, __last, __val,
2196
				__gnu_cxx::__ops::__iter_less_val(),
2197
				__gnu_cxx::__ops::__val_less_iter());
2198
    }
2199
2200
  /**
2201
   *  @brief Finds the largest subrange in which @p __val could be inserted
2202
   *         at any place in it without changing the ordering.
2203
   *  @param  __first   An iterator.
2204
   *  @param  __last    Another iterator.
2205
   *  @param  __val     The search term.
2206
   *  @param  __comp    A functor to use for comparisons.
2207
   *  @return  An pair of iterators defining the subrange.
2208
   *  @ingroup binary_search_algorithms
2209
   *
2210
   *  This is equivalent to
2211
   *  @code
2212
   *    std::make_pair(lower_bound(__first, __last, __val, __comp),
2213
   *                   upper_bound(__first, __last, __val, __comp))
2214
   *  @endcode
2215
   *  but does not actually call those functions.
2216
  */
2217
  template<typename _ForwardIterator, typename _Tp, typename _Compare>
2218
    inline pair<_ForwardIterator, _ForwardIterator>
2219
    equal_range(_ForwardIterator __first, _ForwardIterator __last,
2220
		const _Tp& __val, _Compare __comp)
2221
    {
2222
      typedef typename iterator_traits<_ForwardIterator>::value_type
2223
	_ValueType;
2224
2225
      // concept requirements
2226
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2227
      __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2228
				  _ValueType, _Tp>)
2229
      __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2230
				  _Tp, _ValueType>)
2231
      __glibcxx_requires_partitioned_lower_pred(__first, __last,
2232
						__val, __comp);
2233
      __glibcxx_requires_partitioned_upper_pred(__first, __last,
2234
						__val, __comp);
2235
2236
      return std::__equal_range(__first, __last, __val,
2237
				__gnu_cxx::__ops::__iter_comp_val(__comp),
2238
				__gnu_cxx::__ops::__val_comp_iter(__comp));
2239
    }
2240
2241
  /**
2242
   *  @brief Determines whether an element exists in a range.
2243
   *  @ingroup binary_search_algorithms
2244
   *  @param  __first   An iterator.
2245
   *  @param  __last    Another iterator.
2246
   *  @param  __val     The search term.
2247
   *  @return True if @p __val (or its equivalent) is in [@p
2248
   *  __first,@p __last ].
2249
   *
2250
   *  Note that this does not actually return an iterator to @p __val.  For
2251
   *  that, use std::find or a container's specialized find member functions.
2252
  */
2253
  template<typename _ForwardIterator, typename _Tp>
2254
    bool
2255
    binary_search(_ForwardIterator __first, _ForwardIterator __last,
2256
                  const _Tp& __val)
2257
    {
2258
      typedef typename iterator_traits<_ForwardIterator>::value_type
2259
	_ValueType;
2260
2261
      // concept requirements
2262
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2263
      __glibcxx_function_requires(_LessThanOpConcept<_Tp, _ValueType>)
2264
      __glibcxx_requires_partitioned_lower(__first, __last, __val);
2265
      __glibcxx_requires_partitioned_upper(__first, __last, __val);
2266
2267
      _ForwardIterator __i
2268
	= std::__lower_bound(__first, __last, __val,
2269
			     __gnu_cxx::__ops::__iter_less_val());
2270
      return __i != __last && !(__val < *__i);
2271
    }
2272
2273
  /**
2274
   *  @brief Determines whether an element exists in a range.
2275
   *  @ingroup binary_search_algorithms
2276
   *  @param  __first   An iterator.
2277
   *  @param  __last    Another iterator.
2278
   *  @param  __val     The search term.
2279
   *  @param  __comp    A functor to use for comparisons.
2280
   *  @return  True if @p __val (or its equivalent) is in @p [__first,__last].
2281
   *
2282
   *  Note that this does not actually return an iterator to @p __val.  For
2283
   *  that, use std::find or a container's specialized find member functions.
2284
   *
2285
   *  The comparison function should have the same effects on ordering as
2286
   *  the function used for the initial sort.
2287
  */
2288
  template<typename _ForwardIterator, typename _Tp, typename _Compare>
2289
    bool
2290
    binary_search(_ForwardIterator __first, _ForwardIterator __last,
2291
                  const _Tp& __val, _Compare __comp)
2292
    {
2293
      typedef typename iterator_traits<_ForwardIterator>::value_type
2294
	_ValueType;
2295
2296
      // concept requirements
2297
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2298
      __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2299
				  _Tp, _ValueType>)
2300
      __glibcxx_requires_partitioned_lower_pred(__first, __last,
2301
						__val, __comp);
2302
      __glibcxx_requires_partitioned_upper_pred(__first, __last,
2303
						__val, __comp);
2304
2305
      _ForwardIterator __i
2306
	= std::__lower_bound(__first, __last, __val,
2307
			     __gnu_cxx::__ops::__iter_comp_val(__comp));
2308
      return __i != __last && !bool(__comp(__val, *__i));
2309
    }
2310
2311
  // merge
2312
2313
  /// This is a helper function for the __merge_adaptive routines.
2314
  template<typename _InputIterator1, typename _InputIterator2,
2315
	   typename _OutputIterator, typename _Compare>
2316
    void
2317
    __move_merge_adaptive(_InputIterator1 __first1, _InputIterator1 __last1,
2318
			  _InputIterator2 __first2, _InputIterator2 __last2,
2319
			  _OutputIterator __result, _Compare __comp)
2320
    {
2321
      while (__first1 != __last1 && __first2 != __last2)
2322
	{
2323
	  if (__comp(__first2, __first1))
2324
	    {
2325
	      *__result = _GLIBCXX_MOVE(*__first2);
2326
	      ++__first2;
2327
	    }
2328
	  else
2329
	    {
2330
	      *__result = _GLIBCXX_MOVE(*__first1);
2331
	      ++__first1;
2332
	    }
2333
	  ++__result;
2334
	}
2335
      if (__first1 != __last1)
2336
	_GLIBCXX_MOVE3(__first1, __last1, __result);
2337
    }
2338
2339
  /// This is a helper function for the __merge_adaptive routines.
2340
  template<typename _BidirectionalIterator1, typename _BidirectionalIterator2,
2341
	   typename _BidirectionalIterator3, typename _Compare>
2342
    void
2343
    __move_merge_adaptive_backward(_BidirectionalIterator1 __first1,
2344
				   _BidirectionalIterator1 __last1,
2345
				   _BidirectionalIterator2 __first2,
2346
				   _BidirectionalIterator2 __last2,
2347
				   _BidirectionalIterator3 __result,
2348
				   _Compare __comp)
2349
    {
2350
      if (__first1 == __last1)
2351
	{
2352
	  _GLIBCXX_MOVE_BACKWARD3(__first2, __last2, __result);
2353
	  return;
2354
	}
2355
      else if (__first2 == __last2)
2356
	return;
2357
2358
      --__last1;
2359
      --__last2;
2360
      while (true)
2361
	{
2362
	  if (__comp(__last2, __last1))
2363
	    {
2364
	      *--__result = _GLIBCXX_MOVE(*__last1);
2365
	      if (__first1 == __last1)
2366
		{
2367
		  _GLIBCXX_MOVE_BACKWARD3(__first2, ++__last2, __result);
2368
		  return;
2369
		}
2370
	      --__last1;
2371
	    }
2372
	  else
2373
	    {
2374
	      *--__result = _GLIBCXX_MOVE(*__last2);
2375
	      if (__first2 == __last2)
2376
		return;
2377
	      --__last2;
2378
	    }
2379
	}
2380
    }
2381
2382
  /// This is a helper function for the merge routines.
2383
  template<typename _BidirectionalIterator1, typename _BidirectionalIterator2,
2384
	   typename _Distance>
2385
    _BidirectionalIterator1
2386
    __rotate_adaptive(_BidirectionalIterator1 __first,
2387
		      _BidirectionalIterator1 __middle,
2388
		      _BidirectionalIterator1 __last,
2389
		      _Distance __len1, _Distance __len2,
2390
		      _BidirectionalIterator2 __buffer,
2391
		      _Distance __buffer_size)
2392
    {
2393
      _BidirectionalIterator2 __buffer_end;
2394
      if (__len1 > __len2 && __len2 <= __buffer_size)
2395
	{
2396
	  if (__len2)
2397
	    {
2398
	      __buffer_end = _GLIBCXX_MOVE3(__middle, __last, __buffer);
2399
	      _GLIBCXX_MOVE_BACKWARD3(__first, __middle, __last);
2400
	      return _GLIBCXX_MOVE3(__buffer, __buffer_end, __first);
2401
	    }
2402
	  else
2403
	    return __first;
2404
	}
2405
      else if (__len1 <= __buffer_size)
2406
	{
2407
	  if (__len1)
2408
	    {
2409
	      __buffer_end = _GLIBCXX_MOVE3(__first, __middle, __buffer);
2410
	      _GLIBCXX_MOVE3(__middle, __last, __first);
2411
	      return _GLIBCXX_MOVE_BACKWARD3(__buffer, __buffer_end, __last);
2412
	    }
2413
	  else
2414
	    return __last;
2415
	}
2416
      else
2417
	{
2418
	  std::rotate(__first, __middle, __last);
2419
	  std::advance(__first, std::distance(__middle, __last));
2420
	  return __first;
2421
	}
2422
    }
2423
2424
  /// This is a helper function for the merge routines.
2425
  template<typename _BidirectionalIterator, typename _Distance, 
2426
	   typename _Pointer, typename _Compare>
2427
    void
2428
    __merge_adaptive(_BidirectionalIterator __first,
2429
                     _BidirectionalIterator __middle,
2430
		     _BidirectionalIterator __last,
2431
		     _Distance __len1, _Distance __len2,
2432
		     _Pointer __buffer, _Distance __buffer_size,
2433
		     _Compare __comp)
2434
    {
2435
      if (__len1 <= __len2 && __len1 <= __buffer_size)
2436
	{
2437
	  _Pointer __buffer_end = _GLIBCXX_MOVE3(__first, __middle, __buffer);
2438
	  std::__move_merge_adaptive(__buffer, __buffer_end, __middle, __last,
2439
				     __first, __comp);
2440
	}
2441
      else if (__len2 <= __buffer_size)
2442
	{
2443
	  _Pointer __buffer_end = _GLIBCXX_MOVE3(__middle, __last, __buffer);
2444
	  std::__move_merge_adaptive_backward(__first, __middle, __buffer,
2445
					      __buffer_end, __last, __comp);
2446
	}
2447
      else
2448
	{
2449
	  _BidirectionalIterator __first_cut = __first;
2450
	  _BidirectionalIterator __second_cut = __middle;
2451
	  _Distance __len11 = 0;
2452
	  _Distance __len22 = 0;
2453
	  if (__len1 > __len2)
2454
	    {
2455
	      __len11 = __len1 / 2;
2456
	      std::advance(__first_cut, __len11);
2457
	      __second_cut
2458
		= std::__lower_bound(__middle, __last, *__first_cut,
2459
				     __gnu_cxx::__ops::__iter_comp_val(__comp));
2460
	      __len22 = std::distance(__middle, __second_cut);
2461
	    }
2462
	  else
2463
	    {
2464
	      __len22 = __len2 / 2;
2465
	      std::advance(__second_cut, __len22);
2466
	      __first_cut
2467
		= std::__upper_bound(__first, __middle, *__second_cut,
2468
				     __gnu_cxx::__ops::__val_comp_iter(__comp));
2469
	      __len11 = std::distance(__first, __first_cut);
2470
	    }
2471
	  _BidirectionalIterator __new_middle
2472
	    = std::__rotate_adaptive(__first_cut, __middle, __second_cut,
2473
				     __len1 - __len11, __len22, __buffer,
2474
				     __buffer_size);
2475
	  std::__merge_adaptive(__first, __first_cut, __new_middle, __len11,
2476
				__len22, __buffer, __buffer_size, __comp);
2477
	  std::__merge_adaptive(__new_middle, __second_cut, __last,
2478
				__len1 - __len11,
2479
				__len2 - __len22, __buffer,
2480
				__buffer_size, __comp);
2481
	}
2482
    }
2483
2484
  /// This is a helper function for the merge routines.
2485
  template<typename _BidirectionalIterator, typename _Distance,
2486
	   typename _Compare>
2487
    void
2488
    __merge_without_buffer(_BidirectionalIterator __first,
2489
                           _BidirectionalIterator __middle,
2490
			   _BidirectionalIterator __last,
2491
			   _Distance __len1, _Distance __len2,
2492
			   _Compare __comp)
2493
    {
2494
      if (__len1 == 0 || __len2 == 0)
2495
	return;
2496
      if (__len1 + __len2 == 2)
2497
	{
2498
	  if (__comp(__middle, __first))
2499
	    std::iter_swap(__first, __middle);
2500
	  return;
2501
	}
2502
      _BidirectionalIterator __first_cut = __first;
2503
      _BidirectionalIterator __second_cut = __middle;
2504
      _Distance __len11 = 0;
2505
      _Distance __len22 = 0;
2506
      if (__len1 > __len2)
2507
	{
2508
	  __len11 = __len1 / 2;
2509
	  std::advance(__first_cut, __len11);
2510
	  __second_cut
2511
	    = std::__lower_bound(__middle, __last, *__first_cut,
2512
				 __gnu_cxx::__ops::__iter_comp_val(__comp));
2513
	  __len22 = std::distance(__middle, __second_cut);
2514
	}
2515
      else
2516
	{
2517
	  __len22 = __len2 / 2;
2518
	  std::advance(__second_cut, __len22);
2519
	  __first_cut
2520
	    = std::__upper_bound(__first, __middle, *__second_cut,
2521
				 __gnu_cxx::__ops::__val_comp_iter(__comp));
2522
	  __len11 = std::distance(__first, __first_cut);
2523
	}
2524
      std::rotate(__first_cut, __middle, __second_cut);
2525
      _BidirectionalIterator __new_middle = __first_cut;
2526
      std::advance(__new_middle, std::distance(__middle, __second_cut));
2527
      std::__merge_without_buffer(__first, __first_cut, __new_middle,
2528
				  __len11, __len22, __comp);
2529
      std::__merge_without_buffer(__new_middle, __second_cut, __last,
2530
				  __len1 - __len11, __len2 - __len22, __comp);
2531
    }
2532
2533
  template<typename _BidirectionalIterator, typename _Compare>
2534
    void
2535
    __inplace_merge(_BidirectionalIterator __first,
2536
		    _BidirectionalIterator __middle,
2537
		    _BidirectionalIterator __last,
2538
		    _Compare __comp)
2539
    {
2540
      typedef typename iterator_traits<_BidirectionalIterator>::value_type
2541
          _ValueType;
2542
      typedef typename iterator_traits<_BidirectionalIterator>::difference_type
2543
          _DistanceType;
2544
2545
      if (__first == __middle || __middle == __last)
2546
	return;
2547
2548
      const _DistanceType __len1 = std::distance(__first, __middle);
2549
      const _DistanceType __len2 = std::distance(__middle, __last);
2550
2551
      typedef _Temporary_buffer<_BidirectionalIterator, _ValueType> _TmpBuf;
2552
      _TmpBuf __buf(__first, __last);
2553
2554
      if (__buf.begin() == 0)
2555
	std::__merge_without_buffer
2556
	  (__first, __middle, __last, __len1, __len2, __comp);
2557
      else
2558
	std::__merge_adaptive
2559
	  (__first, __middle, __last, __len1, __len2, __buf.begin(),
2560
	   _DistanceType(__buf.size()), __comp);
2561
    }
2562
2563
  /**
2564
   *  @brief Merges two sorted ranges in place.
2565
   *  @ingroup sorting_algorithms
2566
   *  @param  __first   An iterator.
2567
   *  @param  __middle  Another iterator.
2568
   *  @param  __last    Another iterator.
2569
   *  @return  Nothing.
2570
   *
2571
   *  Merges two sorted and consecutive ranges, [__first,__middle) and
2572
   *  [__middle,__last), and puts the result in [__first,__last).  The
2573
   *  output will be sorted.  The sort is @e stable, that is, for
2574
   *  equivalent elements in the two ranges, elements from the first
2575
   *  range will always come before elements from the second.
2576
   *
2577
   *  If enough additional memory is available, this takes (__last-__first)-1
2578
   *  comparisons.  Otherwise an NlogN algorithm is used, where N is
2579
   *  distance(__first,__last).
2580
  */
2581
  template<typename _BidirectionalIterator>
2582
    inline void
2583
    inplace_merge(_BidirectionalIterator __first,
2584
		  _BidirectionalIterator __middle,
2585
		  _BidirectionalIterator __last)
2586
    {
2587
      // concept requirements
2588
      __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<
2589
	    _BidirectionalIterator>)
2590
      __glibcxx_function_requires(_LessThanComparableConcept<
2591
	    typename iterator_traits<_BidirectionalIterator>::value_type>)
2592
      __glibcxx_requires_sorted(__first, __middle);
2593
      __glibcxx_requires_sorted(__middle, __last);
2594
2595
      std::__inplace_merge(__first, __middle, __last,
2596
			   __gnu_cxx::__ops::__iter_less_iter());
2597
    }
2598
2599
  /**
2600
   *  @brief Merges two sorted ranges in place.
2601
   *  @ingroup sorting_algorithms
2602
   *  @param  __first   An iterator.
2603
   *  @param  __middle  Another iterator.
2604
   *  @param  __last    Another iterator.
2605
   *  @param  __comp    A functor to use for comparisons.
2606
   *  @return  Nothing.
2607
   *
2608
   *  Merges two sorted and consecutive ranges, [__first,__middle) and
2609
   *  [middle,last), and puts the result in [__first,__last).  The output will
2610
   *  be sorted.  The sort is @e stable, that is, for equivalent
2611
   *  elements in the two ranges, elements from the first range will always
2612
   *  come before elements from the second.
2613
   *
2614
   *  If enough additional memory is available, this takes (__last-__first)-1
2615
   *  comparisons.  Otherwise an NlogN algorithm is used, where N is
2616
   *  distance(__first,__last).
2617
   *
2618
   *  The comparison function should have the same effects on ordering as
2619
   *  the function used for the initial sort.
2620
  */
2621
  template<typename _BidirectionalIterator, typename _Compare>
2622
    inline void
2623
    inplace_merge(_BidirectionalIterator __first,
2624
		  _BidirectionalIterator __middle,
2625
		  _BidirectionalIterator __last,
2626
		  _Compare __comp)
2627
    {
2628
      // concept requirements
2629
      __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<
2630
	    _BidirectionalIterator>)
2631
      __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2632
	    typename iterator_traits<_BidirectionalIterator>::value_type,
2633
	    typename iterator_traits<_BidirectionalIterator>::value_type>)
2634
      __glibcxx_requires_sorted_pred(__first, __middle, __comp);
2635
      __glibcxx_requires_sorted_pred(__middle, __last, __comp);
2636
2637
      std::__inplace_merge(__first, __middle, __last,
2638
			   __gnu_cxx::__ops::__iter_comp_iter(__comp));
2639
    }
2640
2641
2642
  /// This is a helper function for the __merge_sort_loop routines.
2643
  template<typename _InputIterator, typename _OutputIterator,
2644
	   typename _Compare>
2645
    _OutputIterator
2646
    __move_merge(_InputIterator __first1, _InputIterator __last1,
2647
		 _InputIterator __first2, _InputIterator __last2,
2648
		 _OutputIterator __result, _Compare __comp)
2649
    {
2650
      while (__first1 != __last1 && __first2 != __last2)
2651
	{
2652
	  if (__comp(__first2, __first1))
2653
	    {
2654
	      *__result = _GLIBCXX_MOVE(*__first2);
2655
	      ++__first2;
2656
	    }
2657
	  else
2658
	    {
2659
	      *__result = _GLIBCXX_MOVE(*__first1);
2660
	      ++__first1;
2661
	    }
2662
	  ++__result;
2663
	}
2664
      return _GLIBCXX_MOVE3(__first2, __last2,
2665
			    _GLIBCXX_MOVE3(__first1, __last1,
2666
					   __result));
2667
    }
2668
2669
  template<typename _RandomAccessIterator1, typename _RandomAccessIterator2,
2670
	   typename _Distance, typename _Compare>
2671
    void
2672
    __merge_sort_loop(_RandomAccessIterator1 __first,
2673
		      _RandomAccessIterator1 __last,
2674
		      _RandomAccessIterator2 __result, _Distance __step_size,
2675
		      _Compare __comp)
2676
    {
2677
      const _Distance __two_step = 2 * __step_size;
2678
2679
      while (__last - __first >= __two_step)
2680
	{
2681
	  __result = std::__move_merge(__first, __first + __step_size,
2682
				       __first + __step_size,
2683
				       __first + __two_step,
2684
				       __result, __comp);
2685
	  __first += __two_step;
2686
	}
2687
      __step_size = std::min(_Distance(__last - __first), __step_size);
2688
2689
      std::__move_merge(__first, __first + __step_size,
2690
			__first + __step_size, __last, __result, __comp);
2691
    }
2692
2693
  template<typename _RandomAccessIterator, typename _Distance,
2694
	   typename _Compare>
2695
    void
2696
    __chunk_insertion_sort(_RandomAccessIterator __first,
2697
			   _RandomAccessIterator __last,
2698
			   _Distance __chunk_size, _Compare __comp)
2699
    {
2700
      while (__last - __first >= __chunk_size)
2701
	{
2702
	  std::__insertion_sort(__first, __first + __chunk_size, __comp);
2703
	  __first += __chunk_size;
2704
	}
2705
      std::__insertion_sort(__first, __last, __comp);
2706
    }
2707
2708
  enum { _S_chunk_size = 7 };
2709
2710
  template<typename _RandomAccessIterator, typename _Pointer, typename _Compare>
2711
    void
2712
    __merge_sort_with_buffer(_RandomAccessIterator __first,
2713
			     _RandomAccessIterator __last,
2714
                             _Pointer __buffer, _Compare __comp)
2715
    {
2716
      typedef typename iterator_traits<_RandomAccessIterator>::difference_type
2717
	_Distance;
2718
2719
      const _Distance __len = __last - __first;
2720
      const _Pointer __buffer_last = __buffer + __len;
2721
2722
      _Distance __step_size = _S_chunk_size;
2723
      std::__chunk_insertion_sort(__first, __last, __step_size, __comp);
2724
2725
      while (__step_size < __len)
2726
	{
2727
	  std::__merge_sort_loop(__first, __last, __buffer,
2728
				 __step_size, __comp);
2729
	  __step_size *= 2;
2730
	  std::__merge_sort_loop(__buffer, __buffer_last, __first,
2731
				 __step_size, __comp);
2732
	  __step_size *= 2;
2733
	}
2734
    }
2735
2736
  template<typename _RandomAccessIterator, typename _Pointer,
2737
	   typename _Distance, typename _Compare>
2738
    void
2739
    __stable_sort_adaptive(_RandomAccessIterator __first,
2740
			   _RandomAccessIterator __last,
2741
                           _Pointer __buffer, _Distance __buffer_size,
2742
                           _Compare __comp)
2743
    {
2744
      const _Distance __len = (__last - __first + 1) / 2;
2745
      const _RandomAccessIterator __middle = __first + __len;
2746
      if (__len > __buffer_size)
2747
	{
2748
	  std::__stable_sort_adaptive(__first, __middle, __buffer,
2749
				      __buffer_size, __comp);
2750
	  std::__stable_sort_adaptive(__middle, __last, __buffer,
2751
				      __buffer_size, __comp);
2752
	}
2753
      else
2754
	{
2755
	  std::__merge_sort_with_buffer(__first, __middle, __buffer, __comp);
2756
	  std::__merge_sort_with_buffer(__middle, __last, __buffer, __comp);
2757
	}
2758
      std::__merge_adaptive(__first, __middle, __last,
2759
			    _Distance(__middle - __first),
2760
			    _Distance(__last - __middle),
2761
			    __buffer, __buffer_size,
2762
			    __comp);
2763
    }
2764
2765
  /// This is a helper function for the stable sorting routines.
2766
  template<typename _RandomAccessIterator, typename _Compare>
2767
    void
2768
    __inplace_stable_sort(_RandomAccessIterator __first,
2769
			  _RandomAccessIterator __last, _Compare __comp)
2770
    {
2771
      if (__last - __first < 15)
2772
	{
2773
	  std::__insertion_sort(__first, __last, __comp);
2774
	  return;
2775
	}
2776
      _RandomAccessIterator __middle = __first + (__last - __first) / 2;
2777
      std::__inplace_stable_sort(__first, __middle, __comp);
2778
      std::__inplace_stable_sort(__middle, __last, __comp);
2779
      std::__merge_without_buffer(__first, __middle, __last,
2780
				  __middle - __first,
2781
				  __last - __middle,
2782
				  __comp);
2783
    }
2784
2785
  // stable_sort
2786
2787
  // Set algorithms: includes, set_union, set_intersection, set_difference,
2788
  // set_symmetric_difference.  All of these algorithms have the precondition
2789
  // that their input ranges are sorted and the postcondition that their output
2790
  // ranges are sorted.
2791
2792
  template<typename _InputIterator1, typename _InputIterator2,
2793
	   typename _Compare>
2794
    bool
2795
    __includes(_InputIterator1 __first1, _InputIterator1 __last1,
2796
	       _InputIterator2 __first2, _InputIterator2 __last2,
2797
	       _Compare __comp)
2798
    {
2799
      while (__first1 != __last1 && __first2 != __last2)
2800
	if (__comp(__first2, __first1))
2801
	  return false;
2802
	else if (__comp(__first1, __first2))
2803
	  ++__first1;
2804
	else
2805
	  ++__first1, ++__first2;
2806
2807
      return __first2 == __last2;
2808
    }
2809
2810
  /**
2811
   *  @brief Determines whether all elements of a sequence exists in a range.
2812
   *  @param  __first1  Start of search range.
2813
   *  @param  __last1   End of search range.
2814
   *  @param  __first2  Start of sequence
2815
   *  @param  __last2   End of sequence.
2816
   *  @return  True if each element in [__first2,__last2) is contained in order
2817
   *  within [__first1,__last1).  False otherwise.
2818
   *  @ingroup set_algorithms
2819
   *
2820
   *  This operation expects both [__first1,__last1) and
2821
   *  [__first2,__last2) to be sorted.  Searches for the presence of
2822
   *  each element in [__first2,__last2) within [__first1,__last1).
2823
   *  The iterators over each range only move forward, so this is a
2824
   *  linear algorithm.  If an element in [__first2,__last2) is not
2825
   *  found before the search iterator reaches @p __last2, false is
2826
   *  returned.
2827
  */
2828
  template<typename _InputIterator1, typename _InputIterator2>
2829
    inline bool
2830
    includes(_InputIterator1 __first1, _InputIterator1 __last1,
2831
	     _InputIterator2 __first2, _InputIterator2 __last2)
2832
    {
2833
      // concept requirements
2834
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
2835
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
2836
      __glibcxx_function_requires(_LessThanOpConcept<
2837
	    typename iterator_traits<_InputIterator1>::value_type,
2838
	    typename iterator_traits<_InputIterator2>::value_type>)
2839
      __glibcxx_function_requires(_LessThanOpConcept<
2840
	    typename iterator_traits<_InputIterator2>::value_type,
2841
	    typename iterator_traits<_InputIterator1>::value_type>)
2842
      __glibcxx_requires_sorted_set(__first1, __last1, __first2);
2843
      __glibcxx_requires_sorted_set(__first2, __last2, __first1);
2844
2845
      return std::__includes(__first1, __last1, __first2, __last2,
2846
			     __gnu_cxx::__ops::__iter_less_iter());
2847
    }
2848
2849
  /**
2850
   *  @brief Determines whether all elements of a sequence exists in a range
2851
   *  using comparison.
2852
   *  @ingroup set_algorithms
2853
   *  @param  __first1  Start of search range.
2854
   *  @param  __last1   End of search range.
2855
   *  @param  __first2  Start of sequence
2856
   *  @param  __last2   End of sequence.
2857
   *  @param  __comp    Comparison function to use.
2858
   *  @return True if each element in [__first2,__last2) is contained
2859
   *  in order within [__first1,__last1) according to comp.  False
2860
   *  otherwise.  @ingroup set_algorithms
2861
   *
2862
   *  This operation expects both [__first1,__last1) and
2863
   *  [__first2,__last2) to be sorted.  Searches for the presence of
2864
   *  each element in [__first2,__last2) within [__first1,__last1),
2865
   *  using comp to decide.  The iterators over each range only move
2866
   *  forward, so this is a linear algorithm.  If an element in
2867
   *  [__first2,__last2) is not found before the search iterator
2868
   *  reaches @p __last2, false is returned.
2869
  */
2870
  template<typename _InputIterator1, typename _InputIterator2,
2871
	   typename _Compare>
2872
    inline bool
2873
    includes(_InputIterator1 __first1, _InputIterator1 __last1,
2874
	     _InputIterator2 __first2, _InputIterator2 __last2,
2875
	     _Compare __comp)
2876
    {
2877
      // concept requirements
2878
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
2879
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
2880
      __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2881
	    typename iterator_traits<_InputIterator1>::value_type,
2882
	    typename iterator_traits<_InputIterator2>::value_type>)
2883
      __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2884
	    typename iterator_traits<_InputIterator2>::value_type,
2885
	    typename iterator_traits<_InputIterator1>::value_type>)
2886
      __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
2887
      __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
2888
2889
      return std::__includes(__first1, __last1, __first2, __last2,
2890
			     __gnu_cxx::__ops::__iter_comp_iter(__comp));
2891
    }
2892
2893
  // nth_element
2894
  // merge
2895
  // set_difference
2896
  // set_intersection
2897
  // set_union
2898
  // stable_sort
2899
  // set_symmetric_difference
2900
  // min_element
2901
  // max_element
2902
2903
  template<typename _BidirectionalIterator, typename _Compare>
2904
    bool
2905
    __next_permutation(_BidirectionalIterator __first,
2906
		       _BidirectionalIterator __last, _Compare __comp)
2907
    {
2908
      if (__first == __last)
2909
	return false;
2910
      _BidirectionalIterator __i = __first;
2911
      ++__i;
2912
      if (__i == __last)
2913
	return false;
2914
      __i = __last;
2915
      --__i;
2916
2917
      for(;;)
2918
	{
2919
	  _BidirectionalIterator __ii = __i;
2920
	  --__i;
2921
	  if (__comp(__i, __ii))
2922
	    {
2923
	      _BidirectionalIterator __j = __last;
2924
	      while (!__comp(__i, --__j))
2925
		{}
2926
	      std::iter_swap(__i, __j);
2927
	      std::__reverse(__ii, __last,
2928
			     std::__iterator_category(__first));
2929
	      return true;
2930
	    }
2931
	  if (__i == __first)
2932
	    {
2933
	      std::__reverse(__first, __last,
2934
			     std::__iterator_category(__first));
2935
	      return false;
2936
	    }
2937
	}
2938
    }
2939
2940
  /**
2941
   *  @brief  Permute range into the next @e dictionary ordering.
2942
   *  @ingroup sorting_algorithms
2943
   *  @param  __first  Start of range.
2944
   *  @param  __last   End of range.
2945
   *  @return  False if wrapped to first permutation, true otherwise.
2946
   *
2947
   *  Treats all permutations of the range as a set of @e dictionary sorted
2948
   *  sequences.  Permutes the current sequence into the next one of this set.
2949
   *  Returns true if there are more sequences to generate.  If the sequence
2950
   *  is the largest of the set, the smallest is generated and false returned.
2951
  */
2952
  template<typename _BidirectionalIterator>
2953
    inline bool
2954
    next_permutation(_BidirectionalIterator __first,
2955
		     _BidirectionalIterator __last)
2956
    {
2957
      // concept requirements
2958
      __glibcxx_function_requires(_BidirectionalIteratorConcept<
2959
				  _BidirectionalIterator>)
2960
      __glibcxx_function_requires(_LessThanComparableConcept<
2961
	    typename iterator_traits<_BidirectionalIterator>::value_type>)
2962
      __glibcxx_requires_valid_range(__first, __last);
2963
2964
      return std::__next_permutation
2965
	(__first, __last, __gnu_cxx::__ops::__iter_less_iter());
2966
    }
2967
2968
  /**
2969
   *  @brief  Permute range into the next @e dictionary ordering using
2970
   *          comparison functor.
2971
   *  @ingroup sorting_algorithms
2972
   *  @param  __first  Start of range.
2973
   *  @param  __last   End of range.
2974
   *  @param  __comp   A comparison functor.
2975
   *  @return  False if wrapped to first permutation, true otherwise.
2976
   *
2977
   *  Treats all permutations of the range [__first,__last) as a set of
2978
   *  @e dictionary sorted sequences ordered by @p __comp.  Permutes the current
2979
   *  sequence into the next one of this set.  Returns true if there are more
2980
   *  sequences to generate.  If the sequence is the largest of the set, the
2981
   *  smallest is generated and false returned.
2982
  */
2983
  template<typename _BidirectionalIterator, typename _Compare>
2984
    inline bool
2985
    next_permutation(_BidirectionalIterator __first,
2986
		     _BidirectionalIterator __last, _Compare __comp)
2987
    {
2988
      // concept requirements
2989
      __glibcxx_function_requires(_BidirectionalIteratorConcept<
2990
				  _BidirectionalIterator>)
2991
      __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
2992
	    typename iterator_traits<_BidirectionalIterator>::value_type,
2993
	    typename iterator_traits<_BidirectionalIterator>::value_type>)
2994
      __glibcxx_requires_valid_range(__first, __last);
2995
2996
      return std::__next_permutation
2997
	(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
2998
    }
2999
3000
  template<typename _BidirectionalIterator, typename _Compare>
3001
    bool
3002
    __prev_permutation(_BidirectionalIterator __first,
3003
		       _BidirectionalIterator __last, _Compare __comp)
3004
    {
3005
      if (__first == __last)
3006
	return false;
3007
      _BidirectionalIterator __i = __first;
3008
      ++__i;
3009
      if (__i == __last)
3010
	return false;
3011
      __i = __last;
3012
      --__i;
3013
3014
      for(;;)
3015
	{
3016
	  _BidirectionalIterator __ii = __i;
3017
	  --__i;
3018
	  if (__comp(__ii, __i))
3019
	    {
3020
	      _BidirectionalIterator __j = __last;
3021
	      while (!__comp(--__j, __i))
3022
		{}
3023
	      std::iter_swap(__i, __j);
3024
	      std::__reverse(__ii, __last,
3025
			     std::__iterator_category(__first));
3026
	      return true;
3027
	    }
3028
	  if (__i == __first)
3029
	    {
3030
	      std::__reverse(__first, __last,
3031
			     std::__iterator_category(__first));
3032
	      return false;
3033
	    }
3034
	}
3035
    }
3036
3037
  /**
3038
   *  @brief  Permute range into the previous @e dictionary ordering.
3039
   *  @ingroup sorting_algorithms
3040
   *  @param  __first  Start of range.
3041
   *  @param  __last   End of range.
3042
   *  @return  False if wrapped to last permutation, true otherwise.
3043
   *
3044
   *  Treats all permutations of the range as a set of @e dictionary sorted
3045
   *  sequences.  Permutes the current sequence into the previous one of this
3046
   *  set.  Returns true if there are more sequences to generate.  If the
3047
   *  sequence is the smallest of the set, the largest is generated and false
3048
   *  returned.
3049
  */
3050
  template<typename _BidirectionalIterator>
3051
    inline bool
3052
    prev_permutation(_BidirectionalIterator __first,
3053
		     _BidirectionalIterator __last)
3054
    {
3055
      // concept requirements
3056
      __glibcxx_function_requires(_BidirectionalIteratorConcept<
3057
				  _BidirectionalIterator>)
3058
      __glibcxx_function_requires(_LessThanComparableConcept<
3059
	    typename iterator_traits<_BidirectionalIterator>::value_type>)
3060
      __glibcxx_requires_valid_range(__first, __last);
3061
3062
      return std::__prev_permutation(__first, __last,
3063
				     __gnu_cxx::__ops::__iter_less_iter());
3064
    }
3065
3066
  /**
3067
   *  @brief  Permute range into the previous @e dictionary ordering using
3068
   *          comparison functor.
3069
   *  @ingroup sorting_algorithms
3070
   *  @param  __first  Start of range.
3071
   *  @param  __last   End of range.
3072
   *  @param  __comp   A comparison functor.
3073
   *  @return  False if wrapped to last permutation, true otherwise.
3074
   *
3075
   *  Treats all permutations of the range [__first,__last) as a set of
3076
   *  @e dictionary sorted sequences ordered by @p __comp.  Permutes the current
3077
   *  sequence into the previous one of this set.  Returns true if there are
3078
   *  more sequences to generate.  If the sequence is the smallest of the set,
3079
   *  the largest is generated and false returned.
3080
  */
3081
  template<typename _BidirectionalIterator, typename _Compare>
3082
    inline bool
3083
    prev_permutation(_BidirectionalIterator __first,
3084
		     _BidirectionalIterator __last, _Compare __comp)
3085
    {
3086
      // concept requirements
3087
      __glibcxx_function_requires(_BidirectionalIteratorConcept<
3088
				  _BidirectionalIterator>)
3089
      __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
3090
	    typename iterator_traits<_BidirectionalIterator>::value_type,
3091
	    typename iterator_traits<_BidirectionalIterator>::value_type>)
3092
      __glibcxx_requires_valid_range(__first, __last);
3093
3094
      return std::__prev_permutation(__first, __last,
3095
				__gnu_cxx::__ops::__iter_comp_iter(__comp));
3096
    }
3097
3098
  // replace
3099
  // replace_if
3100
3101
  template<typename _InputIterator, typename _OutputIterator,
3102
	   typename _Predicate, typename _Tp>
3103
    _OutputIterator
3104
    __replace_copy_if(_InputIterator __first, _InputIterator __last,
3105
		      _OutputIterator __result,
3106
		      _Predicate __pred, const _Tp& __new_value)
3107
    {
3108
      for (; __first != __last; ++__first, ++__result)
3109
	if (__pred(__first))
3110
	  *__result = __new_value;
3111
	else
3112
	  *__result = *__first;
3113
      return __result;
3114
    }
3115
3116
  /**
3117
   *  @brief Copy a sequence, replacing each element of one value with another
3118
   *         value.
3119
   *  @param  __first      An input iterator.
3120
   *  @param  __last       An input iterator.
3121
   *  @param  __result     An output iterator.
3122
   *  @param  __old_value  The value to be replaced.
3123
   *  @param  __new_value  The replacement value.
3124
   *  @return   The end of the output sequence, @p result+(last-first).
3125
   *
3126
   *  Copies each element in the input range @p [__first,__last) to the
3127
   *  output range @p [__result,__result+(__last-__first)) replacing elements
3128
   *  equal to @p __old_value with @p __new_value.
3129
  */
3130
  template<typename _InputIterator, typename _OutputIterator, typename _Tp>
3131
    inline _OutputIterator
3132
    replace_copy(_InputIterator __first, _InputIterator __last,
3133
		 _OutputIterator __result,
3134
		 const _Tp& __old_value, const _Tp& __new_value)
3135
    {
3136
      // concept requirements
3137
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3138
      __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
3139
	    typename iterator_traits<_InputIterator>::value_type>)
3140
      __glibcxx_function_requires(_EqualOpConcept<
3141
	    typename iterator_traits<_InputIterator>::value_type, _Tp>)
3142
      __glibcxx_requires_valid_range(__first, __last);
3143
3144
      return std::__replace_copy_if(__first, __last, __result,
3145
			__gnu_cxx::__ops::__iter_equals_val(__old_value),
3146
					      __new_value);
3147
    }
3148
3149
  /**
3150
   *  @brief Copy a sequence, replacing each value for which a predicate
3151
   *         returns true with another value.
3152
   *  @ingroup mutating_algorithms
3153
   *  @param  __first      An input iterator.
3154
   *  @param  __last       An input iterator.
3155
   *  @param  __result     An output iterator.
3156
   *  @param  __pred       A predicate.
3157
   *  @param  __new_value  The replacement value.
3158
   *  @return   The end of the output sequence, @p __result+(__last-__first).
3159
   *
3160
   *  Copies each element in the range @p [__first,__last) to the range
3161
   *  @p [__result,__result+(__last-__first)) replacing elements for which
3162
   *  @p __pred returns true with @p __new_value.
3163
  */
3164
  template<typename _InputIterator, typename _OutputIterator,
3165
	   typename _Predicate, typename _Tp>
3166
    inline _OutputIterator
3167
    replace_copy_if(_InputIterator __first, _InputIterator __last,
3168
		    _OutputIterator __result,
3169
		    _Predicate __pred, const _Tp& __new_value)
3170
    {
3171
      // concept requirements
3172
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3173
      __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
3174
	    typename iterator_traits<_InputIterator>::value_type>)
3175
      __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
3176
	    typename iterator_traits<_InputIterator>::value_type>)
3177
      __glibcxx_requires_valid_range(__first, __last);
3178
3179
      return std::__replace_copy_if(__first, __last, __result,
3180
				__gnu_cxx::__ops::__pred_iter(__pred),
3181
					      __new_value);
3182
    }
3183
3184
  template<typename _InputIterator, typename _Predicate>
3185
    typename iterator_traits<_InputIterator>::difference_type
3186
    __count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
3187
    {
3188
      typename iterator_traits<_InputIterator>::difference_type __n = 0;
3189
      for (; __first != __last; ++__first)
3190
	if (__pred(__first))
3191
	  ++__n;
3192
      return __n;
3193
    }
3194
3195
#if __cplusplus >= 201103L
3196
  /**
3197
   *  @brief  Determines whether the elements of a sequence are sorted.
3198
   *  @ingroup sorting_algorithms
3199
   *  @param  __first   An iterator.
3200
   *  @param  __last    Another iterator.
3201
   *  @return  True if the elements are sorted, false otherwise.
3202
  */
3203
  template<typename _ForwardIterator>
3204
    inline bool
3205
    is_sorted(_ForwardIterator __first, _ForwardIterator __last)
3206
    { return std::is_sorted_until(__first, __last) == __last; }
3207
3208
  /**
3209
   *  @brief  Determines whether the elements of a sequence are sorted
3210
   *          according to a comparison functor.
3211
   *  @ingroup sorting_algorithms
3212
   *  @param  __first   An iterator.
3213
   *  @param  __last    Another iterator.
3214
   *  @param  __comp    A comparison functor.
3215
   *  @return  True if the elements are sorted, false otherwise.
3216
  */
3217
  template<typename _ForwardIterator, typename _Compare>
3218
    inline bool
3219
    is_sorted(_ForwardIterator __first, _ForwardIterator __last,
3220
	      _Compare __comp)
3221
    { return std::is_sorted_until(__first, __last, __comp) == __last; }
3222
3223
  template<typename _ForwardIterator, typename _Compare>
3224
    _ForwardIterator
3225
    __is_sorted_until(_ForwardIterator __first, _ForwardIterator __last,
3226
		      _Compare __comp)
3227
    {
3228
      if (__first == __last)
3229
	return __last;
3230
3231
      _ForwardIterator __next = __first;
3232
      for (++__next; __next != __last; __first = __next, ++__next)
3233
	if (__comp(__next, __first))
3234
	  return __next;
3235
      return __next;
3236
    }
3237
3238
  /**
3239
   *  @brief  Determines the end of a sorted sequence.
3240
   *  @ingroup sorting_algorithms
3241
   *  @param  __first   An iterator.
3242
   *  @param  __last    Another iterator.
3243
   *  @return  An iterator pointing to the last iterator i in [__first, __last)
3244
   *           for which the range [__first, i) is sorted.
3245
  */
3246
  template<typename _ForwardIterator>
3247
    inline _ForwardIterator
3248
    is_sorted_until(_ForwardIterator __first, _ForwardIterator __last)
3249
    {
3250
      // concept requirements
3251
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3252
      __glibcxx_function_requires(_LessThanComparableConcept<
3253
	    typename iterator_traits<_ForwardIterator>::value_type>)
3254
      __glibcxx_requires_valid_range(__first, __last);
3255
3256
      return std::__is_sorted_until(__first, __last,
3257
				    __gnu_cxx::__ops::__iter_less_iter());
3258
    }
3259
3260
  /**
3261
   *  @brief  Determines the end of a sorted sequence using comparison functor.
3262
   *  @ingroup sorting_algorithms
3263
   *  @param  __first   An iterator.
3264
   *  @param  __last    Another iterator.
3265
   *  @param  __comp    A comparison functor.
3266
   *  @return  An iterator pointing to the last iterator i in [__first, __last)
3267
   *           for which the range [__first, i) is sorted.
3268
  */
3269
  template<typename _ForwardIterator, typename _Compare>
3270
    inline _ForwardIterator
3271
    is_sorted_until(_ForwardIterator __first, _ForwardIterator __last,
3272
		    _Compare __comp)
3273
    {
3274
      // concept requirements
3275
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3276
      __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
3277
	    typename iterator_traits<_ForwardIterator>::value_type,
3278
	    typename iterator_traits<_ForwardIterator>::value_type>)
3279
      __glibcxx_requires_valid_range(__first, __last);
3280
3281
      return std::__is_sorted_until(__first, __last,
3282
				    __gnu_cxx::__ops::__iter_comp_iter(__comp));
3283
    }
3284
3285
  /**
3286
   *  @brief  Determines min and max at once as an ordered pair.
3287
   *  @ingroup sorting_algorithms
3288
   *  @param  __a  A thing of arbitrary type.
3289
   *  @param  __b  Another thing of arbitrary type.
3290
   *  @return A pair(__b, __a) if __b is smaller than __a, pair(__a,
3291
   *  __b) otherwise.
3292
  */
3293
  template<typename _Tp>
3294
    inline pair<const _Tp&, const _Tp&>
3295
    minmax(const _Tp& __a, const _Tp& __b)
3296
    {
3297
      // concept requirements
3298
      __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
3299
3300
      return __b < __a ? pair<const _Tp&, const _Tp&>(__b, __a)
3301
	               : pair<const _Tp&, const _Tp&>(__a, __b);
3302
    }
3303
3304
  /**
3305
   *  @brief  Determines min and max at once as an ordered pair.
3306
   *  @ingroup sorting_algorithms
3307
   *  @param  __a  A thing of arbitrary type.
3308
   *  @param  __b  Another thing of arbitrary type.
3309
   *  @param  __comp  A @link comparison_functors comparison functor @endlink.
3310
   *  @return A pair(__b, __a) if __b is smaller than __a, pair(__a,
3311
   *  __b) otherwise.
3312
  */
3313
  template<typename _Tp, typename _Compare>
3314
    inline pair<const _Tp&, const _Tp&>
3315
    minmax(const _Tp& __a, const _Tp& __b, _Compare __comp)
3316
    {
3317
      return __comp(__b, __a) ? pair<const _Tp&, const _Tp&>(__b, __a)
3318
	                      : pair<const _Tp&, const _Tp&>(__a, __b);
3319
    }
3320
3321
  template<typename _ForwardIterator, typename _Compare>
3322
    pair<_ForwardIterator, _ForwardIterator>
3323
    __minmax_element(_ForwardIterator __first, _ForwardIterator __last,
3324
		     _Compare __comp)
3325
    {
3326
      _ForwardIterator __next = __first;
3327
      if (__first == __last
3328
	  || ++__next == __last)
3329
	return std::make_pair(__first, __first);
3330
3331
      _ForwardIterator __min, __max;
3332
      if (__comp(__next, __first))
3333
	{
3334
	  __min = __next;
3335
	  __max = __first;
3336
	}
3337
      else
3338
	{
3339
	  __min = __first;
3340
	  __max = __next;
3341
	}
3342
3343
      __first = __next;
3344
      ++__first;
3345
3346
      while (__first != __last)
3347
	{
3348
	  __next = __first;
3349
	  if (++__next == __last)
3350
	    {
3351
	      if (__comp(__first, __min))
3352
		__min = __first;
3353
	      else if (!__comp(__first, __max))
3354
		__max = __first;
3355
	      break;
3356
	    }
3357
3358
	  if (__comp(__next, __first))
3359
	    {
3360
	      if (__comp(__next, __min))
3361
		__min = __next;
3362
	      if (!__comp(__first, __max))
3363
		__max = __first;
3364
	    }
3365
	  else
3366
	    {
3367
	      if (__comp(__first, __min))
3368
		__min = __first;
3369
	      if (!__comp(__next, __max))
3370
		__max = __next;
3371
	    }
3372
3373
	  __first = __next;
3374
	  ++__first;
3375
	}
3376
3377
      return std::make_pair(__min, __max);
3378
    }
3379
3380
  /**
3381
   *  @brief  Return a pair of iterators pointing to the minimum and maximum
3382
   *          elements in a range.
3383
   *  @ingroup sorting_algorithms
3384
   *  @param  __first  Start of range.
3385
   *  @param  __last   End of range.
3386
   *  @return  make_pair(m, M), where m is the first iterator i in 
3387
   *           [__first, __last) such that no other element in the range is
3388
   *           smaller, and where M is the last iterator i in [__first, __last)
3389
   *           such that no other element in the range is larger.
3390
  */
3391
  template<typename _ForwardIterator>
3392
    inline pair<_ForwardIterator, _ForwardIterator>
3393
    minmax_element(_ForwardIterator __first, _ForwardIterator __last)
3394
    {
3395
      // concept requirements
3396
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3397
      __glibcxx_function_requires(_LessThanComparableConcept<
3398
	    typename iterator_traits<_ForwardIterator>::value_type>)
3399
      __glibcxx_requires_valid_range(__first, __last);
3400
3401
      return std::__minmax_element(__first, __last,
3402
				   __gnu_cxx::__ops::__iter_less_iter());
3403
    }
3404
3405
  /**
3406
   *  @brief  Return a pair of iterators pointing to the minimum and maximum
3407
   *          elements in a range.
3408
   *  @ingroup sorting_algorithms
3409
   *  @param  __first  Start of range.
3410
   *  @param  __last   End of range.
3411
   *  @param  __comp   Comparison functor.
3412
   *  @return  make_pair(m, M), where m is the first iterator i in 
3413
   *           [__first, __last) such that no other element in the range is
3414
   *           smaller, and where M is the last iterator i in [__first, __last)
3415
   *           such that no other element in the range is larger.
3416
  */
3417
  template<typename _ForwardIterator, typename _Compare>
3418
    inline pair<_ForwardIterator, _ForwardIterator>
3419
    minmax_element(_ForwardIterator __first, _ForwardIterator __last,
3420
		   _Compare __comp)
3421
    {
3422
      // concept requirements
3423
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3424
      __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
3425
	    typename iterator_traits<_ForwardIterator>::value_type,
3426
	    typename iterator_traits<_ForwardIterator>::value_type>)
3427
      __glibcxx_requires_valid_range(__first, __last);
3428
3429
      return std::__minmax_element(__first, __last,
3430
				   __gnu_cxx::__ops::__iter_comp_iter(__comp));
3431
    }
3432
3433
  // N2722 + DR 915.
3434
  template<typename _Tp>
3435
    inline _Tp
3436
    min(initializer_list<_Tp> __l)
3437
    { return *std::min_element(__l.begin(), __l.end()); }
3438
3439
  template<typename _Tp, typename _Compare>
3440
    inline _Tp
3441
    min(initializer_list<_Tp> __l, _Compare __comp)
3442
    { return *std::min_element(__l.begin(), __l.end(), __comp); }
3443
3444
  template<typename _Tp>
3445
    inline _Tp
3446
    max(initializer_list<_Tp> __l)
3447
    { return *std::max_element(__l.begin(), __l.end()); }
3448
3449
  template<typename _Tp, typename _Compare>
3450
    inline _Tp
3451
    max(initializer_list<_Tp> __l, _Compare __comp)
3452
    { return *std::max_element(__l.begin(), __l.end(), __comp); }
3453
3454
  template<typename _Tp>
3455
    inline pair<_Tp, _Tp>
3456
    minmax(initializer_list<_Tp> __l)
3457
    {
3458
      pair<const _Tp*, const _Tp*> __p =
3459
	std::minmax_element(__l.begin(), __l.end());
3460
      return std::make_pair(*__p.first, *__p.second);
3461
    }
3462
3463
  template<typename _Tp, typename _Compare>
3464
    inline pair<_Tp, _Tp>
3465
    minmax(initializer_list<_Tp> __l, _Compare __comp)
3466
    {
3467
      pair<const _Tp*, const _Tp*> __p =
3468
	std::minmax_element(__l.begin(), __l.end(), __comp);
3469
      return std::make_pair(*__p.first, *__p.second);
3470
    }
3471
3472
  template<typename _ForwardIterator1, typename _ForwardIterator2,
3473
	   typename _BinaryPredicate>
3474
    bool
3475
    __is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
3476
		     _ForwardIterator2 __first2, _BinaryPredicate __pred)
3477
    {
3478
      // Efficiently compare identical prefixes:  O(N) if sequences
3479
      // have the same elements in the same order.
3480
      for (; __first1 != __last1; ++__first1, ++__first2)
3481
	if (!__pred(__first1, __first2))
3482
	  break;
3483
3484
      if (__first1 == __last1)
3485
	return true;
3486
3487
      // Establish __last2 assuming equal ranges by iterating over the
3488
      // rest of the list.
3489
      _ForwardIterator2 __last2 = __first2;
3490
      std::advance(__last2, std::distance(__first1, __last1));
3491
      for (_ForwardIterator1 __scan = __first1; __scan != __last1; ++__scan)
3492
	{
3493
	  if (__scan != std::__find_if(__first1, __scan,
3494
			  __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan)))
3495
	    continue; // We've seen this one before.
3496
	  
3497
	  auto __matches
3498
	    = std::__count_if(__first2, __last2,
3499
			__gnu_cxx::__ops::__iter_comp_iter(__pred, __scan));
3500
	  if (0 == __matches ||
3501
	      std::__count_if(__scan, __last1,
3502
			__gnu_cxx::__ops::__iter_comp_iter(__pred, __scan))
3503
	      != __matches)
3504
	    return false;
3505
	}
3506
      return true;
3507
    }
3508
3509
  /**
3510
   *  @brief  Checks whether a permutation of the second sequence is equal
3511
   *          to the first sequence.
3512
   *  @ingroup non_mutating_algorithms
3513
   *  @param  __first1  Start of first range.
3514
   *  @param  __last1   End of first range.
3515
   *  @param  __first2  Start of second range.
3516
   *  @return true if there exists a permutation of the elements in the range
3517
   *          [__first2, __first2 + (__last1 - __first1)), beginning with 
3518
   *          ForwardIterator2 begin, such that equal(__first1, __last1, begin)
3519
   *          returns true; otherwise, returns false.
3520
  */
3521
  template<typename _ForwardIterator1, typename _ForwardIterator2>
3522
    inline bool
3523
    is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
3524
		   _ForwardIterator2 __first2)
3525
    {
3526
      // concept requirements
3527
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
3528
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
3529
      __glibcxx_function_requires(_EqualOpConcept<
3530
		typename iterator_traits<_ForwardIterator1>::value_type,
3531
		typename iterator_traits<_ForwardIterator2>::value_type>)
3532
      __glibcxx_requires_valid_range(__first1, __last1);
3533
3534
      return std::__is_permutation(__first1, __last1, __first2,
3535
				   __gnu_cxx::__ops::__iter_equal_to_iter());
3536
    }
3537
3538
  /**
3539
   *  @brief  Checks whether a permutation of the second sequence is equal
3540
   *          to the first sequence.
3541
   *  @ingroup non_mutating_algorithms
3542
   *  @param  __first1  Start of first range.
3543
   *  @param  __last1   End of first range.
3544
   *  @param  __first2  Start of second range.
3545
   *  @param  __pred    A binary predicate.
3546
   *  @return true if there exists a permutation of the elements in
3547
   *          the range [__first2, __first2 + (__last1 - __first1)),
3548
   *          beginning with ForwardIterator2 begin, such that
3549
   *          equal(__first1, __last1, __begin, __pred) returns true;
3550
   *          otherwise, returns false.
3551
  */
3552
  template<typename _ForwardIterator1, typename _ForwardIterator2,
3553
	   typename _BinaryPredicate>
3554
    inline bool
3555
    is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
3556
		   _ForwardIterator2 __first2, _BinaryPredicate __pred)
3557
    {
3558
      // concept requirements
3559
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
3560
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
3561
      __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
3562
	    typename iterator_traits<_ForwardIterator1>::value_type,
3563
	    typename iterator_traits<_ForwardIterator2>::value_type>)
3564
      __glibcxx_requires_valid_range(__first1, __last1);
3565
3566
      return std::__is_permutation(__first1, __last1, __first2,
3567
				   __gnu_cxx::__ops::__iter_comp_iter(__pred));
3568
    }
3569
3570
#if __cplusplus > 201103L
3571
  template<typename _ForwardIterator1, typename _ForwardIterator2,
3572
	   typename _BinaryPredicate>
3573
    bool
3574
    __is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
3575
		     _ForwardIterator2 __first2, _ForwardIterator2 __last2,
3576
		     _BinaryPredicate __pred)
3577
    {
3578
      using _Cat1
3579
	= typename iterator_traits<_ForwardIterator1>::iterator_category;
3580
      using _Cat2
3581
	= typename iterator_traits<_ForwardIterator2>::iterator_category;
3582
      using _It1_is_RA = is_same<_Cat1, random_access_iterator_tag>;
3583
      using _It2_is_RA = is_same<_Cat2, random_access_iterator_tag>;
3584
      constexpr bool __ra_iters = _It1_is_RA() && _It2_is_RA();
3585
      if (__ra_iters)
3586
	{
3587
	  auto __d1 = std::distance(__first1, __last1);
3588
	  auto __d2 = std::distance(__first2, __last2);
3589
	  if (__d1 != __d2)
3590
	    return false;
3591
	}
3592
3593
      // Efficiently compare identical prefixes:  O(N) if sequences
3594
      // have the same elements in the same order.
3595
      for (; __first1 != __last1; ++__first1, ++__first2)
3596
	if (!__pred(__first1, __first2))
3597
	  break;
3598
3599
      if (__ra_iters)
3600
	{
3601
	  if (__first1 == __last1)
3602
	    return true;
3603
	}
3604
      else
3605
	{
3606
	  auto __d1 = std::distance(__first1, __last1);
3607
	  auto __d2 = std::distance(__first2, __last2);
3608
	  if (__d1 == 0 && __d2 == 0)
3609
	    return true;
3610
	  if (__d1 != __d2)
3611
	    return false;
3612
	}
3613
3614
      for (_ForwardIterator1 __scan = __first1; __scan != __last1; ++__scan)
3615
	{
3616
	  if (__scan != std::__find_if(__first1, __scan,
3617
			__gnu_cxx::__ops::__iter_comp_iter(__pred, __scan)))
3618
	    continue; // We've seen this one before.
3619
3620
	  auto __matches = std::__count_if(__first2, __last2,
3621
		__gnu_cxx::__ops::__iter_comp_iter(__pred, __scan));
3622
	  if (0 == __matches
3623
	      || std::__count_if(__scan, __last1,
3624
			__gnu_cxx::__ops::__iter_comp_iter(__pred, __scan))
3625
	      != __matches)
3626
	    return false;
3627
	}
3628
      return true;
3629
    }
3630
3631
  /**
3632
   *  @brief  Checks whether a permutaion of the second sequence is equal
3633
   *          to the first sequence.
3634
   *  @ingroup non_mutating_algorithms
3635
   *  @param  __first1  Start of first range.
3636
   *  @param  __last1   End of first range.
3637
   *  @param  __first2  Start of second range.
3638
   *  @param  __last2   End of first range.
3639
   *  @return true if there exists a permutation of the elements in the range
3640
   *          [__first2, __last2), beginning with ForwardIterator2 begin,
3641
   *          such that equal(__first1, __last1, begin) returns true;
3642
   *          otherwise, returns false.
3643
  */
3644
  template<typename _ForwardIterator1, typename _ForwardIterator2>
3645
    inline bool
3646
    is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
3647
		   _ForwardIterator2 __first2, _ForwardIterator2 __last2)
3648
    {
3649
      __glibcxx_requires_valid_range(__first1, __last1);
3650
      __glibcxx_requires_valid_range(__first2, __last2);
3651
3652
      return
3653
	std::__is_permutation(__first1, __last1, __first2, __last2,
3654
			      __gnu_cxx::__ops::__iter_equal_to_iter());
3655
    }
3656
3657
  /**
3658
   *  @brief  Checks whether a permutation of the second sequence is equal
3659
   *          to the first sequence.
3660
   *  @ingroup non_mutating_algorithms
3661
   *  @param  __first1  Start of first range.
3662
   *  @param  __last1   End of first range.
3663
   *  @param  __first2  Start of second range.
3664
   *  @param  __last2   End of first range.
3665
   *  @param  __pred    A binary predicate.
3666
   *  @return true if there exists a permutation of the elements in the range
3667
   *          [__first2, __last2), beginning with ForwardIterator2 begin,
3668
   *          such that equal(__first1, __last1, __begin, __pred) returns true;
3669
   *          otherwise, returns false.
3670
  */
3671
  template<typename _ForwardIterator1, typename _ForwardIterator2,
3672
	   typename _BinaryPredicate>
3673
    inline bool
3674
    is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
3675
		   _ForwardIterator2 __first2, _ForwardIterator2 __last2,
3676
		   _BinaryPredicate __pred)
3677
    {
3678
      __glibcxx_requires_valid_range(__first1, __last1);
3679
      __glibcxx_requires_valid_range(__first2, __last2);
3680
3681
      return std::__is_permutation(__first1, __last1, __first2, __last2,
3682
				   __gnu_cxx::__ops::__iter_comp_iter(__pred));
3683
    }
3684
#endif
3685
3686
#ifdef _GLIBCXX_USE_C99_STDINT_TR1
3687
  /**
3688
   *  @brief Shuffle the elements of a sequence using a uniform random
3689
   *         number generator.
3690
   *  @ingroup mutating_algorithms
3691
   *  @param  __first   A forward iterator.
3692
   *  @param  __last    A forward iterator.
3693
   *  @param  __g       A UniformRandomNumberGenerator (26.5.1.3).
3694
   *  @return  Nothing.
3695
   *
3696
   *  Reorders the elements in the range @p [__first,__last) using @p __g to
3697
   *  provide random numbers.
3698
  */
3699
  template<typename _RandomAccessIterator,
3700
	   typename _UniformRandomNumberGenerator>
3701
    void
3702
    shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last,
3703
	    _UniformRandomNumberGenerator&& __g)
3704
    {
3705
      // concept requirements
3706
      __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
3707
	    _RandomAccessIterator>)
3708
      __glibcxx_requires_valid_range(__first, __last);
3709
3710
      if (__first == __last)
3711
	return;
3712
3713
      typedef typename iterator_traits<_RandomAccessIterator>::difference_type
3714
	_DistanceType;
3715
3716
      typedef typename std::make_unsigned<_DistanceType>::type __ud_type;
3717
      typedef typename std::uniform_int_distribution<__ud_type> __distr_type;
3718
      typedef typename __distr_type::param_type __p_type;
3719
      __distr_type __d;
3720
3721
      for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
3722
	std::iter_swap(__i, __first + __d(__g, __p_type(0, __i - __first)));
3723
    }
3724
#endif
3725
3726
#endif // C++11
3727
3728
_GLIBCXX_END_NAMESPACE_VERSION
3729
3730
_GLIBCXX_BEGIN_NAMESPACE_ALGO
3731
3732
  /**
3733
   *  @brief Apply a function to every element of a sequence.
3734
   *  @ingroup non_mutating_algorithms
3735
   *  @param  __first  An input iterator.
3736
   *  @param  __last   An input iterator.
3737
   *  @param  __f      A unary function object.
3738
   *  @return   @p __f (std::move(@p __f) in C++0x).
3739
   *
3740
   *  Applies the function object @p __f to each element in the range
3741
   *  @p [first,last).  @p __f must not modify the order of the sequence.
3742
   *  If @p __f has a return value it is ignored.
3743
  */
3744
  template<typename _InputIterator, typename _Function>
3745
    _Function
3746
    for_each(_InputIterator __first, _InputIterator __last, _Function __f)
3747
    {
3748
      // concept requirements
3749
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3750
      __glibcxx_requires_valid_range(__first, __last);
3751
      for (; __first != __last; ++__first)
3752
	__f(*__first);
3753
      return _GLIBCXX_MOVE(__f);
3754
    }
3755
3756
  /**
3757
   *  @brief Find the first occurrence of a value in a sequence.
3758
   *  @ingroup non_mutating_algorithms
3759
   *  @param  __first  An input iterator.
3760
   *  @param  __last   An input iterator.
3761
   *  @param  __val    The value to find.
3762
   *  @return   The first iterator @c i in the range @p [__first,__last)
3763
   *  such that @c *i == @p __val, or @p __last if no such iterator exists.
3764
  */
3765
  template<typename _InputIterator, typename _Tp>
3766
    inline _InputIterator
3767
    find(_InputIterator __first, _InputIterator __last,
3768
	 const _Tp& __val)
3769
    {
3770
      // concept requirements
3771
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3772
      __glibcxx_function_requires(_EqualOpConcept<
3773
		typename iterator_traits<_InputIterator>::value_type, _Tp>)
3774
      __glibcxx_requires_valid_range(__first, __last);
3775
      return std::__find_if(__first, __last,
3776
			    __gnu_cxx::__ops::__iter_equals_val(__val));
3777
    }
3778
3779
  /**
3780
   *  @brief Find the first element in a sequence for which a
3781
   *         predicate is true.
3782
   *  @ingroup non_mutating_algorithms
3783
   *  @param  __first  An input iterator.
3784
   *  @param  __last   An input iterator.
3785
   *  @param  __pred   A predicate.
3786
   *  @return   The first iterator @c i in the range @p [__first,__last)
3787
   *  such that @p __pred(*i) is true, or @p __last if no such iterator exists.
3788
  */
3789
  template<typename _InputIterator, typename _Predicate>
3790
    inline _InputIterator
3791
    find_if(_InputIterator __first, _InputIterator __last,
3792
	    _Predicate __pred)
3793
    {
3794
      // concept requirements
3795
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3796
      __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
3797
	      typename iterator_traits<_InputIterator>::value_type>)
3798
      __glibcxx_requires_valid_range(__first, __last);
3799
3800
      return std::__find_if(__first, __last,
3801
			    __gnu_cxx::__ops::__pred_iter(__pred));
3802
    }
3803
3804
  /**
3805
   *  @brief  Find element from a set in a sequence.
3806
   *  @ingroup non_mutating_algorithms
3807
   *  @param  __first1  Start of range to search.
3808
   *  @param  __last1   End of range to search.
3809
   *  @param  __first2  Start of match candidates.
3810
   *  @param  __last2   End of match candidates.
3811
   *  @return   The first iterator @c i in the range
3812
   *  @p [__first1,__last1) such that @c *i == @p *(i2) such that i2 is an
3813
   *  iterator in [__first2,__last2), or @p __last1 if no such iterator exists.
3814
   *
3815
   *  Searches the range @p [__first1,__last1) for an element that is
3816
   *  equal to some element in the range [__first2,__last2).  If
3817
   *  found, returns an iterator in the range [__first1,__last1),
3818
   *  otherwise returns @p __last1.
3819
  */
3820
  template<typename _InputIterator, typename _ForwardIterator>
3821
    _InputIterator
3822
    find_first_of(_InputIterator __first1, _InputIterator __last1,
3823
		  _ForwardIterator __first2, _ForwardIterator __last2)
3824
    {
3825
      // concept requirements
3826
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3827
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3828
      __glibcxx_function_requires(_EqualOpConcept<
3829
	    typename iterator_traits<_InputIterator>::value_type,
3830
	    typename iterator_traits<_ForwardIterator>::value_type>)
3831
      __glibcxx_requires_valid_range(__first1, __last1);
3832
      __glibcxx_requires_valid_range(__first2, __last2);
3833
3834
      for (; __first1 != __last1; ++__first1)
3835
	for (_ForwardIterator __iter = __first2; __iter != __last2; ++__iter)
3836
	  if (*__first1 == *__iter)
3837
	    return __first1;
3838
      return __last1;
3839
    }
3840
3841
  /**
3842
   *  @brief  Find element from a set in a sequence using a predicate.
3843
   *  @ingroup non_mutating_algorithms
3844
   *  @param  __first1  Start of range to search.
3845
   *  @param  __last1   End of range to search.
3846
   *  @param  __first2  Start of match candidates.
3847
   *  @param  __last2   End of match candidates.
3848
   *  @param  __comp    Predicate to use.
3849
   *  @return   The first iterator @c i in the range
3850
   *  @p [__first1,__last1) such that @c comp(*i, @p *(i2)) is true
3851
   *  and i2 is an iterator in [__first2,__last2), or @p __last1 if no
3852
   *  such iterator exists.
3853
   *
3854
3855
   *  Searches the range @p [__first1,__last1) for an element that is
3856
   *  equal to some element in the range [__first2,__last2).  If
3857
   *  found, returns an iterator in the range [__first1,__last1),
3858
   *  otherwise returns @p __last1.
3859
  */
3860
  template<typename _InputIterator, typename _ForwardIterator,
3861
	   typename _BinaryPredicate>
3862
    _InputIterator
3863
    find_first_of(_InputIterator __first1, _InputIterator __last1,
3864
		  _ForwardIterator __first2, _ForwardIterator __last2,
3865
		  _BinaryPredicate __comp)
3866
    {
3867
      // concept requirements
3868
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3869
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3870
      __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
3871
	    typename iterator_traits<_InputIterator>::value_type,
3872
	    typename iterator_traits<_ForwardIterator>::value_type>)
3873
      __glibcxx_requires_valid_range(__first1, __last1);
3874
      __glibcxx_requires_valid_range(__first2, __last2);
3875
3876
      for (; __first1 != __last1; ++__first1)
3877
	for (_ForwardIterator __iter = __first2; __iter != __last2; ++__iter)
3878
	  if (__comp(*__first1, *__iter))
3879
	    return __first1;
3880
      return __last1;
3881
    }
3882
3883
  /**
3884
   *  @brief Find two adjacent values in a sequence that are equal.
3885
   *  @ingroup non_mutating_algorithms
3886
   *  @param  __first  A forward iterator.
3887
   *  @param  __last   A forward iterator.
3888
   *  @return   The first iterator @c i such that @c i and @c i+1 are both
3889
   *  valid iterators in @p [__first,__last) and such that @c *i == @c *(i+1),
3890
   *  or @p __last if no such iterator exists.
3891
  */
3892
  template<typename _ForwardIterator>
3893
    inline _ForwardIterator
3894
    adjacent_find(_ForwardIterator __first, _ForwardIterator __last)
3895
    {
3896
      // concept requirements
3897
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3898
      __glibcxx_function_requires(_EqualityComparableConcept<
3899
	    typename iterator_traits<_ForwardIterator>::value_type>)
3900
      __glibcxx_requires_valid_range(__first, __last);
3901
3902
      return std::__adjacent_find(__first, __last,
3903
				  __gnu_cxx::__ops::__iter_equal_to_iter());
3904
    }
3905
3906
  /**
3907
   *  @brief Find two adjacent values in a sequence using a predicate.
3908
   *  @ingroup non_mutating_algorithms
3909
   *  @param  __first         A forward iterator.
3910
   *  @param  __last          A forward iterator.
3911
   *  @param  __binary_pred   A binary predicate.
3912
   *  @return   The first iterator @c i such that @c i and @c i+1 are both
3913
   *  valid iterators in @p [__first,__last) and such that
3914
   *  @p __binary_pred(*i,*(i+1)) is true, or @p __last if no such iterator
3915
   *  exists.
3916
  */
3917
  template<typename _ForwardIterator, typename _BinaryPredicate>
3918
    inline _ForwardIterator
3919
    adjacent_find(_ForwardIterator __first, _ForwardIterator __last,
3920
		  _BinaryPredicate __binary_pred)
3921
    {
3922
      // concept requirements
3923
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3924
      __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
3925
	    typename iterator_traits<_ForwardIterator>::value_type,
3926
	    typename iterator_traits<_ForwardIterator>::value_type>)
3927
      __glibcxx_requires_valid_range(__first, __last);
3928
3929
      return std::__adjacent_find(__first, __last,
3930
			__gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
3931
    }
3932
3933
  /**
3934
   *  @brief Count the number of copies of a value in a sequence.
3935
   *  @ingroup non_mutating_algorithms
3936
   *  @param  __first  An input iterator.
3937
   *  @param  __last   An input iterator.
3938
   *  @param  __value  The value to be counted.
3939
   *  @return   The number of iterators @c i in the range @p [__first,__last)
3940
   *  for which @c *i == @p __value
3941
  */
3942
  template<typename _InputIterator, typename _Tp>
3943
    inline typename iterator_traits<_InputIterator>::difference_type
3944
    count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
3945
    {
3946
      // concept requirements
3947
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3948
      __glibcxx_function_requires(_EqualOpConcept<
3949
	    typename iterator_traits<_InputIterator>::value_type, _Tp>)
3950
      __glibcxx_requires_valid_range(__first, __last);
3951
3952
      return std::__count_if(__first, __last,
3953
			     __gnu_cxx::__ops::__iter_equals_val(__value));
3954
    }
3955
3956
  /**
3957
   *  @brief Count the elements of a sequence for which a predicate is true.
3958
   *  @ingroup non_mutating_algorithms
3959
   *  @param  __first  An input iterator.
3960
   *  @param  __last   An input iterator.
3961
   *  @param  __pred   A predicate.
3962
   *  @return   The number of iterators @c i in the range @p [__first,__last)
3963
   *  for which @p __pred(*i) is true.
3964
  */
3965
  template<typename _InputIterator, typename _Predicate>
3966
    inline typename iterator_traits<_InputIterator>::difference_type
3967
    count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
3968
    {
3969
      // concept requirements
3970
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
3971
      __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
3972
	    typename iterator_traits<_InputIterator>::value_type>)
3973
      __glibcxx_requires_valid_range(__first, __last);
3974
3975
      return std::__count_if(__first, __last,
3976
			     __gnu_cxx::__ops::__pred_iter(__pred));
3977
    }
3978
3979
  /**
3980
   *  @brief Search a sequence for a matching sub-sequence.
3981
   *  @ingroup non_mutating_algorithms
3982
   *  @param  __first1  A forward iterator.
3983
   *  @param  __last1   A forward iterator.
3984
   *  @param  __first2  A forward iterator.
3985
   *  @param  __last2   A forward iterator.
3986
   *  @return The first iterator @c i in the range @p
3987
   *  [__first1,__last1-(__last2-__first2)) such that @c *(i+N) == @p
3988
   *  *(__first2+N) for each @c N in the range @p
3989
   *  [0,__last2-__first2), or @p __last1 if no such iterator exists.
3990
   *
3991
   *  Searches the range @p [__first1,__last1) for a sub-sequence that
3992
   *  compares equal value-by-value with the sequence given by @p
3993
   *  [__first2,__last2) and returns an iterator to the first element
3994
   *  of the sub-sequence, or @p __last1 if the sub-sequence is not
3995
   *  found.
3996
   *
3997
   *  Because the sub-sequence must lie completely within the range @p
3998
   *  [__first1,__last1) it must start at a position less than @p
3999
   *  __last1-(__last2-__first2) where @p __last2-__first2 is the
4000
   *  length of the sub-sequence.
4001
   *
4002
   *  This means that the returned iterator @c i will be in the range
4003
   *  @p [__first1,__last1-(__last2-__first2))
4004
  */
4005
  template<typename _ForwardIterator1, typename _ForwardIterator2>
4006
    inline _ForwardIterator1
4007
    search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
4008
	   _ForwardIterator2 __first2, _ForwardIterator2 __last2)
4009
    {
4010
      // concept requirements
4011
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
4012
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
4013
      __glibcxx_function_requires(_EqualOpConcept<
4014
	    typename iterator_traits<_ForwardIterator1>::value_type,
4015
	    typename iterator_traits<_ForwardIterator2>::value_type>)
4016
      __glibcxx_requires_valid_range(__first1, __last1);
4017
      __glibcxx_requires_valid_range(__first2, __last2);
4018
4019
      return std::__search(__first1, __last1, __first2, __last2,
4020
			   __gnu_cxx::__ops::__iter_equal_to_iter());
4021
    }
4022
4023
  /**
4024
   *  @brief Search a sequence for a matching sub-sequence using a predicate.
4025
   *  @ingroup non_mutating_algorithms
4026
   *  @param  __first1     A forward iterator.
4027
   *  @param  __last1      A forward iterator.
4028
   *  @param  __first2     A forward iterator.
4029
   *  @param  __last2      A forward iterator.
4030
   *  @param  __predicate  A binary predicate.
4031
   *  @return   The first iterator @c i in the range
4032
   *  @p [__first1,__last1-(__last2-__first2)) such that
4033
   *  @p __predicate(*(i+N),*(__first2+N)) is true for each @c N in the range
4034
   *  @p [0,__last2-__first2), or @p __last1 if no such iterator exists.
4035
   *
4036
   *  Searches the range @p [__first1,__last1) for a sub-sequence that
4037
   *  compares equal value-by-value with the sequence given by @p
4038
   *  [__first2,__last2), using @p __predicate to determine equality,
4039
   *  and returns an iterator to the first element of the
4040
   *  sub-sequence, or @p __last1 if no such iterator exists.
4041
   *
4042
   *  @see search(_ForwardIter1, _ForwardIter1, _ForwardIter2, _ForwardIter2)
4043
  */
4044
  template<typename _ForwardIterator1, typename _ForwardIterator2,
4045
	   typename _BinaryPredicate>
4046
    inline _ForwardIterator1
4047
    search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
4048
	   _ForwardIterator2 __first2, _ForwardIterator2 __last2,
4049
	   _BinaryPredicate  __predicate)
4050
    {
4051
      // concept requirements
4052
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
4053
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
4054
      __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
4055
	    typename iterator_traits<_ForwardIterator1>::value_type,
4056
	    typename iterator_traits<_ForwardIterator2>::value_type>)
4057
      __glibcxx_requires_valid_range(__first1, __last1);
4058
      __glibcxx_requires_valid_range(__first2, __last2);
4059
4060
      return std::__search(__first1, __last1, __first2, __last2,
4061
			   __gnu_cxx::__ops::__iter_comp_iter(__predicate));
4062
    }
4063
4064
  /**
4065
   *  @brief Search a sequence for a number of consecutive values.
4066
   *  @ingroup non_mutating_algorithms
4067
   *  @param  __first  A forward iterator.
4068
   *  @param  __last   A forward iterator.
4069
   *  @param  __count  The number of consecutive values.
4070
   *  @param  __val    The value to find.
4071
   *  @return The first iterator @c i in the range @p
4072
   *  [__first,__last-__count) such that @c *(i+N) == @p __val for
4073
   *  each @c N in the range @p [0,__count), or @p __last if no such
4074
   *  iterator exists.
4075
   *
4076
   *  Searches the range @p [__first,__last) for @p count consecutive elements
4077
   *  equal to @p __val.
4078
  */
4079
  template<typename _ForwardIterator, typename _Integer, typename _Tp>
4080
    inline _ForwardIterator
4081
    search_n(_ForwardIterator __first, _ForwardIterator __last,
4082
	     _Integer __count, const _Tp& __val)
4083
    {
4084
      // concept requirements
4085
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
4086
      __glibcxx_function_requires(_EqualOpConcept<
4087
	    typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
4088
      __glibcxx_requires_valid_range(__first, __last);
4089
4090
      return std::__search_n(__first, __last, __count,
4091
			     __gnu_cxx::__ops::__iter_equals_val(__val));
4092
    }
4093
4094
4095
  /**
4096
   *  @brief Search a sequence for a number of consecutive values using a
4097
   *         predicate.
4098
   *  @ingroup non_mutating_algorithms
4099
   *  @param  __first        A forward iterator.
4100
   *  @param  __last         A forward iterator.
4101
   *  @param  __count        The number of consecutive values.
4102
   *  @param  __val          The value to find.
4103
   *  @param  __binary_pred  A binary predicate.
4104
   *  @return The first iterator @c i in the range @p
4105
   *  [__first,__last-__count) such that @p
4106
   *  __binary_pred(*(i+N),__val) is true for each @c N in the range
4107
   *  @p [0,__count), or @p __last if no such iterator exists.
4108
   *
4109
   *  Searches the range @p [__first,__last) for @p __count
4110
   *  consecutive elements for which the predicate returns true.
4111
  */
4112
  template<typename _ForwardIterator, typename _Integer, typename _Tp,
4113
           typename _BinaryPredicate>
4114
    inline _ForwardIterator
4115
    search_n(_ForwardIterator __first, _ForwardIterator __last,
4116
	     _Integer __count, const _Tp& __val,
4117
	     _BinaryPredicate __binary_pred)
4118
    {
4119
      // concept requirements
4120
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
4121
      __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
4122
	    typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
4123
      __glibcxx_requires_valid_range(__first, __last);
4124
4125
      return std::__search_n(__first, __last, __count,
4126
		__gnu_cxx::__ops::__iter_comp_val(__binary_pred, __val));
4127
    }
4128
4129
4130
  /**
4131
   *  @brief Perform an operation on a sequence.
4132
   *  @ingroup mutating_algorithms
4133
   *  @param  __first     An input iterator.
4134
   *  @param  __last      An input iterator.
4135
   *  @param  __result    An output iterator.
4136
   *  @param  __unary_op  A unary operator.
4137
   *  @return   An output iterator equal to @p __result+(__last-__first).
4138
   *
4139
   *  Applies the operator to each element in the input range and assigns
4140
   *  the results to successive elements of the output sequence.
4141
   *  Evaluates @p *(__result+N)=unary_op(*(__first+N)) for each @c N in the
4142
   *  range @p [0,__last-__first).
4143
   *
4144
   *  @p unary_op must not alter its argument.
4145
  */
4146
  template<typename _InputIterator, typename _OutputIterator,
4147
	   typename _UnaryOperation>
4148
    _OutputIterator
4149
    transform(_InputIterator __first, _InputIterator __last,
4150
	      _OutputIterator __result, _UnaryOperation __unary_op)
4151
    {
4152
      // concept requirements
4153
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
4154
      __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4155
            // "the type returned by a _UnaryOperation"
4156
            __typeof__(__unary_op(*__first))>)
4157
      __glibcxx_requires_valid_range(__first, __last);
4158
4159
      for (; __first != __last; ++__first, ++__result)
4160
	*__result = __unary_op(*__first);
4161
      return __result;
4162
    }
4163
4164
  /**
4165
   *  @brief Perform an operation on corresponding elements of two sequences.
4166
   *  @ingroup mutating_algorithms
4167
   *  @param  __first1     An input iterator.
4168
   *  @param  __last1      An input iterator.
4169
   *  @param  __first2     An input iterator.
4170
   *  @param  __result     An output iterator.
4171
   *  @param  __binary_op  A binary operator.
4172
   *  @return   An output iterator equal to @p result+(last-first).
4173
   *
4174
   *  Applies the operator to the corresponding elements in the two
4175
   *  input ranges and assigns the results to successive elements of the
4176
   *  output sequence.
4177
   *  Evaluates @p
4178
   *  *(__result+N)=__binary_op(*(__first1+N),*(__first2+N)) for each
4179
   *  @c N in the range @p [0,__last1-__first1).
4180
   *
4181
   *  @p binary_op must not alter either of its arguments.
4182
  */
4183
  template<typename _InputIterator1, typename _InputIterator2,
4184
	   typename _OutputIterator, typename _BinaryOperation>
4185
    _OutputIterator
4186
    transform(_InputIterator1 __first1, _InputIterator1 __last1,
4187
	      _InputIterator2 __first2, _OutputIterator __result,
4188
	      _BinaryOperation __binary_op)
4189
    {
4190
      // concept requirements
4191
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
4192
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
4193
      __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4194
            // "the type returned by a _BinaryOperation"
4195
            __typeof__(__binary_op(*__first1,*__first2))>)
4196
      __glibcxx_requires_valid_range(__first1, __last1);
4197
4198
      for (; __first1 != __last1; ++__first1, ++__first2, ++__result)
4199
	*__result = __binary_op(*__first1, *__first2);
4200
      return __result;
4201
    }
4202
4203
  /**
4204
   *  @brief Replace each occurrence of one value in a sequence with another
4205
   *         value.
4206
   *  @ingroup mutating_algorithms
4207
   *  @param  __first      A forward iterator.
4208
   *  @param  __last       A forward iterator.
4209
   *  @param  __old_value  The value to be replaced.
4210
   *  @param  __new_value  The replacement value.
4211
   *  @return   replace() returns no value.
4212
   *
4213
   *  For each iterator @c i in the range @p [__first,__last) if @c *i ==
4214
   *  @p __old_value then the assignment @c *i = @p __new_value is performed.
4215
  */
4216
  template<typename _ForwardIterator, typename _Tp>
4217
    void
4218
    replace(_ForwardIterator __first, _ForwardIterator __last,
4219
	    const _Tp& __old_value, const _Tp& __new_value)
4220
    {
4221
      // concept requirements
4222
      __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
4223
				  _ForwardIterator>)
4224
      __glibcxx_function_requires(_EqualOpConcept<
4225
	    typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
4226
      __glibcxx_function_requires(_ConvertibleConcept<_Tp,
4227
	    typename iterator_traits<_ForwardIterator>::value_type>)
4228
      __glibcxx_requires_valid_range(__first, __last);
4229
4230
      for (; __first != __last; ++__first)
4231
	if (*__first == __old_value)
4232
	  *__first = __new_value;
4233
    }
4234
4235
  /**
4236
   *  @brief Replace each value in a sequence for which a predicate returns
4237
   *         true with another value.
4238
   *  @ingroup mutating_algorithms
4239
   *  @param  __first      A forward iterator.
4240
   *  @param  __last       A forward iterator.
4241
   *  @param  __pred       A predicate.
4242
   *  @param  __new_value  The replacement value.
4243
   *  @return   replace_if() returns no value.
4244
   *
4245
   *  For each iterator @c i in the range @p [__first,__last) if @p __pred(*i)
4246
   *  is true then the assignment @c *i = @p __new_value is performed.
4247
  */
4248
  template<typename _ForwardIterator, typename _Predicate, typename _Tp>
4249
    void
4250
    replace_if(_ForwardIterator __first, _ForwardIterator __last,
4251
	       _Predicate __pred, const _Tp& __new_value)
4252
    {
4253
      // concept requirements
4254
      __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
4255
				  _ForwardIterator>)
4256
      __glibcxx_function_requires(_ConvertibleConcept<_Tp,
4257
	    typename iterator_traits<_ForwardIterator>::value_type>)
4258
      __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
4259
	    typename iterator_traits<_ForwardIterator>::value_type>)
4260
      __glibcxx_requires_valid_range(__first, __last);
4261
4262
      for (; __first != __last; ++__first)
4263
	if (__pred(*__first))
4264
	  *__first = __new_value;
4265
    }
4266
4267
  /**
4268
   *  @brief Assign the result of a function object to each value in a
4269
   *         sequence.
4270
   *  @ingroup mutating_algorithms
4271
   *  @param  __first  A forward iterator.
4272
   *  @param  __last   A forward iterator.
4273
   *  @param  __gen    A function object taking no arguments and returning
4274
   *                 std::iterator_traits<_ForwardIterator>::value_type
4275
   *  @return   generate() returns no value.
4276
   *
4277
   *  Performs the assignment @c *i = @p __gen() for each @c i in the range
4278
   *  @p [__first,__last).
4279
  */
4280
  template<typename _ForwardIterator, typename _Generator>
4281
    void
4282
    generate(_ForwardIterator __first, _ForwardIterator __last,
4283
	     _Generator __gen)
4284
    {
4285
      // concept requirements
4286
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
4287
      __glibcxx_function_requires(_GeneratorConcept<_Generator,
4288
	    typename iterator_traits<_ForwardIterator>::value_type>)
4289
      __glibcxx_requires_valid_range(__first, __last);
4290
4291
      for (; __first != __last; ++__first)
4292
	*__first = __gen();
4293
    }
4294
4295
  /**
4296
   *  @brief Assign the result of a function object to each value in a
4297
   *         sequence.
4298
   *  @ingroup mutating_algorithms
4299
   *  @param  __first  A forward iterator.
4300
   *  @param  __n      The length of the sequence.
4301
   *  @param  __gen    A function object taking no arguments and returning
4302
   *                 std::iterator_traits<_ForwardIterator>::value_type
4303
   *  @return   The end of the sequence, @p __first+__n
4304
   *
4305
   *  Performs the assignment @c *i = @p __gen() for each @c i in the range
4306
   *  @p [__first,__first+__n).
4307
   *
4308
   *  _GLIBCXX_RESOLVE_LIB_DEFECTS
4309
   *  DR 865. More algorithms that throw away information
4310
  */
4311
  template<typename _OutputIterator, typename _Size, typename _Generator>
4312
    _OutputIterator
4313
    generate_n(_OutputIterator __first, _Size __n, _Generator __gen)
4314
    {
4315
      // concept requirements
4316
      __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4317
            // "the type returned by a _Generator"
4318
            __typeof__(__gen())>)
4319
4320
      for (; __n > 0; --__n, ++__first)
4321
	*__first = __gen();
4322
      return __first;
4323
    }
4324
4325
  /**
4326
   *  @brief Copy a sequence, removing consecutive duplicate values.
4327
   *  @ingroup mutating_algorithms
4328
   *  @param  __first   An input iterator.
4329
   *  @param  __last    An input iterator.
4330
   *  @param  __result  An output iterator.
4331
   *  @return   An iterator designating the end of the resulting sequence.
4332
   *
4333
   *  Copies each element in the range @p [__first,__last) to the range
4334
   *  beginning at @p __result, except that only the first element is copied
4335
   *  from groups of consecutive elements that compare equal.
4336
   *  unique_copy() is stable, so the relative order of elements that are
4337
   *  copied is unchanged.
4338
   *
4339
   *  _GLIBCXX_RESOLVE_LIB_DEFECTS
4340
   *  DR 241. Does unique_copy() require CopyConstructible and Assignable?
4341
   *  
4342
   *  _GLIBCXX_RESOLVE_LIB_DEFECTS
4343
   *  DR 538. 241 again: Does unique_copy() require CopyConstructible and 
4344
   *  Assignable?
4345
  */
4346
  template<typename _InputIterator, typename _OutputIterator>
4347
    inline _OutputIterator
4348
    unique_copy(_InputIterator __first, _InputIterator __last,
4349
		_OutputIterator __result)
4350
    {
4351
      // concept requirements
4352
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
4353
      __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4354
	    typename iterator_traits<_InputIterator>::value_type>)
4355
      __glibcxx_function_requires(_EqualityComparableConcept<
4356
	    typename iterator_traits<_InputIterator>::value_type>)
4357
      __glibcxx_requires_valid_range(__first, __last);
4358
4359
      if (__first == __last)
4360
	return __result;
4361
      return std::__unique_copy(__first, __last, __result,
4362
				__gnu_cxx::__ops::__iter_equal_to_iter(),
4363
				std::__iterator_category(__first),
4364
				std::__iterator_category(__result));
4365
    }
4366
4367
  /**
4368
   *  @brief Copy a sequence, removing consecutive values using a predicate.
4369
   *  @ingroup mutating_algorithms
4370
   *  @param  __first        An input iterator.
4371
   *  @param  __last         An input iterator.
4372
   *  @param  __result       An output iterator.
4373
   *  @param  __binary_pred  A binary predicate.
4374
   *  @return   An iterator designating the end of the resulting sequence.
4375
   *
4376
   *  Copies each element in the range @p [__first,__last) to the range
4377
   *  beginning at @p __result, except that only the first element is copied
4378
   *  from groups of consecutive elements for which @p __binary_pred returns
4379
   *  true.
4380
   *  unique_copy() is stable, so the relative order of elements that are
4381
   *  copied is unchanged.
4382
   *
4383
   *  _GLIBCXX_RESOLVE_LIB_DEFECTS
4384
   *  DR 241. Does unique_copy() require CopyConstructible and Assignable?
4385
  */
4386
  template<typename _InputIterator, typename _OutputIterator,
4387
	   typename _BinaryPredicate>
4388
    inline _OutputIterator
4389
    unique_copy(_InputIterator __first, _InputIterator __last,
4390
		_OutputIterator __result,
4391
		_BinaryPredicate __binary_pred)
4392
    {
4393
      // concept requirements -- predicates checked later
4394
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
4395
      __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4396
	    typename iterator_traits<_InputIterator>::value_type>)
4397
      __glibcxx_requires_valid_range(__first, __last);
4398
4399
      if (__first == __last)
4400
	return __result;
4401
      return std::__unique_copy(__first, __last, __result,
4402
			__gnu_cxx::__ops::__iter_comp_iter(__binary_pred),
4403
				std::__iterator_category(__first),
4404
				std::__iterator_category(__result));
4405
    }
4406
4407
  /**
4408
   *  @brief Randomly shuffle the elements of a sequence.
4409
   *  @ingroup mutating_algorithms
4410
   *  @param  __first   A forward iterator.
4411
   *  @param  __last    A forward iterator.
4412
   *  @return  Nothing.
4413
   *
4414
   *  Reorder the elements in the range @p [__first,__last) using a random
4415
   *  distribution, so that every possible ordering of the sequence is
4416
   *  equally likely.
4417
  */
4418
  template<typename _RandomAccessIterator>
4419
    inline void
4420
    random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last)
4421
    {
4422
      // concept requirements
4423
      __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4424
	    _RandomAccessIterator>)
4425
      __glibcxx_requires_valid_range(__first, __last);
4426
4427
      if (__first != __last)
4428
	for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
4429
	  std::iter_swap(__i, __first + (std::rand() % ((__i - __first) + 1)));
4430
    }
4431
4432
  /**
4433
   *  @brief Shuffle the elements of a sequence using a random number
4434
   *         generator.
4435
   *  @ingroup mutating_algorithms
4436
   *  @param  __first   A forward iterator.
4437
   *  @param  __last    A forward iterator.
4438
   *  @param  __rand    The RNG functor or function.
4439
   *  @return  Nothing.
4440
   *
4441
   *  Reorders the elements in the range @p [__first,__last) using @p __rand to
4442
   *  provide a random distribution. Calling @p __rand(N) for a positive
4443
   *  integer @p N should return a randomly chosen integer from the
4444
   *  range [0,N).
4445
  */
4446
  template<typename _RandomAccessIterator, typename _RandomNumberGenerator>
4447
    void
4448
    random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last,
4449
#if __cplusplus >= 201103L
4450
		   _RandomNumberGenerator&& __rand)
4451
#else
4452
		   _RandomNumberGenerator& __rand)
4453
#endif
4454
    {
4455
      // concept requirements
4456
      __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4457
	    _RandomAccessIterator>)
4458
      __glibcxx_requires_valid_range(__first, __last);
4459
4460
      if (__first == __last)
4461
	return;
4462
      for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
4463
	std::iter_swap(__i, __first + __rand((__i - __first) + 1));
4464
    }
4465
4466
4467
  /**
4468
   *  @brief Move elements for which a predicate is true to the beginning
4469
   *         of a sequence.
4470
   *  @ingroup mutating_algorithms
4471
   *  @param  __first   A forward iterator.
4472
   *  @param  __last    A forward iterator.
4473
   *  @param  __pred    A predicate functor.
4474
   *  @return  An iterator @p middle such that @p __pred(i) is true for each
4475
   *  iterator @p i in the range @p [__first,middle) and false for each @p i
4476
   *  in the range @p [middle,__last).
4477
   *
4478
   *  @p __pred must not modify its operand. @p partition() does not preserve
4479
   *  the relative ordering of elements in each group, use
4480
   *  @p stable_partition() if this is needed.
4481
  */
4482
  template<typename _ForwardIterator, typename _Predicate>
4483
    inline _ForwardIterator
4484
    partition(_ForwardIterator __first, _ForwardIterator __last,
4485
	      _Predicate   __pred)
4486
    {
4487
      // concept requirements
4488
      __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
4489
				  _ForwardIterator>)
4490
      __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
4491
	    typename iterator_traits<_ForwardIterator>::value_type>)
4492
      __glibcxx_requires_valid_range(__first, __last);
4493
4494
      return std::__partition(__first, __last, __pred,
4495
			      std::__iterator_category(__first));
4496
    }
4497
4498
4499
  /**
4500
   *  @brief Sort the smallest elements of a sequence.
4501
   *  @ingroup sorting_algorithms
4502
   *  @param  __first   An iterator.
4503
   *  @param  __middle  Another iterator.
4504
   *  @param  __last    Another iterator.
4505
   *  @return  Nothing.
4506
   *
4507
   *  Sorts the smallest @p (__middle-__first) elements in the range
4508
   *  @p [first,last) and moves them to the range @p [__first,__middle). The
4509
   *  order of the remaining elements in the range @p [__middle,__last) is
4510
   *  undefined.
4511
   *  After the sort if @e i and @e j are iterators in the range
4512
   *  @p [__first,__middle) such that i precedes j and @e k is an iterator in
4513
   *  the range @p [__middle,__last) then *j<*i and *k<*i are both false.
4514
  */
4515
  template<typename _RandomAccessIterator>
4516
    inline void
4517
    partial_sort(_RandomAccessIterator __first,
4518
		 _RandomAccessIterator __middle,
4519
		 _RandomAccessIterator __last)
4520
    {
4521
      // concept requirements
4522
      __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4523
	    _RandomAccessIterator>)
4524
      __glibcxx_function_requires(_LessThanComparableConcept<
4525
	    typename iterator_traits<_RandomAccessIterator>::value_type>)
4526
      __glibcxx_requires_valid_range(__first, __middle);
4527
      __glibcxx_requires_valid_range(__middle, __last);
4528
4529
      std::__partial_sort(__first, __middle, __last,
4530
			  __gnu_cxx::__ops::__iter_less_iter());
4531
    }
4532
4533
  /**
4534
   *  @brief Sort the smallest elements of a sequence using a predicate
4535
   *         for comparison.
4536
   *  @ingroup sorting_algorithms
4537
   *  @param  __first   An iterator.
4538
   *  @param  __middle  Another iterator.
4539
   *  @param  __last    Another iterator.
4540
   *  @param  __comp    A comparison functor.
4541
   *  @return  Nothing.
4542
   *
4543
   *  Sorts the smallest @p (__middle-__first) elements in the range
4544
   *  @p [__first,__last) and moves them to the range @p [__first,__middle). The
4545
   *  order of the remaining elements in the range @p [__middle,__last) is
4546
   *  undefined.
4547
   *  After the sort if @e i and @e j are iterators in the range
4548
   *  @p [__first,__middle) such that i precedes j and @e k is an iterator in
4549
   *  the range @p [__middle,__last) then @p *__comp(j,*i) and @p __comp(*k,*i)
4550
   *  are both false.
4551
  */
4552
  template<typename _RandomAccessIterator, typename _Compare>
4553
    inline void
4554
    partial_sort(_RandomAccessIterator __first,
4555
		 _RandomAccessIterator __middle,
4556
		 _RandomAccessIterator __last,
4557
		 _Compare __comp)
4558
    {
4559
      // concept requirements
4560
      __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4561
	    _RandomAccessIterator>)
4562
      __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
4563
	    typename iterator_traits<_RandomAccessIterator>::value_type,
4564
	    typename iterator_traits<_RandomAccessIterator>::value_type>)
4565
      __glibcxx_requires_valid_range(__first, __middle);
4566
      __glibcxx_requires_valid_range(__middle, __last);
4567
4568
      std::__partial_sort(__first, __middle, __last,
4569
			  __gnu_cxx::__ops::__iter_comp_iter(__comp));
4570
    }
4571
4572
  /**
4573
   *  @brief Sort a sequence just enough to find a particular position.
4574
   *  @ingroup sorting_algorithms
4575
   *  @param  __first   An iterator.
4576
   *  @param  __nth     Another iterator.
4577
   *  @param  __last    Another iterator.
4578
   *  @return  Nothing.
4579
   *
4580
   *  Rearranges the elements in the range @p [__first,__last) so that @p *__nth
4581
   *  is the same element that would have been in that position had the
4582
   *  whole sequence been sorted. The elements either side of @p *__nth are
4583
   *  not completely sorted, but for any iterator @e i in the range
4584
   *  @p [__first,__nth) and any iterator @e j in the range @p [__nth,__last) it
4585
   *  holds that *j < *i is false.
4586
  */
4587
  template<typename _RandomAccessIterator>
4588
    inline void
4589
    nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth,
4590
		_RandomAccessIterator __last)
4591
    {
4592
      // concept requirements
4593
      __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4594
				  _RandomAccessIterator>)
4595
      __glibcxx_function_requires(_LessThanComparableConcept<
4596
	    typename iterator_traits<_RandomAccessIterator>::value_type>)
4597
      __glibcxx_requires_valid_range(__first, __nth);
4598
      __glibcxx_requires_valid_range(__nth, __last);
4599
4600
      if (__first == __last || __nth == __last)
4601
	return;
4602
4603
      std::__introselect(__first, __nth, __last,
4604
			 std::__lg(__last - __first) * 2,
4605
			 __gnu_cxx::__ops::__iter_less_iter());
4606
    }
4607
4608
  /**
4609
   *  @brief Sort a sequence just enough to find a particular position
4610
   *         using a predicate for comparison.
4611
   *  @ingroup sorting_algorithms
4612
   *  @param  __first   An iterator.
4613
   *  @param  __nth     Another iterator.
4614
   *  @param  __last    Another iterator.
4615
   *  @param  __comp    A comparison functor.
4616
   *  @return  Nothing.
4617
   *
4618
   *  Rearranges the elements in the range @p [__first,__last) so that @p *__nth
4619
   *  is the same element that would have been in that position had the
4620
   *  whole sequence been sorted. The elements either side of @p *__nth are
4621
   *  not completely sorted, but for any iterator @e i in the range
4622
   *  @p [__first,__nth) and any iterator @e j in the range @p [__nth,__last) it
4623
   *  holds that @p __comp(*j,*i) is false.
4624
  */
4625
  template<typename _RandomAccessIterator, typename _Compare>
4626
    inline void
4627
    nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth,
4628
		_RandomAccessIterator __last, _Compare __comp)
4629
    {
4630
      // concept requirements
4631
      __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4632
				  _RandomAccessIterator>)
4633
      __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
4634
	    typename iterator_traits<_RandomAccessIterator>::value_type,
4635
	    typename iterator_traits<_RandomAccessIterator>::value_type>)
4636
      __glibcxx_requires_valid_range(__first, __nth);
4637
      __glibcxx_requires_valid_range(__nth, __last);
4638
4639
      if (__first == __last || __nth == __last)
4640
	return;
4641
4642
      std::__introselect(__first, __nth, __last,
4643
			 std::__lg(__last - __first) * 2,
4644
			 __gnu_cxx::__ops::__iter_comp_iter(__comp));
4645
    }
4646
4647
  /**
4648
   *  @brief Sort the elements of a sequence.
4649
   *  @ingroup sorting_algorithms
4650
   *  @param  __first   An iterator.
4651
   *  @param  __last    Another iterator.
4652
   *  @return  Nothing.
4653
   *
4654
   *  Sorts the elements in the range @p [__first,__last) in ascending order,
4655
   *  such that for each iterator @e i in the range @p [__first,__last-1),  
4656
   *  *(i+1)<*i is false.
4657
   *
4658
   *  The relative ordering of equivalent elements is not preserved, use
4659
   *  @p stable_sort() if this is needed.
4660
  */
4661
  template<typename _RandomAccessIterator>
4662
    inline void
4663
    sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
4664
    {
4665
      // concept requirements
4666
      __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4667
	    _RandomAccessIterator>)
4668
      __glibcxx_function_requires(_LessThanComparableConcept<
4669
	    typename iterator_traits<_RandomAccessIterator>::value_type>)
4670
      __glibcxx_requires_valid_range(__first, __last);
4671
4672
      std::__sort(__first, __last, __gnu_cxx::__ops::__iter_less_iter());
4673
    }
4674
4675
  /**
4676
   *  @brief Sort the elements of a sequence using a predicate for comparison.
4677
   *  @ingroup sorting_algorithms
4678
   *  @param  __first   An iterator.
4679
   *  @param  __last    Another iterator.
4680
   *  @param  __comp    A comparison functor.
4681
   *  @return  Nothing.
4682
   *
4683
   *  Sorts the elements in the range @p [__first,__last) in ascending order,
4684
   *  such that @p __comp(*(i+1),*i) is false for every iterator @e i in the
4685
   *  range @p [__first,__last-1).
4686
   *
4687
   *  The relative ordering of equivalent elements is not preserved, use
4688
   *  @p stable_sort() if this is needed.
4689
  */
4690
  template<typename _RandomAccessIterator, typename _Compare>
4691
    inline void
4692
    sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
4693
	 _Compare __comp)
4694
    {
4695
      // concept requirements
4696
      __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4697
	    _RandomAccessIterator>)
4698
      __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
4699
	    typename iterator_traits<_RandomAccessIterator>::value_type,
4700
	    typename iterator_traits<_RandomAccessIterator>::value_type>)
4701
      __glibcxx_requires_valid_range(__first, __last);
4702
4703
      std::__sort(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
4704
    }
4705
4706
  template<typename _InputIterator1, typename _InputIterator2,
4707
	   typename _OutputIterator, typename _Compare>
4708
    _OutputIterator
4709
    __merge(_InputIterator1 __first1, _InputIterator1 __last1,
4710
	    _InputIterator2 __first2, _InputIterator2 __last2,
4711
	    _OutputIterator __result, _Compare __comp)
4712
    {
4713
      while (__first1 != __last1 && __first2 != __last2)
4714
	{
4715
	  if (__comp(__first2, __first1))
4716
	    {
4717
	      *__result = *__first2;
4718
	      ++__first2;
4719
	    }
4720
	  else
4721
	    {
4722
	      *__result = *__first1;
4723
	      ++__first1;
4724
	    }
4725
	  ++__result;
4726
	}
4727
      return std::copy(__first2, __last2,
4728
		       std::copy(__first1, __last1, __result));
4729
    }
4730
4731
  /**
4732
   *  @brief Merges two sorted ranges.
4733
   *  @ingroup sorting_algorithms
4734
   *  @param  __first1  An iterator.
4735
   *  @param  __first2  Another iterator.
4736
   *  @param  __last1   Another iterator.
4737
   *  @param  __last2   Another iterator.
4738
   *  @param  __result  An iterator pointing to the end of the merged range.
4739
   *  @return         An iterator pointing to the first element <em>not less
4740
   *                  than</em> @e val.
4741
   *
4742
   *  Merges the ranges @p [__first1,__last1) and @p [__first2,__last2) into
4743
   *  the sorted range @p [__result, __result + (__last1-__first1) +
4744
   *  (__last2-__first2)).  Both input ranges must be sorted, and the
4745
   *  output range must not overlap with either of the input ranges.
4746
   *  The sort is @e stable, that is, for equivalent elements in the
4747
   *  two ranges, elements from the first range will always come
4748
   *  before elements from the second.
4749
  */
4750
  template<typename _InputIterator1, typename _InputIterator2,
4751
	   typename _OutputIterator>
4752
    inline _OutputIterator
4753
    merge(_InputIterator1 __first1, _InputIterator1 __last1,
4754
	  _InputIterator2 __first2, _InputIterator2 __last2,
4755
	  _OutputIterator __result)
4756
    {
4757
      // concept requirements
4758
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
4759
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
4760
      __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4761
	    typename iterator_traits<_InputIterator1>::value_type>)
4762
      __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4763
	    typename iterator_traits<_InputIterator2>::value_type>)
4764
      __glibcxx_function_requires(_LessThanOpConcept<
4765
	    typename iterator_traits<_InputIterator2>::value_type,
4766
	    typename iterator_traits<_InputIterator1>::value_type>)	
4767
      __glibcxx_requires_sorted_set(__first1, __last1, __first2);
4768
      __glibcxx_requires_sorted_set(__first2, __last2, __first1);
4769
4770
      return _GLIBCXX_STD_A::__merge(__first1, __last1,
4771
				     __first2, __last2, __result,
4772
				     __gnu_cxx::__ops::__iter_less_iter());
4773
    }
4774
4775
  /**
4776
   *  @brief Merges two sorted ranges.
4777
   *  @ingroup sorting_algorithms
4778
   *  @param  __first1  An iterator.
4779
   *  @param  __first2  Another iterator.
4780
   *  @param  __last1   Another iterator.
4781
   *  @param  __last2   Another iterator.
4782
   *  @param  __result  An iterator pointing to the end of the merged range.
4783
   *  @param  __comp    A functor to use for comparisons.
4784
   *  @return         An iterator pointing to the first element "not less
4785
   *                  than" @e val.
4786
   *
4787
   *  Merges the ranges @p [__first1,__last1) and @p [__first2,__last2) into
4788
   *  the sorted range @p [__result, __result + (__last1-__first1) +
4789
   *  (__last2-__first2)).  Both input ranges must be sorted, and the
4790
   *  output range must not overlap with either of the input ranges.
4791
   *  The sort is @e stable, that is, for equivalent elements in the
4792
   *  two ranges, elements from the first range will always come
4793
   *  before elements from the second.
4794
   *
4795
   *  The comparison function should have the same effects on ordering as
4796
   *  the function used for the initial sort.
4797
  */
4798
  template<typename _InputIterator1, typename _InputIterator2,
4799
	   typename _OutputIterator, typename _Compare>
4800
    inline _OutputIterator
4801
    merge(_InputIterator1 __first1, _InputIterator1 __last1,
4802
	  _InputIterator2 __first2, _InputIterator2 __last2,
4803
	  _OutputIterator __result, _Compare __comp)
4804
    {
4805
      // concept requirements
4806
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
4807
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
4808
      __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4809
	    typename iterator_traits<_InputIterator1>::value_type>)
4810
      __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4811
	    typename iterator_traits<_InputIterator2>::value_type>)
4812
      __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
4813
	    typename iterator_traits<_InputIterator2>::value_type,
4814
	    typename iterator_traits<_InputIterator1>::value_type>)
4815
      __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
4816
      __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
4817
4818
      return _GLIBCXX_STD_A::__merge(__first1, __last1,
4819
				__first2, __last2, __result,
4820
				__gnu_cxx::__ops::__iter_comp_iter(__comp));
4821
    }
4822
4823
  template<typename _RandomAccessIterator, typename _Compare>
4824
    inline void
4825
    __stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
4826
		  _Compare __comp)
4827
    {
4828
      typedef typename iterator_traits<_RandomAccessIterator>::value_type
4829
	_ValueType;
4830
      typedef typename iterator_traits<_RandomAccessIterator>::difference_type
4831
	_DistanceType;
4832
4833
      typedef _Temporary_buffer<_RandomAccessIterator, _ValueType> _TmpBuf;
4834
      _TmpBuf __buf(__first, __last);
4835
4836
      if (__buf.begin() == 0)
4837
	std::__inplace_stable_sort(__first, __last, __comp);
4838
      else
4839
	std::__stable_sort_adaptive(__first, __last, __buf.begin(),
4840
				    _DistanceType(__buf.size()), __comp);
4841
    }
4842
4843
  /**
4844
   *  @brief Sort the elements of a sequence, preserving the relative order
4845
   *         of equivalent elements.
4846
   *  @ingroup sorting_algorithms
4847
   *  @param  __first   An iterator.
4848
   *  @param  __last    Another iterator.
4849
   *  @return  Nothing.
4850
   *
4851
   *  Sorts the elements in the range @p [__first,__last) in ascending order,
4852
   *  such that for each iterator @p i in the range @p [__first,__last-1),
4853
   *  @p *(i+1)<*i is false.
4854
   *
4855
   *  The relative ordering of equivalent elements is preserved, so any two
4856
   *  elements @p x and @p y in the range @p [__first,__last) such that
4857
   *  @p x<y is false and @p y<x is false will have the same relative
4858
   *  ordering after calling @p stable_sort().
4859
  */
4860
  template<typename _RandomAccessIterator>
4861
    inline void
4862
    stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
4863
    {
4864
      // concept requirements
4865
      __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4866
	    _RandomAccessIterator>)
4867
      __glibcxx_function_requires(_LessThanComparableConcept<
4868
	    typename iterator_traits<_RandomAccessIterator>::value_type>)
4869
      __glibcxx_requires_valid_range(__first, __last);
4870
4871
      _GLIBCXX_STD_A::__stable_sort(__first, __last,
4872
				    __gnu_cxx::__ops::__iter_less_iter());
4873
    }
4874
4875
  /**
4876
   *  @brief Sort the elements of a sequence using a predicate for comparison,
4877
   *         preserving the relative order of equivalent elements.
4878
   *  @ingroup sorting_algorithms
4879
   *  @param  __first   An iterator.
4880
   *  @param  __last    Another iterator.
4881
   *  @param  __comp    A comparison functor.
4882
   *  @return  Nothing.
4883
   *
4884
   *  Sorts the elements in the range @p [__first,__last) in ascending order,
4885
   *  such that for each iterator @p i in the range @p [__first,__last-1),
4886
   *  @p __comp(*(i+1),*i) is false.
4887
   *
4888
   *  The relative ordering of equivalent elements is preserved, so any two
4889
   *  elements @p x and @p y in the range @p [__first,__last) such that
4890
   *  @p __comp(x,y) is false and @p __comp(y,x) is false will have the same
4891
   *  relative ordering after calling @p stable_sort().
4892
  */
4893
  template<typename _RandomAccessIterator, typename _Compare>
4894
    inline void
4895
    stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
4896
		_Compare __comp)
4897
    {
4898
      // concept requirements
4899
      __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
4900
	    _RandomAccessIterator>)
4901
      __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
4902
	    typename iterator_traits<_RandomAccessIterator>::value_type,
4903
	    typename iterator_traits<_RandomAccessIterator>::value_type>)
4904
      __glibcxx_requires_valid_range(__first, __last);
4905
4906
      _GLIBCXX_STD_A::__stable_sort(__first, __last,
4907
				    __gnu_cxx::__ops::__iter_comp_iter(__comp));
4908
    }
4909
4910
  template<typename _InputIterator1, typename _InputIterator2,
4911
	   typename _OutputIterator,
4912
	   typename _Compare>
4913
    _OutputIterator
4914
    __set_union(_InputIterator1 __first1, _InputIterator1 __last1,
4915
		_InputIterator2 __first2, _InputIterator2 __last2,
4916
		_OutputIterator __result, _Compare __comp)
4917
    {
4918
      while (__first1 != __last1 && __first2 != __last2)
4919
	{
4920
	  if (__comp(__first1, __first2))
4921
	    {
4922
	      *__result = *__first1;
4923
	      ++__first1;
4924
	    }
4925
	  else if (__comp(__first2, __first1))
4926
	    {
4927
	      *__result = *__first2;
4928
	      ++__first2;
4929
	    }
4930
	  else
4931
	    {
4932
	      *__result = *__first1;
4933
	      ++__first1;
4934
	      ++__first2;
4935
	    }
4936
	  ++__result;
4937
	}
4938
      return std::copy(__first2, __last2,
4939
		       std::copy(__first1, __last1, __result));
4940
    }
4941
4942
  /**
4943
   *  @brief Return the union of two sorted ranges.
4944
   *  @ingroup set_algorithms
4945
   *  @param  __first1  Start of first range.
4946
   *  @param  __last1   End of first range.
4947
   *  @param  __first2  Start of second range.
4948
   *  @param  __last2   End of second range.
4949
   *  @return  End of the output range.
4950
   *  @ingroup set_algorithms
4951
   *
4952
   *  This operation iterates over both ranges, copying elements present in
4953
   *  each range in order to the output range.  Iterators increment for each
4954
   *  range.  When the current element of one range is less than the other,
4955
   *  that element is copied and the iterator advanced.  If an element is
4956
   *  contained in both ranges, the element from the first range is copied and
4957
   *  both ranges advance.  The output range may not overlap either input
4958
   *  range.
4959
  */
4960
  template<typename _InputIterator1, typename _InputIterator2,
4961
	   typename _OutputIterator>
4962
    inline _OutputIterator
4963
    set_union(_InputIterator1 __first1, _InputIterator1 __last1,
4964
	      _InputIterator2 __first2, _InputIterator2 __last2,
4965
	      _OutputIterator __result)
4966
    {
4967
      // concept requirements
4968
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
4969
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
4970
      __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4971
	    typename iterator_traits<_InputIterator1>::value_type>)
4972
      __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
4973
	    typename iterator_traits<_InputIterator2>::value_type>)
4974
      __glibcxx_function_requires(_LessThanOpConcept<
4975
	    typename iterator_traits<_InputIterator1>::value_type,
4976
	    typename iterator_traits<_InputIterator2>::value_type>)
4977
      __glibcxx_function_requires(_LessThanOpConcept<
4978
	    typename iterator_traits<_InputIterator2>::value_type,
4979
	    typename iterator_traits<_InputIterator1>::value_type>)
4980
      __glibcxx_requires_sorted_set(__first1, __last1, __first2);
4981
      __glibcxx_requires_sorted_set(__first2, __last2, __first1);
4982
4983
      return _GLIBCXX_STD_A::__set_union(__first1, __last1,
4984
				__first2, __last2, __result,
4985
				__gnu_cxx::__ops::__iter_less_iter());
4986
    }
4987
4988
  /**
4989
   *  @brief Return the union of two sorted ranges using a comparison functor.
4990
   *  @ingroup set_algorithms
4991
   *  @param  __first1  Start of first range.
4992
   *  @param  __last1   End of first range.
4993
   *  @param  __first2  Start of second range.
4994
   *  @param  __last2   End of second range.
4995
   *  @param  __comp    The comparison functor.
4996
   *  @return  End of the output range.
4997
   *  @ingroup set_algorithms
4998
   *
4999
   *  This operation iterates over both ranges, copying elements present in
5000
   *  each range in order to the output range.  Iterators increment for each
5001
   *  range.  When the current element of one range is less than the other
5002
   *  according to @p __comp, that element is copied and the iterator advanced.
5003
   *  If an equivalent element according to @p __comp is contained in both
5004
   *  ranges, the element from the first range is copied and both ranges
5005
   *  advance.  The output range may not overlap either input range.
5006
  */
5007
  template<typename _InputIterator1, typename _InputIterator2,
5008
	   typename _OutputIterator, typename _Compare>
5009
    inline _OutputIterator
5010
    set_union(_InputIterator1 __first1, _InputIterator1 __last1,
5011
	      _InputIterator2 __first2, _InputIterator2 __last2,
5012
	      _OutputIterator __result, _Compare __comp)
5013
    {
5014
      // concept requirements
5015
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5016
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5017
      __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5018
	    typename iterator_traits<_InputIterator1>::value_type>)
5019
      __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5020
	    typename iterator_traits<_InputIterator2>::value_type>)
5021
      __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5022
	    typename iterator_traits<_InputIterator1>::value_type,
5023
	    typename iterator_traits<_InputIterator2>::value_type>)
5024
      __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5025
	    typename iterator_traits<_InputIterator2>::value_type,
5026
	    typename iterator_traits<_InputIterator1>::value_type>)
5027
      __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
5028
      __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
5029
5030
      return _GLIBCXX_STD_A::__set_union(__first1, __last1,
5031
				__first2, __last2, __result,
5032
				__gnu_cxx::__ops::__iter_comp_iter(__comp));
5033
    }
5034
5035
  template<typename _InputIterator1, typename _InputIterator2,
5036
	   typename _OutputIterator,
5037
	   typename _Compare>
5038
    _OutputIterator
5039
    __set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
5040
		       _InputIterator2 __first2, _InputIterator2 __last2,
5041
		       _OutputIterator __result, _Compare __comp)
5042
    {
5043
      while (__first1 != __last1 && __first2 != __last2)
5044
	if (__comp(__first1, __first2))
5045
	  ++__first1;
5046
	else if (__comp(__first2, __first1))
5047
	  ++__first2;
5048
	else
5049
	  {
5050
	    *__result = *__first1;
5051
	    ++__first1;
5052
	    ++__first2;
5053
	    ++__result;
5054
	  }
5055
      return __result;
5056
    }
5057
5058
  /**
5059
   *  @brief Return the intersection of two sorted ranges.
5060
   *  @ingroup set_algorithms
5061
   *  @param  __first1  Start of first range.
5062
   *  @param  __last1   End of first range.
5063
   *  @param  __first2  Start of second range.
5064
   *  @param  __last2   End of second range.
5065
   *  @return  End of the output range.
5066
   *  @ingroup set_algorithms
5067
   *
5068
   *  This operation iterates over both ranges, copying elements present in
5069
   *  both ranges in order to the output range.  Iterators increment for each
5070
   *  range.  When the current element of one range is less than the other,
5071
   *  that iterator advances.  If an element is contained in both ranges, the
5072
   *  element from the first range is copied and both ranges advance.  The
5073
   *  output range may not overlap either input range.
5074
  */
5075
  template<typename _InputIterator1, typename _InputIterator2,
5076
	   typename _OutputIterator>
5077
    inline _OutputIterator
5078
    set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
5079
		     _InputIterator2 __first2, _InputIterator2 __last2,
5080
		     _OutputIterator __result)
5081
    {
5082
      // concept requirements
5083
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5084
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5085
      __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5086
	    typename iterator_traits<_InputIterator1>::value_type>)
5087
      __glibcxx_function_requires(_LessThanOpConcept<
5088
	    typename iterator_traits<_InputIterator1>::value_type,
5089
	    typename iterator_traits<_InputIterator2>::value_type>)
5090
      __glibcxx_function_requires(_LessThanOpConcept<
5091
	    typename iterator_traits<_InputIterator2>::value_type,
5092
	    typename iterator_traits<_InputIterator1>::value_type>)
5093
      __glibcxx_requires_sorted_set(__first1, __last1, __first2);
5094
      __glibcxx_requires_sorted_set(__first2, __last2, __first1);
5095
5096
      return _GLIBCXX_STD_A::__set_intersection(__first1, __last1,
5097
				     __first2, __last2, __result,
5098
				     __gnu_cxx::__ops::__iter_less_iter());
5099
    }
5100
5101
  /**
5102
   *  @brief Return the intersection of two sorted ranges using comparison
5103
   *  functor.
5104
   *  @ingroup set_algorithms
5105
   *  @param  __first1  Start of first range.
5106
   *  @param  __last1   End of first range.
5107
   *  @param  __first2  Start of second range.
5108
   *  @param  __last2   End of second range.
5109
   *  @param  __comp    The comparison functor.
5110
   *  @return  End of the output range.
5111
   *  @ingroup set_algorithms
5112
   *
5113
   *  This operation iterates over both ranges, copying elements present in
5114
   *  both ranges in order to the output range.  Iterators increment for each
5115
   *  range.  When the current element of one range is less than the other
5116
   *  according to @p __comp, that iterator advances.  If an element is
5117
   *  contained in both ranges according to @p __comp, the element from the
5118
   *  first range is copied and both ranges advance.  The output range may not
5119
   *  overlap either input range.
5120
  */
5121
  template<typename _InputIterator1, typename _InputIterator2,
5122
	   typename _OutputIterator, typename _Compare>
5123
    inline _OutputIterator
5124
    set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
5125
		     _InputIterator2 __first2, _InputIterator2 __last2,
5126
		     _OutputIterator __result, _Compare __comp)
5127
    {
5128
      // concept requirements
5129
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5130
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5131
      __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5132
	    typename iterator_traits<_InputIterator1>::value_type>)
5133
      __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5134
	    typename iterator_traits<_InputIterator1>::value_type,
5135
	    typename iterator_traits<_InputIterator2>::value_type>)
5136
      __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5137
	    typename iterator_traits<_InputIterator2>::value_type,
5138
	    typename iterator_traits<_InputIterator1>::value_type>)
5139
      __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
5140
      __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
5141
5142
      return _GLIBCXX_STD_A::__set_intersection(__first1, __last1,
5143
				__first2, __last2, __result,
5144
				__gnu_cxx::__ops::__iter_comp_iter(__comp));
5145
    }
5146
5147
  template<typename _InputIterator1, typename _InputIterator2,
5148
	   typename _OutputIterator,
5149
	   typename _Compare>
5150
    _OutputIterator
5151
    __set_difference(_InputIterator1 __first1, _InputIterator1 __last1,
5152
		     _InputIterator2 __first2, _InputIterator2 __last2,
5153
		     _OutputIterator __result, _Compare __comp)
5154
    {
5155
      while (__first1 != __last1 && __first2 != __last2)
5156
	if (__comp(__first1, __first2))
5157
	  {
5158
	    *__result = *__first1;
5159
	    ++__first1;
5160
	    ++__result;
5161
	  }
5162
	else if (__comp(__first2, __first1))
5163
	  ++__first2;
5164
	else
5165
	  {
5166
	    ++__first1;
5167
	    ++__first2;
5168
	  }
5169
      return std::copy(__first1, __last1, __result);
5170
    }
5171
5172
  /**
5173
   *  @brief Return the difference of two sorted ranges.
5174
   *  @ingroup set_algorithms
5175
   *  @param  __first1  Start of first range.
5176
   *  @param  __last1   End of first range.
5177
   *  @param  __first2  Start of second range.
5178
   *  @param  __last2   End of second range.
5179
   *  @return  End of the output range.
5180
   *  @ingroup set_algorithms
5181
   *
5182
   *  This operation iterates over both ranges, copying elements present in
5183
   *  the first range but not the second in order to the output range.
5184
   *  Iterators increment for each range.  When the current element of the
5185
   *  first range is less than the second, that element is copied and the
5186
   *  iterator advances.  If the current element of the second range is less,
5187
   *  the iterator advances, but no element is copied.  If an element is
5188
   *  contained in both ranges, no elements are copied and both ranges
5189
   *  advance.  The output range may not overlap either input range.
5190
  */
5191
  template<typename _InputIterator1, typename _InputIterator2,
5192
	   typename _OutputIterator>
5193
    inline _OutputIterator
5194
    set_difference(_InputIterator1 __first1, _InputIterator1 __last1,
5195
		   _InputIterator2 __first2, _InputIterator2 __last2,
5196
		   _OutputIterator __result)
5197
    {
5198
      // concept requirements
5199
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5200
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5201
      __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5202
	    typename iterator_traits<_InputIterator1>::value_type>)
5203
      __glibcxx_function_requires(_LessThanOpConcept<
5204
	    typename iterator_traits<_InputIterator1>::value_type,
5205
	    typename iterator_traits<_InputIterator2>::value_type>)
5206
      __glibcxx_function_requires(_LessThanOpConcept<
5207
	    typename iterator_traits<_InputIterator2>::value_type,
5208
	    typename iterator_traits<_InputIterator1>::value_type>)	
5209
      __glibcxx_requires_sorted_set(__first1, __last1, __first2);
5210
      __glibcxx_requires_sorted_set(__first2, __last2, __first1);
5211
5212
      return _GLIBCXX_STD_A::__set_difference(__first1, __last1,
5213
				   __first2, __last2, __result,
5214
				   __gnu_cxx::__ops::__iter_less_iter());
5215
    }
5216
5217
  /**
5218
   *  @brief  Return the difference of two sorted ranges using comparison
5219
   *  functor.
5220
   *  @ingroup set_algorithms
5221
   *  @param  __first1  Start of first range.
5222
   *  @param  __last1   End of first range.
5223
   *  @param  __first2  Start of second range.
5224
   *  @param  __last2   End of second range.
5225
   *  @param  __comp    The comparison functor.
5226
   *  @return  End of the output range.
5227
   *  @ingroup set_algorithms
5228
   *
5229
   *  This operation iterates over both ranges, copying elements present in
5230
   *  the first range but not the second in order to the output range.
5231
   *  Iterators increment for each range.  When the current element of the
5232
   *  first range is less than the second according to @p __comp, that element
5233
   *  is copied and the iterator advances.  If the current element of the
5234
   *  second range is less, no element is copied and the iterator advances.
5235
   *  If an element is contained in both ranges according to @p __comp, no
5236
   *  elements are copied and both ranges advance.  The output range may not
5237
   *  overlap either input range.
5238
  */
5239
  template<typename _InputIterator1, typename _InputIterator2,
5240
	   typename _OutputIterator, typename _Compare>
5241
    inline _OutputIterator
5242
    set_difference(_InputIterator1 __first1, _InputIterator1 __last1,
5243
		   _InputIterator2 __first2, _InputIterator2 __last2,
5244
		   _OutputIterator __result, _Compare __comp)
5245
    {
5246
      // concept requirements
5247
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5248
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5249
      __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5250
	    typename iterator_traits<_InputIterator1>::value_type>)
5251
      __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5252
	    typename iterator_traits<_InputIterator1>::value_type,
5253
	    typename iterator_traits<_InputIterator2>::value_type>)
5254
      __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5255
	    typename iterator_traits<_InputIterator2>::value_type,
5256
	    typename iterator_traits<_InputIterator1>::value_type>)
5257
      __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
5258
      __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
5259
5260
      return _GLIBCXX_STD_A::__set_difference(__first1, __last1,
5261
				   __first2, __last2, __result,
5262
				   __gnu_cxx::__ops::__iter_comp_iter(__comp));
5263
    }
5264
5265
  template<typename _InputIterator1, typename _InputIterator2,
5266
	   typename _OutputIterator,
5267
	   typename _Compare>
5268
    _OutputIterator
5269
    __set_symmetric_difference(_InputIterator1 __first1,
5270
			       _InputIterator1 __last1,
5271
			       _InputIterator2 __first2,
5272
			       _InputIterator2 __last2,
5273
			       _OutputIterator __result,
5274
			       _Compare __comp)
5275
    {
5276
      while (__first1 != __last1 && __first2 != __last2)
5277
	if (__comp(__first1, __first2))
5278
	  {
5279
	    *__result = *__first1;
5280
	    ++__first1;
5281
	    ++__result;
5282
	  }
5283
	else if (__comp(__first2, __first1))
5284
	  {
5285
	    *__result = *__first2;
5286
	    ++__first2;
5287
	    ++__result;
5288
	  }
5289
	else
5290
	  {
5291
	    ++__first1;
5292
	    ++__first2;
5293
	  }
5294
      return std::copy(__first2, __last2, 
5295
		       std::copy(__first1, __last1, __result));
5296
    }
5297
5298
  /**
5299
   *  @brief  Return the symmetric difference of two sorted ranges.
5300
   *  @ingroup set_algorithms
5301
   *  @param  __first1  Start of first range.
5302
   *  @param  __last1   End of first range.
5303
   *  @param  __first2  Start of second range.
5304
   *  @param  __last2   End of second range.
5305
   *  @return  End of the output range.
5306
   *  @ingroup set_algorithms
5307
   *
5308
   *  This operation iterates over both ranges, copying elements present in
5309
   *  one range but not the other in order to the output range.  Iterators
5310
   *  increment for each range.  When the current element of one range is less
5311
   *  than the other, that element is copied and the iterator advances.  If an
5312
   *  element is contained in both ranges, no elements are copied and both
5313
   *  ranges advance.  The output range may not overlap either input range.
5314
  */
5315
  template<typename _InputIterator1, typename _InputIterator2,
5316
	   typename _OutputIterator>
5317
    inline _OutputIterator
5318
    set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1,
5319
			     _InputIterator2 __first2, _InputIterator2 __last2,
5320
			     _OutputIterator __result)
5321
    {
5322
      // concept requirements
5323
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5324
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5325
      __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5326
	    typename iterator_traits<_InputIterator1>::value_type>)
5327
      __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5328
	    typename iterator_traits<_InputIterator2>::value_type>)
5329
      __glibcxx_function_requires(_LessThanOpConcept<
5330
	    typename iterator_traits<_InputIterator1>::value_type,
5331
	    typename iterator_traits<_InputIterator2>::value_type>)
5332
      __glibcxx_function_requires(_LessThanOpConcept<
5333
	    typename iterator_traits<_InputIterator2>::value_type,
5334
	    typename iterator_traits<_InputIterator1>::value_type>)	
5335
      __glibcxx_requires_sorted_set(__first1, __last1, __first2);
5336
      __glibcxx_requires_sorted_set(__first2, __last2, __first1);
5337
5338
      return _GLIBCXX_STD_A::__set_symmetric_difference(__first1, __last1,
5339
					__first2, __last2, __result,
5340
					__gnu_cxx::__ops::__iter_less_iter());
5341
    }
5342
5343
  /**
5344
   *  @brief  Return the symmetric difference of two sorted ranges using
5345
   *  comparison functor.
5346
   *  @ingroup set_algorithms
5347
   *  @param  __first1  Start of first range.
5348
   *  @param  __last1   End of first range.
5349
   *  @param  __first2  Start of second range.
5350
   *  @param  __last2   End of second range.
5351
   *  @param  __comp    The comparison functor.
5352
   *  @return  End of the output range.
5353
   *  @ingroup set_algorithms
5354
   *
5355
   *  This operation iterates over both ranges, copying elements present in
5356
   *  one range but not the other in order to the output range.  Iterators
5357
   *  increment for each range.  When the current element of one range is less
5358
   *  than the other according to @p comp, that element is copied and the
5359
   *  iterator advances.  If an element is contained in both ranges according
5360
   *  to @p __comp, no elements are copied and both ranges advance.  The output
5361
   *  range may not overlap either input range.
5362
  */
5363
  template<typename _InputIterator1, typename _InputIterator2,
5364
	   typename _OutputIterator, typename _Compare>
5365
    inline _OutputIterator
5366
    set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1,
5367
			     _InputIterator2 __first2, _InputIterator2 __last2,
5368
			     _OutputIterator __result,
5369
			     _Compare __comp)
5370
    {
5371
      // concept requirements
5372
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
5373
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
5374
      __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5375
	    typename iterator_traits<_InputIterator1>::value_type>)
5376
      __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
5377
	    typename iterator_traits<_InputIterator2>::value_type>)
5378
      __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5379
	    typename iterator_traits<_InputIterator1>::value_type,
5380
	    typename iterator_traits<_InputIterator2>::value_type>)
5381
      __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5382
	    typename iterator_traits<_InputIterator2>::value_type,
5383
	    typename iterator_traits<_InputIterator1>::value_type>)
5384
      __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
5385
      __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
5386
5387
      return _GLIBCXX_STD_A::__set_symmetric_difference(__first1, __last1,
5388
				__first2, __last2, __result,
5389
				__gnu_cxx::__ops::__iter_comp_iter(__comp));
5390
    }
5391
5392
  template<typename _ForwardIterator, typename _Compare>
5393
    _ForwardIterator
5394
    __min_element(_ForwardIterator __first, _ForwardIterator __last,
5395
		  _Compare __comp)
5396
    {
5397
      if (__first == __last)
5398
	return __first;
5399
      _ForwardIterator __result = __first;
5400
      while (++__first != __last)
5401
	if (__comp(__first, __result))
5402
	  __result = __first;
5403
      return __result;
5404
    }
5405
5406
  /**
5407
   *  @brief  Return the minimum element in a range.
5408
   *  @ingroup sorting_algorithms
5409
   *  @param  __first  Start of range.
5410
   *  @param  __last   End of range.
5411
   *  @return  Iterator referencing the first instance of the smallest value.
5412
  */
5413
  template<typename _ForwardIterator>
5414
    _ForwardIterator
5415
    inline min_element(_ForwardIterator __first, _ForwardIterator __last)
5416
    {
5417
      // concept requirements
5418
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
5419
      __glibcxx_function_requires(_LessThanComparableConcept<
5420
	    typename iterator_traits<_ForwardIterator>::value_type>)
5421
      __glibcxx_requires_valid_range(__first, __last);
5422
5423
      return _GLIBCXX_STD_A::__min_element(__first, __last,
5424
				__gnu_cxx::__ops::__iter_less_iter());
5425
    }
5426
5427
  /**
5428
   *  @brief  Return the minimum element in a range using comparison functor.
5429
   *  @ingroup sorting_algorithms
5430
   *  @param  __first  Start of range.
5431
   *  @param  __last   End of range.
5432
   *  @param  __comp   Comparison functor.
5433
   *  @return  Iterator referencing the first instance of the smallest value
5434
   *  according to __comp.
5435
  */
5436
  template<typename _ForwardIterator, typename _Compare>
5437
    inline _ForwardIterator
5438
    min_element(_ForwardIterator __first, _ForwardIterator __last,
5439
		_Compare __comp)
5440
    {
5441
      // concept requirements
5442
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
5443
      __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5444
	    typename iterator_traits<_ForwardIterator>::value_type,
5445
	    typename iterator_traits<_ForwardIterator>::value_type>)
5446
      __glibcxx_requires_valid_range(__first, __last);
5447
5448
      return _GLIBCXX_STD_A::__min_element(__first, __last,
5449
				__gnu_cxx::__ops::__iter_comp_iter(__comp));
5450
    }
5451
5452
  template<typename _ForwardIterator, typename _Compare>
5453
    _ForwardIterator
5454
    __max_element(_ForwardIterator __first, _ForwardIterator __last,
5455
		  _Compare __comp)
5456
    {
5457
      if (__first == __last) return __first;
5458
      _ForwardIterator __result = __first;
5459
      while (++__first != __last)
5460
	if (__comp(__result, __first))
5461
	  __result = __first;
5462
      return __result;
5463
    }
5464
5465
  /**
5466
   *  @brief  Return the maximum element in a range.
5467
   *  @ingroup sorting_algorithms
5468
   *  @param  __first  Start of range.
5469
   *  @param  __last   End of range.
5470
   *  @return  Iterator referencing the first instance of the largest value.
5471
  */
5472
  template<typename _ForwardIterator>
5473
    inline _ForwardIterator
5474
    max_element(_ForwardIterator __first, _ForwardIterator __last)
5475
    {
5476
      // concept requirements
5477
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
5478
      __glibcxx_function_requires(_LessThanComparableConcept<
5479
	    typename iterator_traits<_ForwardIterator>::value_type>)
5480
      __glibcxx_requires_valid_range(__first, __last);
5481
5482
      return _GLIBCXX_STD_A::__max_element(__first, __last,
5483
				__gnu_cxx::__ops::__iter_less_iter());
5484
    }
5485
5486
  /**
5487
   *  @brief  Return the maximum element in a range using comparison functor.
5488
   *  @ingroup sorting_algorithms
5489
   *  @param  __first  Start of range.
5490
   *  @param  __last   End of range.
5491
   *  @param  __comp   Comparison functor.
5492
   *  @return  Iterator referencing the first instance of the largest value
5493
   *  according to __comp.
5494
  */
5495
  template<typename _ForwardIterator, typename _Compare>
5496
    inline _ForwardIterator
5497
    max_element(_ForwardIterator __first, _ForwardIterator __last,
5498
		_Compare __comp)
5499
    {
5500
      // concept requirements
5501
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
5502
      __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
5503
	    typename iterator_traits<_ForwardIterator>::value_type,
5504
	    typename iterator_traits<_ForwardIterator>::value_type>)
5505
      __glibcxx_requires_valid_range(__first, __last);
5506
5507
      return _GLIBCXX_STD_A::__max_element(__first, __last,
5508
				__gnu_cxx::__ops::__iter_comp_iter(__comp));
5509
    }
5510
5511
_GLIBCXX_END_NAMESPACE_ALGO
5512
} // namespace std
5513
5514
#endif /* _STL_ALGO_H */
(-)GCC_XML/Support/GCC/4.9/bits/stl_algobase.h (+1422 lines)
Line 0 Link Here
1
// Core algorithmic facilities -*- C++ -*-
2
3
// Copyright (C) 2001-2014 Free Software Foundation, Inc.
4
//
5
// This file is part of the GNU ISO C++ Library.  This library is free
6
// software; you can redistribute it and/or modify it under the
7
// terms of the GNU General Public License as published by the
8
// Free Software Foundation; either version 3, or (at your option)
9
// any later version.
10
11
// This library is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
// GNU General Public License for more details.
15
16
// Under Section 7 of GPL version 3, you are granted additional
17
// permissions described in the GCC Runtime Library Exception, version
18
// 3.1, as published by the Free Software Foundation.
19
20
// You should have received a copy of the GNU General Public License and
21
// a copy of the GCC Runtime Library Exception along with this program;
22
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23
// <http://www.gnu.org/licenses/>.
24
25
/*
26
 *
27
 * Copyright (c) 1994
28
 * Hewlett-Packard Company
29
 *
30
 * Permission to use, copy, modify, distribute and sell this software
31
 * and its documentation for any purpose is hereby granted without fee,
32
 * provided that the above copyright notice appear in all copies and
33
 * that both that copyright notice and this permission notice appear
34
 * in supporting documentation.  Hewlett-Packard Company makes no
35
 * representations about the suitability of this software for any
36
 * purpose.  It is provided "as is" without express or implied warranty.
37
 *
38
 *
39
 * Copyright (c) 1996-1998
40
 * Silicon Graphics Computer Systems, Inc.
41
 *
42
 * Permission to use, copy, modify, distribute and sell this software
43
 * and its documentation for any purpose is hereby granted without fee,
44
 * provided that the above copyright notice appear in all copies and
45
 * that both that copyright notice and this permission notice appear
46
 * in supporting documentation.  Silicon Graphics makes no
47
 * representations about the suitability of this software for any
48
 * purpose.  It is provided "as is" without express or implied warranty.
49
 */
50
51
/** @file bits/stl_algobase.h
52
 *  This is an internal header file, included by other library headers.
53
 *  Do not attempt to use it directly. @headername{algorithm}
54
 */
55
56
#ifndef _STL_ALGOBASE_H
57
#define _STL_ALGOBASE_H 1
58
59
#include <bits/c++config.h>
60
#include <bits/functexcept.h>
61
#include <bits/cpp_type_traits.h>
62
#include <ext/type_traits.h>
63
#include <ext/numeric_traits.h>
64
#include <bits/stl_pair.h>
65
#include <bits/stl_iterator_base_types.h>
66
#include <bits/stl_iterator_base_funcs.h>
67
#include <bits/stl_iterator.h>
68
#include <bits/concept_check.h>
69
#include <debug/debug.h>
70
#include <bits/move.h> // For std::swap and _GLIBCXX_MOVE
71
#include <bits/predefined_ops.h>
72
73
namespace std _GLIBCXX_VISIBILITY(default)
74
{
75
_GLIBCXX_BEGIN_NAMESPACE_VERSION
76
77
#if __cplusplus < 201103L
78
  // See http://gcc.gnu.org/ml/libstdc++/2004-08/msg00167.html: in a
79
  // nutshell, we are partially implementing the resolution of DR 187,
80
  // when it's safe, i.e., the value_types are equal.
81
  template<bool _BoolType>
82
    struct __iter_swap
83
    {
84
      template<typename _ForwardIterator1, typename _ForwardIterator2>
85
        static void
86
        iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
87
        {
88
          typedef typename iterator_traits<_ForwardIterator1>::value_type
89
            _ValueType1;
90
          _ValueType1 __tmp = _GLIBCXX_MOVE(*__a);
91
          *__a = _GLIBCXX_MOVE(*__b);
92
          *__b = _GLIBCXX_MOVE(__tmp);
93
	}
94
    };
95
96
  template<>
97
    struct __iter_swap<true>
98
    {
99
      template<typename _ForwardIterator1, typename _ForwardIterator2>
100
        static void 
101
        iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
102
        {
103
          swap(*__a, *__b);
104
        }
105
    };
106
#endif
107
108
  /**
109
   *  @brief Swaps the contents of two iterators.
110
   *  @ingroup mutating_algorithms
111
   *  @param  __a  An iterator.
112
   *  @param  __b  Another iterator.
113
   *  @return   Nothing.
114
   *
115
   *  This function swaps the values pointed to by two iterators, not the
116
   *  iterators themselves.
117
  */
118
  template<typename _ForwardIterator1, typename _ForwardIterator2>
119
    inline void
120
    iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
121
    {
122
      // concept requirements
123
      __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
124
				  _ForwardIterator1>)
125
      __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
126
				  _ForwardIterator2>)
127
128
#if __cplusplus < 201103L
129
      typedef typename iterator_traits<_ForwardIterator1>::value_type
130
	_ValueType1;
131
      typedef typename iterator_traits<_ForwardIterator2>::value_type
132
	_ValueType2;
133
134
      __glibcxx_function_requires(_ConvertibleConcept<_ValueType1,
135
				  _ValueType2>)
136
      __glibcxx_function_requires(_ConvertibleConcept<_ValueType2,
137
				  _ValueType1>)
138
139
      typedef typename iterator_traits<_ForwardIterator1>::reference
140
	_ReferenceType1;
141
      typedef typename iterator_traits<_ForwardIterator2>::reference
142
	_ReferenceType2;
143
      std::__iter_swap<__are_same<_ValueType1, _ValueType2>::__value
144
	&& __are_same<_ValueType1&, _ReferenceType1>::__value
145
	&& __are_same<_ValueType2&, _ReferenceType2>::__value>::
146
	iter_swap(__a, __b);
147
#else
148
      swap(*__a, *__b);
149
#endif
150
    }
151
152
  /**
153
   *  @brief Swap the elements of two sequences.
154
   *  @ingroup mutating_algorithms
155
   *  @param  __first1  A forward iterator.
156
   *  @param  __last1   A forward iterator.
157
   *  @param  __first2  A forward iterator.
158
   *  @return   An iterator equal to @p first2+(last1-first1).
159
   *
160
   *  Swaps each element in the range @p [first1,last1) with the
161
   *  corresponding element in the range @p [first2,(last1-first1)).
162
   *  The ranges must not overlap.
163
  */
164
  template<typename _ForwardIterator1, typename _ForwardIterator2>
165
    _ForwardIterator2
166
    swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
167
		_ForwardIterator2 __first2)
168
    {
169
      // concept requirements
170
      __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
171
				  _ForwardIterator1>)
172
      __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
173
				  _ForwardIterator2>)
174
      __glibcxx_requires_valid_range(__first1, __last1);
175
176
      for (; __first1 != __last1; ++__first1, ++__first2)
177
	std::iter_swap(__first1, __first2);
178
      return __first2;
179
    }
180
181
  /**
182
   *  @brief This does what you think it does.
183
   *  @ingroup sorting_algorithms
184
   *  @param  __a  A thing of arbitrary type.
185
   *  @param  __b  Another thing of arbitrary type.
186
   *  @return   The lesser of the parameters.
187
   *
188
   *  This is the simple classic generic implementation.  It will work on
189
   *  temporary expressions, since they are only evaluated once, unlike a
190
   *  preprocessor macro.
191
  */
192
  template<typename _Tp>
193
    inline const _Tp&
194
    min(const _Tp& __a, const _Tp& __b)
195
    {
196
      // concept requirements
197
      __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
198
      //return __b < __a ? __b : __a;
199
      if (__b < __a)
200
	return __b;
201
      return __a;
202
    }
203
204
  /**
205
   *  @brief This does what you think it does.
206
   *  @ingroup sorting_algorithms
207
   *  @param  __a  A thing of arbitrary type.
208
   *  @param  __b  Another thing of arbitrary type.
209
   *  @return   The greater of the parameters.
210
   *
211
   *  This is the simple classic generic implementation.  It will work on
212
   *  temporary expressions, since they are only evaluated once, unlike a
213
   *  preprocessor macro.
214
  */
215
  template<typename _Tp>
216
    inline const _Tp&
217
    max(const _Tp& __a, const _Tp& __b)
218
    {
219
      // concept requirements
220
      __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
221
      //return  __a < __b ? __b : __a;
222
      if (__a < __b)
223
	return __b;
224
      return __a;
225
    }
226
227
  /**
228
   *  @brief This does what you think it does.
229
   *  @ingroup sorting_algorithms
230
   *  @param  __a  A thing of arbitrary type.
231
   *  @param  __b  Another thing of arbitrary type.
232
   *  @param  __comp  A @link comparison_functors comparison functor@endlink.
233
   *  @return   The lesser of the parameters.
234
   *
235
   *  This will work on temporary expressions, since they are only evaluated
236
   *  once, unlike a preprocessor macro.
237
  */
238
  template<typename _Tp, typename _Compare>
239
    inline const _Tp&
240
    min(const _Tp& __a, const _Tp& __b, _Compare __comp)
241
    {
242
      //return __comp(__b, __a) ? __b : __a;
243
      if (__comp(__b, __a))
244
	return __b;
245
      return __a;
246
    }
247
248
  /**
249
   *  @brief This does what you think it does.
250
   *  @ingroup sorting_algorithms
251
   *  @param  __a  A thing of arbitrary type.
252
   *  @param  __b  Another thing of arbitrary type.
253
   *  @param  __comp  A @link comparison_functors comparison functor@endlink.
254
   *  @return   The greater of the parameters.
255
   *
256
   *  This will work on temporary expressions, since they are only evaluated
257
   *  once, unlike a preprocessor macro.
258
  */
259
  template<typename _Tp, typename _Compare>
260
    inline const _Tp&
261
    max(const _Tp& __a, const _Tp& __b, _Compare __comp)
262
    {
263
      //return __comp(__a, __b) ? __b : __a;
264
      if (__comp(__a, __b))
265
	return __b;
266
      return __a;
267
    }
268
269
  // If _Iterator is a __normal_iterator return its base (a plain pointer,
270
  // normally) otherwise return it untouched.  See copy, fill, ... 
271
  template<typename _Iterator>
272
    struct _Niter_base
273
    : _Iter_base<_Iterator, __is_normal_iterator<_Iterator>::__value>
274
    { };
275
276
  template<typename _Iterator>
277
    inline typename _Niter_base<_Iterator>::iterator_type
278
    __niter_base(_Iterator __it)
279
    { return std::_Niter_base<_Iterator>::_S_base(__it); }
280
281
  // Likewise, for move_iterator.
282
  template<typename _Iterator>
283
    struct _Miter_base
284
    : _Iter_base<_Iterator, __is_move_iterator<_Iterator>::__value>
285
    { };
286
287
  template<typename _Iterator>
288
    inline typename _Miter_base<_Iterator>::iterator_type
289
    __miter_base(_Iterator __it)
290
    { return std::_Miter_base<_Iterator>::_S_base(__it); }
291
292
  // All of these auxiliary structs serve two purposes.  (1) Replace
293
  // calls to copy with memmove whenever possible.  (Memmove, not memcpy,
294
  // because the input and output ranges are permitted to overlap.)
295
  // (2) If we're using random access iterators, then write the loop as
296
  // a for loop with an explicit count.
297
298
  template<bool, bool, typename>
299
    struct __copy_move
300
    {
301
      template<typename _II, typename _OI>
302
        static _OI
303
        __copy_m(_II __first, _II __last, _OI __result)
304
        {
305
	  for (; __first != __last; ++__result, ++__first)
306
	    *__result = *__first;
307
	  return __result;
308
	}
309
    };
310
311
#if __cplusplus >= 201103L
312
  template<typename _Category>
313
    struct __copy_move<true, false, _Category>
314
    {
315
      template<typename _II, typename _OI>
316
        static _OI
317
        __copy_m(_II __first, _II __last, _OI __result)
318
        {
319
	  for (; __first != __last; ++__result, ++__first)
320
	    *__result = std::move(*__first);
321
	  return __result;
322
	}
323
    };
324
#endif
325
326
  template<>
327
    struct __copy_move<false, false, random_access_iterator_tag>
328
    {
329
      template<typename _II, typename _OI>
330
        static _OI
331
        __copy_m(_II __first, _II __last, _OI __result)
332
        { 
333
	  typedef typename iterator_traits<_II>::difference_type _Distance;
334
	  for(_Distance __n = __last - __first; __n > 0; --__n)
335
	    {
336
	      *__result = *__first;
337
	      ++__first;
338
	      ++__result;
339
	    }
340
	  return __result;
341
	}
342
    };
343
344
#if __cplusplus >= 201103L
345
  template<>
346
    struct __copy_move<true, false, random_access_iterator_tag>
347
    {
348
      template<typename _II, typename _OI>
349
        static _OI
350
        __copy_m(_II __first, _II __last, _OI __result)
351
        { 
352
	  typedef typename iterator_traits<_II>::difference_type _Distance;
353
	  for(_Distance __n = __last - __first; __n > 0; --__n)
354
	    {
355
	      *__result = std::move(*__first);
356
	      ++__first;
357
	      ++__result;
358
	    }
359
	  return __result;
360
	}
361
    };
362
#endif
363
364
  template<bool _IsMove>
365
    struct __copy_move<_IsMove, true, random_access_iterator_tag>
366
    {
367
      template<typename _Tp>
368
        static _Tp*
369
        __copy_m(const _Tp* __first, const _Tp* __last, _Tp* __result)
370
        {
371
#if __cplusplus >= 201103L
372
	  // trivial types can have deleted assignment
373
	  static_assert( is_copy_assignable<_Tp>::value,
374
	                 "type is not assignable" );
375
#endif
376
	  const ptrdiff_t _Num = __last - __first;
377
	  if (_Num)
378
	    __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);
379
	  return __result + _Num;
380
	}
381
    };
382
383
  template<bool _IsMove, typename _II, typename _OI>
384
    inline _OI
385
    __copy_move_a(_II __first, _II __last, _OI __result)
386
    {
387
      typedef typename iterator_traits<_II>::value_type _ValueTypeI;
388
      typedef typename iterator_traits<_OI>::value_type _ValueTypeO;
389
      typedef typename iterator_traits<_II>::iterator_category _Category;
390
      const bool __simple = (__is_trivial(_ValueTypeI)
391
	                     && __is_pointer<_II>::__value
392
	                     && __is_pointer<_OI>::__value
393
			     && __are_same<_ValueTypeI, _ValueTypeO>::__value);
394
395
      return std::__copy_move<_IsMove, __simple,
396
	                      _Category>::__copy_m(__first, __last, __result);
397
    }
398
399
  // Helpers for streambuf iterators (either istream or ostream).
400
  // NB: avoid including <iosfwd>, relatively large.
401
  template<typename _CharT>
402
    struct char_traits;
403
404
  template<typename _CharT, typename _Traits>
405
    class istreambuf_iterator;
406
407
  template<typename _CharT, typename _Traits>
408
    class ostreambuf_iterator;
409
410
  template<bool _IsMove, typename _CharT>
411
    typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, 
412
	     ostreambuf_iterator<_CharT, char_traits<_CharT> > >::__type
413
    __copy_move_a2(_CharT*, _CharT*,
414
		   ostreambuf_iterator<_CharT, char_traits<_CharT> >);
415
416
  template<bool _IsMove, typename _CharT>
417
    typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, 
418
	     ostreambuf_iterator<_CharT, char_traits<_CharT> > >::__type
419
    __copy_move_a2(const _CharT*, const _CharT*,
420
		   ostreambuf_iterator<_CharT, char_traits<_CharT> >);
421
422
  template<bool _IsMove, typename _CharT>
423
    typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
424
				    _CharT*>::__type
425
    __copy_move_a2(istreambuf_iterator<_CharT, char_traits<_CharT> >,
426
		   istreambuf_iterator<_CharT, char_traits<_CharT> >, _CharT*);
427
428
  template<bool _IsMove, typename _II, typename _OI>
429
    inline _OI
430
    __copy_move_a2(_II __first, _II __last, _OI __result)
431
    {
432
      return _OI(std::__copy_move_a<_IsMove>(std::__niter_base(__first),
433
					     std::__niter_base(__last),
434
					     std::__niter_base(__result)));
435
    }
436
437
  /**
438
   *  @brief Copies the range [first,last) into result.
439
   *  @ingroup mutating_algorithms
440
   *  @param  __first  An input iterator.
441
   *  @param  __last   An input iterator.
442
   *  @param  __result An output iterator.
443
   *  @return   result + (first - last)
444
   *
445
   *  This inline function will boil down to a call to @c memmove whenever
446
   *  possible.  Failing that, if random access iterators are passed, then the
447
   *  loop count will be known (and therefore a candidate for compiler
448
   *  optimizations such as unrolling).  Result may not be contained within
449
   *  [first,last); the copy_backward function should be used instead.
450
   *
451
   *  Note that the end of the output range is permitted to be contained
452
   *  within [first,last).
453
  */
454
  template<typename _II, typename _OI>
455
    inline _OI
456
    copy(_II __first, _II __last, _OI __result)
457
    {
458
      // concept requirements
459
      __glibcxx_function_requires(_InputIteratorConcept<_II>)
460
      __glibcxx_function_requires(_OutputIteratorConcept<_OI,
461
	    typename iterator_traits<_II>::value_type>)
462
      __glibcxx_requires_valid_range(__first, __last);
463
464
      return (std::__copy_move_a2<__is_move_iterator<_II>::__value>
465
	      (std::__miter_base(__first), std::__miter_base(__last),
466
	       __result));
467
    }
468
469
#if __cplusplus >= 201103L
470
  /**
471
   *  @brief Moves the range [first,last) into result.
472
   *  @ingroup mutating_algorithms
473
   *  @param  __first  An input iterator.
474
   *  @param  __last   An input iterator.
475
   *  @param  __result An output iterator.
476
   *  @return   result + (first - last)
477
   *
478
   *  This inline function will boil down to a call to @c memmove whenever
479
   *  possible.  Failing that, if random access iterators are passed, then the
480
   *  loop count will be known (and therefore a candidate for compiler
481
   *  optimizations such as unrolling).  Result may not be contained within
482
   *  [first,last); the move_backward function should be used instead.
483
   *
484
   *  Note that the end of the output range is permitted to be contained
485
   *  within [first,last).
486
  */
487
  template<typename _II, typename _OI>
488
    inline _OI
489
    move(_II __first, _II __last, _OI __result)
490
    {
491
      // concept requirements
492
      __glibcxx_function_requires(_InputIteratorConcept<_II>)
493
      __glibcxx_function_requires(_OutputIteratorConcept<_OI,
494
	    typename iterator_traits<_II>::value_type>)
495
      __glibcxx_requires_valid_range(__first, __last);
496
497
      return std::__copy_move_a2<true>(std::__miter_base(__first),
498
				       std::__miter_base(__last), __result);
499
    }
500
501
#define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::move(_Tp, _Up, _Vp)
502
#else
503
#define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::copy(_Tp, _Up, _Vp)
504
#endif
505
506
  template<bool, bool, typename>
507
    struct __copy_move_backward
508
    {
509
      template<typename _BI1, typename _BI2>
510
        static _BI2
511
        __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
512
        {
513
	  while (__first != __last)
514
	    *--__result = *--__last;
515
	  return __result;
516
	}
517
    };
518
519
#if __cplusplus >= 201103L
520
  template<typename _Category>
521
    struct __copy_move_backward<true, false, _Category>
522
    {
523
      template<typename _BI1, typename _BI2>
524
        static _BI2
525
        __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
526
        {
527
	  while (__first != __last)
528
	    *--__result = std::move(*--__last);
529
	  return __result;
530
	}
531
    };
532
#endif
533
534
  template<>
535
    struct __copy_move_backward<false, false, random_access_iterator_tag>
536
    {
537
      template<typename _BI1, typename _BI2>
538
        static _BI2
539
        __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
540
        {
541
	  typename iterator_traits<_BI1>::difference_type __n;
542
	  for (__n = __last - __first; __n > 0; --__n)
543
	    *--__result = *--__last;
544
	  return __result;
545
	}
546
    };
547
548
#if __cplusplus >= 201103L
549
  template<>
550
    struct __copy_move_backward<true, false, random_access_iterator_tag>
551
    {
552
      template<typename _BI1, typename _BI2>
553
        static _BI2
554
        __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
555
        {
556
	  typename iterator_traits<_BI1>::difference_type __n;
557
	  for (__n = __last - __first; __n > 0; --__n)
558
	    *--__result = std::move(*--__last);
559
	  return __result;
560
	}
561
    };
562
#endif
563
564
  template<bool _IsMove>
565
    struct __copy_move_backward<_IsMove, true, random_access_iterator_tag>
566
    {
567
      template<typename _Tp>
568
        static _Tp*
569
        __copy_move_b(const _Tp* __first, const _Tp* __last, _Tp* __result)
570
        {
571
#if __cplusplus >= 201103L
572
	  // trivial types can have deleted assignment
573
	  static_assert( is_copy_assignable<_Tp>::value,
574
	                 "type is not assignable" );
575
#endif
576
	  const ptrdiff_t _Num = __last - __first;
577
	  if (_Num)
578
	    __builtin_memmove(__result - _Num, __first, sizeof(_Tp) * _Num);
579
	  return __result - _Num;
580
	}
581
    };
582
583
  template<bool _IsMove, typename _BI1, typename _BI2>
584
    inline _BI2
585
    __copy_move_backward_a(_BI1 __first, _BI1 __last, _BI2 __result)
586
    {
587
      typedef typename iterator_traits<_BI1>::value_type _ValueType1;
588
      typedef typename iterator_traits<_BI2>::value_type _ValueType2;
589
      typedef typename iterator_traits<_BI1>::iterator_category _Category;
590
      const bool __simple = (__is_trivial(_ValueType1)
591
	                     && __is_pointer<_BI1>::__value
592
	                     && __is_pointer<_BI2>::__value
593
			     && __are_same<_ValueType1, _ValueType2>::__value);
594
595
      return std::__copy_move_backward<_IsMove, __simple,
596
	                               _Category>::__copy_move_b(__first,
597
								 __last,
598
								 __result);
599
    }
600
601
  template<bool _IsMove, typename _BI1, typename _BI2>
602
    inline _BI2
603
    __copy_move_backward_a2(_BI1 __first, _BI1 __last, _BI2 __result)
604
    {
605
      return _BI2(std::__copy_move_backward_a<_IsMove>
606
		  (std::__niter_base(__first), std::__niter_base(__last),
607
		   std::__niter_base(__result)));
608
    }
609
610
  /**
611
   *  @brief Copies the range [first,last) into result.
612
   *  @ingroup mutating_algorithms
613
   *  @param  __first  A bidirectional iterator.
614
   *  @param  __last   A bidirectional iterator.
615
   *  @param  __result A bidirectional iterator.
616
   *  @return   result - (first - last)
617
   *
618
   *  The function has the same effect as copy, but starts at the end of the
619
   *  range and works its way to the start, returning the start of the result.
620
   *  This inline function will boil down to a call to @c memmove whenever
621
   *  possible.  Failing that, if random access iterators are passed, then the
622
   *  loop count will be known (and therefore a candidate for compiler
623
   *  optimizations such as unrolling).
624
   *
625
   *  Result may not be in the range (first,last].  Use copy instead.  Note
626
   *  that the start of the output range may overlap [first,last).
627
  */
628
  template<typename _BI1, typename _BI2>
629
    inline _BI2
630
    copy_backward(_BI1 __first, _BI1 __last, _BI2 __result)
631
    {
632
      // concept requirements
633
      __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
634
      __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
635
      __glibcxx_function_requires(_ConvertibleConcept<
636
	    typename iterator_traits<_BI1>::value_type,
637
	    typename iterator_traits<_BI2>::value_type>)
638
      __glibcxx_requires_valid_range(__first, __last);
639
640
      return (std::__copy_move_backward_a2<__is_move_iterator<_BI1>::__value>
641
	      (std::__miter_base(__first), std::__miter_base(__last),
642
	       __result));
643
    }
644
645
#if __cplusplus >= 201103L
646
  /**
647
   *  @brief Moves the range [first,last) into result.
648
   *  @ingroup mutating_algorithms
649
   *  @param  __first  A bidirectional iterator.
650
   *  @param  __last   A bidirectional iterator.
651
   *  @param  __result A bidirectional iterator.
652
   *  @return   result - (first - last)
653
   *
654
   *  The function has the same effect as move, but starts at the end of the
655
   *  range and works its way to the start, returning the start of the result.
656
   *  This inline function will boil down to a call to @c memmove whenever
657
   *  possible.  Failing that, if random access iterators are passed, then the
658
   *  loop count will be known (and therefore a candidate for compiler
659
   *  optimizations such as unrolling).
660
   *
661
   *  Result may not be in the range (first,last].  Use move instead.  Note
662
   *  that the start of the output range may overlap [first,last).
663
  */
664
  template<typename _BI1, typename _BI2>
665
    inline _BI2
666
    move_backward(_BI1 __first, _BI1 __last, _BI2 __result)
667
    {
668
      // concept requirements
669
      __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
670
      __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
671
      __glibcxx_function_requires(_ConvertibleConcept<
672
	    typename iterator_traits<_BI1>::value_type,
673
	    typename iterator_traits<_BI2>::value_type>)
674
      __glibcxx_requires_valid_range(__first, __last);
675
676
      return std::__copy_move_backward_a2<true>(std::__miter_base(__first),
677
						std::__miter_base(__last),
678
						__result);
679
    }
680
681
#define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::move_backward(_Tp, _Up, _Vp)
682
#else
683
#define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::copy_backward(_Tp, _Up, _Vp)
684
#endif
685
686
  template<typename _ForwardIterator, typename _Tp>
687
    inline typename
688
    __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, void>::__type
689
    __fill_a(_ForwardIterator __first, _ForwardIterator __last,
690
 	     const _Tp& __value)
691
    {
692
      for (; __first != __last; ++__first)
693
	*__first = __value;
694
    }
695
    
696
  template<typename _ForwardIterator, typename _Tp>
697
    inline typename
698
    __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type
699
    __fill_a(_ForwardIterator __first, _ForwardIterator __last,
700
	     const _Tp& __value)
701
    {
702
      const _Tp __tmp = __value;
703
      for (; __first != __last; ++__first)
704
	*__first = __tmp;
705
    }
706
707
  // Specialization: for char types we can use memset.
708
  template<typename _Tp>
709
    inline typename
710
    __gnu_cxx::__enable_if<__is_byte<_Tp>::__value, void>::__type
711
    __fill_a(_Tp* __first, _Tp* __last, const _Tp& __c)
712
    {
713
      const _Tp __tmp = __c;
714
      __builtin_memset(__first, static_cast<unsigned char>(__tmp),
715
		       __last - __first);
716
    }
717
718
  /**
719
   *  @brief Fills the range [first,last) with copies of value.
720
   *  @ingroup mutating_algorithms
721
   *  @param  __first  A forward iterator.
722
   *  @param  __last   A forward iterator.
723
   *  @param  __value  A reference-to-const of arbitrary type.
724
   *  @return   Nothing.
725
   *
726
   *  This function fills a range with copies of the same value.  For char
727
   *  types filling contiguous areas of memory, this becomes an inline call
728
   *  to @c memset or @c wmemset.
729
  */
730
  template<typename _ForwardIterator, typename _Tp>
731
    inline void
732
    fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
733
    {
734
      // concept requirements
735
      __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
736
				  _ForwardIterator>)
737
      __glibcxx_requires_valid_range(__first, __last);
738
739
      std::__fill_a(std::__niter_base(__first), std::__niter_base(__last),
740
		    __value);
741
    }
742
743
  template<typename _OutputIterator, typename _Size, typename _Tp>
744
    inline typename
745
    __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, _OutputIterator>::__type
746
    __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value)
747
    {
748
      for (; __n > 0; --__n, ++__first)
749
	*__first = __value;
750
      return __first;
751
    }
752
753
  template<typename _OutputIterator, typename _Size, typename _Tp>
754
    inline typename
755
    __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type
756
    __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value)
757
    {
758
      const _Tp __tmp = __value;
759
      for (; __n > 0; --__n, ++__first)
760
	*__first = __tmp;
761
      return __first;
762
    }
763
764
  template<typename _Size, typename _Tp>
765
    inline typename
766
    __gnu_cxx::__enable_if<__is_byte<_Tp>::__value, _Tp*>::__type
767
    __fill_n_a(_Tp* __first, _Size __n, const _Tp& __c)
768
    {
769
      std::__fill_a(__first, __first + __n, __c);
770
      return __first + __n;
771
    }
772
773
  /**
774
   *  @brief Fills the range [first,first+n) with copies of value.
775
   *  @ingroup mutating_algorithms
776
   *  @param  __first  An output iterator.
777
   *  @param  __n      The count of copies to perform.
778
   *  @param  __value  A reference-to-const of arbitrary type.
779
   *  @return   The iterator at first+n.
780
   *
781
   *  This function fills a range with copies of the same value.  For char
782
   *  types filling contiguous areas of memory, this becomes an inline call
783
   *  to @c memset or @ wmemset.
784
   *
785
   *  _GLIBCXX_RESOLVE_LIB_DEFECTS
786
   *  DR 865. More algorithms that throw away information
787
  */
788
  template<typename _OI, typename _Size, typename _Tp>
789
    inline _OI
790
    fill_n(_OI __first, _Size __n, const _Tp& __value)
791
    {
792
      // concept requirements
793
      __glibcxx_function_requires(_OutputIteratorConcept<_OI, _Tp>)
794
795
      return _OI(std::__fill_n_a(std::__niter_base(__first), __n, __value));
796
    }
797
798
  template<bool _BoolType>
799
    struct __equal
800
    {
801
      template<typename _II1, typename _II2>
802
        static bool
803
        equal(_II1 __first1, _II1 __last1, _II2 __first2)
804
        {
805
	  for (; __first1 != __last1; ++__first1, ++__first2)
806
	    if (!(*__first1 == *__first2))
807
	      return false;
808
	  return true;
809
	}
810
    };
811
812
  template<>
813
    struct __equal<true>
814
    {
815
      template<typename _Tp>
816
        static bool
817
        equal(const _Tp* __first1, const _Tp* __last1, const _Tp* __first2)
818
        {
819
	  return !__builtin_memcmp(__first1, __first2, sizeof(_Tp)
820
				   * (__last1 - __first1));
821
	}
822
    };
823
824
  template<typename _II1, typename _II2>
825
    inline bool
826
    __equal_aux(_II1 __first1, _II1 __last1, _II2 __first2)
827
    {
828
      typedef typename iterator_traits<_II1>::value_type _ValueType1;
829
      typedef typename iterator_traits<_II2>::value_type _ValueType2;
830
      const bool __simple = ((__is_integer<_ValueType1>::__value
831
			      || __is_pointer<_ValueType1>::__value)
832
	                     && __is_pointer<_II1>::__value
833
	                     && __is_pointer<_II2>::__value
834
			     && __are_same<_ValueType1, _ValueType2>::__value);
835
836
      return std::__equal<__simple>::equal(__first1, __last1, __first2);
837
    }
838
839
  template<typename, typename>
840
    struct __lc_rai
841
    {
842
      template<typename _II1, typename _II2>
843
        static _II1
844
        __newlast1(_II1, _II1 __last1, _II2, _II2)
845
        { return __last1; }
846
847
      template<typename _II>
848
        static bool
849
        __cnd2(_II __first, _II __last)
850
        { return __first != __last; }
851
    };
852
853
  template<>
854
    struct __lc_rai<random_access_iterator_tag, random_access_iterator_tag>
855
    {
856
      template<typename _RAI1, typename _RAI2>
857
        static _RAI1
858
        __newlast1(_RAI1 __first1, _RAI1 __last1,
859
		   _RAI2 __first2, _RAI2 __last2)
860
        {
861
	  const typename iterator_traits<_RAI1>::difference_type
862
	    __diff1 = __last1 - __first1;
863
	  const typename iterator_traits<_RAI2>::difference_type
864
	    __diff2 = __last2 - __first2;
865
	  return __diff2 < __diff1 ? __first1 + __diff2 : __last1;
866
	}
867
868
      template<typename _RAI>
869
        static bool
870
        __cnd2(_RAI, _RAI)
871
        { return true; }
872
    };
873
874
  template<typename _II1, typename _II2, typename _Compare>
875
    bool
876
    __lexicographical_compare_impl(_II1 __first1, _II1 __last1,
877
				   _II2 __first2, _II2 __last2,
878
				   _Compare __comp)
879
    {
880
      typedef typename iterator_traits<_II1>::iterator_category _Category1;
881
      typedef typename iterator_traits<_II2>::iterator_category _Category2;
882
      typedef std::__lc_rai<_Category1, _Category2> __rai_type;
883
884
      __last1 = __rai_type::__newlast1(__first1, __last1, __first2, __last2);
885
      for (; __first1 != __last1 && __rai_type::__cnd2(__first2, __last2);
886
	   ++__first1, ++__first2)
887
	{
888
	  if (__comp(__first1, __first2))
889
	    return true;
890
	  if (__comp(__first2, __first1))
891
	    return false;
892
	}
893
      return __first1 == __last1 && __first2 != __last2;
894
    }
895
896
  template<bool _BoolType>
897
    struct __lexicographical_compare
898
    {
899
      template<typename _II1, typename _II2>
900
        static bool __lc(_II1, _II1, _II2, _II2);
901
    };
902
903
  template<bool _BoolType>
904
    template<typename _II1, typename _II2>
905
      bool
906
      __lexicographical_compare<_BoolType>::
907
      __lc(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
908
      {
909
	return std::__lexicographical_compare_impl(__first1, __last1,
910
						   __first2, __last2,
911
					__gnu_cxx::__ops::__iter_less_iter());
912
      }
913
914
  template<>
915
    struct __lexicographical_compare<true>
916
    {
917
      template<typename _Tp, typename _Up>
918
        static bool
919
        __lc(const _Tp* __first1, const _Tp* __last1,
920
	     const _Up* __first2, const _Up* __last2)
921
	{
922
	  const size_t __len1 = __last1 - __first1;
923
	  const size_t __len2 = __last2 - __first2;
924
	  const int __result = __builtin_memcmp(__first1, __first2,
925
						std::min(__len1, __len2));
926
	  return __result != 0 ? __result < 0 : __len1 < __len2;
927
	}
928
    };
929
930
  template<typename _II1, typename _II2>
931
    inline bool
932
    __lexicographical_compare_aux(_II1 __first1, _II1 __last1,
933
				  _II2 __first2, _II2 __last2)
934
    {
935
      typedef typename iterator_traits<_II1>::value_type _ValueType1;
936
      typedef typename iterator_traits<_II2>::value_type _ValueType2;
937
      const bool __simple =
938
	(__is_byte<_ValueType1>::__value && __is_byte<_ValueType2>::__value
939
	 && !__gnu_cxx::__numeric_traits<_ValueType1>::__is_signed
940
	 && !__gnu_cxx::__numeric_traits<_ValueType2>::__is_signed
941
	 && __is_pointer<_II1>::__value
942
	 && __is_pointer<_II2>::__value);
943
944
      return std::__lexicographical_compare<__simple>::__lc(__first1, __last1,
945
							    __first2, __last2);
946
    }
947
948
  template<typename _ForwardIterator, typename _Tp, typename _Compare>
949
    _ForwardIterator
950
    __lower_bound(_ForwardIterator __first, _ForwardIterator __last,
951
		  const _Tp& __val, _Compare __comp)
952
    {
953
      typedef typename iterator_traits<_ForwardIterator>::difference_type
954
	_DistanceType;
955
956
      _DistanceType __len = std::distance(__first, __last);
957
958
      while (__len > 0)
959
	{
960
	  _DistanceType __half = __len >> 1;
961
	  _ForwardIterator __middle = __first;
962
	  std::advance(__middle, __half);
963
	  if (__comp(__middle, __val))
964
	    {
965
	      __first = __middle;
966
	      ++__first;
967
	      __len = __len - __half - 1;
968
	    }
969
	  else
970
	    __len = __half;
971
	}
972
      return __first;
973
    }
974
975
  /**
976
   *  @brief Finds the first position in which @a val could be inserted
977
   *         without changing the ordering.
978
   *  @param  __first   An iterator.
979
   *  @param  __last    Another iterator.
980
   *  @param  __val     The search term.
981
   *  @return         An iterator pointing to the first element <em>not less
982
   *                  than</em> @a val, or end() if every element is less than 
983
   *                  @a val.
984
   *  @ingroup binary_search_algorithms
985
  */
986
  template<typename _ForwardIterator, typename _Tp>
987
    inline _ForwardIterator
988
    lower_bound(_ForwardIterator __first, _ForwardIterator __last,
989
		const _Tp& __val)
990
    {
991
      // concept requirements
992
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
993
      __glibcxx_function_requires(_LessThanOpConcept<
994
	    typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
995
      __glibcxx_requires_partitioned_lower(__first, __last, __val);
996
997
      return std::__lower_bound(__first, __last, __val,
998
				__gnu_cxx::__ops::__iter_less_val());
999
    }
1000
1001
  /// This is a helper function for the sort routines and for random.tcc.
1002
  //  Precondition: __n > 0.
1003
  inline _GLIBCXX_CONSTEXPR int
1004
  __lg(int __n)
1005
  { return sizeof(int) * __CHAR_BIT__  - 1 - __builtin_clz(__n); }
1006
1007
  inline _GLIBCXX_CONSTEXPR unsigned
1008
  __lg(unsigned __n)
1009
  { return sizeof(int) * __CHAR_BIT__  - 1 - __builtin_clz(__n); }
1010
1011
  inline _GLIBCXX_CONSTEXPR long
1012
  __lg(long __n)
1013
  { return sizeof(long) * __CHAR_BIT__ - 1 - __builtin_clzl(__n); }
1014
1015
  inline _GLIBCXX_CONSTEXPR unsigned long
1016
  __lg(unsigned long __n)
1017
  { return sizeof(long) * __CHAR_BIT__ - 1 - __builtin_clzl(__n); }
1018
1019
  inline _GLIBCXX_CONSTEXPR long long
1020
  __lg(long long __n)
1021
  { return sizeof(long long) * __CHAR_BIT__ - 1 - __builtin_clzll(__n); }
1022
1023
  inline _GLIBCXX_CONSTEXPR unsigned long long
1024
  __lg(unsigned long long __n)
1025
  { return sizeof(long long) * __CHAR_BIT__ - 1 - __builtin_clzll(__n); }
1026
1027
_GLIBCXX_END_NAMESPACE_VERSION
1028
1029
_GLIBCXX_BEGIN_NAMESPACE_ALGO
1030
1031
  /**
1032
   *  @brief Tests a range for element-wise equality.
1033
   *  @ingroup non_mutating_algorithms
1034
   *  @param  __first1  An input iterator.
1035
   *  @param  __last1   An input iterator.
1036
   *  @param  __first2  An input iterator.
1037
   *  @return   A boolean true or false.
1038
   *
1039
   *  This compares the elements of two ranges using @c == and returns true or
1040
   *  false depending on whether all of the corresponding elements of the
1041
   *  ranges are equal.
1042
  */
1043
  template<typename _II1, typename _II2>
1044
    inline bool
1045
    equal(_II1 __first1, _II1 __last1, _II2 __first2)
1046
    {
1047
      // concept requirements
1048
      __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1049
      __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1050
      __glibcxx_function_requires(_EqualOpConcept<
1051
	    typename iterator_traits<_II1>::value_type,
1052
	    typename iterator_traits<_II2>::value_type>)
1053
      __glibcxx_requires_valid_range(__first1, __last1);
1054
1055
      return std::__equal_aux(std::__niter_base(__first1),
1056
			      std::__niter_base(__last1),
1057
			      std::__niter_base(__first2));
1058
    }
1059
1060
  /**
1061
   *  @brief Tests a range for element-wise equality.
1062
   *  @ingroup non_mutating_algorithms
1063
   *  @param  __first1  An input iterator.
1064
   *  @param  __last1   An input iterator.
1065
   *  @param  __first2  An input iterator.
1066
   *  @param __binary_pred A binary predicate @link functors
1067
   *                  functor@endlink.
1068
   *  @return         A boolean true or false.
1069
   *
1070
   *  This compares the elements of two ranges using the binary_pred
1071
   *  parameter, and returns true or
1072
   *  false depending on whether all of the corresponding elements of the
1073
   *  ranges are equal.
1074
  */
1075
  template<typename _IIter1, typename _IIter2, typename _BinaryPredicate>
1076
    inline bool
1077
    equal(_IIter1 __first1, _IIter1 __last1,
1078
	  _IIter2 __first2, _BinaryPredicate __binary_pred)
1079
    {
1080
      // concept requirements
1081
      __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1082
      __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1083
      __glibcxx_requires_valid_range(__first1, __last1);
1084
1085
      for (; __first1 != __last1; ++__first1, ++__first2)
1086
	if (!bool(__binary_pred(*__first1, *__first2)))
1087
	  return false;
1088
      return true;
1089
    }
1090
1091
#if __cplusplus > 201103L
1092
  /**
1093
   *  @brief Tests a range for element-wise equality.
1094
   *  @ingroup non_mutating_algorithms
1095
   *  @param  __first1  An input iterator.
1096
   *  @param  __last1   An input iterator.
1097
   *  @param  __first2  An input iterator.
1098
   *  @param  __last2   An input iterator.
1099
   *  @return   A boolean true or false.
1100
   *
1101
   *  This compares the elements of two ranges using @c == and returns true or
1102
   *  false depending on whether all of the corresponding elements of the
1103
   *  ranges are equal.
1104
  */
1105
  template<typename _II1, typename _II2>
1106
    inline bool
1107
    equal(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1108
    {
1109
      // concept requirements
1110
      __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1111
      __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1112
      __glibcxx_function_requires(_EqualOpConcept<
1113
	    typename iterator_traits<_II1>::value_type,
1114
	    typename iterator_traits<_II2>::value_type>)
1115
      __glibcxx_requires_valid_range(__first1, __last1);
1116
      __glibcxx_requires_valid_range(__first2, __last2);
1117
1118
      using _RATag = random_access_iterator_tag;
1119
      using _Cat1 = typename iterator_traits<_II1>::iterator_category;
1120
      using _Cat2 = typename iterator_traits<_II2>::iterator_category;
1121
      using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1122
      if (_RAIters())
1123
	{
1124
	  auto __d1 = std::distance(__first1, __last1);
1125
	  auto __d2 = std::distance(__first2, __last2);
1126
	  if (__d1 != __d2)
1127
	    return false;
1128
	  return _GLIBCXX_STD_A::equal(__first1, __last1, __first2);
1129
	}
1130
1131
      for (; __first1 != __last1 && __first2 != __last2; ++__first1, ++__first2)
1132
	if (!(*__first1 == *__first2))
1133
	  return false;
1134
      return __first1 == __last1 && __first2 == __last2;
1135
    }
1136
1137
  /**
1138
   *  @brief Tests a range for element-wise equality.
1139
   *  @ingroup non_mutating_algorithms
1140
   *  @param  __first1  An input iterator.
1141
   *  @param  __last1   An input iterator.
1142
   *  @param  __first2  An input iterator.
1143
   *  @param  __last2   An input iterator.
1144
   *  @param __binary_pred A binary predicate @link functors
1145
   *                  functor@endlink.
1146
   *  @return         A boolean true or false.
1147
   *
1148
   *  This compares the elements of two ranges using the binary_pred
1149
   *  parameter, and returns true or
1150
   *  false depending on whether all of the corresponding elements of the
1151
   *  ranges are equal.
1152
  */
1153
  template<typename _IIter1, typename _IIter2, typename _BinaryPredicate>
1154
    inline bool
1155
    equal(_IIter1 __first1, _IIter1 __last1,
1156
	  _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
1157
    {
1158
      // concept requirements
1159
      __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1160
      __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1161
      __glibcxx_requires_valid_range(__first1, __last1);
1162
      __glibcxx_requires_valid_range(__first2, __last2);
1163
1164
      using _RATag = random_access_iterator_tag;
1165
      using _Cat1 = typename iterator_traits<_IIter1>::iterator_category;
1166
      using _Cat2 = typename iterator_traits<_IIter2>::iterator_category;
1167
      using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1168
      if (_RAIters())
1169
	{
1170
	  auto __d1 = std::distance(__first1, __last1);
1171
	  auto __d2 = std::distance(__first2, __last2);
1172
	  if (__d1 != __d2)
1173
	    return false;
1174
	  return _GLIBCXX_STD_A::equal(__first1, __last1, __first2,
1175
				       __binary_pred);
1176
	}
1177
1178
      for (; __first1 != __last1 && __first2 != __last2; ++__first1, ++__first2)
1179
	if (!bool(__binary_pred(*__first1, *__first2)))
1180
	  return false;
1181
      return __first1 == __last1 && __first2 == __last2;
1182
    }
1183
#endif
1184
1185
  /**
1186
   *  @brief Performs @b dictionary comparison on ranges.
1187
   *  @ingroup sorting_algorithms
1188
   *  @param  __first1  An input iterator.
1189
   *  @param  __last1   An input iterator.
1190
   *  @param  __first2  An input iterator.
1191
   *  @param  __last2   An input iterator.
1192
   *  @return   A boolean true or false.
1193
   *
1194
   *  <em>Returns true if the sequence of elements defined by the range
1195
   *  [first1,last1) is lexicographically less than the sequence of elements
1196
   *  defined by the range [first2,last2).  Returns false otherwise.</em>
1197
   *  (Quoted from [25.3.8]/1.)  If the iterators are all character pointers,
1198
   *  then this is an inline call to @c memcmp.
1199
  */
1200
  template<typename _II1, typename _II2>
1201
    inline bool
1202
    lexicographical_compare(_II1 __first1, _II1 __last1,
1203
			    _II2 __first2, _II2 __last2)
1204
    {
1205
#ifdef _GLIBCXX_CONCEPT_CHECKS
1206
      // concept requirements
1207
      typedef typename iterator_traits<_II1>::value_type _ValueType1;
1208
      typedef typename iterator_traits<_II2>::value_type _ValueType2;
1209
#endif
1210
      __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1211
      __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1212
      __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
1213
      __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
1214
      __glibcxx_requires_valid_range(__first1, __last1);
1215
      __glibcxx_requires_valid_range(__first2, __last2);
1216
1217
      return std::__lexicographical_compare_aux(std::__niter_base(__first1),
1218
						std::__niter_base(__last1),
1219
						std::__niter_base(__first2),
1220
						std::__niter_base(__last2));
1221
    }
1222
1223
  /**
1224
   *  @brief Performs @b dictionary comparison on ranges.
1225
   *  @ingroup sorting_algorithms
1226
   *  @param  __first1  An input iterator.
1227
   *  @param  __last1   An input iterator.
1228
   *  @param  __first2  An input iterator.
1229
   *  @param  __last2   An input iterator.
1230
   *  @param  __comp  A @link comparison_functors comparison functor@endlink.
1231
   *  @return   A boolean true or false.
1232
   *
1233
   *  The same as the four-parameter @c lexicographical_compare, but uses the
1234
   *  comp parameter instead of @c <.
1235
  */
1236
  template<typename _II1, typename _II2, typename _Compare>
1237
    inline bool
1238
    lexicographical_compare(_II1 __first1, _II1 __last1,
1239
			    _II2 __first2, _II2 __last2, _Compare __comp)
1240
    {
1241
      // concept requirements
1242
      __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1243
      __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1244
      __glibcxx_requires_valid_range(__first1, __last1);
1245
      __glibcxx_requires_valid_range(__first2, __last2);
1246
1247
      return std::__lexicographical_compare_impl
1248
	(__first1, __last1, __first2, __last2,
1249
	 __gnu_cxx::__ops::__iter_comp_iter(__comp));
1250
    }
1251
1252
  template<typename _InputIterator1, typename _InputIterator2,
1253
	   typename _BinaryPredicate>
1254
    pair<_InputIterator1, _InputIterator2>
1255
    __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1256
	       _InputIterator2 __first2, _BinaryPredicate __binary_pred)
1257
    {
1258
      while (__first1 != __last1 && __binary_pred(__first1, __first2))
1259
        {
1260
	  ++__first1;
1261
	  ++__first2;
1262
        }
1263
      return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
1264
    }
1265
1266
  /**
1267
   *  @brief Finds the places in ranges which don't match.
1268
   *  @ingroup non_mutating_algorithms
1269
   *  @param  __first1  An input iterator.
1270
   *  @param  __last1   An input iterator.
1271
   *  @param  __first2  An input iterator.
1272
   *  @return   A pair of iterators pointing to the first mismatch.
1273
   *
1274
   *  This compares the elements of two ranges using @c == and returns a pair
1275
   *  of iterators.  The first iterator points into the first range, the
1276
   *  second iterator points into the second range, and the elements pointed
1277
   *  to by the iterators are not equal.
1278
  */
1279
  template<typename _InputIterator1, typename _InputIterator2>
1280
    inline pair<_InputIterator1, _InputIterator2>
1281
    mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1282
	     _InputIterator2 __first2)
1283
    {
1284
      // concept requirements
1285
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1286
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1287
      __glibcxx_function_requires(_EqualOpConcept<
1288
	    typename iterator_traits<_InputIterator1>::value_type,
1289
	    typename iterator_traits<_InputIterator2>::value_type>)
1290
      __glibcxx_requires_valid_range(__first1, __last1);
1291
1292
      return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2,
1293
			     __gnu_cxx::__ops::__iter_equal_to_iter());
1294
    }
1295
1296
  /**
1297
   *  @brief Finds the places in ranges which don't match.
1298
   *  @ingroup non_mutating_algorithms
1299
   *  @param  __first1  An input iterator.
1300
   *  @param  __last1   An input iterator.
1301
   *  @param  __first2  An input iterator.
1302
   *  @param __binary_pred A binary predicate @link functors
1303
   *         functor@endlink.
1304
   *  @return   A pair of iterators pointing to the first mismatch.
1305
   *
1306
   *  This compares the elements of two ranges using the binary_pred
1307
   *  parameter, and returns a pair
1308
   *  of iterators.  The first iterator points into the first range, the
1309
   *  second iterator points into the second range, and the elements pointed
1310
   *  to by the iterators are not equal.
1311
  */
1312
  template<typename _InputIterator1, typename _InputIterator2,
1313
	   typename _BinaryPredicate>
1314
    inline pair<_InputIterator1, _InputIterator2>
1315
    mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1316
	     _InputIterator2 __first2, _BinaryPredicate __binary_pred)
1317
    {
1318
      // concept requirements
1319
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1320
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1321
      __glibcxx_requires_valid_range(__first1, __last1);
1322
1323
      return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2,
1324
	__gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
1325
    }
1326
1327
#if __cplusplus > 201103L
1328
1329
  template<typename _InputIterator1, typename _InputIterator2,
1330
	   typename _BinaryPredicate>
1331
    pair<_InputIterator1, _InputIterator2>
1332
    __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1333
	       _InputIterator2 __first2, _InputIterator2 __last2,
1334
	       _BinaryPredicate __binary_pred)
1335
    {
1336
      while (__first1 != __last1 && __first2 != __last2
1337
	     && __binary_pred(__first1, __first2))
1338
        {
1339
	  ++__first1;
1340
	  ++__first2;
1341
        }
1342
      return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
1343
    }
1344
1345
  /**
1346
   *  @brief Finds the places in ranges which don't match.
1347
   *  @ingroup non_mutating_algorithms
1348
   *  @param  __first1  An input iterator.
1349
   *  @param  __last1   An input iterator.
1350
   *  @param  __first2  An input iterator.
1351
   *  @param  __last2   An input iterator.
1352
   *  @return   A pair of iterators pointing to the first mismatch.
1353
   *
1354
   *  This compares the elements of two ranges using @c == and returns a pair
1355
   *  of iterators.  The first iterator points into the first range, the
1356
   *  second iterator points into the second range, and the elements pointed
1357
   *  to by the iterators are not equal.
1358
  */
1359
  template<typename _InputIterator1, typename _InputIterator2>
1360
    inline pair<_InputIterator1, _InputIterator2>
1361
    mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1362
	     _InputIterator2 __first2, _InputIterator2 __last2)
1363
    {
1364
      // concept requirements
1365
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1366
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1367
      __glibcxx_function_requires(_EqualOpConcept<
1368
	    typename iterator_traits<_InputIterator1>::value_type,
1369
	    typename iterator_traits<_InputIterator2>::value_type>)
1370
      __glibcxx_requires_valid_range(__first1, __last1);
1371
      __glibcxx_requires_valid_range(__first2, __last2);
1372
1373
      return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2, __last2,
1374
			     __gnu_cxx::__ops::__iter_equal_to_iter());
1375
    }
1376
1377
  /**
1378
   *  @brief Finds the places in ranges which don't match.
1379
   *  @ingroup non_mutating_algorithms
1380
   *  @param  __first1  An input iterator.
1381
   *  @param  __last1   An input iterator.
1382
   *  @param  __first2  An input iterator.
1383
   *  @param  __last2   An input iterator.
1384
   *  @param __binary_pred A binary predicate @link functors
1385
   *         functor@endlink.
1386
   *  @return   A pair of iterators pointing to the first mismatch.
1387
   *
1388
   *  This compares the elements of two ranges using the binary_pred
1389
   *  parameter, and returns a pair
1390
   *  of iterators.  The first iterator points into the first range, the
1391
   *  second iterator points into the second range, and the elements pointed
1392
   *  to by the iterators are not equal.
1393
  */
1394
  template<typename _InputIterator1, typename _InputIterator2,
1395
	   typename _BinaryPredicate>
1396
    inline pair<_InputIterator1, _InputIterator2>
1397
    mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1398
	     _InputIterator2 __first2, _InputIterator2 __last2,
1399
	     _BinaryPredicate __binary_pred)
1400
    {
1401
      // concept requirements
1402
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1403
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1404
      __glibcxx_requires_valid_range(__first1, __last1);
1405
      __glibcxx_requires_valid_range(__first2, __last2);
1406
1407
      return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2, __last2,
1408
			     __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
1409
    }
1410
#endif
1411
1412
_GLIBCXX_END_NAMESPACE_ALGO
1413
} // namespace std
1414
1415
// NB: This file is included within many other C++ includes, as a way
1416
// of getting the base algorithms. So, make sure that parallel bits
1417
// come in too if requested. 
1418
#ifdef _GLIBCXX_PARALLEL
1419
# include <parallel/algobase.h>
1420
#endif
1421
1422
#endif
(-)GCC_XML/Support/GCC/4.9/complex (+1954 lines)
Line 0 Link Here
1
// The template and inlines for the -*- C++ -*- complex number classes.
2
3
// Copyright (C) 1997-2014 Free Software Foundation, Inc.
4
//
5
// This file is part of the GNU ISO C++ Library.  This library is free
6
// software; you can redistribute it and/or modify it under the
7
// terms of the GNU General Public License as published by the
8
// Free Software Foundation; either version 3, or (at your option)
9
// any later version.
10
11
// This library is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
// GNU General Public License for more details.
15
16
// Under Section 7 of GPL version 3, you are granted additional
17
// permissions described in the GCC Runtime Library Exception, version
18
// 3.1, as published by the Free Software Foundation.
19
20
// You should have received a copy of the GNU General Public License and
21
// a copy of the GCC Runtime Library Exception along with this program;
22
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23
// <http://www.gnu.org/licenses/>.
24
25
/** @file include/complex
26
 *  This is a Standard C++ Library header.
27
 */
28
29
//
30
// ISO C++ 14882: 26.2  Complex Numbers
31
// Note: this is not a conforming implementation.
32
// Initially implemented by Ulrich Drepper <drepper@cygnus.com>
33
// Improved by Gabriel Dos Reis <dosreis@cmla.ens-cachan.fr>
34
//
35
36
#ifndef _GLIBCXX_COMPLEX
37
#define _GLIBCXX_COMPLEX 1
38
39
#pragma GCC system_header
40
41
#include <bits/c++config.h>
42
#include <bits/cpp_type_traits.h>
43
#include <ext/type_traits.h>
44
#include <cmath>
45
#include <sstream>
46
47
// Get rid of a macro possibly defined in <complex.h>
48
#undef complex
49
50
namespace std _GLIBCXX_VISIBILITY(default)
51
{
52
_GLIBCXX_BEGIN_NAMESPACE_VERSION
53
54
  /**
55
   * @defgroup complex_numbers Complex Numbers
56
   * @ingroup numerics
57
   *
58
   * Classes and functions for complex numbers.
59
   * @{
60
   */
61
62
  // Forward declarations.
63
  template<typename _Tp> class complex;
64
  template<> class complex<float>;
65
  template<> class complex<double>;
66
  template<> class complex<long double>;
67
68
  ///  Return magnitude of @a z.
69
  template<typename _Tp> _Tp abs(const complex<_Tp>&);
70
  ///  Return phase angle of @a z.
71
  template<typename _Tp> _Tp arg(const complex<_Tp>&);
72
  ///  Return @a z magnitude squared.
73
  template<typename _Tp> _Tp norm(const complex<_Tp>&);
74
75
  ///  Return complex conjugate of @a z.
76
  template<typename _Tp> complex<_Tp> conj(const complex<_Tp>&);
77
  ///  Return complex with magnitude @a rho and angle @a theta.
78
  template<typename _Tp> complex<_Tp> polar(const _Tp&, const _Tp& = 0);
79
80
  // Transcendentals:
81
  /// Return complex cosine of @a z.
82
  template<typename _Tp> complex<_Tp> cos(const complex<_Tp>&);
83
  /// Return complex hyperbolic cosine of @a z.
84
  template<typename _Tp> complex<_Tp> cosh(const complex<_Tp>&);
85
  /// Return complex base e exponential of @a z.
86
  template<typename _Tp> complex<_Tp> exp(const complex<_Tp>&);
87
  /// Return complex natural logarithm of @a z.
88
  template<typename _Tp> complex<_Tp> log(const complex<_Tp>&);
89
  /// Return complex base 10 logarithm of @a z.
90
  template<typename _Tp> complex<_Tp> log10(const complex<_Tp>&);
91
  /// Return @a x to the @a y'th power.
92
  template<typename _Tp> complex<_Tp> pow(const complex<_Tp>&, int);
93
  /// Return @a x to the @a y'th power.
94
  template<typename _Tp> complex<_Tp> pow(const complex<_Tp>&, const _Tp&);
95
  /// Return @a x to the @a y'th power.
96
  template<typename _Tp> complex<_Tp> pow(const complex<_Tp>&, 
97
                                          const complex<_Tp>&);
98
  /// Return @a x to the @a y'th power.
99
  template<typename _Tp> complex<_Tp> pow(const _Tp&, const complex<_Tp>&);
100
  /// Return complex sine of @a z.
101
  template<typename _Tp> complex<_Tp> sin(const complex<_Tp>&);
102
  /// Return complex hyperbolic sine of @a z.
103
  template<typename _Tp> complex<_Tp> sinh(const complex<_Tp>&);
104
  /// Return complex square root of @a z.
105
  template<typename _Tp> complex<_Tp> sqrt(const complex<_Tp>&);
106
  /// Return complex tangent of @a z.
107
  template<typename _Tp> complex<_Tp> tan(const complex<_Tp>&);
108
  /// Return complex hyperbolic tangent of @a z.
109
  template<typename _Tp> complex<_Tp> tanh(const complex<_Tp>&);
110
    
111
    
112
  // 26.2.2  Primary template class complex
113
  /**
114
   *  Template to represent complex numbers.
115
   *
116
   *  Specializations for float, double, and long double are part of the
117
   *  library.  Results with any other type are not guaranteed.
118
   *
119
   *  @param  Tp  Type of real and imaginary values.
120
  */
121
  template<typename _Tp>
122
    struct complex
123
    {
124
      /// Value typedef.
125
      typedef _Tp value_type;
126
      
127
      ///  Default constructor.  First parameter is x, second parameter is y.
128
      ///  Unspecified parameters default to 0.
129
      _GLIBCXX_CONSTEXPR complex(const _Tp& __r = _Tp(), const _Tp& __i = _Tp())
130
      : _M_real(__r), _M_imag(__i) { }
131
132
      // Lets the compiler synthesize the copy constructor   
133
      // complex (const complex<_Tp>&);
134
      ///  Copy constructor.
135
      template<typename _Up>
136
        _GLIBCXX_CONSTEXPR complex(const complex<_Up>& __z)
137
	: _M_real(__z.real()), _M_imag(__z.imag()) { }
138
139
#if __cplusplus >= 201103L
140
      // _GLIBCXX_RESOLVE_LIB_DEFECTS
141
      // DR 387. std::complex over-encapsulated.
142
      _GLIBCXX_ABI_TAG_CXX11
143
      constexpr _Tp 
144
      real() { return _M_real; }
145
146
      _GLIBCXX_ABI_TAG_CXX11
147
      constexpr _Tp 
148
      imag() { return _M_imag; }
149
#else
150
      ///  Return real part of complex number.
151
      _Tp& 
152
      real() { return _M_real; }
153
154
      ///  Return real part of complex number.
155
      const _Tp& 
156
      real() const { return _M_real; }
157
158
      ///  Return imaginary part of complex number.
159
      _Tp& 
160
      imag() { return _M_imag; }
161
162
      ///  Return imaginary part of complex number.
163
      const _Tp& 
164
      imag() const { return _M_imag; }
165
#endif
166
167
      // _GLIBCXX_RESOLVE_LIB_DEFECTS
168
      // DR 387. std::complex over-encapsulated.
169
      void 
170
      real(_Tp __val) { _M_real = __val; }
171
172
      void 
173
      imag(_Tp __val) { _M_imag = __val; }
174
175
      /// Assign this complex number to scalar @a t.
176
      complex<_Tp>& operator=(const _Tp&);
177
      
178
      /// Add @a t to this complex number.
179
      // 26.2.5/1
180
      complex<_Tp>&
181
      operator+=(const _Tp& __t)
182
      {
183
	_M_real += __t;
184
	return *this;
185
      }
186
187
      /// Subtract @a t from this complex number.
188
      // 26.2.5/3
189
      complex<_Tp>&
190
      operator-=(const _Tp& __t)
191
      {
192
	_M_real -= __t;
193
	return *this;
194
      }
195
196
      /// Multiply this complex number by @a t.
197
      complex<_Tp>& operator*=(const _Tp&);
198
      /// Divide this complex number by @a t.
199
      complex<_Tp>& operator/=(const _Tp&);
200
201
      // Lets the compiler synthesize the
202
      // copy and assignment operator
203
      // complex<_Tp>& operator= (const complex<_Tp>&);
204
      /// Assign this complex number to complex @a z.
205
      template<typename _Up>
206
        complex<_Tp>& operator=(const complex<_Up>&);
207
      /// Add @a z to this complex number.
208
      template<typename _Up>
209
        complex<_Tp>& operator+=(const complex<_Up>&);
210
      /// Subtract @a z from this complex number.
211
      template<typename _Up>
212
        complex<_Tp>& operator-=(const complex<_Up>&);
213
      /// Multiply this complex number by @a z.
214
      template<typename _Up>
215
        complex<_Tp>& operator*=(const complex<_Up>&);
216
      /// Divide this complex number by @a z.
217
      template<typename _Up>
218
        complex<_Tp>& operator/=(const complex<_Up>&);
219
220
      _GLIBCXX_USE_CONSTEXPR complex __rep() const
221
      { return *this; }
222
223
    private:
224
      _Tp _M_real;
225
      _Tp _M_imag;
226
    };
227
228
  template<typename _Tp>
229
    complex<_Tp>&
230
    complex<_Tp>::operator=(const _Tp& __t)
231
    {
232
     _M_real = __t;
233
     _M_imag = _Tp();
234
     return *this;
235
    } 
236
237
  // 26.2.5/5
238
  template<typename _Tp>
239
    complex<_Tp>&
240
    complex<_Tp>::operator*=(const _Tp& __t)
241
    {
242
      _M_real *= __t;
243
      _M_imag *= __t;
244
      return *this;
245
    }
246
247
  // 26.2.5/7
248
  template<typename _Tp>
249
    complex<_Tp>&
250
    complex<_Tp>::operator/=(const _Tp& __t)
251
    {
252
      _M_real /= __t;
253
      _M_imag /= __t;
254
      return *this;
255
    }
256
257
  template<typename _Tp>
258
    template<typename _Up>
259
    complex<_Tp>&
260
    complex<_Tp>::operator=(const complex<_Up>& __z)
261
    {
262
      _M_real = __z.real();
263
      _M_imag = __z.imag();
264
      return *this;
265
    }
266
267
  // 26.2.5/9
268
  template<typename _Tp>
269
    template<typename _Up>
270
    complex<_Tp>&
271
    complex<_Tp>::operator+=(const complex<_Up>& __z)
272
    {
273
      _M_real += __z.real();
274
      _M_imag += __z.imag();
275
      return *this;
276
    }
277
278
  // 26.2.5/11
279
  template<typename _Tp>
280
    template<typename _Up>
281
    complex<_Tp>&
282
    complex<_Tp>::operator-=(const complex<_Up>& __z)
283
    {
284
      _M_real -= __z.real();
285
      _M_imag -= __z.imag();
286
      return *this;
287
    }
288
289
  // 26.2.5/13
290
  // XXX: This is a grammar school implementation.
291
  template<typename _Tp>
292
    template<typename _Up>
293
    complex<_Tp>&
294
    complex<_Tp>::operator*=(const complex<_Up>& __z)
295
    {
296
      const _Tp __r = _M_real * __z.real() - _M_imag * __z.imag();
297
      _M_imag = _M_real * __z.imag() + _M_imag * __z.real();
298
      _M_real = __r;
299
      return *this;
300
    }
301
302
  // 26.2.5/15
303
  // XXX: This is a grammar school implementation.
304
  template<typename _Tp>
305
    template<typename _Up>
306
    complex<_Tp>&
307
    complex<_Tp>::operator/=(const complex<_Up>& __z)
308
    {
309
      const _Tp __r =  _M_real * __z.real() + _M_imag * __z.imag();
310
      const _Tp __n = std::norm(__z);
311
      _M_imag = (_M_imag * __z.real() - _M_real * __z.imag()) / __n;
312
      _M_real = __r / __n;
313
      return *this;
314
    }
315
    
316
  // Operators:
317
  //@{
318
  ///  Return new complex value @a x plus @a y.
319
  template<typename _Tp>
320
    inline complex<_Tp>
321
    operator+(const complex<_Tp>& __x, const complex<_Tp>& __y)
322
    {
323
      complex<_Tp> __r = __x;
324
      __r += __y;
325
      return __r;
326
    }
327
328
  template<typename _Tp>
329
    inline complex<_Tp>
330
    operator+(const complex<_Tp>& __x, const _Tp& __y)
331
    {
332
      complex<_Tp> __r = __x;
333
      __r += __y;
334
      return __r;
335
    }
336
337
  template<typename _Tp>
338
    inline complex<_Tp>
339
    operator+(const _Tp& __x, const complex<_Tp>& __y)
340
    {
341
      complex<_Tp> __r = __y;
342
      __r += __x;
343
      return __r;
344
    }
345
  //@}
346
347
  //@{
348
  ///  Return new complex value @a x minus @a y.
349
  template<typename _Tp>
350
    inline complex<_Tp>
351
    operator-(const complex<_Tp>& __x, const complex<_Tp>& __y)
352
    {
353
      complex<_Tp> __r = __x;
354
      __r -= __y;
355
      return __r;
356
    }
357
    
358
  template<typename _Tp>
359
    inline complex<_Tp>
360
    operator-(const complex<_Tp>& __x, const _Tp& __y)
361
    {
362
      complex<_Tp> __r = __x;
363
      __r -= __y;
364
      return __r;
365
    }
366
367
  template<typename _Tp>
368
    inline complex<_Tp>
369
    operator-(const _Tp& __x, const complex<_Tp>& __y)
370
    {
371
      complex<_Tp> __r(__x, -__y.imag());
372
      __r -= __y.real();
373
      return __r;
374
    }
375
  //@}
376
377
  //@{
378
  ///  Return new complex value @a x times @a y.
379
  template<typename _Tp>
380
    inline complex<_Tp>
381
    operator*(const complex<_Tp>& __x, const complex<_Tp>& __y)
382
    {
383
      complex<_Tp> __r = __x;
384
      __r *= __y;
385
      return __r;
386
    }
387
388
  template<typename _Tp>
389
    inline complex<_Tp>
390
    operator*(const complex<_Tp>& __x, const _Tp& __y)
391
    {
392
      complex<_Tp> __r = __x;
393
      __r *= __y;
394
      return __r;
395
    }
396
397
  template<typename _Tp>
398
    inline complex<_Tp>
399
    operator*(const _Tp& __x, const complex<_Tp>& __y)
400
    {
401
      complex<_Tp> __r = __y;
402
      __r *= __x;
403
      return __r;
404
    }
405
  //@}
406
407
  //@{
408
  ///  Return new complex value @a x divided by @a y.
409
  template<typename _Tp>
410
    inline complex<_Tp>
411
    operator/(const complex<_Tp>& __x, const complex<_Tp>& __y)
412
    {
413
      complex<_Tp> __r = __x;
414
      __r /= __y;
415
      return __r;
416
    }
417
    
418
  template<typename _Tp>
419
    inline complex<_Tp>
420
    operator/(const complex<_Tp>& __x, const _Tp& __y)
421
    {
422
      complex<_Tp> __r = __x;
423
      __r /= __y;
424
      return __r;
425
    }
426
427
  template<typename _Tp>
428
    inline complex<_Tp>
429
    operator/(const _Tp& __x, const complex<_Tp>& __y)
430
    {
431
      complex<_Tp> __r = __x;
432
      __r /= __y;
433
      return __r;
434
    }
435
  //@}
436
437
  ///  Return @a x.
438
  template<typename _Tp>
439
    inline complex<_Tp>
440
    operator+(const complex<_Tp>& __x)
441
    { return __x; }
442
443
  ///  Return complex negation of @a x.
444
  template<typename _Tp>
445
    inline complex<_Tp>
446
    operator-(const complex<_Tp>& __x)
447
    {  return complex<_Tp>(-__x.real(), -__x.imag()); }
448
449
  //@{
450
  ///  Return true if @a x is equal to @a y.
451
  template<typename _Tp>
452
    inline _GLIBCXX_CONSTEXPR bool
453
    operator==(const complex<_Tp>& __x, const complex<_Tp>& __y)
454
    { return __x.real() == __y.real() && __x.imag() == __y.imag(); }
455
456
  template<typename _Tp>
457
    inline _GLIBCXX_CONSTEXPR bool
458
    operator==(const complex<_Tp>& __x, const _Tp& __y)
459
    { return __x.real() == __y && __x.imag() == _Tp(); }
460
461
  template<typename _Tp>
462
    inline _GLIBCXX_CONSTEXPR bool
463
    operator==(const _Tp& __x, const complex<_Tp>& __y)
464
    { return __x == __y.real() && _Tp() == __y.imag(); }
465
  //@}
466
467
  //@{
468
  ///  Return false if @a x is equal to @a y.
469
  template<typename _Tp>
470
    inline _GLIBCXX_CONSTEXPR bool
471
    operator!=(const complex<_Tp>& __x, const complex<_Tp>& __y)
472
    { return __x.real() != __y.real() || __x.imag() != __y.imag(); }
473
474
  template<typename _Tp>
475
    inline _GLIBCXX_CONSTEXPR bool
476
    operator!=(const complex<_Tp>& __x, const _Tp& __y)
477
    { return __x.real() != __y || __x.imag() != _Tp(); }
478
479
  template<typename _Tp>
480
    inline _GLIBCXX_CONSTEXPR bool
481
    operator!=(const _Tp& __x, const complex<_Tp>& __y)
482
    { return __x != __y.real() || _Tp() != __y.imag(); }
483
  //@}
484
485
  ///  Extraction operator for complex values.
486
  template<typename _Tp, typename _CharT, class _Traits>
487
    basic_istream<_CharT, _Traits>&
488
    operator>>(basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __x)
489
    {
490
      _Tp __re_x, __im_x;
491
      _CharT __ch;
492
      __is >> __ch;
493
      if (__ch == '(') 
494
	{
495
	  __is >> __re_x >> __ch;
496
	  if (__ch == ',') 
497
	    {
498
	      __is >> __im_x >> __ch;
499
	      if (__ch == ')') 
500
		__x = complex<_Tp>(__re_x, __im_x);
501
	      else
502
		__is.setstate(ios_base::failbit);
503
	    }
504
	  else if (__ch == ')') 
505
	    __x = __re_x;
506
	  else
507
	    __is.setstate(ios_base::failbit);
508
	}
509
      else 
510
	{
511
	  __is.putback(__ch);
512
	  __is >> __re_x;
513
	  __x = __re_x;
514
	}
515
      return __is;
516
    }
517
518
  ///  Insertion operator for complex values.
519
  template<typename _Tp, typename _CharT, class _Traits>
520
    basic_ostream<_CharT, _Traits>&
521
    operator<<(basic_ostream<_CharT, _Traits>& __os, const complex<_Tp>& __x)
522
    {
523
      basic_ostringstream<_CharT, _Traits> __s;
524
      __s.flags(__os.flags());
525
      __s.imbue(__os.getloc());
526
      __s.precision(__os.precision());
527
      __s << '(' << __x.real() << ',' << __x.imag() << ')';
528
      return __os << __s.str();
529
    }
530
531
  // Values
532
#if __cplusplus >= 201103L
533
  template<typename _Tp>
534
    constexpr _Tp
535
    real(const complex<_Tp>& __z)
536
    { return __z.real(); }
537
538
  template<typename _Tp>
539
    constexpr _Tp
540
    imag(const complex<_Tp>& __z)
541
    { return __z.imag(); }
542
#else
543
  template<typename _Tp>
544
    inline _Tp&
545
    real(complex<_Tp>& __z)
546
    { return __z.real(); }
547
    
548
  template<typename _Tp>
549
    inline const _Tp&
550
    real(const complex<_Tp>& __z)
551
    { return __z.real(); }
552
    
553
  template<typename _Tp>
554
    inline _Tp&
555
    imag(complex<_Tp>& __z)
556
    { return __z.imag(); }
557
    
558
  template<typename _Tp>
559
    inline const _Tp&
560
    imag(const complex<_Tp>& __z)
561
    { return __z.imag(); }
562
#endif
563
564
  // 26.2.7/3 abs(__z):  Returns the magnitude of __z.
565
  template<typename _Tp>
566
    inline _Tp
567
    __complex_abs(const complex<_Tp>& __z)
568
    {
569
      _Tp __x = __z.real();
570
      _Tp __y = __z.imag();
571
      const _Tp __s = std::max(abs(__x), abs(__y));
572
      if (__s == _Tp())  // well ...
573
        return __s;
574
      __x /= __s; 
575
      __y /= __s;
576
      return __s * sqrt(__x * __x + __y * __y);
577
    }
578
579
#if _GLIBCXX_USE_C99_COMPLEX
580
  inline float
581
  __complex_abs(__complex__ float __z) { return __builtin_cabsf(__z); }
582
583
  inline double
584
  __complex_abs(__complex__ double __z) { return __builtin_cabs(__z); }
585
586
  inline long double
587
  __complex_abs(const __complex__ long double& __z)
588
  { return __builtin_cabsl(__z); }
589
590
  template<typename _Tp>
591
    inline _Tp
592
    abs(const complex<_Tp>& __z) { return __complex_abs(__z.__rep()); }
593
#else
594
  template<typename _Tp>
595
    inline _Tp
596
    abs(const complex<_Tp>& __z) { return __complex_abs(__z); }
597
#endif  
598
599
600
  // 26.2.7/4: arg(__z): Returns the phase angle of __z.
601
  template<typename _Tp>
602
    inline _Tp
603
    __complex_arg(const complex<_Tp>& __z)
604
    { return  atan2(__z.imag(), __z.real()); }
605
606
#if _GLIBCXX_USE_C99_COMPLEX
607
  inline float
608
  __complex_arg(__complex__ float __z) { return __builtin_cargf(__z); }
609
610
  inline double
611
  __complex_arg(__complex__ double __z) { return __builtin_carg(__z); }
612
613
  inline long double
614
  __complex_arg(const __complex__ long double& __z)
615
  { return __builtin_cargl(__z); }
616
617
  template<typename _Tp>
618
    inline _Tp
619
    arg(const complex<_Tp>& __z) { return __complex_arg(__z.__rep()); }
620
#else
621
  template<typename _Tp>
622
    inline _Tp
623
    arg(const complex<_Tp>& __z) { return __complex_arg(__z); }
624
#endif
625
626
  // 26.2.7/5: norm(__z) returns the squared magnitude of __z.
627
  //     As defined, norm() is -not- a norm is the common mathematical
628
  //     sens used in numerics.  The helper class _Norm_helper<> tries to
629
  //     distinguish between builtin floating point and the rest, so as
630
  //     to deliver an answer as close as possible to the real value.
631
  template<bool>
632
    struct _Norm_helper
633
    {
634
      template<typename _Tp>
635
        static inline _Tp _S_do_it(const complex<_Tp>& __z)
636
        {
637
          const _Tp __x = __z.real();
638
          const _Tp __y = __z.imag();
639
          return __x * __x + __y * __y;
640
        }
641
    };
642
643
  template<>
644
    struct _Norm_helper<true>
645
    {
646
      template<typename _Tp>
647
        static inline _Tp _S_do_it(const complex<_Tp>& __z)
648
        {
649
          _Tp __res = std::abs(__z);
650
          return __res * __res;
651
        }
652
    };
653
  
654
  template<typename _Tp>
655
    inline _Tp
656
    norm(const complex<_Tp>& __z)
657
    {
658
      return _Norm_helper<__is_floating<_Tp>::__value 
659
	&& !_GLIBCXX_FAST_MATH>::_S_do_it(__z);
660
    }
661
662
  template<typename _Tp>
663
    inline complex<_Tp>
664
    polar(const _Tp& __rho, const _Tp& __theta)
665
    { return complex<_Tp>(__rho * cos(__theta), __rho * sin(__theta)); }
666
667
  template<typename _Tp>
668
    inline complex<_Tp>
669
    conj(const complex<_Tp>& __z)
670
    { return complex<_Tp>(__z.real(), -__z.imag()); }
671
  
672
  // Transcendentals
673
674
  // 26.2.8/1 cos(__z):  Returns the cosine of __z.
675
  template<typename _Tp>
676
    inline complex<_Tp>
677
    __complex_cos(const complex<_Tp>& __z)
678
    {
679
      const _Tp __x = __z.real();
680
      const _Tp __y = __z.imag();
681
      return complex<_Tp>(cos(__x) * cosh(__y), -sin(__x) * sinh(__y));
682
    }
683
684
#if _GLIBCXX_USE_C99_COMPLEX
685
  inline __complex__ float
686
  __complex_cos(__complex__ float __z) { return __builtin_ccosf(__z); }
687
688
  inline __complex__ double
689
  __complex_cos(__complex__ double __z) { return __builtin_ccos(__z); }
690
691
  inline __complex__ long double
692
  __complex_cos(const __complex__ long double& __z)
693
  { return __builtin_ccosl(__z); }
694
695
  template<typename _Tp>
696
    inline complex<_Tp>
697
    cos(const complex<_Tp>& __z) { return __complex_cos(__z.__rep()); }
698
#else
699
  template<typename _Tp>
700
    inline complex<_Tp>
701
    cos(const complex<_Tp>& __z) { return __complex_cos(__z); }
702
#endif
703
704
  // 26.2.8/2 cosh(__z): Returns the hyperbolic cosine of __z.
705
  template<typename _Tp>
706
    inline complex<_Tp>
707
    __complex_cosh(const complex<_Tp>& __z)
708
    {
709
      const _Tp __x = __z.real();
710
      const _Tp __y = __z.imag();
711
      return complex<_Tp>(cosh(__x) * cos(__y), sinh(__x) * sin(__y));
712
    }
713
714
#if _GLIBCXX_USE_C99_COMPLEX
715
  inline __complex__ float
716
  __complex_cosh(__complex__ float __z) { return __builtin_ccoshf(__z); }
717
718
  inline __complex__ double
719
  __complex_cosh(__complex__ double __z) { return __builtin_ccosh(__z); }
720
721
  inline __complex__ long double
722
  __complex_cosh(const __complex__ long double& __z)
723
  { return __builtin_ccoshl(__z); }
724
725
  template<typename _Tp>
726
    inline complex<_Tp>
727
    cosh(const complex<_Tp>& __z) { return __complex_cosh(__z.__rep()); }
728
#else
729
  template<typename _Tp>
730
    inline complex<_Tp>
731
    cosh(const complex<_Tp>& __z) { return __complex_cosh(__z); }
732
#endif
733
734
  // 26.2.8/3 exp(__z): Returns the complex base e exponential of x
735
  template<typename _Tp>
736
    inline complex<_Tp>
737
    __complex_exp(const complex<_Tp>& __z)
738
    { return std::polar(exp(__z.real()), __z.imag()); }
739
740
#if _GLIBCXX_USE_C99_COMPLEX
741
  inline __complex__ float
742
  __complex_exp(__complex__ float __z) { return __builtin_cexpf(__z); }
743
744
  inline __complex__ double
745
  __complex_exp(__complex__ double __z) { return __builtin_cexp(__z); }
746
747
  inline __complex__ long double
748
  __complex_exp(const __complex__ long double& __z)
749
  { return __builtin_cexpl(__z); }
750
751
  template<typename _Tp>
752
    inline complex<_Tp>
753
    exp(const complex<_Tp>& __z) { return __complex_exp(__z.__rep()); }
754
#else
755
  template<typename _Tp>
756
    inline complex<_Tp>
757
    exp(const complex<_Tp>& __z) { return __complex_exp(__z); }
758
#endif
759
760
  // 26.2.8/5 log(__z): Returns the natural complex logarithm of __z.
761
  //                    The branch cut is along the negative axis.
762
  template<typename _Tp>
763
    inline complex<_Tp>
764
    __complex_log(const complex<_Tp>& __z)
765
    { return complex<_Tp>(log(std::abs(__z)), std::arg(__z)); }
766
767
#if _GLIBCXX_USE_C99_COMPLEX
768
  inline __complex__ float
769
  __complex_log(__complex__ float __z) { return __builtin_clogf(__z); }
770
771
  inline __complex__ double
772
  __complex_log(__complex__ double __z) { return __builtin_clog(__z); }
773
774
  inline __complex__ long double
775
  __complex_log(const __complex__ long double& __z)
776
  { return __builtin_clogl(__z); }
777
778
  template<typename _Tp>
779
    inline complex<_Tp>
780
    log(const complex<_Tp>& __z) { return __complex_log(__z.__rep()); }
781
#else
782
  template<typename _Tp>
783
    inline complex<_Tp>
784
    log(const complex<_Tp>& __z) { return __complex_log(__z); }
785
#endif
786
787
  template<typename _Tp>
788
    inline complex<_Tp>
789
    log10(const complex<_Tp>& __z)
790
    { return std::log(__z) / log(_Tp(10.0)); }
791
792
  // 26.2.8/10 sin(__z): Returns the sine of __z.
793
  template<typename _Tp>
794
    inline complex<_Tp>
795
    __complex_sin(const complex<_Tp>& __z)
796
    {
797
      const _Tp __x = __z.real();
798
      const _Tp __y = __z.imag();
799
      return complex<_Tp>(sin(__x) * cosh(__y), cos(__x) * sinh(__y)); 
800
    }
801
802
#if _GLIBCXX_USE_C99_COMPLEX
803
  inline __complex__ float
804
  __complex_sin(__complex__ float __z) { return __builtin_csinf(__z); }
805
806
  inline __complex__ double
807
  __complex_sin(__complex__ double __z) { return __builtin_csin(__z); }
808
809
  inline __complex__ long double
810
  __complex_sin(const __complex__ long double& __z)
811
  { return __builtin_csinl(__z); }
812
813
  template<typename _Tp>
814
    inline complex<_Tp>
815
    sin(const complex<_Tp>& __z) { return __complex_sin(__z.__rep()); }
816
#else
817
  template<typename _Tp>
818
    inline complex<_Tp>
819
    sin(const complex<_Tp>& __z) { return __complex_sin(__z); }
820
#endif
821
822
  // 26.2.8/11 sinh(__z): Returns the hyperbolic sine of __z.
823
  template<typename _Tp>
824
    inline complex<_Tp>
825
    __complex_sinh(const complex<_Tp>& __z)
826
    {
827
      const _Tp __x = __z.real();
828
      const _Tp  __y = __z.imag();
829
      return complex<_Tp>(sinh(__x) * cos(__y), cosh(__x) * sin(__y));
830
    }
831
832
#if _GLIBCXX_USE_C99_COMPLEX
833
  inline __complex__ float
834
  __complex_sinh(__complex__ float __z) { return __builtin_csinhf(__z); }      
835
836
  inline __complex__ double
837
  __complex_sinh(__complex__ double __z) { return __builtin_csinh(__z); }      
838
839
  inline __complex__ long double
840
  __complex_sinh(const __complex__ long double& __z)
841
  { return __builtin_csinhl(__z); }      
842
843
  template<typename _Tp>
844
    inline complex<_Tp>
845
    sinh(const complex<_Tp>& __z) { return __complex_sinh(__z.__rep()); }
846
#else
847
  template<typename _Tp>
848
    inline complex<_Tp>
849
    sinh(const complex<_Tp>& __z) { return __complex_sinh(__z); }
850
#endif
851
852
  // 26.2.8/13 sqrt(__z): Returns the complex square root of __z.
853
  //                     The branch cut is on the negative axis.
854
  template<typename _Tp>
855
    complex<_Tp>
856
    __complex_sqrt(const complex<_Tp>& __z)
857
    {
858
      _Tp __x = __z.real();
859
      _Tp __y = __z.imag();
860
861
      if (__x == _Tp())
862
        {
863
          _Tp __t = sqrt(abs(__y) / 2);
864
          return complex<_Tp>(__t, __y < _Tp() ? -__t : __t);
865
        }
866
      else
867
        {
868
          _Tp __t = sqrt(2 * (std::abs(__z) + abs(__x)));
869
          _Tp __u = __t / 2;
870
          return __x > _Tp()
871
            ? complex<_Tp>(__u, __y / __t)
872
            : complex<_Tp>(abs(__y) / __t, __y < _Tp() ? -__u : __u);
873
        }
874
    }
875
876
#if _GLIBCXX_USE_C99_COMPLEX
877
  inline __complex__ float
878
  __complex_sqrt(__complex__ float __z) { return __builtin_csqrtf(__z); }
879
880
  inline __complex__ double
881
  __complex_sqrt(__complex__ double __z) { return __builtin_csqrt(__z); }
882
883
  inline __complex__ long double
884
  __complex_sqrt(const __complex__ long double& __z)
885
  { return __builtin_csqrtl(__z); }
886
887
  template<typename _Tp>
888
    inline complex<_Tp>
889
    sqrt(const complex<_Tp>& __z) { return __complex_sqrt(__z.__rep()); }
890
#else
891
  template<typename _Tp>
892
    inline complex<_Tp>
893
    sqrt(const complex<_Tp>& __z) { return __complex_sqrt(__z); }
894
#endif
895
896
  // 26.2.8/14 tan(__z):  Return the complex tangent of __z.
897
  
898
  template<typename _Tp>
899
    inline complex<_Tp>
900
    __complex_tan(const complex<_Tp>& __z)
901
    { return std::sin(__z) / std::cos(__z); }
902
903
#if _GLIBCXX_USE_C99_COMPLEX
904
  inline __complex__ float
905
  __complex_tan(__complex__ float __z) { return __builtin_ctanf(__z); }
906
907
  inline __complex__ double
908
  __complex_tan(__complex__ double __z) { return __builtin_ctan(__z); }
909
910
  inline __complex__ long double
911
  __complex_tan(const __complex__ long double& __z)
912
  { return __builtin_ctanl(__z); }
913
914
  template<typename _Tp>
915
    inline complex<_Tp>
916
    tan(const complex<_Tp>& __z) { return __complex_tan(__z.__rep()); }
917
#else
918
  template<typename _Tp>
919
    inline complex<_Tp>
920
    tan(const complex<_Tp>& __z) { return __complex_tan(__z); }
921
#endif
922
923
924
  // 26.2.8/15 tanh(__z):  Returns the hyperbolic tangent of __z.
925
  
926
  template<typename _Tp>
927
    inline complex<_Tp>
928
    __complex_tanh(const complex<_Tp>& __z)
929
    { return std::sinh(__z) / std::cosh(__z); }
930
931
#if _GLIBCXX_USE_C99_COMPLEX
932
  inline __complex__ float
933
  __complex_tanh(__complex__ float __z) { return __builtin_ctanhf(__z); }
934
935
  inline __complex__ double
936
  __complex_tanh(__complex__ double __z) { return __builtin_ctanh(__z); }
937
938
  inline __complex__ long double
939
  __complex_tanh(const __complex__ long double& __z)
940
  { return __builtin_ctanhl(__z); }
941
942
  template<typename _Tp>
943
    inline complex<_Tp>
944
    tanh(const complex<_Tp>& __z) { return __complex_tanh(__z.__rep()); }
945
#else
946
  template<typename _Tp>
947
    inline complex<_Tp>
948
    tanh(const complex<_Tp>& __z) { return __complex_tanh(__z); }
949
#endif
950
951
952
  // 26.2.8/9  pow(__x, __y): Returns the complex power base of __x
953
  //                          raised to the __y-th power.  The branch
954
  //                          cut is on the negative axis.
955
  template<typename _Tp>
956
    complex<_Tp>
957
    __complex_pow_unsigned(complex<_Tp> __x, unsigned __n)
958
    {
959
      complex<_Tp> __y = __n % 2 ? __x : complex<_Tp>(1);
960
961
      while (__n >>= 1)
962
        {
963
          __x *= __x;
964
          if (__n % 2)
965
            __y *= __x;
966
        }
967
968
      return __y;
969
    }
970
971
  // In C++11 mode we used to implement the resolution of
972
  // DR 844. complex pow return type is ambiguous.
973
  // thus the following overload was disabled in that mode.  However, doing
974
  // that causes all sorts of issues, see, for example:
975
  //   http://gcc.gnu.org/ml/libstdc++/2013-01/msg00058.html
976
  // and also PR57974.
977
  template<typename _Tp>
978
    inline complex<_Tp>
979
    pow(const complex<_Tp>& __z, int __n)
980
    {
981
      return __n < 0
982
	? complex<_Tp>(1) / std::__complex_pow_unsigned(__z, -(unsigned)__n)
983
        : std::__complex_pow_unsigned(__z, __n);
984
    }
985
986
  template<typename _Tp>
987
    complex<_Tp>
988
    pow(const complex<_Tp>& __x, const _Tp& __y)
989
    {
990
#ifndef _GLIBCXX_USE_C99_COMPLEX
991
      if (__x == _Tp())
992
	return _Tp();
993
#endif
994
      if (__x.imag() == _Tp() && __x.real() > _Tp())
995
        return pow(__x.real(), __y);
996
997
      complex<_Tp> __t = std::log(__x);
998
      return std::polar(exp(__y * __t.real()), __y * __t.imag());
999
    }
1000
1001
  template<typename _Tp>
1002
    inline complex<_Tp>
1003
    __complex_pow(const complex<_Tp>& __x, const complex<_Tp>& __y)
1004
    { return __x == _Tp() ? _Tp() : std::exp(__y * std::log(__x)); }
1005
1006
#if _GLIBCXX_USE_C99_COMPLEX
1007
  inline __complex__ float
1008
  __complex_pow(__complex__ float __x, __complex__ float __y)
1009
  { return __builtin_cpowf(__x, __y); }
1010
1011
  inline __complex__ double
1012
  __complex_pow(__complex__ double __x, __complex__ double __y)
1013
  { return __builtin_cpow(__x, __y); }
1014
1015
  inline __complex__ long double
1016
  __complex_pow(const __complex__ long double& __x,
1017
		const __complex__ long double& __y)
1018
  { return __builtin_cpowl(__x, __y); }
1019
1020
  template<typename _Tp>
1021
    inline complex<_Tp>
1022
    pow(const complex<_Tp>& __x, const complex<_Tp>& __y)
1023
    { return __complex_pow(__x.__rep(), __y.__rep()); }
1024
#else
1025
  template<typename _Tp>
1026
    inline complex<_Tp>
1027
    pow(const complex<_Tp>& __x, const complex<_Tp>& __y)
1028
    { return __complex_pow(__x, __y); }
1029
#endif
1030
1031
  template<typename _Tp>
1032
    inline complex<_Tp>
1033
    pow(const _Tp& __x, const complex<_Tp>& __y)
1034
    {
1035
      return __x > _Tp() ? std::polar(pow(__x, __y.real()),
1036
				      __y.imag() * log(__x))
1037
	                 : std::pow(complex<_Tp>(__x), __y);
1038
    }
1039
1040
  /// 26.2.3  complex specializations
1041
  /// complex<float> specialization
1042
  template<>
1043
    struct complex<float>
1044
    {
1045
      typedef float value_type;
1046
      typedef __complex__ float _ComplexT;
1047
1048
      _GLIBCXX_CONSTEXPR complex(_ComplexT __z) : _M_value(__z) { }
1049
1050
      _GLIBCXX_CONSTEXPR complex(float __r = 0.0f, float __i = 0.0f)
1051
#if __cplusplus >= 201103L
1052
      : _M_value{ __r, __i } { }
1053
#else
1054
      {
1055
	__real__ _M_value = __r;
1056
	__imag__ _M_value = __i;
1057
      }
1058
#endif
1059
1060
      explicit _GLIBCXX_CONSTEXPR complex(const complex<double>&);
1061
      explicit _GLIBCXX_CONSTEXPR complex(const complex<long double>&);	
1062
1063
#if __cplusplus >= 201103L
1064
      // _GLIBCXX_RESOLVE_LIB_DEFECTS
1065
      // DR 387. std::complex over-encapsulated.
1066
      __attribute ((__abi_tag__ ("cxx11")))
1067
      constexpr float 
1068
      real() const { return __real__ _M_value; }
1069
1070
      __attribute ((__abi_tag__ ("cxx11")))
1071
      constexpr float 
1072
      imag() const { return __imag__ _M_value; }
1073
#else
1074
      float& 
1075
      real() { return __real__ _M_value; }
1076
1077
      const float& 
1078
      real() const { return __real__ _M_value; }      
1079
1080
      float& 
1081
      imag() { return __imag__ _M_value; }
1082
1083
      const float& 
1084
      imag() const { return __imag__ _M_value; }
1085
#endif
1086
1087
      // _GLIBCXX_RESOLVE_LIB_DEFECTS
1088
      // DR 387. std::complex over-encapsulated.
1089
      void 
1090
      real(float __val) { __real__ _M_value = __val; }
1091
1092
      void 
1093
      imag(float __val) { __imag__ _M_value = __val; }
1094
1095
      complex&
1096
      operator=(float __f);
1097
1098
      complex&
1099
      operator+=(float __f)
1100
      {
1101
	_M_value += __f;
1102
	return *this;
1103
      }
1104
1105
      complex&
1106
      operator-=(float __f)
1107
      {
1108
	_M_value -= __f;
1109
	return *this;
1110
      }
1111
1112
      complex&
1113
      operator*=(float __f)
1114
      {
1115
	_M_value *= __f;
1116
	return *this;
1117
      }
1118
1119
      complex&
1120
      operator/=(float __f)
1121
      {
1122
	_M_value /= __f;
1123
	return *this;
1124
      }
1125
1126
      // Let the compiler synthesize the copy and assignment
1127
      // operator.  It always does a pretty good job.
1128
      // complex& operator=(const complex&);
1129
1130
      template<typename _Tp>
1131
        complex&
1132
        operator=(const complex<_Tp>&  __z)
1133
	{
1134
	  __real__ _M_value = __z.real();
1135
	  __imag__ _M_value = __z.imag();
1136
	  return *this;
1137
	}
1138
1139
      template<typename _Tp>
1140
        complex&
1141
        operator+=(const complex<_Tp>& __z)
1142
	{
1143
	  __real__ _M_value += __z.real();
1144
	  __imag__ _M_value += __z.imag();
1145
	  return *this;
1146
	}
1147
1148
      template<class _Tp>
1149
        complex&
1150
        operator-=(const complex<_Tp>& __z)
1151
	{
1152
	  __real__ _M_value -= __z.real();
1153
	  __imag__ _M_value -= __z.imag();
1154
	  return *this;
1155
	}
1156
1157
      template<class _Tp>
1158
        complex&
1159
        operator*=(const complex<_Tp>& __z)
1160
	{
1161
	  _ComplexT __t;
1162
	  __real__ __t = __z.real();
1163
	  __imag__ __t = __z.imag();
1164
	  _M_value *= __t;
1165
	  return *this;
1166
	}
1167
1168
      template<class _Tp>
1169
        complex&
1170
        operator/=(const complex<_Tp>& __z)
1171
	{
1172
	  _ComplexT __t;
1173
	  __real__ __t = __z.real();
1174
	  __imag__ __t = __z.imag();
1175
	  _M_value /= __t;
1176
	  return *this;
1177
	}
1178
1179
      _GLIBCXX_USE_CONSTEXPR _ComplexT __rep() const { return _M_value; }
1180
1181
    private:
1182
      _ComplexT _M_value;
1183
    };
1184
1185
  /// 26.2.3  complex specializations
1186
  /// complex<double> specialization
1187
  template<>
1188
    struct complex<double>
1189
    {
1190
      typedef double value_type;
1191
      typedef __complex__ double _ComplexT;
1192
1193
      _GLIBCXX_CONSTEXPR complex(_ComplexT __z) : _M_value(__z) { }
1194
1195
      _GLIBCXX_CONSTEXPR complex(double __r = 0.0, double __i = 0.0)
1196
#if __cplusplus >= 201103L
1197
      : _M_value{ __r, __i } { }
1198
#else
1199
      {
1200
	__real__ _M_value = __r;
1201
	__imag__ _M_value = __i;
1202
      }
1203
#endif
1204
1205
      _GLIBCXX_CONSTEXPR complex(const complex<float>& __z)
1206
      : _M_value(__z.__rep()) { }
1207
1208
      explicit _GLIBCXX_CONSTEXPR complex(const complex<long double>&);	
1209
1210
#if __cplusplus >= 201103L
1211
      // _GLIBCXX_RESOLVE_LIB_DEFECTS
1212
      // DR 387. std::complex over-encapsulated.
1213
      __attribute ((__abi_tag__ ("cxx11")))
1214
      constexpr double 
1215
      real() const { return __real__ _M_value; }
1216
1217
      __attribute ((__abi_tag__ ("cxx11")))
1218
      constexpr double 
1219
      imag() const { return __imag__ _M_value; }
1220
#else
1221
      double& 
1222
      real() { return __real__ _M_value; }
1223
1224
      const double& 
1225
      real() const { return __real__ _M_value; }
1226
1227
      double& 
1228
      imag() { return __imag__ _M_value; }
1229
1230
      const double& 
1231
      imag() const { return __imag__ _M_value; }
1232
#endif
1233
1234
      // _GLIBCXX_RESOLVE_LIB_DEFECTS
1235
      // DR 387. std::complex over-encapsulated.
1236
      void 
1237
      real(double __val) { __real__ _M_value = __val; }
1238
1239
      void 
1240
      imag(double __val) { __imag__ _M_value = __val; }
1241
1242
      complex&
1243
      operator=(double __d);
1244
1245
      complex&
1246
      operator+=(double __d)
1247
      {
1248
	_M_value += __d;
1249
	return *this;
1250
      }
1251
	
1252
      complex&
1253
      operator-=(double __d)
1254
      {
1255
	_M_value -= __d;
1256
	return *this;
1257
      }
1258
1259
      complex&
1260
      operator*=(double __d)
1261
      {
1262
	_M_value *= __d;
1263
	return *this;
1264
      }
1265
1266
      complex&
1267
      operator/=(double __d)
1268
      {
1269
	_M_value /= __d;
1270
	return *this;
1271
      }
1272
1273
      // The compiler will synthesize this, efficiently.
1274
      // complex& operator=(const complex&);
1275
1276
      template<typename _Tp>
1277
        complex&
1278
        operator=(const complex<_Tp>& __z)
1279
	{
1280
	  __real__ _M_value = __z.real();
1281
	  __imag__ _M_value = __z.imag();
1282
	  return *this;
1283
	}
1284
1285
      template<typename _Tp>
1286
        complex&
1287
        operator+=(const complex<_Tp>& __z)
1288
	{
1289
	  __real__ _M_value += __z.real();
1290
	  __imag__ _M_value += __z.imag();
1291
	  return *this;
1292
	}
1293
1294
      template<typename _Tp>
1295
        complex&
1296
        operator-=(const complex<_Tp>& __z)
1297
	{
1298
	  __real__ _M_value -= __z.real();
1299
	  __imag__ _M_value -= __z.imag();
1300
	  return *this;
1301
	}
1302
1303
      template<typename _Tp>
1304
        complex&
1305
        operator*=(const complex<_Tp>& __z)
1306
	{
1307
	  _ComplexT __t;
1308
	  __real__ __t = __z.real();
1309
	  __imag__ __t = __z.imag();
1310
	  _M_value *= __t;
1311
	  return *this;
1312
	}
1313
1314
      template<typename _Tp>
1315
        complex&
1316
        operator/=(const complex<_Tp>& __z)
1317
	{
1318
	  _ComplexT __t;
1319
	  __real__ __t = __z.real();
1320
	  __imag__ __t = __z.imag();
1321
	  _M_value /= __t;
1322
	  return *this;
1323
	}
1324
1325
      _GLIBCXX_USE_CONSTEXPR _ComplexT __rep() const { return _M_value; }
1326
1327
    private:
1328
      _ComplexT _M_value;
1329
    };
1330
1331
  /// 26.2.3  complex specializations
1332
  /// complex<long double> specialization
1333
  template<>
1334
    struct complex<long double>
1335
    {
1336
      typedef long double value_type;
1337
      typedef __complex__ long double _ComplexT;
1338
1339
      _GLIBCXX_CONSTEXPR complex(_ComplexT __z) : _M_value(__z) { }
1340
1341
      _GLIBCXX_CONSTEXPR complex(long double __r = 0.0L, 
1342
				 long double __i = 0.0L)
1343
#if __cplusplus >= 201103L
1344
      : _M_value{ __r, __i } { }
1345
#else
1346
      {
1347
	__real__ _M_value = __r;
1348
	__imag__ _M_value = __i;
1349
      }
1350
#endif
1351
1352
      _GLIBCXX_CONSTEXPR complex(const complex<float>& __z)
1353
      : _M_value(__z.__rep()) { }
1354
1355
      _GLIBCXX_CONSTEXPR complex(const complex<double>& __z)
1356
      : _M_value(__z.__rep()) { }
1357
1358
#if __cplusplus >= 201103L
1359
      // _GLIBCXX_RESOLVE_LIB_DEFECTS
1360
      // DR 387. std::complex over-encapsulated.
1361
      __attribute ((__abi_tag__ ("cxx11")))
1362
      constexpr long double 
1363
      real() const { return __real__ _M_value; }
1364
1365
      __attribute ((__abi_tag__ ("cxx11")))
1366
      constexpr long double 
1367
      imag() const { return __imag__ _M_value; }
1368
#else
1369
      long double& 
1370
      real() { return __real__ _M_value; }
1371
1372
      const long double& 
1373
      real() const { return __real__ _M_value; }
1374
1375
      long double& 
1376
      imag() { return __imag__ _M_value; }
1377
1378
      const long double& 
1379
      imag() const { return __imag__ _M_value; }
1380
#endif
1381
1382
      // _GLIBCXX_RESOLVE_LIB_DEFECTS
1383
      // DR 387. std::complex over-encapsulated.
1384
      void 
1385
      real(long double __val) { __real__ _M_value = __val; }
1386
1387
      void 
1388
      imag(long double __val) { __imag__ _M_value = __val; }
1389
1390
      complex&
1391
      operator=(long double __r);
1392
1393
      complex&
1394
      operator+=(long double __r)
1395
      {
1396
	_M_value += __r;
1397
	return *this;
1398
      }
1399
1400
      complex&
1401
      operator-=(long double __r)
1402
      {
1403
	_M_value -= __r;
1404
	return *this;
1405
      }
1406
1407
      complex&
1408
      operator*=(long double __r)
1409
      {
1410
	_M_value *= __r;
1411
	return *this;
1412
      }
1413
1414
      complex&
1415
      operator/=(long double __r)
1416
      {
1417
	_M_value /= __r;
1418
	return *this;
1419
      }
1420
1421
      // The compiler knows how to do this efficiently
1422
      // complex& operator=(const complex&);
1423
1424
      template<typename _Tp>
1425
        complex&
1426
        operator=(const complex<_Tp>& __z)
1427
	{
1428
	  __real__ _M_value = __z.real();
1429
	  __imag__ _M_value = __z.imag();
1430
	  return *this;
1431
	}
1432
1433
      template<typename _Tp>
1434
        complex&
1435
	operator+=(const complex<_Tp>& __z)
1436
	{
1437
	  __real__ _M_value += __z.real();
1438
	  __imag__ _M_value += __z.imag();
1439
	  return *this;
1440
	}
1441
1442
      template<typename _Tp>
1443
        complex&
1444
	operator-=(const complex<_Tp>& __z)
1445
	{
1446
	  __real__ _M_value -= __z.real();
1447
	  __imag__ _M_value -= __z.imag();
1448
	  return *this;
1449
	}
1450
1451
      template<typename _Tp>
1452
        complex&
1453
	operator*=(const complex<_Tp>& __z)
1454
	{
1455
	  _ComplexT __t;
1456
	  __real__ __t = __z.real();
1457
	  __imag__ __t = __z.imag();
1458
	  _M_value *= __t;
1459
	  return *this;
1460
	}
1461
1462
      template<typename _Tp>
1463
        complex&
1464
	operator/=(const complex<_Tp>& __z)
1465
	{
1466
	  _ComplexT __t;
1467
	  __real__ __t = __z.real();
1468
	  __imag__ __t = __z.imag();
1469
	  _M_value /= __t;
1470
	  return *this;
1471
	}
1472
1473
      _GLIBCXX_USE_CONSTEXPR _ComplexT __rep() const { return _M_value; }
1474
1475
    private:
1476
      _ComplexT _M_value;
1477
    };
1478
1479
  // These bits have to be at the end of this file, so that the
1480
  // specializations have all been defined.
1481
  inline _GLIBCXX_CONSTEXPR
1482
  complex<float>::complex(const complex<double>& __z)
1483
  : _M_value(__z.__rep()) { }
1484
1485
  inline _GLIBCXX_CONSTEXPR
1486
  complex<float>::complex(const complex<long double>& __z)
1487
  : _M_value(__z.__rep()) { }
1488
1489
  inline _GLIBCXX_CONSTEXPR
1490
  complex<double>::complex(const complex<long double>& __z)
1491
  : _M_value(__z.__rep()) { }
1492
1493
  // Inhibit implicit instantiations for required instantiations,
1494
  // which are defined via explicit instantiations elsewhere.
1495
  // NB:  This syntax is a GNU extension.
1496
#if _GLIBCXX_EXTERN_TEMPLATE
1497
  extern template istream& operator>>(istream&, complex<float>&);
1498
  extern template ostream& operator<<(ostream&, const complex<float>&);
1499
  extern template istream& operator>>(istream&, complex<double>&);
1500
  extern template ostream& operator<<(ostream&, const complex<double>&);
1501
  extern template istream& operator>>(istream&, complex<long double>&);
1502
  extern template ostream& operator<<(ostream&, const complex<long double>&);
1503
1504
#ifdef _GLIBCXX_USE_WCHAR_T
1505
  extern template wistream& operator>>(wistream&, complex<float>&);
1506
  extern template wostream& operator<<(wostream&, const complex<float>&);
1507
  extern template wistream& operator>>(wistream&, complex<double>&);
1508
  extern template wostream& operator<<(wostream&, const complex<double>&);
1509
  extern template wistream& operator>>(wistream&, complex<long double>&);
1510
  extern template wostream& operator<<(wostream&, const complex<long double>&);
1511
#endif
1512
#endif
1513
1514
  // @} group complex_numbers
1515
1516
_GLIBCXX_END_NAMESPACE_VERSION
1517
} // namespace
1518
1519
namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
1520
{
1521
_GLIBCXX_BEGIN_NAMESPACE_VERSION
1522
1523
  // See ext/type_traits.h for the primary template.
1524
  template<typename _Tp, typename _Up>
1525
    struct __promote_2<std::complex<_Tp>, _Up>
1526
    {
1527
    public:
1528
      typedef std::complex<typename __promote_2<_Tp, _Up>::__type> __type;
1529
    };
1530
1531
  template<typename _Tp, typename _Up>
1532
    struct __promote_2<_Tp, std::complex<_Up> >
1533
    {
1534
    public:
1535
      typedef std::complex<typename __promote_2<_Tp, _Up>::__type> __type;
1536
    };
1537
  
1538
  template<typename _Tp, typename _Up>
1539
    struct __promote_2<std::complex<_Tp>, std::complex<_Up> >
1540
    {
1541
    public:
1542
      typedef std::complex<typename __promote_2<_Tp, _Up>::__type> __type;
1543
    };
1544
1545
_GLIBCXX_END_NAMESPACE_VERSION
1546
} // namespace
1547
1548
#if __cplusplus >= 201103L
1549
1550
namespace std _GLIBCXX_VISIBILITY(default)
1551
{
1552
_GLIBCXX_BEGIN_NAMESPACE_VERSION
1553
1554
  // Forward declarations.
1555
  template<typename _Tp> std::complex<_Tp> acos(const std::complex<_Tp>&);
1556
  template<typename _Tp> std::complex<_Tp> asin(const std::complex<_Tp>&);
1557
  template<typename _Tp> std::complex<_Tp> atan(const std::complex<_Tp>&);
1558
1559
  template<typename _Tp> std::complex<_Tp> acosh(const std::complex<_Tp>&);
1560
  template<typename _Tp> std::complex<_Tp> asinh(const std::complex<_Tp>&);
1561
  template<typename _Tp> std::complex<_Tp> atanh(const std::complex<_Tp>&);
1562
  // DR 595.
1563
  template<typename _Tp> _Tp               fabs(const std::complex<_Tp>&);
1564
1565
  template<typename _Tp>
1566
    inline std::complex<_Tp>
1567
    __complex_acos(const std::complex<_Tp>& __z)
1568
    {
1569
      const std::complex<_Tp> __t = std::asin(__z);
1570
      const _Tp __pi_2 = 1.5707963267948966192313216916397514L;
1571
      return std::complex<_Tp>(__pi_2 - __t.real(), -__t.imag());
1572
    }
1573
1574
#if _GLIBCXX_USE_C99_COMPLEX_TR1
1575
  inline __complex__ float
1576
  __complex_acos(__complex__ float __z)
1577
  { return __builtin_cacosf(__z); }
1578
1579
  inline __complex__ double
1580
  __complex_acos(__complex__ double __z)
1581
  { return __builtin_cacos(__z); }
1582
1583
  inline __complex__ long double
1584
  __complex_acos(const __complex__ long double& __z)
1585
  { return __builtin_cacosl(__z); }
1586
1587
  template<typename _Tp>
1588
    inline std::complex<_Tp>
1589
    acos(const std::complex<_Tp>& __z)
1590
    { return __complex_acos(__z.__rep()); }
1591
#else
1592
  /// acos(__z) [8.1.2].
1593
  //  Effects:  Behaves the same as C99 function cacos, defined
1594
  //            in subclause 7.3.5.1.
1595
  template<typename _Tp>
1596
    inline std::complex<_Tp>
1597
    acos(const std::complex<_Tp>& __z)
1598
    { return __complex_acos(__z); }
1599
#endif
1600
1601
  template<typename _Tp>
1602
    inline std::complex<_Tp>
1603
    __complex_asin(const std::complex<_Tp>& __z)
1604
    {
1605
      std::complex<_Tp> __t(-__z.imag(), __z.real());
1606
      __t = std::asinh(__t);
1607
      return std::complex<_Tp>(__t.imag(), -__t.real());
1608
    }
1609
1610
#if _GLIBCXX_USE_C99_COMPLEX_TR1
1611
  inline __complex__ float
1612
  __complex_asin(__complex__ float __z)
1613
  { return __builtin_casinf(__z); }
1614
1615
  inline __complex__ double
1616
  __complex_asin(__complex__ double __z)
1617
  { return __builtin_casin(__z); }
1618
1619
  inline __complex__ long double
1620
  __complex_asin(const __complex__ long double& __z)
1621
  { return __builtin_casinl(__z); }
1622
1623
  template<typename _Tp>
1624
    inline std::complex<_Tp>
1625
    asin(const std::complex<_Tp>& __z)
1626
    { return __complex_asin(__z.__rep()); }
1627
#else
1628
  /// asin(__z) [8.1.3].
1629
  //  Effects:  Behaves the same as C99 function casin, defined
1630
  //            in subclause 7.3.5.2.
1631
  template<typename _Tp>
1632
    inline std::complex<_Tp>
1633
    asin(const std::complex<_Tp>& __z)
1634
    { return __complex_asin(__z); }
1635
#endif
1636
  
1637
  template<typename _Tp>
1638
    std::complex<_Tp>
1639
    __complex_atan(const std::complex<_Tp>& __z)
1640
    {
1641
      const _Tp __r2 = __z.real() * __z.real();
1642
      const _Tp __x = _Tp(1.0) - __r2 - __z.imag() * __z.imag();
1643
1644
      _Tp __num = __z.imag() + _Tp(1.0);
1645
      _Tp __den = __z.imag() - _Tp(1.0);
1646
1647
      __num = __r2 + __num * __num;
1648
      __den = __r2 + __den * __den;
1649
1650
      return std::complex<_Tp>(_Tp(0.5) * atan2(_Tp(2.0) * __z.real(), __x),
1651
			       _Tp(0.25) * log(__num / __den));
1652
    }
1653
1654
#if _GLIBCXX_USE_C99_COMPLEX_TR1
1655
  inline __complex__ float
1656
  __complex_atan(__complex__ float __z)
1657
  { return __builtin_catanf(__z); }
1658
1659
  inline __complex__ double
1660
  __complex_atan(__complex__ double __z)
1661
  { return __builtin_catan(__z); }
1662
1663
  inline __complex__ long double
1664
  __complex_atan(const __complex__ long double& __z)
1665
  { return __builtin_catanl(__z); }
1666
1667
  template<typename _Tp>
1668
    inline std::complex<_Tp>
1669
    atan(const std::complex<_Tp>& __z)
1670
    { return __complex_atan(__z.__rep()); }
1671
#else
1672
  /// atan(__z) [8.1.4].
1673
  //  Effects:  Behaves the same as C99 function catan, defined
1674
  //            in subclause 7.3.5.3.
1675
  template<typename _Tp>
1676
    inline std::complex<_Tp>
1677
    atan(const std::complex<_Tp>& __z)
1678
    { return __complex_atan(__z); }
1679
#endif
1680
1681
  template<typename _Tp>
1682
    std::complex<_Tp>
1683
    __complex_acosh(const std::complex<_Tp>& __z)
1684
    {
1685
      // Kahan's formula.
1686
      return _Tp(2.0) * std::log(std::sqrt(_Tp(0.5) * (__z + _Tp(1.0)))
1687
				 + std::sqrt(_Tp(0.5) * (__z - _Tp(1.0))));
1688
    }
1689
1690
#if _GLIBCXX_USE_C99_COMPLEX_TR1
1691
  inline __complex__ float
1692
  __complex_acosh(__complex__ float __z)
1693
  { return __builtin_cacoshf(__z); }
1694
1695
  inline __complex__ double
1696
  __complex_acosh(__complex__ double __z)
1697
  { return __builtin_cacosh(__z); }
1698
1699
  inline __complex__ long double
1700
  __complex_acosh(const __complex__ long double& __z)
1701
  { return __builtin_cacoshl(__z); }
1702
1703
  template<typename _Tp>
1704
    inline std::complex<_Tp>
1705
    acosh(const std::complex<_Tp>& __z)
1706
    { return __complex_acosh(__z.__rep()); }
1707
#else
1708
  /// acosh(__z) [8.1.5].
1709
  //  Effects:  Behaves the same as C99 function cacosh, defined
1710
  //            in subclause 7.3.6.1.
1711
  template<typename _Tp>
1712
    inline std::complex<_Tp>
1713
    acosh(const std::complex<_Tp>& __z)
1714
    { return __complex_acosh(__z); }
1715
#endif
1716
1717
  template<typename _Tp>
1718
    std::complex<_Tp>
1719
    __complex_asinh(const std::complex<_Tp>& __z)
1720
    {
1721
      std::complex<_Tp> __t((__z.real() - __z.imag())
1722
			    * (__z.real() + __z.imag()) + _Tp(1.0),
1723
			    _Tp(2.0) * __z.real() * __z.imag());
1724
      __t = std::sqrt(__t);
1725
1726
      return std::log(__t + __z);
1727
    }
1728
1729
#if _GLIBCXX_USE_C99_COMPLEX_TR1
1730
  inline __complex__ float
1731
  __complex_asinh(__complex__ float __z)
1732
  { return __builtin_casinhf(__z); }
1733
1734
  inline __complex__ double
1735
  __complex_asinh(__complex__ double __z)
1736
  { return __builtin_casinh(__z); }
1737
1738
  inline __complex__ long double
1739
  __complex_asinh(const __complex__ long double& __z)
1740
  { return __builtin_casinhl(__z); }
1741
1742
  template<typename _Tp>
1743
    inline std::complex<_Tp>
1744
    asinh(const std::complex<_Tp>& __z)
1745
    { return __complex_asinh(__z.__rep()); }
1746
#else
1747
  /// asinh(__z) [8.1.6].
1748
  //  Effects:  Behaves the same as C99 function casin, defined
1749
  //            in subclause 7.3.6.2.
1750
  template<typename _Tp>
1751
    inline std::complex<_Tp>
1752
    asinh(const std::complex<_Tp>& __z)
1753
    { return __complex_asinh(__z); }
1754
#endif
1755
1756
  template<typename _Tp>
1757
    std::complex<_Tp>
1758
    __complex_atanh(const std::complex<_Tp>& __z)
1759
    {
1760
      const _Tp __i2 = __z.imag() * __z.imag();
1761
      const _Tp __x = _Tp(1.0) - __i2 - __z.real() * __z.real();
1762
1763
      _Tp __num = _Tp(1.0) + __z.real();
1764
      _Tp __den = _Tp(1.0) - __z.real();
1765
1766
      __num = __i2 + __num * __num;
1767
      __den = __i2 + __den * __den;
1768
1769
      return std::complex<_Tp>(_Tp(0.25) * (log(__num) - log(__den)),
1770
			       _Tp(0.5) * atan2(_Tp(2.0) * __z.imag(), __x));
1771
    }
1772
1773
#if _GLIBCXX_USE_C99_COMPLEX_TR1
1774
  inline __complex__ float
1775
  __complex_atanh(__complex__ float __z)
1776
  { return __builtin_catanhf(__z); }
1777
1778
  inline __complex__ double
1779
  __complex_atanh(__complex__ double __z)
1780
  { return __builtin_catanh(__z); }
1781
1782
  inline __complex__ long double
1783
  __complex_atanh(const __complex__ long double& __z)
1784
  { return __builtin_catanhl(__z); }
1785
1786
  template<typename _Tp>
1787
    inline std::complex<_Tp>
1788
    atanh(const std::complex<_Tp>& __z)
1789
    { return __complex_atanh(__z.__rep()); }
1790
#else
1791
  /// atanh(__z) [8.1.7].
1792
  //  Effects:  Behaves the same as C99 function catanh, defined
1793
  //            in subclause 7.3.6.3.
1794
  template<typename _Tp>
1795
    inline std::complex<_Tp>
1796
    atanh(const std::complex<_Tp>& __z)
1797
    { return __complex_atanh(__z); }
1798
#endif
1799
1800
  template<typename _Tp>
1801
    inline _Tp
1802
    /// fabs(__z) [8.1.8].
1803
    //  Effects:  Behaves the same as C99 function cabs, defined
1804
    //            in subclause 7.3.8.1.
1805
    fabs(const std::complex<_Tp>& __z)
1806
    { return std::abs(__z); }
1807
1808
  /// Additional overloads [8.1.9].
1809
  template<typename _Tp>
1810
    inline typename __gnu_cxx::__promote<_Tp>::__type
1811
    arg(_Tp __x)
1812
    {
1813
      typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
1814
#if (_GLIBCXX_USE_C99_MATH && !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC)
1815
      return std::signbit(__x) ? __type(3.1415926535897932384626433832795029L)
1816
	                       : __type();
1817
#else
1818
      return std::arg(std::complex<__type>(__x));
1819
#endif
1820
    }
1821
1822
  template<typename _Tp>
1823
    inline typename __gnu_cxx::__promote<_Tp>::__type
1824
    imag(_Tp)
1825
    { return _Tp(); }
1826
1827
  template<typename _Tp>
1828
    inline typename __gnu_cxx::__promote<_Tp>::__type
1829
    norm(_Tp __x)
1830
    {
1831
      typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
1832
      return __type(__x) * __type(__x);
1833
    }
1834
1835
  template<typename _Tp>
1836
    inline typename __gnu_cxx::__promote<_Tp>::__type
1837
    real(_Tp __x)
1838
    { return __x; }
1839
1840
  template<typename _Tp, typename _Up>
1841
    inline std::complex<typename __gnu_cxx::__promote_2<_Tp, _Up>::__type>
1842
    pow(const std::complex<_Tp>& __x, const _Up& __y)
1843
    {
1844
      typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1845
      return std::pow(std::complex<__type>(__x), __type(__y));
1846
    }
1847
1848
  template<typename _Tp, typename _Up>
1849
    inline std::complex<typename __gnu_cxx::__promote_2<_Tp, _Up>::__type>
1850
    pow(const _Tp& __x, const std::complex<_Up>& __y)
1851
    {
1852
      typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1853
      return std::pow(__type(__x), std::complex<__type>(__y));
1854
    }
1855
1856
  template<typename _Tp, typename _Up>
1857
    inline std::complex<typename __gnu_cxx::__promote_2<_Tp, _Up>::__type>
1858
    pow(const std::complex<_Tp>& __x, const std::complex<_Up>& __y)
1859
    {
1860
      typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1861
      return std::pow(std::complex<__type>(__x),
1862
		      std::complex<__type>(__y));
1863
    }
1864
1865
  // Forward declarations.
1866
  // DR 781.
1867
  template<typename _Tp> std::complex<_Tp> proj(const std::complex<_Tp>&);
1868
1869
  template<typename _Tp>
1870
    std::complex<_Tp>
1871
    __complex_proj(const std::complex<_Tp>& __z)
1872
    {
1873
      const _Tp __den = (__z.real() * __z.real()
1874
			 + __z.imag() * __z.imag() + _Tp(1.0));
1875
1876
      return std::complex<_Tp>((_Tp(2.0) * __z.real()) / __den,
1877
			       (_Tp(2.0) * __z.imag()) / __den);
1878
    }
1879
1880
#if _GLIBCXX_USE_C99_COMPLEX
1881
  inline __complex__ float
1882
  __complex_proj(__complex__ float __z)
1883
  { return __builtin_cprojf(__z); }
1884
1885
  inline __complex__ double
1886
  __complex_proj(__complex__ double __z)
1887
  { return __builtin_cproj(__z); }
1888
1889
  inline __complex__ long double
1890
  __complex_proj(const __complex__ long double& __z)
1891
  { return __builtin_cprojl(__z); }
1892
1893
  template<typename _Tp>
1894
    inline std::complex<_Tp>
1895
    proj(const std::complex<_Tp>& __z)
1896
    { return __complex_proj(__z.__rep()); }
1897
#else
1898
  template<typename _Tp>
1899
    inline std::complex<_Tp>
1900
    proj(const std::complex<_Tp>& __z)
1901
    { return __complex_proj(__z); }
1902
#endif
1903
1904
  // DR 1137.
1905
  template<typename _Tp>
1906
    inline typename __gnu_cxx::__promote<_Tp>::__type
1907
    proj(_Tp __x)
1908
    { return __x; }
1909
1910
  template<typename _Tp>
1911
    inline typename __gnu_cxx::__promote<_Tp>::__type
1912
    conj(_Tp __x)
1913
    { return __x; }
1914
1915
#if __cplusplus > 201103L
1916
1917
inline namespace literals {
1918
inline namespace complex_literals {
1919
1920
  constexpr std::complex<float>
1921
  operator""if(long double __num)
1922
  { return std::complex<float>{0.0F, static_cast<float>(__num)}; }
1923
1924
  constexpr std::complex<float>
1925
  operator""if(unsigned long long __num)
1926
  { return std::complex<float>{0.0F, static_cast<float>(__num)}; }
1927
1928
  constexpr std::complex<double>
1929
  operator""i(long double __num)
1930
  { return std::complex<double>{0.0, static_cast<double>(__num)}; }
1931
1932
  constexpr std::complex<double>
1933
  operator""i(unsigned long long __num)
1934
  { return std::complex<double>{0.0, static_cast<double>(__num)}; }
1935
1936
  constexpr std::complex<long double>
1937
  operator""il(long double __num)
1938
  { return std::complex<long double>{0.0L, __num}; }
1939
1940
  constexpr std::complex<long double>
1941
  operator""il(unsigned long long __num)
1942
  { return std::complex<long double>{0.0L, static_cast<long double>(__num)}; }
1943
1944
} // inline namespace complex_literals
1945
} // inline namespace literals
1946
1947
#endif // C++14
1948
1949
_GLIBCXX_END_NAMESPACE_VERSION
1950
} // namespace
1951
1952
#endif  // C++11
1953
1954
#endif  /* _GLIBCXX_COMPLEX */
(-)GCC_XML/Support/GCC/4.9/emmintrin.h (+1535 lines)
Line 0 Link Here
1
/* Copyright (C) 2003-2014 Free Software Foundation, Inc.
2
3
   This file is part of GCC.
4
5
   GCC is free software; you can redistribute it and/or modify
6
   it under the terms of the GNU General Public License as published by
7
   the Free Software Foundation; either version 3, or (at your option)
8
   any later version.
9
10
   GCC is distributed in the hope that it will be useful,
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
   GNU General Public License for more details.
14
15
   Under Section 7 of GPL version 3, you are granted additional
16
   permissions described in the GCC Runtime Library Exception, version
17
   3.1, as published by the Free Software Foundation.
18
19
   You should have received a copy of the GNU General Public License and
20
   a copy of the GCC Runtime Library Exception along with this program;
21
   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
22
   <http://www.gnu.org/licenses/>.  */
23
24
/* Implemented from the specification included in the Intel C++ Compiler
25
   User Guide and Reference, version 9.0.  */
26
27
#ifndef _EMMINTRIN_H_INCLUDED
28
#define _EMMINTRIN_H_INCLUDED
29
30
/* We need definitions from the SSE header files*/
31
#include <xmmintrin.h>
32
33
#ifndef __SSE2__
34
#pragma GCC push_options
35
#pragma GCC target("sse2")
36
#define __DISABLE_SSE2__
37
#endif /* __SSE2__ */
38
39
/* SSE2 */
40
typedef double __v2df __attribute__ ((__vector_size__ (16)));
41
typedef long long __v2di __attribute__ ((__vector_size__ (16)));
42
typedef int __v4si __attribute__ ((__vector_size__ (16)));
43
typedef short __v8hi __attribute__ ((__vector_size__ (16)));
44
typedef char __v16qi __attribute__ ((__vector_size__ (16)));
45
46
/* The Intel API is flexible enough that we must allow aliasing with other
47
   vector types, and their scalar components.  */
48
typedef long long __m128i __attribute__ ((__vector_size__ (16), __may_alias__));
49
typedef double __m128d __attribute__ ((__vector_size__ (16), __may_alias__));
50
51
/* Create a selector for use with the SHUFPD instruction.  */
52
#define _MM_SHUFFLE2(fp1,fp0) \
53
 (((fp1) << 1) | (fp0))
54
55
/* Create a vector with element 0 as F and the rest zero.  */
56
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
57
_mm_set_sd (double __F)
58
{
59
  return __extension__ (__m128d){ __F, 0.0 };
60
}
61
62
/* Create a vector with both elements equal to F.  */
63
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
64
_mm_set1_pd (double __F)
65
{
66
  return __extension__ (__m128d){ __F, __F };
67
}
68
69
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
70
_mm_set_pd1 (double __F)
71
{
72
  return _mm_set1_pd (__F);
73
}
74
75
/* Create a vector with the lower value X and upper value W.  */
76
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
77
_mm_set_pd (double __W, double __X)
78
{
79
  return __extension__ (__m128d){ __X, __W };
80
}
81
82
/* Create a vector with the lower value W and upper value X.  */
83
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
84
_mm_setr_pd (double __W, double __X)
85
{
86
  return __extension__ (__m128d){ __W, __X };
87
}
88
89
/* Create an undefined vector.  */
90
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
91
_mm_undefined_pd (void)
92
{
93
  __m128d __Y = __Y;
94
  return __Y;
95
}
96
97
/* Create a vector of zeros.  */
98
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
99
_mm_setzero_pd (void)
100
{
101
  return __extension__ (__m128d){ 0.0, 0.0 };
102
}
103
104
/* Sets the low DPFP value of A from the low value of B.  */
105
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
106
_mm_move_sd (__m128d __A, __m128d __B)
107
{
108
  return (__m128d) __builtin_ia32_movsd ((__v2df)__A, (__v2df)__B);
109
}
110
111
/* Load two DPFP values from P.  The address must be 16-byte aligned.  */
112
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
113
_mm_load_pd (double const *__P)
114
{
115
  return *(__m128d *)__P;
116
}
117
118
/* Load two DPFP values from P.  The address need not be 16-byte aligned.  */
119
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
120
_mm_loadu_pd (double const *__P)
121
{
122
  return __builtin_ia32_loadupd (__P);
123
}
124
125
/* Create a vector with all two elements equal to *P.  */
126
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
127
_mm_load1_pd (double const *__P)
128
{
129
  return _mm_set1_pd (*__P);
130
}
131
132
/* Create a vector with element 0 as *P and the rest zero.  */
133
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
134
_mm_load_sd (double const *__P)
135
{
136
  return _mm_set_sd (*__P);
137
}
138
139
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
140
_mm_load_pd1 (double const *__P)
141
{
142
  return _mm_load1_pd (__P);
143
}
144
145
/* Load two DPFP values in reverse order.  The address must be aligned.  */
146
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
147
_mm_loadr_pd (double const *__P)
148
{
149
  __m128d __tmp = _mm_load_pd (__P);
150
  return __builtin_ia32_shufpd (__tmp, __tmp, _MM_SHUFFLE2 (0,1));
151
}
152
153
/* Store two DPFP values.  The address must be 16-byte aligned.  */
154
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
155
_mm_store_pd (double *__P, __m128d __A)
156
{
157
  *(__m128d *)__P = __A;
158
}
159
160
/* Store two DPFP values.  The address need not be 16-byte aligned.  */
161
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
162
_mm_storeu_pd (double *__P, __m128d __A)
163
{
164
  __builtin_ia32_storeupd (__P, __A);
165
}
166
167
/* Stores the lower DPFP value.  */
168
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
169
_mm_store_sd (double *__P, __m128d __A)
170
{
171
  *__P = __builtin_ia32_vec_ext_v2df (__A, 0);
172
}
173
174
extern __inline double __attribute__((__gnu_inline__, __always_inline__, __artificial__))
175
_mm_cvtsd_f64 (__m128d __A)
176
{
177
  return __builtin_ia32_vec_ext_v2df (__A, 0);
178
}
179
180
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
181
_mm_storel_pd (double *__P, __m128d __A)
182
{
183
  _mm_store_sd (__P, __A);
184
}
185
186
/* Stores the upper DPFP value.  */
187
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
188
_mm_storeh_pd (double *__P, __m128d __A)
189
{
190
  *__P = __builtin_ia32_vec_ext_v2df (__A, 1);
191
}
192
193
/* Store the lower DPFP value across two words.
194
   The address must be 16-byte aligned.  */
195
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
196
_mm_store1_pd (double *__P, __m128d __A)
197
{
198
  _mm_store_pd (__P, __builtin_ia32_shufpd (__A, __A, _MM_SHUFFLE2 (0,0)));
199
}
200
201
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
202
_mm_store_pd1 (double *__P, __m128d __A)
203
{
204
  _mm_store1_pd (__P, __A);
205
}
206
207
/* Store two DPFP values in reverse order.  The address must be aligned.  */
208
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
209
_mm_storer_pd (double *__P, __m128d __A)
210
{
211
  _mm_store_pd (__P, __builtin_ia32_shufpd (__A, __A, _MM_SHUFFLE2 (0,1)));
212
}
213
214
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
215
_mm_cvtsi128_si32 (__m128i __A)
216
{
217
  return __builtin_ia32_vec_ext_v4si ((__v4si)__A, 0);
218
}
219
220
#ifdef __x86_64__
221
/* Intel intrinsic.  */
222
extern __inline long long __attribute__((__gnu_inline__, __always_inline__, __artificial__))
223
_mm_cvtsi128_si64 (__m128i __A)
224
{
225
  return __builtin_ia32_vec_ext_v2di ((__v2di)__A, 0);
226
}
227
228
/* Microsoft intrinsic.  */
229
extern __inline long long __attribute__((__gnu_inline__, __always_inline__, __artificial__))
230
_mm_cvtsi128_si64x (__m128i __A)
231
{
232
  return __builtin_ia32_vec_ext_v2di ((__v2di)__A, 0);
233
}
234
#endif
235
236
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
237
_mm_add_pd (__m128d __A, __m128d __B)
238
{
239
  return (__m128d)__builtin_ia32_addpd ((__v2df)__A, (__v2df)__B);
240
}
241
242
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
243
_mm_add_sd (__m128d __A, __m128d __B)
244
{
245
  return (__m128d)__builtin_ia32_addsd ((__v2df)__A, (__v2df)__B);
246
}
247
248
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
249
_mm_sub_pd (__m128d __A, __m128d __B)
250
{
251
  return (__m128d)__builtin_ia32_subpd ((__v2df)__A, (__v2df)__B);
252
}
253
254
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
255
_mm_sub_sd (__m128d __A, __m128d __B)
256
{
257
  return (__m128d)__builtin_ia32_subsd ((__v2df)__A, (__v2df)__B);
258
}
259
260
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
261
_mm_mul_pd (__m128d __A, __m128d __B)
262
{
263
  return (__m128d)__builtin_ia32_mulpd ((__v2df)__A, (__v2df)__B);
264
}
265
266
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
267
_mm_mul_sd (__m128d __A, __m128d __B)
268
{
269
  return (__m128d)__builtin_ia32_mulsd ((__v2df)__A, (__v2df)__B);
270
}
271
272
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
273
_mm_div_pd (__m128d __A, __m128d __B)
274
{
275
  return (__m128d)__builtin_ia32_divpd ((__v2df)__A, (__v2df)__B);
276
}
277
278
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
279
_mm_div_sd (__m128d __A, __m128d __B)
280
{
281
  return (__m128d)__builtin_ia32_divsd ((__v2df)__A, (__v2df)__B);
282
}
283
284
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
285
_mm_sqrt_pd (__m128d __A)
286
{
287
  return (__m128d)__builtin_ia32_sqrtpd ((__v2df)__A);
288
}
289
290
/* Return pair {sqrt (A[0), B[1]}.  */
291
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
292
_mm_sqrt_sd (__m128d __A, __m128d __B)
293
{
294
  __v2df __tmp = __builtin_ia32_movsd ((__v2df)__A, (__v2df)__B);
295
  return (__m128d)__builtin_ia32_sqrtsd ((__v2df)__tmp);
296
}
297
298
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
299
_mm_min_pd (__m128d __A, __m128d __B)
300
{
301
  return (__m128d)__builtin_ia32_minpd ((__v2df)__A, (__v2df)__B);
302
}
303
304
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
305
_mm_min_sd (__m128d __A, __m128d __B)
306
{
307
  return (__m128d)__builtin_ia32_minsd ((__v2df)__A, (__v2df)__B);
308
}
309
310
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
311
_mm_max_pd (__m128d __A, __m128d __B)
312
{
313
  return (__m128d)__builtin_ia32_maxpd ((__v2df)__A, (__v2df)__B);
314
}
315
316
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
317
_mm_max_sd (__m128d __A, __m128d __B)
318
{
319
  return (__m128d)__builtin_ia32_maxsd ((__v2df)__A, (__v2df)__B);
320
}
321
322
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
323
_mm_and_pd (__m128d __A, __m128d __B)
324
{
325
  return (__m128d)__builtin_ia32_andpd ((__v2df)__A, (__v2df)__B);
326
}
327
328
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
329
_mm_andnot_pd (__m128d __A, __m128d __B)
330
{
331
  return (__m128d)__builtin_ia32_andnpd ((__v2df)__A, (__v2df)__B);
332
}
333
334
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
335
_mm_or_pd (__m128d __A, __m128d __B)
336
{
337
  return (__m128d)__builtin_ia32_orpd ((__v2df)__A, (__v2df)__B);
338
}
339
340
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
341
_mm_xor_pd (__m128d __A, __m128d __B)
342
{
343
  return (__m128d)__builtin_ia32_xorpd ((__v2df)__A, (__v2df)__B);
344
}
345
346
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
347
_mm_cmpeq_pd (__m128d __A, __m128d __B)
348
{
349
  return (__m128d)__builtin_ia32_cmpeqpd ((__v2df)__A, (__v2df)__B);
350
}
351
352
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
353
_mm_cmplt_pd (__m128d __A, __m128d __B)
354
{
355
  return (__m128d)__builtin_ia32_cmpltpd ((__v2df)__A, (__v2df)__B);
356
}
357
358
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
359
_mm_cmple_pd (__m128d __A, __m128d __B)
360
{
361
  return (__m128d)__builtin_ia32_cmplepd ((__v2df)__A, (__v2df)__B);
362
}
363
364
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
365
_mm_cmpgt_pd (__m128d __A, __m128d __B)
366
{
367
  return (__m128d)__builtin_ia32_cmpgtpd ((__v2df)__A, (__v2df)__B);
368
}
369
370
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
371
_mm_cmpge_pd (__m128d __A, __m128d __B)
372
{
373
  return (__m128d)__builtin_ia32_cmpgepd ((__v2df)__A, (__v2df)__B);
374
}
375
376
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
377
_mm_cmpneq_pd (__m128d __A, __m128d __B)
378
{
379
  return (__m128d)__builtin_ia32_cmpneqpd ((__v2df)__A, (__v2df)__B);
380
}
381
382
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
383
_mm_cmpnlt_pd (__m128d __A, __m128d __B)
384
{
385
  return (__m128d)__builtin_ia32_cmpnltpd ((__v2df)__A, (__v2df)__B);
386
}
387
388
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
389
_mm_cmpnle_pd (__m128d __A, __m128d __B)
390
{
391
  return (__m128d)__builtin_ia32_cmpnlepd ((__v2df)__A, (__v2df)__B);
392
}
393
394
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
395
_mm_cmpngt_pd (__m128d __A, __m128d __B)
396
{
397
  return (__m128d)__builtin_ia32_cmpngtpd ((__v2df)__A, (__v2df)__B);
398
}
399
400
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
401
_mm_cmpnge_pd (__m128d __A, __m128d __B)
402
{
403
  return (__m128d)__builtin_ia32_cmpngepd ((__v2df)__A, (__v2df)__B);
404
}
405
406
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
407
_mm_cmpord_pd (__m128d __A, __m128d __B)
408
{
409
  return (__m128d)__builtin_ia32_cmpordpd ((__v2df)__A, (__v2df)__B);
410
}
411
412
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
413
_mm_cmpunord_pd (__m128d __A, __m128d __B)
414
{
415
  return (__m128d)__builtin_ia32_cmpunordpd ((__v2df)__A, (__v2df)__B);
416
}
417
418
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
419
_mm_cmpeq_sd (__m128d __A, __m128d __B)
420
{
421
  return (__m128d)__builtin_ia32_cmpeqsd ((__v2df)__A, (__v2df)__B);
422
}
423
424
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
425
_mm_cmplt_sd (__m128d __A, __m128d __B)
426
{
427
  return (__m128d)__builtin_ia32_cmpltsd ((__v2df)__A, (__v2df)__B);
428
}
429
430
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
431
_mm_cmple_sd (__m128d __A, __m128d __B)
432
{
433
  return (__m128d)__builtin_ia32_cmplesd ((__v2df)__A, (__v2df)__B);
434
}
435
436
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
437
_mm_cmpgt_sd (__m128d __A, __m128d __B)
438
{
439
  return (__m128d) __builtin_ia32_movsd ((__v2df) __A,
440
					 (__v2df)
441
					 __builtin_ia32_cmpltsd ((__v2df) __B,
442
								 (__v2df)
443
								 __A));
444
}
445
446
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
447
_mm_cmpge_sd (__m128d __A, __m128d __B)
448
{
449
  return (__m128d) __builtin_ia32_movsd ((__v2df) __A,
450
					 (__v2df)
451
					 __builtin_ia32_cmplesd ((__v2df) __B,
452
								 (__v2df)
453
								 __A));
454
}
455
456
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
457
_mm_cmpneq_sd (__m128d __A, __m128d __B)
458
{
459
  return (__m128d)__builtin_ia32_cmpneqsd ((__v2df)__A, (__v2df)__B);
460
}
461
462
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
463
_mm_cmpnlt_sd (__m128d __A, __m128d __B)
464
{
465
  return (__m128d)__builtin_ia32_cmpnltsd ((__v2df)__A, (__v2df)__B);
466
}
467
468
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
469
_mm_cmpnle_sd (__m128d __A, __m128d __B)
470
{
471
  return (__m128d)__builtin_ia32_cmpnlesd ((__v2df)__A, (__v2df)__B);
472
}
473
474
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
475
_mm_cmpngt_sd (__m128d __A, __m128d __B)
476
{
477
  return (__m128d) __builtin_ia32_movsd ((__v2df) __A,
478
					 (__v2df)
479
					 __builtin_ia32_cmpnltsd ((__v2df) __B,
480
								  (__v2df)
481
								  __A));
482
}
483
484
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
485
_mm_cmpnge_sd (__m128d __A, __m128d __B)
486
{
487
  return (__m128d) __builtin_ia32_movsd ((__v2df) __A,
488
					 (__v2df)
489
					 __builtin_ia32_cmpnlesd ((__v2df) __B,
490
								  (__v2df)
491
								  __A));
492
}
493
494
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
495
_mm_cmpord_sd (__m128d __A, __m128d __B)
496
{
497
  return (__m128d)__builtin_ia32_cmpordsd ((__v2df)__A, (__v2df)__B);
498
}
499
500
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
501
_mm_cmpunord_sd (__m128d __A, __m128d __B)
502
{
503
  return (__m128d)__builtin_ia32_cmpunordsd ((__v2df)__A, (__v2df)__B);
504
}
505
506
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
507
_mm_comieq_sd (__m128d __A, __m128d __B)
508
{
509
  return __builtin_ia32_comisdeq ((__v2df)__A, (__v2df)__B);
510
}
511
512
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
513
_mm_comilt_sd (__m128d __A, __m128d __B)
514
{
515
  return __builtin_ia32_comisdlt ((__v2df)__A, (__v2df)__B);
516
}
517
518
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
519
_mm_comile_sd (__m128d __A, __m128d __B)
520
{
521
  return __builtin_ia32_comisdle ((__v2df)__A, (__v2df)__B);
522
}
523
524
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
525
_mm_comigt_sd (__m128d __A, __m128d __B)
526
{
527
  return __builtin_ia32_comisdgt ((__v2df)__A, (__v2df)__B);
528
}
529
530
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
531
_mm_comige_sd (__m128d __A, __m128d __B)
532
{
533
  return __builtin_ia32_comisdge ((__v2df)__A, (__v2df)__B);
534
}
535
536
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
537
_mm_comineq_sd (__m128d __A, __m128d __B)
538
{
539
  return __builtin_ia32_comisdneq ((__v2df)__A, (__v2df)__B);
540
}
541
542
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
543
_mm_ucomieq_sd (__m128d __A, __m128d __B)
544
{
545
  return __builtin_ia32_ucomisdeq ((__v2df)__A, (__v2df)__B);
546
}
547
548
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
549
_mm_ucomilt_sd (__m128d __A, __m128d __B)
550
{
551
  return __builtin_ia32_ucomisdlt ((__v2df)__A, (__v2df)__B);
552
}
553
554
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
555
_mm_ucomile_sd (__m128d __A, __m128d __B)
556
{
557
  return __builtin_ia32_ucomisdle ((__v2df)__A, (__v2df)__B);
558
}
559
560
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
561
_mm_ucomigt_sd (__m128d __A, __m128d __B)
562
{
563
  return __builtin_ia32_ucomisdgt ((__v2df)__A, (__v2df)__B);
564
}
565
566
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
567
_mm_ucomige_sd (__m128d __A, __m128d __B)
568
{
569
  return __builtin_ia32_ucomisdge ((__v2df)__A, (__v2df)__B);
570
}
571
572
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
573
_mm_ucomineq_sd (__m128d __A, __m128d __B)
574
{
575
  return __builtin_ia32_ucomisdneq ((__v2df)__A, (__v2df)__B);
576
}
577
578
/* Create a vector of Qi, where i is the element number.  */
579
580
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
581
_mm_set_epi64x (long long __q1, long long __q0)
582
{
583
  return __extension__ (__m128i)(__v2di){ __q0, __q1 };
584
}
585
586
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
587
_mm_set_epi64 (__m64 __q1,  __m64 __q0)
588
{
589
  return _mm_set_epi64x ((long long)__q1, (long long)__q0);
590
}
591
592
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
593
_mm_set_epi32 (int __q3, int __q2, int __q1, int __q0)
594
{
595
  return __extension__ (__m128i)(__v4si){ __q0, __q1, __q2, __q3 };
596
}
597
598
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
599
_mm_set_epi16 (short __q7, short __q6, short __q5, short __q4,
600
	       short __q3, short __q2, short __q1, short __q0)
601
{
602
  return __extension__ (__m128i)(__v8hi){
603
    __q0, __q1, __q2, __q3, __q4, __q5, __q6, __q7 };
604
}
605
606
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
607
_mm_set_epi8 (char __q15, char __q14, char __q13, char __q12,
608
	      char __q11, char __q10, char __q09, char __q08,
609
	      char __q07, char __q06, char __q05, char __q04,
610
	      char __q03, char __q02, char __q01, char __q00)
611
{
612
  return __extension__ (__m128i)(__v16qi){
613
    __q00, __q01, __q02, __q03, __q04, __q05, __q06, __q07,
614
    __q08, __q09, __q10, __q11, __q12, __q13, __q14, __q15
615
  };
616
}
617
618
/* Set all of the elements of the vector to A.  */
619
620
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
621
_mm_set1_epi64x (long long __A)
622
{
623
  return _mm_set_epi64x (__A, __A);
624
}
625
626
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
627
_mm_set1_epi64 (__m64 __A)
628
{
629
  return _mm_set_epi64 (__A, __A);
630
}
631
632
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
633
_mm_set1_epi32 (int __A)
634
{
635
  return _mm_set_epi32 (__A, __A, __A, __A);
636
}
637
638
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
639
_mm_set1_epi16 (short __A)
640
{
641
  return _mm_set_epi16 (__A, __A, __A, __A, __A, __A, __A, __A);
642
}
643
644
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
645
_mm_set1_epi8 (char __A)
646
{
647
  return _mm_set_epi8 (__A, __A, __A, __A, __A, __A, __A, __A,
648
		       __A, __A, __A, __A, __A, __A, __A, __A);
649
}
650
651
/* Create a vector of Qi, where i is the element number.
652
   The parameter order is reversed from the _mm_set_epi* functions.  */
653
654
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
655
_mm_setr_epi64 (__m64 __q0, __m64 __q1)
656
{
657
  return _mm_set_epi64 (__q1, __q0);
658
}
659
660
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
661
_mm_setr_epi32 (int __q0, int __q1, int __q2, int __q3)
662
{
663
  return _mm_set_epi32 (__q3, __q2, __q1, __q0);
664
}
665
666
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
667
_mm_setr_epi16 (short __q0, short __q1, short __q2, short __q3,
668
	        short __q4, short __q5, short __q6, short __q7)
669
{
670
  return _mm_set_epi16 (__q7, __q6, __q5, __q4, __q3, __q2, __q1, __q0);
671
}
672
673
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
674
_mm_setr_epi8 (char __q00, char __q01, char __q02, char __q03,
675
	       char __q04, char __q05, char __q06, char __q07,
676
	       char __q08, char __q09, char __q10, char __q11,
677
	       char __q12, char __q13, char __q14, char __q15)
678
{
679
  return _mm_set_epi8 (__q15, __q14, __q13, __q12, __q11, __q10, __q09, __q08,
680
		       __q07, __q06, __q05, __q04, __q03, __q02, __q01, __q00);
681
}
682
683
/* Create a vector with element 0 as *P and the rest zero.  */
684
685
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
686
_mm_load_si128 (__m128i const *__P)
687
{
688
  return *__P;
689
}
690
691
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
692
_mm_loadu_si128 (__m128i const *__P)
693
{
694
  return (__m128i) __builtin_ia32_loaddqu ((char const *)__P);
695
}
696
697
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
698
_mm_loadl_epi64 (__m128i const *__P)
699
{
700
  return _mm_set_epi64 ((__m64)0LL, *(__m64 *)__P);
701
}
702
703
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
704
_mm_store_si128 (__m128i *__P, __m128i __B)
705
{
706
  *__P = __B;
707
}
708
709
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
710
_mm_storeu_si128 (__m128i *__P, __m128i __B)
711
{
712
  __builtin_ia32_storedqu ((char *)__P, (__v16qi)__B);
713
}
714
715
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
716
_mm_storel_epi64 (__m128i *__P, __m128i __B)
717
{
718
  *(long long *)__P = __builtin_ia32_vec_ext_v2di ((__v2di)__B, 0);
719
}
720
721
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
722
_mm_movepi64_pi64 (__m128i __B)
723
{
724
  return (__m64) __builtin_ia32_vec_ext_v2di ((__v2di)__B, 0);
725
}
726
727
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
728
_mm_movpi64_epi64 (__m64 __A)
729
{
730
  return _mm_set_epi64 ((__m64)0LL, __A);
731
}
732
733
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
734
_mm_move_epi64 (__m128i __A);
735
736
/* Create an undefined vector.  */
737
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
738
_mm_undefined_si128 (void)
739
{
740
  __m128i __Y = __Y;
741
  return __Y;
742
}
743
744
/* Create a vector of zeros.  */
745
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
746
_mm_setzero_si128 (void)
747
{
748
  return __extension__ (__m128i)(__v4si){ 0, 0, 0, 0 };
749
}
750
751
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
752
_mm_cvtepi32_pd (__m128i __A)
753
{
754
  return (__m128d)__builtin_ia32_cvtdq2pd ((__v4si) __A);
755
}
756
757
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
758
_mm_cvtepi32_ps (__m128i __A)
759
{
760
  return (__m128)__builtin_ia32_cvtdq2ps ((__v4si) __A);
761
}
762
763
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
764
_mm_cvtpd_epi32 (__m128d __A)
765
{
766
  return (__m128i)__builtin_ia32_cvtpd2dq ((__v2df) __A);
767
}
768
769
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
770
_mm_cvtpd_pi32 (__m128d __A)
771
{
772
  return (__m64)__builtin_ia32_cvtpd2pi ((__v2df) __A);
773
}
774
775
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
776
_mm_cvtpd_ps (__m128d __A)
777
{
778
  return (__m128)__builtin_ia32_cvtpd2ps ((__v2df) __A);
779
}
780
781
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
782
_mm_cvttpd_epi32 (__m128d __A)
783
{
784
  return (__m128i)__builtin_ia32_cvttpd2dq ((__v2df) __A);
785
}
786
787
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
788
_mm_cvttpd_pi32 (__m128d __A)
789
{
790
  return (__m64)__builtin_ia32_cvttpd2pi ((__v2df) __A);
791
}
792
793
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
794
_mm_cvtpi32_pd (__m64 __A)
795
{
796
  return (__m128d)__builtin_ia32_cvtpi2pd ((__v2si) __A);
797
}
798
799
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
800
_mm_cvtps_epi32 (__m128 __A)
801
{
802
  return (__m128i)__builtin_ia32_cvtps2dq ((__v4sf) __A);
803
}
804
805
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
806
_mm_cvttps_epi32 (__m128 __A)
807
{
808
  return (__m128i)__builtin_ia32_cvttps2dq ((__v4sf) __A);
809
}
810
811
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
812
_mm_cvtps_pd (__m128 __A)
813
{
814
  return (__m128d)__builtin_ia32_cvtps2pd ((__v4sf) __A);
815
}
816
817
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
818
_mm_cvtsd_si32 (__m128d __A)
819
{
820
  return __builtin_ia32_cvtsd2si ((__v2df) __A);
821
}
822
823
#ifdef __x86_64__
824
/* Intel intrinsic.  */
825
extern __inline long long __attribute__((__gnu_inline__, __always_inline__, __artificial__))
826
_mm_cvtsd_si64 (__m128d __A)
827
{
828
  return __builtin_ia32_cvtsd2si64 ((__v2df) __A);
829
}
830
831
/* Microsoft intrinsic.  */
832
extern __inline long long __attribute__((__gnu_inline__, __always_inline__, __artificial__))
833
_mm_cvtsd_si64x (__m128d __A)
834
{
835
  return __builtin_ia32_cvtsd2si64 ((__v2df) __A);
836
}
837
#endif
838
839
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
840
_mm_cvttsd_si32 (__m128d __A)
841
{
842
  return __builtin_ia32_cvttsd2si ((__v2df) __A);
843
}
844
845
#ifdef __x86_64__
846
/* Intel intrinsic.  */
847
extern __inline long long __attribute__((__gnu_inline__, __always_inline__, __artificial__))
848
_mm_cvttsd_si64 (__m128d __A)
849
{
850
  return __builtin_ia32_cvttsd2si64 ((__v2df) __A);
851
}
852
853
/* Microsoft intrinsic.  */
854
extern __inline long long __attribute__((__gnu_inline__, __always_inline__, __artificial__))
855
_mm_cvttsd_si64x (__m128d __A)
856
{
857
  return __builtin_ia32_cvttsd2si64 ((__v2df) __A);
858
}
859
#endif
860
861
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
862
_mm_cvtsd_ss (__m128 __A, __m128d __B)
863
{
864
  return (__m128)__builtin_ia32_cvtsd2ss ((__v4sf) __A, (__v2df) __B);
865
}
866
867
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
868
_mm_cvtsi32_sd (__m128d __A, int __B)
869
{
870
  return (__m128d)__builtin_ia32_cvtsi2sd ((__v2df) __A, __B);
871
}
872
873
#ifdef __x86_64__
874
/* Intel intrinsic.  */
875
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
876
_mm_cvtsi64_sd (__m128d __A, long long __B)
877
{
878
  return (__m128d)__builtin_ia32_cvtsi642sd ((__v2df) __A, __B);
879
}
880
881
/* Microsoft intrinsic.  */
882
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
883
_mm_cvtsi64x_sd (__m128d __A, long long __B)
884
{
885
  return (__m128d)__builtin_ia32_cvtsi642sd ((__v2df) __A, __B);
886
}
887
#endif
888
889
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
890
_mm_cvtss_sd (__m128d __A, __m128 __B)
891
{
892
  return (__m128d)__builtin_ia32_cvtss2sd ((__v2df) __A, (__v4sf)__B);
893
}
894
895
#ifdef __OPTIMIZE__
896
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
897
_mm_shuffle_pd(__m128d __A, __m128d __B, const int __mask)
898
{
899
  return (__m128d)__builtin_ia32_shufpd ((__v2df)__A, (__v2df)__B, __mask);
900
}
901
#else
902
#define _mm_shuffle_pd(A, B, N)						\
903
  ((__m128d)__builtin_ia32_shufpd ((__v2df)(__m128d)(A),		\
904
				   (__v2df)(__m128d)(B), (int)(N)))
905
#endif
906
907
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
908
_mm_unpackhi_pd (__m128d __A, __m128d __B)
909
{
910
  return (__m128d)__builtin_ia32_unpckhpd ((__v2df)__A, (__v2df)__B);
911
}
912
913
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
914
_mm_unpacklo_pd (__m128d __A, __m128d __B)
915
{
916
  return (__m128d)__builtin_ia32_unpcklpd ((__v2df)__A, (__v2df)__B);
917
}
918
919
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
920
_mm_loadh_pd (__m128d __A, double const *__B)
921
{
922
  return (__m128d)__builtin_ia32_loadhpd ((__v2df)__A, __B);
923
}
924
925
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
926
_mm_loadl_pd (__m128d __A, double const *__B)
927
{
928
  return (__m128d)__builtin_ia32_loadlpd ((__v2df)__A, __B);
929
}
930
931
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
932
_mm_movemask_pd (__m128d __A)
933
{
934
  return __builtin_ia32_movmskpd ((__v2df)__A);
935
}
936
937
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
938
_mm_packs_epi16 (__m128i __A, __m128i __B)
939
{
940
  return (__m128i)__builtin_ia32_packsswb128 ((__v8hi)__A, (__v8hi)__B);
941
}
942
943
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
944
_mm_packs_epi32 (__m128i __A, __m128i __B)
945
{
946
  return (__m128i)__builtin_ia32_packssdw128 ((__v4si)__A, (__v4si)__B);
947
}
948
949
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
950
_mm_packus_epi16 (__m128i __A, __m128i __B)
951
{
952
  return (__m128i)__builtin_ia32_packuswb128 ((__v8hi)__A, (__v8hi)__B);
953
}
954
955
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
956
_mm_unpackhi_epi8 (__m128i __A, __m128i __B)
957
{
958
  return (__m128i)__builtin_ia32_punpckhbw128 ((__v16qi)__A, (__v16qi)__B);
959
}
960
961
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
962
_mm_unpackhi_epi16 (__m128i __A, __m128i __B)
963
{
964
  return (__m128i)__builtin_ia32_punpckhwd128 ((__v8hi)__A, (__v8hi)__B);
965
}
966
967
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
968
_mm_unpackhi_epi32 (__m128i __A, __m128i __B)
969
{
970
  return (__m128i)__builtin_ia32_punpckhdq128 ((__v4si)__A, (__v4si)__B);
971
}
972
973
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
974
_mm_unpackhi_epi64 (__m128i __A, __m128i __B)
975
{
976
  return (__m128i)__builtin_ia32_punpckhqdq128 ((__v2di)__A, (__v2di)__B);
977
}
978
979
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
980
_mm_unpacklo_epi8 (__m128i __A, __m128i __B)
981
{
982
  return (__m128i)__builtin_ia32_punpcklbw128 ((__v16qi)__A, (__v16qi)__B);
983
}
984
985
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
986
_mm_unpacklo_epi16 (__m128i __A, __m128i __B)
987
{
988
  return (__m128i)__builtin_ia32_punpcklwd128 ((__v8hi)__A, (__v8hi)__B);
989
}
990
991
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
992
_mm_unpacklo_epi32 (__m128i __A, __m128i __B)
993
{
994
  return (__m128i)__builtin_ia32_punpckldq128 ((__v4si)__A, (__v4si)__B);
995
}
996
997
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
998
_mm_unpacklo_epi64 (__m128i __A, __m128i __B)
999
{
1000
  return (__m128i)__builtin_ia32_punpcklqdq128 ((__v2di)__A, (__v2di)__B);
1001
}
1002
1003
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1004
_mm_add_epi8 (__m128i __A, __m128i __B)
1005
{
1006
  return (__m128i)__builtin_ia32_paddb128 ((__v16qi)__A, (__v16qi)__B);
1007
}
1008
1009
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1010
_mm_add_epi16 (__m128i __A, __m128i __B)
1011
{
1012
  return (__m128i)__builtin_ia32_paddw128 ((__v8hi)__A, (__v8hi)__B);
1013
}
1014
1015
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1016
_mm_add_epi32 (__m128i __A, __m128i __B)
1017
{
1018
  return (__m128i)__builtin_ia32_paddd128 ((__v4si)__A, (__v4si)__B);
1019
}
1020
1021
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1022
_mm_add_epi64 (__m128i __A, __m128i __B)
1023
{
1024
  return (__m128i)__builtin_ia32_paddq128 ((__v2di)__A, (__v2di)__B);
1025
}
1026
1027
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1028
_mm_adds_epi8 (__m128i __A, __m128i __B)
1029
{
1030
  return (__m128i)__builtin_ia32_paddsb128 ((__v16qi)__A, (__v16qi)__B);
1031
}
1032
1033
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1034
_mm_adds_epi16 (__m128i __A, __m128i __B)
1035
{
1036
  return (__m128i)__builtin_ia32_paddsw128 ((__v8hi)__A, (__v8hi)__B);
1037
}
1038
1039
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1040
_mm_adds_epu8 (__m128i __A, __m128i __B)
1041
{
1042
  return (__m128i)__builtin_ia32_paddusb128 ((__v16qi)__A, (__v16qi)__B);
1043
}
1044
1045
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1046
_mm_adds_epu16 (__m128i __A, __m128i __B)
1047
{
1048
  return (__m128i)__builtin_ia32_paddusw128 ((__v8hi)__A, (__v8hi)__B);
1049
}
1050
1051
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1052
_mm_sub_epi8 (__m128i __A, __m128i __B)
1053
{
1054
  return (__m128i)__builtin_ia32_psubb128 ((__v16qi)__A, (__v16qi)__B);
1055
}
1056
1057
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1058
_mm_sub_epi16 (__m128i __A, __m128i __B)
1059
{
1060
  return (__m128i)__builtin_ia32_psubw128 ((__v8hi)__A, (__v8hi)__B);
1061
}
1062
1063
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1064
_mm_sub_epi32 (__m128i __A, __m128i __B)
1065
{
1066
  return (__m128i)__builtin_ia32_psubd128 ((__v4si)__A, (__v4si)__B);
1067
}
1068
1069
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1070
_mm_sub_epi64 (__m128i __A, __m128i __B)
1071
{
1072
  return (__m128i)__builtin_ia32_psubq128 ((__v2di)__A, (__v2di)__B);
1073
}
1074
1075
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1076
_mm_subs_epi8 (__m128i __A, __m128i __B)
1077
{
1078
  return (__m128i)__builtin_ia32_psubsb128 ((__v16qi)__A, (__v16qi)__B);
1079
}
1080
1081
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1082
_mm_subs_epi16 (__m128i __A, __m128i __B)
1083
{
1084
  return (__m128i)__builtin_ia32_psubsw128 ((__v8hi)__A, (__v8hi)__B);
1085
}
1086
1087
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1088
_mm_subs_epu8 (__m128i __A, __m128i __B)
1089
{
1090
  return (__m128i)__builtin_ia32_psubusb128 ((__v16qi)__A, (__v16qi)__B);
1091
}
1092
1093
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1094
_mm_subs_epu16 (__m128i __A, __m128i __B)
1095
{
1096
  return (__m128i)__builtin_ia32_psubusw128 ((__v8hi)__A, (__v8hi)__B);
1097
}
1098
1099
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1100
_mm_madd_epi16 (__m128i __A, __m128i __B)
1101
{
1102
  return (__m128i)__builtin_ia32_pmaddwd128 ((__v8hi)__A, (__v8hi)__B);
1103
}
1104
1105
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1106
_mm_mulhi_epi16 (__m128i __A, __m128i __B)
1107
{
1108
  return (__m128i)__builtin_ia32_pmulhw128 ((__v8hi)__A, (__v8hi)__B);
1109
}
1110
1111
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1112
_mm_mullo_epi16 (__m128i __A, __m128i __B)
1113
{
1114
  return (__m128i)__builtin_ia32_pmullw128 ((__v8hi)__A, (__v8hi)__B);
1115
}
1116
1117
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1118
_mm_mul_su32 (__m64 __A, __m64 __B)
1119
{
1120
  return (__m64)__builtin_ia32_pmuludq ((__v2si)__A, (__v2si)__B);
1121
}
1122
1123
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1124
_mm_mul_epu32 (__m128i __A, __m128i __B)
1125
{
1126
  return (__m128i)__builtin_ia32_pmuludq128 ((__v4si)__A, (__v4si)__B);
1127
}
1128
1129
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1130
_mm_slli_epi16 (__m128i __A, int __B)
1131
{
1132
  return (__m128i)__builtin_ia32_psllwi128 ((__v8hi)__A, __B);
1133
}
1134
1135
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1136
_mm_slli_epi32 (__m128i __A, int __B)
1137
{
1138
  return (__m128i)__builtin_ia32_pslldi128 ((__v4si)__A, __B);
1139
}
1140
1141
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1142
_mm_slli_epi64 (__m128i __A, int __B)
1143
{
1144
  return (__m128i)__builtin_ia32_psllqi128 ((__v2di)__A, __B);
1145
}
1146
1147
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1148
_mm_srai_epi16 (__m128i __A, int __B)
1149
{
1150
  return (__m128i)__builtin_ia32_psrawi128 ((__v8hi)__A, __B);
1151
}
1152
1153
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1154
_mm_srai_epi32 (__m128i __A, int __B)
1155
{
1156
  return (__m128i)__builtin_ia32_psradi128 ((__v4si)__A, __B);
1157
}
1158
1159
#ifdef __OPTIMIZE__
1160
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1161
_mm_srli_si128 (__m128i __A, const int __N)
1162
{
1163
  return (__m128i)__builtin_ia32_psrldqi128 (__A, __N * 8);
1164
}
1165
1166
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1167
_mm_slli_si128 (__m128i __A, const int __N)
1168
{
1169
  return (__m128i)__builtin_ia32_pslldqi128 (__A, __N * 8);
1170
}
1171
#else
1172
#define _mm_srli_si128(A, N) \
1173
  ((__m128i)__builtin_ia32_psrldqi128 ((__m128i)(A), (int)(N) * 8))
1174
#define _mm_slli_si128(A, N) \
1175
  ((__m128i)__builtin_ia32_pslldqi128 ((__m128i)(A), (int)(N) * 8))
1176
#endif
1177
1178
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1179
_mm_srli_epi16 (__m128i __A, int __B)
1180
{
1181
  return (__m128i)__builtin_ia32_psrlwi128 ((__v8hi)__A, __B);
1182
}
1183
1184
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1185
_mm_srli_epi32 (__m128i __A, int __B)
1186
{
1187
  return (__m128i)__builtin_ia32_psrldi128 ((__v4si)__A, __B);
1188
}
1189
1190
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1191
_mm_srli_epi64 (__m128i __A, int __B)
1192
{
1193
  return (__m128i)__builtin_ia32_psrlqi128 ((__v2di)__A, __B);
1194
}
1195
1196
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1197
_mm_sll_epi16 (__m128i __A, __m128i __B)
1198
{
1199
  return (__m128i)__builtin_ia32_psllw128((__v8hi)__A, (__v8hi)__B);
1200
}
1201
1202
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1203
_mm_sll_epi32 (__m128i __A, __m128i __B)
1204
{
1205
  return (__m128i)__builtin_ia32_pslld128((__v4si)__A, (__v4si)__B);
1206
}
1207
1208
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1209
_mm_sll_epi64 (__m128i __A, __m128i __B)
1210
{
1211
  return (__m128i)__builtin_ia32_psllq128((__v2di)__A, (__v2di)__B);
1212
}
1213
1214
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1215
_mm_sra_epi16 (__m128i __A, __m128i __B)
1216
{
1217
  return (__m128i)__builtin_ia32_psraw128 ((__v8hi)__A, (__v8hi)__B);
1218
}
1219
1220
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1221
_mm_sra_epi32 (__m128i __A, __m128i __B)
1222
{
1223
  return (__m128i)__builtin_ia32_psrad128 ((__v4si)__A, (__v4si)__B);
1224
}
1225
1226
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1227
_mm_srl_epi16 (__m128i __A, __m128i __B)
1228
{
1229
  return (__m128i)__builtin_ia32_psrlw128 ((__v8hi)__A, (__v8hi)__B);
1230
}
1231
1232
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1233
_mm_srl_epi32 (__m128i __A, __m128i __B)
1234
{
1235
  return (__m128i)__builtin_ia32_psrld128 ((__v4si)__A, (__v4si)__B);
1236
}
1237
1238
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1239
_mm_srl_epi64 (__m128i __A, __m128i __B)
1240
{
1241
  return (__m128i)__builtin_ia32_psrlq128 ((__v2di)__A, (__v2di)__B);
1242
}
1243
1244
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1245
_mm_and_si128 (__m128i __A, __m128i __B)
1246
{
1247
  return (__m128i)__builtin_ia32_pand128 ((__v2di)__A, (__v2di)__B);
1248
}
1249
1250
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1251
_mm_andnot_si128 (__m128i __A, __m128i __B)
1252
{
1253
  return (__m128i)__builtin_ia32_pandn128 ((__v2di)__A, (__v2di)__B);
1254
}
1255
1256
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1257
_mm_or_si128 (__m128i __A, __m128i __B)
1258
{
1259
  return (__m128i)__builtin_ia32_por128 ((__v2di)__A, (__v2di)__B);
1260
}
1261
1262
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1263
_mm_xor_si128 (__m128i __A, __m128i __B)
1264
{
1265
  return (__m128i)__builtin_ia32_pxor128 ((__v2di)__A, (__v2di)__B);
1266
}
1267
1268
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1269
_mm_cmpeq_epi8 (__m128i __A, __m128i __B)
1270
{
1271
  return (__m128i)__builtin_ia32_pcmpeqb128 ((__v16qi)__A, (__v16qi)__B);
1272
}
1273
1274
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1275
_mm_cmpeq_epi16 (__m128i __A, __m128i __B)
1276
{
1277
  return (__m128i)__builtin_ia32_pcmpeqw128 ((__v8hi)__A, (__v8hi)__B);
1278
}
1279
1280
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1281
_mm_cmpeq_epi32 (__m128i __A, __m128i __B)
1282
{
1283
  return (__m128i)__builtin_ia32_pcmpeqd128 ((__v4si)__A, (__v4si)__B);
1284
}
1285
1286
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1287
_mm_cmplt_epi8 (__m128i __A, __m128i __B)
1288
{
1289
  return (__m128i)__builtin_ia32_pcmpgtb128 ((__v16qi)__B, (__v16qi)__A);
1290
}
1291
1292
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1293
_mm_cmplt_epi16 (__m128i __A, __m128i __B)
1294
{
1295
  return (__m128i)__builtin_ia32_pcmpgtw128 ((__v8hi)__B, (__v8hi)__A);
1296
}
1297
1298
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1299
_mm_cmplt_epi32 (__m128i __A, __m128i __B)
1300
{
1301
  return (__m128i)__builtin_ia32_pcmpgtd128 ((__v4si)__B, (__v4si)__A);
1302
}
1303
1304
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1305
_mm_cmpgt_epi8 (__m128i __A, __m128i __B)
1306
{
1307
  return (__m128i)__builtin_ia32_pcmpgtb128 ((__v16qi)__A, (__v16qi)__B);
1308
}
1309
1310
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1311
_mm_cmpgt_epi16 (__m128i __A, __m128i __B)
1312
{
1313
  return (__m128i)__builtin_ia32_pcmpgtw128 ((__v8hi)__A, (__v8hi)__B);
1314
}
1315
1316
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1317
_mm_cmpgt_epi32 (__m128i __A, __m128i __B)
1318
{
1319
  return (__m128i)__builtin_ia32_pcmpgtd128 ((__v4si)__A, (__v4si)__B);
1320
}
1321
1322
#ifdef __OPTIMIZE__
1323
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1324
_mm_extract_epi16 (__m128i const __A, int const __N)
1325
{
1326
  return (unsigned short) __builtin_ia32_vec_ext_v8hi ((__v8hi)__A, __N);
1327
}
1328
1329
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1330
_mm_insert_epi16 (__m128i const __A, int const __D, int const __N)
1331
{
1332
  return (__m128i) __builtin_ia32_vec_set_v8hi ((__v8hi)__A, __D, __N);
1333
}
1334
#else
1335
#define _mm_extract_epi16(A, N) \
1336
  ((int) (unsigned short) __builtin_ia32_vec_ext_v8hi ((__v8hi)(__m128i)(A), (int)(N)))
1337
#define _mm_insert_epi16(A, D, N)				\
1338
  ((__m128i) __builtin_ia32_vec_set_v8hi ((__v8hi)(__m128i)(A),	\
1339
					  (int)(D), (int)(N)))
1340
#endif
1341
1342
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1343
_mm_max_epi16 (__m128i __A, __m128i __B)
1344
{
1345
  return (__m128i)__builtin_ia32_pmaxsw128 ((__v8hi)__A, (__v8hi)__B);
1346
}
1347
1348
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1349
_mm_max_epu8 (__m128i __A, __m128i __B)
1350
{
1351
  return (__m128i)__builtin_ia32_pmaxub128 ((__v16qi)__A, (__v16qi)__B);
1352
}
1353
1354
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1355
_mm_min_epi16 (__m128i __A, __m128i __B)
1356
{
1357
  return (__m128i)__builtin_ia32_pminsw128 ((__v8hi)__A, (__v8hi)__B);
1358
}
1359
1360
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1361
_mm_min_epu8 (__m128i __A, __m128i __B)
1362
{
1363
  return (__m128i)__builtin_ia32_pminub128 ((__v16qi)__A, (__v16qi)__B);
1364
}
1365
1366
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1367
_mm_movemask_epi8 (__m128i __A)
1368
{
1369
  return __builtin_ia32_pmovmskb128 ((__v16qi)__A);
1370
}
1371
1372
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1373
_mm_mulhi_epu16 (__m128i __A, __m128i __B)
1374
{
1375
  return (__m128i)__builtin_ia32_pmulhuw128 ((__v8hi)__A, (__v8hi)__B);
1376
}
1377
1378
#ifdef __OPTIMIZE__
1379
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1380
_mm_shufflehi_epi16 (__m128i __A, const int __mask)
1381
{
1382
  return (__m128i)__builtin_ia32_pshufhw ((__v8hi)__A, __mask);
1383
}
1384
1385
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1386
_mm_shufflelo_epi16 (__m128i __A, const int __mask)
1387
{
1388
  return (__m128i)__builtin_ia32_pshuflw ((__v8hi)__A, __mask);
1389
}
1390
1391
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1392
_mm_shuffle_epi32 (__m128i __A, const int __mask)
1393
{
1394
  return (__m128i)__builtin_ia32_pshufd ((__v4si)__A, __mask);
1395
}
1396
#else
1397
#define _mm_shufflehi_epi16(A, N) \
1398
  ((__m128i)__builtin_ia32_pshufhw ((__v8hi)(__m128i)(A), (int)(N)))
1399
#define _mm_shufflelo_epi16(A, N) \
1400
  ((__m128i)__builtin_ia32_pshuflw ((__v8hi)(__m128i)(A), (int)(N)))
1401
#define _mm_shuffle_epi32(A, N) \
1402
  ((__m128i)__builtin_ia32_pshufd ((__v4si)(__m128i)(A), (int)(N)))
1403
#endif
1404
1405
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1406
_mm_maskmoveu_si128 (__m128i __A, __m128i __B, char *__C)
1407
{
1408
  __builtin_ia32_maskmovdqu ((__v16qi)__A, (__v16qi)__B, __C);
1409
}
1410
1411
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1412
_mm_avg_epu8 (__m128i __A, __m128i __B)
1413
{
1414
  return (__m128i)__builtin_ia32_pavgb128 ((__v16qi)__A, (__v16qi)__B);
1415
}
1416
1417
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1418
_mm_avg_epu16 (__m128i __A, __m128i __B)
1419
{
1420
  return (__m128i)__builtin_ia32_pavgw128 ((__v8hi)__A, (__v8hi)__B);
1421
}
1422
1423
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1424
_mm_sad_epu8 (__m128i __A, __m128i __B)
1425
{
1426
  return (__m128i)__builtin_ia32_psadbw128 ((__v16qi)__A, (__v16qi)__B);
1427
}
1428
1429
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1430
_mm_stream_si32 (int *__A, int __B)
1431
{
1432
  __builtin_ia32_movnti (__A, __B);
1433
}
1434
1435
#ifdef __x86_64__
1436
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1437
_mm_stream_si64 (long long int *__A, long long int __B);
1438
#endif
1439
1440
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1441
_mm_stream_si128 (__m128i *__A, __m128i __B)
1442
{
1443
  __builtin_ia32_movntdq ((__v2di *)__A, (__v2di)__B);
1444
}
1445
1446
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1447
_mm_stream_pd (double *__A, __m128d __B)
1448
{
1449
  __builtin_ia32_movntpd (__A, (__v2df)__B);
1450
}
1451
1452
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1453
_mm_clflush (void const *__A)
1454
{
1455
  __builtin_ia32_clflush (__A);
1456
}
1457
1458
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1459
_mm_lfence (void)
1460
{
1461
  __builtin_ia32_lfence ();
1462
}
1463
1464
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1465
_mm_mfence (void)
1466
{
1467
  __builtin_ia32_mfence ();
1468
}
1469
1470
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1471
_mm_cvtsi32_si128 (int __A)
1472
{
1473
  return _mm_set_epi32 (0, 0, 0, __A);
1474
}
1475
1476
#ifdef __x86_64__
1477
/* Intel intrinsic.  */
1478
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1479
_mm_cvtsi64_si128 (long long __A)
1480
{
1481
  return _mm_set_epi64x (0, __A);
1482
}
1483
1484
/* Microsoft intrinsic.  */
1485
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1486
_mm_cvtsi64x_si128 (long long __A)
1487
{
1488
  return _mm_set_epi64x (0, __A);
1489
}
1490
#endif
1491
1492
/* Casts between various SP, DP, INT vector types.  Note that these do no
1493
   conversion of values, they just change the type.  */
1494
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1495
_mm_castpd_ps(__m128d __A)
1496
{
1497
  return (__m128) __A;
1498
}
1499
1500
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1501
_mm_castpd_si128(__m128d __A)
1502
{
1503
  return (__m128i) __A;
1504
}
1505
1506
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1507
_mm_castps_pd(__m128 __A)
1508
{
1509
  return (__m128d) __A;
1510
}
1511
1512
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1513
_mm_castps_si128(__m128 __A)
1514
{
1515
  return (__m128i) __A;
1516
}
1517
1518
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1519
_mm_castsi128_ps(__m128i __A)
1520
{
1521
  return (__m128) __A;
1522
}
1523
1524
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1525
_mm_castsi128_pd(__m128i __A)
1526
{
1527
  return (__m128d) __A;
1528
}
1529
1530
#ifdef __DISABLE_SSE2__
1531
#undef __DISABLE_SSE2__
1532
#pragma GCC pop_options
1533
#endif /* __DISABLE_SSE2__ */
1534
1535
#endif /* _EMMINTRIN_H_INCLUDED */
(-)GCC_XML/Support/GCC/4.9/ext/atomicity.h (+117 lines)
Line 0 Link Here
1
// Support for atomic operations -*- C++ -*-
2
3
// Copyright (C) 2004-2014 Free Software Foundation, Inc.
4
//
5
// This file is part of the GNU ISO C++ Library.  This library is free
6
// software; you can redistribute it and/or modify it under the
7
// terms of the GNU General Public License as published by the
8
// Free Software Foundation; either version 3, or (at your option)
9
// any later version.
10
11
// This library is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
// GNU General Public License for more details.
15
16
// Under Section 7 of GPL version 3, you are granted additional
17
// permissions described in the GCC Runtime Library Exception, version
18
// 3.1, as published by the Free Software Foundation.
19
20
// You should have received a copy of the GNU General Public License and
21
// a copy of the GCC Runtime Library Exception along with this program;
22
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23
// <http://www.gnu.org/licenses/>.
24
25
/** @file ext/atomicity.h
26
 *  This file is a GNU extension to the Standard C++ Library.
27
 */
28
29
#ifndef _GLIBCXX_ATOMICITY_H
30
#define _GLIBCXX_ATOMICITY_H	1
31
32
#pragma GCC system_header
33
34
#include <bits/c++config.h>
35
#include <bits/gthr.h>
36
#include <bits/atomic_word.h>
37
38
namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
39
{
40
_GLIBCXX_BEGIN_NAMESPACE_VERSION
41
42
  // Functions for portable atomic access.
43
  // To abstract locking primitives across all thread policies, use:
44
  // __exchange_and_add_dispatch
45
  // __atomic_add_dispatch
46
#ifdef _GLIBCXX_ATOMIC_BUILTINS
47
  static inline _Atomic_word 
48
  __exchange_and_add(volatile _Atomic_word* __mem, int __val)
49
  { return __sync_fetch_and_add(__mem, __val, __ATOMIC_ACQ_REL); }
50
51
  static inline void
52
  __atomic_add(volatile _Atomic_word* __mem, int __val)
53
  { __sync_fetch_and_add(__mem, __val, __ATOMIC_ACQ_REL); }
54
#else
55
  _Atomic_word
56
  __attribute__ ((__unused__))
57
  __exchange_and_add(volatile _Atomic_word*, int) throw ();
58
59
  void
60
  __attribute__ ((__unused__))
61
  __atomic_add(volatile _Atomic_word*, int) throw ();
62
#endif
63
64
  static inline _Atomic_word
65
  __exchange_and_add_single(_Atomic_word* __mem, int __val)
66
  {
67
    _Atomic_word __result = *__mem;
68
    *__mem += __val;
69
    return __result;
70
  }
71
72
  static inline void
73
  __atomic_add_single(_Atomic_word* __mem, int __val)
74
  { *__mem += __val; }
75
76
  static inline _Atomic_word
77
  __attribute__ ((__unused__))
78
  __exchange_and_add_dispatch(_Atomic_word* __mem, int __val)
79
  {
80
#ifdef __GTHREADS
81
    if (__gthread_active_p())
82
      return __exchange_and_add(__mem, __val);
83
    else
84
      return __exchange_and_add_single(__mem, __val);
85
#else
86
    return __exchange_and_add_single(__mem, __val);
87
#endif
88
  }
89
90
  static inline void
91
  __attribute__ ((__unused__))
92
  __atomic_add_dispatch(_Atomic_word* __mem, int __val)
93
  {
94
#ifdef __GTHREADS
95
    if (__gthread_active_p())
96
      __atomic_add(__mem, __val);
97
    else
98
      __atomic_add_single(__mem, __val);
99
#else
100
    __atomic_add_single(__mem, __val);
101
#endif
102
  }
103
104
_GLIBCXX_END_NAMESPACE_VERSION
105
} // namespace
106
107
// Even if the CPU doesn't need a memory barrier, we need to ensure
108
// that the compiler doesn't reorder memory accesses across the
109
// barriers.
110
#ifndef _GLIBCXX_READ_MEM_BARRIER
111
#define _GLIBCXX_READ_MEM_BARRIER __asm __volatile ("":::"memory")
112
#endif
113
#ifndef _GLIBCXX_WRITE_MEM_BARRIER
114
#define _GLIBCXX_WRITE_MEM_BARRIER __asm __volatile ("":::"memory")
115
#endif
116
117
#endif 
(-)GCC_XML/Support/GCC/4.9/gccxml_builtins.h (+158 lines)
Line 0 Link Here
1
#define __builtin_apply(x,y,z) ((void*)0)
2
#define __builtin_nan(x) (0.0)
3
#define __builtin_nanf(x) (0.0f)
4
#define __builtin_nanl(x) (0.0l)
5
#define __builtin_huge_val(x) (0.0)
6
#define __builtin_huge_valf(x) (0.0f)
7
#define __builtin_huge_vall(x) (0.0l)
8
#define __builtin_apply_args(x) ((void*)0)
9
#define __builtin_types_compatible_p(x,y) 0
10
#define __builtin_choose_expr(x,y,z) int
11
#define __builtin_constant_p(x) 0
12
void* __builtin_memchr(void const*, int, unsigned int);
13
void __builtin_return (void *RESULT);
14
void * __builtin_return_address (unsigned int LEVEL);
15
void * __builtin_frame_address (unsigned int LEVEL);
16
long __builtin_expect (long EXP, long C);
17
void __builtin_prefetch (const void *ADDR, ...);
18
double __builtin_inf (void);
19
float __builtin_inff (void);
20
long double __builtin_infl (void);
21
double __builtin_nans (const char *str);
22
float __builtin_nansf (const char *str);
23
long double __builtin_nansl (const char *str);
24
double      __builtin_acos(double);
25
float       __builtin_acosf(float);
26
long double __builtin_acosl(long double);
27
double      __builtin_asin(double);
28
float       __builtin_asinf(float);
29
long double __builtin_asinl(long double);
30
double      __builtin_atan(double);
31
double      __builtin_atan2(double, double);
32
float       __builtin_atan2f(float, float);
33
long double __builtin_atan2l(long double, long double);
34
float       __builtin_atanf(float);
35
long double __builtin_atanl(long double);
36
double      __builtin_ceil(double);
37
float       __builtin_ceilf(float);
38
long double __builtin_ceill(long double);
39
double      __builtin_cos(double);
40
float       __builtin_cosf(float);
41
double      __builtin_cosh(double);
42
float       __builtin_coshf(float);
43
long double __builtin_coshl(long double);
44
long double __builtin_cosl(long double);
45
double      __builtin_exp(double);
46
float       __builtin_expf(float);
47
long double __builtin_expl(long double);
48
double      __builtin_fabs(double);
49
float       __builtin_fabsf(float);
50
long double __builtin_fabsl(long double);
51
double      __builtin_floor(double);
52
float       __builtin_floorf(float);
53
long double __builtin_floorl(long double);
54
float       __builtin_fmodf(float, float);
55
long double __builtin_fmodl(long double, long double);
56
double      __builtin_frexp(double, int*);
57
float       __builtin_frexpf(float, int*);
58
long double __builtin_frexpl(long double, int*);
59
double      __builtin_ldexp(double, int);
60
float       __builtin_ldexpf(float, int);
61
long double __builtin_ldexpl(long double, int);
62
double      __builtin_log(double);
63
double      __builtin_log10(double);
64
float       __builtin_log10f(float);
65
long double __builtin_log10l(long double);
66
float       __builtin_logf(float);
67
long double __builtin_logl(long double);
68
float       __builtin_modff(float, float*);
69
long double __builtin_modfl(long double, long double*);
70
float       __builtin_powf(float, float);
71
long double __builtin_powl(long double, long double);
72
double      __builtin_powi(double, int);
73
float       __builtin_powif(float, int);
74
long double __builtin_powil(long double, int);
75
double      __builtin_sin(double);
76
float       __builtin_sinf(float);
77
double      __builtin_sinh(double);
78
float       __builtin_sinhf(float);
79
long double __builtin_sinhl(long double);
80
long double __builtin_sinl(long double);
81
double      __builtin_sqrt(double);
82
float       __builtin_sqrtf(float);
83
long double __builtin_sqrtl(long double);
84
double      __builtin_tan(double);
85
float       __builtin_tanf(float);
86
double      __builtin_tanh(double);
87
float       __builtin_tanhf(float);
88
long double __builtin_tanhl(long double);
89
long double __builtin_tanl(long double);
90
float       __builtin_cabsf(float __complex__);
91
double      __builtin_cabs(double __complex__);
92
long double __builtin_cabsl(long double __complex__);
93
float       __builtin_cargf(float __complex__);
94
double      __builtin_carg(double __complex__);
95
long double __builtin_cargl(long double __complex__);
96
int         __builtin_ctz(int);
97
int         __builtin_ctzl(long);
98
int         __builtin_ctzll(long long);
99
int         __builtin_popcount(int);
100
int         __builtin_popcountl(long);
101
int         __builtin_popcountll(long long);
102
float       __complex__ __builtin_ccosf(float __complex__);
103
double      __complex__ __builtin_ccos(double __complex__);
104
long double __complex__ __builtin_ccosl(long double __complex__);
105
float       __complex__ __builtin_ccoshf(float __complex__);
106
double      __complex__ __builtin_ccosh(double __complex__);
107
long double __complex__ __builtin_ccoshl(long double __complex__);
108
float       __complex__ __builtin_cexpf(float __complex__);
109
double      __complex__ __builtin_cexp(double __complex__);
110
long double __complex__ __builtin_cexpl(long double __complex__);
111
float       __complex__ __builtin_clogf(float __complex__);
112
double      __complex__ __builtin_clog(double __complex__);
113
long double __complex__ __builtin_clogl(long double __complex__);
114
float       __complex__ __builtin_csinf(float __complex__);
115
double      __complex__ __builtin_csin(double __complex__);
116
long double __complex__ __builtin_csinl(long double __complex__);
117
float       __complex__ __builtin_csinhf(float __complex__);
118
double      __complex__ __builtin_csinh(double __complex__);
119
long double __complex__ __builtin_csinhl(long double __complex__);
120
float       __complex__ __builtin_csqrtf(float __complex__);
121
double      __complex__ __builtin_csqrt(double __complex__);
122
long double __complex__ __builtin_csqrtl(long double __complex__);
123
float       __complex__ __builtin_ctanf(float __complex__);
124
double      __complex__ __builtin_ctan(double __complex__);
125
long double __complex__ __builtin_ctanl(long double __complex__);
126
float       __complex__ __builtin_ctanhf(float __complex__);
127
double      __complex__ __builtin_ctanh(double __complex__);
128
long double __complex__ __builtin_ctanhl(long double __complex__);
129
float       __complex__ __builtin_cpowf(float __complex__, float __complex__);
130
double      __complex__ __builtin_cpow(double __complex__, double __complex__);
131
long double __complex__ __builtin_cpowl(long double __complex__, long double __complex__);
132
133
/* The GCC 4.5 parser hard-codes handling of these, so they do not
134
   have real signatures.  */
135
bool __builtin_fpclassify(...);
136
bool __builtin_isfinite(...);
137
bool __builtin_isgreater(...);
138
bool __builtin_isgreaterequal(...);
139
bool __builtin_isinf(...);
140
bool __builtin_isinf_sign(...);
141
bool __builtin_isless(...);
142
bool __builtin_islessequal(...);
143
bool __builtin_islessgreater(...);
144
bool __builtin_isnan(...);
145
bool __builtin_isnormal(...);
146
bool __builtin_isunordered(...);
147
bool __builtin_va_arg_pack(...);
148
int  __builtin_va_arg_pack_len(...);
149
150
/* We fake some constant expressions from GCC 4.5 parser.  */
151
#define __is_empty(x) false
152
#define __is_pod(x) false
153
#define __is_trivial(x) false
154
#define __has_trivial_destructor(x) false
155
#define __has_trivial_constructor(x) false
156
157
extern unsigned int  __builtin_bswap32(unsigned int _data);
158
extern unsigned long __builtin_bswap64(unsigned long _data);
(-)GCC_XML/Support/GCC/4.9/iomanip (+530 lines)
Line 0 Link Here
1
// Standard stream manipulators -*- C++ -*-
2
3
// Copyright (C) 1997-2014 Free Software Foundation, Inc.
4
//
5
// This file is part of the GNU ISO C++ Library.  This library is free
6
// software; you can redistribute it and/or modify it under the
7
// terms of the GNU General Public License as published by the
8
// Free Software Foundation; either version 3, or (at your option)
9
// any later version.
10
11
// This library is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
// GNU General Public License for more details.
15
16
// Under Section 7 of GPL version 3, you are granted additional
17
// permissions described in the GCC Runtime Library Exception, version
18
// 3.1, as published by the Free Software Foundation.
19
20
// You should have received a copy of the GNU General Public License and
21
// a copy of the GCC Runtime Library Exception along with this program;
22
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23
// <http://www.gnu.org/licenses/>.
24
25
/** @file include/iomanip
26
 *  This is a Standard C++ Library header.
27
 */
28
29
//
30
// ISO C++ 14882: 27.6.3  Standard manipulators
31
//
32
33
#ifndef _GLIBCXX_IOMANIP
34
#define _GLIBCXX_IOMANIP 1
35
36
#pragma GCC system_header
37
38
#include <bits/c++config.h>
39
#include <iosfwd>
40
#include <bits/ios_base.h>
41
42
#if __cplusplus >= 201103L
43
#include <locale>
44
#endif
45
46
namespace std _GLIBCXX_VISIBILITY(default)
47
{
48
_GLIBCXX_BEGIN_NAMESPACE_VERSION
49
50
  // [27.6.3] standard manipulators
51
  // Also see DR 183.
52
53
  struct _Resetiosflags { ios_base::fmtflags _M_mask; };
54
55
  /**
56
   *  @brief  Manipulator for @c setf.
57
   *  @param  __mask  A format flags mask.
58
   *
59
   *  Sent to a stream object, this manipulator resets the specified flags,
60
   *  via @e stream.setf(0,__mask).
61
  */
62
  inline _Resetiosflags 
63
  resetiosflags(ios_base::fmtflags __mask)
64
  { _Resetiosflags r = { __mask }; return r; }
65
66
  template<typename _CharT, typename _Traits>
67
    inline basic_istream<_CharT, _Traits>& 
68
    operator>>(basic_istream<_CharT, _Traits>& __is, _Resetiosflags __f)
69
    { 
70
      __is.setf(ios_base::fmtflags(0), __f._M_mask); 
71
      return __is; 
72
    }
73
74
  template<typename _CharT, typename _Traits>
75
    inline basic_ostream<_CharT, _Traits>& 
76
    operator<<(basic_ostream<_CharT, _Traits>& __os, _Resetiosflags __f)
77
    { 
78
      __os.setf(ios_base::fmtflags(0), __f._M_mask); 
79
      return __os; 
80
    }
81
82
83
  struct _Setiosflags { ios_base::fmtflags _M_mask; };
84
85
  /**
86
   *  @brief  Manipulator for @c setf.
87
   *  @param  __mask  A format flags mask.
88
   *
89
   *  Sent to a stream object, this manipulator sets the format flags
90
   *  to @a __mask.
91
  */
92
  inline _Setiosflags 
93
  setiosflags(ios_base::fmtflags __mask)
94
  { _Setiosflags s = { __mask }; return s; }
95
96
  template<typename _CharT, typename _Traits>
97
    inline basic_istream<_CharT, _Traits>& 
98
    operator>>(basic_istream<_CharT, _Traits>& __is, _Setiosflags __f)
99
    { 
100
      __is.setf(__f._M_mask); 
101
      return __is; 
102
    }
103
104
  template<typename _CharT, typename _Traits>
105
    inline basic_ostream<_CharT, _Traits>& 
106
    operator<<(basic_ostream<_CharT, _Traits>& __os, _Setiosflags __f)
107
    { 
108
      __os.setf(__f._M_mask); 
109
      return __os; 
110
    }
111
112
113
  struct _Setbase { int _M_base; };
114
115
  /**
116
   *  @brief  Manipulator for @c setf.
117
   *  @param  __base  A numeric base.
118
   *
119
   *  Sent to a stream object, this manipulator changes the
120
   *  @c ios_base::basefield flags to @c oct, @c dec, or @c hex when @a base
121
   *  is 8, 10, or 16, accordingly, and to 0 if @a __base is any other value.
122
  */
123
  inline _Setbase 
124
  setbase(int __base)
125
  { _Setbase s = { __base }; return s; }
126
127
  template<typename _CharT, typename _Traits>
128
    inline basic_istream<_CharT, _Traits>& 
129
    operator>>(basic_istream<_CharT, _Traits>& __is, _Setbase __f)
130
    {
131
      __is.setf(__f._M_base ==  8 ? ios_base::oct : 
132
		__f._M_base == 10 ? ios_base::dec : 
133
		__f._M_base == 16 ? ios_base::hex : 
134
		ios_base::fmtflags(0), ios_base::basefield);
135
      return __is; 
136
    }
137
  
138
  template<typename _CharT, typename _Traits>
139
    inline basic_ostream<_CharT, _Traits>& 
140
    operator<<(basic_ostream<_CharT, _Traits>& __os, _Setbase __f)
141
    {
142
      __os.setf(__f._M_base ==  8 ? ios_base::oct : 
143
		__f._M_base == 10 ? ios_base::dec : 
144
		__f._M_base == 16 ? ios_base::hex : 
145
		ios_base::fmtflags(0), ios_base::basefield);
146
      return __os; 
147
    }
148
  
149
150
  template<typename _CharT>
151
    struct _Setfill { _CharT _M_c; };
152
153
  /**
154
   *  @brief  Manipulator for @c fill.
155
   *  @param  __c  The new fill character.
156
   *
157
   *  Sent to a stream object, this manipulator calls @c fill(__c) for that
158
   *  object.
159
  */
160
  template<typename _CharT>
161
    inline _Setfill<_CharT>
162
    setfill(_CharT __c)
163
    { _Setfill<_CharT> s = { __c }; return s; }
164
165
  template<typename _CharT, typename _Traits>
166
    inline basic_istream<_CharT, _Traits>& 
167
    operator>>(basic_istream<_CharT, _Traits>& __is, _Setfill<_CharT> __f)
168
    { 
169
      __is.fill(__f._M_c); 
170
      return __is; 
171
    }
172
173
  template<typename _CharT, typename _Traits>
174
    inline basic_ostream<_CharT, _Traits>& 
175
    operator<<(basic_ostream<_CharT, _Traits>& __os, _Setfill<_CharT> __f)
176
    { 
177
      __os.fill(__f._M_c); 
178
      return __os; 
179
    }
180
181
182
  struct _Setprecision { int _M_n; };
183
184
  /**
185
   *  @brief  Manipulator for @c precision.
186
   *  @param  __n  The new precision.
187
   *
188
   *  Sent to a stream object, this manipulator calls @c precision(__n) for
189
   *  that object.
190
  */
191
  inline _Setprecision 
192
  setprecision(int __n)
193
  { _Setprecision s = { __n }; return s; }
194
195
  template<typename _CharT, typename _Traits>
196
    inline basic_istream<_CharT, _Traits>& 
197
    operator>>(basic_istream<_CharT, _Traits>& __is, _Setprecision __f)
198
    { 
199
      __is.precision(__f._M_n); 
200
      return __is; 
201
    }
202
203
  template<typename _CharT, typename _Traits>
204
    inline basic_ostream<_CharT, _Traits>& 
205
    operator<<(basic_ostream<_CharT, _Traits>& __os, _Setprecision __f)
206
    { 
207
      __os.precision(__f._M_n); 
208
      return __os; 
209
    }
210
211
212
  struct _Setw { int _M_n; };
213
214
  /**
215
   *  @brief  Manipulator for @c width.
216
   *  @param  __n  The new width.
217
   *
218
   *  Sent to a stream object, this manipulator calls @c width(__n) for
219
   *  that object.
220
  */
221
  inline _Setw 
222
  setw(int __n)
223
  { _Setw s = {__n} ; return s; }
224
225
  template<typename _CharT, typename _Traits>
226
    inline basic_istream<_CharT, _Traits>& 
227
    operator>>(basic_istream<_CharT, _Traits>& __is, _Setw __f)
228
    {
229
      __is.width(__f._M_n);
230
      return __is; 
231
    }
232
233
  template<typename _CharT, typename _Traits>
234
    inline basic_ostream<_CharT, _Traits>& 
235
    operator<<(basic_ostream<_CharT, _Traits>& __os, _Setw __f)
236
    {
237
      __os.width(__f._M_n);
238
      return __os; 
239
    }
240
241
#if __cplusplus >= 201103L
242
  
243
  template<typename _MoneyT>
244
    struct _Get_money { _MoneyT& _M_mon; bool _M_intl; };
245
246
  /**
247
   *  @brief  Extended manipulator for extracting money.
248
   *  @param  __mon  Either long double or a specialization of @c basic_string.
249
   *  @param  __intl A bool indicating whether international format 
250
   *                 is to be used.
251
   *
252
   *  Sent to a stream object, this manipulator extracts @a __mon.
253
  */
254
  template<typename _MoneyT>
255
    inline _Get_money<_MoneyT>
256
    get_money(_MoneyT& __mon, bool __intl = false)
257
    { _Get_money<_MoneyT> r = { __mon, __intl }; return r; }
258
259
  template<typename _CharT, typename _Traits, typename _MoneyT>
260
    basic_istream<_CharT, _Traits>&
261
    operator>>(basic_istream<_CharT, _Traits>& __is, _Get_money<_MoneyT> __f)
262
    {
263
      typename basic_istream<_CharT, _Traits>::sentry __cerb(__is, false);
264
      if (__cerb)
265
	{
266
	  ios_base::iostate __err = ios_base::goodbit;
267
	  __try
268
	    {
269
	      typedef istreambuf_iterator<_CharT, _Traits>   _Iter;
270
	      typedef money_get<_CharT, _Iter>               _MoneyGet;
271
272
	      const _MoneyGet& __mg = use_facet<_MoneyGet>(__is.getloc());
273
	      __mg.get(_Iter(__is.rdbuf()), _Iter(), __f._M_intl,
274
		       __is, __err, __f._M_mon);
275
	    }
276
	  __catch(__cxxabiv1::__forced_unwind&)
277
	    {
278
	      __is._M_setstate(ios_base::badbit);
279
	      __throw_exception_again;
280
	    }
281
	  __catch(...)
282
	    { __is._M_setstate(ios_base::badbit); }
283
	  if (__err)
284
	    __is.setstate(__err);
285
	}
286
      return __is; 
287
    }
288
289
290
  template<typename _MoneyT>
291
    struct _Put_money { const _MoneyT& _M_mon; bool _M_intl; };
292
293
  /**
294
   *  @brief  Extended manipulator for inserting money.
295
   *  @param  __mon  Either long double or a specialization of @c basic_string.
296
   *  @param  __intl A bool indicating whether international format 
297
   *                 is to be used.
298
   *
299
   *  Sent to a stream object, this manipulator inserts @a __mon.
300
  */
301
  template<typename _MoneyT>
302
    inline _Put_money<_MoneyT>
303
    put_money(const _MoneyT& __mon, bool __intl = false)
304
    { _Put_money<_MoneyT> r = { __mon, __intl }; return r; }
305
306
  template<typename _CharT, typename _Traits, typename _MoneyT>
307
    basic_ostream<_CharT, _Traits>& 
308
    operator<<(basic_ostream<_CharT, _Traits>& __os, _Put_money<_MoneyT> __f)
309
    {
310
      typename basic_ostream<_CharT, _Traits>::sentry __cerb(__os);
311
      if (__cerb)
312
	{
313
	  ios_base::iostate __err = ios_base::goodbit;
314
	  __try
315
	    {
316
	      typedef ostreambuf_iterator<_CharT, _Traits>   _Iter;
317
	      typedef money_put<_CharT, _Iter>               _MoneyPut;
318
319
	      const _MoneyPut& __mp = use_facet<_MoneyPut>(__os.getloc());
320
	      if (__mp.put(_Iter(__os.rdbuf()), __f._M_intl, __os,
321
			   __os.fill(), __f._M_mon).failed())
322
		__err |= ios_base::badbit;
323
	    }
324
	  __catch(__cxxabiv1::__forced_unwind&)
325
	    {
326
	      __os._M_setstate(ios_base::badbit);
327
	      __throw_exception_again;
328
	    }
329
	  __catch(...)
330
	    { __os._M_setstate(ios_base::badbit); }
331
	  if (__err)
332
	    __os.setstate(__err);
333
	}
334
      return __os; 
335
    }
336
337
#if __cplusplus > 201103L
338
339
_GLIBCXX_END_NAMESPACE_VERSION
340
  namespace __detail {
341
  _GLIBCXX_BEGIN_NAMESPACE_VERSION
342
343
    /**
344
     * @brief Struct for delimited strings.
345
     *        The left and right delimiters can be different.
346
     */
347
    template<typename _String, typename _CharT>
348
      struct _Quoted_string
349
      {
350
	static_assert(is_reference<_String>::value
351
		   || is_pointer<_String>::value,
352
		      "String type must be pointer or reference");
353
354
	_Quoted_string(_String __str, _CharT __del, _CharT __esc)
355
	: _M_string(__str), _M_delim{__del}, _M_escape{__esc}
356
	{ }
357
358
	_Quoted_string&
359
	operator=(_Quoted_string&) = delete;
360
361
	_String _M_string;
362
	_CharT _M_delim;
363
	_CharT _M_escape;
364
      };
365
366
    /**
367
     * @brief Inserter for delimited strings.
368
     *        The left and right delimiters can be different.
369
     */
370
    template<typename _CharT, typename _Traits>
371
      auto&
372
      operator<<(std::basic_ostream<_CharT, _Traits>& __os,
373
		 const _Quoted_string<const _CharT*, _CharT>& __str)
374
      {
375
	__os << __str._M_delim;
376
	for (const _CharT* __c = __str._M_string; *__c; ++__c)
377
	  {
378
	    if (*__c == __str._M_delim || *__c == __str._M_escape)
379
	      __os << __str._M_escape;
380
	    __os << *__c;
381
	  }
382
	__os << __str._M_delim;
383
384
	return __os;
385
      }
386
387
    /**
388
     * @brief Inserter for delimited strings.
389
     *        The left and right delimiters can be different.
390
     */
391
    template<typename _CharT, typename _Traits, typename _String>
392
      auto&
393
      operator<<(std::basic_ostream<_CharT, _Traits>& __os,
394
		 const _Quoted_string<_String, _CharT>& __str)
395
      {
396
	__os << __str._M_delim;
397
	for (auto& __c : __str._M_string)
398
	  {
399
	    if (__c == __str._M_delim || __c == __str._M_escape)
400
	      __os << __str._M_escape;
401
	    __os << __c;
402
	  }
403
	__os << __str._M_delim;
404
405
	return __os;
406
      }
407
408
    /**
409
     * @brief Extractor for delimited strings.
410
     *        The left and right delimiters can be different.
411
     */
412
    template<typename _CharT, typename _Traits, typename _Alloc>
413
      auto&
414
      operator>>(std::basic_istream<_CharT, _Traits>& __is,
415
		 const _Quoted_string<basic_string<_CharT, _Traits, _Alloc>&,
416
				      _CharT>& __str)
417
      {
418
	_CharT __c;
419
	__is >> __c;
420
	if (!__is.good())
421
	  return __is;
422
	if (__c != __str._M_delim)
423
	  {
424
	    __is.unget();
425
	    __is >> __str._M_string;
426
	    return __is;
427
	  }
428
	__str._M_string.clear();
429
	std::ios_base::fmtflags __flags
430
	  = __is.flags(__is.flags() & ~std::ios_base::skipws);
431
	do
432
	  {
433
	    __is >> __c;
434
	    if (!__is.good())
435
	      break;
436
	    if (__c == __str._M_escape)
437
	      {
438
		__is >> __c;
439
		if (!__is.good())
440
		  break;
441
	      }
442
	    else if (__c == __str._M_delim)
443
	      break;
444
	    __str._M_string += __c;
445
	  }
446
	while (true);
447
	__is.setf(__flags);
448
449
	return __is;
450
      }
451
  _GLIBCXX_END_NAMESPACE_VERSION
452
  } // namespace __detail
453
_GLIBCXX_BEGIN_NAMESPACE_VERSION
454
455
  /**
456
   * @brief Manipulator for quoted strings.
457
   * @param __str    String to quote.
458
   * @param __delim  Character to quote string with.
459
   * @param __escape Escape character to escape itself or quote character.
460
   */
461
  template<typename _CharT>
462
    inline auto
463
    quoted(const _CharT* __string,
464
	   _CharT __delim = _CharT('"'), _CharT __escape = _CharT('\\'))
465
    {
466
      return __detail::_Quoted_string<const _CharT*, _CharT>(__string, __delim,
467
							     __escape);
468
    }
469
470
  template<typename _CharT, typename _Traits, typename _Alloc>
471
    inline auto
472
    quoted(const basic_string<_CharT, _Traits, _Alloc>& __string,
473
	   _CharT __delim = _CharT('"'), _CharT __escape = _CharT('\\'))
474
    {
475
      return __detail::_Quoted_string<
476
			const basic_string<_CharT, _Traits, _Alloc>&, _CharT>(
477
				__string, __delim, __escape);
478
    }
479
480
  template<typename _CharT, typename _Traits, typename _Alloc>
481
    inline auto
482
    quoted(basic_string<_CharT, _Traits, _Alloc>& __string,
483
	   _CharT __delim = _CharT('"'), _CharT __escape = _CharT('\\'))
484
    {
485
      return __detail::_Quoted_string<
486
			basic_string<_CharT, _Traits, _Alloc>&, _CharT>(
487
				__string, __delim, __escape);
488
    }
489
490
#endif // __cplusplus > 201103L
491
492
#endif // __cplusplus >= 201103L
493
494
  // Inhibit implicit instantiations for required instantiations,
495
  // which are defined via explicit instantiations elsewhere.  
496
  // NB:  This syntax is a GNU extension.
497
#if _GLIBCXX_EXTERN_TEMPLATE
498
  extern template ostream& operator<<(ostream&, _Setfill<char>);
499
  extern template ostream& operator<<(ostream&, _Setiosflags);
500
  extern template ostream& operator<<(ostream&, _Resetiosflags);
501
  extern template ostream& operator<<(ostream&, _Setbase);
502
  extern template ostream& operator<<(ostream&, _Setprecision);
503
  extern template ostream& operator<<(ostream&, _Setw);
504
  extern template istream& operator>>(istream&, _Setfill<char>);
505
  extern template istream& operator>>(istream&, _Setiosflags);
506
  extern template istream& operator>>(istream&, _Resetiosflags);
507
  extern template istream& operator>>(istream&, _Setbase);
508
  extern template istream& operator>>(istream&, _Setprecision);
509
  extern template istream& operator>>(istream&, _Setw);
510
511
#ifdef _GLIBCXX_USE_WCHAR_T
512
  extern template wostream& operator<<(wostream&, _Setfill<wchar_t>);
513
  extern template wostream& operator<<(wostream&, _Setiosflags);
514
  extern template wostream& operator<<(wostream&, _Resetiosflags);
515
  extern template wostream& operator<<(wostream&, _Setbase);
516
  extern template wostream& operator<<(wostream&, _Setprecision);
517
  extern template wostream& operator<<(wostream&, _Setw);
518
  extern template wistream& operator>>(wistream&, _Setfill<wchar_t>);
519
  extern template wistream& operator>>(wistream&, _Setiosflags);
520
  extern template wistream& operator>>(wistream&, _Resetiosflags);
521
  extern template wistream& operator>>(wistream&, _Setbase);
522
  extern template wistream& operator>>(wistream&, _Setprecision);
523
  extern template wistream& operator>>(wistream&, _Setw);
524
#endif
525
#endif
526
527
_GLIBCXX_END_NAMESPACE_VERSION
528
} // namespace
529
530
#endif /* _GLIBCXX_IOMANIP */
(-)GCC_XML/Support/GCC/4.9/mmintrin.h (+888 lines)
Line 0 Link Here
1
/* Copyright (C) 2002-2014 Free Software Foundation, Inc.
2
3
   This file is part of GCC.
4
5
   GCC is free software; you can redistribute it and/or modify
6
   it under the terms of the GNU General Public License as published by
7
   the Free Software Foundation; either version 3, or (at your option)
8
   any later version.
9
10
   GCC is distributed in the hope that it will be useful,
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
   GNU General Public License for more details.
14
15
   Under Section 7 of GPL version 3, you are granted additional
16
   permissions described in the GCC Runtime Library Exception, version
17
   3.1, as published by the Free Software Foundation.
18
19
   You should have received a copy of the GNU General Public License and
20
   a copy of the GCC Runtime Library Exception along with this program;
21
   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
22
   <http://www.gnu.org/licenses/>.  */
23
24
/* Implemented from the specification included in the Intel C++ Compiler
25
   User Guide and Reference, version 9.0.  */
26
27
#ifndef _MMINTRIN_H_INCLUDED
28
#define _MMINTRIN_H_INCLUDED
29
30
#ifndef __MMX__
31
#pragma GCC push_options
32
#pragma GCC target("mmx")
33
#define __DISABLE_MMX__
34
#endif /* __MMX__ */
35
36
/* The Intel API is flexible enough that we must allow aliasing with other
37
   vector types, and their scalar components.  */
38
typedef int __m64 __attribute__ ((__vector_size__ (8), __may_alias__));
39
40
/* Internal data types for implementing the intrinsics.  */
41
typedef int __v2si __attribute__ ((__vector_size__ (8)));
42
typedef short __v4hi __attribute__ ((__vector_size__ (8)));
43
typedef char __v8qi __attribute__ ((__vector_size__ (8)));
44
typedef long long __v1di __attribute__ ((__vector_size__ (8)));
45
typedef float __v2sf __attribute__ ((__vector_size__ (8)));
46
47
/* Empty the multimedia state.  */
48
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
49
_mm_empty (void)
50
{
51
  __builtin_ia32_emms ();
52
}
53
54
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
55
_m_empty (void)
56
{
57
  _mm_empty ();
58
}
59
60
/* Convert I to a __m64 object.  The integer is zero-extended to 64-bits.  */
61
extern __inline __m64  __attribute__((__gnu_inline__, __always_inline__, __artificial__))
62
_mm_cvtsi32_si64 (int __i)
63
{
64
  return (__m64) __builtin_ia32_vec_init_v2si (__i, 0);
65
}
66
67
extern __inline __m64  __attribute__((__gnu_inline__, __always_inline__, __artificial__))
68
_m_from_int (int __i)
69
{
70
  return _mm_cvtsi32_si64 (__i);
71
}
72
73
#ifdef __x86_64__
74
/* Convert I to a __m64 object.  */
75
76
/* Intel intrinsic.  */
77
extern __inline __m64  __attribute__((__gnu_inline__, __always_inline__, __artificial__))
78
_m_from_int64 (long long __i)
79
{
80
  return (__m64) __i;
81
}
82
83
extern __inline __m64  __attribute__((__gnu_inline__, __always_inline__, __artificial__))
84
_mm_cvtsi64_m64 (long long __i)
85
{
86
  return (__m64) __i;
87
}
88
89
/* Microsoft intrinsic.  */
90
extern __inline __m64  __attribute__((__gnu_inline__, __always_inline__, __artificial__))
91
_mm_cvtsi64x_si64 (long long __i)
92
{
93
  return (__m64) __i;
94
}
95
96
extern __inline __m64  __attribute__((__gnu_inline__, __always_inline__, __artificial__))
97
_mm_set_pi64x (long long __i)
98
{
99
  return (__m64) __i;
100
}
101
#endif
102
103
/* Convert the lower 32 bits of the __m64 object into an integer.  */
104
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
105
_mm_cvtsi64_si32 (__m64 __i)
106
{
107
  return __builtin_ia32_vec_ext_v2si ((__v2si)__i, 0);
108
}
109
110
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
111
_m_to_int (__m64 __i)
112
{
113
  return _mm_cvtsi64_si32 (__i);
114
}
115
116
#ifdef __x86_64__
117
/* Convert the __m64 object to a 64bit integer.  */
118
119
/* Intel intrinsic.  */
120
extern __inline long long __attribute__((__gnu_inline__, __always_inline__, __artificial__))
121
_m_to_int64 (__m64 __i)
122
{
123
  return (long long)__i;
124
}
125
126
extern __inline long long __attribute__((__gnu_inline__, __always_inline__, __artificial__))
127
_mm_cvtm64_si64 (__m64 __i)
128
{
129
  return (long long)__i;
130
}
131
132
/* Microsoft intrinsic.  */
133
extern __inline long long __attribute__((__gnu_inline__, __always_inline__, __artificial__))
134
_mm_cvtsi64_si64x (__m64 __i)
135
{
136
  return (long long)__i;
137
}
138
#endif
139
140
/* Pack the four 16-bit values from M1 into the lower four 8-bit values of
141
   the result, and the four 16-bit values from M2 into the upper four 8-bit
142
   values of the result, all with signed saturation.  */
143
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
144
_mm_packs_pi16 (__m64 __m1, __m64 __m2)
145
{
146
  return (__m64) __builtin_ia32_packsswb ((__v4hi)__m1, (__v4hi)__m2);
147
}
148
149
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
150
_m_packsswb (__m64 __m1, __m64 __m2)
151
{
152
  return _mm_packs_pi16 (__m1, __m2);
153
}
154
155
/* Pack the two 32-bit values from M1 in to the lower two 16-bit values of
156
   the result, and the two 32-bit values from M2 into the upper two 16-bit
157
   values of the result, all with signed saturation.  */
158
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
159
_mm_packs_pi32 (__m64 __m1, __m64 __m2)
160
{
161
  return (__m64) __builtin_ia32_packssdw ((__v2si)__m1, (__v2si)__m2);
162
}
163
164
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
165
_m_packssdw (__m64 __m1, __m64 __m2)
166
{
167
  return _mm_packs_pi32 (__m1, __m2);
168
}
169
170
/* Pack the four 16-bit values from M1 into the lower four 8-bit values of
171
   the result, and the four 16-bit values from M2 into the upper four 8-bit
172
   values of the result, all with unsigned saturation.  */
173
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
174
_mm_packs_pu16 (__m64 __m1, __m64 __m2)
175
{
176
  return (__m64) __builtin_ia32_packuswb ((__v4hi)__m1, (__v4hi)__m2);
177
}
178
179
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
180
_m_packuswb (__m64 __m1, __m64 __m2)
181
{
182
  return _mm_packs_pu16 (__m1, __m2);
183
}
184
185
/* Interleave the four 8-bit values from the high half of M1 with the four
186
   8-bit values from the high half of M2.  */
187
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
188
_mm_unpackhi_pi8 (__m64 __m1, __m64 __m2)
189
{
190
  return (__m64) __builtin_ia32_punpckhbw ((__v8qi)__m1, (__v8qi)__m2);
191
}
192
193
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
194
_m_punpckhbw (__m64 __m1, __m64 __m2)
195
{
196
  return _mm_unpackhi_pi8 (__m1, __m2);
197
}
198
199
/* Interleave the two 16-bit values from the high half of M1 with the two
200
   16-bit values from the high half of M2.  */
201
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
202
_mm_unpackhi_pi16 (__m64 __m1, __m64 __m2)
203
{
204
  return (__m64) __builtin_ia32_punpckhwd ((__v4hi)__m1, (__v4hi)__m2);
205
}
206
207
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
208
_m_punpckhwd (__m64 __m1, __m64 __m2)
209
{
210
  return _mm_unpackhi_pi16 (__m1, __m2);
211
}
212
213
/* Interleave the 32-bit value from the high half of M1 with the 32-bit
214
   value from the high half of M2.  */
215
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
216
_mm_unpackhi_pi32 (__m64 __m1, __m64 __m2)
217
{
218
  return (__m64) __builtin_ia32_punpckhdq ((__v2si)__m1, (__v2si)__m2);
219
}
220
221
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
222
_m_punpckhdq (__m64 __m1, __m64 __m2)
223
{
224
  return _mm_unpackhi_pi32 (__m1, __m2);
225
}
226
227
/* Interleave the four 8-bit values from the low half of M1 with the four
228
   8-bit values from the low half of M2.  */
229
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
230
_mm_unpacklo_pi8 (__m64 __m1, __m64 __m2)
231
{
232
  return (__m64) __builtin_ia32_punpcklbw ((__v8qi)__m1, (__v8qi)__m2);
233
}
234
235
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
236
_m_punpcklbw (__m64 __m1, __m64 __m2)
237
{
238
  return _mm_unpacklo_pi8 (__m1, __m2);
239
}
240
241
/* Interleave the two 16-bit values from the low half of M1 with the two
242
   16-bit values from the low half of M2.  */
243
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
244
_mm_unpacklo_pi16 (__m64 __m1, __m64 __m2)
245
{
246
  return (__m64) __builtin_ia32_punpcklwd ((__v4hi)__m1, (__v4hi)__m2);
247
}
248
249
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
250
_m_punpcklwd (__m64 __m1, __m64 __m2)
251
{
252
  return _mm_unpacklo_pi16 (__m1, __m2);
253
}
254
255
/* Interleave the 32-bit value from the low half of M1 with the 32-bit
256
   value from the low half of M2.  */
257
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
258
_mm_unpacklo_pi32 (__m64 __m1, __m64 __m2)
259
{
260
  return (__m64) __builtin_ia32_punpckldq ((__v2si)__m1, (__v2si)__m2);
261
}
262
263
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
264
_m_punpckldq (__m64 __m1, __m64 __m2)
265
{
266
  return _mm_unpacklo_pi32 (__m1, __m2);
267
}
268
269
/* Add the 8-bit values in M1 to the 8-bit values in M2.  */
270
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
271
_mm_add_pi8 (__m64 __m1, __m64 __m2)
272
{
273
  return (__m64) __builtin_ia32_paddb ((__v8qi)__m1, (__v8qi)__m2);
274
}
275
276
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
277
_m_paddb (__m64 __m1, __m64 __m2)
278
{
279
  return _mm_add_pi8 (__m1, __m2);
280
}
281
282
/* Add the 16-bit values in M1 to the 16-bit values in M2.  */
283
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
284
_mm_add_pi16 (__m64 __m1, __m64 __m2)
285
{
286
  return (__m64) __builtin_ia32_paddw ((__v4hi)__m1, (__v4hi)__m2);
287
}
288
289
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
290
_m_paddw (__m64 __m1, __m64 __m2)
291
{
292
  return _mm_add_pi16 (__m1, __m2);
293
}
294
295
/* Add the 32-bit values in M1 to the 32-bit values in M2.  */
296
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
297
_mm_add_pi32 (__m64 __m1, __m64 __m2)
298
{
299
  return (__m64) __builtin_ia32_paddd ((__v2si)__m1, (__v2si)__m2);
300
}
301
302
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
303
_m_paddd (__m64 __m1, __m64 __m2)
304
{
305
  return _mm_add_pi32 (__m1, __m2);
306
}
307
308
/* Add the 64-bit values in M1 to the 64-bit values in M2.  */
309
#ifndef __SSE2__
310
#pragma GCC push_options
311
#pragma GCC target("sse2")
312
#define __DISABLE_SSE2__
313
#endif /* __SSE2__ */
314
315
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
316
_mm_add_si64 (__m64 __m1, __m64 __m2);
317
#ifdef __DISABLE_SSE2__
318
#undef __DISABLE_SSE2__
319
#pragma GCC pop_options
320
#endif /* __DISABLE_SSE2__ */
321
322
/* Add the 8-bit values in M1 to the 8-bit values in M2 using signed
323
   saturated arithmetic.  */
324
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
325
_mm_adds_pi8 (__m64 __m1, __m64 __m2)
326
{
327
  return (__m64) __builtin_ia32_paddsb ((__v8qi)__m1, (__v8qi)__m2);
328
}
329
330
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
331
_m_paddsb (__m64 __m1, __m64 __m2)
332
{
333
  return _mm_adds_pi8 (__m1, __m2);
334
}
335
336
/* Add the 16-bit values in M1 to the 16-bit values in M2 using signed
337
   saturated arithmetic.  */
338
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
339
_mm_adds_pi16 (__m64 __m1, __m64 __m2)
340
{
341
  return (__m64) __builtin_ia32_paddsw ((__v4hi)__m1, (__v4hi)__m2);
342
}
343
344
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
345
_m_paddsw (__m64 __m1, __m64 __m2)
346
{
347
  return _mm_adds_pi16 (__m1, __m2);
348
}
349
350
/* Add the 8-bit values in M1 to the 8-bit values in M2 using unsigned
351
   saturated arithmetic.  */
352
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
353
_mm_adds_pu8 (__m64 __m1, __m64 __m2)
354
{
355
  return (__m64) __builtin_ia32_paddusb ((__v8qi)__m1, (__v8qi)__m2);
356
}
357
358
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
359
_m_paddusb (__m64 __m1, __m64 __m2)
360
{
361
  return _mm_adds_pu8 (__m1, __m2);
362
}
363
364
/* Add the 16-bit values in M1 to the 16-bit values in M2 using unsigned
365
   saturated arithmetic.  */
366
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
367
_mm_adds_pu16 (__m64 __m1, __m64 __m2)
368
{
369
  return (__m64) __builtin_ia32_paddusw ((__v4hi)__m1, (__v4hi)__m2);
370
}
371
372
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
373
_m_paddusw (__m64 __m1, __m64 __m2)
374
{
375
  return _mm_adds_pu16 (__m1, __m2);
376
}
377
378
/* Subtract the 8-bit values in M2 from the 8-bit values in M1.  */
379
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
380
_mm_sub_pi8 (__m64 __m1, __m64 __m2)
381
{
382
  return (__m64) __builtin_ia32_psubb ((__v8qi)__m1, (__v8qi)__m2);
383
}
384
385
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
386
_m_psubb (__m64 __m1, __m64 __m2)
387
{
388
  return _mm_sub_pi8 (__m1, __m2);
389
}
390
391
/* Subtract the 16-bit values in M2 from the 16-bit values in M1.  */
392
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
393
_mm_sub_pi16 (__m64 __m1, __m64 __m2)
394
{
395
  return (__m64) __builtin_ia32_psubw ((__v4hi)__m1, (__v4hi)__m2);
396
}
397
398
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
399
_m_psubw (__m64 __m1, __m64 __m2)
400
{
401
  return _mm_sub_pi16 (__m1, __m2);
402
}
403
404
/* Subtract the 32-bit values in M2 from the 32-bit values in M1.  */
405
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
406
_mm_sub_pi32 (__m64 __m1, __m64 __m2)
407
{
408
  return (__m64) __builtin_ia32_psubd ((__v2si)__m1, (__v2si)__m2);
409
}
410
411
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
412
_m_psubd (__m64 __m1, __m64 __m2)
413
{
414
  return _mm_sub_pi32 (__m1, __m2);
415
}
416
417
/* Add the 64-bit values in M1 to the 64-bit values in M2.  */
418
#ifndef __SSE2__
419
#pragma GCC push_options
420
#pragma GCC target("sse2")
421
#define __DISABLE_SSE2__
422
#endif /* __SSE2__ */
423
424
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
425
_mm_sub_si64 (__m64 __m1, __m64 __m2);
426
#ifdef __DISABLE_SSE2__
427
#undef __DISABLE_SSE2__
428
#pragma GCC pop_options
429
#endif /* __DISABLE_SSE2__ */
430
431
/* Subtract the 8-bit values in M2 from the 8-bit values in M1 using signed
432
   saturating arithmetic.  */
433
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
434
_mm_subs_pi8 (__m64 __m1, __m64 __m2)
435
{
436
  return (__m64) __builtin_ia32_psubsb ((__v8qi)__m1, (__v8qi)__m2);
437
}
438
439
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
440
_m_psubsb (__m64 __m1, __m64 __m2)
441
{
442
  return _mm_subs_pi8 (__m1, __m2);
443
}
444
445
/* Subtract the 16-bit values in M2 from the 16-bit values in M1 using
446
   signed saturating arithmetic.  */
447
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
448
_mm_subs_pi16 (__m64 __m1, __m64 __m2)
449
{
450
  return (__m64) __builtin_ia32_psubsw ((__v4hi)__m1, (__v4hi)__m2);
451
}
452
453
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
454
_m_psubsw (__m64 __m1, __m64 __m2)
455
{
456
  return _mm_subs_pi16 (__m1, __m2);
457
}
458
459
/* Subtract the 8-bit values in M2 from the 8-bit values in M1 using
460
   unsigned saturating arithmetic.  */
461
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
462
_mm_subs_pu8 (__m64 __m1, __m64 __m2)
463
{
464
  return (__m64) __builtin_ia32_psubusb ((__v8qi)__m1, (__v8qi)__m2);
465
}
466
467
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
468
_m_psubusb (__m64 __m1, __m64 __m2)
469
{
470
  return _mm_subs_pu8 (__m1, __m2);
471
}
472
473
/* Subtract the 16-bit values in M2 from the 16-bit values in M1 using
474
   unsigned saturating arithmetic.  */
475
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
476
_mm_subs_pu16 (__m64 __m1, __m64 __m2)
477
{
478
  return (__m64) __builtin_ia32_psubusw ((__v4hi)__m1, (__v4hi)__m2);
479
}
480
481
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
482
_m_psubusw (__m64 __m1, __m64 __m2)
483
{
484
  return _mm_subs_pu16 (__m1, __m2);
485
}
486
487
/* Multiply four 16-bit values in M1 by four 16-bit values in M2 producing
488
   four 32-bit intermediate results, which are then summed by pairs to
489
   produce two 32-bit results.  */
490
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
491
_mm_madd_pi16 (__m64 __m1, __m64 __m2)
492
{
493
  return (__m64) __builtin_ia32_pmaddwd ((__v4hi)__m1, (__v4hi)__m2);
494
}
495
496
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
497
_m_pmaddwd (__m64 __m1, __m64 __m2)
498
{
499
  return _mm_madd_pi16 (__m1, __m2);
500
}
501
502
/* Multiply four signed 16-bit values in M1 by four signed 16-bit values in
503
   M2 and produce the high 16 bits of the 32-bit results.  */
504
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
505
_mm_mulhi_pi16 (__m64 __m1, __m64 __m2)
506
{
507
  return (__m64) __builtin_ia32_pmulhw ((__v4hi)__m1, (__v4hi)__m2);
508
}
509
510
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
511
_m_pmulhw (__m64 __m1, __m64 __m2)
512
{
513
  return _mm_mulhi_pi16 (__m1, __m2);
514
}
515
516
/* Multiply four 16-bit values in M1 by four 16-bit values in M2 and produce
517
   the low 16 bits of the results.  */
518
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
519
_mm_mullo_pi16 (__m64 __m1, __m64 __m2)
520
{
521
  return (__m64) __builtin_ia32_pmullw ((__v4hi)__m1, (__v4hi)__m2);
522
}
523
524
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
525
_m_pmullw (__m64 __m1, __m64 __m2)
526
{
527
  return _mm_mullo_pi16 (__m1, __m2);
528
}
529
530
/* Shift four 16-bit values in M left by COUNT.  */
531
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
532
_mm_sll_pi16 (__m64 __m, __m64 __count);
533
534
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
535
_m_psllw (__m64 __m, __m64 __count)
536
{
537
  return _mm_sll_pi16 (__m, __count);
538
}
539
540
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
541
_mm_slli_pi16 (__m64 __m, int __count);
542
543
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
544
_m_psllwi (__m64 __m, int __count)
545
{
546
  return _mm_slli_pi16 (__m, __count);
547
}
548
549
/* Shift two 32-bit values in M left by COUNT.  */
550
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
551
_mm_sll_pi32 (__m64 __m, __m64 __count);
552
553
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
554
_m_pslld (__m64 __m, __m64 __count)
555
{
556
  return _mm_sll_pi32 (__m, __count);
557
}
558
559
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
560
_mm_slli_pi32 (__m64 __m, int __count);
561
562
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
563
_m_pslldi (__m64 __m, int __count)
564
{
565
  return _mm_slli_pi32 (__m, __count);
566
}
567
568
/* Shift the 64-bit value in M left by COUNT.  */
569
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
570
_mm_sll_si64 (__m64 __m, __m64 __count);
571
572
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
573
_m_psllq (__m64 __m, __m64 __count)
574
{
575
  return _mm_sll_si64 (__m, __count);
576
}
577
578
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
579
_mm_slli_si64 (__m64 __m, int __count);
580
581
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
582
_m_psllqi (__m64 __m, int __count)
583
{
584
  return _mm_slli_si64 (__m, __count);
585
}
586
587
/* Shift four 16-bit values in M right by COUNT; shift in the sign bit.  */
588
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
589
_mm_sra_pi16 (__m64 __m, __m64 __count);
590
591
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
592
_m_psraw (__m64 __m, __m64 __count)
593
{
594
  return _mm_sra_pi16 (__m, __count);
595
}
596
597
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
598
_mm_srai_pi16 (__m64 __m, int __count);
599
600
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
601
_m_psrawi (__m64 __m, int __count)
602
{
603
  return _mm_srai_pi16 (__m, __count);
604
}
605
606
/* Shift two 32-bit values in M right by COUNT; shift in the sign bit.  */
607
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
608
_mm_sra_pi32 (__m64 __m, __m64 __count);
609
610
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
611
_m_psrad (__m64 __m, __m64 __count)
612
{
613
  return _mm_sra_pi32 (__m, __count);
614
}
615
616
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
617
_mm_srai_pi32 (__m64 __m, int __count);
618
619
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
620
_m_psradi (__m64 __m, int __count)
621
{
622
  return _mm_srai_pi32 (__m, __count);
623
}
624
625
/* Shift four 16-bit values in M right by COUNT; shift in zeros.  */
626
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
627
_mm_srl_pi16 (__m64 __m, __m64 __count);
628
629
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
630
_m_psrlw (__m64 __m, __m64 __count)
631
{
632
  return _mm_srl_pi16 (__m, __count);
633
}
634
635
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
636
_mm_srli_pi16 (__m64 __m, int __count);
637
638
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
639
_m_psrlwi (__m64 __m, int __count)
640
{
641
  return _mm_srli_pi16 (__m, __count);
642
}
643
644
/* Shift two 32-bit values in M right by COUNT; shift in zeros.  */
645
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
646
_mm_srl_pi32 (__m64 __m, __m64 __count);
647
648
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
649
_m_psrld (__m64 __m, __m64 __count)
650
{
651
  return _mm_srl_pi32 (__m, __count);
652
}
653
654
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
655
_mm_srli_pi32 (__m64 __m, int __count);
656
657
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
658
_m_psrldi (__m64 __m, int __count)
659
{
660
  return _mm_srli_pi32 (__m, __count);
661
}
662
663
/* Shift the 64-bit value in M left by COUNT; shift in zeros.  */
664
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
665
_mm_srl_si64 (__m64 __m, __m64 __count);
666
667
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
668
_m_psrlq (__m64 __m, __m64 __count)
669
{
670
  return _mm_srl_si64 (__m, __count);
671
}
672
673
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
674
_mm_srli_si64 (__m64 __m, int __count);
675
676
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
677
_m_psrlqi (__m64 __m, int __count)
678
{
679
  return _mm_srli_si64 (__m, __count);
680
}
681
682
/* Bit-wise AND the 64-bit values in M1 and M2.  */
683
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
684
_mm_and_si64 (__m64 __m1, __m64 __m2)
685
{
686
  return __builtin_ia32_pand (__m1, __m2);
687
}
688
689
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
690
_m_pand (__m64 __m1, __m64 __m2)
691
{
692
  return _mm_and_si64 (__m1, __m2);
693
}
694
695
/* Bit-wise complement the 64-bit value in M1 and bit-wise AND it with the
696
   64-bit value in M2.  */
697
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
698
_mm_andnot_si64 (__m64 __m1, __m64 __m2)
699
{
700
  return __builtin_ia32_pandn (__m1, __m2);
701
}
702
703
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
704
_m_pandn (__m64 __m1, __m64 __m2)
705
{
706
  return _mm_andnot_si64 (__m1, __m2);
707
}
708
709
/* Bit-wise inclusive OR the 64-bit values in M1 and M2.  */
710
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
711
_mm_or_si64 (__m64 __m1, __m64 __m2)
712
{
713
  return __builtin_ia32_por (__m1, __m2);
714
}
715
716
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
717
_m_por (__m64 __m1, __m64 __m2)
718
{
719
  return _mm_or_si64 (__m1, __m2);
720
}
721
722
/* Bit-wise exclusive OR the 64-bit values in M1 and M2.  */
723
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
724
_mm_xor_si64 (__m64 __m1, __m64 __m2)
725
{
726
  return __builtin_ia32_pxor (__m1, __m2);
727
}
728
729
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
730
_m_pxor (__m64 __m1, __m64 __m2)
731
{
732
  return _mm_xor_si64 (__m1, __m2);
733
}
734
735
/* Compare eight 8-bit values.  The result of the comparison is 0xFF if the
736
   test is true and zero if false.  */
737
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
738
_mm_cmpeq_pi8 (__m64 __m1, __m64 __m2)
739
{
740
  return (__m64) __builtin_ia32_pcmpeqb ((__v8qi)__m1, (__v8qi)__m2);
741
}
742
743
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
744
_m_pcmpeqb (__m64 __m1, __m64 __m2)
745
{
746
  return _mm_cmpeq_pi8 (__m1, __m2);
747
}
748
749
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
750
_mm_cmpgt_pi8 (__m64 __m1, __m64 __m2)
751
{
752
  return (__m64) __builtin_ia32_pcmpgtb ((__v8qi)__m1, (__v8qi)__m2);
753
}
754
755
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
756
_m_pcmpgtb (__m64 __m1, __m64 __m2)
757
{
758
  return _mm_cmpgt_pi8 (__m1, __m2);
759
}
760
761
/* Compare four 16-bit values.  The result of the comparison is 0xFFFF if
762
   the test is true and zero if false.  */
763
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
764
_mm_cmpeq_pi16 (__m64 __m1, __m64 __m2)
765
{
766
  return (__m64) __builtin_ia32_pcmpeqw ((__v4hi)__m1, (__v4hi)__m2);
767
}
768
769
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
770
_m_pcmpeqw (__m64 __m1, __m64 __m2)
771
{
772
  return _mm_cmpeq_pi16 (__m1, __m2);
773
}
774
775
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
776
_mm_cmpgt_pi16 (__m64 __m1, __m64 __m2)
777
{
778
  return (__m64) __builtin_ia32_pcmpgtw ((__v4hi)__m1, (__v4hi)__m2);
779
}
780
781
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
782
_m_pcmpgtw (__m64 __m1, __m64 __m2)
783
{
784
  return _mm_cmpgt_pi16 (__m1, __m2);
785
}
786
787
/* Compare two 32-bit values.  The result of the comparison is 0xFFFFFFFF if
788
   the test is true and zero if false.  */
789
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
790
_mm_cmpeq_pi32 (__m64 __m1, __m64 __m2)
791
{
792
  return (__m64) __builtin_ia32_pcmpeqd ((__v2si)__m1, (__v2si)__m2);
793
}
794
795
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
796
_m_pcmpeqd (__m64 __m1, __m64 __m2)
797
{
798
  return _mm_cmpeq_pi32 (__m1, __m2);
799
}
800
801
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
802
_mm_cmpgt_pi32 (__m64 __m1, __m64 __m2)
803
{
804
  return (__m64) __builtin_ia32_pcmpgtd ((__v2si)__m1, (__v2si)__m2);
805
}
806
807
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
808
_m_pcmpgtd (__m64 __m1, __m64 __m2)
809
{
810
  return _mm_cmpgt_pi32 (__m1, __m2);
811
}
812
813
/* Creates a 64-bit zero.  */
814
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
815
_mm_setzero_si64 (void)
816
{
817
  return (__m64)0LL;
818
}
819
820
/* Creates a vector of two 32-bit values; I0 is least significant.  */
821
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
822
_mm_set_pi32 (int __i1, int __i0)
823
{
824
  return (__m64) __builtin_ia32_vec_init_v2si (__i0, __i1);
825
}
826
827
/* Creates a vector of four 16-bit values; W0 is least significant.  */
828
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
829
_mm_set_pi16 (short __w3, short __w2, short __w1, short __w0)
830
{
831
  return (__m64) __builtin_ia32_vec_init_v4hi (__w0, __w1, __w2, __w3);
832
}
833
834
/* Creates a vector of eight 8-bit values; B0 is least significant.  */
835
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
836
_mm_set_pi8 (char __b7, char __b6, char __b5, char __b4,
837
	     char __b3, char __b2, char __b1, char __b0)
838
{
839
  return (__m64) __builtin_ia32_vec_init_v8qi (__b0, __b1, __b2, __b3,
840
					       __b4, __b5, __b6, __b7);
841
}
842
843
/* Similar, but with the arguments in reverse order.  */
844
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
845
_mm_setr_pi32 (int __i0, int __i1)
846
{
847
  return _mm_set_pi32 (__i1, __i0);
848
}
849
850
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
851
_mm_setr_pi16 (short __w0, short __w1, short __w2, short __w3)
852
{
853
  return _mm_set_pi16 (__w3, __w2, __w1, __w0);
854
}
855
856
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
857
_mm_setr_pi8 (char __b0, char __b1, char __b2, char __b3,
858
	      char __b4, char __b5, char __b6, char __b7)
859
{
860
  return _mm_set_pi8 (__b7, __b6, __b5, __b4, __b3, __b2, __b1, __b0);
861
}
862
863
/* Creates a vector of two 32-bit values, both elements containing I.  */
864
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
865
_mm_set1_pi32 (int __i)
866
{
867
  return _mm_set_pi32 (__i, __i);
868
}
869
870
/* Creates a vector of four 16-bit values, all elements containing W.  */
871
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
872
_mm_set1_pi16 (short __w)
873
{
874
  return _mm_set_pi16 (__w, __w, __w, __w);
875
}
876
877
/* Creates a vector of eight 8-bit values, all elements containing B.  */
878
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
879
_mm_set1_pi8 (char __b)
880
{
881
  return _mm_set_pi8 (__b, __b, __b, __b, __b, __b, __b, __b);
882
}
883
#ifdef __DISABLE_MMX__
884
#undef __DISABLE_MMX__
885
#pragma GCC pop_options
886
#endif /* __DISABLE_MMX__ */
887
888
#endif /* _MMINTRIN_H_INCLUDED */
(-)GCC_XML/Support/GCC/4.9/xmmintrin.h (+1253 lines)
Line 0 Link Here
1
/* Copyright (C) 2002-2014 Free Software Foundation, Inc.
2
3
   This file is part of GCC.
4
5
   GCC is free software; you can redistribute it and/or modify
6
   it under the terms of the GNU General Public License as published by
7
   the Free Software Foundation; either version 3, or (at your option)
8
   any later version.
9
10
   GCC is distributed in the hope that it will be useful,
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
   GNU General Public License for more details.
14
15
   Under Section 7 of GPL version 3, you are granted additional
16
   permissions described in the GCC Runtime Library Exception, version
17
   3.1, as published by the Free Software Foundation.
18
19
   You should have received a copy of the GNU General Public License and
20
   a copy of the GCC Runtime Library Exception along with this program;
21
   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
22
   <http://www.gnu.org/licenses/>.  */
23
24
/* Implemented from the specification included in the Intel C++ Compiler
25
   User Guide and Reference, version 9.0.  */
26
27
#ifndef _XMMINTRIN_H_INCLUDED
28
#define _XMMINTRIN_H_INCLUDED
29
30
/* We need type definitions from the MMX header file.  */
31
#include <mmintrin.h>
32
33
/* Get _mm_malloc () and _mm_free ().  */
34
#include <mm_malloc.h>
35
36
/* Constants for use with _mm_prefetch.  */
37
enum _mm_hint
38
{
39
  /* _MM_HINT_ET is _MM_HINT_T with set 3rd bit.  */
40
  _MM_HINT_ET0 = 7,
41
  _MM_HINT_ET1 = 6,
42
  _MM_HINT_T0 = 3,
43
  _MM_HINT_T1 = 2,
44
  _MM_HINT_T2 = 1,
45
  _MM_HINT_NTA = 0
46
};
47
48
/* Loads one cache line from address P to a location "closer" to the
49
   processor.  The selector I specifies the type of prefetch operation.  */
50
#ifdef __OPTIMIZE__
51
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
52
_mm_prefetch (const void *__P, enum _mm_hint __I)
53
{
54
  __builtin_prefetch (__P, (__I & 0x4) >> 2, __I & 0x3);
55
}
56
#else
57
#define _mm_prefetch(P, I) \
58
  __builtin_prefetch ((P), ((I & 0x4) >> 2), (I & 0x3))
59
#endif
60
61
#ifndef __SSE__
62
#pragma GCC push_options
63
#pragma GCC target("sse")
64
#define __DISABLE_SSE__
65
#endif /* __SSE__ */
66
67
/* The Intel API is flexible enough that we must allow aliasing with other
68
   vector types, and their scalar components.  */
69
typedef float __m128 __attribute__ ((__vector_size__ (16), __may_alias__));
70
71
/* Internal data types for implementing the intrinsics.  */
72
typedef float __v4sf __attribute__ ((__vector_size__ (16)));
73
74
/* Create a selector for use with the SHUFPS instruction.  */
75
#define _MM_SHUFFLE(fp3,fp2,fp1,fp0) \
76
 (((fp3) << 6) | ((fp2) << 4) | ((fp1) << 2) | (fp0))
77
78
/* Bits in the MXCSR.  */
79
#define _MM_EXCEPT_MASK       0x003f
80
#define _MM_EXCEPT_INVALID    0x0001
81
#define _MM_EXCEPT_DENORM     0x0002
82
#define _MM_EXCEPT_DIV_ZERO   0x0004
83
#define _MM_EXCEPT_OVERFLOW   0x0008
84
#define _MM_EXCEPT_UNDERFLOW  0x0010
85
#define _MM_EXCEPT_INEXACT    0x0020
86
87
#define _MM_MASK_MASK         0x1f80
88
#define _MM_MASK_INVALID      0x0080
89
#define _MM_MASK_DENORM       0x0100
90
#define _MM_MASK_DIV_ZERO     0x0200
91
#define _MM_MASK_OVERFLOW     0x0400
92
#define _MM_MASK_UNDERFLOW    0x0800
93
#define _MM_MASK_INEXACT      0x1000
94
95
#define _MM_ROUND_MASK        0x6000
96
#define _MM_ROUND_NEAREST     0x0000
97
#define _MM_ROUND_DOWN        0x2000
98
#define _MM_ROUND_UP          0x4000
99
#define _MM_ROUND_TOWARD_ZERO 0x6000
100
101
#define _MM_FLUSH_ZERO_MASK   0x8000
102
#define _MM_FLUSH_ZERO_ON     0x8000
103
#define _MM_FLUSH_ZERO_OFF    0x0000
104
105
/* Create an undefined vector.  */
106
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
107
_mm_undefined_ps (void)
108
{
109
  __m128 __Y = __Y;
110
  return __Y;
111
}
112
113
/* Create a vector of zeros.  */
114
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
115
_mm_setzero_ps (void)
116
{
117
  return __extension__ (__m128){ 0.0f, 0.0f, 0.0f, 0.0f };
118
}
119
120
/* Perform the respective operation on the lower SPFP (single-precision
121
   floating-point) values of A and B; the upper three SPFP values are
122
   passed through from A.  */
123
124
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
125
_mm_add_ss (__m128 __A, __m128 __B)
126
{
127
  return (__m128) __builtin_ia32_addss ((__v4sf)__A, (__v4sf)__B);
128
}
129
130
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
131
_mm_sub_ss (__m128 __A, __m128 __B)
132
{
133
  return (__m128) __builtin_ia32_subss ((__v4sf)__A, (__v4sf)__B);
134
}
135
136
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
137
_mm_mul_ss (__m128 __A, __m128 __B)
138
{
139
  return (__m128) __builtin_ia32_mulss ((__v4sf)__A, (__v4sf)__B);
140
}
141
142
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
143
_mm_div_ss (__m128 __A, __m128 __B)
144
{
145
  return (__m128) __builtin_ia32_divss ((__v4sf)__A, (__v4sf)__B);
146
}
147
148
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
149
_mm_sqrt_ss (__m128 __A)
150
{
151
  return (__m128) __builtin_ia32_sqrtss ((__v4sf)__A);
152
}
153
154
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
155
_mm_rcp_ss (__m128 __A)
156
{
157
  return (__m128) __builtin_ia32_rcpss ((__v4sf)__A);
158
}
159
160
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
161
_mm_rsqrt_ss (__m128 __A)
162
{
163
  return (__m128) __builtin_ia32_rsqrtss ((__v4sf)__A);
164
}
165
166
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
167
_mm_min_ss (__m128 __A, __m128 __B)
168
{
169
  return (__m128) __builtin_ia32_minss ((__v4sf)__A, (__v4sf)__B);
170
}
171
172
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
173
_mm_max_ss (__m128 __A, __m128 __B)
174
{
175
  return (__m128) __builtin_ia32_maxss ((__v4sf)__A, (__v4sf)__B);
176
}
177
178
/* Perform the respective operation on the four SPFP values in A and B.  */
179
180
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
181
_mm_add_ps (__m128 __A, __m128 __B)
182
{
183
  return (__m128) __builtin_ia32_addps ((__v4sf)__A, (__v4sf)__B);
184
}
185
186
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
187
_mm_sub_ps (__m128 __A, __m128 __B)
188
{
189
  return (__m128) __builtin_ia32_subps ((__v4sf)__A, (__v4sf)__B);
190
}
191
192
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
193
_mm_mul_ps (__m128 __A, __m128 __B)
194
{
195
  return (__m128) __builtin_ia32_mulps ((__v4sf)__A, (__v4sf)__B);
196
}
197
198
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
199
_mm_div_ps (__m128 __A, __m128 __B)
200
{
201
  return (__m128) __builtin_ia32_divps ((__v4sf)__A, (__v4sf)__B);
202
}
203
204
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
205
_mm_sqrt_ps (__m128 __A)
206
{
207
  return (__m128) __builtin_ia32_sqrtps ((__v4sf)__A);
208
}
209
210
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
211
_mm_rcp_ps (__m128 __A)
212
{
213
  return (__m128) __builtin_ia32_rcpps ((__v4sf)__A);
214
}
215
216
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
217
_mm_rsqrt_ps (__m128 __A)
218
{
219
  return (__m128) __builtin_ia32_rsqrtps ((__v4sf)__A);
220
}
221
222
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
223
_mm_min_ps (__m128 __A, __m128 __B)
224
{
225
  return (__m128) __builtin_ia32_minps ((__v4sf)__A, (__v4sf)__B);
226
}
227
228
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
229
_mm_max_ps (__m128 __A, __m128 __B)
230
{
231
  return (__m128) __builtin_ia32_maxps ((__v4sf)__A, (__v4sf)__B);
232
}
233
234
/* Perform logical bit-wise operations on 128-bit values.  */
235
236
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
237
_mm_and_ps (__m128 __A, __m128 __B)
238
{
239
  return __builtin_ia32_andps (__A, __B);
240
}
241
242
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
243
_mm_andnot_ps (__m128 __A, __m128 __B)
244
{
245
  return __builtin_ia32_andnps (__A, __B);
246
}
247
248
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
249
_mm_or_ps (__m128 __A, __m128 __B)
250
{
251
  return __builtin_ia32_orps (__A, __B);
252
}
253
254
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
255
_mm_xor_ps (__m128 __A, __m128 __B)
256
{
257
  return __builtin_ia32_xorps (__A, __B);
258
}
259
260
/* Perform a comparison on the lower SPFP values of A and B.  If the
261
   comparison is true, place a mask of all ones in the result, otherwise a
262
   mask of zeros.  The upper three SPFP values are passed through from A.  */
263
264
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
265
_mm_cmpeq_ss (__m128 __A, __m128 __B)
266
{
267
  return (__m128) __builtin_ia32_cmpeqss ((__v4sf)__A, (__v4sf)__B);
268
}
269
270
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
271
_mm_cmplt_ss (__m128 __A, __m128 __B)
272
{
273
  return (__m128) __builtin_ia32_cmpltss ((__v4sf)__A, (__v4sf)__B);
274
}
275
276
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
277
_mm_cmple_ss (__m128 __A, __m128 __B)
278
{
279
  return (__m128) __builtin_ia32_cmpless ((__v4sf)__A, (__v4sf)__B);
280
}
281
282
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
283
_mm_cmpgt_ss (__m128 __A, __m128 __B)
284
{
285
  return (__m128) __builtin_ia32_movss ((__v4sf) __A,
286
					(__v4sf)
287
					__builtin_ia32_cmpltss ((__v4sf) __B,
288
								(__v4sf)
289
								__A));
290
}
291
292
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
293
_mm_cmpge_ss (__m128 __A, __m128 __B)
294
{
295
  return (__m128) __builtin_ia32_movss ((__v4sf) __A,
296
					(__v4sf)
297
					__builtin_ia32_cmpless ((__v4sf) __B,
298
								(__v4sf)
299
								__A));
300
}
301
302
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
303
_mm_cmpneq_ss (__m128 __A, __m128 __B)
304
{
305
  return (__m128) __builtin_ia32_cmpneqss ((__v4sf)__A, (__v4sf)__B);
306
}
307
308
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
309
_mm_cmpnlt_ss (__m128 __A, __m128 __B)
310
{
311
  return (__m128) __builtin_ia32_cmpnltss ((__v4sf)__A, (__v4sf)__B);
312
}
313
314
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
315
_mm_cmpnle_ss (__m128 __A, __m128 __B)
316
{
317
  return (__m128) __builtin_ia32_cmpnless ((__v4sf)__A, (__v4sf)__B);
318
}
319
320
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
321
_mm_cmpngt_ss (__m128 __A, __m128 __B)
322
{
323
  return (__m128) __builtin_ia32_movss ((__v4sf) __A,
324
					(__v4sf)
325
					__builtin_ia32_cmpnltss ((__v4sf) __B,
326
								 (__v4sf)
327
								 __A));
328
}
329
330
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
331
_mm_cmpnge_ss (__m128 __A, __m128 __B)
332
{
333
  return (__m128) __builtin_ia32_movss ((__v4sf) __A,
334
					(__v4sf)
335
					__builtin_ia32_cmpnless ((__v4sf) __B,
336
								 (__v4sf)
337
								 __A));
338
}
339
340
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
341
_mm_cmpord_ss (__m128 __A, __m128 __B)
342
{
343
  return (__m128) __builtin_ia32_cmpordss ((__v4sf)__A, (__v4sf)__B);
344
}
345
346
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
347
_mm_cmpunord_ss (__m128 __A, __m128 __B)
348
{
349
  return (__m128) __builtin_ia32_cmpunordss ((__v4sf)__A, (__v4sf)__B);
350
}
351
352
/* Perform a comparison on the four SPFP values of A and B.  For each
353
   element, if the comparison is true, place a mask of all ones in the
354
   result, otherwise a mask of zeros.  */
355
356
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
357
_mm_cmpeq_ps (__m128 __A, __m128 __B)
358
{
359
  return (__m128) __builtin_ia32_cmpeqps ((__v4sf)__A, (__v4sf)__B);
360
}
361
362
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
363
_mm_cmplt_ps (__m128 __A, __m128 __B)
364
{
365
  return (__m128) __builtin_ia32_cmpltps ((__v4sf)__A, (__v4sf)__B);
366
}
367
368
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
369
_mm_cmple_ps (__m128 __A, __m128 __B)
370
{
371
  return (__m128) __builtin_ia32_cmpleps ((__v4sf)__A, (__v4sf)__B);
372
}
373
374
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
375
_mm_cmpgt_ps (__m128 __A, __m128 __B)
376
{
377
  return (__m128) __builtin_ia32_cmpgtps ((__v4sf)__A, (__v4sf)__B);
378
}
379
380
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
381
_mm_cmpge_ps (__m128 __A, __m128 __B)
382
{
383
  return (__m128) __builtin_ia32_cmpgeps ((__v4sf)__A, (__v4sf)__B);
384
}
385
386
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
387
_mm_cmpneq_ps (__m128 __A, __m128 __B)
388
{
389
  return (__m128) __builtin_ia32_cmpneqps ((__v4sf)__A, (__v4sf)__B);
390
}
391
392
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
393
_mm_cmpnlt_ps (__m128 __A, __m128 __B)
394
{
395
  return (__m128) __builtin_ia32_cmpnltps ((__v4sf)__A, (__v4sf)__B);
396
}
397
398
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
399
_mm_cmpnle_ps (__m128 __A, __m128 __B)
400
{
401
  return (__m128) __builtin_ia32_cmpnleps ((__v4sf)__A, (__v4sf)__B);
402
}
403
404
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
405
_mm_cmpngt_ps (__m128 __A, __m128 __B)
406
{
407
  return (__m128) __builtin_ia32_cmpngtps ((__v4sf)__A, (__v4sf)__B);
408
}
409
410
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
411
_mm_cmpnge_ps (__m128 __A, __m128 __B)
412
{
413
  return (__m128) __builtin_ia32_cmpngeps ((__v4sf)__A, (__v4sf)__B);
414
}
415
416
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
417
_mm_cmpord_ps (__m128 __A, __m128 __B)
418
{
419
  return (__m128) __builtin_ia32_cmpordps ((__v4sf)__A, (__v4sf)__B);
420
}
421
422
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
423
_mm_cmpunord_ps (__m128 __A, __m128 __B)
424
{
425
  return (__m128) __builtin_ia32_cmpunordps ((__v4sf)__A, (__v4sf)__B);
426
}
427
428
/* Compare the lower SPFP values of A and B and return 1 if true
429
   and 0 if false.  */
430
431
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
432
_mm_comieq_ss (__m128 __A, __m128 __B)
433
{
434
  return __builtin_ia32_comieq ((__v4sf)__A, (__v4sf)__B);
435
}
436
437
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
438
_mm_comilt_ss (__m128 __A, __m128 __B)
439
{
440
  return __builtin_ia32_comilt ((__v4sf)__A, (__v4sf)__B);
441
}
442
443
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
444
_mm_comile_ss (__m128 __A, __m128 __B)
445
{
446
  return __builtin_ia32_comile ((__v4sf)__A, (__v4sf)__B);
447
}
448
449
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
450
_mm_comigt_ss (__m128 __A, __m128 __B)
451
{
452
  return __builtin_ia32_comigt ((__v4sf)__A, (__v4sf)__B);
453
}
454
455
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
456
_mm_comige_ss (__m128 __A, __m128 __B)
457
{
458
  return __builtin_ia32_comige ((__v4sf)__A, (__v4sf)__B);
459
}
460
461
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
462
_mm_comineq_ss (__m128 __A, __m128 __B)
463
{
464
  return __builtin_ia32_comineq ((__v4sf)__A, (__v4sf)__B);
465
}
466
467
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
468
_mm_ucomieq_ss (__m128 __A, __m128 __B)
469
{
470
  return __builtin_ia32_ucomieq ((__v4sf)__A, (__v4sf)__B);
471
}
472
473
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
474
_mm_ucomilt_ss (__m128 __A, __m128 __B)
475
{
476
  return __builtin_ia32_ucomilt ((__v4sf)__A, (__v4sf)__B);
477
}
478
479
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
480
_mm_ucomile_ss (__m128 __A, __m128 __B)
481
{
482
  return __builtin_ia32_ucomile ((__v4sf)__A, (__v4sf)__B);
483
}
484
485
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
486
_mm_ucomigt_ss (__m128 __A, __m128 __B)
487
{
488
  return __builtin_ia32_ucomigt ((__v4sf)__A, (__v4sf)__B);
489
}
490
491
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
492
_mm_ucomige_ss (__m128 __A, __m128 __B)
493
{
494
  return __builtin_ia32_ucomige ((__v4sf)__A, (__v4sf)__B);
495
}
496
497
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
498
_mm_ucomineq_ss (__m128 __A, __m128 __B)
499
{
500
  return __builtin_ia32_ucomineq ((__v4sf)__A, (__v4sf)__B);
501
}
502
503
/* Convert the lower SPFP value to a 32-bit integer according to the current
504
   rounding mode.  */
505
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
506
_mm_cvtss_si32 (__m128 __A)
507
{
508
  return __builtin_ia32_cvtss2si ((__v4sf) __A);
509
}
510
511
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
512
_mm_cvt_ss2si (__m128 __A)
513
{
514
  return _mm_cvtss_si32 (__A);
515
}
516
517
#ifdef __x86_64__
518
/* Convert the lower SPFP value to a 32-bit integer according to the
519
   current rounding mode.  */
520
521
/* Intel intrinsic.  */
522
extern __inline long long __attribute__((__gnu_inline__, __always_inline__, __artificial__))
523
_mm_cvtss_si64 (__m128 __A)
524
{
525
  return __builtin_ia32_cvtss2si64 ((__v4sf) __A);
526
}
527
528
/* Microsoft intrinsic.  */
529
extern __inline long long __attribute__((__gnu_inline__, __always_inline__, __artificial__))
530
_mm_cvtss_si64x (__m128 __A)
531
{
532
  return __builtin_ia32_cvtss2si64 ((__v4sf) __A);
533
}
534
#endif
535
536
/* Convert the two lower SPFP values to 32-bit integers according to the
537
   current rounding mode.  Return the integers in packed form.  */
538
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
539
_mm_cvtps_pi32 (__m128 __A)
540
{
541
  return (__m64) __builtin_ia32_cvtps2pi ((__v4sf) __A);
542
}
543
544
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
545
_mm_cvt_ps2pi (__m128 __A)
546
{
547
  return _mm_cvtps_pi32 (__A);
548
}
549
550
/* Truncate the lower SPFP value to a 32-bit integer.  */
551
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
552
_mm_cvttss_si32 (__m128 __A)
553
{
554
  return __builtin_ia32_cvttss2si ((__v4sf) __A);
555
}
556
557
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
558
_mm_cvtt_ss2si (__m128 __A)
559
{
560
  return _mm_cvttss_si32 (__A);
561
}
562
563
#ifdef __x86_64__
564
/* Truncate the lower SPFP value to a 32-bit integer.  */
565
566
/* Intel intrinsic.  */
567
extern __inline long long __attribute__((__gnu_inline__, __always_inline__, __artificial__))
568
_mm_cvttss_si64 (__m128 __A)
569
{
570
  return __builtin_ia32_cvttss2si64 ((__v4sf) __A);
571
}
572
573
/* Microsoft intrinsic.  */
574
extern __inline long long __attribute__((__gnu_inline__, __always_inline__, __artificial__))
575
_mm_cvttss_si64x (__m128 __A)
576
{
577
  return __builtin_ia32_cvttss2si64 ((__v4sf) __A);
578
}
579
#endif
580
581
/* Truncate the two lower SPFP values to 32-bit integers.  Return the
582
   integers in packed form.  */
583
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
584
_mm_cvttps_pi32 (__m128 __A)
585
{
586
  return (__m64) __builtin_ia32_cvttps2pi ((__v4sf) __A);
587
}
588
589
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
590
_mm_cvtt_ps2pi (__m128 __A)
591
{
592
  return _mm_cvttps_pi32 (__A);
593
}
594
595
/* Convert B to a SPFP value and insert it as element zero in A.  */
596
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
597
_mm_cvtsi32_ss (__m128 __A, int __B)
598
{
599
  return (__m128) __builtin_ia32_cvtsi2ss ((__v4sf) __A, __B);
600
}
601
602
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
603
_mm_cvt_si2ss (__m128 __A, int __B)
604
{
605
  return _mm_cvtsi32_ss (__A, __B);
606
}
607
608
#ifdef __x86_64__
609
/* Convert B to a SPFP value and insert it as element zero in A.  */
610
611
/* Intel intrinsic.  */
612
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
613
_mm_cvtsi64_ss (__m128 __A, long long __B)
614
{
615
  return (__m128) __builtin_ia32_cvtsi642ss ((__v4sf) __A, __B);
616
}
617
618
/* Microsoft intrinsic.  */
619
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
620
_mm_cvtsi64x_ss (__m128 __A, long long __B)
621
{
622
  return (__m128) __builtin_ia32_cvtsi642ss ((__v4sf) __A, __B);
623
}
624
#endif
625
626
/* Convert the two 32-bit values in B to SPFP form and insert them
627
   as the two lower elements in A.  */
628
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
629
_mm_cvtpi32_ps (__m128 __A, __m64 __B)
630
{
631
  return (__m128) __builtin_ia32_cvtpi2ps ((__v4sf) __A, (__v2si)__B);
632
}
633
634
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
635
_mm_cvt_pi2ps (__m128 __A, __m64 __B)
636
{
637
  return _mm_cvtpi32_ps (__A, __B);
638
}
639
640
/* Convert the four signed 16-bit values in A to SPFP form.  */
641
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
642
_mm_cvtpi16_ps (__m64 __A)
643
{
644
  __v4hi __sign;
645
  __v2si __hisi, __losi;
646
  __v4sf __zero, __ra, __rb;
647
648
  /* This comparison against zero gives us a mask that can be used to
649
     fill in the missing sign bits in the unpack operations below, so
650
     that we get signed values after unpacking.  */
651
  __sign = __builtin_ia32_pcmpgtw ((__v4hi)0LL, (__v4hi)__A);
652
653
  /* Convert the four words to doublewords.  */
654
  __losi = (__v2si) __builtin_ia32_punpcklwd ((__v4hi)__A, __sign);
655
  __hisi = (__v2si) __builtin_ia32_punpckhwd ((__v4hi)__A, __sign);
656
657
  /* Convert the doublewords to floating point two at a time.  */
658
  __zero = (__v4sf) _mm_setzero_ps ();
659
  __ra = __builtin_ia32_cvtpi2ps (__zero, __losi);
660
  __rb = __builtin_ia32_cvtpi2ps (__ra, __hisi);
661
662
  return (__m128) __builtin_ia32_movlhps (__ra, __rb);
663
}
664
665
/* Convert the four unsigned 16-bit values in A to SPFP form.  */
666
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
667
_mm_cvtpu16_ps (__m64 __A)
668
{
669
  __v2si __hisi, __losi;
670
  __v4sf __zero, __ra, __rb;
671
672
  /* Convert the four words to doublewords.  */
673
  __losi = (__v2si) __builtin_ia32_punpcklwd ((__v4hi)__A, (__v4hi)0LL);
674
  __hisi = (__v2si) __builtin_ia32_punpckhwd ((__v4hi)__A, (__v4hi)0LL);
675
676
  /* Convert the doublewords to floating point two at a time.  */
677
  __zero = (__v4sf) _mm_setzero_ps ();
678
  __ra = __builtin_ia32_cvtpi2ps (__zero, __losi);
679
  __rb = __builtin_ia32_cvtpi2ps (__ra, __hisi);
680
681
  return (__m128) __builtin_ia32_movlhps (__ra, __rb);
682
}
683
684
/* Convert the low four signed 8-bit values in A to SPFP form.  */
685
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
686
_mm_cvtpi8_ps (__m64 __A)
687
{
688
  __v8qi __sign;
689
690
  /* This comparison against zero gives us a mask that can be used to
691
     fill in the missing sign bits in the unpack operations below, so
692
     that we get signed values after unpacking.  */
693
  __sign = __builtin_ia32_pcmpgtb ((__v8qi)0LL, (__v8qi)__A);
694
695
  /* Convert the four low bytes to words.  */
696
  __A = (__m64) __builtin_ia32_punpcklbw ((__v8qi)__A, __sign);
697
698
  return _mm_cvtpi16_ps(__A);
699
}
700
701
/* Convert the low four unsigned 8-bit values in A to SPFP form.  */
702
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
703
_mm_cvtpu8_ps(__m64 __A)
704
{
705
  __A = (__m64) __builtin_ia32_punpcklbw ((__v8qi)__A, (__v8qi)0LL);
706
  return _mm_cvtpu16_ps(__A);
707
}
708
709
/* Convert the four signed 32-bit values in A and B to SPFP form.  */
710
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
711
_mm_cvtpi32x2_ps(__m64 __A, __m64 __B)
712
{
713
  __v4sf __zero = (__v4sf) _mm_setzero_ps ();
714
  __v4sf __sfa = __builtin_ia32_cvtpi2ps (__zero, (__v2si)__A);
715
  __v4sf __sfb = __builtin_ia32_cvtpi2ps (__sfa, (__v2si)__B);
716
  return (__m128) __builtin_ia32_movlhps (__sfa, __sfb);
717
}
718
719
/* Convert the four SPFP values in A to four signed 16-bit integers.  */
720
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
721
_mm_cvtps_pi16(__m128 __A)
722
{
723
  __v4sf __hisf = (__v4sf)__A;
724
  __v4sf __losf = __builtin_ia32_movhlps (__hisf, __hisf);
725
  __v2si __hisi = __builtin_ia32_cvtps2pi (__hisf);
726
  __v2si __losi = __builtin_ia32_cvtps2pi (__losf);
727
  return (__m64) __builtin_ia32_packssdw (__hisi, __losi);
728
}
729
730
/* Convert the four SPFP values in A to four signed 8-bit integers.  */
731
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
732
_mm_cvtps_pi8(__m128 __A)
733
{
734
  __v4hi __tmp = (__v4hi) _mm_cvtps_pi16 (__A);
735
  return (__m64) __builtin_ia32_packsswb (__tmp, (__v4hi)0LL);
736
}
737
738
/* Selects four specific SPFP values from A and B based on MASK.  */
739
#ifdef __OPTIMIZE__
740
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
741
_mm_shuffle_ps (__m128 __A, __m128 __B, int const __mask)
742
{
743
  return (__m128) __builtin_ia32_shufps ((__v4sf)__A, (__v4sf)__B, __mask);
744
}
745
#else
746
#define _mm_shuffle_ps(A, B, MASK)					\
747
  ((__m128) __builtin_ia32_shufps ((__v4sf)(__m128)(A),			\
748
				   (__v4sf)(__m128)(B), (int)(MASK)))
749
#endif
750
751
/* Selects and interleaves the upper two SPFP values from A and B.  */
752
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
753
_mm_unpackhi_ps (__m128 __A, __m128 __B)
754
{
755
  return (__m128) __builtin_ia32_unpckhps ((__v4sf)__A, (__v4sf)__B);
756
}
757
758
/* Selects and interleaves the lower two SPFP values from A and B.  */
759
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
760
_mm_unpacklo_ps (__m128 __A, __m128 __B)
761
{
762
  return (__m128) __builtin_ia32_unpcklps ((__v4sf)__A, (__v4sf)__B);
763
}
764
765
/* Sets the upper two SPFP values with 64-bits of data loaded from P;
766
   the lower two values are passed through from A.  */
767
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
768
_mm_loadh_pi (__m128 __A, __m64 const *__P);
769
770
/* Stores the upper two SPFP values of A into P.  */
771
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
772
_mm_storeh_pi (__m64 *__P, __m128 __A);
773
774
/* Moves the upper two values of B into the lower two values of A.  */
775
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
776
_mm_movehl_ps (__m128 __A, __m128 __B)
777
{
778
  return (__m128) __builtin_ia32_movhlps ((__v4sf)__A, (__v4sf)__B);
779
}
780
781
/* Moves the lower two values of B into the upper two values of A.  */
782
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
783
_mm_movelh_ps (__m128 __A, __m128 __B)
784
{
785
  return (__m128) __builtin_ia32_movlhps ((__v4sf)__A, (__v4sf)__B);
786
}
787
788
/* Sets the lower two SPFP values with 64-bits of data loaded from P;
789
   the upper two values are passed through from A.  */
790
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
791
_mm_loadl_pi (__m128 __A, __m64 const *__P);
792
793
/* Stores the lower two SPFP values of A into P.  */
794
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
795
_mm_storel_pi (__m64 *__P, __m128 __A);
796
797
/* Creates a 4-bit mask from the most significant bits of the SPFP values.  */
798
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
799
_mm_movemask_ps (__m128 __A)
800
{
801
  return __builtin_ia32_movmskps ((__v4sf)__A);
802
}
803
804
/* Return the contents of the control register.  */
805
extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
806
_mm_getcsr (void)
807
{
808
  return __builtin_ia32_stmxcsr ();
809
}
810
811
/* Read exception bits from the control register.  */
812
extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
813
_MM_GET_EXCEPTION_STATE (void)
814
{
815
  return _mm_getcsr() & _MM_EXCEPT_MASK;
816
}
817
818
extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
819
_MM_GET_EXCEPTION_MASK (void)
820
{
821
  return _mm_getcsr() & _MM_MASK_MASK;
822
}
823
824
extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
825
_MM_GET_ROUNDING_MODE (void)
826
{
827
  return _mm_getcsr() & _MM_ROUND_MASK;
828
}
829
830
extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
831
_MM_GET_FLUSH_ZERO_MODE (void)
832
{
833
  return _mm_getcsr() & _MM_FLUSH_ZERO_MASK;
834
}
835
836
/* Set the control register to I.  */
837
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
838
_mm_setcsr (unsigned int __I)
839
{
840
  __builtin_ia32_ldmxcsr (__I);
841
}
842
843
/* Set exception bits in the control register.  */
844
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
845
_MM_SET_EXCEPTION_STATE(unsigned int __mask)
846
{
847
  _mm_setcsr((_mm_getcsr() & ~_MM_EXCEPT_MASK) | __mask);
848
}
849
850
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
851
_MM_SET_EXCEPTION_MASK (unsigned int __mask)
852
{
853
  _mm_setcsr((_mm_getcsr() & ~_MM_MASK_MASK) | __mask);
854
}
855
856
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
857
_MM_SET_ROUNDING_MODE (unsigned int __mode)
858
{
859
  _mm_setcsr((_mm_getcsr() & ~_MM_ROUND_MASK) | __mode);
860
}
861
862
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
863
_MM_SET_FLUSH_ZERO_MODE (unsigned int __mode)
864
{
865
  _mm_setcsr((_mm_getcsr() & ~_MM_FLUSH_ZERO_MASK) | __mode);
866
}
867
868
/* Create a vector with element 0 as F and the rest zero.  */
869
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
870
_mm_set_ss (float __F)
871
{
872
  return __extension__ (__m128)(__v4sf){ __F, 0.0f, 0.0f, 0.0f };
873
}
874
875
/* Create a vector with all four elements equal to F.  */
876
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
877
_mm_set1_ps (float __F)
878
{
879
  return __extension__ (__m128)(__v4sf){ __F, __F, __F, __F };
880
}
881
882
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
883
_mm_set_ps1 (float __F)
884
{
885
  return _mm_set1_ps (__F);
886
}
887
888
/* Create a vector with element 0 as *P and the rest zero.  */
889
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
890
_mm_load_ss (float const *__P)
891
{
892
  return _mm_set_ss (*__P);
893
}
894
895
/* Create a vector with all four elements equal to *P.  */
896
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
897
_mm_load1_ps (float const *__P)
898
{
899
  return _mm_set1_ps (*__P);
900
}
901
902
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
903
_mm_load_ps1 (float const *__P)
904
{
905
  return _mm_load1_ps (__P);
906
}
907
908
/* Load four SPFP values from P.  The address must be 16-byte aligned.  */
909
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
910
_mm_load_ps (float const *__P)
911
{
912
  return (__m128) *(__v4sf *)__P;
913
}
914
915
/* Load four SPFP values from P.  The address need not be 16-byte aligned.  */
916
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
917
_mm_loadu_ps (float const *__P)
918
{
919
  return (__m128) __builtin_ia32_loadups (__P);
920
}
921
922
/* Load four SPFP values in reverse order.  The address must be aligned.  */
923
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
924
_mm_loadr_ps (float const *__P)
925
{
926
  __v4sf __tmp = *(__v4sf *)__P;
927
  return (__m128) __builtin_ia32_shufps (__tmp, __tmp, _MM_SHUFFLE (0,1,2,3));
928
}
929
930
/* Create the vector [Z Y X W].  */
931
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
932
_mm_set_ps (const float __Z, const float __Y, const float __X, const float __W)
933
{
934
  return __extension__ (__m128)(__v4sf){ __W, __X, __Y, __Z };
935
}
936
937
/* Create the vector [W X Y Z].  */
938
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
939
_mm_setr_ps (float __Z, float __Y, float __X, float __W)
940
{
941
  return __extension__ (__m128)(__v4sf){ __Z, __Y, __X, __W };
942
}
943
944
/* Stores the lower SPFP value.  */
945
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
946
_mm_store_ss (float *__P, __m128 __A)
947
{
948
  *__P = __builtin_ia32_vec_ext_v4sf ((__v4sf)__A, 0);
949
}
950
951
extern __inline float __attribute__((__gnu_inline__, __always_inline__, __artificial__))
952
_mm_cvtss_f32 (__m128 __A)
953
{
954
  return __builtin_ia32_vec_ext_v4sf ((__v4sf)__A, 0);
955
}
956
957
/* Store four SPFP values.  The address must be 16-byte aligned.  */
958
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
959
_mm_store_ps (float *__P, __m128 __A)
960
{
961
  *(__v4sf *)__P = (__v4sf)__A;
962
}
963
964
/* Store four SPFP values.  The address need not be 16-byte aligned.  */
965
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
966
_mm_storeu_ps (float *__P, __m128 __A)
967
{
968
  __builtin_ia32_storeups (__P, (__v4sf)__A);
969
}
970
971
/* Store the lower SPFP value across four words.  */
972
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
973
_mm_store1_ps (float *__P, __m128 __A)
974
{
975
  __v4sf __va = (__v4sf)__A;
976
  __v4sf __tmp = __builtin_ia32_shufps (__va, __va, _MM_SHUFFLE (0,0,0,0));
977
  _mm_storeu_ps (__P, __tmp);
978
}
979
980
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
981
_mm_store_ps1 (float *__P, __m128 __A)
982
{
983
  _mm_store1_ps (__P, __A);
984
}
985
986
/* Store four SPFP values in reverse order.  The address must be aligned.  */
987
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
988
_mm_storer_ps (float *__P, __m128 __A)
989
{
990
  __v4sf __va = (__v4sf)__A;
991
  __v4sf __tmp = __builtin_ia32_shufps (__va, __va, _MM_SHUFFLE (0,1,2,3));
992
  _mm_store_ps (__P, __tmp);
993
}
994
995
/* Sets the low SPFP value of A from the low value of B.  */
996
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
997
_mm_move_ss (__m128 __A, __m128 __B)
998
{
999
  return (__m128) __builtin_ia32_movss ((__v4sf)__A, (__v4sf)__B);
1000
}
1001
1002
/* Extracts one of the four words of A.  The selector N must be immediate.  */
1003
#ifdef __OPTIMIZE__
1004
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1005
_mm_extract_pi16 (__m64 const __A, int const __N)
1006
{
1007
  return __builtin_ia32_vec_ext_v4hi ((__v4hi)__A, __N);
1008
}
1009
1010
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1011
_m_pextrw (__m64 const __A, int const __N)
1012
{
1013
  return _mm_extract_pi16 (__A, __N);
1014
}
1015
#else
1016
#define _mm_extract_pi16(A, N)	\
1017
  ((int) __builtin_ia32_vec_ext_v4hi ((__v4hi)(__m64)(A), (int)(N)))
1018
1019
#define _m_pextrw(A, N) _mm_extract_pi16(A, N)
1020
#endif
1021
1022
/* Inserts word D into one of four words of A.  The selector N must be
1023
   immediate.  */
1024
#ifdef __OPTIMIZE__
1025
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1026
_mm_insert_pi16 (__m64 const __A, int const __D, int const __N)
1027
{
1028
  return (__m64) __builtin_ia32_vec_set_v4hi ((__v4hi)__A, __D, __N);
1029
}
1030
1031
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1032
_m_pinsrw (__m64 const __A, int const __D, int const __N)
1033
{
1034
  return _mm_insert_pi16 (__A, __D, __N);
1035
}
1036
#else
1037
#define _mm_insert_pi16(A, D, N)				\
1038
  ((__m64) __builtin_ia32_vec_set_v4hi ((__v4hi)(__m64)(A),	\
1039
					(int)(D), (int)(N)))
1040
1041
#define _m_pinsrw(A, D, N) _mm_insert_pi16(A, D, N)
1042
#endif
1043
1044
/* Compute the element-wise maximum of signed 16-bit values.  */
1045
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1046
_mm_max_pi16 (__m64 __A, __m64 __B)
1047
{
1048
  return (__m64) __builtin_ia32_pmaxsw ((__v4hi)__A, (__v4hi)__B);
1049
}
1050
1051
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1052
_m_pmaxsw (__m64 __A, __m64 __B)
1053
{
1054
  return _mm_max_pi16 (__A, __B);
1055
}
1056
1057
/* Compute the element-wise maximum of unsigned 8-bit values.  */
1058
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1059
_mm_max_pu8 (__m64 __A, __m64 __B)
1060
{
1061
  return (__m64) __builtin_ia32_pmaxub ((__v8qi)__A, (__v8qi)__B);
1062
}
1063
1064
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1065
_m_pmaxub (__m64 __A, __m64 __B)
1066
{
1067
  return _mm_max_pu8 (__A, __B);
1068
}
1069
1070
/* Compute the element-wise minimum of signed 16-bit values.  */
1071
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1072
_mm_min_pi16 (__m64 __A, __m64 __B)
1073
{
1074
  return (__m64) __builtin_ia32_pminsw ((__v4hi)__A, (__v4hi)__B);
1075
}
1076
1077
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1078
_m_pminsw (__m64 __A, __m64 __B)
1079
{
1080
  return _mm_min_pi16 (__A, __B);
1081
}
1082
1083
/* Compute the element-wise minimum of unsigned 8-bit values.  */
1084
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1085
_mm_min_pu8 (__m64 __A, __m64 __B)
1086
{
1087
  return (__m64) __builtin_ia32_pminub ((__v8qi)__A, (__v8qi)__B);
1088
}
1089
1090
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1091
_m_pminub (__m64 __A, __m64 __B)
1092
{
1093
  return _mm_min_pu8 (__A, __B);
1094
}
1095
1096
/* Create an 8-bit mask of the signs of 8-bit values.  */
1097
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1098
_mm_movemask_pi8 (__m64 __A)
1099
{
1100
  return __builtin_ia32_pmovmskb ((__v8qi)__A);
1101
}
1102
1103
extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1104
_m_pmovmskb (__m64 __A)
1105
{
1106
  return _mm_movemask_pi8 (__A);
1107
}
1108
1109
/* Multiply four unsigned 16-bit values in A by four unsigned 16-bit values
1110
   in B and produce the high 16 bits of the 32-bit results.  */
1111
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1112
_mm_mulhi_pu16 (__m64 __A, __m64 __B)
1113
{
1114
  return (__m64) __builtin_ia32_pmulhuw ((__v4hi)__A, (__v4hi)__B);
1115
}
1116
1117
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1118
_m_pmulhuw (__m64 __A, __m64 __B)
1119
{
1120
  return _mm_mulhi_pu16 (__A, __B);
1121
}
1122
1123
/* Return a combination of the four 16-bit values in A.  The selector
1124
   must be an immediate.  */
1125
#ifdef __OPTIMIZE__
1126
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1127
_mm_shuffle_pi16 (__m64 __A, int const __N)
1128
{
1129
  return (__m64) __builtin_ia32_pshufw ((__v4hi)__A, __N);
1130
}
1131
1132
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1133
_m_pshufw (__m64 __A, int const __N)
1134
{
1135
  return _mm_shuffle_pi16 (__A, __N);
1136
}
1137
#else
1138
#define _mm_shuffle_pi16(A, N) \
1139
  ((__m64) __builtin_ia32_pshufw ((__v4hi)(__m64)(A), (int)(N)))
1140
1141
#define _m_pshufw(A, N) _mm_shuffle_pi16 (A, N)
1142
#endif
1143
1144
/* Conditionally store byte elements of A into P.  The high bit of each
1145
   byte in the selector N determines whether the corresponding byte from
1146
   A is stored.  */
1147
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1148
_mm_maskmove_si64 (__m64 __A, __m64 __N, char *__P)
1149
{
1150
  __builtin_ia32_maskmovq ((__v8qi)__A, (__v8qi)__N, __P);
1151
}
1152
1153
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1154
_m_maskmovq (__m64 __A, __m64 __N, char *__P)
1155
{
1156
  _mm_maskmove_si64 (__A, __N, __P);
1157
}
1158
1159
/* Compute the rounded averages of the unsigned 8-bit values in A and B.  */
1160
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1161
_mm_avg_pu8 (__m64 __A, __m64 __B)
1162
{
1163
  return (__m64) __builtin_ia32_pavgb ((__v8qi)__A, (__v8qi)__B);
1164
}
1165
1166
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1167
_m_pavgb (__m64 __A, __m64 __B)
1168
{
1169
  return _mm_avg_pu8 (__A, __B);
1170
}
1171
1172
/* Compute the rounded averages of the unsigned 16-bit values in A and B.  */
1173
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1174
_mm_avg_pu16 (__m64 __A, __m64 __B)
1175
{
1176
  return (__m64) __builtin_ia32_pavgw ((__v4hi)__A, (__v4hi)__B);
1177
}
1178
1179
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1180
_m_pavgw (__m64 __A, __m64 __B)
1181
{
1182
  return _mm_avg_pu16 (__A, __B);
1183
}
1184
1185
/* Compute the sum of the absolute differences of the unsigned 8-bit
1186
   values in A and B.  Return the value in the lower 16-bit word; the
1187
   upper words are cleared.  */
1188
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1189
_mm_sad_pu8 (__m64 __A, __m64 __B)
1190
{
1191
  return (__m64) __builtin_ia32_psadbw ((__v8qi)__A, (__v8qi)__B);
1192
}
1193
1194
extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1195
_m_psadbw (__m64 __A, __m64 __B)
1196
{
1197
  return _mm_sad_pu8 (__A, __B);
1198
}
1199
1200
/* Stores the data in A to the address P without polluting the caches.  */
1201
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1202
_mm_stream_pi (__m64 *__P, __m64 __A)
1203
{
1204
  __builtin_ia32_movntq ((unsigned long long *)__P, (unsigned long long)__A);
1205
}
1206
1207
/* Likewise.  The address must be 16-byte aligned.  */
1208
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1209
_mm_stream_ps (float *__P, __m128 __A)
1210
{
1211
  __builtin_ia32_movntps (__P, (__v4sf)__A);
1212
}
1213
1214
/* Guarantees that every preceding store is globally visible before
1215
   any subsequent store.  */
1216
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1217
_mm_sfence (void)
1218
{
1219
  __builtin_ia32_sfence ();
1220
}
1221
1222
/* The execution of the next instruction is delayed by an implementation
1223
   specific amount of time.  The instruction does not modify the
1224
   architectural state.  */
1225
extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
1226
_mm_pause (void)
1227
{
1228
    __asm__ __volatile__ ("rep; nop" : : );
1229
}
1230
1231
/* Transpose the 4x4 matrix composed of row[0-3].  */
1232
#define _MM_TRANSPOSE4_PS(row0, row1, row2, row3)			\
1233
do {									\
1234
  __v4sf __r0 = (row0), __r1 = (row1), __r2 = (row2), __r3 = (row3);	\
1235
  __v4sf __t0 = __builtin_ia32_unpcklps (__r0, __r1);			\
1236
  __v4sf __t1 = __builtin_ia32_unpcklps (__r2, __r3);			\
1237
  __v4sf __t2 = __builtin_ia32_unpckhps (__r0, __r1);			\
1238
  __v4sf __t3 = __builtin_ia32_unpckhps (__r2, __r3);			\
1239
  (row0) = __builtin_ia32_movlhps (__t0, __t1);				\
1240
  (row1) = __builtin_ia32_movhlps (__t1, __t0);				\
1241
  (row2) = __builtin_ia32_movlhps (__t2, __t3);				\
1242
  (row3) = __builtin_ia32_movhlps (__t3, __t2);				\
1243
} while (0)
1244
1245
/* For backward source compatibility.  */
1246
# include <emmintrin.h>
1247
1248
#ifdef __DISABLE_SSE__
1249
#undef __DISABLE_SSE__
1250
#pragma GCC pop_options
1251
#endif /* __DISABLE_SSE__ */
1252
1253
#endif /* _XMMINTRIN_H_INCLUDED */
(-)GCC_XML/VcInstall/CMakeLists.txt (-2 / +1 lines)
Lines 15-25 Link Here
15
# Create the MSVC support directories.
15
# Create the MSVC support directories.
16
# This will just execute on every build because we don't know
16
# This will just execute on every build because we don't know
17
# what files and directories it may create.
17
# what files and directories it may create.
18
GET_TARGET_PROPERTY(GCCXML_VCCONFIG_EXE ${VCCONFIG_TARGET} LOCATION)
19
ADD_CUSTOM_COMMAND(
18
ADD_CUSTOM_COMMAND(
20
  OUTPUT ${GCCXML_BINARY_DIR}/vcInstall_stamp.c
19
  OUTPUT ${GCCXML_BINARY_DIR}/vcInstall_stamp.c
21
20
22
  COMMAND ${GCCXML_VCCONFIG_EXE}
21
  COMMAND ${VCCONFIG_TARGET}
23
  ${GCCXML_SOURCE_DIR}/VcInstall ${GCCXML_BINARY_DIR}/Support
22
  ${GCCXML_SOURCE_DIR}/VcInstall ${GCCXML_BINARY_DIR}/Support
24
  ${GCCXML_BINARY_DIR}/vcInstall_stamp.c
23
  ${GCCXML_BINARY_DIR}/vcInstall_stamp.c
25
24
(-)README.rst (-1 / +8 lines)
Lines 4-9 Link Here
4
GCC-XML
4
GCC-XML
5
=======
5
=======
6
6
7
**Note:** GCC-XML has been succeeded by `CastXML`_.
8
9
.. _`CastXML`: https://github.com/CastXML/CastXML#readme
10
11
------------
12
Introduction
13
------------
14
7
This program dumps an XML description of C++ source code
15
This program dumps an XML description of C++ source code
8
using an extension of the GCC C++ compiler.
16
using an extension of the GCC C++ compiler.
9
17
Lines 72-77 Link Here
72
80
73
* GCC-XML homepage: http://www.gccxml.org
81
* GCC-XML homepage: http://www.gccxml.org
74
* CMake homepage: http://www.cmake.org
82
* CMake homepage: http://www.cmake.org
75
* GCC-XML mailing list: http://www.gccxml.org/mailman/listinfo/gccxml
76
83
77
.. _homepage: http://www.gccxml.org
84
.. _homepage: http://www.gccxml.org

Return to bug 443140