From 94b286f1f92f42cfea8fea88f8ad6a8de793584b Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 9 May 2018 16:35:15 +0300 Subject: [PATCH] docs: add new alignment option to docs --- docs/source/getting_started.rst | 7 +++++++ docs/source/index.rst | 1 + docs/source/opt.rst | 36 +++++++++++++++++++++++++++++++++ docs/source/troubleshooting.rst | 3 +++ include/cglm/types.h | 6 +++--- 5 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 docs/source/opt.rst diff --git a/docs/source/getting_started.rst b/docs/source/getting_started.rst index a152371..05c4440 100644 --- a/docs/source/getting_started.rst +++ b/docs/source/getting_started.rst @@ -27,6 +27,13 @@ Alignment is Required: **vec4** and **mat4** requires 16 byte alignment because vec4 and mat4 operations are vectorized by SIMD instructions (SSE/AVX). +**UPDATE:** + By starting v0.4.5 cglm provides an option to disable alignment requirement, it is enabled as default + + | Check :doc:`opt` page for more details + + Also alignment is disabled for older msvc verisons as default. Now alignment only is required in Visual Studio 2017 version 15.6+ if CGLM_ALL_UNALIGNED macro is not defined. + Allocations: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *cglm* doesn't alloc any memory on heap. So it doesn't provide any allocator. diff --git a/docs/source/index.rst b/docs/source/index.rst index 32e7b48..cfdf220 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -40,6 +40,7 @@ Also currently only **float** type is supported for most operations. getting_started opengl api + opt troubleshooting Indices and tables diff --git a/docs/source/opt.rst b/docs/source/opt.rst new file mode 100644 index 0000000..c614e42 --- /dev/null +++ b/docs/source/opt.rst @@ -0,0 +1,36 @@ +.. default-domain:: C + +Options +=============================================================================== + +A few options are provided via macros. + +Alignment +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +As default, cglm requires types to be aligned. Alignment requirements: + +vec3: 8 byte +vec4: 16 byte +mat4: 16 byte +versor: 16 byte + +By starting **v0.4.5** cglm provides an option to disable alignment requirement. +To enable this option define **CGLM_ALL_UNALIGNED** macro before all headers. +You can define it in Xcode, Visual Studio (or other IDEs) or you can also prefer +to define it in build system. If you use pre-compiled verisons then you +have to compile cglm with **CGLM_ALL_UNALIGNED** macro. + +**VERY VERY IMPORTANT:** If you use cglm in multiple projects and + those projects are depends on each other, then + + | *ALWAYS* or *NEVER USE* **CGLM_ALL_UNALIGNED** macro in linked projects + + if you do not know what you are doing. Because a cglm header included + via 'project A' may force types to be aligned and another cglm header + included via 'project B' may not require alignment. In this case + cglm functions will read from and write to **INVALID MEMORY LOCATIONs**. + + ALWAYS USE SAME CONFIGURATION / OPTION for **cglm** if you have multiple projects. + + For instance if you set CGLM_ALL_UNALIGNED in a project then set it in other projects too diff --git a/docs/source/troubleshooting.rst b/docs/source/troubleshooting.rst index d599c7d..7c416b0 100644 --- a/docs/source/troubleshooting.rst +++ b/docs/source/troubleshooting.rst @@ -43,6 +43,9 @@ you may do it yourself. **This MSVC issue is still in TODOs.** +**UPDATE:** By starting v0.4.5 cglm provides an option to disable alignment requirement. +Also alignment is disabled for older msvc verisons as default. Now alignment only is required in Visual Studio 2017 version 15.6+ if CGLM_ALL_UNALIGNED macro is defined. + Crashes, Invalid Memory Access: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/include/cglm/types.h b/include/cglm/types.h index 4a7d019..99226df 100644 --- a/include/cglm/types.h +++ b/include/cglm/types.h @@ -9,10 +9,10 @@ #define cglm_types_h #if defined(_MSC_VER) -#if _MSC_VER < 1913 /* Visual Studio 2017 version 15.6 */ -# define CGLM_ALL_UNALIGNED /* do not use alignment for older visual studio versions */ -# define CGLM_ALIGN(X) /* __declspec(align(X)) */ +#if _MSC_VER < 1913 /* Visual Studio 2017 version 15.6 */ +# define CGLM_ALL_UNALIGNED +# define CGLM_ALIGN(X) /* no alignment */ #else # define CGLM_ALIGN(X) __declspec(align(X)) #endif