None interactive physical object

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

None interactive physical object

Postby Overhertz » Fri Apr 06, 2012 11:52 am

Hello there, i am wondering is it possible to add a physics object - a box (very large box) that can be moved around (not interactive with physics objects) but still callback with a list of objects it is colliding with (other bodies that are inside the square) ?

so imaging a very large square newton world... for this example 10000 x 10000 and a box size of 1000 x 1000 .. so in the following example, newton could callback a set function with a list of the blue bodies

Image

anyways i hope this is possible, please let me know.

Thanks in advance.
Ziron Programming Language
Download the Assembler HERE
User avatar
Overhertz
 
Posts: 112
Joined: Mon Jul 06, 2009 11:19 am

Re: None interactive physical object

Postby Julio Jerez » Fri Apr 06, 2012 11:59 am

that will be funtion

void NewtonWorldForEachBodyInAABBDo (const NewtonWorld* const newtonWorld, const dFloat* const p0, const dFloat* const p1, NewtonBodyIterator callback, void* const userData);
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: None interactive physical object

Postby Overhertz » Fri Apr 06, 2012 12:29 pm

aha super, thanks alot :)

can i ask, would it be fast ? lets say there are 5000 physical objects in a moving world, and theres maybe 50-100 inside the bounding box, would it take a large performance hit to call on this function each frame ?

Thanks again :)
Ziron Programming Language
Download the Assembler HERE
User avatar
Overhertz
 
Posts: 112
Joined: Mon Jul 06, 2009 11:19 am

Re: None interactive physical object

Postby Julio Jerez » Fri Apr 06, 2012 1:46 pm

the performace cost is

n * log (k * m)

where m is the number of objec in the scene an dn is teh nuibe of object inside the box. k is a const
In core 300 ke is very small, so teh funtion is very fast, in core 200 k is larger because the wold is AABB brad phase is base on a dgTree redblack tree
in both case it is very fast, try it out.

you have a world with 5000 objects?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: None interactive physical object

Postby Overhertz » Sat Apr 07, 2012 9:15 am

5000 yes, possibly more at some point, is core3 drop in compatible with 2 (if not i will just write a new header) ? And is there somewhere i can download the compiled dll ? I am using it with several languages, one being assembly (Ziron)
Ziron Programming Language
Download the Assembler HERE
User avatar
Overhertz
 
Posts: 112
Joined: Mon Jul 06, 2009 11:19 am

Re: None interactive physical object

Postby Julio Jerez » Sat Apr 07, 2012 10:45 am

assembly?, why are you doing that? compling in assembly with today's CPU, in almost all cases result in significally slower code generation.

this is because compilers use an algorithm call Dynamics Programing to optimize several code generation sequences of the same block of functions.
there they consider: Register allocation, superscalar instrution schedule, branch prediction, inteprocedural register alocation, and many more options.
they do that on several generation of the same code and selects the set with the fastest execution.
A programmer, no matter how good he is, will only generate his best path of instructions.

You may see the coded generated for a compiler and think that you can create better code. Thsi si a big mistake, It may be the case your generated code looks prettier
but do not t let that confuse you, chances are that the best you can do is to mach the compiler generated code performace if you are lucky, most likelly you get a next lost.

I do not recomend using assymbly code under any circunstance, CPUs are too complex for a person to be productive using machine language compilers.
I used to be and assembly oprogrammer, who wrote Rendering engines in software before the D3D era, and even then when the first optimizing compile for C++ came out (Watcom compiler)
we had a hard time beating it. today it is impossible.


as core core 300, is is open source, I will try to put alpha2 thsi weekend wit a linux make file.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: None interactive physical object

Postby Overhertz » Sat Apr 07, 2012 11:06 am

Ziron is a programming language developed by my company http://en.wikipedia.org/wiki/Ziron

and compilers can not match a programmers ability to optimize code ever, so i disagree, in alot of cases of course compilers will produce very fast and good code, but programming in Ziron is much more simple, you have low level access, you can see exactly what is going on, less bugs, much smaller code.

as for the core3 release, will it contain a compiled dll binary?
Ziron Programming Language
Download the Assembler HERE
User avatar
Overhertz
 
Posts: 112
Joined: Mon Jul 06, 2009 11:19 am

Re: None interactive physical object

Postby Julio Jerez » Sat Apr 07, 2012 12:16 pm

Ok I see, this is and assembler that you guys make. It is an optimizing compiler?
in the sample I see that for exmpale you cna use register as variables, that is what I was talking about.

say you use variable EAX, what this means is that the compile have to generate the entire set on intruction not using register EAX, as along as eax is alive.
this is known are Register preasure, basically you are increasing teh register preasure for that function, and you are counting that it is the programmer that is going to make the code efficient.
C compilers used to have the keyword "Register", to hint the compiler what variables assign to a register, but more advaced compiler optimizations thecnique do not use it at all because of that reason.

but I asume you have a solution for that.
the way GCC handle it, is that the do allow to declare registers, but not specific registers, tha way the optimized can use then as the optimizer determine it is best.

I can see teh value of a tool liek that, for emebded systems, and just in time scripting languages that can have debug and all that goiddies.
But not to compiet with big compilesle liek Intel, GCC and Microsoft.

In the Newton SDK I was am trying to do that myself, basically I am trin to make a object oriented script lanagauare with JIT, simular to c# and java.
as a matter of fact is is model after those two. BUt taht is a fart as I go.
I find all of teh OS stuff to comberson (linking, system call, and all that junk needed to make and comipler/linker)


I always check the exe, I can add compiled DLL.
why don't you just run the project file in VS, it should build then out of the Box.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: None interactive physical object

Postby Overhertz » Sat Apr 07, 2012 12:32 pm

I no longer have visual studio installed and i've tried with gcc but it just throws alot of errors, and i'd assume VS would optimize the code much better so would be nice to have a compiled dll, if you could do that i will be very happy.

About the registers, it is impossible for any language to keep eax safe, so most likely it would just push it on the stack or store it in a private variable somewhere, however for a low level coder this can be optimized easily by using xchg's and other useful instructions which a compiler will rarely dare to use. Most compilers will just max out the registers available and then fall back onto the stack, but sometimes you could manually save 1 or 2 registers or purposely wipe another, which can be very difficult in higher level languages.

And for optimizing in Ziron - only somethings are automatically optimized (by config)

Studying the PE file format was a big pain, else writing the internal assembler and linker was not a big deal, the greatest part of Ziron is the plugin system, it allows for other programmers to add external optimizers and many other useful plugins, even extending the syntax or making things easier or whatever, the possibilities are endless :)

Anyways, Thanks :)
Ziron Programming Language
Download the Assembler HERE
User avatar
Overhertz
 
Posts: 112
Joined: Mon Jul 06, 2009 11:19 am

Re: None interactive physical object

Postby Julio Jerez » Sat Apr 07, 2012 1:19 pm

Overhertz wrote:About the registers, it is impossible for any language to keep eax safe, so most likely it would just push it on the stack or store it in a private variable somewhere, however for a low level coder this can be optimized easily by using xchg's and other useful instructions which a compiler will rarely dare to use. Most compilers will just max out the registers available and then fall back onto the stack, but sometimes you could manually save 1 or 2 registers or purposely wipe another, which can be very difficult in higher level languages.


This is exactly what I was saying before, some instructions like xchg are not used by compilers because they are really bad.
the reason for that is that all of the thechnique for compile optimization count on the assumption that instrution con not have side effect.
instruction line Pre increment, post increment, inc, xchg, rep move, jump and inc, and all of the dedicate special function are out of favor because of the side effects.
CPU makers do no even bother to make those instrutions super scalar anymore.

when the intel CPU find and xchg instrution, it issues a pipeline stall that could be 20 for 40 cicles, it is a nasty operation. it is better to do
tmp = x1
x1 = x2
x2 = tmp

instead xch x1, x2
the same goes for increment, and others.

has you read the book: Compilers Principles, Techinque and Tools, by Alfred V. Aho?
if you have not, please read that book so that you underntand what I am talking about?
it is not untill you do that, that you will beleive it. it is very difficult to see it by comparing code fragmnets generared by a compiler out of context.

Are you writing you own code generator or are you using a comercial one?




I will put the compiled libraries.
Has you try compiled the engine with your compiler?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: None interactive physical object

Postby Overhertz » Sat Apr 07, 2012 1:54 pm

The assembler and language are all custom, the syntax is also custom, so it can not compile c or c++ projects (they are different language).

The xchg instruction only has a lock if you use a memory operand, however xchg ecx, eax is not a problem.
Ziron Programming Language
Download the Assembler HERE
User avatar
Overhertz
 
Posts: 112
Joined: Mon Jul 06, 2009 11:19 am

Re: None interactive physical object

Postby Julio Jerez » Sat Apr 07, 2012 2:19 pm

Ok I will add the dll, with next check in.

I am not trying to be annoying or axnoxios, I am simply informing you of some things you migh not know. so this is my last commnet

Instructions like xchg ecx, eax are also bad. no as bad as when they block the bus, but they also stall the pile line.
they are difficult to use in algorithmic optimizations use byt because of the fact that they act on more than one CPU resurce.

these fact of optimization techique is what has made CPU makes to abandone those intructions, in favor of the ones that can be implemented with a small set if micro op that can be issue out of order,
and without register dependecies. this is because the CPU internally have more registers than you see.

xchg ecx, eax is a CISC instruction, and one of the nasties at that. That last thing you want to use are instructions like
xchg, inc, dec, movs, xabc, addc, subc, ... and so on


Let me give you an example

say you have some code liek this

Code: Select all
a = b + c;
c = b + f;

the assembly pout put may be

Code: Select all
mov eax, b
add eax, c
mov a, eax

mov eax, b
add eax, f
mov c, eax


it may look that that code is poorly issue by a complier, but the compiler makers know that the CPU will not use register eax, instead it will use a alias of register eax,
so the entire 6 instruction may be executed in on tick all at once as long a there are not internal dependencies and the register can be renamed(eax, in thes case).
if you rearrange the instruction, or you use instructions that change the value of some register, then the CPU decoder can not issue out of order instruction and serialize then all, taking 6 ticks instead of one.
That's the kind of knowledge big compiler makers have that we do not. an this is why you may think that compiler generated code is inefficient, but it is not.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: None interactive physical object

Postby Overhertz » Sat Apr 07, 2012 2:39 pm

xchg with registers is more than acceptable, infact i bet if you disassemble your newton dll you will find that VS also uses the xchg instruction quite alot (and worse of all it often uses it with memory operands)

and i do not need an explanation of how the CPU works, after all i'm the developer of an assembler lol

as for inc and dec, they also can be useful when used along side a single cmp instruction and a jump loop

anyways i will not bother to argue about this topic - as for the dll, thanks :)
Ziron Programming Language
Download the Assembler HERE
User avatar
Overhertz
 
Posts: 112
Joined: Mon Jul 06, 2009 11:19 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest