If you need really fast rand there should be a random number generator that operate without division ... What is you target and intended use ?
Is it possible to do integer division without using Std.int() or cast? These are rather slow, I'm trying to optimize a random number generator.
Casting double to int is very expensive. Can you bench with Math.floor.round please ?
If I were you :
Rng are a big problem so I would make something mathematically portable and hint in the docs about potential speed issue and why not hint to faster strategies (rand maps, faster algorithm)
:)
Well nobody should try to do 10 mega random with a general lib random but that is my opinion ;)
Yes, I think that "Std.int( / )" has become pseudo standard longhand for integer division at compile time. Currently this this not supported by the hxcpp backend.
I campaigned for Math.idiv, which would work on runtime/dynamic as well, but this has been rejected. :(
Hugh
@hughsando I deeply but humbly think you should start cpp.Math which would provide an entry point for such native math functions and intrinsics, this would give you leverage to add vectorised cross platform primitives and I am sure flixel or the future flambe would use it at some point.
Yours
I think cpp.NativeMath is probably the way to go - did you have some specific syntax in mind?
Hugh
Hi Huge !
Did my homework and explored the different intrinsic provider, remembered their syntax was horrible but with years it got worse.
Methink we should start small with a cpp.NativeMath with all the regular Carmack tricks.
Then we should stick to haxe naming convention maybe flavored with opengl for typing ( ex saturatedAdd_f32_f32, divide_i32_i32).
We want this code to be readable rather than concise because haxe already provide mechanics to shorten these names for math freaks.
Since auto vectorisation works well these days, we can delay the intrinsic access api.
Second stage (intrinsics) would be to have the equivalent of http://www.agner.org/optimize/ ' s vectorclass. Which is not the most efficient implementation but I think it perfectly matches haxe constraints and leaves room for vectorisation. Alas its licence impeached us to add it to haxe so we ll have to rewrite something similar.
We can delay this until someone really needs it since the 3d community is still young and might probably turn to webgl.
Direct intrinsic access can be done via cpp.Function so i think we can leave it behind for now.
What do you think ?
trace((20000000 * 48271)% 0x7FFFFFFF);