Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Общие вопросы > Порт на msvc


Автор: C4Grey 28.3.2008, 00:35
Салют, Homo Programaticus!
Сразу перехожу к проблеме:

Код

#ifndef VEC3_H_INCLUDED 
#define VEC3_H_INCLUDED 

#include <xmmintrin.h> 
#include "platform.h" 

namespace ogldemo { 

#ifdef __GNUC__ 

    typedef __m128 float4_t; 

    class vec3_t { 

        float4_t xmm; 

    public: 

        ALWAYS_INLINE vec3_t() {} 

        ALWAYS_INLINE vec3_t(float4_t v) : xmm(v) {} 

        ALWAYS_INLINE vec3_t(float x, float y, float z, float w) : xmm((float4_t){x,y,z,w}) {} 

        // 
        // 
        // 

        ALWAYS_INLINE vec3_t operator+ (const vec3_t& b) { 
            return xmm + b.xmm; 
        } 

        ALWAYS_INLINE vec3_t operator* (const vec3_t& b) { 
            return xmm * b.xmm; 
        } 

        // 
        // 
        // 

        ALWAYS_INLINE float x() const { 
            return Component(1); 
        } 

        ALWAYS_INLINE float y() const { 
            return Component(2); 
        } 

        ALWAYS_INLINE float z() const { 
            return Component(3); 
        } 

        ALWAYS_INLINE float w() const { 
            return Component(4); 
        } 

        // 
        // 
        // 

        ALWAYS_INLINE float& x() { 
            return Component(1); 
        } 

        ALWAYS_INLINE float& y() { 
            return Component(2); 
        } 

        ALWAYS_INLINE float& z() { 
            return Component(3); 
        } 

        ALWAYS_INLINE float& w() { 
            return Component(4); 
        } 

    protected: 

        ALWAYS_INLINE float Component(int idx) const { 
            return *((float*)(&xmm) + (idx - 1)); 
        } 

        ALWAYS_INLINE float& Component(int idx) { 
            return *((float*)(&xmm) + (idx - 1)); 
        } 
    }; 

#elif __MSVC__ 

#endif 
} 

#endif // VEC3_H_INCLUDED 


Вот такой код есть...Возникла необходимость просто портировать его на msvc, итог:

Код

#ifndef VEC3_H_INCLUDED 
#define VEC3_H_INCLUDED 

#include <xmmintrin.h> 
//#include "platform.h" 

namespace ogldemo { 

//#ifdef __GNUC__ 

    typedef __m128 float4_t; 

    class vec3_t { 

       float4_t xmm; 

    public: vec3_t() {};
               vec3_t(float4_t v) : xmm(v) {};
               vec3_t(float x, float y, float z, float w) : xmm((float4_t){x,y,z,w}) {};
        // 
        // 
        // 

        vec3_t operator+ (const vec3_t& b) { 
            return xmm + b.xmm; 
        } 

        vec3_t operator* (const vec3_t& b) { 
            return xmm * b.xmm; 
        } 

        // 
        // 
        // 

       float x() const { 
            return Component(1); 
        } 

        float y() const { 
            return Component(2); 
        } 

        float z() const { 
            return Component(3); 
        } 

        float w() const { 
            return Component(4); 
        } 

        // 
        // 
        // 

        float& x() { 
            return Component(1); 
        } 

        float& y() { 
            return Component(2); 
        } 

        float& z() { 
            return Component(3); 
        } 

        float& w() { 
            return Component(4); 
        } 

    protected: 

        float Component(int idx) const { 
            return *((float*)(&xmm) + (idx - 1)); 
        } 

        float& Component(int idx) { 
            return *((float*)(&xmm) + (idx - 1)); 
        } 
    }; 
//#elif __MSVC__ 

//#endif 
} 

#endif // VEC3_H_INCLUDED 


В строчке 
vec3_t(float x, float y, float z, float w) : xmm((float4_t){x,y,z,w}) {};
Вдает кучу ошибок:

Error    1    error C2958: the left parenthesis '(' found at 'd:\kvaz studio\visual studio 2008\projects\vect_3\vect_3\vect_c.cpp(19)' was not matched correctly
Error    2    error C2059: syntax error : ')'    
Error    3    error C2059: syntax error : '{'    
Error    4    error C2334: unexpected token(s) preceding '{'; skipping apparent function body
Error    5    error C2143: syntax error : missing ')' before '{'
Error    6    error C2059: syntax error : ')'    
Error    7    error C2143: syntax error : missing ';' before '}'

и в
Код

vec3_t operator+ (const vec3_t& b) { 
            return xmm + b.xmm; 
        } 


конкретно
return xmm + b.xmm; 
Ошибка:
Error    8    error C2676: binary '+' : 'ogldemo::float4_t' does not define this operator or a conversion to a type acceptable to the predefined operator    
то же самое и для второго оператора...
Использую Microsoft Visual Studio 2008.
Поправте, пожалуйста... smile 

Автор: korian 28.3.2008, 07:20
((float4_t){x,y,z,w}) - интересная конструкция... она легальна в C++?

vec3_t(float x, float y, float z, float w) : xmm((float4_t){x,y,z,w}) {};
vec3_t(float x, float y, float z, float w) { Component(1) = x; Component(2) = y; Component(3) = z; Component(4) = w; }

а по второму хз, ну нету оператора + для типа float4_t...

Автор: C4Grey 28.3.2008, 20:45
korian, спасибо. А по поводу оператора, ладно, буду использовать тогда
return _mm_add_ps, return _mm_mul_ps.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)