Skip to content

Commit 70e0fe5

Browse files
committed
edit pass
1 parent 27b7e12 commit 70e0fe5

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

docs/standard-library/vectorized-stl-algorithms.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,33 @@ helpviewer_keywords: ["_USE_STD_VECTOR_ALGORITHMS", "_USE_STD_VECTOR_FLOATING_AL
77
---
88
# Vectorized STL Algorithms
99

10-
Under specific conditions, algorithms in the C++ Standard Template Library (STL) can process multiple elements simultaneously on a single CPU core, rather than handling each element individually. This optimization uses single instruction, multiple data (SIMD) instructions provided by the CPU, a technique known as vectorization. When this optimization isn't applied, the implementation is referred to as scalar.
10+
Under specific conditions, algorithms in the C++ Standard Template Library (STL) can process multiple elements simultaneously on a single CPU core, rather than handling each element individually. This optimization uses single instruction, multiple data (SIMD) instructions provided by the CPU, a technique called vectorization. When this optimization isn't applied, the implementation is referred to as scalar.
1111

1212
The conditions required for vectorization are:
13-
- The container or range must be contiguous. Examples of contiguous containers include `array`, `vector`, and `basic_string`. Contiguous ranges are provided by types like `span` and `basic_string_view`. Built-in arrays also form contiguous ranges. In contrast, containers like `list` and `map` aren't contiguous.
13+
- The container or range must be contiguous. Examples include `array`, `vector`, and `basic_string`. Types like `span` and `basic_string_view` provide contiguous ranges. Built-in arrays also form contiguous ranges. Containers like `list` and `map` aren't contiguous.
1414
- The target platform must support the necessary SIMD instructions to implement the algorithm for the element types. This is typically true for arithmetic types and simple operations.
15-
- One of the following conditions must be met:
15+
- One of these conditions must be met:
1616
- The compiler can emit vectorized machine code for an implementation written as scalar code (auto-vectorization).
17-
- The algorithm's implementation is explicitly written to use vectorized code (manual vectorization).
17+
- The algorithm's implementation explicitly uses vectorized code (manual vectorization).
1818

1919
## Auto-vectorization in the STL
2020

21-
For more information about automatic vectorization, see [Auto-Vectorizer](../parallel/auto-parallelization-and-auto-vectorization.md#auto-vectorizer) and the discussion in that article about the [`/arch`](../build/reference/arch-minimum-cpu-architecture.md) switch. This applies to the STL implementation code the same way it does to user code.
21+
For more information about automatic vectorization, see [Auto-Vectorizer](../parallel/auto-parallelization-and-auto-vectorization.md#auto-vectorizer) and the discussion in that article about the [`/arch`](../build/reference/arch-minimum-cpu-architecture.md) switch. This applies to the STL implementation code the same way it applies to user code.
2222

23-
Algorithms like `transform`, `reduce`, `accumulate` heavily benefit from auto-vectorization.
23+
Algorithms like `transform`, `reduce`, and `accumulate` heavily benefit from auto-vectorization.
2424

2525
## Manual vectorization in the STL
2626

27-
For x64 and x86, certain algorithms include manual vectorization. This implementation is separately compiled and relies on runtime CPU dispatch, so it applies only to suitable CPUs.
27+
Certain algorithms for x64 and x86 include manual vectorization. This implementation is separately compiled and relies on runtime CPU dispatch, so it applies only to suitable CPUs.
2828

29-
Manually vectorized algorithms use template meta-programming to detect whether the element type is suitable for vectorization. As a result, they're only vectorized for simple types such as standard integer types.
29+
Manually vectorized algorithms use template metaprogramming to detect if the element type is suitable for vectorization. As a result, they're only vectorized for simple types such as standard integer types.
3030

31-
Generally, programs either benefit in performance from this manual vectorization or are unaffected by it. You can disable manual vectorization by defining `_USE_STD_VECTOR_ALGORITHMS=0` in your project. Manually vectorized algorithms are enabled by default on x64 and x86 because it defaults to 1 on those platforms.
31+
Programs generally either benefit in performance from manual vectorization or remain unaffected by it. Disable manual vectorization by defining `_USE_STD_VECTOR_ALGORITHMS=0` in your project. Manually vectorized algorithms are enabled by default on x64 and x86 because it defaults to 1 on those platforms.
3232

33-
Ensure that you assign the same value to `_USE_STD_VECTOR_ALGORITHMS` for all linked translation units that use algorithms. A reliable way to do this is by configuring it in the project properties instead of in the source code. For more information about how to configure it, see [/D (Preprocessor Definitions)](../build/reference/d-preprocessor-definitions.md).
33+
Assign the same value to `_USE_STD_VECTOR_ALGORITHMS` for all linked translation units that use algorithms. Configure it in the project properties instead of in the source code for consistency. For more information about how to configure it, see [/D (Preprocessor Definitions)](../build/reference/d-preprocessor-definitions.md).
3434

3535

36-
The `_USE_STD_VECTOR_ALGORITHMS` macro determines the behavior of the following manually vectorized algorithms:
36+
The `_USE_STD_VECTOR_ALGORITHMS` macro controls the behavior of these manually vectorized algorithms:
3737
- `contains`, `contains_subrange`
3838
- `find`, `find_last`, `find_end`, `find_first_of`, `adjacent_find`
3939
- `count`
@@ -50,7 +50,7 @@ The `_USE_STD_VECTOR_ALGORITHMS` macro determines the behavior of the following
5050
- `max`, `min`, `minmax`
5151
- `max_element`, `min_element`, `minmax_element`
5252

53-
In addition to algorithms, the `_USE_STD_VECTOR_ALGORITHMS` macro controls the manual vectorization of:
53+
The `_USE_STD_VECTOR_ALGORITHMS` macro also controls the manual vectorization of:
5454

5555
- `basic_string` and `basic_string_view` members:
5656
- `find`
@@ -62,19 +62,19 @@ In addition to algorithms, the `_USE_STD_VECTOR_ALGORITHMS` macro controls the m
6262
## Manually vectorized algorithms for floating point types
6363

6464
Vectorization of floating-point types involves specific considerations:
65-
- Vectorization may reorder operations, which can affect the precision of floating point results.
66-
- Floating point types may contain `NaN` values, which don't behave transitively on comparisons.
67-
- Floating point operations may raise exceptions.
65+
- Vectorization might reorder operations, which can affect the precision of floating-point results.
66+
- Floating-point types might contain `NaN` values, which don't behave transitively in comparisons.
67+
- Floating-point operations might raise exceptions.
6868

69-
The STL deals with the first two considerations safely. Only `max_element`, `min_element`, `minmax_element`, `max`, `min`, `minmax`, `is_sorted`, and `is_sorted_until` are manually vectorized. These algorithms:
70-
- Don’t compute new floating-point values. Instead, they only compare existing values to ensure that differences in operation order don't impact precision.
71-
- Since these are sorting algorithms, `NaN` values aren't allowed inputs.
69+
The STL addresses the first two considerations safely. Only `max_element`, `min_element`, `minmax_element`, `max`, `min`, `minmax`, `is_sorted`, and `is_sorted_until` are manually vectorized. These algorithms:
70+
- Don’t compute new floating-point values. Instead, they compare existing values to ensure that differences in operation order don't impact precision.
71+
- Because these are sorting algorithms, `NaN` values aren't allowed as inputs.
7272

73-
Use `_USE_STD_VECTOR_FLOATING_ALGORITHMS` to control the use of these vectorized algorithms for floating point types. Set it to 0 to disable vectorization. `_USE_STD_VECTOR_FLOATING_ALGORITHMS` has no effect if `_USE_STD_VECTOR_ALGORITHMS` is set to 0.
73+
Use `_USE_STD_VECTOR_FLOATING_ALGORITHMS` to control the use of these vectorized algorithms for floating-point types. Set it to 0 to disable vectorization. `_USE_STD_VECTOR_FLOATING_ALGORITHMS` doesn't affect anything if `_USE_STD_VECTOR_ALGORITHMS` is set to 0.
7474

7575
`_USE_STD_VECTOR_FLOATING_ALGORITHMS` defaults to 0 when [`/fp:except`](../build/reference/fp-specify-floating-point-behavior.md#except) is set.
7676

77-
Ensure that you assign the same value to `_USE_STD_VECTOR_FLOATING_ALGORITHMS` for all linked translation units that use algorithms. A reliable way to do this is by configuring it in the project properties instead of in the source code. For more information about how to configure it, see [/D (Preprocessor Definitions)](../build/reference/d-preprocessor-definitions.md).
77+
Assign the same value to `_USE_STD_VECTOR_FLOATING_ALGORITHMS` for all linked translation units that use algorithms. Configure it in the project properties instead of in the source code for consistency. For more information about how to configure it, see [/D (Preprocessor Definitions)](../build/reference/d-preprocessor-definitions.md).
7878

7979
## See also
8080

0 commit comments

Comments
 (0)