1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
/* helper functions for Highway
*
* 29/07/21 kleisauke
* - from vector.c
*/
/*
This file is part of VIPS.
VIPS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
/*
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /*HAVE_CONFIG_H*/
#include <glib/gi18n-lib.h>
#include <stdlib.h>
#include <math.h>
#include <vips/vips.h>
#include <vips/vector.h>
#include <vips/debug.h>
#include <vips/internal.h>
/* If we are building with -fcf-protection (run-time checking of
* indirect jumps) then Orc won't work. Make sure it's off.
*
* https://gcc.gnu.org/onlinedocs/gcc/\
* Instrumentation-Options.html#index-fcf-protection
* https://gitlab.freedesktop.org/gstreamer/orc/issues/17
*
* orc 0.4.30 and later work with cf-protection.
*/
#ifdef __CET__
#ifndef HAVE_ORC_CF_PROTECTION
#undef HAVE_ORC
#endif
#endif
#ifdef HAVE_HWY
#include <hwy/highway.h>
#elif defined(HAVE_ORC)
#include <orc/orc.h>
#endif /*HAVE_HWY*/
/* Cleared by the command-line `--vips-novector` switch and the
* `VIPS_NOVECTOR` env var.
*/
gboolean vips__vector_enabled = TRUE;
void
vips__vector_init(void)
{
#ifdef HAVE_ORC
orc_init();
#endif /*HAVE_ORC*/
/* Check whether any features are being disabled by the environment.
*/
const char *env;
if ((env = g_getenv("VIPS_VECTOR")))
return vips_vector_disable_targets(
g_ascii_strtoll(env, NULL, 0));
/* Look for the deprecated IM_NOVECTOR environment variable as well.
*/
if (g_getenv("VIPS_NOVECTOR")
#if ENABLE_DEPRECATED
|| g_getenv("IM_NOVECTOR")
#endif
)
vips__vector_enabled = FALSE;
}
gboolean
vips_vector_isenabled(void)
{
#ifdef HAVE_HWY
return vips__vector_enabled && vips_vector_get_supported_targets() != 0;
#elif defined(HAVE_ORC)
return vips__vector_enabled;
#else
return FALSE;
#endif
}
void
vips_vector_set_enabled(gboolean enabled)
{
vips__vector_enabled = enabled;
}
/**
* vips_vector_get_builtin_targets:
*
* Gets a bitfield of builtin targets that libvips was built with.
*
* Returns: a bitfield of builtin targets.
*/
gint64
vips_vector_get_builtin_targets(void)
{
#ifdef HAVE_HWY
return HWY_TARGETS;
#else
return 0;
#endif
}
/**
* vips_vector_get_supported_targets:
*
* Gets a bitfield of enabled targets that are supported on this CPU. The
* targets returned may change after calling vips_vector_disable_targets().
*
* Returns: a bitfield of supported CPU targets.
*/
gint64
vips_vector_get_supported_targets(void)
{
#ifdef HAVE_HWY
return hwy::SupportedTargets() & ~(HWY_EMU128 | HWY_SCALAR);
#elif defined(HAVE_ORC)
return orc_target_get_default_flags(orc_target_get_default());
#else
return 0;
#endif
}
/**
* vips_vector_target_name:
* @target: A specific target to describe.
*
* Generates a human-readable ASCII string descriptor for a specific target.
*
* Returns: a string describing the target.
*/
const char *
vips_vector_target_name(gint64 target)
{
#ifdef HAVE_HWY
return hwy::TargetName(target);
#elif defined(HAVE_ORC)
return orc_target_get_flag_name(orc_target_get_default(),
log2(target));
#else
return NULL;
#endif
}
/**
* vips_vector_disable_targets:
* @disabled_targets: A bitfield of targets to disable at runtime.
*
* Takes a bitfield of targets to disable on the runtime platform.
* Handy for testing and benchmarking purposes.
*
* This can also be set using the `VIPS_VECTOR` environment variable.
*/
void
vips_vector_disable_targets(gint64 disabled_targets)
{
#ifdef HAVE_HWY
hwy::SetSupportedTargetsForTest(
vips_vector_get_supported_targets() & ~disabled_targets);
#endif
}
|