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