Proposition for SDL_math

Not even that different at all times, actually; many games that would be
cathegorized as 2D when considering the rendering subsystem still use proper
3D calcutations internally.

//David

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------> http://www.linuxaudiodev.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |--------------------------------------> david at linuxdj.com -'On Thursday 29 March 2001 02:54, Jared Maguire wrote:

The C/C++ argument is silly, do the core math routines in C, with c++
wrapper classes and everyone’s happy. And the 2d/3d argument is somewhat
silly, too – 2d math is 3d math with z=0.

…but you occasionally use maths for other things than 3D, right…? :wink:

//David

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------> http://www.linuxaudiodev.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |--------------------------------------> david at linuxdj.com -'On Thursday 29 March 2001 00:42, Marco Iannaccone wrote:

Also, I think it should be a general graphical math lib… and not focus
entirely upon OpenGL & 3D graphics (I realize you weren’t necessarily

proposing

it be only 3D math functions, I was just stating a preference :wink:

Agree on everything, except this. I think it should be focused on OpenGL,
that’s the “official” SDL 3D API…

The trick is to design around array operations.

Ok. I have no idea what you are talking about, though. :slight_smile:

It’s basically how the average audio or image processing plugin API works. A
simple example:

void SomeLib_multiply(float *array1, float *array2, int size);

—8<------------------------------------------------------------------
void SomeLib_multiply(float *array1, float *array2, int size)
{
int i;
for(i = 0; i < size; ++i)
array1[i] *= array2[i];
}

or in C++ (which is much nicer in this case):

class SomeLib_array_t
{
	float *data;
	int size;
  public:
	<various nice interface methods>
	SomeLib_array_t operator*(SomeLib_array_t a2);
};

—8<------------------------------------------------------------------
SomeLib_array_t SomeLib_array_t::operator*(SomeLib_array_t a2)
{
for(int i = 0; i < size; ++i)
data[i] *= a2.data[i];
return *this;
}

IMHO, sometimes too much encapsulation is a bad thing. A simple API
lets the programmer do the programming, and less time reading docs…

Right, but I don’t see how this applies to a high speed math library… I
mean, it has to be array based for performance and SIMD acceleration
support, and the API has to be rather simple to minimize overhead.

Any API that takes too much time to learn in relation to the benefits is
very likely poorly designed, or just the wrong tool for your project.

Or the people designing it just got carried away, which tends to be one of
the biggest problems with C++ fanatics. I know where he’s coming from on
this. Simplicity would definately be the better choice for this library
(or any library really).

Exactly.

I mean,
even if it takes the guy twice as long to do it himself then to figure
out the docs, its worth it in my opinion.

That won’t work if you have to code for a living. The priority is getting
the product out in time - all other things are secondary, and can be
sacrificed to meet the deadline, even if that means that lots of code
will have to be thrown away and rewritten for the next release…

That depends on where you work.

Yeah. I should be looking for another job, I guess… heh

A lot of places use this philosophy, which
unfortunately is very detrimental in the long term. A much better model is
that making sure the product works at all should be the 1st priority, and
getting it out on time secondary, with everyone else below that.

I’m pulling in that direction as much as possible despite the situation, and
it really does pay in the long run to spend some extra time cleaning code up
while I’m hacking around in it anyway. By just reading through the code, I’ve
found several “potential” bugs creeping around, waiting to strike.

Don’t
believe that’s a good model? Just look at how everyone hates all the
bugginess of microsoft products.

OTOH, look at the story of MS as a company WRT growth and profit. I wouldn’t
exactly consider their model useless from that POV…

Selling crap today works better than selling the perfect solution tomorrow,
in the real world. Sad but true.

It’s causing a lot of people to switch to
Linux as a result.

Yeah, I’m one of them. (Although there are a few other reasons as well, a
desperate need for solid hard real time solutions being one of them. I
actually started out with RTLinux rather than “pure” Linux, and developed a
serious Linux addiction from there. :slight_smile:

Anyway, this is getting offtopic.

Is that unusual, or something…? :wink:

Why are you assuming that “API” is synonymous to various crap from MS?
There is a big difference between “must get all of this in before the
deadline” style APIs and properly designed stuff. It doesn’t have to be
nasty just because it’s called “API”! :wink:

That’s not really the issue I don’t think. It’s the people driving the
API. Some of the worst APIs are designed by people who take all the time
they need to to “design it right”, and end up throwing everything but the
kitchen sink into it. They want to make it very robust and flexible, but
the problem is they make it too complicated as well.

Right; solve the problem, and anything that’s a logical consequence of the
API you design for that (or someone will end up wondering why seemingly legal
constructs break), but don’t strap “nice” bonuses onto that.

Also, count on throwing everything away and starting over once or twice per
project. That’s about the only way to get anything but the most trivial
things totally right.

The 2 reasons I like
SDL is because it allows me to do the things I want to do, and because it
is easy to use.

Same here; I’m probably even using SDL for things it’s not really meant for,
just because I know my ways around it, it’s robust, nice and fast etc. :slight_smile:

I think API design is an art form really, and while anyone
can do it, few can really master it.

Yep. (Remains to see which group I belong to when MAIA is released… :wink:

//David

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------> http://www.linuxaudiodev.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |--------------------------------------> david at linuxdj.com -'On Thursday 29 March 2001 02:08, Jason Hoffoss wrote:

On Wednesday 28 March 2001 11:06, you wrote:

AFAIK there is no such thing as C++ library. There are
linking problems with C++ mangled symbols, which are
far from standard. I would imagine that it would be
possible to make something that could be called 'a library’
which would put the functionality into the headers.

Surely? Were we can find C math lib as efficient as C++?
If we will have C++ wrapper of C math lib, how fast it will be?
I think it will be the worst of two worlds.

This is true. Making math in C++ is usually much different
than in C. I would make a whole new implementation for C++
instead of writing wrappers for C routines.

But, like I said, there is this C+±library linking thing.
We could write headers, but thats not a real library.

– Timo Suoranta – @Timo_K_Suoranta

Except that for many 2D instances, setting z=0 (or any other constant) still
requires more computation than if the extraneous 3D sections of the algorythm
were simply removed from the equation.

Just because the z=0 eliminates the variable in “real world” computations (pen
& paper) doesn’t mean the variable and extra computation goes away for the
computer!On Fri, 30 Mar 2001, you wrote:

On Thursday 29 March 2001 02:54, Jared Maguire wrote:

The C/C++ argument is silly, do the core math routines in C, with c++
wrapper classes and everyone’s happy. And the 2d/3d argument is somewhat
silly, too – 2d math is 3d math with z=0.

Not even that different at all times, actually; many games that would be
cathegorized as 2D when considering the rendering subsystem still use proper
3D calcutations internally.


Sam “Criswell” Hart <@Sam_Hart> AIM, Yahoo!:
Homepage: < http://www.geekcomix.com/snh/ >
PGP Info: < http://www.geekcomix.com/snh/contact/ >
Advogato: < http://advogato.org/person/criswell/ >

Of course. I’m talking about low level 1D array operations, rather than 3D
and 4D matrix operations. 3D matrix operations isn’t all there is to math
libs, even for 3D. (Well, maybe it is in some 3D maths libs, but then they’re
really a very specialized kind of array based math libs.)

//David

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------> http://www.linuxaudiodev.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |--------------------------------------> david at linuxdj.com -'On Friday 30 March 2001 18:46, Samuel Hart wrote:

On Fri, 30 Mar 2001, you wrote:

On Thursday 29 March 2001 02:54, Jared Maguire wrote:

The C/C++ argument is silly, do the core math routines in C, with c++
wrapper classes and everyone’s happy. And the 2d/3d argument is
somewhat silly, too – 2d math is 3d math with z=0.

Not even that different at all times, actually; many games that would be
cathegorized as 2D when considering the rendering subsystem still use
proper 3D calcutations internally.

Except that for many 2D instances, setting z=0 (or any other constant)
still requires more computation than if the extraneous 3D sections of the
algorythm were simply removed from the equation.

Just because the z=0 eliminates the variable in “real world” computations
(pen & paper) doesn’t mean the variable and extra computation goes away for
the computer!

What math libs are you talking about anyway? Do you even know what your
talking about? What source code have you examined to base your comments off
of? I’ve looked over Wolfenstein, Doom, and a few other (true 3d) engines
and the math fits the algorithms pretty tightly… obviously you never
written an application that umm has to redraw 60 times per second. Its still
about speed, and clever design.

Programming is an exercise of caching, who said that? You use the ANSI C
math library to create all your lookup tables, and you use standard C or C++
operators like ‘*’ or ‘+’ to actually do the math. Sure people write
routines to do matrix operations, or vector calculations, or point in
polygon tests or whatever, but again your missing the big picture – those
routines are specific for the data structure at hand. There are so many ways
to approach a problem a math lib would only get in the way. At least the one
your describing, or think your describing, because your not writing it
anyway. The routines to do math fit closely with the data structure at hand,
it has to be if your writing a software rasterizer. And if your doing
hardware based, then no math library helps with the math because most of
that is handled with OpenGL!! So are you talking about a math library
specifically for the data structures that would be optimal for pairing
OpenGL and a software rasterizer? Of course not, because it has to be
"slashdot" perfection it must work with everything and every approach and be
GNU at the same time! what??

So what are you talking about? Are you talking about writing games, because
that is what SDL is for, at least until or if it has windowing support or a
competely functional GUI. Or are you just talking for the sake of talking?

Why dont we here from the person who actually is going to program it. He
doesn’t need a defense attorney, you might be saying stuff that totally is
opposite of his intentions. Just because people on this list cant keep their
mouth shut.

769 messages in less than a month…grr…

I guess you need some code

;-------------------
;
; xpartialbyystep
;
; multiplies long [ystep] (possibly negative), by word [xpartial] (in BX)
;
; returns dx:ax
; trashes bx,cx,di
;
;-------------------

PROC xpartialbyystep NEAR
;
; setup
;
mov ax,[WORD ystep]
mov cx,[WORD ystep+2]
or cx,cx ; is ystep negatice?
jns @@multpos
;
; multiply negative cx:ax by bx
;
neg cx
neg ax
sbb cx,0

mul bx ; fractionfraction
mov di,dx ; di is low word of result
mov ax,cx ;
mul bx ; units
fraction
add ax,di
adc dx,0

neg dx
neg ax
sbb dx,0
ret
;
; multiply positive cx:ax by bx
;
EVEN
@@multpos:
mul bx ; fractionfraction
mov di,dx ; di is low word of result
mov ax,cx ;
mul bx ; units
fraction
add ax,di
adc dx,0

ret

ENDP

Alright… here is a piece of code from Wolfenstein from (WL_DR_A.asm).
Granted this is old code not updated for 386+ processors here, but i’m
trying to make a point… Notice how he only uses four multiplies to
calculate the initial starting (x, y) position on the grid for vertical
intersection testing? Now, notice what he does here, that the math portion,
the fixed point is highly optimized for the algorithm. Obviously only
Carmack is aware of how the fixed point relates to this. A library wouldn’t
know where the possibilities of overflow could occur… if it (a library)
stored the decimal offset as memory then it would have to reference and
compare it in order to
determine how to shift, or use self-modifying code. Both makes assumptions
that only the person implementing the code should make. In an related
example, if world coordinates of a tile-based world take up 16-bits, or
65536 x 65536, an algorithm must accomodate that. More specifically, you
couldn’t use a 16.16 tangent table and divide a world coordinate by a
tangent entry, because the resulting shift necessary on the world coordinate
would cause an overflow. I’m really rusty on my x86 asm, I promise I’ll try
to give a better explanation in the future.

Anyway, He has to know about the 16.16 fixed point and work around the
limitations.
Heh, not using 32-bit registers back then (circa 1992). You think he’s
resorting to asm because of deadlines? No, obviously the math is used for
speed. And the stuff he is getting is from lookup tables, more specifically
precalculated tangent lookup tables. Stuff that a math library couldnt hope
to do, because lookup tables must be accomodating to algorithms.

And back to modern times… even if it is purely floating point, then there
are other problems… like caching issues (fitting certain portions of code
in L1 cache) . In games, math that needs the optimization is the same
math that is tied in closely with the algorithms used, usually inside
rendering
routines. The ANSI C math library generates great lookup point tables.
Yippe.

I only say all this because you really are annoying me. I’m sure a math
library would be useful for CAD and other stuff, or maybe even for a game. I
gave an opinion and the specific reasons why, for the hope he could overcome
those OR perhaps think about some practical limitations while designing it.
It isnt necessary to argue for the sake of arguing, for this list has
already spirled out of control. Next time when I make a suggestion I will
attach code to specify what i’m trying to say. Perhaps then it will have
more weight, or else make me look more foolish. Whatever :slight_smile:

Matt

Of course. I’m talking about low level 1D array operations, rather than 3D
and 4D matrix operations. 3D matrix operations isn’t all there is to math
libs, even for 3D. (Well, maybe it is in some 3D maths libs, but then
they’re> really a very specialized kind of array based math libs.)

//David

[…]

So what are you talking about? Are you talking about writing games, because
that is what SDL is for, at least until or if it has windowing support or a
competely functional GUI. Or are you just talking for the sake of talking?

I’m talking about doing things they way things are done now, rather than a
few years ago. The levels where you switch from one language or programming
style changes with every processor generation - mainly because the increased
complexity required to do the state-of-the-art tricks becomes too high for
the tools and methods of the last generation.

(But what do I know? I’ve only been hacking for some 16 years or so…)

Either way, you’re right; I’m just wasting my time on mailing lists, when I
should be hacking useful code.

//David

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------> http://www.linuxaudiodev.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |--------------------------------------> david at linuxdj.com -'On Friday 30 March 2001 21:31, Matt Johnson wrote:

What math libs are you talking about anyway? Do you even know what your
talking about?

Actually, it was apparent to me that the person you were responding about does
know what he is talking about.

So what are you talking about? Are you talking about writing games, because
that is what SDL is for,

No, SDL is for “media” applications (Simple Direct-media Layer). It just so
happens to be used primarily for games, but that doesn’t mean it lacks
functionality elsewhere.

Why dont we here from the person who actually is going to program it.

That person asked for comments. This is what they got.

I only say all this because you really are annoying me. I’m sure a math
library would be useful for CAD and other stuff, or maybe even for a game.

I originally responded to the querry because I thought it would be a good idea.
There is an awful lot of math involved in computer science, and
especially multi-media apps… And that math is often difficult to grasp for
the average person.

Thus, encapsulating some of the more tricky graphical algorythms into a
library that is both SDL friendly and cross-platform (but an add-on library,
ala SDL_mixer, et al) seemed like a good idea to me. (As a matter of fact, I
personally would love to bring some of my undergraduate simulations up to date,
http://www.geekcomix.com/snh/bh/ , but I’m feeling too lazy/busy to do
much of the math coding work myself.)

Since it would be an add-on library, no one would be forced to use it. All this
discussion originally was intended for was to determine if there was an
interest (because of the response, obviously there is) and to determine what
some of the needs of the developer audience would be.On Fri, 30 Mar 2001, you wrote:


Sam “Criswell” Hart <@Sam_Hart> AIM, Yahoo!:
Homepage: < http://www.geekcomix.com/snh/ >
PGP Info: < http://www.geekcomix.com/snh/contact/ >
Advogato: < http://advogato.org/person/criswell/ >

So what are you talking about? Are you talking about writing games, because
that is what SDL is for, at least until or if it has windowing support or a
competely functional GUI. Or are you just talking for the sake of talking?

Technically, SDL is designed for more than just games, though that is
probably the primary use people use it for.

And back to modern times… even if it is purely floating point, then there
are other problems… like caching issues (fitting certain portions of code
in L1 cache) . In games, math that needs the optimization is the same
math that is tied in closely with the algorithms used, usually inside
rendering
routines. The ANSI C math library generates great lookup point tables.
Yippe.

I think you are going a little overboard. The importance of assembly has
faded a lot these days. I used to work at a computer game development
company (Volition Inc.), and the only assembly anywhere in the code was a
handful of routines in the graphics library, which I believe was used only to
speed up software 3d rendering. I’m not aware of anyone there ever having
worried about fitting anything in the L1 cache either. Yes, you do have to
do a lot of different tricks to get as much speed as possible out of a
system, but you only need this in a few places really, and generally it’s not
where you expect them.

There’s an old school rule that says you should never optimize until you
can’t put it off any longer. The reason is because working with optimized
code is infiniately harder than unoptimized code. Also, you should normally
do profiling to determine where optimizing needs to be done, rather than
making educated guesses.

For the record, we used a math library at Volition Inc for FreeSpace and
Summoner, and will they will be using it for all future products as well (we
standardized on a foundation library while I was there, which all new
projects are designed around now). Maybe we could have speeded things up a
little more using assembly, L1 cache tricks and not using a math library, but
I guess everyone there was of the option it wasn’t worth it. It only makes
our jobs harder, making deadlines harder to meet, and doesn’t really give us
enough benefit to justify it.

You are quoting the Wolfenstein source code. Well, how many games have you
both started and finished? If you’ve started a lot and worked on them pretty
far, but never quite got them finished, believe me, there’s still a lot you
can learn. The ending phases of game developement have lot of unique aspects
you don’t encounter earlier on in developement. Not to mention, you always
learn more the more games you do. If you having tried just ditching
assembly, L1 cache tricks, etc in favor of doing things the easier way, you
should give it a try on a project sometime, just as a comparison against your
normal routine. See what the advantages and disadvantages are, and then try
and take the best of both worlds in future projects. That’s how you grow as
a programmer.

Another good example I think is fixed-point math. I see people talking about
it on this list a lot. Why? I haven’t bothered using fixed point math since
my 486 days. Is there still some compelling reason for using it that I’m
missing or something? Maybe it’s important for other architectures besides
the x86? As for x86, floats are just a lot better to use than fixed point I
think. My opinion anyway.On Friday 30 March 2001 11:31, you wrote:

In my personal point of view, it would be nice.

The only big doubt is whether a C++ implementation will be developed. I know
that all SDL is C and not C++, but I think that there only a few guys left
out there that still use C math libraries. C++ is just more powerful for
this kind of things, the code is way more readable.
Of course, I would not like to start a big flame about old school boys that
believe that C++ is too slow for overhead against new guys that know well
that C++ can be driven to be even faster than C. This is not the point. The
point is that most people nowadays use C++ at least for math libraries, and
we should not ignore this.

Personally, I’m not going to use any math library that comes in C-only
fashion, and I know the same would apply to a lot of developers.

hrm g. I’d say go for C unless it doesn’t make sense - or provide a C++
layer as well… C++ is -really- hard to extend into CORBA for example
:slight_smile: (the reverse is easy of course). Or make into an extension library for
scripting language…

I’m not looking at this as a language war issue (I use either C or C++
depending on situation - my ever unfinished project is about 50% of each)
but rather an issue of practicality…

I mean one can always write in C++ then provide a C interface as well
(examples: BeOS, SMPEG) or vice versa (gtk+ and gtk-- for example)

… off to the races to see what wall my face will hit next…On Thu, 29 Mar 2001, Giovanni Bajo wrote:

Also, I think it should be a general graphical math lib… and not focus
entirely upon OpenGL & 3D graphics (I realize you weren’t necessarily
proposing
it be only 3D math functions, I was just stating a preference :wink:

Agree on everything, except this. I think it should be focused on OpenGL,
that’s the “official” SDL 3D API…

Och, I don’t see the whole idea as terribly bad - there’s some great math
algorithms in the “graphics gems” series for example that aren’t in opengl

  • or don’t necessarily map to 3D :slight_smile:

3D math that suplements OpenGL is not bad g

but the SDL connection? Aren’t there some algorithms that benefit from
being split off into another thread and/or parallel processed? Those
could be VERY handy to write as SDL’s threading layer’s a wee bit more
friendly than porting it to all platforms…

(I don’t see any reason to replace any of OpenGL’s math - especially now
that some videocards (geforce3) are implementing some of the math
onboard :slight_smile:

…wandering off before sticks foot down throat again…On Wed, 28 Mar 2001, Marco Iannaccone wrote:

this is seriously wandering off now - hrm… Although I do say that the
whole thing has some useful stuff to stick into a FAQ maybe to get people
to quit about this…On Thu, 29 Mar 2001, Alexei Nikitin wrote:

From: “Jared Maguire”

The C/C++ argument is silly, do the core math routines in C, with c++
wrapper classes and everyone’s happy. And the 2d/3d argument is somewhat
silly, too – 2d math is 3d math with z=0.

Surely? Were we can find C math lib as efficient as C++?
If we will have C++ wrapper of C math lib, how fast it will be?
I think it will be the worst of two worlds.

glarg. it’s arguments like this (and of course the “gee everyone uses B
why should we bother with A” (replace B with C++ and A with C… or many
other possiblilities)) that make me veryvery annoyed. Lack of knowledge
maybe?

Folks : if you're GOING to make arguments like this anyways, BACK IT UP! with nice solid provable facts. Argghh. I thought logic was a required subject for anyone who programmed!

Any decent optimizer will clean this up - my experiences with g++ (not the
most optimal of compilers/linkers anymore) suggest it can handle this
fine…

Ach, if you’re this picky just code in assembly. Then you’ll be as fast
as you can be - providing you know how to optimize it for the processor
g… (aside: I once did up a 3D math lib in C++, C, and assembly…
C++ and C were the same speed and I’m sorry to admit it but both were
-slightly- faster than my hand-optimized assembler. I’m not up to
handling the call reshuffling optimizers can do - I don’t know the rules)

…off to kick dead whale down beach again (see hacker’s jargon)…

this is seriously wandering off now - hrm… Although I do say that the
whole thing has some useful stuff to stick into a FAQ maybe to get people
to quit about this…

The C/C++ argument is silly, do the core math routines in C, with c++
wrapper classes and everyone’s happy. And the 2d/3d argument is
somewhat

silly, too – 2d math is 3d math with z=0.

Surely? Were we can find C math lib as efficient as C++?
If we will have C++ wrapper of C math lib, how fast it will be?
I think it will be the worst of two worlds.

glarg. it’s arguments like this (and of course the “gee everyone uses B
why should we bother with A” (replace B with C++ and A with C… or many
other possiblilities)) that make me veryvery annoyed. Lack of knowledge
maybe?

Yes. It’s surely lack of knowledge. First of all lack of knowledge in
English language.
I can not understand approximately a half of the text. “glarg” for example.

Folks : if you're GOING to make arguments like this anyways, BACK IT UP! with nice solid provable facts. Argghh. I thought logic was a required subject for anyone who programmed!

Any decent optimizer will clean this up - my experiences with g++ (not the
most optimal of compilers/linkers anymore) suggest it can handle this
fine…

What it can handle fine?

Ach, if you’re this picky just code in assembly. Then you’ll be as fast
as you can be - providing you know how to optimize it for the processor
g… (aside: I once did up a 3D math lib in C++, C, and assembly…
C++ and C were the same speed and I’m sorry to admit it but both were
-slightly- faster than my hand-optimized assembler. I’m not up to
handling the call reshuffling optimizers can do - I don’t know the rules)

Yes. C and C++ code have a same speed mainly due to the fact that C is
subset of C++.
But I can supposed that the power of C++ is in extensions, such as templates
and overloading.
According to my observations, template based libs are clear and faster then
C libs. This is an origin of my wonder about suggestion to write wrappers
around C libs.

I think that g++ code can be usually improved with assembler by factor
1.2-1.6, MSVC 5.0 - by factor 1.05-1.1.
qsort work 4 times slower then STL sort.
This is my very subjective opinion.

…off to kick dead whale down beach again (see hacker’s jargon)…

Thanks, I am not a hacker.

Best wishes,
AlexeiFrom: winterlion@fsj.net (Teunis Peters)

On Thu, 29 Mar 2001, Alexei Nikitin wrote:

From: “Jared Maguire”

Folks : if you're GOING to make arguments like this anyways, BACK IT UP! with nice solid provable facts. Argghh. I thought logic was a required subject for anyone who programmed!

Any decent optimizer will clean this up - my experiences with g++ (not
the most optimal of compilers/linkers anymore) suggest it can handle this
fine…

What it can handle fine?

He’s saying g++ can handle optimizing the wrapper so it isn’t slow. My
personal stance on this, however, based on experience, is that if you are
writing portable code, it’s better not to rely on a compiler optimizing for
you. Not all compilers can optimize, and not all do a very good job of it
either. If you know what you are doing, it’s better for you to do what you
can to speed things up. Then you can expect better results on whatever
platforms it goes to. C/C++ gets you about as close to assembly as any other
programming language that I know of, so it’s only slightly worse than doing
assembly, and it’s still portable.

Yes. C and C++ code have a same speed mainly due to the fact that C is
subset of C++.

That isn’t necessarily the reason, unless you are writing C++ code that is
pretty must just C anyway. If you go heavily into the C++ realm, it’s going
to use very different code than a C version would, and so if they time about
the same at that point, you can’t just say it’s because C is just a subset of
C++.

But I can supposed that the power of C++ is in extensions, such as
templates and overloading.
According to my observations, template based libs are clear and faster then
C libs. This is an origin of my wonder about suggestion to write wrappers
around C libs.

I’m not sure I’d agree that the are clearer. As far as faster, I’ve never
timed them so I wouldn’t know.

I think that g++ code can be usually improved with assembler by factor
1.2-1.6, MSVC 5.0 - by factor 1.05-1.1.
qsort work 4 times slower then STL sort.
This is my very subjective opinion.

qsort() uses a function callback, which means that you function call overhead
times the number of iterations it needs to go through. Definately not going
to be very speedy if you have a lot of iterations. You’d be better off
writing your own sort code and optimizing it. You might even beat STL. Not
sure how it works exactly.

of? I’ve looked over Wolfenstein, Doom, and a few other (true 3d) engines
and the math fits the algorithms pretty tightly… obviously you never

Wolfenstein and Doom are far from true 3d engines. The ones you mentioned
are actually 2d engines.

written an application that umm has to redraw 60 times per second. Its still
about speed, and clever design.

math library to create all your lookup tables, and you use standard C or C++

Lookup tables are mostly thing of the past by now, as processors do things
faster than accessing memory (or even cache).

routines to do matrix operations, or vector calculations, or point in
polygon tests or whatever, but again your missing the big picture – those
routines are specific for the data structure at hand. There are so many ways
to approach a problem a math lib would only get in the way. At least the one

This is true. It is possible to make a true 3D application by using either
3x3 or 4x4 matrices; you can do it with or without quaternations; you can
use row or column order matrices; you can use left hand or right hand
coordinate system; you can implement camera in several ways; there is a
lot to choose from when you think about material management; a lot to
choose when you think about object instance and mesh management; even more
when you want to make things hierarchial…

And if your doing hardware based, then no math library helps with the
math because most of that is handled with OpenGL!! So are you talking

OpenGL matrix operations, unfortunately, are sort of primitive. You can
not have matrix for each object instance, and you don’t have camera at
all; you have to make them yourself. It is possible to program OpenGL
without custom matrix class…

(x) …But in the real life, as soon as you want to do something more
interesting with OpenGL, you start looking for a good math library,
and usually end up writing it yourself. This is why and how I wrote
mine.

So what are you talking about? Are you talking about writing games, because
that is what SDL is for, at least until or if it has windowing support or a
competely functional GUI. Or are you just talking for the sake of talking?

Reason for many people who are looking for math (matrix) library is
my (x) above.

Next time when I make a suggestion I will attach code to specify what
i’m trying to say. Perhaps then it will have more weight, or else make
me look more foolish. Whatever :slight_smile:

Not all people are looking for the exciting task of tweaking routines
in assembler. The fact is, writing 3d application using 4x4 matrices
is easier if you have a matrix library at hand which you can trust,
and which you don’t even need to fully understand. Yes, that’s right:
You don’t have to completely understand how dot-product works (and
why it works). It is enough that you know what you do with it as
black box.

No, those applications will not be optimized. But they are still fun for
people who write them…

– Timo Suoranta – @Timo_K_Suoranta

math library to create all your lookup tables, and you use
standard C or C++
Lookup tables are mostly thing of the past by now, as processors do
things
faster than accessing memory (or even cache).

Even square roots and trig functions like atan? (e-mail me with your
answers, because this is getting off-topic!)–

Olivier A. Dagenais - Software Architect and Developer

math library to create all your lookup tables, and you use
standard C or C++
Lookup tables are mostly thing of the past by now, as processors do
things
faster than accessing memory (or even cache).

Even square roots and trig functions like atan? (e-mail me with your
answers, because this is getting off-topic!)

I’m going to jump in here and answer “yes”.
fixedpoint math -is- slower than floating point on current processors,
with the exception of addition and subtraction (hunt down a processor
timing chart on intel to find out - I looked it up a ways back)
sin/cos take negligible time; atan is fast - I haven’t checked it against
a chart lookup though. But considering the cost of a chart lookup for
cache-hit and memory transfer, I’d say go with “atan”. sqrt? On older
chips (pentium and before) charts are better, but on newer chips I’ve no
idea. Suspect that especially on architecture such as Pentium/II+ or
AMD/3D-now sqrt is much cheaper - but not free.

A quick-lookup (small!) chart for sqrt is probably a good idea if you
don’t need high accuracy - or at least test it. Perhaps the time needed
to develop this (sqrt chart) isn’t worth it though.

And on this being SDL-associated? Not -directly-, but both atan and sqrt
are required for many operations in 3D calculations - although sqrt is
more useful.

A “standard” math library for SDL would not be a terrible thing - it would
help neos get used to the system and build things more rapidly and provide
a focus for people who need math libraries to improve.

I -do- offer the reccomendation that if huge lists of vectors will have
operations performed on them that specialized list objects should handle
it. While the cost of math operations is particularily tiny now, the cost
of a function call is quite high.

(or in short form - operations on arrays should not call functions if
they’re meant to be efficient)

G’day, eh? :slight_smile:
- TeunisOn Wed, 4 Apr 2001, Olivier Dagenais wrote: