-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
BitOps.pas
10281 lines (8554 loc) · 304 KB
/
BitOps.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{-------------------------------------------------------------------------------
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
-------------------------------------------------------------------------------}
{===============================================================================
BitOps
Set of functions providing some of the not-so-common bit-manipulating
operations and other binary utilities.
Version 1.22 (2024-05-31)
Last change 2024-05-31
©2014-2024 František Milt
Contacts:
František Milt: [email protected]
Support:
If you find this code useful, please consider supporting its author(s) by
making a small donation using the following link(s):
https://www.paypal.me/FMilt
Changelog:
For detailed changelog and history please refer to this git repository:
github.com/TheLazyTomcat/Lib.BitOps
Dependencies:
* AuxExceptions - github.com/TheLazyTomcat/Lib.AuxExceptions
AuxTypes - github.com/TheLazyTomcat/Lib.AuxTypes
BasicUIM - github.com/TheLazyTomcat/Lib.BasicUIM
* SimpleCPUID - github.com/TheLazyTomcat/Lib.SimpleCPUID
Library AuxExceptions is required only when rebasing local exception classes
(see symbol BitOps_UseAuxExceptions for details).
SimpleCPUID is required only when PurePascal symbol is not defined.
Libraries AuxExceptions and SimpleCPUID might also be required as an indirect
dependencies.
Indirect dependencies:
StrRect - github.com/TheLazyTomcat/Lib.StrRect
UInt64Utils - github.com/TheLazyTomcat/Lib.UInt64Utils
WinFileInfo - github.com/TheLazyTomcat/Lib.WinFileInfo
===============================================================================}
unit BitOps;
{
BitOps_PurePascal
If you want to compile this unit without ASM, don't want to or cannot define
PurePascal for the entire project and at the same time you don't want to or
cannot make changes to this unit, define this symbol for the entire project
and only this unit will be compiled in PurePascal mode.
}
{$IFDEF BitOps_PurePascal}
{$DEFINE PurePascal}
{$ENDIF}
{
BitOps_UseAuxExceptions
If you want library-specific exceptions to be based on more advanced classes
provided by AuxExceptions library instead of basic Exception class, and don't
want to or cannot change code in this unit, you can define global symbol
BitOps_UseAuxExceptions to achieve this.
}
{$IF Defined(BitOps_UseAuxExceptions)}
{$DEFINE UseAuxExceptions}
{$IFEND}
//------------------------------------------------------------------------------
{$IF defined(CPU64) or defined(CPU64BITS)}
{$DEFINE CPU64bit}
{$ELSEIF defined(CPU16)}
{$MESSAGE FATAL '16bit CPU not supported'}
{$ELSE}
{$DEFINE CPU32bit}
{$IFEND}
{$IF defined(CPUX86_64) or defined(CPUX64)}
{$DEFINE x64}
{$ELSEIF defined(CPU386)}
{$DEFINE x86}
{$ELSE}
{$DEFINE PurePascal}
{$IFEND}
{$IF Defined(WINDOWS) or Defined(MSWINDOWS)}
{$DEFINE Windows}
{$IFEND}
{$IFDEF FPC}
{$MODE ObjFPC}
{$MODESWITCH ClassicProcVars+}
{$INLINE ON}
{$DEFINE CanInline}
{$IFNDEF PurePascal}
{$ASMMODE Intel}
{$ENDIF}
{$DEFINE FPC_DisableWarns}
{$MACRO ON}
{$ELSE}
{$IF CompilerVersion >= 17} // Delphi 2005+
{$DEFINE CanInline}
{$ELSE}
{$UNDEF CanInline}
{$IFEND}
{$ENDIF}
{$H+}
{$IFOPT Q+}
{$DEFINE OverflowChecks}
{$ENDIF}
//------------------------------------------------------------------------------
{
UseLookupTable
When defined, PopCount functions will, in their PurePascal version, use
lookup table instead of testing each bit in a passed value.
Defined by default.
To disable/undefine this symbol in a project without changing this library,
define project-wide symbol BitOps_UseLookupTable_Off.
}
{$DEFINE UseLookupTable}
{$IFDEF BitOps_UseLookupTable_Off}
{$UNDEF UseLookupTable}
{$ENDIF}
{
AllowASMExtensions
Allows use of x86(-64) instruction extensions in ASM.
When defined, availability of each extension is tested at unit initialization.
The instructions are used only when proper extension is supported. When it is
not, pascal form of the function is called instead.
Currently used extensions:
CMOV - ParallelBitsDeposit(CMOVcc)[32b,p64]
POPCNT - PopCount, ParallelBitsExtract[32b,p64], ParallelBitsDeposit[32b,p64]
LZCNT - LZCount
BMI1 - TZCount(TZCNT), ExtractBits(BEXTR)
BMI2 - ParallelBitsExtract(PEXT), ParallelBitsDeposit(PDEP)
[32b] = 32bit ASM variant of the function
[p64] = function accepting 64bit values
(ins) = ins is a specific used instruction from the extension set
Defined by default.
To disable/undefine this symbol in a project without changing this library,
define project-wide symbol BitOps_AllowASMExtensions_Off.
}
{$DEFINE AllowASMExtensions}
{$IFDEF BitOps_AllowASMExtensions_Off}
{$UNDEF AllowASMExtensions}
{$ENDIF}
//------------------------------------------------------------------------------
// do not touch following...
{$IF not Defined(PurePascal) and Defined(AllowASMExtensions)}
{$DEFINE ASM_Extensions}
{$ELSE}
{$UNDEF ASM_Extensions}
{$IFEND}
interface
uses
SysUtils,
AuxTypes{$IFDEF UseAuxExceptions}, AuxExceptions{$ENDIF};
{===============================================================================
Library-specific exceptions
===============================================================================}
type
EBOException = class({$IFDEF UseAuxExceptions}EAEGeneralException{$ELSE}Exception{$ENDIF});
EBOUnknownFunction = class(EBOException);
EBONoImplementation = class(EBOException);
EBOInvalidValue = class(EBOException);
EBOUnsupportedPlatform = class(EBOException);
EBOConversionError = class(EBOException);
EBOInvalidCharacter = class(EBOConversionError);
EBOBufferTooSmall = class(EBOConversionError);
EBOSizeMismatch = class(EBOConversionError);
{===============================================================================
--------------------------------------------------------------------------------
Binary data <-> string conversions
--------------------------------------------------------------------------------
===============================================================================}
{-------------------------------------------------------------------------------
================================================================================
Integer number <-> Bit string conversions
================================================================================
-------------------------------------------------------------------------------}
{
Following functions are converting numbers (unsigned integers) to their bit
string representations and back. Bit string here means a string, where each
character represents one particular bit from the number.
The resulting string is ordered from the most significant (highest) bit (on
the left side) to the least significant (lowest) bit (on the right side).
The string can be split into groups of bits when a better readability is
required, and both bit characters and splitting character can be user defined.
}
type
TBitStringSplit = (bssNone,bss4bits,bss8bits,bss16bits,bss32bits);
TBitStringFormat = record
Split: TBitStringSplit;
SetBitChar: Char;
ZeroBitChar: Char;
SplitChar: Char;
end;
const
DefBitStringFormat: TBitStringFormat = (
Split: bssNone;
SetBitChar: '1';
ZeroBitChar: '0';
SplitChar: ' ');
//------------------------------------------------------------------------------
Function NumberToBitStr(Number: UInt8; BitStringFormat: TBitStringFormat): String; overload;
Function NumberToBitStr(Number: UInt16; BitStringFormat: TBitStringFormat): String; overload;
Function NumberToBitStr(Number: UInt32; BitStringFormat: TBitStringFormat): String; overload;
Function NumberToBitStr(Number: UInt64; BitStringFormat: TBitStringFormat): String; overload;
Function NumberToBitStr(Number: UInt8; Split: TBitStringSplit): String; overload;
Function NumberToBitStr(Number: UInt16; Split: TBitStringSplit): String; overload;
Function NumberToBitStr(Number: UInt32; Split: TBitStringSplit): String; overload;
Function NumberToBitStr(Number: UInt64; Split: TBitStringSplit): String; overload;
Function NumberToBitStr(Number: UInt8): String; overload;
Function NumberToBitStr(Number: UInt16): String; overload;
Function NumberToBitStr(Number: UInt32): String; overload;
Function NumberToBitStr(Number: UInt64): String; overload;
//------------------------------------------------------------------------------
Function BitStrToNumber(const BitString: String; BitStringFormat: TBitStringFormat): UInt64; overload;
Function BitStrToNumber(const BitString: String; Split: TBitStringSplit): UInt64; overload;
Function BitStrToNumber(const BitString: String): UInt64; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function TryBitStrToNumber(const BitString: String; out Value: UInt8; BitStringFormat: TBitStringFormat): Boolean; overload;
Function TryBitStrToNumber(const BitString: String; out Value: UInt16; BitStringFormat: TBitStringFormat): Boolean; overload;
Function TryBitStrToNumber(const BitString: String; out Value: UInt32; BitStringFormat: TBitStringFormat): Boolean; overload;
Function TryBitStrToNumber(const BitString: String; out Value: UInt64; BitStringFormat: TBitStringFormat): Boolean; overload;
Function TryBitStrToNumber(const BitString: String; out Value: UInt8; Split: TBitStringSplit): Boolean; overload;
Function TryBitStrToNumber(const BitString: String; out Value: UInt16; Split: TBitStringSplit): Boolean; overload;
Function TryBitStrToNumber(const BitString: String; out Value: UInt32; Split: TBitStringSplit): Boolean; overload;
Function TryBitStrToNumber(const BitString: String; out Value: UInt64; Split: TBitStringSplit): Boolean; overload;
Function TryBitStrToNumber(const BitString: String; out Value: UInt8): Boolean; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function TryBitStrToNumber(const BitString: String; out Value: UInt16): Boolean; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function TryBitStrToNumber(const BitString: String; out Value: UInt32): Boolean; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function TryBitStrToNumber(const BitString: String; out Value: UInt64): Boolean; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function BitStrToNumberDef(const BitString: String; Default: UInt64; BitStringFormat: TBitStringFormat): UInt64; overload;
Function BitStrToNumberDef(const BitString: String; Default: UInt64; Split: TBitStringSplit): UInt64; overload;
Function BitStrToNumberDef(const BitString: String; Default: UInt64): UInt64; overload;
{-------------------------------------------------------------------------------
================================================================================
Integer number <-> Octal string conversions
================================================================================
-------------------------------------------------------------------------------}
{
Following functions are converting unsigned numbers to their octal (base-8)
representation and back.
}
Function NumberToOctStr(Number: UInt8): String; overload;
Function NumberToOctStr(Number: UInt16): String; overload;
Function NumberToOctStr(Number: UInt32): String; overload;
Function NumberToOctStr(Number: UInt64): String; overload;
//------------------------------------------------------------------------------
Function OctStrToNumber(const OctString: String): UInt64;
//------------------------------------------------------------------------------
Function TryOctStrToNumber(const OctString: String; out Value: UInt8): Boolean; overload;
Function TryOctStrToNumber(const OctString: String; out Value: UInt16): Boolean; overload;
Function TryOctStrToNumber(const OctString: String; out Value: UInt32): Boolean; overload;
Function TryOctStrToNumber(const OctString: String; out Value: UInt64): Boolean; overload;
//------------------------------------------------------------------------------
Function OctStrToNumberDef(const OctString: String; Default: UInt64): UInt64;
{-------------------------------------------------------------------------------
================================================================================
General data <-> Hex string conversions
================================================================================
-------------------------------------------------------------------------------}
{
Functions converting general data (buffer or array of bytes) to hexadecimal
representation and back.
The resulting string contains pair of hexadecimal numbers (0..9,a..f), where
each pair represents one byte. These pairs appear in the order they have in
the source data (first byte is to the left in the string, last byte is to
the right). But note that the pairs themselwes are ordered from from most
significant nibble to the least significant (ie. left character represents
higher four bits of the byte, right character represents lower four bits).
The string can be split for better readability, you can select splitting
character and whether the hexadecimal chars will be of lower or upper case.
}
type
THexStringSplit = (hssNone,hssNibble,hssByte,hssWord,hss24bits,hssLong,
hssQuad,hss80bits,hssOcta);
THexStringFormat = record
Split: THexStringSplit;
SplitChar: Char;
UpperCase: Boolean;
end;
const
DefHexStringFormat: THexStringFormat = (
Split: hssNone;
SplitChar: ' ';
UpperCase: True);
type
TArrayOfBytes = packed array of UInt8;
//------------------------------------------------------------------------------
Function DataToHexStr(const Buffer; Size: TMemSize; HexStringFormat: THexStringFormat): String; overload;
Function DataToHexStr(Arr: array of UInt8; HexStringFormat: THexStringFormat): String; overload;
Function DataToHexStr(const Buffer; Size: TMemSize; Split: THexStringSplit): String; overload;
Function DataToHexStr(Arr: array of UInt8; Split: THexStringSplit): String; overload;
Function DataToHexStr(const Buffer; Size: TMemSize): String; overload;
Function DataToHexStr(Arr: array of UInt8): String; overload;
//------------------------------------------------------------------------------
Function HexStrToData(const Str: String; out Buffer; Size: TMemSize; HexStringFormat: THexStringFormat): TMemSize; overload;
Function HexStrToData(const Str: String; HexStringFormat: THexStringFormat): TArrayOfBytes; overload;
Function HexStrToData(const Str: String; out Buffer; Size: TMemSize; SplitChar: Char): TMemSize; overload;
Function HexStrToData(const Str: String; SplitChar: Char): TArrayOfBytes; overload;
Function HexStrToData(const Str: String; out Buffer; Size: TMemSize): TMemSize; overload;
Function HexStrToData(const Str: String): TArrayOfBytes; overload;{$IFDEF CanInline} inline; {$ENDIF}
//------------------------------------------------------------------------------
Function TryHexStrToData(const Str: String; out Buffer; var Size: TMemSize; HexStringFormat: THexStringFormat): Boolean; overload;
Function TryHexStrToData(const Str: String; out Arr: TArrayOfBytes; HexStringFormat: THexStringFormat): Boolean; overload;
Function TryHexStrToData(const Str: String; out Buffer; var Size: TMemSize; SplitChar: Char): Boolean; overload;
Function TryHexStrToData(const Str: String; out Arr: TArrayOfBytes; SplitChar: Char): Boolean; overload;
Function TryHexStrToData(const Str: String; out Buffer; var Size: TMemSize): Boolean; overload;
Function TryHexStrToData(const Str: String; out Arr: TArrayOfBytes): Boolean; overload;{$IFDEF CanInline} inline; {$ENDIF}
{-------------------------------------------------------------------------------
================================================================================
General data <-> Bit string conversions
================================================================================
-------------------------------------------------------------------------------}
{
Conversion of general data to its bit string representation and back.
The resulting string can be split for better readability and the splitting
character can be selected.
It is possible to define order in which the bytes appear in the bit string
as well as order of bits within the individual bytes (groups of eight
chracters). Let's have an example:
Data(hex): 82 A3
bytes L2R, bits L2R ... 01000001 11000101
bytes L2R, bits R2L ... 10000010 10100011
bytes R2L, bits L2R ... 11000101 01000001
bytes R2L, bits R2L ... 10100011 10000010
}
type
TBitStringOrder = (bsoLeftToRight,bsoRightToLeft);
TDataBitStringFormat = record
Split: TBitStringSplit;
SplitChar: Char;
BytesOrder: TBitStringOrder;
BitsInByteOrder: TBitStringOrder;
end;
const
DefDataBitStringFormat: TDataBitStringFormat = (
Split: bssNone;
SplitChar: ' ';
BytesOrder: bsoLeftToRight;
BitsInByteOrder: bsoLeftToRight);
//------------------------------------------------------------------------------
Function DataToBitStr(const Buffer; Size: TMemSize; BitStringFormat: TDataBitStringFormat): String; overload;
Function DataToBitStr(Arr: array of UInt8; BitStringFormat: TDataBitStringFormat): String; overload;
Function DataToBitStr(const Buffer; Size: TMemSize; Split: TBitStringSplit): String; overload;
Function DataToBitStr(Arr: array of UInt8; Split: TBitStringSplit): String; overload;
Function DataToBitStr(const Buffer; Size: TMemSize): String; overload;
Function DataToBitStr(Arr: array of UInt8): String; overload;
//------------------------------------------------------------------------------
Function BitStrToData(const Str: String; out Buffer; Size: TMemSize; BitStringFormat: TDataBitStringFormat): TMemSize; overload;
Function BitStrToData(const Str: String; BitStringFormat: TDataBitStringFormat): TArrayOfBytes; overload;
Function BitStrToData(const Str: String; out Buffer; Size: TMemSize; SplitChar: Char): TMemSize; overload;
Function BitStrToData(const Str: String; SplitChar: Char): TArrayOfBytes; overload;
Function BitStrToData(const Str: String; out Buffer; Size: TMemSize): TMemSize; overload;
Function BitStrToData(const Str: String): TArrayOfBytes; overload;{$IFDEF CanInline} inline; {$ENDIF}
//------------------------------------------------------------------------------
Function TryBitStrToData(const Str: String; out Buffer; var Size: TMemSize; BitStringFormat: TDataBitStringFormat): Boolean; overload;
Function TryBitStrToData(const Str: String; out Arr: TArrayOfBytes; BitStringFormat: TDataBitStringFormat): Boolean; overload;
Function TryBitStrToData(const Str: String; out Buffer; var Size: TMemSize; SplitChar: Char): Boolean; overload;
Function TryBitStrToData(const Str: String; out Arr: TArrayOfBytes; SplitChar: Char): Boolean; overload;
Function TryBitStrToData(const Str: String; out Buffer; var Size: TMemSize): Boolean; overload;
Function TryBitStrToData(const Str: String; out Arr: TArrayOfBytes): Boolean; overload;{$IFDEF CanInline} inline; {$ENDIF}
{===============================================================================
--------------------------------------------------------------------------------
Bit-level manipulations
--------------------------------------------------------------------------------
===============================================================================}
{-------------------------------------------------------------------------------
================================================================================
Rotate left (ROL)
================================================================================
-------------------------------------------------------------------------------}
{
Rotates the number left - that is, the number is shifted left (towards higher
places) by a selected amount of bits, while the shifted-out bits are inserted
to the right (lower places).
Assembly implementation uses instruction ROL.
Only lower 3, 4, 5 or 6 bits of the shift, depending on the argument size,
are used (the ASM version masks 5 or 6 bits, but the result is the same).
}
Function ROL(Value: UInt8; Shift: Integer): UInt8; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function ROL(Value: UInt16; Shift: Integer): UInt16; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function ROL(Value: UInt32; Shift: Integer): UInt32; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function ROL(Value: UInt64; Shift: Integer): UInt64; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
//------------------------------------------------------------------------------
procedure ROLValue(var Value: UInt8; Shift: Integer); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure ROLValue(var Value: UInt16; Shift: Integer); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure ROLValue(var Value: UInt32; Shift: Integer); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure ROLValue(var Value: UInt64; Shift: Integer); overload;{$IFDEF CanInline} inline;{$ENDIF}
{-------------------------------------------------------------------------------
================================================================================
Rotate right (ROR)
================================================================================
-------------------------------------------------------------------------------}
{
Rotates the number right - the number is shifted right (towards lower places)
by a selected amount of bits, while the shifted-out bits are inserted to the
left (higher places).
Assembly implementation uses instruction ROR.
Only lower 3, 4, 5 or 6 bits of the shift, depending on the argument size,
are used (the ASM version masks 5 or 6 bits, but the result is the same).
}
Function ROR(Value: UInt8; Shift: Integer): UInt8; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function ROR(Value: UInt16; Shift: Integer): UInt16; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function ROR(Value: UInt32; Shift: Integer): UInt32; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function ROR(Value: UInt64; Shift: Integer): UInt64; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
//------------------------------------------------------------------------------
procedure RORValue(var Value: UInt8; Shift: Integer); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure RORValue(var Value: UInt16; Shift: Integer); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure RORValue(var Value: UInt32; Shift: Integer); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure RORValue(var Value: UInt64; Shift: Integer); overload;{$IFDEF CanInline} inline;{$ENDIF}
{-------------------------------------------------------------------------------
================================================================================
Rotate left with carry (RCL)
================================================================================
-------------------------------------------------------------------------------}
{
Rotates the number left with carry - works the same as ROL, but the number
is being rotated trough carry flag, effectively making it n + 1 bits wide.
When the number is shifted, the bit shifted in is taken from carry flag and
bit shifted out is stored back in the carry flag.
First shifted-in bit is taken from the parameter CF, and the last shifted-out
bit is returned again in the CF.
For example...
original number: 01001100 (0x4C)
original carry: 1
rotating left by 3 places...
resulting number: 01100101 (0x65)
resulting carry: 0
Assembly implementation uses instruction RCL.
Only lower 5 bits (for 8bit, 16bit and 32bit numbers) or 6 bits (for 64bit
numbers) of the shift are used.
}
Function RCLCarry(Value: UInt8; Shift: Integer; var CF: Boolean): UInt8; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function RCLCarry(Value: UInt16; Shift: Integer; var CF: Boolean): UInt16; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function RCLCarry(Value: UInt32; Shift: Integer; var CF: Boolean): UInt32; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function RCLCarry(Value: UInt64; Shift: Integer; var CF: Boolean): UInt64; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
//------------------------------------------------------------------------------
Function RCL(Value: UInt8; Shift: Integer; CF: Boolean = False): UInt8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function RCL(Value: UInt16; Shift: Integer; CF: Boolean = False): UInt16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function RCL(Value: UInt32; Shift: Integer; CF: Boolean = False): UInt32; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function RCL(Value: UInt64; Shift: Integer; CF: Boolean = False): UInt64; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
procedure RCLValueCarry(var Value: UInt8; Shift: Integer; var CF: Boolean); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure RCLValueCarry(var Value: UInt16; Shift: Integer; var CF: Boolean); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure RCLValueCarry(var Value: UInt32; Shift: Integer; var CF: Boolean); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure RCLValueCarry(var Value: UInt64; Shift: Integer; var CF: Boolean); overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
procedure RCLValue(var Value: UInt8; Shift: Integer; CF: Boolean = False); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure RCLValue(var Value: UInt16; Shift: Integer; CF: Boolean = False); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure RCLValue(var Value: UInt32; Shift: Integer; CF: Boolean = False); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure RCLValue(var Value: UInt64; Shift: Integer; CF: Boolean = False); overload;{$IFDEF CanInline} inline;{$ENDIF}
{-------------------------------------------------------------------------------
================================================================================
Rotate right with carry (RCR)
================================================================================
-------------------------------------------------------------------------------}
{
Rotates the number right with carry - works the same as ROR, but the number
is being shifted trough carry flag. See description of RCL for more info.
Assembly implementation uses instruction RCR.
Only lower 5 bits (for 8bit, 16bit and 32bit numbers) or 6 bits (for 64bit
numbers) of the shift are used.
}
Function RCRCarry(Value: UInt8; Shift: Integer; var CF: Boolean): UInt8; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function RCRCarry(Value: UInt16; Shift: Integer; var CF: Boolean): UInt16; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function RCRCarry(Value: UInt32; Shift: Integer; var CF: Boolean): UInt32; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function RCRCarry(Value: UInt64; Shift: Integer; var CF: Boolean): UInt64; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
//------------------------------------------------------------------------------
Function RCR(Value: UInt8; Shift: Integer; CF: Boolean = False): UInt8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function RCR(Value: UInt16; Shift: Integer; CF: Boolean = False): UInt16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function RCR(Value: UInt32; Shift: Integer; CF: Boolean = False): UInt32; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function RCR(Value: UInt64; Shift: Integer; CF: Boolean = False): UInt64; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
procedure RCRValueCarry(var Value: UInt8; Shift: Integer; var CF: Boolean); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure RCRValueCarry(var Value: UInt16; Shift: Integer; var CF: Boolean); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure RCRValueCarry(var Value: UInt32; Shift: Integer; var CF: Boolean); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure RCRValueCarry(var Value: UInt64; Shift: Integer; var CF: Boolean); overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
procedure RCRValue(var Value: UInt8; Shift: Integer; CF: Boolean = False); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure RCRValue(var Value: UInt16; Shift: Integer; CF: Boolean = False); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure RCRValue(var Value: UInt32; Shift: Integer; CF: Boolean = False); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure RCRValue(var Value: UInt64; Shift: Integer; CF: Boolean = False); overload;{$IFDEF CanInline} inline;{$ENDIF}
{-------------------------------------------------------------------------------
================================================================================
Arithmetic left shift (SAL)
================================================================================
-------------------------------------------------------------------------------}
{
This operation is identical to logical left shift (SHL).
Assembly implementation uses instruction SAL.
Only lower 5 bits (for 8bit, 16bit and 32bit numbers) or 6 bits (for 64bit
numbers) of the shift are used.
}
Function SAL(Value: UInt8; Shift: Integer): UInt8; overload;{$IFDEF PurePascal}{$IFDEF CanInline} inline;{$ENDIF}{$ELSE} register; assembler;{$ENDIF}
Function SAL(Value: UInt16; Shift: Integer): UInt16; overload;{$IFDEF PurePascal}{$IFDEF CanInline} inline;{$ENDIF}{$ELSE} register; assembler;{$ENDIF}
Function SAL(Value: UInt32; Shift: Integer): UInt32; overload;{$IFDEF PurePascal}{$IFDEF CanInline} inline;{$ENDIF}{$ELSE} register; assembler;{$ENDIF}
Function SAL(Value: UInt64; Shift: Integer): UInt64; overload;{$IFDEF PurePascal}{$IFDEF CanInline} inline;{$ENDIF}{$ELSE} register; assembler;{$ENDIF}
//------------------------------------------------------------------------------
procedure SALValue(var Value: UInt8; Shift: Integer); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure SALValue(var Value: UInt16; Shift: Integer); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure SALValue(var Value: UInt32; Shift: Integer); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure SALValue(var Value: UInt64; Shift: Integer); overload;{$IFDEF CanInline} inline;{$ENDIF}
{-------------------------------------------------------------------------------
================================================================================
Arithmetic right shift (SAR)
================================================================================
-------------------------------------------------------------------------------}
{
Shifts the number to the right (towards lower bits), while preserving the
highest bit. For example...
number 10010100
SAR by 3...
result 11110010
Assembly implementation uses instruction SAR.
Only lower 5 bits (for 8bit, 16bit and 32bit numbers) or 6 bits (for 64bit
numbers) of the shift are used.
}
Function SAR(Value: UInt8; Shift: Integer): UInt8; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function SAR(Value: UInt16; Shift: Integer): UInt16; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function SAR(Value: UInt32; Shift: Integer): UInt32; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function SAR(Value: UInt64; Shift: Integer): UInt64; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
//------------------------------------------------------------------------------
procedure SARValue(var Value: UInt8; Shift: Integer); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure SARValue(var Value: UInt16; Shift: Integer); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure SARValue(var Value: UInt32; Shift: Integer); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure SARValue(var Value: UInt64; Shift: Integer); overload;{$IFDEF CanInline} inline;{$ENDIF}
{-------------------------------------------------------------------------------
================================================================================
Endianity swap
================================================================================
-------------------------------------------------------------------------------}
{
Reverses order of bytes within the number or general data buffer.
Assembly implementation uses instruction BSWAP.
}
Function EndianSwap(Value: UInt16): UInt16; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function EndianSwap(Value: UInt32): UInt32; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function EndianSwap(Value: UInt64): UInt64; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function SwapEndian(Value: UInt16): UInt16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function SwapEndian(Value: UInt32): UInt32; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function SwapEndian(Value: UInt64): UInt64; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
procedure EndianSwapValue(var Value: UInt16); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure EndianSwapValue(var Value: UInt32); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure EndianSwapValue(var Value: UInt64); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure SwapEndianValue(var Value: UInt16); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure SwapEndianValue(var Value: UInt32); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure SwapEndianValue(var Value: UInt64); overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
procedure EndianSwap(var Buffer; Size: TMemSize); overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
procedure SwapEndian(var Buffer; Size: TMemSize); overload;
//------------------------------------------------------------------------------
{
Reverses byte order of individial items in a given array or vector.
Number in the name denotes size of items in bits. Function without number
accepts an explicitly given item size (in bytes).
Argument Arr should point to the first element/item in the array.
Count gives number of items in the array (NOT its size in bytes).
}
procedure EndianSwapItems16(var Arr; Count: TMemSize);{$IFNDEF PurePascal} register; assembler;{$ENDIF}
procedure EndianSwapItems32(var Arr; Count: TMemSize);{$IFNDEF PurePascal} register; assembler;{$ENDIF}
procedure EndianSwapItems64(var Arr; Count: TMemSize);{$IFNDEF PurePascal} register; assembler;{$ENDIF}
procedure EndianSwapItems(var Arr; ItemSize,Count: TMemSize);
procedure SwapEndianItems16(var Arr; Count: TMemSize);
procedure SwapEndianItems32(var Arr; Count: TMemSize);
procedure SwapEndianItems64(var Arr; Count: TMemSize);
procedure SwapEndianItems(var Arr; ItemSize,Count: TMemSize);
{-------------------------------------------------------------------------------
================================================================================
Bit test (BT)
================================================================================
-------------------------------------------------------------------------------}
{
Returns true when selected bit in the Value is set, false when it is clear.
Assembly implementation uses instruction BT.
The bit number/index is taken modulo 8, 16, 32 or 64, depending on argument
width.
}
Function BT(Value: UInt8; Bit: Integer): Boolean; overload;{$IFDEF PurePascal}{$IFDEF CanInline} inline;{$ENDIF}{$ELSE} register; assembler;{$ENDIF}
Function BT(Value: UInt16; Bit: Integer): Boolean; overload;{$IFDEF PurePascal}{$IFDEF CanInline} inline;{$ENDIF}{$ELSE} register; assembler;{$ENDIF}
Function BT(Value: UInt32; Bit: Integer): Boolean; overload;{$IFDEF PurePascal}{$IFDEF CanInline} inline;{$ENDIF}{$ELSE} register; assembler;{$ENDIF}
Function BT(Value: UInt64; Bit: Integer): Boolean; overload;{$IFDEF PurePascal}{$IFDEF CanInline} inline;{$ENDIF}{$ELSE} register; assembler;{$ENDIF}
{-------------------------------------------------------------------------------
================================================================================
Bit test and set (BTS)
================================================================================
-------------------------------------------------------------------------------}
{
Sets the selected bit in the Value (to 1) and returns true when the bit was
previously set, false when it was clear.
Assembly implementation uses instruction BTS.
The bit number/index is taken modulo 8, 16, 32 or 64, depending on argument
width.
}
Function BTS(var Value: UInt8; Bit: Integer): Boolean; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function BTS(var Value: UInt16; Bit: Integer): Boolean; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function BTS(var Value: UInt32; Bit: Integer): Boolean; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function BTS(var Value: UInt64; Bit: Integer): Boolean; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
{-------------------------------------------------------------------------------
================================================================================
Bit test and reset (BTR)
================================================================================
-------------------------------------------------------------------------------}
{
Resets the selected bit in the Value (to 0) and returns true when the bit was
previously set, false when it was clear.
Assembly implementation uses instruction BTR.
The bit number/index is taken modulo 8, 16, 32 or 64, depending on argument
width.
}
Function BTR(var Value: UInt8; Bit: Integer): Boolean; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function BTR(var Value: UInt16; Bit: Integer): Boolean; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function BTR(var Value: UInt32; Bit: Integer): Boolean; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function BTR(var Value: UInt64; Bit: Integer): Boolean; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
{-------------------------------------------------------------------------------
================================================================================
Bit test and complement (BTC)
================================================================================
-------------------------------------------------------------------------------}
{
Complements the selected bit in the Value (swaps its state, 0 <-> 1) and
returns true when the bit was previously set, false when it was clear.
Assembly implementation uses instruction BTC.
The bit number/index is taken modulo 8, 16, 32 or 64, depending on argument
width.
}
Function BTC(var Value: UInt8; Bit: Integer): Boolean; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function BTC(var Value: UInt16; Bit: Integer): Boolean; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function BTC(var Value: UInt32; Bit: Integer): Boolean; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function BTC(var Value: UInt64; Bit: Integer): Boolean; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
{-------------------------------------------------------------------------------
================================================================================
Bit test and set to a given value
================================================================================
-------------------------------------------------------------------------------}
{
Sets value of the selected bit in the number given in Value to a NewValue and
returns its previous state.
The bit number/index is taken modulo 8, 16, 32 or 64, depending on argument
width.
}
Function BitSetTo(var Value: UInt8; Bit: Integer; NewValue: Boolean): Boolean; overload;
Function BitSetTo(var Value: UInt16; Bit: Integer; NewValue: Boolean): Boolean; overload;
Function BitSetTo(var Value: UInt32; Bit: Integer; NewValue: Boolean): Boolean; overload;
Function BitSetTo(var Value: UInt64; Bit: Integer; NewValue: Boolean): Boolean; overload;
{-------------------------------------------------------------------------------
================================================================================
Bit scan forward (BSF)
================================================================================
-------------------------------------------------------------------------------}
{
Returns index of lowest set (1) bit in the passed number. If no bit is set,
then -1 is returned.
Assembly implementation uses instruction BSF.
}
Function BSF(Value: UInt8): Integer; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function BSF(Value: UInt16): Integer; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function BSF(Value: UInt32): Integer; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function BSF(Value: UInt64): Integer; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
{-------------------------------------------------------------------------------
================================================================================
Bit scan reversed (BSR)
================================================================================
-------------------------------------------------------------------------------}
{
Returns index of highest set bit in the passed number. If no bit is set, then
-1 is returned.
Assembly implementation uses instruction BSR.
}
Function BSR(Value: UInt8): Integer; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function BSR(Value: UInt16): Integer; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function BSR(Value: UInt32): Integer; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function BSR(Value: UInt64): Integer; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
{-------------------------------------------------------------------------------
================================================================================
Population count
================================================================================
-------------------------------------------------------------------------------}
{
Returns number of set (1) bits in the passed number. When no bit is set, it
will return 0.
Assembly implementation uses instruction POPCNT.
}
Function PopCount(Value: UInt8): Integer; overload;
Function PopCount(Value: UInt16): Integer; overload;
Function PopCount(Value: UInt32): Integer; overload;
Function PopCount(Value: UInt64): Integer; overload;
{-------------------------------------------------------------------------------
================================================================================
Nibble manipulation
================================================================================
-------------------------------------------------------------------------------}
{
Following funtions are meant for obtaining or changing lower or higher
nibbles (half bytes, 4bit halfs) within one byte (an octet).
}
Function GetHighNibble(Value: UInt8): TNibble;{$IFDEF CanInline} inline;{$ENDIF}
Function GetLowNibble(Value: UInt8): TNibble;{$IFDEF CanInline} inline;{$ENDIF}
Function SetHighNibble(Value: UInt8; SetTo: TNibble): UInt8;{$IFDEF CanInline} inline;{$ENDIF}
Function SetLowNibble(Value: UInt8; SetTo: TNibble): UInt8;{$IFDEF CanInline} inline;{$ENDIF}
procedure SetHighNibbleValue(var Value: UInt8; SetTo: TNibble);{$IFDEF CanInline} inline;{$ENDIF}
procedure SetLowNibbleValue(var Value: UInt8; SetTo: TNibble);{$IFDEF CanInline} inline;{$ENDIF}
{-------------------------------------------------------------------------------
================================================================================
Get flag state
================================================================================
-------------------------------------------------------------------------------}
{
When exact match is false, the following function will return true when at
least one bit set in FlagBitmask is also set in the Value, false otherwise.
When exact match is true, then true is returned only when all bits set in the
FlagBitmask are also set in Value, false otherwise.
}
Function GetFlagState(Value,FlagBitmask: UInt8; ExactMatch: Boolean = False): Boolean; overload;
Function GetFlagState(Value,FlagBitmask: UInt16; ExactMatch: Boolean = False): Boolean; overload;
Function GetFlagState(Value,FlagBitmask: UInt32; ExactMatch: Boolean = False): Boolean; overload;
Function GetFlagState(Value,FlagBitmask: UInt64; ExactMatch: Boolean = False): Boolean; overload;
{-------------------------------------------------------------------------------
================================================================================
Set flag
================================================================================
-------------------------------------------------------------------------------}
{
Bits set in the FlagBitmask are also set (to 1) in the passed number and this
resulting number is then returned.
Functions accepting array of flags will set all bits within all the passed
flag bistmasks.
Functions with bits noted in name (*_8, *_16, ...) are there mainly for older
versions of Delphi (up to Delphi 2007), because they are not able to
distinguish what overloaded function to call (some problem with open array
parameter parsing).
}
Function SetFlag(Value,FlagBitmask: UInt8): UInt8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function SetFlag(Value,FlagBitmask: UInt16): UInt16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function SetFlag(Value,FlagBitmask: UInt32): UInt32; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function SetFlag(Value,FlagBitmask: UInt64): UInt64; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
procedure SetFlagValue(var Value: UInt8; FlagBitmask: UInt8); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure SetFlagValue(var Value: UInt16; FlagBitmask: UInt16); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure SetFlagValue(var Value: UInt32; FlagBitmask: UInt32); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure SetFlagValue(var Value: UInt64; FlagBitmask: UInt64); overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function SetFlags_8(Value: UInt8; Flags: array of UInt8): UInt8;
Function SetFlags_16(Value: UInt16; Flags: array of UInt16): UInt16;
Function SetFlags_32(Value: UInt32; Flags: array of UInt32): UInt32;
Function SetFlags_64(Value: UInt64; Flags: array of UInt64): UInt64;
//------------------------------------------------------------------------------
Function SetFlags(Value: UInt8; Flags: array of UInt8): UInt8; overload;
Function SetFlags(Value: UInt16; Flags: array of UInt16): UInt16; overload;
Function SetFlags(Value: UInt32; Flags: array of UInt32): UInt32; overload;
Function SetFlags(Value: UInt64; Flags: array of UInt64): UInt64; overload;
//------------------------------------------------------------------------------
procedure SetFlagsValue_8(var Value: UInt8; Flags: array of UInt8);
procedure SetFlagsValue_16(var Value: UInt16; Flags: array of UInt16);
procedure SetFlagsValue_32(var Value: UInt32; Flags: array of UInt32);
procedure SetFlagsValue_64(var Value: UInt64; Flags: array of UInt64);
//------------------------------------------------------------------------------
procedure SetFlagsValue(var Value: UInt8; Flags: array of UInt8); overload;
procedure SetFlagsValue(var Value: UInt16; Flags: array of UInt16); overload;
procedure SetFlagsValue(var Value: UInt32; Flags: array of UInt32); overload;
procedure SetFlagsValue(var Value: UInt64; Flags: array of UInt64); overload;
{-------------------------------------------------------------------------------
================================================================================
Reset flag
================================================================================
-------------------------------------------------------------------------------}
{
Bits set in the FlagBitmask are reset (to 0) in the passed number and this
resulting number is then returned.
Functions accepting array of flags will reset all bits within all the passed
flag bistmasks.
Functions with bits noted in name (*_8, *_16, ...) are there mainly for older
versions of Delphi (up to Delphi 2007), because they are not able to
distinguish what overloaded function to call (some problem with open array