… | |
… | |
105 | { |
105 | { |
106 | puts (errline); |
106 | puts (errline); |
107 | abort (); |
107 | abort (); |
108 | } |
108 | } |
109 | |
109 | |
110 | In this case, the compiler would probbaly be smart enough to decude it on |
110 | In this case, the compiler would probably be smart enough to deduce it on |
111 | it's own, so this is mainly useful for declarations. |
111 | its own, so this is mainly useful for declarations. |
112 | |
112 | |
113 | =item ecb_const |
113 | =item ecb_const |
114 | |
114 | |
115 | Declares that the function only depends on the values of it's arguments, |
115 | Declares that the function only depends on the values of its arguments, |
116 | much like a mathematical function. It specifically does not read or write |
116 | much like a mathematical function. It specifically does not read or write |
117 | any memory any arguments might point to, global variables, or call any |
117 | any memory any arguments might point to, global variables, or call any |
118 | non-const functions. It also must not have any side effects. |
118 | non-const functions. It also must not have any side effects. |
119 | |
119 | |
120 | Such a function can be optimised much more aggressively by the compiler - |
120 | Such a function can be optimised much more aggressively by the compiler - |
121 | for example, multiple calls with the same arguments can be optimised into |
121 | for example, multiple calls with the same arguments can be optimised into |
122 | a single call, which wouldn't be possible if the compiler would have to |
122 | a single call, which wouldn't be possible if the compiler would have to |
123 | expect any side effects. |
123 | expect any side effects. |
124 | |
124 | |
125 | It is best suited for functions in the sense of mathematical functions, |
125 | It is best suited for functions in the sense of mathematical functions, |
126 | such as a function return the square root of its input argument. |
126 | such as a function returning the square root of its input argument. |
127 | |
127 | |
128 | Not suited would be a function that calculates the hash of some memory |
128 | Not suited would be a function that calculates the hash of some memory |
129 | area you pass in, prints some messages or looks at a global variable to |
129 | area you pass in, prints some messages or looks at a global variable to |
130 | decide on rounding. |
130 | decide on rounding. |
131 | |
131 | |
… | |
… | |
154 | possible. |
154 | possible. |
155 | |
155 | |
156 | The compiler reacts by trying to place hot functions near to each other in |
156 | The compiler reacts by trying to place hot functions near to each other in |
157 | memory. |
157 | memory. |
158 | |
158 | |
159 | Whether a function is hot or not often depend son the whole program, |
159 | Whether a function is hot or not often depends on the whole program, |
160 | and less on the function itself. C<ecb_cold> is likely more useful in |
160 | and less on the function itself. C<ecb_cold> is likely more useful in |
161 | practise. |
161 | practise. |
162 | |
162 | |
163 | =item ecb_cold |
163 | =item ecb_cold |
164 | |
164 | |
… | |
… | |
169 | |
169 | |
170 | In addition to placing cold functions together (or at least away from hot |
170 | In addition to placing cold functions together (or at least away from hot |
171 | functions), this knowledge can be used in other ways, for example, the |
171 | functions), this knowledge can be used in other ways, for example, the |
172 | function will be optimised for size, as opposed to speed, and codepaths |
172 | function will be optimised for size, as opposed to speed, and codepaths |
173 | leading to calls to those functions can automatically be marked as if |
173 | leading to calls to those functions can automatically be marked as if |
174 | C<ecb_unlikel> had been used to reach them. |
174 | C<ecb_unlikely> had been used to reach them. |
175 | |
175 | |
176 | Good examples for such functions would be error reporting functions, or |
176 | Good examples for such functions would be error reporting functions, or |
177 | functions only called in exceptional or rare cases. |
177 | functions only called in exceptional or rare cases. |
178 | |
178 | |
179 | =item ecb_artificial |
179 | =item ecb_artificial |