I believe there is a TBCD lib in Fpc somewhere that can do this.
Title: Re: 128 bit integers
Post by: Thaddy on June 16, 2019, 04:38:02 pm
This is already present in fpc. Operations on that are not (yet) fully supported, but I have a full set of operators if you need them. (Only UNSIGNED integers, see: https://bugs.freepascal.org/view.php?id=35371 and https://www.freepascal.org/docs-html/rtl/sysutils/int128rec.html ) Just let me know. The bug resolve is not to my liking, but at least Florian has a proposed solution. I also implemented that.
Title: Re: 128 bit integers
Post by: julkas on June 16, 2019, 04:53:28 pm
@Thaddy Can you share your code? Is there support for __builtin_clz GNU C family operations?
Title: Re: 128 bit integers
Post by: Thaddy on June 16, 2019, 06:48:45 pm
I have to ask for permission, but it it is pure Pascal. The clz support depends on the FPU support and so the compiler modes.. I can probably share it.
Title: Re: 128 bit integers
Post by: julkas on June 17, 2019, 02:38:48 pm
Thanks @Thaddy. I want RTL bit helpers (operations) (CPU optimized) on 16, 32, 64, 128 bit ordinal types. I found only PopCnt function. GCC __builtin family has
Title: Re: 128 bit integers
Post by: Thaddy on June 17, 2019, 02:53:30 pm
Freepascal will optimize based on the FPU settings with which you compile. E.g. -CfAVX/ -CfAVX2 etc on windows and e.g. - CfVFPv4 on armhf. Results may vary, so I usually do a bit of inline assembler when it is absolutely necessary. But i didn't do that with the code I referred to: that's pure Pascal.
Title: Re: 128 bit integers
Post by: howardpc on June 17, 2019, 02:56:11 pm
I want RTL bit helpers (operations) (CPU optimized) on 16, 32, 64, 128 bit ordinal types. I found only PopCnt function.
FPC has RorByte, RolByte, BsfByte, BsrByte, all with Word, DWord and QWord analogs. There is also SarShortint, with SmallInt, Longint and Int64 analogs.
Title: Re: 128 bit integers
Post by: marcov on June 17, 2019, 02:59:36 pm
Afaik there are
function BsfByte(Const AValue: Byte): Byte;[internproc:fpc_in_bsf_x]; function BsrByte(Const AValue: Byte): Byte;[internproc:fpc_in_bsr_x]; function BsfWord(Const AValue: Word): cardinal;[internproc:fpc_in_bsf_x]; function BsrWord(Const AValue: Word): cardinal;[internproc:fpc_in_bsr_x];
and also dword, qword in trunk versions which are afaik somewhat like clz/ctz, though the error on no bit is different. See attached help page. ffs might be clz on not value.
But in general intrinsics are only added when they are actually used.
Title: Re: 128 bit integers
Post by: julkas on June 17, 2019, 03:06:45 pm