1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/liboil/src/c/generate_clamp.pl Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,264 @@
1.4 +#!/usr/bin/perl
1.5 +#
1.6 +
1.7 +
1.8 +
1.9 +print <<EOF
1.10 +/* This file is autogenerated. Do not edit. */
1.11 +/*
1.12 + * LIBOIL - Library of Optimized Inner Loops
1.13 + * Copyright (c) 2005 David A. Schleef <ds\@schleef.org>
1.14 + * All rights reserved.
1.15 + *
1.16 + * Redistribution and use in source and binary forms, with or without
1.17 + * modification, are permitted provided that the following conditions
1.18 + * are met:
1.19 + * 1. Redistributions of source code must retain the above copyright
1.20 + * notice, this list of conditions and the following disclaimer.
1.21 + * 2. Redistributions in binary form must reproduce the above copyright
1.22 + * notice, this list of conditions and the following disclaimer in the
1.23 + * documentation and/or other materials provided with the distribution.
1.24 + *
1.25 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1.26 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1.27 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1.28 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
1.29 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1.30 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1.31 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1.32 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
1.33 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
1.34 + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1.35 + * POSSIBILITY OF SUCH DAMAGE.
1.36 + */
1.37 +
1.38 +#ifdef HAVE_CONFIG_H
1.39 +#include "config.h"
1.40 +#endif
1.41 +
1.42 +#include <math.h>
1.43 +
1.44 +#include <liboil/liboil.h>
1.45 +#include <liboil/liboilclasses.h>
1.46 +
1.47 +EOF
1.48 +;
1.49 +
1.50 +
1.51 +sub clamp_pointer
1.52 +{
1.53 + my $kernel = shift;
1.54 + my $type = shift;
1.55 + my $low = 1;
1.56 + my $high = 1;
1.57 +
1.58 + ($kernel eq "clamphigh") and $low = 0;
1.59 + ($kernel eq "clamplow") and $high = 0;
1.60 +
1.61 + print <<EOF
1.62 +static void
1.63 +${kernel}_${type}_pointer (oil_type_${type} *dest, oil_type_${type} *src1,
1.64 + int n
1.65 +EOF
1.66 +;
1.67 +
1.68 + $low && print (" , oil_type_${type} *low\n");
1.69 + $high && print (" , oil_type_${type} *high\n");
1.70 +
1.71 + print <<EOF
1.72 + )
1.73 +{
1.74 + while (n) {
1.75 + oil_type_${type} x = *src1;
1.76 +EOF
1.77 +;
1.78 + ($low) and print (" if (x < *low) x = *low;\n");
1.79 + ($high) and print (" if (x > *high) x = *high;\n");
1.80 +
1.81 + print <<EOF
1.82 + *dest = x;
1.83 + dest++;
1.84 + src1++;
1.85 + n--;
1.86 + }
1.87 +}
1.88 +OIL_DEFINE_IMPL (${kernel}_${type}_pointer, ${kernel}_${type});
1.89 +
1.90 +EOF
1.91 +;
1.92 +}
1.93 +
1.94 +sub clamp_unroll4
1.95 +{
1.96 + my $kernel = shift;
1.97 + my $type = shift;
1.98 + my $low = 1;
1.99 + my $high = 1;
1.100 +
1.101 + ($kernel eq "clamphigh") and $low = 0;
1.102 + ($kernel eq "clamplow") and $high = 0;
1.103 +
1.104 + $proto = "";
1.105 + $low and $proto .= ", oil_type_${type} *low";
1.106 + $high and $proto .= ", oil_type_${type} *high";
1.107 +
1.108 + $clamp = "";
1.109 + $low and $clamp .= " if (x < *low) x = *low;\n";
1.110 + $high and $clamp .= " if (x > *high) x = *high;\n";
1.111 +
1.112 + print <<EOF
1.113 +static void
1.114 +${kernel}_${type}_unroll4 (oil_type_${type} *dest, oil_type_${type} *src,
1.115 + int n $proto)
1.116 +{
1.117 + oil_type_${type} x;
1.118 + while (n&3) {
1.119 + x = *src;
1.120 +$clamp
1.121 + *dest = x;
1.122 + dest++;
1.123 + src++;
1.124 + n--;
1.125 + }
1.126 + n >>= 2;
1.127 + while (n) {
1.128 + x = src[0];
1.129 +$clamp
1.130 + dest[0] = x;
1.131 + x = src[1];
1.132 +$clamp
1.133 + dest[1] = x;
1.134 + x = src[2];
1.135 +$clamp
1.136 + dest[2] = x;
1.137 + x = src[3];
1.138 +$clamp
1.139 + dest[3] = x;
1.140 + dest+=4;
1.141 + src+=4;
1.142 + n--;
1.143 + }
1.144 +}
1.145 +OIL_DEFINE_IMPL (${kernel}_${type}_unroll4, ${kernel}_${type});
1.146 +
1.147 +EOF
1.148 +;
1.149 +}
1.150 +
1.151 +sub clamp_trick
1.152 +{
1.153 + my $kernel = shift;
1.154 + my $type = shift;
1.155 + my $low = 1;
1.156 + my $high = 1;
1.157 +
1.158 + ($kernel eq "clamphigh") and $low = 0;
1.159 + ($kernel eq "clamplow") and $high = 0;
1.160 +
1.161 + $proto = "";
1.162 + $low and $proto .= ", oil_type_${type} *low";
1.163 + $high and $proto .= ", oil_type_${type} *high";
1.164 +
1.165 + $clamp = "";
1.166 + $low and $clamp .= " x = x - (((x-*low)>>31)&(x-*low));\n";
1.167 + $high and $clamp .= " x = x + (((*high-x)>>31)&(*high-x));\n";
1.168 +
1.169 + print <<EOF
1.170 +static void
1.171 +${kernel}_${type}_trick (oil_type_${type} *dest, oil_type_${type} *src,
1.172 + int n $proto)
1.173 +{
1.174 + int x;
1.175 + while (n&3) {
1.176 + x = *src;
1.177 +$clamp
1.178 + *dest = x;
1.179 + dest++;
1.180 + src++;
1.181 + n--;
1.182 + }
1.183 + n >>= 2;
1.184 + while (n) {
1.185 + x = src[0];
1.186 +$clamp
1.187 + dest[0] = x;
1.188 + x = src[1];
1.189 +$clamp
1.190 + dest[1] = x;
1.191 + x = src[2];
1.192 +$clamp
1.193 + dest[2] = x;
1.194 + x = src[3];
1.195 +$clamp
1.196 + dest[3] = x;
1.197 + dest+=4;
1.198 + src+=4;
1.199 + n--;
1.200 + }
1.201 +}
1.202 +OIL_DEFINE_IMPL (${kernel}_${type}_trick, ${kernel}_${type});
1.203 +
1.204 +EOF
1.205 +;
1.206 +}
1.207 +
1.208 +
1.209 +clamp_pointer("clamp", "s8");
1.210 +clamp_pointer("clamp", "u8");
1.211 +clamp_pointer("clamp", "s16");
1.212 +clamp_pointer("clamp", "u16");
1.213 +clamp_pointer("clamp", "s32");
1.214 +clamp_pointer("clamp", "u32");
1.215 +
1.216 +clamp_unroll4("clamp", "s8");
1.217 +clamp_unroll4("clamp", "u8");
1.218 +clamp_unroll4("clamp", "s16");
1.219 +clamp_unroll4("clamp", "u16");
1.220 +clamp_unroll4("clamp", "s32");
1.221 +clamp_unroll4("clamp", "u32");
1.222 +
1.223 +clamp_trick("clamp", "s8");
1.224 +clamp_trick("clamp", "u8");
1.225 +clamp_trick("clamp", "s16");
1.226 +clamp_trick("clamp", "u16");
1.227 +
1.228 +clamp_pointer("clamphigh", "s8");
1.229 +clamp_pointer("clamphigh", "u8");
1.230 +clamp_pointer("clamphigh", "s16");
1.231 +clamp_pointer("clamphigh", "u16");
1.232 +clamp_pointer("clamphigh", "s32");
1.233 +clamp_pointer("clamphigh", "u32");
1.234 +
1.235 +clamp_unroll4("clamphigh", "s8");
1.236 +clamp_unroll4("clamphigh", "u8");
1.237 +clamp_unroll4("clamphigh", "s16");
1.238 +clamp_unroll4("clamphigh", "u16");
1.239 +clamp_unroll4("clamphigh", "s32");
1.240 +clamp_unroll4("clamphigh", "u32");
1.241 +
1.242 +clamp_trick("clamphigh", "s8");
1.243 +clamp_trick("clamphigh", "u8");
1.244 +clamp_trick("clamphigh", "s16");
1.245 +clamp_trick("clamphigh", "u16");
1.246 +
1.247 +clamp_pointer("clamplow", "s8");
1.248 +clamp_pointer("clamplow", "u8");
1.249 +clamp_pointer("clamplow", "s16");
1.250 +clamp_pointer("clamplow", "u16");
1.251 +clamp_pointer("clamplow", "s32");
1.252 +clamp_pointer("clamplow", "u32");
1.253 +
1.254 +clamp_unroll4("clamplow", "s8");
1.255 +clamp_unroll4("clamplow", "u8");
1.256 +clamp_unroll4("clamplow", "s16");
1.257 +clamp_unroll4("clamplow", "u16");
1.258 +clamp_unroll4("clamplow", "s32");
1.259 +clamp_unroll4("clamplow", "u32");
1.260 +
1.261 +clamp_trick("clamplow", "s8");
1.262 +clamp_trick("clamplow", "u8");
1.263 +clamp_trick("clamplow", "s16");
1.264 +clamp_trick("clamplow", "u16");
1.265 +
1.266 +exit 0;
1.267 +