Skip to content

Commit 00ee512

Browse files
author
Colin Robertson
authored
Add /fpcvt compiler option docs (MicrosoftDocs#3886)
* Add /fpcvt compiler option docs * Fix copypasta error * Update fp conversion intrinsics, too. * Replace deleted table row * Acrolinx pass * Fix TOC issues * Add useful links to intrinsics * Updates per John Morgan, plus acrolink * Update version info
1 parent cf5c7af commit 00ee512

10 files changed

+399
-146
lines changed

docs/build/reference/compiler-options-listed-alphabetically.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ This table contains an alphabetical list of compiler options. For a list of comp
5050
| [`/Fo`](fo-object-file-name.md) | Creates an object file. |
5151
| [`/fp`](fp-specify-floating-point-behavior.md) | Specify floating-point behavior. |
5252
| [`/Fp`](fp-name-dot-pch-file.md) | Specifies a precompiled header file name. |
53+
| [`/fpcvt`](fpcvt.md) | Specify floating-point to unsigned integer conversion behavior. |
5354
| [`/FR`](fr-fr-create-dot-sbr-file.md)<br /><br /> [`/Fr`](fr-fr-create-dot-sbr-file.md) | Generates browser files. **`/Fr`** is deprecated. |
5455
| [`/FS`](fs-force-synchronous-pdb-writes.md) | Forces serialization of all writes to the program database (PDB) file through MSPDBSRV.EXE. |
5556
| [`/fsanitize`](fsanitize.md) | Enables compilation of sanitizer instrumentation such as AddressSanitizer. |

docs/build/reference/compiler-options-listed-by-category.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ This article contains a categorical list of compiler options. For an alphabetica
3333
| [`/clr`](clr-common-language-runtime-compilation.md) | Produces an output file to run on the common language runtime. |
3434
| [`/EH`](eh-exception-handling-model.md) | Specifies the model of exception handling. |
3535
| [`/fp`](fp-specify-floating-point-behavior.md) | Specifies floating-point behavior. |
36+
| [`/fpcvt`](fpcvt.md) | Specify floating-point to unsigned integer conversion behavior. |
3637
| [`/GA`](ga-optimize-for-windows-application.md) | Optimizes for Windows applications. |
3738
| [`/Gd`](gd-gr-gv-gz-calling-convention.md) | Uses the **`__cdecl`** calling convention. (x86 only) |
3839
| [`/Ge`](ge-enable-stack-probes.md) | Deprecated. Activates stack probes. |

docs/build/reference/fp-specify-floating-point-behavior.md

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ f1_keywords: ["VC.Project.VCCLCompilerTool.floatingPointModel", "VC.Project.VCCL
66
helpviewer_keywords: ["-fp compiler option [C++]", "/fp compiler option [C++]"]
77
ms.assetid: 10469d6b-e68b-4268-8075-d073f4f5d57e
88
---
9-
# /fp (Specify floating-point behavior)
9+
# `/fp` (Specify floating-point behavior)
1010

11-
Specifies how the compiler treats floating-point expressions, optimizations, and exceptions. The **/fp** options specify whether the generated code allows floating-point environment changes to the rounding mode, exception masks, and subnormal behavior, and whether floating-point status checks return current, accurate results. It controls whether the compiler generates code that maintains source operation and expression ordering and conforms to the standard for NaN propagation, or if it instead generates more efficient code that may reorder or combine operations and use simplifying algebraic transformations that aren't allowed by the standard.
11+
Specifies how the compiler treats floating-point expressions, optimizations, and exceptions. The **`/fp`** options specify whether the generated code allows floating-point environment changes to the rounding mode, exception masks, and subnormal behavior, and whether floating-point status checks return current, accurate results. It controls whether the compiler generates code that maintains source operation and expression order, and conforms to the standard for NaN propagation. Or, if it instead generates more efficient code that may reorder or combine operations and use simplifying algebraic transformations that aren't allowed by the IEEE-754 standard.
1212

1313
## Syntax
1414

15-
::: moniker range=">msvc-160"
15+
::: moniker range=">=msvc-170"
1616

1717
**`/fp:contract`**\
1818
**`/fp:except`**\[**`-`**]\
@@ -21,6 +21,7 @@ Specifies how the compiler treats floating-point expressions, optimizations, and
2121
**`/fp:strict`**
2222

2323
::: moniker-end
24+
2425
::: moniker range="<=msvc-160"
2526

2627
**`/fp:except`**\[**`-`**]\
@@ -32,7 +33,7 @@ Specifies how the compiler treats floating-point expressions, optimizations, and
3233

3334
### Arguments
3435

35-
::: moniker range=">msvc-160"
36+
::: moniker range=">=msvc-170"
3637

3738
#### <a name="contract"></a> `/fp:contract`
3839

@@ -50,7 +51,7 @@ By default, the compiler uses **`/fp:precise`** behavior.
5051

5152
Under **`/fp:precise`**, the compiler preserves the source expression ordering and rounding properties of floating-point code when it generates and optimizes object code for the target machine. The compiler rounds to source code precision at four specific points during expression evaluation: at assignments, typecasts, when floating-point arguments get passed to a function call, and when a function call returns a floating-point value. Intermediate computations may be performed at machine precision. Typecasts can be used to explicitly round intermediate computations.
5253

53-
::: moniker range=">msvc-160"
54+
::: moniker range=">=msvc-170"
5455

5556
The compiler doesn't perform algebraic transformations on floating-point expressions, such as reassociation or distribution, unless it can guarantee the transformation produces a bitwise identical result. Expressions that involve special values (NaN, +infinity, -infinity, -0.0) are processed according to IEEE-754 specifications. For example, `x != x` evaluates to **`true`** if `x` is NaN. Floating-point contractions aren't generated by default under **`/fp:precise`**. This behavior is new in Visual Studio 2022. Previous compiler versions could generate contractions by default under **`/fp:precise`**.
5657

@@ -61,7 +62,7 @@ The compiler doesn't perform algebraic transformations on floating-point express
6162

6263
::: moniker-end
6364

64-
The compiler generates code intended to run in the [default floating-point environment](#the-default-floating-point-environment). It also assumes the floating-point environment isn't accessed or modified at runtime. That is, it assumes the code doesn't unmask floating-point exceptions, read or write floating-point status registers, or change rounding modes.
65+
The compiler generates code intended to run in the [default floating-point environment](#the-default-floating-point-environment). It also assumes the floating-point environment isn't accessed or modified at runtime. That is, it assumes the code: leaves floating-point exceptions masked, doesn't read or write floating-point status registers, and doesn't change rounding modes.
6566

6667
If your floating-point code doesn't depend on the order of operations and expressions in your floating-point statements (for example, if you don't care whether `a * b + a * c` is computed as `(b + c) * a` or `2 * a` as `a + a`), consider the [`/fp:fast`](#fast) option, which can produce faster, more efficient code. If your code both depends on the order of operations and expressions, and accesses or alters the floating-point environment (for example, to change rounding modes or to trap floating-point exceptions), use [`/fp:strict`](#strict).
6768

@@ -77,9 +78,9 @@ Under **`/fp:strict`**, the compiler generates code that allows the program to s
7778

7879
The **`/fp:fast`** option allows the compiler to reorder, combine, or simplify floating-point operations to optimize floating-point code for speed and space. The compiler may omit rounding at assignment statements, typecasts, or function calls. It may reorder operations or make algebraic transforms, for example, by use of associative and distributive laws. It may reorder code even if such transformations result in observably different rounding behavior. Because of this enhanced optimization, the result of some floating-point computations may differ from the ones produced by other **`/fp`** options. Special values (NaN, +infinity, -infinity, -0.0) may not be propagated or behave strictly according to the IEEE-754 standard. Floating-point contractions may be generated under **`/fp:fast`**. The compiler is still bound by the underlying architecture under **`/fp:fast`**, and more optimizations may be available through use of the [`/arch`](arch-minimum-cpu-architecture.md) option.
7980

80-
Under **`/fp:fast`**, the compiler generates code intended to run in the default floating-point environment and assumes the floating-point environment isn't accessed or modified at runtime. That is, it assumes the code doesn't unmask floating-point exceptions, read or write floating-point status registers, or change rounding modes.
81+
Under **`/fp:fast`**, the compiler generates code intended to run in the default floating-point environment and assumes the floating-point environment isn't accessed or modified at runtime. That is, it assumes the code: leaves floating-point exceptions masked, doesn't read or write floating-point status registers, and doesn't change rounding modes.
8182

82-
`/fp:fast` is intended for programs that don't require strict source code ordering and rounding of floating-point expressions, and don't rely on the standard rules for handling special values such as NaN. If your floating-point code requires preservation of source code ordering and rounding, or relies on standard behavior of special values, use [`/fp:precise`](#precise). If your code accesses or modifies the floating-point environment to change rounding modes, unmask floating-point exceptions, or check floating-point status, use [`/fp:strict`](#strict).
83+
**`/fp:fast`** is intended for programs that don't require strict source code ordering and rounding of floating-point expressions, and don't rely on the standard rules for handling special values such as `NaN`. If your floating-point code requires preservation of source code ordering and rounding, or relies on standard behavior of special values, use [`/fp:precise`](#precise). If your code accesses or modifies the floating-point environment to change rounding modes, unmask floating-point exceptions, or check floating-point status, use [`/fp:strict`](#strict).
8384

8485
#### <a name="except"></a> `/fp:except`
8586

@@ -97,24 +98,26 @@ The [`/Za`](za-ze-disable-language-extensions.md) (ANSI compatibility) option is
9798

9899
The compiler provides three pragma directives to override the floating-point behavior specified on the command line: [`float_control`](../../preprocessor/float-control.md), [`fenv_access`](../../preprocessor/fenv-access.md), and [`fp_contract`](../../preprocessor/fp-contract.md). You can use these directives to control floating-point behavior at function-level, not within a function. These directives don't correspond directly to the **`/fp`** options. This table shows how the **`/fp`** options and pragma directives map to each other. For more information, see the documentation for the individual options and pragma directives.
99100

100-
::: moniker range=">msvc-160"
101+
::: moniker range=">=msvc-170"
101102

102103
| Option | `float_control(precise, *)` | `float_control(except, *)` | `fenv_access(*)` | `fp_contract(*)` |
103104
|--|--|--|--|--|
104-
| `/fp:fast` | `off` | `off` | `off` | `on` |
105-
| `/fp:precise` | `on` | `off` | `off` | `off`\* |
106-
| `/fp:strict` | `on` | `on` | `on` | `off` |
105+
| **`/fp:fast`** | `off` | `off` | `off` | `on` |
106+
| **`/fp:precise`** | `on` | `off` | `off` | `off`\* |
107+
| **`/fp:strict`** | `on` | `on` | `on` | `off` |
107108

108109
\* In versions of Visual Studio before Visual Studio 2022, the **`/fp:precise`** behavior defaulted to `fp_contract(on)`.
109110

110111
::: moniker-end
111-
::: moniker range=">msvc-160"
112+
::: moniker range="<=msvc-160"
112113

113114
| Option | `float_control(precise, *)` | `float_control(except, *)` | `fenv_access(*)` | `fp_contract(*)` |
114115
|--|--|--|--|--|
115-
| `/fp:fast` | `off` | `off` | `off` | `on` |
116-
| `/fp:precise` | `on` | `off` | `off` | `on` |
117-
| `/fp:strict` | `on` | `on` | `on` | `off` |
116+
| **`/fp:fast`** | `off` | `off` | `off` | `on` |
117+
| **`/fp:precise`** | `on` | `off` | `off` | `on`\* |
118+
| **`/fp:strict`** | `on` | `on` | `on` | `off` |
119+
120+
\* In versions of Visual Studio starting with Visual Studio 2022, the **`/fp:precise`** behavior defaults to `fp_contract(off)`.
118121

119122
::: moniker-end
120123

docs/build/reference/fpcvt.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
description: "Learn more about: /fpcvt (Floating-point to integer conversion compatibility)"
3+
title: "/fpcvt (Floating-point to unsigned integer conversion compatibility)"
4+
ms.date: 11/03/2021
5+
f1_keywords: ["/fpcvt", "-fpcvt"]
6+
helpviewer_keywords: ["-fpcvt compiler option [C++]", "/fpcvt compiler option [C++]"]
7+
---
8+
# `/fpcvt` (Floating-point to integer conversion compatibility)
9+
10+
Specifies how the compiler treats floating-point conversions to integer types.
11+
12+
## Syntax
13+
14+
> **`/fpcvt:IA`**\
15+
> **`/fpcvt:BC`**
16+
17+
### Arguments
18+
19+
#### <a name="fpcvt-ia"></a> `/fpcvt:IA`
20+
21+
The **`/fpcvt:IA`** option tells the compiler to convert floating point values to integers so the results are compatible with the Intel AVX-512 conversion instructions. This behavior is the usual behavior in Visual Studio 2019 for x86 targets.
22+
23+
#### <a name="fpcvt-bc"></a> `/fpcvt:BC`
24+
25+
The **`/fpcvt:BC`** option tells the compiler to convert floating point values to unsigned integers so the results are compatible with the Visual Studio 2017 and earlier compilers. This behavior is the default in Visual Studio 2022.
26+
27+
## Remarks
28+
29+
In Visual Studio 2019 version 16.8 and later versions, the **`/fpcvt`** compiler option can be used to control the results of floating-point to integer conversions. The **`/fpcvt:BC`** option specifies the default behavior of Visual Studio 2022, which is the same as the behavior of Visual Studio 2017 and earlier versions. The **`/fpcvt:IA`** option specifies behavior compatible with Intel Architecture (IA) AVX-512 conversion instruction behavior. This option can be used with either 32-bit x86 or 64-bit x64 targets, and it applies whether [`/arch:AVX512`](arch-x86.md) is specified or not.
30+
31+
For Visual Studio 2019, the default behavior for x64 targets is consistent with **`/fpcvt:BC`** unless **`/arch:AVX512`** is specified. Usually, the behavior for x86 targets is consistent with **`/fpcvt:IA`**, except under **`/arch:IA32`**, **`/arch:SSE`**, or sometimes where the result of a function call is directly converted to an unsigned integer. Use of **`/fpcvt`** overrides the default, so all conversions are handled consistently on either target. The behavior of conversions for ARM and ARM64 targets isn't consistent with either **`/fpcvt:BC`** or **`/fpcvt:IA`**.
32+
33+
Standard C++ specifies that if a floating-point value can be exactly represented in an integer type, conversion from floating-point to that integer type must return that value. Otherwise, any behavior at all is allowed. Both **`/fpcvt`** options conform with Standard C++. The only difference is in what values are returned for invalid source values.
34+
35+
The **`/fpcvt:IA`** option causes any invalid conversion to return a single *sentinel* value, which is the destination value farthest from zero. For conversion to signed types, the sentinel is the minimum value for that type. Unsigned types use the maximum value. Floating-point operations may return a Not-a-Number (NaN) value to indicate an invalid operation. That's not an option for conversion to integer types, which don't have NaN values. The sentinel is used as a proxy for a NaN value, although it can also be the result of a valid conversion.
36+
37+
The **`/fpcvt:BC`** option also makes conversion to signed types return the minimum possible value when the source is invalid. However, conversion to unsigned integer types is based on conversion to **`long long`**. To convert a value to **`unsigned int`**, the compiler first converts it to type **`long long`**. The compiler then truncates the result to 32 bits. To convert a value to **`unsigned long long`**, valid source values that are too high for a **`long long`** are handled as a special case. All other values are first converted to **`long long`** and then recast to **`unsigned long long`**.
38+
39+
The **`/fpcvt`** options are new in Visual Studio 2019 version 16.8. If you specify more than one **`/fpcvt`** option on the command line, the later option takes precedence and the compiler generates a warning.
40+
41+
### Intrinsic functions for conversions
42+
43+
You can specify the behavior of a specific conversion independently of the **`/fpcvt `** option, which applies globally. The compiler provides intrinsic sentinel conversion functions for conversions compatible with **`/fpcvt:IA`**. For more information, see [Sentinel conversion functions](../../intrinsics/sentinel-conversion-functions.md). The compiler also provides saturation conversion functions compatible with conversions on ARM or ARM64 target architectures. For more information, see [Saturation conversion functions](../../intrinsics/saturation-conversion-functions.md).
44+
45+
The compiler also supports intrinsic conversion functions that execute as quickly as possible for valid conversions. These functions may generate any value or throw an exception for an invalid conversion. The results depend on the target platform, compiler options, and context. They're useful for handling values that have already been range-checked, or values generated in a way that can't cause an invalid conversion. For more information, see [Fast conversion functions](../../intrinsics/fast-conversion-functions.md).
46+
47+
### To set this compiler option in the Visual Studio development environment
48+
49+
1. Open the project's **Property Pages** dialog box. For details, see [Set C++ compiler and build properties in Visual Studio](../working-with-project-properties.md).
50+
51+
1. Select the **Configuration Properties** > **C/C++** > **Command Line** property page.
52+
53+
1. Modify the **Additional Options** property to add **`/fpcvt:IA`** or **`/fpcvt:BC`**. Choose **OK** to save your changes.
54+
55+
### To set this compiler option programmatically
56+
57+
- See <xref:Microsoft.VisualStudio.VCProjectEngine.VCLinkerTool.AdditionalOptions%2A>.
58+
59+
## See also
60+
61+
[MSVC compiler options](compiler-options.md)\
62+
[MSVC compiler command-line syntax](compiler-command-line-syntax.md)\
63+
[Fast conversion functions](../../intrinsics/fast-conversion-functions.md)\
64+
[Saturation conversion functions](../../intrinsics/saturation-conversion-functions.md)\
65+
[Sentinel conversion functions](../../intrinsics/sentinel-conversion-functions.md)

docs/build/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,8 @@ items:
561561
href: ../build/reference/fc-full-path-of-source-code-file-in-diagnostics.md
562562
- name: /fp (Specify floating-point behavior)
563563
href: ../build/reference/fp-specify-floating-point-behavior.md
564+
- name: /fpcvt (Floating-point to unsigned integer conversion behavior)
565+
href: ../build/reference/fpcvt.md
564566
- name: /FS (Force synchronous PDB writes)
565567
href: ../build/reference/fs-force-synchronous-pdb-writes.md
566568
- name: /fsanitize (Enable sanitizers)

0 commit comments

Comments
 (0)