~ubuntu-branches/ubuntu/trusty/khronos-opencl-man/trusty

« back to all changes in this revision

Viewing changes to attributes-types.xml

  • Committer: Package Import Robot
  • Author(s): Mathieu Malaterre
  • Date: 2013-05-21 18:06:15 UTC
  • Revision ID: package-import@ubuntu.com-20130521180615-6e0s2n3pai95ip2f
Tags: upstream-1.0~svn21772
ImportĀ upstreamĀ versionĀ 1.0~svn21772

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="UTF-8"?>
 
2
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook MathML Module V1.1b1//EN"
 
3
              "http://www.oasis-open.org/docbook/xml/mathml/1.1CR1/dbmathml.dtd">
 
4
 
 
5
<refentry>
 
6
    <refentryinfo>
 
7
        <keywordset>
 
8
            <keyword>Attributes of Types</keyword>
 
9
        </keywordset>
 
10
    </refentryinfo>
 
11
 
 
12
    <refmeta>
 
13
        <refentrytitle>Attributes of Types</refentrytitle>
 
14
 
 
15
        <refmiscinfo>
 
16
            <copyright>
 
17
                <year>2007-2011</year>
 
18
                <holder>The Khronos Group Inc.
 
19
 Permission is hereby granted, free of charge, to any person obtaining a
 
20
copy of this software and/or associated documentation files (the
 
21
"Materials"), to deal in the Materials without restriction, including
 
22
without limitation the rights to use, copy, modify, merge, publish,
 
23
distribute, sublicense, and/or sell copies of the Materials, and to
 
24
permit persons to whom the Materials are furnished to do so, subject to
 
25
the condition that this copyright notice and permission notice shall be included
 
26
in all copies or substantial portions of the Materials.</holder>
 
27
            </copyright>
 
28
        </refmiscinfo>
 
29
        <manvolnum>3</manvolnum>
 
30
    </refmeta>
 
31
 
 
32
<!-- ================================ SYNOPSIS -->
 
33
 
 
34
    <refnamediv id="AttributesofTypes">
 
35
        <refname>Attributes of Types</refname>
 
36
 
 
37
        <refpurpose>
 
38
            Attributes of Types.
 
39
        </refpurpose>
 
40
    </refnamediv>
 
41
 
 
42
    <!-- ALTERNATIVE SYNTAX SYNOPSIS (NON-FUNCTION) -->
 
43
 
 
44
    <refsect2 id="synopsis">
 
45
        <title>
 
46
        </title>
 
47
 
 
48
        <informaltable frame="none">
 
49
            <tgroup cols="1" align="left" colsep="0" rowsep="0">
 
50
                <colspec colname="col1" colnum="1" />
 
51
                <tbody>
 
52
                    <row>
 
53
                        <entry>
 
54
__attribute__ ((aligned))
 
55
__attribute__ ((aligned (<emphasis>n</emphasis>)))
 
56
__attribute__ ((packed))
 
57
                        </entry>
 
58
                    </row>
 
59
                </tbody>
 
60
            </tgroup>
 
61
        </informaltable>
 
62
    </refsect2>
 
63
 
 
64
<!-- ================================ DESCRIPTION  -->
 
65
 
 
66
    <refsect1 id="description"><title>Description</title>
 
67
        <para>
 
68
          The keyword <constant>__attribute__</constant> allows you to specify special attributes
 
69
          of <code>enum</code>, <code>struct</code> and <code>union</code> types when you
 
70
          define such types.  This keyword is followed by an attribute specification inside
 
71
          double parentheses. Two attributes are currently defined for types: aligned, and packed.
 
72
        </para>
 
73
 
 
74
        <para>
 
75
          You may specify type attributes in an <code>enum</code>, <code>struct</code>,
 
76
          or <code>union</code> type declaration or definition, or for other types in a
 
77
          <code>typedef</code> declaration.
 
78
        </para>
 
79
 
 
80
        <para>
 
81
          For an <code>enum</code>, <code>struct</code>, or <code>union</code> type, you
 
82
          may specify attributes either between the <code>enum</code>, <code>struct</code>
 
83
          or <code>union</code> tag and the name of the type, or just past the closing curly
 
84
          brace of the <emphasis>definition</emphasis>. The former syntax is preferred.
 
85
        </para>
 
86
    </refsect1>
 
87
 
 
88
    <refsect2 id="aligned"><title>aligned (<varname>alignment</varname>)</title>
 
89
        <!-- Using refsect2 so we can have shaded backgrounds behind examples  -->
 
90
        <para>
 
91
          This attribute specifies a minimum alignment (in bytes) for variables of the specified
 
92
          type. For example, the declarations:
 
93
        </para>
 
94
 
 
95
    <para>
 
96
        <informaltable frame="none">
 
97
            <tgroup cols="1" align="left" colsep="0" rowsep="0">
 
98
                <colspec colname="col1" colnum="1" /> 
 
99
                <tbody>
 
100
                    <row>
 
101
                        <entry>    <code>struct S { short f[3]; } __attribute__ ((aligned (8)));
 
102
    typedef int more_aligned_int __attribute__ ((aligned (8)));</code></entry>
 
103
                    </row>
 
104
                </tbody>
 
105
            </tgroup>
 
106
        </informaltable>
 
107
    </para>
 
108
 
 
109
    <para>
 
110
      force the compiler to ensure (as far as it can) that each variable whose type is
 
111
      <code>struct S</code> or <code>more_aligned_int</code> will be allocated and aligned
 
112
      <emphasis>at least</emphasis> on a 8-byte boundary.
 
113
    </para>
 
114
 
 
115
    <para>
 
116
      Note that the alignment of any given <code>struct</code> or <code>union</code> type
 
117
      is required by the ISO C standard to be at least a perfect multiple of the lowest
 
118
      common multiple of the alignments of all of the members of the <code>struct</code>
 
119
      or <code>union</code> in question and must also be a power of two. This means that
 
120
      you <emphasis>can</emphasis> effectively adjust the alignment of a <code>struct</code>
 
121
      or <code>union</code> type by attaching an aligned attribute to any one of the members
 
122
      of such a type, but the notation illustrated in the example above is a more obvious,
 
123
      intuitive, and readable way to request the compiler to adjust the alignment of an entire
 
124
      <code>struct</code> or <code>union</code> type.
 
125
    </para>
 
126
 
 
127
    <para>
 
128
      As in the preceding example, you can explicitly specify the alignment (in bytes) that
 
129
      you wish the compiler to use for a given <code>struct</code> or <code>union</code>
 
130
      type. Alternatively, you can leave out the alignment factor and just ask the compiler
 
131
      to align a type to the maximum useful alignment for the target machine you are compiling
 
132
      for. For example, you could write:
 
133
    </para>
 
134
 
 
135
    <para>
 
136
         <informaltable frame="none">
 
137
            <tgroup cols="1" align="left" colsep="0" rowsep="0">
 
138
                <colspec colname="col1" colnum="1" />
 
139
                <tbody>
 
140
                    <row>
 
141
                        <entry>    <code>struct S { short f[3]; } __attribute__ ((aligned));</code></entry>
 
142
                    </row>
 
143
                </tbody>
 
144
            </tgroup>
 
145
        </informaltable>
 
146
    </para>
 
147
 
 
148
    <para>
 
149
      Whenever you leave out the alignment factor in an <code>aligned</code> attribute
 
150
      specification, the compiler automatically sets the alignment for the type to the largest
 
151
      alignment which is ever used for any data type on the target machine you are compiling
 
152
      for. In the example above, the size of each <code>short</code> is 2 bytes, and therefore
 
153
      the size of the entire <code>struct S</code> type is 6 bytes. The smallest power of two
 
154
      which is greater than or equal to that is 8, so the compiler sets the alignment for the
 
155
      entire <code>struct S</code> type to 8 bytes.
 
156
    </para>
 
157
 
 
158
    <para>
 
159
      Note that the effectiveness of aligned attributes may be limited by inherent limitations
 
160
      of the OpenCL device and compiler. For some devices, the OpenCL compiler may only be
 
161
      able to arrange for variables to be aligned up to a certain maximum alignment. If the
 
162
      OpenCL compiler is only able to align variables up to a maximum of 8 byte alignment, then
 
163
      specifying <code>aligned(16)</code> in an <code>__attribute__</code> will still only provide
 
164
      you with 8 byte alignment. See your platform-specific documentation for further information.
 
165
    </para>
 
166
 
 
167
    <para>
 
168
      The <code>aligned</code> attribute can only increase the alignment; but you can decrease
 
169
      it by specifying <code>packed</code> as well. See below.
 
170
    </para>
 
171
 
 
172
</refsect2>
 
173
 
 
174
<refsect2 id="packed"><title>packed</title>
 
175
    <!-- Using refsect2 so we can have shaded backgrounds behind examples  -->
 
176
 
 
177
    <para>
 
178
      The <constant>packed</constant> attribute, attached to the <code>struct</code>
 
179
      or <code>union</code> type definition, specifies that each member of the structure or
 
180
      union is placed to minimize the memory required. When attached to an <code>enum</code>
 
181
      definition, it indicates that the smallest integral type should be used.
 
182
    </para>
 
183
 
 
184
    <para>
 
185
      Specifying this attribute for <code>struct</code> and <code>union</code> types is equivalent
 
186
      to specifying the <code>packed</code> attribute on each of the structure or union members.
 
187
    </para>
 
188
 
 
189
    <para>
 
190
      In the following example <code>struct my_packed_struct</code>'s members are packed closely
 
191
      together, but the internal layout of its <code>s</code> member is not packed. To do that,
 
192
      <code>struct my_unpacked_struct</code> would need to be packed, too.
 
193
    </para>
 
194
 
 
195
    <para>
 
196
         <informaltable frame="none">
 
197
            <tgroup cols="1" align="left" colsep="0" rowsep="0">
 
198
                <colspec colname="col1" colnum="1" /> <tbody>
 
199
                    <row>
 
200
                        <entry>    <code>struct my_unpacked_struct
 
201
    {
 
202
        char c; int i;
 
203
    };
 
204
 
 
205
    struct __attribute__ ((packed)) my_packed_struct
 
206
    {
 
207
        char c;
 
208
        int i;
 
209
        struct my_unpacked_struct s;
 
210
    };</code></entry>
 
211
                    </row>
 
212
                </tbody>
 
213
            </tgroup>
 
214
        </informaltable>
 
215
    </para>
 
216
 
 
217
    <para>
 
218
      You may only specify this attribute on the definition of a <code>enum</code>,
 
219
      <code>struct</code>, or <code>union</code>, not on a <code>typedef</code> which does not
 
220
      also define the enumerated type, structure or union.
 
221
    </para>
 
222
</refsect2>
 
223
 
 
224
<!-- ================================ EXAMPLE  -->
 
225
<!-- DO NOT DELETE IN CASE AN EXAMPLE IS ADDED IN THE FUTURE -->
 
226
<!--
 
227
    <refsect2 id="example1">
 
228
        <title>
 
229
            Example
 
230
        </title>
 
231
 
 
232
        <informaltable frame="none">
 
233
            <tgroup cols="1" align="left" colsep="0" rowsep="0">
 
234
                <colspec colname="col1" colnum="1" />
 
235
                <tbody>
 
236
                    <row>
 
237
                        <entry>
 
238
                            Example goes here - it will be set in "code" type with white space preserved.
 
239
                        </entry>
 
240
                    </row>
 
241
                </tbody>
 
242
            </tgroup>
 
243
        </informaltable>
 
244
    </refsect2>
 
245
-->
 
246
 
 
247
<!-- ================================ SPECIFICATION  -->
 
248
<!-- Set the "uri" attribute in the <olink /> element to the "named destination" for the PDF page
 
249
-->
 
250
    <refsect1 id="specification"><title>Specification</title>
 
251
        <para>
 
252
            <imageobject>
 
253
                <imagedata fileref="pdficon_small1.gif" format="gif" />
 
254
            </imageobject>
 
255
 
 
256
            <olink uri="attributes-types">OpenCL Specification</olink>
 
257
        </para>
 
258
    </refsect1>
 
259
 
 
260
<!-- ================================ ALSO SEE  -->
 
261
 
 
262
    <refsect1 id="seealso"><title>Also see</title>
 
263
        <para>
 
264
            <citerefentry href="attribute"><refentrytitle>__attribute__</refentrytitle></citerefentry>,
 
265
            <citerefentry href="attributes-blocksAndControlFlow"><refentrytitle>Blocks and Control-Flow Statement Attributes Attributes</refentrytitle></citerefentry>,
 
266
            <citerefentry href="attributes-variables"><refentrytitle>Variable Attributes</refentrytitle></citerefentry>
 
267
        </para>
 
268
    </refsect1>
 
269
 
 
270
<!-- ============================== COPYRIGHT -->
 
271
<!-- Content included from copyright.inc.xsl -->
 
272
 
 
273
    <refsect3 id="Copyright"><title></title>
 
274
        <imageobject>
 
275
                <imagedata fileref="KhronosLogo.jpg" format="jpg" />
 
276
        </imageobject>
 
277
        <para />
 
278
    </refsect3>
 
279
 
 
280
<!-- 23-Oct-2011 -->
 
281
</refentry>
 
282