|
1 #!/usr/bin/perl |
|
2 # |
|
3 |
|
4 |
|
5 |
|
6 print <<EOF |
|
7 /* This file is autogenerated. Do not edit. */ |
|
8 /* |
|
9 * LIBOIL - Library of Optimized Inner Loops |
|
10 * Copyright (c) 2005 David A. Schleef <ds\@schleef.org> |
|
11 * All rights reserved. |
|
12 * |
|
13 * Redistribution and use in source and binary forms, with or without |
|
14 * modification, are permitted provided that the following conditions |
|
15 * are met: |
|
16 * 1. Redistributions of source code must retain the above copyright |
|
17 * notice, this list of conditions and the following disclaimer. |
|
18 * 2. Redistributions in binary form must reproduce the above copyright |
|
19 * notice, this list of conditions and the following disclaimer in the |
|
20 * documentation and/or other materials provided with the distribution. |
|
21 * |
|
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
|
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, |
|
26 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|
27 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
|
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|
30 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
|
31 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
32 * POSSIBILITY OF SUCH DAMAGE. |
|
33 */ |
|
34 |
|
35 #ifdef HAVE_CONFIG_H |
|
36 #include "config.h" |
|
37 #endif |
|
38 |
|
39 #include <math.h> |
|
40 |
|
41 #include <liboil/liboil.h> |
|
42 #include <liboil/liboilclasses.h> |
|
43 |
|
44 EOF |
|
45 ; |
|
46 |
|
47 |
|
48 sub clamp_pointer |
|
49 { |
|
50 my $kernel = shift; |
|
51 my $type = shift; |
|
52 my $low = 1; |
|
53 my $high = 1; |
|
54 |
|
55 ($kernel eq "clamphigh") and $low = 0; |
|
56 ($kernel eq "clamplow") and $high = 0; |
|
57 |
|
58 print <<EOF |
|
59 static void |
|
60 ${kernel}_${type}_pointer (oil_type_${type} *dest, oil_type_${type} *src1, |
|
61 int n |
|
62 EOF |
|
63 ; |
|
64 |
|
65 $low && print (" , oil_type_${type} *low\n"); |
|
66 $high && print (" , oil_type_${type} *high\n"); |
|
67 |
|
68 print <<EOF |
|
69 ) |
|
70 { |
|
71 while (n) { |
|
72 oil_type_${type} x = *src1; |
|
73 EOF |
|
74 ; |
|
75 ($low) and print (" if (x < *low) x = *low;\n"); |
|
76 ($high) and print (" if (x > *high) x = *high;\n"); |
|
77 |
|
78 print <<EOF |
|
79 *dest = x; |
|
80 dest++; |
|
81 src1++; |
|
82 n--; |
|
83 } |
|
84 } |
|
85 OIL_DEFINE_IMPL (${kernel}_${type}_pointer, ${kernel}_${type}); |
|
86 |
|
87 EOF |
|
88 ; |
|
89 } |
|
90 |
|
91 sub clamp_unroll4 |
|
92 { |
|
93 my $kernel = shift; |
|
94 my $type = shift; |
|
95 my $low = 1; |
|
96 my $high = 1; |
|
97 |
|
98 ($kernel eq "clamphigh") and $low = 0; |
|
99 ($kernel eq "clamplow") and $high = 0; |
|
100 |
|
101 $proto = ""; |
|
102 $low and $proto .= ", oil_type_${type} *low"; |
|
103 $high and $proto .= ", oil_type_${type} *high"; |
|
104 |
|
105 $clamp = ""; |
|
106 $low and $clamp .= " if (x < *low) x = *low;\n"; |
|
107 $high and $clamp .= " if (x > *high) x = *high;\n"; |
|
108 |
|
109 print <<EOF |
|
110 static void |
|
111 ${kernel}_${type}_unroll4 (oil_type_${type} *dest, oil_type_${type} *src, |
|
112 int n $proto) |
|
113 { |
|
114 oil_type_${type} x; |
|
115 while (n&3) { |
|
116 x = *src; |
|
117 $clamp |
|
118 *dest = x; |
|
119 dest++; |
|
120 src++; |
|
121 n--; |
|
122 } |
|
123 n >>= 2; |
|
124 while (n) { |
|
125 x = src[0]; |
|
126 $clamp |
|
127 dest[0] = x; |
|
128 x = src[1]; |
|
129 $clamp |
|
130 dest[1] = x; |
|
131 x = src[2]; |
|
132 $clamp |
|
133 dest[2] = x; |
|
134 x = src[3]; |
|
135 $clamp |
|
136 dest[3] = x; |
|
137 dest+=4; |
|
138 src+=4; |
|
139 n--; |
|
140 } |
|
141 } |
|
142 OIL_DEFINE_IMPL (${kernel}_${type}_unroll4, ${kernel}_${type}); |
|
143 |
|
144 EOF |
|
145 ; |
|
146 } |
|
147 |
|
148 sub clamp_trick |
|
149 { |
|
150 my $kernel = shift; |
|
151 my $type = shift; |
|
152 my $low = 1; |
|
153 my $high = 1; |
|
154 |
|
155 ($kernel eq "clamphigh") and $low = 0; |
|
156 ($kernel eq "clamplow") and $high = 0; |
|
157 |
|
158 $proto = ""; |
|
159 $low and $proto .= ", oil_type_${type} *low"; |
|
160 $high and $proto .= ", oil_type_${type} *high"; |
|
161 |
|
162 $clamp = ""; |
|
163 $low and $clamp .= " x = x - (((x-*low)>>31)&(x-*low));\n"; |
|
164 $high and $clamp .= " x = x + (((*high-x)>>31)&(*high-x));\n"; |
|
165 |
|
166 print <<EOF |
|
167 static void |
|
168 ${kernel}_${type}_trick (oil_type_${type} *dest, oil_type_${type} *src, |
|
169 int n $proto) |
|
170 { |
|
171 int x; |
|
172 while (n&3) { |
|
173 x = *src; |
|
174 $clamp |
|
175 *dest = x; |
|
176 dest++; |
|
177 src++; |
|
178 n--; |
|
179 } |
|
180 n >>= 2; |
|
181 while (n) { |
|
182 x = src[0]; |
|
183 $clamp |
|
184 dest[0] = x; |
|
185 x = src[1]; |
|
186 $clamp |
|
187 dest[1] = x; |
|
188 x = src[2]; |
|
189 $clamp |
|
190 dest[2] = x; |
|
191 x = src[3]; |
|
192 $clamp |
|
193 dest[3] = x; |
|
194 dest+=4; |
|
195 src+=4; |
|
196 n--; |
|
197 } |
|
198 } |
|
199 OIL_DEFINE_IMPL (${kernel}_${type}_trick, ${kernel}_${type}); |
|
200 |
|
201 EOF |
|
202 ; |
|
203 } |
|
204 |
|
205 |
|
206 clamp_pointer("clamp", "s8"); |
|
207 clamp_pointer("clamp", "u8"); |
|
208 clamp_pointer("clamp", "s16"); |
|
209 clamp_pointer("clamp", "u16"); |
|
210 clamp_pointer("clamp", "s32"); |
|
211 clamp_pointer("clamp", "u32"); |
|
212 |
|
213 clamp_unroll4("clamp", "s8"); |
|
214 clamp_unroll4("clamp", "u8"); |
|
215 clamp_unroll4("clamp", "s16"); |
|
216 clamp_unroll4("clamp", "u16"); |
|
217 clamp_unroll4("clamp", "s32"); |
|
218 clamp_unroll4("clamp", "u32"); |
|
219 |
|
220 clamp_trick("clamp", "s8"); |
|
221 clamp_trick("clamp", "u8"); |
|
222 clamp_trick("clamp", "s16"); |
|
223 clamp_trick("clamp", "u16"); |
|
224 |
|
225 clamp_pointer("clamphigh", "s8"); |
|
226 clamp_pointer("clamphigh", "u8"); |
|
227 clamp_pointer("clamphigh", "s16"); |
|
228 clamp_pointer("clamphigh", "u16"); |
|
229 clamp_pointer("clamphigh", "s32"); |
|
230 clamp_pointer("clamphigh", "u32"); |
|
231 |
|
232 clamp_unroll4("clamphigh", "s8"); |
|
233 clamp_unroll4("clamphigh", "u8"); |
|
234 clamp_unroll4("clamphigh", "s16"); |
|
235 clamp_unroll4("clamphigh", "u16"); |
|
236 clamp_unroll4("clamphigh", "s32"); |
|
237 clamp_unroll4("clamphigh", "u32"); |
|
238 |
|
239 clamp_trick("clamphigh", "s8"); |
|
240 clamp_trick("clamphigh", "u8"); |
|
241 clamp_trick("clamphigh", "s16"); |
|
242 clamp_trick("clamphigh", "u16"); |
|
243 |
|
244 clamp_pointer("clamplow", "s8"); |
|
245 clamp_pointer("clamplow", "u8"); |
|
246 clamp_pointer("clamplow", "s16"); |
|
247 clamp_pointer("clamplow", "u16"); |
|
248 clamp_pointer("clamplow", "s32"); |
|
249 clamp_pointer("clamplow", "u32"); |
|
250 |
|
251 clamp_unroll4("clamplow", "s8"); |
|
252 clamp_unroll4("clamplow", "u8"); |
|
253 clamp_unroll4("clamplow", "s16"); |
|
254 clamp_unroll4("clamplow", "u16"); |
|
255 clamp_unroll4("clamplow", "s32"); |
|
256 clamp_unroll4("clamplow", "u32"); |
|
257 |
|
258 clamp_trick("clamplow", "s8"); |
|
259 clamp_trick("clamplow", "u8"); |
|
260 clamp_trick("clamplow", "s16"); |
|
261 clamp_trick("clamplow", "u16"); |
|
262 |
|
263 exit 0; |
|
264 |