From 6201277441db4023b833e6d643de8077fe38ed6e Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Sat, 25 Jun 2022 15:06:43 +0200 Subject: d: Add `@simd` and `@simd_clones` attributes to compiler and library The `@simd` attribute is equivalent to `__attribute__((simd))`, and `@simd_clones` is a convenience alias to allow specifying whether the compiler should generated masked or non-masked simd clones. gcc/d/ChangeLog: * d-attribs.cc (handle_omp_declare_simd_attribute): New function. (d_handle_simd_attribute): New function. (d_langhook_common_attribute_table): Add 'omp declare simd' attribute. (d_langhook_attribute_table): Add simd attribute. libphobos/ChangeLog: * libdruntime/gcc/attributes.d (simd): Define. gcc/testsuite/ChangeLog: * gdc.dg/attr_simd1.d: New test. * gdc.dg/attr_simd2.d: New test. --- libphobos/libdruntime/gcc/attributes.d | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'libphobos') diff --git a/libphobos/libdruntime/gcc/attributes.d b/libphobos/libdruntime/gcc/attributes.d index 40a18bf..9d7f2e1 100644 --- a/libphobos/libdruntime/gcc/attributes.d +++ b/libphobos/libdruntime/gcc/attributes.d @@ -372,6 +372,46 @@ auto section(A...)(A arguments) } /** + * The `@simd` attribute enables creation of one or more function versions that + * can process multiple arguments using SIMD instructions from a single + * invocation. Specifying this attribute allows compiler to assume that such + * versions are available at link time (provided in the same or another module). + * Generated versions are target-dependent and described in the corresponding + * Vector ABI document. For x86_64 target this document can be found here. + * https://sourceware.org/glibc/wiki/libmvec?action=AttachFile&do=view&target=VectorABI.txt + * + * The `@simd_clones` attribute is the same as `@simd`, but also includes a + * `mask` argument. Valid masks values are `notinbranch` or `inbranch`, and + * instructs the compiler to generate non-masked or masked clones + * correspondingly. + * + * Example: + * --- + * import gcc.attributes; + * + * @simd double sqrt(double x); + * @simd("notinbranch") double atan2(double y, double x); + * --- + */ +enum simd = attribute("simd"); + +auto simd_clones(string mask) +{ + if (mask == "notinbranch" || mask == "inbranch") + return attribute("simd", mask); + else + { + assert(false, "unrecognized parameter `" ~ mask + ~ "` for `gcc.attribute.simd_clones`"); + } +} + +auto simd_clones(A...)(A arguments) +{ + assert(false, "simd_clones attribute argument not a string constant"); +} + +/** * The `@symver` attribute creates a symbol version on ELF targets. The syntax * of the string parameter is `name@nodename`. The `name` part of the parameter * is the actual name of the symbol by which it will be externally referenced. -- cgit v1.1