2 Stimmen

Wie überladet man Funktionen, deren Argumente sich nur durch das gcc- Vektor-Erweiterungs-Vector_Size-Attribut unterscheiden?

Ich versuche, einige gängige Hilfsfunktionen zu schreiben, wie z.B. die Addition aller Elemente in einem gcc-Vektor.

inline float add_all(float const in __attribute__((vector_size(8))))
{
  return in[0] + in[1];
}

inline float add_all(float const in __attribute__((vector_size(16))))
{
  return in[0] + in[1] + in[2] + in[3];
}

inline double add_all(double const in __attribute__((vector_size(16))))
{
  return in[0] + in[1];
}

inline double add_all(double const in __attribute__((vector_size(32))))
{
  return in[0] + in[1] + in[2] + in[3];
}

Allerdings meldet gcc beim Kompilieren:

In file included from matrix.hpp:5:0,
                 from matrix.cpp:3:
vector.hpp:22:1: Fehler: 'float vxl::add_all(__vector(4) float)' steht im Widerspruch zu einer früheren Deklaration
 }
 ^
vector.hpp:14:14: Hinweis: frühere Deklaration 'float vxl::add_all(__vector(2) float)'
 inline float add_all(float const in __attribute__((vector_size(8))))
              ^
vector.hpp:19:14: Hinweis: -fabi-version=6 (or =0) vermeidet diesen Fehler mit einer Änderung im Mangeln
 inline float add_all(float const in __attribute__((vector_size(16))))
              ^
vector.hpp:32:1: Fehler: 'double vxl::add_all(__vector(4) double)' steht im Widerspruch zu einer früheren Deklaration
 }
 ^
vector.hpp:24:15: Hinweis: frühere Deklaration 'double vxl::add_all(__vector(2) double)'
 inline double add_all(double const in __attribute__((vector_size(16))))
               ^
vector.hpp:29:15: Hinweis: -fabi-version=6 (or =0) vermeidet diesen Fehler mit einer Änderung im Mangeln
 inline double add_all(double const in __attribute__((vector_size(32))))

Gibt es eine Lösung, außer der von gcc vorgeschlagenen?

4voto

Ross Ridge Punkte 37449

Bieten Sie ein zusätzliches Standardargument an, das den Funktionen einen anderen verunstalteten Namen gibt:

typedef float __attribute__((vector_size(8))) vector_f8;
typedef float __attribute__((vector_size(16))) vector_f16;
typedef double __attribute__((vector_size(16))) vector_d16;
typedef double __attribute__((vector_size(32))) vector_d32;

template 
struct vector_len {
    static int const len = _len;
};

float
add_all(vector_f8 in, vector_len<8> *_p = NULL) {
    return in[0] + in[1];
}

float
add_all(vector_f16 in, vector_len<16> *_p = NULL) {
    return in[0] + in[1] + in[2] + in[3];
}

float
add_all(vector_d16 in, vector_len<16> *_p = NULL) {
    return in[0] + in[1];
}

float
add_all(vector_d32 in, vector_len<32> *_p = NULL) {
    return in[0] + in[1] + in[2] + in[3];
}

CodeJaeger.com

CodeJaeger ist eine Gemeinschaft für Programmierer, die täglich Hilfe erhalten..
Wir haben viele Inhalte, und Sie können auch Ihre eigenen Fragen stellen oder die Fragen anderer Leute lösen.

Powered by:

X