[fpc-devel] [fpc-announce] FPC 3.2.0 released!

Marco van de Voort fpc at pascalprogramming.org
Sat Jul 4 15:10:24 CEST 2020


Op 2020-07-03 om 19:18 schreef Keith Bowes via fpc-devel:
>  Another thing was the Card function, which
> I thought would be easy to do, as surely the code keeps track of how
> many elements there are in a set, but if it does, I couldn't find it.

(Just a bit of fun, doesn't really answer your question, since obviously 
you'd need it in a ISO compatible mode. Also note that 3.2.0 branched 
over an year ago)

But 3.2.0 supports generic functions, and 3.0.0 already supported popcnt 
(https://www.freepascal.org/docs-html/rtl/system/popcnt.html).

But the syntax will be CARD<settype>(variable), and there are some minor 
things wrong with it: (anyone?)

- needs set type to be defined as type to reuse.

- what to do with a small registerable set, need const ref, but const 
[ref] is not yet supported in delphi mode?)

- and alignment requirements for the pointer walking.

- assumes unused bits in the last byte are 0. If that is unsure one 
could use the result of the AND 7 to make an and mask to mask out the 
unnecessary bits.


{$mode delphi}
{$pointermath on}

Function CARD<T>(const a: T): Integer;
Var bits,dwords,rest,i : Integer;
     p: pbyte;
begin
   result:=0;
   p:=@a;
   bits:=(high(t)+1) ;
   dwords:=bits div 32;
   rest:=(bits mod 32); // bytes
   if (rest and 7)>0 then // round rest bits (and 7) up to whole byte (8)
     rest:=rest+8;
   rest:=rest shr 3; // bits -> bytes.
   for i:=0 to dwords-1 do
     begin
       result:=result +popcnt({unaligned?} pdword(p)^);
       inc(pdword(p));
     end;
   for i:=0 to rest-1 do
     begin
       result:=result +popcnt({unaligned?} pbyte(p)^);
       inc(p);
     end;
end;

Type TSettype = set of 0..80;

Var t : TSettype;
     i : Integer;
Begin
   t:=[];
   for i:=0 to 5 do
     Include(t,i*13);
   Writeln(CARD<tsettype>(t));
End.
> I'll probably get back into it eventually, but I might have to redo what
> I've already done, because conflicts in the Makefiles are pretty much a
> certainty.  Personally, I'm nut sure why the Makefiles are included in
> SVN; they should be generated `fpcmake -r` before compilation (or being
> packed into a source tarball) to avoid this kind of thing.

But that would cause a bootstrap requirement on fpcmake, instead just 
the compiler. Note that recently, the generation date has been removed 
from the generate file to reduce conflicts.

> Anyway, it'll be nice if we can get some more ISO 10206 features.  Some
> have been popping up here and there over the years (string slices, the
> ** operator, WriteStr/ReadStr, etc), but a lot of useful features are
> missing and seemingly have no equivalent in Borland's proprietary
> dialect.

And of course schemata are the proverbial elephant in the room.




More information about the fpc-devel mailing list