Git Product home page Git Product logo

sce_vectormath's Introduction

	Vector math library


* Overview

  The Vector math library provides 3-D/4-D vector operations including
  addition, outer product, multiply by a matrix, quaternion etc.


* License

  This library is licensed under the terms in the file 'LICENSE' in
  this directory. (BSD license)

* Usage

  See the documents `doc/*.pdf'.

  No shared library, static library nor executable is installed,
  because all functions in this library are provided as inline
  functions. Copy the appropriate header files into your project.

* Contacting the project

  Module maintainer: Erwin Coumans

  Feedback and patches:
    http://www.bulletphysics.com/Bullet/phpBB2/viewforum.php?f=18
	
  Main repository URL:
	https://github.com/erwincoumans/sce_vectormath
	(moved from http://bullet.googlecode.com/svn/trunk/Extras/vectormathlibrary)

* Example usage:

	See physics effects sample code in https://github.com/erwincoumans/bullet3

---
EOF

sce_vectormath's People

Contributors

erwincoumans avatar yotis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

sce_vectormath's Issues

narrowing conversion warnings

When compiling with -std=c++0x in gcc-4.7.1 I get these warnings:
warning: narrowing conversion of '2147483648u' from 'unsigned int' to 'const int' inside { }

strict alignment optimization warnings

When using the last commit (6c3d81e) on linux x86_64 (gcc-4.3.3), there are warnings about strict aliasing optimization
warning: dereferencing type-punned pointer will break strict-aliasing rules

The warnings are emitted from the following files
include/vectormath/SSE/cpp/boolInVec.h ()
include/vectormath/SSE/cpp/vectormath_aos.h

There are hints in the code about using unions for passing values.
The following patch uses unions and fixes those warnings. Also checked assembly code and there are no more instructions generated (gcc-4.3.3, x86_64).

diff --git a/include/vectormath/SSE/cpp/boolInVec.h b/include/vectormath/SSE/cpp/boolInVec.h
index a11f72a..5cb224b 100644
--- a/include/vectormath/SSE/cpp/boolInVec.h
+++ b/include/vectormath/SSE/cpp/boolInVec.h
@@ -135,11 +135,21 @@ boolInVec::boolInVec(const floatInVec &vec)
     *this = (vec != floatInVec(0.0f));
 }

+union boolInVec_converter
+{
+    __m128 m128;
+    bool b;
+    float f;
+    int i;
+    boolInVec_converter(int i) : i(i) {}
+    boolInVec_converter(__m128 m128) : m128(m128) {}
+    boolInVec_converter() {}
+};
+
 inline
 boolInVec::boolInVec(bool scalar)
 {
-    unsigned int mask = -(int)scalar;
-   mData = _mm_set1_ps(*(float *)&mask); // TODO: Union
+    mData = _mm_set1_ps(boolInVec_converter(-(int)scalar).f);
 }

 #ifdef _VECTORMATH_NO_SCALAR_CAST
@@ -151,7 +161,7 @@ inline
 boolInVec::operator bool() const
 #endif
 {
-   return *(bool *)&mData;
+    return boolInVec_converter(mData).b;
 }

 inline
diff --git a/include/vectormath/SSE/cpp/vectormath_aos.h b/include/vectormath/SSE/cpp/vectormath_aos.h
index 60d5949..41a8624 100644
--- a/include/vectormath/SSE/cpp/vectormath_aos.h
+++ b/include/vectormath/SSE/cpp/vectormath_aos.h
@@ -95,6 +95,15 @@ union SSEFloat
    SSEFloat() {}//uninitialized
 };

+union scalar_converter
+{
+    unsigned int ui;
+    float f;
+    scalar_converter(unsigned int ui) : ui(ui) {}
+    scalar_converter(float f) : f(f) {}
+    scalar_converter() {}
+};
+
 static VECTORMATH_FORCE_INLINE __m128 vec_sel(__m128 a, __m128 b, __m128 mask)
 {
    return _mm_or_ps(_mm_and_ps(mask, b), _mm_andnot_ps(mask, a));
@@ -105,12 +114,12 @@ static VECTORMATH_FORCE_INLINE __m128 vec_sel(__m128 a, __m128 b, const unsigned
 }
 static VECTORMATH_FORCE_INLINE __m128 vec_sel(__m128 a, __m128 b, unsigned int _mask)
 {
-   return vec_sel(a, b, _mm_set1_ps(*(float *)&_mask));
+        return vec_sel(a, b, _mm_set1_ps(scalar_converter(_mask).f));
 }

 static VECTORMATH_FORCE_INLINE __m128 toM128(unsigned int x)
 {
-    return _mm_set1_ps( *(float *)&x );
+    return _mm_set1_ps(scalar_converter(x).f);
 }

 static VECTORMATH_FORCE_INLINE __m128 fabsf4(__m128 x)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.