Skip to content

Commit c890131

Browse files
authored
Update CoPilot instructions (#287)
1 parent 74f4bec commit c890131

File tree

1 file changed

+277
-3
lines changed

1 file changed

+277
-3
lines changed

.github/copilot-instructions.md

Lines changed: 277 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ These instructions define how GitHub Copilot should assist with this project. Th
66

77
- **Project Type**: Math Library / DirectX / Direct3D
88
- **Project Name**: DirectXMath SIMD C++ linear algebra library
9-
- **Language**: C++
9+
- **Language**: C++ (minimum C++11; C++14, C++17, and C++20 features used conditionally)
1010
- **Framework / Libraries**: STL / CMake / CTest
11+
- **Compiler Requirement**: Visual C++ 2017 or later (`_MSC_VER >= 1910`) when using MSVC
1112

1213
## Getting Started
1314

@@ -20,6 +21,7 @@ These instructions define how GitHub Copilot should assist with this project. Th
2021
## General Guidelines
2122

2223
- **Code Style**: The project uses an .editorconfig file to enforce coding standards. Follow the rules defined in `.editorconfig` for indentation, line endings, and other formatting. Additional information can be found on the wiki at [Implementation](https://github.com/microsoft/DirectXMath/wiki/Implementation). The code requires C++11/C++14 features.
24+
> Notable `.editorconfig` rules: C/C++ files use 4-space indentation, `crlf` line endings, and `latin1` charset — avoid non-ASCII characters in source files. HLSL files have separate indent/spacing rules defined in `.editorconfig`.
2325
- **Documentation**: The project provides documentation on [Microsoft Learn](https://learn.microsoft.com/windows/win32/dxmath/directxmath-portal) with additional wiki pages available on [GitHub](https://github.com/microsoft/DirectXMath/wiki/).
2426
- **Error Handling**: The majority of functions have no error conditions and do not throw C++ exceptions which is why they are marked `noexcept`. A few functions have `bool` results to indicate success or failure.
2527
- **Testing**: Unit tests for this project are implemented in this repository [Test Suite](https://github.com/walbourn/directxmathtest/) and can be run using CTest per the instructions at [Test Documentation](https://github.com/walbourn/directxmathtest/wiki).
@@ -34,18 +36,274 @@ These instructions define how GitHub Copilot should assist with this project. Th
3436
.azuredevops/ # Azure DevOps pipeline configuration and policy files.
3537
.github/ # GitHub Actions workflow files and linter configuration files.
3638
.nuget/ # NuGet package configuration files.
37-
build/ # Miscellaneous build files and scripts.
39+
build/ # Miscellaneous build files and scripts (CMake config templates, pkg-config, PowerShell helpers).
3840
Inc/ # DirectXMath public and implementation files. The library is header-only, so all files are in this directory.
3941
Extensions/ # Extensions to the DirectXMath library with standalone SSE-level specific functions for runtime selection of SIMD instruction set.
4042
MatrixStack/ # D3DX9-like matrix stack implementation for DirectXMath.
4143
SHMath/ # Spherical harmonic functions using DirectXMath.
4244
Stereo3D/ # Stereo 3D projection matrix functions using DirectXMath created for HoloLens.
4345
XDSP/ # Digital Signal Processing (DSP) functions using DirectXMath.
4446
Tests/ # Tests are designed to be cloned from a separate repository at this location.
47+
wiki/ # Local clone of the GitHub wiki documentation repository.
4548
```
4649

4750
> The `Extensions` are not needed if building the library using `/arch:AVX` or `/arch:AVX2` which causes the DirectXMath library to build utilizing the additional SIMD instructions.
4851
52+
### Public Header Files (`Inc/`)
53+
54+
| File | Purpose |
55+
| --- | --- |
56+
| `DirectXMath.h` | Core library: types, constants, vector and matrix math functions |
57+
| `DirectXMathConvert.inl` | Implementation of type conversion / load / store functions |
58+
| `DirectXMathMatrix.inl` | Implementation of matrix math functions |
59+
| `DirectXMathMisc.inl` | Implementation of miscellaneous functions (quaternion, color, plane, etc.) |
60+
| `DirectXMathVector.inl` | Implementation of vector math functions |
61+
| `DirectXCollision.h` / `.inl` | Bounding volumes: `BoundingSphere`, `BoundingBox`, `BoundingOrientedBox`, `BoundingFrustum` |
62+
| `DirectXColors.h` | Predefined color constants (`DirectX::Colors::*` sRGB, `DirectX::ColorsLinear::*` linear) |
63+
| `DirectXPackedVector.h` / `.inl` | GPU-friendly packed vector types (`DirectX::PackedVector::*`), e.g. `XMCOLOR`, `XMHALF4`, `XMBYTE4` |
64+
65+
### Extension Header Files (`Extensions/`)
66+
67+
Each extension header provides optimized overrides for a specific instruction set tier. They must be included **after** `DirectXMath.h` and live in their own sub-namespace:
68+
69+
| File | Namespace | Instruction set |
70+
| --- | --- | --- |
71+
| `DirectXMathSSE3.h` | `DirectX::SSE3` | SSE3 |
72+
| `DirectXMathSSE4.h` | `DirectX::SSE4` | SSE4.1 |
73+
| `DirectXMathAVX.h` | `DirectX::AVX` | AVX |
74+
| `DirectXMathAVX2.h` | `DirectX::AVX2` | AVX2 |
75+
| `DirectXMathFMA3.h` | `DirectX::FMA3` | FMA3 |
76+
| `DirectXMathFMA4.h` | `DirectX::FMA4` | FMA4 (AMD) |
77+
| `DirectXMathF16C.h` | `DirectX::F16C` | F16C (half-precision) |
78+
| `DirectXMathBE.h` | `DirectX::BEMath` | Big-endian scalar fallback |
79+
80+
## Namespace Structure
81+
82+
All types and functions are in the `DirectX` namespace. Sub-namespaces are used for optional components:
83+
84+
| Namespace | Contents |
85+
| --- | --- |
86+
| `DirectX` | All core math types and functions |
87+
| `DirectX::PackedVector` | GPU-friendly packed types from `DirectXPackedVector.h` |
88+
| `DirectX::Colors` | sRGB named color constants from `DirectXColors.h` |
89+
| `DirectX::ColorsLinear` | Linear-space color constants from `DirectXColors.h` |
90+
| `DirectX::MathInternal` | Private implementation details (do not use directly) |
91+
| `DirectX::SSE3`, `::SSE4`, `::AVX`, `::AVX2`, `::FMA3`, `::FMA4`, `::F16C`, `::BEMath` | Extension-specific optimized overrides |
92+
93+
## SIMD Intrinsic Macro Hierarchy
94+
95+
DirectXMath auto-selects the SIMD backend based on compiler/architecture. Macros cascade from highest to lowest:
96+
97+
```cpp
98+
_XM_AVX2_INTRINSICS_ -> enables _XM_FMA3_INTRINSICS_ + _XM_F16C_INTRINSICS_
99+
_XM_AVX_INTRINSICS_ -> enables _XM_SSE4_INTRINSICS_
100+
_XM_SSE4_INTRINSICS_ -> enables _XM_SSE3_INTRINSICS_
101+
_XM_SSE3_INTRINSICS_ -> enables _XM_SSE_INTRINSICS_
102+
_XM_SSE_INTRINSICS_ (auto-enabled for x86/x64)
103+
_XM_ARM_NEON_INTRINSICS_ (auto-enabled for ARM/ARM64)
104+
_XM_NO_INTRINSICS_ (pure C++ fallback; force with this define)
105+
```
106+
107+
Optional macros:
108+
- `_XM_SVML_INTRINSICS_` — Intel Short Vector Math Library (auto-enabled with MSVC 2019+; opt-out with `_XM_DISABLE_INTEL_SVML_`)
109+
- `_XM_NO_MOVNT_` — Disables non-temporal store instructions (`_mm_stream_ps`, etc.)
110+
- `_XM_FAVOR_INTEL_` — Uses `_mm_permute_ps` (AVX) over `_mm_shuffle_ps` when available
111+
- `_XM_NO_XMVECTOR_OVERLOADS_` — Disables `XMVECTOR` arithmetic operators (auto-set for GCC/Clang)
112+
113+
When writing multi-path implementations, follow this pattern:
114+
115+
```cpp
116+
#if defined(_XM_NO_INTRINSICS_)
117+
// Pure C++ path
118+
#elif defined(_XM_ARM_NEON_INTRINSICS_)
119+
// ARM NEON path
120+
#elif defined(_XM_AVX2_INTRINSICS_)
121+
// AVX2 path
122+
#elif defined(_XM_SSE4_INTRINSICS_)
123+
// SSE4.1 path
124+
#elif defined(_XM_SSE_INTRINSICS_)
125+
// SSE/SSE2 path (baseline for x86/x64)
126+
#endif
127+
```
128+
129+
## Core Type System
130+
131+
### Computation Type
132+
133+
`XMVECTOR` is the fundamental 128-bit SIMD register type. It maps to `__m128` (SSE), `float32x4_t` (ARM NEON), or a plain struct (no-intrinsics). It must be **16-byte aligned**.
134+
135+
### Storage Types
136+
137+
Storage types hold data in memory. Use `XMLoad*` / `XMStore*` to move between storage and `XMVECTOR`.
138+
139+
| Type | Description |
140+
| --- | --- |
141+
| `XMFLOAT2` / `XMFLOAT2A` | 2D float vector (A = 16-byte aligned) |
142+
| `XMFLOAT3` / `XMFLOAT3A` | 3D float vector |
143+
| `XMFLOAT4` / `XMFLOAT4A` | 4D float vector |
144+
| `XMINT2/3/4` | 2/3/4D signed int32 vector |
145+
| `XMUINT2/3/4` | 2/3/4D unsigned int32 vector |
146+
| `XMFLOAT3X3`, `XMFLOAT4X3`, `XMFLOAT4X4`, `XMFLOAT4X4A` | Matrix storage types |
147+
148+
### Constant Helper Types
149+
150+
Used for declaring compile-time SIMD constants (not for computation):
151+
152+
```cpp
153+
XMVECTORF32 // float constants: { { { 1.f, 0.f, 0.f, 1.f } } }
154+
XMVECTORI32 // int32 constants: { { { 1, 0, 0, 1 } } }
155+
XMVECTORU32 // uint32 constants: { { { 0xFFFFFFFF, 0, 0, 0 } } }
156+
XMVECTORU8 // uint8 byte pattern: { { { 0x00, 0xFF, ... } } }
157+
```
158+
159+
### Calling Convention Typedefs
160+
161+
XMVECTOR and XMMATRIX have special parameter-passing typedefs to maximize register usage. **Always use these instead of raw `XMVECTOR`/`XMMATRIX` for function parameters.**
162+
163+
| Typedef | Purpose |
164+
| --- | --- |
165+
| `FXMVECTOR` | 1st–3rd `XMVECTOR` parameters (in-register on x86/ARM/ARM64/vectorcall) |
166+
| `GXMVECTOR` | 4th `XMVECTOR` parameter (in-register on ARM/ARM64/vectorcall) |
167+
| `HXMVECTOR` | 5th–6th `XMVECTOR` parameters (in-register on ARM64/vectorcall) |
168+
| `CXMVECTOR` | 7th+ `XMVECTOR` parameters (always by `const` reference) |
169+
| `FXMMATRIX` | 1st `XMMATRIX` parameter (in-register on ARM64/vectorcall) |
170+
| `CXMMATRIX` | 2nd+ `XMMATRIX` parameters (always by `const` reference) |
171+
172+
All functions that take or return `XMVECTOR`/`XMMATRIX` must use `XM_CALLCONV`:
173+
174+
```cpp
175+
XMVECTOR XM_CALLCONV XMVectorHermite(
176+
FXMVECTOR Position0, FXMVECTOR Tangent0, FXMVECTOR Position1,
177+
GXMVECTOR Tangent1, float t) noexcept;
178+
179+
XMVECTOR XM_CALLCONV XMVector3Project(
180+
FXMVECTOR V,
181+
float ViewportX, float ViewportY, float ViewportWidth, float ViewportHeight,
182+
float ViewportMinZ, float ViewportMaxZ,
183+
FXMMATRIX Projection, CXMMATRIX View, CXMMATRIX World) noexcept;
184+
```
185+
186+
### Load/Store Pattern
187+
188+
Always load storage types to `XMVECTOR` before computation, and store back afterward:
189+
190+
```cpp
191+
XMFLOAT3 input{ 1.f, 2.f, 3.f };
192+
XMVECTOR v = XMLoadFloat3(&input); // storage → register
193+
v = XMVector3Normalize(v);
194+
XMFLOAT3 output;
195+
XMStoreFloat3(&output, v); // register → storage
196+
```
197+
198+
Use the `A`-suffixed variants (`XMLoadFloat4A`, `XMStoreFloat4A`) only with 16-byte-aligned storage types (`XMFLOAT4A`, etc.).
199+
200+
## Naming Conventions
201+
202+
Source: `wiki/Implementation.md`
203+
204+
- **PascalCase**: class names, methods, free functions, enums
205+
- **camelCase**: struct member variables
206+
- **UPPERCASE**: preprocessor defines and nameless enums
207+
- **`XM` prefix**: types (`XMVECTOR`, `XMFLOAT3`), utility macros (`XM_PI`, `XM_CALLCONV`)
208+
- **`XMVector*/XMMatrix*/XMColor*/XMQuaternion*`**: function families
209+
- **`XMLoad*/XMStore*`**: load/store conversion functions
210+
- No [Hungarian notation](https://wikipedia.org/wiki/Hungarian_notation) except `p` for pointers and `sz` for strings
211+
212+
## SAL Annotations
213+
214+
The library uses SAL2 annotations on all function parameters. Include them on any new code:
215+
216+
```cpp
217+
_In_ // non-null input pointer
218+
_Out_ // non-null output pointer (written before read)
219+
_Inout_ // non-null input and output pointer
220+
_In_reads_(Count) // input array of Count elements
221+
_Out_writes_(Count) // output array of Count elements
222+
_In_reads_bytes_(n) // input pointer reading n bytes
223+
```
224+
225+
Example:
226+
227+
```cpp
228+
XMMATRIX XM_CALLCONV XMLoadFloat4x4(_In_ const XMFLOAT4X4* pSource) noexcept;
229+
void XM_CALLCONV XMStoreFloat4x4(_Out_ XMFLOAT4X4* pDestination, _In_ FXMMATRIX M) noexcept;
230+
```
231+
232+
SAL annotations compile to no-ops unless `/analyze` is used; they never affect code generation.
233+
234+
## Key Macros
235+
236+
| Macro | Description |
237+
| --- | --- |
238+
| `XM_CALLCONV` | `__vectorcall` (MSVC/clang-cl x86/x64), `__fastcall` (fallback), empty (GCC) |
239+
| `XM_ALIGNED_STRUCT(n)` | Portable `alignas(n) struct` / `__declspec(align(n)) struct` |
240+
| `XM_ALIGNED_DATA(n)` | Portable `alignas(n)` / `__attribute__((aligned(n)))` |
241+
| `XM_DEPRECATED` | `[[deprecated]]` (C++14+), `__attribute__((deprecated))` (GCC), `__declspec(deprecated)` (MSVC) |
242+
| `XM_CACHE_LINE_SIZE` | `64` (x86/x64), `128` (ARM/ARM64) |
243+
| `XMGLOBALCONST` | Used for global color constants in `DirectXColors.h` |
244+
| `XM_STREAM_PS` / `XM_SFENCE` | Non-temporal stores (controlled by `_XM_NO_MOVNT_`) |
245+
| `XM_FMADD_PS` / `XM_FNMADD_PS` | FMA ops when `_XM_FMA3_INTRINSICS_` is active, else expanded to mul+add |
246+
| `XM_PERMUTE_PS` | `_mm_permute_ps` (AVX) or `_mm_shuffle_ps` (SSE) |
247+
248+
## CMake Build Options
249+
250+
| CMake Option | Default | Description |
251+
| --- | --- | --- |
252+
| `BUILD_XDSP` | `OFF` | Build XDSP Digital Signal Processing extension |
253+
| `BUILD_SHMATH` | `OFF` | Build Spherical Harmonics math extension |
254+
| `BUILD_TESTING` | (CTest) | Enable CTest unit tests (requires `Tests/` submodule) |
255+
| `BUILD_AVX_TEST` | `OFF` | Test preset: enable AVX instruction set |
256+
| `BUILD_AVX2_TEST` | `OFF` | Test preset: enable AVX2 instruction set |
257+
| `BUILD_F16C_TEST` | `OFF` | Test preset: enable F16C instruction set |
258+
| `BUILD_NO_INTRINSICS` | `OFF` | Test preset: force `_XM_NO_INTRINSICS_` mode |
259+
260+
The CMake library exports as `Microsoft::DirectXMath` and requires **CMake 3.21+**.
261+
262+
## C++ Standard Feature Usage
263+
264+
The library uses conditional C++ standard feature guards:
265+
266+
```cpp
267+
#if (__cplusplus >= 201402L)
268+
// C++14 features (e.g., [[deprecated]])
269+
#endif
270+
271+
#if (__cplusplus >= 201703L)
272+
// C++17 features (e.g., alignas for XM_ALIGNED_STRUCT)
273+
#endif
274+
275+
#if (__cplusplus >= 202002L)
276+
// C++20 features (e.g., spaceship <=> operator on XMFLOAT2/3/4)
277+
#include <compare>
278+
bool operator == (const XMFLOAT2&) const = default;
279+
auto operator <=> (const XMFLOAT2&) const = default;
280+
#endif
281+
```
282+
283+
The base requirement is **C++11**. Do not unconditionally use C++14/17/20 features without guards.
284+
285+
## File Header Convention
286+
287+
Every source file (`.h`, `.inl`, etc.) must begin with this block:
288+
289+
```cpp
290+
//-------------------------------------------------------------------------------------
291+
// {FileName}
292+
//
293+
// {One-line description}
294+
//
295+
// Copyright (c) Microsoft Corporation.
296+
// Licensed under the MIT License.
297+
//
298+
// http://go.microsoft.com/fwlink/?LinkID=615560
299+
//-------------------------------------------------------------------------------------
300+
```
301+
302+
Section separators within files use:
303+
- Major sections: `//-------------------------------------------------------------------------------------`
304+
- Subsections: `//---------------------------------------------------------------------------------`
305+
306+
The project does **not** use Doxygen. API documentation is maintained exclusively on the GitHub wiki.
49307
## References
50308

51309
- [Source git repository on GitHub](https://github.com/microsoft/DirectXMath.git)
@@ -91,11 +349,27 @@ When creating documentation:
91349
- The code supports building for Windows and Linux.
92350
- Portability and conformance of the code is validated by building with Visual C++, clang/LLVM for Windows, MinGW, and GCC for Linux.
93351

352+
### Platform and Compiler `#ifdef` Guards
353+
354+
Use these established guards — do not invent new ones:
355+
356+
| Guard | Purpose |
357+
| --- | --- |
358+
| `_WIN32` | Windows platform (desktop, UWP, Xbox) |
359+
| `_MSC_VER` | MSVC-specific (and MSVC-like clang-cl) pragmas and warning suppression |
360+
| `__clang__` | Clang/LLVM diagnostic suppressions |
361+
| `__MINGW32__` | MinGW compatibility headers |
362+
| `_M_ARM64` / `_M_X64` / `_M_IX86` | Architecture-specific code paths for MSVC (`#ifdef`) |
363+
| `_M_ARM64EC` | ARM64EC ABI (ARM64 code with x64 interop using ARM-NEON) for MSVC |
364+
| `__aarch64__` / `__x86_64__` / `__i386__` | Additional architecture-specific symbols for MinGW/GNUC (`#if`) |
365+
366+
> `_M_ARM`/ `__arm__` is legacy 32-bit ARM which is deprecated.
367+
94368
## Code Review Instructions
95369

96370
When reviewing code, focus on the following aspects:
97371

98-
- Adherence to coding standards defined in `.editorconfig` and on the [wiki](https://github.com/microsoft/DirectXTK/wiki/Implementation).
372+
- Adherence to coding standards defined in `.editorconfig` and on the [wiki](https://github.com/microsoft/DirectXMath/wiki/Implementation).
99373
- Make coding recommendations based on the *C++ Core Guidelines*.
100374
- Proper use of RAII and smart pointers.
101375
- Correct error handling practices and C++ Exception safety.

0 commit comments

Comments
 (0)