Affix
view release on metacpan or search on metacpan
t/010_simd.t view on Meta::CPAN
use v5.40;
use lib '../lib', 'lib';
use blib;
use Test2::Tools::Affix qw[:all];
use Affix qw[:all];
use Config;
#
$|++;
#
my $c_source = <<'END_C';
#include "std.h"
//ext: .c
#include <stdio.h>
#include <stdint.h>
/* SIMD Vectors */
/* GCC/Clang vector extensions */
#if defined(__GNUC__) || defined(__clang__)
typedef float v4f __attribute__((vector_size(16)));
typedef double v2d __attribute__((vector_size(16)));
typedef int v4i __attribute__((vector_size(16)));
DLLEXPORT int has_vector() { return 1; }
DLLEXPORT v4f add_v4f(v4f a, v4f b) {
return a + b;
}
DLLEXPORT v2d add_v2d(v2d a, v2d b) {
return a + b;
}
DLLEXPORT v4i add_v4i(v4i a, v4i b) {
return a + b;
}
#else
DLLEXPORT int has_vector() { return 0; }
#endif
/* Long Double */
DLLEXPORT long double add_ld(long double a, long double b) {
return a + b;
}
DLLEXPORT double ld_to_d(long double a) {
return (double)a;
}
END_C
# Compile the library
my $lib = compile_ok($c_source);
my $check = wrap( $lib, 'has_vector', [] => Int );
if ( !$check->() ) {
skip_all "Compiler does not support vector extensions";
}
subtest 'Vector[4, Float]' => sub {
# Bind: v4f add_v4f(v4f a, v4f b);
isa_ok my $add = wrap( $lib, 'add_v4f', [ Vector [ 4, Float ], Vector [ 4, Float ] ] => Vector [ 4, Float ] ), ['Affix'];
# Pass as Packed String (Fast Path)
( run in 1.703 second using v1.01-cache-2.11-cpan-39bf76dae61 )