It's free to join Gamasutra!|Have a question? Want to know who runs this site? Here you go.|Targeting the game development market with your product or service? Get info on advertising here.||For altering your contact information or changing email subscription preferences.
Registered members can log in here.Back to the home page.

Search articles, jobs, buyers guide, and more.

by Haim Barad
Gamasutra
January 31, 2000

Printer Friendly Version

Letters to the Editor:
Write a letter
View all letters


Features

Optimizations Corner: An Optimized Matrix Library in C++

Contents

Introduction

The Library

Examples

Last month we discussed microarchitectural "snags" that can slow down your code. This month, we're going to get back on the fast track and show you a set of optimized matrix routines. As you know, SIMD architectural enhancements done to recent microprocessors (MMX™ Technology and Streaming SIMD Extensions) are a perfect fit for matrix and vector operations. This month, Zvi Devir (a student member of my team studying Math and CS at The Technion in Haifa, Israel) will explain and present a matrix library for 3D graphics fully optimized for the Pentium® III processor. The library was written mostly in C++ and compiled with the Intel C++ compiler. The full sources are made completely available.

Introduction

This article is about one of the most common elements in 3D graphics:3D transformation matrices and vectors. As we all know, 3D graphics uses [x,y,z] or [x,y,z,w] vectors to represent points in the three-dimensional space or in the homogeneous space, respectively. You can manipulate these vectors by multiplying them with 4x4 transformation matrices. The standard manipulation matrices are translation, rotation and scaling.

For example, to rotate a vector by 90° around the X axis and then move it 20 units toward the positive infinity of the Y axis, create a rotation matrix and a translation matrix, and multiply the vector with both of them. It is simpler and faster to multiply both the matrices in advance. Later, you can multiply the vector with the product when needed.

However, standard multiplication of one matrix by another takes 64 products and 48 sums. A standard multiplication of a vector by a matrix takes 16 products and 12 sums.

This article presents a better way to manipulate vectors and matrices using Intel’s Streaming SIMD Extensions, to enable the calculation of 4 products or 4 additions at once. The SIMD register can hold 4 floating-point numbers with single precision. Hence one register can hold a full vector, and four registers can hold a full 4x4 matrix.

________________________________________________________

The Library


join | contact us | advertise | write | my profile
news | features | companies | jobs | resumes | education | product guide | projects | store



Copyright © 2003 CMP Media LLC

privacy policy
| terms of service