clampV a instruction to clamp vectors

Posted By: Anonymous

clampV a instruction to clamp vectors - 04/24/15 14:37

Hi, I've written a simple function so I can clamp independently the elements of a vector. I am just wondering if a function like this would be faster if it was part of the engine instruction set?

clampv(VECTOR to return, VECTOR to clamp, var lower A, var lower B, var lower C, var upper A ,var upper B,var upper C);

Thanks
Mal
Posted By: DLively

Re: clampV a instruction to clamp vectors - 04/24/15 14:44

This doesn't answer your question, and im also not a developer, but without seeing the functions guts, it looks like you could shorten your last 6 vars to Vectors, and that would likely save you the resources your looking to save.

clampv(VECTOR to return, VECTOR to clamp, VECTOR lower, VECTOR upper);

you could then access upper A as upper.x, upper B as upper.y and so on... laugh

Hope this helps.
Posted By: jcl

Re: clampV a instruction to clamp vectors - 04/24/15 16:19

Litec-C functions normally not become faster when integrated in the engine. Although VC++ compiles slightly better code than lite-C, the difference is normally only noticeable when the function contains complex loops.
Posted By: Quad

Re: clampV a instruction to clamp vectors - 04/24/15 20:51

another question on point, would such function be faster(even if marginally) when it's a lite-c function or an engine plugin function?
Posted By: Anonymous

Re: clampV a instruction to clamp vectors - 04/24/15 21:55

Thank you jcl for the answer.
Thanks Dlively for pointing out the other vectors.
Posted By: WretchedSid

Re: clampV a instruction to clamp vectors - 04/24/15 22:00

What kind of optimizations does the Lite-C compiler perform anyway? In my experience from some time ago, it wasn't really doing a great job at optimizing code and especially modern compilers have a huge array of optimizations they can perform which speed up more than just loops.
Posted By: jcl

Re: clampV a instruction to clamp vectors - 04/25/15 08:24

The lite-C compiler does not optimize. So a DLL function can be indeed up to 50% faster when created with an optimizing compiler such as VC++.

But you normally will only notice a difference when the function contains large loops. Otherwise the function can be written in lite-C or in VC++ without much effect on the total script execution speed.
Posted By: Reconnoiter

Re: clampV a instruction to clamp vectors - 04/25/15 14:12

Originally Posted By: jcl
The lite-C compiler does not optimize. So a DLL function can be indeed up to 50% faster when created with an optimizing compiler such as VC++.

But you normally will only notice a difference when the function contains large loops. Otherwise the function can be written in lite-C or in VC++ without much effect on the total script execution speed.
, how large loops are we talking about? tia for your time.
Posted By: sivan

Re: clampV a instruction to clamp vectors - 04/27/15 07:19

by the way, it would be more elegant to create support for more types. I mean in general, not only in this particular case. it could be on engine level or via some little lite-c helper packages. for example dynamic memory and dynamic 1D/2D array handling would also require such a support. it would be not a big effort, only a little boring to implement. laugh
© 2024 lite-C Forums