ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libecb/ecb.pod
(Generate patch)

Comparing libecb/ecb.pod (file contents):
Revision 1.8 by root, Thu May 26 20:51:14 2011 UTC vs.
Revision 1.9 by root, Thu May 26 20:54:31 2011 UTC

39 #endif 39 #endif
40 } 40 }
41 41
42=item ecb_noinline 42=item ecb_noinline
43 43
44Prevent a function from being inlined - it might be optimsied away, but 44Prevent a function from being inlined - it might be optimised away, but
45not inlined into other functions. This is useful if you know your function 45not inlined into other functions. This is useful if you know your function
46is rarely called and large enough for inlining not to be helpful. 46is rarely called and large enough for inlining not to be helpful.
47 47
48=item ecb_noreturn 48=item ecb_noreturn
49 49
114 114
115However, by using C<ecb_likely>, you tell the compiler that the condition 115However, by using C<ecb_likely>, you tell the compiler that the condition
116is likely to be true (and for C<ecb_unlikel>, that it is unlikely to be 116is likely to be true (and for C<ecb_unlikel>, that it is unlikely to be
117true). 117true).
118 118
119For example, when you check for a 0-ptr and expect this to be a rare, 119For example, when you check for a null pointer and expect this to be a
120exceptional, case, then use C<ecb_unlikely>: 120rare, exceptional, case, then use C<ecb_unlikely>:
121 121
122 void my_free (void *ptr) 122 void my_free (void *ptr)
123 { 123 {
124 if (ecb_unlikely (ptr == 0)) 124 if (ecb_unlikely (ptr == 0))
125 return; 125 return;
129tell the compiler what the hot path through a function is can increase 129tell the compiler what the hot path through a function is can increase
130performance considerably. 130performance considerably.
131 131
132A very good example is in a function that reserves more space for some 132A very good example is in a function that reserves more space for some
133memory block (for example, inside an implementation of a string stream) - 133memory block (for example, inside an implementation of a string stream) -
134eahc time something is added, you have to check for a buffer overrun, but 134each time something is added, you have to check for a buffer overrun, but
135you expect that most checks will turn out to be false: 135you expect that most checks will turn out to be false:
136 136
137 /* make sure we have "size" extra room in our buffer */ 137 /* make sure we have "size" extra room in our buffer */
138 ecb_inline void 138 ecb_inline void
139 reserve (int size) 139 reserve (int size)
173call will never be executed. 173call will never be executed.
174 174
175=item bool ecb_unreachable () 175=item bool ecb_unreachable ()
176 176
177This function does nothing itself, except tell the compiler that it will 177This function does nothing itself, except tell the compiler that it will
178never be executed. Apart from supressing a warning in some cases, this 178never be executed. Apart from suppressing a warning in some cases, this
179function can be used to implement C<ecb_assume> or similar functions. 179function can be used to implement C<ecb_assume> or similar functions.
180 180
181=item bool ecb_prefetch (addr, rw, locality) [MACRO] 181=item bool ecb_prefetch (addr, rw, locality) [MACRO]
182 182
183Tells the compiler to try to prefetch memory at the given C<addr>ess 183Tells the compiler to try to prefetch memory at the given C<addr>ess
187something... in between. The memory pointed to by the address does not 187something... in between. The memory pointed to by the address does not
188need to be accessible (it could be a null pointer for example), but C<rw> 188need to be accessible (it could be a null pointer for example), but C<rw>
189and C<locality> must be compile-time constants. 189and C<locality> must be compile-time constants.
190 190
191An obvious way to use this is to prefetch some data far away, in a big 191An obvious way to use this is to prefetch some data far away, in a big
192array you loop over. This prefethces memory some 128 array elements later, 192array you loop over. This prefetches memory some 128 array elements later,
193in the hope that it will be ready when the CPU arrives at that location. 193in the hope that it will be ready when the CPU arrives at that location.
194 194
195 int sum = 0; 195 int sum = 0;
196 196
197 for (i = 0; i < N; ++i) 197 for (i = 0; i < N; ++i)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines