diff options
author | Arne Döring <arne.doering@gmx.net> | 2019-11-13 09:22:41 +0100 |
---|---|---|
committer | cooldome <cdome@bk.ru> | 2019-11-13 08:22:41 +0000 |
commit | 0496a666e22465eba9a309f0974220988f7f9920 (patch) | |
tree | d8393dceb5064a0f6bc1331d89759bb18a1a6a0c /doc | |
parent | 84861eb48a1a7aa400b05a39b1d1dc1fc745aed2 (diff) | |
download | Nim-0496a666e22465eba9a309f0974220988f7f9920.tar.gz |
implemented alignas pragma (#12643)
* implemented alignas pragma * fix bootstrap * generate c++ compatible syntax for alignas * Make it work. * Multiple alignof expressions. Implement top level alignof.
Diffstat (limited to 'doc')
-rw-r--r-- | doc/manual.rst | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/doc/manual.rst b/doc/manual.rst index d1fa1ba07..71bfb1e2b 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -6433,6 +6433,38 @@ generates: unsigned int flag:1; }; +Alignas pragma +-------------- + +The ``alignas`` pragma is for variables and object field members. It +modifies the alignment requirement of the thing being declared. The +argument must be a constant power of 2 or 0. Valid non-zero +alignments that are weaker than another alignas pragmas on the same +declaration are ignored. Alignments that are weaker that the +alignment requirement of the type are ignored. ``alignas(0)`` is +always ignored. + +.. code-block:: Nim + + type + sseType = object + sseData {.alignas(16).}: array[4,float32] + + # every object will be aligned to 128-byte boundary + Data = object + x: char + cacheline {.alignas(128).}: array[128, char] # over-aligned array of char, + + proc main() = + echo "sizeof(Data) = ", sizeof(Data), " (1 byte + 127 bytes padding + 128-byte array)" + # output: sizeof(Data) = 256 (1 byte + 127 bytes padding + 128-byte array) + echo "alignment of sseType is ", alignof(sseType) + # output: alignment of sseType is 16 + var d {.alignas(2048).}: Data # this instance of data is aligned even stricter + + main() + +This pragma has no effect on nimvm or the js backend. Volatile pragma --------------- |