On Dec 12, 2005, at 21:55, Joshua Isom wrote:
Because the random benchmark is used for a few other tests, I figured I'd do it next. To do it the same way in pir is slow because it requires putting a variable into a global register and retrieving it 900,000 times. I have three versions written up. One that's split over two files, with one file including main, and the other including an init section and the actual needed sub. Another that's the same but just one file, but a tad uglier to me(7 extra lines just for error checking). And the final cream of the crop(i.e. about twice as fast as the pir), a pasm version, which takes advantage of the fact that the registers stay the same the whole time unless modified.
Hmm. I think we just submit 2 versions: random.pasm and the the split one with randomd_lib.pir. The global is ugly, yes. We could use a closure, but that would restrict the usage to a fixed :outer, which isn't really good. Well, we dont't have a C-like static construct.
But before doing that I'd appreciate, if you cleanup the rand algorithm a bit: IM, IA, IC, and last are integers only. The part of the calculation doesn't involve floats. E.g.:
# random-2.pasm # I0 = N (counter) # I1 = last # N3 = the argument for gen_random # N2 = random result main: get_params "(0)", P0 elements I0, P0 eq I0, 2, arg set I0, 900000 branch arg_ok arg: set S0, P0[1] set I0, S0 arg_ok: set I1, 42 set N3, 100.0 while_1: bsr gen_random dec I0 if I0, while_1 new P0, .FixedFloatArray set P0, 1 set P0[0], N2 sprintf S0, "%.9f\n", P0 print S0 end .constant IM 139968 .constant IA 3877 .constant IC 29573 gen_random: mul I2, I1, .IA add I2, .IC mod I1, I2, .IM set N2, I1 mul N2, N3 div N2, .IM ret