From: Tim H. <tim...@ie...> - 2002-01-13 04:25:05
|
Hello Armin, Thanks for the tips. That was enough for me to get this working. I also modified psyco_generic_call to allow CfNoReturnValue with CfPure. I just had it always return CC_ALWAYS_TRUE. I did this because some of my cimpl_XXX functions have no return values. However, if you think CfNoReturnValue should not be allowed with CfPure, I can instead have the cimpl_XXX function return dummy values. I think this leaves only 'r' disallowed with CfPure, but since 'r' seems to be explicitly run time, that seems not to be a problem. With these changes, the following function (a ripoff of f1()) runs a bit over ten times faster than stock python: def f10(n): "Arbitrary test function." i = 0.0 x = 1.0 while i<n: j = ZERO_F while j<=i: j = j + 1.0 x = x + i*j i = i + 1.0 return x The following silly function now runs ever faster with increasing n, now that everything is compiled away: def f10(n): i = 0 while i < n: x = 5. + 7. i = i + 1 I've had it up to over 100X faster than stock python with large enough n. Anyway, it's all very cool. Thanks for writing this Armin! I'll post patches real soon now. -tim > Hello Tim, > > On Thu, 10 Jan 2002, Tim Hochberg wrote: > > Does that mean modifying psyco_call_var (AKA glue_call_var)? If so, brrrr! > > That's a bit out of my comfort zone right now. If not, could you give me > > some hints on what would need to change in psyco_generic_call to get this to > > work? > > No, all you need to modify is psyco_generic_call(). psyco_call_var() will > just call the C function directly by passing it the arguments listed in > the 'args' array. For example, to call a function with signature (double, > double, double*), the args array must contain 4 values for the first two > doubles, and a 5th value which is a pointer to a 8-bytes buffer. > > In other words, in psyco_generic_call(), in the CfPure case, for any 'a' > or 'A' arguments, you must allocate a buffer whose size is given by > ((vinfo_array_t*) args[i])->count and put it in args[i]. After > psyco_call_var(), you get the output of the C function in the buffers; > they must be put back into the vinfo_array_t's, as compile-time-known > vinfo_t's: for each 'a' argument, fill the corresponding vinfo_array_t > with as many 'vinfo_new(CompileTime_New(...))' as the length of the array > dictates; for each 'A' argument, you must also obtain a reference on the > returned Python objects by using 'vinfo_new(CompileTime_NewSk(sk_new(..., > SkFlagPyObj)))'. > > > Hope this helps, > > Armin. > |