From patchwork Mon Nov 24 18:05:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Senkevich X-Patchwork-Id: 414053 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 7BEA01400DE for ; Tue, 25 Nov 2014 05:05:46 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; q=dns; s=default; b=jhM8 cClB9hhvyqnsLqIDqSsePQuV0E4b3P+7Qyf5NYQHI8ra0SW5ucnm0jk9rxvT4vid GaFOo8RSC4CJ1t75B7cgAsaK2v46Ite6b+gjMImSFS+V+6fYqdY4ODKfgB+eLeYg UqWcmoSLrhaoGYPDB08oe//B9O1oOym+J6X5vdA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; s=default; bh=NKCkGPmLn/ KcdXc+VV3sQUp6xic=; b=gMeiKoJ5CbPPZOD6HC2eTshYJCLtOarV9ljcA7Y5ux WlicSzXZr0UVyVSz39RlXs5z9FmhpxoEk/CDu3ooedw56rnx+dgT38ubrH46HyY1 JiTVoyBsaYuyrKVfcU5nX3lf6Gm/HBdaZ6vyf58RXks9ZejWUZ9A9oIszGl1odsc c= Received: (qmail 1994 invoked by alias); 24 Nov 2014 18:05:39 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 1984 invoked by uid 89); 24 Nov 2014 18:05:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-la0-f48.google.com X-Received: by 10.112.52.73 with SMTP id r9mr9538465lbo.15.1416852333396; Mon, 24 Nov 2014 10:05:33 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: From: Andrew Senkevich Date: Mon, 24 Nov 2014 21:05:02 +0300 Message-ID: Subject: Re: [PATCH 2/N] [x86_64] Vectorized math functions To: Joseph Myers Cc: libc-alpha 2014-11-21 20:55 GMT+03:00 Joseph Myers : > On Thu, 20 Nov 2014, Andrew Senkevich wrote: > >> +#ifndef TEST_MATHVEC >> +# define TEST_MATHVEC 0 >> +#endif > > Making this value explicit in each relevant test would better accord with > current glibc practice. > >> +#ifndef INIT_ARCH_EXT >> +# define INIT_ARCH_EXT >> +# define CHECK_ARCH_EXT >> +#endif > > Again it's worth considering how to avoid this pattern. Maybe a separate > math-tests-arch.h header, with the sysdeps/generic version having a > comment explaining the semantics of the macros and defining them to empty > (and the x86_64 version including the generic one when not doing vector > tests)? > >> +#ifndef VEC_PREFIX >> +# define VEC_PREFIX >> +#endif > > So far we have two ways of distinguishing (in libm-test-ulps) tests for > variants of functions: suffixes (for rounding modes) and type names such > as "double" and "ildoubl" (for the type and for whether the inline > variants are being tested). I don't think adding a third way is a good > idea. I suggest using suffixes (until we can unify things and get down to > a single way). > >> +# define INIT_ARCH_EXT \ >> + __init_cpu_features (); \ >> + avx2_usable = __cpu_features.feature[index_AVX2_Usable] \ >> + & bit_AVX2_Usable; >> + >> +# define CHECK_ARCH_EXT \ >> + if (!avx2_usable) return; > > Any macro expanding to statements should expand to a > > do > { > ...; > } > while (0) > > block unless what it does (e.g. declaring variables to be used outside its > own expansion) is unsuitable for such a block. Fixed. --- WBR, Andrew diff --git a/math/libm-test.inc b/math/libm-test.inc index 5d2ed1a..4958385 100644 --- a/math/libm-test.inc +++ b/math/libm-test.inc @@ -126,6 +126,7 @@ #include #include #include +#include /* Structure for ulp data for a function, or the real or imaginary part of a function. */ @@ -684,7 +685,7 @@ static void test_single_errno (const char *test_name, int errno_value, int expected_value, const char *expected_name) { -#ifndef TEST_INLINE +#if !defined TEST_INLINE && !TEST_MATHVEC if (errno_value == expected_value) { if (print_screen (1)) @@ -1690,9 +1691,18 @@ struct test_fFF_11_data (ARRAY)[i].RM_##ROUNDING_MODE.extra2_expected); \ ROUND_RESTORE_ ## ROUNDING_MODE +#if !TEST_MATHVEC +# define VEC_SUFF +#endif + +#define STR_CONCAT(a, b, c) __STRING (a##b##c) +#define STR_CON3(a, b, c) STR_CONCAT (a, b, c) + /* Start and end the tests for a given function. */ -#define START(FUNC, EXACT) \ - const char *this_func = #FUNC; \ +#define START(FUNC, SUFF, EXACT) \ + CHECK_ARCH_EXT \ + if (TEST_MATHVEC) return; \ + const char *this_func = STR_CON3 (FUNC, SUFF, VEC_SUFF); \ init_max_error (this_func, EXACT) #define END \ print_max_error (this_func) @@ -1705,28 +1715,28 @@ struct test_fFF_11_data { \ do \ { \ - START (FUNC, EXACT); \ + START (FUNC,, EXACT); \ LOOP_MACRO (FUNC, ARRAY, , ## __VA_ARGS__); \ END_MACRO; \ } \ while (0); \ do \ { \ - START (FUNC ## _downward, EXACT); \ + START (FUNC, _downward, EXACT); \ LOOP_MACRO (FUNC, ARRAY, FE_DOWNWARD, ## __VA_ARGS__); \ END_MACRO; \ } \ while (0); \ do \ { \ - START (FUNC ## _towardzero, EXACT); \ + START (FUNC, _towardzero, EXACT); \ LOOP_MACRO (FUNC, ARRAY, FE_TOWARDZERO, ## __VA_ARGS__); \ END_MACRO; \ } \ while (0); \ do \ { \ - START (FUNC ## _upward, EXACT); \ + START (FUNC, _upward, EXACT); \ LOOP_MACRO (FUNC, ARRAY, FE_UPWARD, ## __VA_ARGS__); \ END_MACRO; \ } \ @@ -6034,7 +6044,7 @@ static const struct test_c_c_data cexp_test_data[] = static void cexp_test (void) { - START (cexp, 0); + START (cexp,, 0); RUN_TEST_LOOP_c_c (cexp, cexp_test_data, ); END_COMPLEX; } @@ -7548,7 +7558,7 @@ static const struct test_if_f_data jn_test_data[] = static void jn_test (void) { - START (jn, 0); + START (jn,, 0); RUN_TEST_LOOP_if_f (jn, jn_test_data, ); END; } @@ -9374,7 +9384,7 @@ static const struct test_f_f_data tgamma_test_data[] = static void tgamma_test (void) { - START (tgamma, 0); + START (tgamma,, 0); RUN_TEST_LOOP_f_f (tgamma, tgamma_test_data, ); END; } diff --git a/math/test-double.c b/math/test-double.c index e666197..4aec418 100644 --- a/math/test-double.c +++ b/math/test-double.c @@ -26,6 +26,7 @@ #define PRINTF_XEXPR "a" #define PRINTF_NEXPR "f" #define TEST_DOUBLE 1 +#define TEST_MATHVEC 0 #ifndef __NO_MATH_INLINES # define __NO_MATH_INLINES diff --git a/math/test-float.c b/math/test-float.c index cb68a5c..f646f98 100644 --- a/math/test-float.c +++ b/math/test-float.c @@ -26,6 +26,7 @@ #define PRINTF_XEXPR "a" #define PRINTF_NEXPR "f" #define TEST_FLOAT 1 +#define TEST_MATHVEC 0 #ifndef __NO_MATH_INLINES # define __NO_MATH_INLINES diff --git a/math/test-idouble.c b/math/test-idouble.c index 665f78c..9131055 100644 --- a/math/test-idouble.c +++ b/math/test-idouble.c @@ -26,6 +26,7 @@ #define PRINTF_XEXPR "a" #define PRINTF_NEXPR "f" #define TEST_DOUBLE 1 +#define TEST_MATHVEC 0 #define TEST_INLINE #ifdef __NO_MATH_INLINES diff --git a/math/test-ifloat.c b/math/test-ifloat.c index 41255e9..61a5684 100644 --- a/math/test-ifloat.c +++ b/math/test-ifloat.c @@ -26,6 +26,7 @@ #define PRINTF_XEXPR "a" #define PRINTF_NEXPR "f" #define TEST_FLOAT 1 +#define TEST_MATHVEC 0 #define TEST_INLINE 1 #ifdef __NO_MATH_INLINES diff --git a/math/test-ildoubl.c b/math/test-ildoubl.c index 69ad35e..b8f57a7 100644 --- a/math/test-ildoubl.c +++ b/math/test-ildoubl.c @@ -27,6 +27,7 @@ #define PRINTF_NEXPR "Lf" #define TEST_INLINE #define TEST_LDOUBLE 1 +#define TEST_MATHVEC 0 #ifdef __NO_MATH_INLINES # undef __NO_MATH_INLINES diff --git a/math/test-ldouble.c b/math/test-ldouble.c index 07e4601..4253043 100644 --- a/math/test-ldouble.c +++ b/math/test-ldouble.c @@ -26,6 +26,7 @@ #define PRINTF_XEXPR "La" #define PRINTF_NEXPR "Lf" #define TEST_LDOUBLE 1 +#define TEST_MATHVEC 0 #ifndef __NO_MATH_INLINES # define __NO_MATH_INLINES diff --git a/sysdeps/generic/math-tests-arch.h b/sysdeps/generic/math-tests-arch.h new file mode 100644 index 0000000..c005fad --- /dev/null +++ b/sysdeps/generic/math-tests-arch.h @@ -0,0 +1,21 @@ +/* Runtime architecture check for math tests. + Copyright (C) 2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library 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.1 of the License, or (at your option) any later version. + + The GNU C Library 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 the GNU C Library; if not, see + . */ + +/* Macros used for architecture check in math tests runtime. */ +#define INIT_ARCH_EXT +#define CHECK_ARCH_EXT diff --git a/sysdeps/x86_64/fpu/math-tests-arch.h b/sysdeps/x86_64/fpu/math-tests-arch.h new file mode 100644 index 0000000..dfd8221 --- /dev/null +++ b/sysdeps/x86_64/fpu/math-tests-arch.h @@ -0,0 +1,43 @@ +/* Runtime architecture check for math tests. x86_64 version. + Copyright (C) 2013-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library 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.1 of the License, or (at your option) any later version. + + The GNU C Library 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 the GNU C Library; if not, see + . */ + +#ifdef REQUIRE_AVX2 +# include + + /* Set to 1 if AVX2 supported. */ + static int avx2_usable; + +# define INIT_ARCH_EXT \ + do \ + { \ + __init_cpu_features (); \ + avx2_usable = __cpu_features.feature[index_AVX2_Usable] \ + & bit_AVX2_Usable; \ + } \ + while(0); + +# define CHECK_ARCH_EXT \ + do \ + { \ + if (!avx2_usable) return; \ + } \ + while(0); + +#else +# include +#endif