[fpc-pascal] Very vague gettickcount64 description?

2019-09-06 Thread Paulo Costa

Hi,

While consulting the online reference about gettickcount 
https://www.freepascal.org/docs-html/rtl/sysutils/gettickcount64.html

I could not know anything about the units involved.

It says "It is useful for time measurements, but no assumtions should be 
made as to the interval between the ticks."


I understand that in some cases the measure may deviate from the real 
value but perhaps, at least the units, should be stated.



Greetings,

Paulo Costa
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] The unfortunate deprecation of GetTickCount

2018-04-11 Thread Paulo Costa

Unfortunate is the obscure wording you find on the documentation:

https://www.freepascal.org/docs-html/rtl/sysutils/gettickcount.html

"Description
GetTickCount returns an increasing clock tick count. It is useful for 
time measurements, but no assumtions should be made as to the interval 
between the ticks. This function is provided for Delphi compatibility, 
use GetTickCount64 instead."


One would think that GetTickCount64 would clarify things about the 
interval between the ticks (just to be useful for time measurements) but:

https://www.freepascal.org/docs-html/rtl/sysutils/gettickcount64.html

"Description
GetTickCount64 returns an increasing clock tick count. It is useful for 
time measurements, but no assumtions should be made as to the interval 
between the ticks."


How can it be useful for time measurements if we don't know the units?

Contrast to the Microsoft Documentation:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms724408(v=vs.85).aspx

"Return value
The return value is the number of milliseconds that have elapsed since 
the system was started."


Of course, it is followed by some remarks about the real limitations but 
at least we have some idea on what to expect.


I know that, by being cross platform, GetTickCount64 can behave in 
different ways on other environments but, just because of that, the user 
should not be kept in the dark when using it.


I know that the documentation effort is hard and many times we don't 
appreciate the effort as we should, but please don't be so vague on this 
entry.


Paulo Costa
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] H2pas tool vs others, C header translation

2017-08-27 Thread Paulo Costa

On 27-Aug-17 23:47, Dmitry Boyarintsev wrote:

Is 2 neither true, nor false? 3? 4?

If false is zero,
Then true is not false.

Also C doesn't have a boolean type per se. Iirc it was introduced in 
some version of c++ standard.


In C it's very strange to see code like that:

If (b==1)

It's always
If (b)
Or
If (!b)


Of course, that is because, in C, any value that is not zero, is true.

So you can not compare with 1 or -1 or any other value to test if it is 
true...


Paulo Costa
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Serial to TCP gateway in FPC?

2017-06-29 Thread Paulo Costa

On 29-Jun-17 15:43, Koenraad Lelong wrote:

Op 29-06-17 om 10:25 schreef Bo Berglund:

On Sun, 18 Jun 2017 20:36:11 +0200, Koenraad Lelong
<fpasc...@de-brouwerij.be> wrote:


Do you know the SDPO-package ? That has a serial component (SDPOSerial).
This has a OnRxData event.


Do you mean SDPO or 5DPO (letter S or number 5 at the start)?
I googled for SDPO but the hits were for 5DPO...



It's the same project. Sometimes it's called 5dpo sometimes sdpo.
In the component-list there is a tab 5dpo, but the component itself is 
called TSdpoSerial. If you want to install it, you have to install 
SdpoSerialLaz.


That is correct.

The longer story is that most of those components came from our work on 
a team called 5dpo. Our team was active from 1998 to 2007 in the Robocup 
competitions (Small Size League ans Middle Size League)
The trouble is that you can not have an identifier starting with a 
number, so for component names we replaced the 5 with a S.


Paulo Costa
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Serial to TCP gateway in FPC?

2017-06-20 Thread Paulo Costa

On 20-Jun-17 10:45, Michael Schnell wrote:

On 20.06.2017 11:18, Mark Morgan Lloyd wrote:
I tend to use the lower-level serial.pp unit. The patches I 
contributed a couple of years ago specifically added a couple of 
read-with-timeout functions


IMHO, freeing the user from the necessity to poll or do a thread to wait 
for serial events is a very beneficial strategy.


But Koenraad Lelong said in the other mail that "SDPOSerial" has a 
OnRxData event. Hopefully by "event" a main thread event is meant.


Yes. That is the case.

Paulo Costa
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Happy tickets benchmark

2016-02-16 Thread Paulo Costa

On 16-Feb-16 18:53, Mark Morgan Lloyd wrote:

Serguei TARASSOV wrote:

...

Sounds like the real-life programs don't use inner loops or don't
solve NP-complete problems  :)
For info, my real-life examples are the application server and the DSL
script engine.
So any improvement of quality of FPC's generated code are welcome.


Anybody using a high-level language for real work would be advised to
understand the problem a bit better so that they didn't have to use your
sort of brute-force approach. And at that point, having something that
expresses higher-level algorithms and coding practices (threads, dynamic
arrays) becomes at least as important as brute force efficiency.


I think that the original example should be treated as the code that is 
used to trigger a bug. It must be the simplest possible so the bug can 
be identified and corrected.



... At which
point, pointing out that FPC doesn't have a STEP or BY clause in the FOR
statement would be far more useful criticism.


Depending on the problems that we want to solve, different language 
capabilities become more or less important...


Paulo Costa
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Happy tickets benchmark

2016-02-13 Thread Paulo Costa

On 13-Feb-16 10:44, Serguei TARASSOV wrote:

Could anyone make the series on Windows with FPC, Delphi and MS .Net?
The test of FPC 3.0 and any other comments are welcome.


On my PC with Windows 8.1, fpc 2.6.4 32bits, when I changed the line:
inc(TicketsCount);
to:
TicketsCount := TicketsCount + 1;

the results improved from:
C:\tmp\tests>HappyTickets.exe
Found 4816030 tickets. Elapsed time, msec: 323

to

C:\tmp\tests>HappyTickets.exe
Found 4816030 tickets. Elapsed time, msec: 262


Paulo Costa
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC embedded ? (going slightly off-topic)

2015-03-05 Thread Paulo Costa

On 05/03/2015 19:28, Ewald wrote:


On 05 Mar 2015, at 19:57, Adriaan van Os wrote:


It's a very smal project but I do need to drive one or two stepper motors. What 
I learnt is that that the board does the controlling and that there is a 
separate chip for driving the motor, e.g. for stepping and microstepping ?


Stepping and microstepping can easily be implemented in the microcontroller 
itself, like you say. The reason you need an extra chip is the need for some 
power transistors arranged in a bridge configuration, something similar to the 
L298 or L293D, to name some popular IC's.


While stepping and microstepping can be implemented in the 
microcontroller itself, there ICs that do that and the power driving.
They are very popular in 3D printers and you can buy a board where you 
only have to give the (micro)steps and the direction.

Search, for example, in ebay for A4988.

Paulo Costa
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Initializing dynamic arrays

2012-06-04 Thread Paulo Costa

On 04/06/2012 13:51, inge...@ragnemalm.se wrote:


I am writing a unit for dealing with matrix algebra with arbitrary sized
matrices (as opposed to the FPC unit that deals with a few fixed size
ones).


If you are writing that for your fun and to learn, go ahead, if what you 
really want is to have a unit to deal with arbitrary sized matrices, 
just go to:

http://wiki.freepascal.org/5dpo
and install the SdpoDynmatrix package.
There you have automatically ref counted arbitrary sized matrices with 
overloaded operators to add, subtract, multiply and invert them.


As for the initialization of a matrix you can do the, somewhat ugly but 
effective, trick of creating a function like:


// Converts a String representation to a TDMatrix
// a11 a12 a13; a12 a22 a23;
function StringToDMatrix(str: string): TDMatrix;

and then write:

A := StringToDMatrix('1 2 3; 4 5 6;');

Paulo Costa
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] More doubts on C to pascal header translations:

2011-04-25 Thread Paulo Costa

On 25/04/2011 08:58, Marco van de Voort wrote:

In our previous episode, Paulo Costa said:

I saw that h2pas translated:

typedef void(*callback)(int pos, void* userdata);

to

callback = procedure (pos:cint; var userdata:pointer);cdecl;


userdata is essentially untyped, so it doesn't matter what it exactly points
too.


Right. The trouble here was that I see var foo as a reference to foo, 
which means an implicit pointer. So var userdata:pointer is like a 
pointer to pointer and that doesn't look like the original C code...



shouldn't it be?

callback = procedure (pos:cint; userdata:pointer);cdecl;


It is a better translation, and also pointer style support NIL. Do you use
-v or not?



OK. I did not use the -v option so I was wondering why it was selecting 
the first option.


Paulo Costa
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] A few doubts about C to pascal header translations:

2011-04-25 Thread Paulo Costa

On 24/04/2011 16:41, Marco van de Voort wrote:

In our previous episode, Paulo Costa said:

I've come across some constructs that I'm not sure how to translate:

A procedure where one of the arguments is declared as:
size_t arg;

also a macro where appears:
sizeof(size_t)

I replaced size_t by PtrUInt, is there a better alternative?


On *nix size_t is afaik declared in unit baseunix?



Right now I'm working in Linux but I latter would like to make it work 
in Windows. The main concern was if it was 32/64 bits safe.


Paulo Costa
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] nested macros in C headers

2011-04-24 Thread Paulo Costa

On 24/04/2011 11:24, Bernd wrote:

2011/4/24 Sven Barthpascaldra...@googlemail.com:

Hi!

I did convert the V4L2 headers some time ago, but did not publish them yet.
If you want to, I can send you the Pascal file. I tested it with a radio
tuner, so it should work mostly.


This would surely be helpful. Please consider also releasing them with
an FPC compatible license, because while searching on google I have
seen quite a few discussions where users were desperately searching
for any way to access the v4l API but no existing and working solution
for FPC seems to exist at the moment and porting all these overly
convoluted and obfuscated kernel headers into something readable and
usable is really not a trivial task at all.

Bernd



Well, you can have it with Lazarus in:

http://wiki.lazarus.freepascal.org/5dpo

the TSdpoVideo4L2 component has the V4L2 translated...

Paulo Costa
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] A few doubts about C to pascal header translations:

2011-04-24 Thread Paulo Costa

I've come across some constructs that I'm not sure how to translate:

A procedure where one of the arguments is declared as:
size_t arg;

also a macro where appears:
sizeof(size_t)

I replaced size_t by PtrUInt, is there a better alternative?

Paulo Costa


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] More doubts on C to pascal header translations:

2011-04-24 Thread Paulo Costa

I saw that h2pas translated:

typedef void(*callback)(int pos, void* userdata);

to

callback = procedure (pos:cint; var userdata:pointer);cdecl;

shouldn't it be?

callback = procedure (pos:cint; userdata:pointer);cdecl;

Paulo Costa
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Optimized matrix multiplication functions for pascal?

2010-10-09 Thread Paulo Costa

On 09/10/2010 06:59, Bo Berglund wrote:

I am translating a bunch of Fortran functions to FPC and I
have now come across a problem with a couple of built-in
Fortran90 functions:

MATMUL multiplies two matrices (arrays) and returns the result.

TRANSPOSE reorders the array elemsnts in some predefined way.

The call in the Fortran routine is like this:

b = matmul(transpose(a), a)

where a and b are equal sized dynamic arrays of double.

So I need to get hold of two Delphi functions:

function matmul(X, Y: array of double): array of double;
and
function transpose(X: array of double): array of double;

Where can I find such functions?
I am not a matematician myself so I don't know what these
functions really do...


Try:

http://paginas.fe.up.pt/~paco/pmwiki/index.php?n=DynMatrix.DynMatrix

It is a bit more than just those functions but it could solve, for a 
while, your problem.


Paulo Costa


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Where is IsMultiThreaded set under Linux?

2010-10-08 Thread Paulo Costa

On 08/10/2010 18:35, Henry Vermaak wrote:


I think Jonas was talking about out of order execution in the cpu, not disk i/o.


No, it was out of order writing to memory (RAM), modern CPUs/Memory 
controllers can do strange things reordering writes to RAM.


Paulo Costa
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] code optimization

2010-09-23 Thread Paulo Costa

On 23/09/2010 18:09, stefan...@web.de wrote:

Eduardonec...@retena.com  wrote:




Can you try optimize for size? In some cases, it reduces L2 / L3 cache
miss and runs faster than O3. It happens in other compilers and
languages too.


I just tried it: The code gets even slightly larger and much slower (almost a 
factor of 2).


Hi,

Try -Os3 instead of -O3

and try to reorder

type
 TRectangle   =  object
 width   : Integer;
 Area: Int64;
 NextUnusedRectangle: Integer;

to

type
 TRectangle   =  object
 width   : Integer;
 NextUnusedRectangle: Integer;
 Area: Int64;

and the var declaration:

 var
 i, MinValley, MinValleyWidth: Integer;
 PrevBar, NextBar: Integer;
 RectWidth   : Integer;
 NextBarWidth: Integer;
 NewEntry, NewEntry2 : Integer;
 MinValleyHeight : Integer;
 MinValleyArea   : Int64;
 TotalAreaOfFittingRectangles: Int64;
 CurrentRectangle: Integer;
 PreviousRectangle   : Integer;
 OldFirstUnusedRectangle : Integer;
 BarCase : TBarCase;
 OldPrevNextRectangle: Integer;

It seems a matter of alignment. I tested and could extract a 5% speed 
increase (XP and fpc 2.2.4). With 2.4.0 it may not work like that but is 
worth a try.


Paulo Costa
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal