Re: [fpc-pascal] Branch table
Il 23/08/2018 11:34, Marco Borsari via fpc-pascal ha scritto: It would be for the Wirth optimization in the access of an array, when the index is 0 or 1, allowing the elimination of a multiplication. I'm afraid that this sort of optimization is rather outdated, and doesn't take into account a number of factors which make modern processors behave quite differently from old times ones. First of all, saving a multiplication was important at the times when even integer multiplication was very costly in terms of machine cycles. Today one must carefully check if there's really any saving in replacing a multiplication (which is nowadays very fast) in just a couple of cases (index 0 and 1) with a number of checks and jumps for *all* cases. Moreover, any compiler will align your array elements on 32bits boundaries (or 64bits if you're in a 64bits platform) for better efficiency, so that your multiplication will be a multiplication by a power of two, which all the modern compilers translate into a much faster shl. No doubt that adding checks and jumps to save a shl doesn't make much sense. The second important factor to take into account is that modern processors do not execute instructions taken directly from the slower main memory, but they fetch them from the much faster cache. A jump instruction, if the target isn't very near, will generate a cache flush, thus dramatically increasing the execution time. That's why modern compilers try to avoid a branch table whenever possible. In the example you mentioned earlier (http://www.mindfruit.co.uk/2012/01/switch-blocks-jump-tables.html) you can read that gcc translates a switch (= fpc case) construct into a branch table with -O1 (minimal optimization), but with higher optimization (-O3) it avoids the branch table and translates the construct into a sequel of conditional jumps. In any case for the above reason (avoid cache flushing with a jump target too far away) the code that I had proposed (branch table in the data area) is preferable to the one of your last attempt (branch table in the code area). You may easily verify what solution provides the best efficiency in your platform, by performing a high number of iterations over your code, with random idx's in the range of your array size, and getting the total execution time (sort of: time your_prog). Keeping in mind that on a different platform (different cache size) it could behave quite differently. Giuliano -- Do not do to others as you would have them do to you.They might have different tastes. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] No breakpoint capability
On Sat, 2018-08-25 at 10:56 -0400, john youngquist wrote: > I updated to FPC 3.0.4 and can't get breakpoints to work. > > I get a "can't set breakpoint message" on all lines. > > I am in debug mode and have "generate debug information" enabled. > > This all worked fine in the previous version. I have searched all the > documentation > > I can find and can't even find the word breakpoint. What am I missing? > I assume you are using Lazarus? What do you see in the Debug Output window when you get the message above? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Branch table
Am 26.08.2018 um 11:43 schrieb Giuliano Colla: > Il 23/08/2018 11:34, Marco Borsari via fpc-pascal ha scritto: > >> It would be for the Wirth optimization in the access of an array, >> when the index is 0 or 1, allowing the elimination of a multiplication. > > I'm afraid that this sort of optimization is rather outdated, and doesn't > take into account a number of factors which > make modern processors behave quite differently from old times ones. Multiplication is much less expensive then a jmp in most cases on today's CPUs. It is even the other way round, it is often useful to replace an if statement by a multiplication like: if a>b then Inc(c,d); can be replaced on modern CPUs by Inc(c,d*ord(a>b)); ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Type helper for JNI pointers
Hi, I haven't used type helpers but why not change to defines like type jObjectRec = record end; jObject= ^jObjectRec; jClassRec = record end; jClass = ^jClassRec; or possibly simpler you could try jclass = type(jobject); // I believe this forces a new type and is not just an alias that looks better. Who can change them? These jobject/jclass type definitions are part of fpc... Although type is weird type a = type (pointer); type b = type (a); does not compile, duplicate identifier a type a = type (pointer); type b = type a; compiles, but a type helper for cannot use self as pointer. self <> nil => operator is not overloaded. But you can do writeln(self); type a = type pointer; type b = type (a); does not compile, duplicate identifier a type a = type pointer; type b = type a; compiles, and is like a pointer, but unlike case 2, you cannot do writeln(self) in the type helper type a = type (pointer); type b = type (pointer); does not compile, duplicate identifier type a = type (pointer); type b = type pointer; does not compile, error in type definition type a = type pointer; type b = type (pointer); compiles type a = type pointer; type b = type pointer; compiles Cheers, Benito Am 23.08.2018 um 04:23 schrieb Andrew Haines via fpc-pascal: On 08/12/2018 07:42 AM, Benito van der Zander wrote: But this does not work, because fpc thinks jclass and jobject are the same type, so there is only one type helper for both of the types allowed. Because it is declared as type jobject=pointer; jclass=jobject; What can we do about this? I haven't used type helpers but why not change to defines like type jObjectRec = record end; jObject= ^jObjectRec; jClassRec = record end; jClass = ^jClassRec; or possibly simpler you could try jclass = type(jobject); // I believe this forces a new type and is not just an alias Regards, Andrew ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal