Skip to content

Adding documentation for CA1516 - Use cross-platform intrinsics #47276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions docs/fundamentals/code-analysis/quality-rules/ca1516.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
title: "CA1516: Use cross-platform intrinsics"
description: "Learn about code analyzer rule CA1516 - Use cross-platform intrinsics"
ms.date: 07/09/2025
ms.topic: reference
f1_keywords:
- CA1516
- UseCrossPlatformIntrinsicsAnalyzer
helpviewer_keywords:
- CA1516
author: TannerGooding
dev_langs:
- CSharp
---

# CA1516: Use cross-platform intrinsics

| Property | Value |
|-------------------------------------|------------------------------------------------|
| **Rule ID** | CA1516 |
| **Title** | Use cross-platform intrinsics |
| **Category** | [Maintainability](maintainability-warnings.md) |
| **Fix is breaking or non-breaking** | Non-breaking |
| **Enabled by default in .NET 9** | No |

## Cause

A platform or architecture specific intrinsic is used when a cross-platform equivalent exists.

## Rule description

This rule detects usage of platform-specific intrinsics that can be replaced with an equivalent cross-platform intrinsic instead.

## How to fix violations

Apply the fixer that switches the code to use the equivalent cross-platform intrinsic.

## Example

The following code snippet shows three similar violations of CA1516:

```csharp
using System;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.Arm;
using System.Runtime.Intrinsics.Wasm;
using System.Runtime.Intrinsics.X86;

class C
{
Vector128<byte> M1(Vector128<byte> x, Vector128<byte> y) => AdvSimd.Add(x, y);
Vector128<byte> M2(Vector128<byte> x, Vector128<byte> y) => Sse2.Add(x, y);
Vector128<byte> M3(Vector128<byte> x, Vector128<byte> y) => PackedSimd.Add(x, y);
}
```

The following code snippet fixes the violation and would be applied by the fixer:

```csharp
using System;
using System.Runtime.Intrinsics;

class C
{
Vector128<byte> M1(Vector128<byte> x, Vector128<byte> y) => x + y;
Vector128<byte> M2(Vector128<byte> x, Vector128<byte> y) => x + y;
Vector128<byte> M3(Vector128<byte> x, Vector128<byte> y) => x + y;
}
```

Once the fix has been applied, it becomes more obvious that the three methods could be simplified to be a single method that works on all platforms.

## When to suppress warnings

It's safe to suppress a violation of this rule if you're not concerned about the maintainability of your code.

## Suppress a warning

If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.

```csharp
#pragma warning disable CA1516
// The code that's violating the rule is on this line.
#pragma warning restore CA1516
```

To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../configuration-files.md).

```ini
[*.{cs,vb}]
dotnet_diagnostic.CA1516.severity = none
```

For more information, see [How to suppress code analysis warnings](../suppress-warnings.md).

## Configure code to analyze

You can configure which _output assembly kinds_ to apply this rule to. For example, to only apply this rule to code that produces a console application or a dynamically linked library (that is, not a UI app), add the following key-value pair to an *.editorconfig* file in your project:

```ini
dotnet_code_quality.CA1516.output_kind = ConsoleApplication, DynamicallyLinkedLibrary
```

For more information, see [output_kind](../code-quality-rule-options.md#output_kind).