-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fixed-point data types.h
4471 lines (3949 loc) · 305 KB
/
Fixed-point data types.h
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
/**********************************************************************
* File: Fixed-point data types.h Created: 2024/05/11 *
* Last modified: 2024/06/25 *
* *
* Desc: Provides sizes of 8, 16, 24, and 32 bits. All sizes have *
* support for fixed, normalised, and custom value ranges. *
* There are, also, 4-element vectors of the 8 & 16-bit sizes. *
* All data types are listed at the end of this file within *
* typedefs of their constant counterparts. *
* *
* Notes: Define FPDT_NO_CUSTOM before including this file to exclude *
* declarations of variables & functions for types with *
* user-definable ranges. *
* If using those data types, add fpdtInitCustom; to the *
* global space of one of your project's .c/.cpp source files. *
* SSE3 support required. AVX2 and AVX512 support optional. *
* *
* MIT license. Copyright (c) David William Bull. *
**********************************************************************/
#pragma once
#include <immintrin.h>
#include "typedefs.h"
// External _FPDT_DATA_ to be declared in a main .c/.cpp file, required for data types with a user-definable range
#define fpdtInitCustom __declspec(align(16)) __FPDT_DATA__ __fpdt_data__
// For 2-scalar return values
typedef
#ifdef _VECTOR_STRUCTURES_
SSE2Df32
#else
al8 union { struct { fl32 u, v; } struct { fl32 x, y; }; fl32 _fl[2]; }
#endif
f32x2;
// For 3-scalar return values
typedef
#ifdef _VECTOR_STRUCTURES_
VEC3Du16
#else
union { struct { fs7p8 x, y, z; } struct { fs7p8 r, g, b; }; }
#endif
i16x3;
// For 32-byte return values
typedef
#ifdef _VECTOR_STRUCTURES_
AVX8Df32
#else
union { fl32x8 ymm; fl32x4 xmm[2]; fl32 _fl[8]; }
#endif
f32x8;
typedef
#ifdef _VECTOR_STRUCTURES_
AVX16Du16
#else
union { csi256 ymm; csi128 xmm[2]; cui16 _u16[16]; }
#endif
i16x16;
typedef
#ifdef _VECTOR_STRUCTURES_
AVX4Du64
#else
union { csi256 ymm; csi128 xmm[2]; cui64 _u64[4]; }
#endif
i64x4;
// For 64-byte return values
typedef
#ifdef _VECTOR_STRUCTURES_
AVX16Df32
#else
union { fl32x16 zmm; fl32x8 ymm[2]; fl32x4 xmm[4]; fl32 _fl[16]; }
#endif
f32x16;
typedef
#ifdef _VECTOR_STRUCTURES_
AVX16Ds32
#else
union { csi512 zmm; csi256 ymm[2]; csi128 xmm[4]; csi64 _s64[16]; cui64 _u64[16]; }
#endif
i32x16;
typedef const f32x2 cf32x2; // For 2-scalar return values
typedef const i16x3 ci16x3; // For 3-scalar return values
typedef const i64x4 ci64x4; // For 32-byte packed integer return values
typedef const f32x8 cf32x8; // For 32-byte packed floating-point return values
typedef const i16x16 ci16x16; // For 32-byte packed integer return values
typedef const i32x16 ci32x16; // For 64-byte packed integer return values
typedef const f32x16 cf32x16; // For 64-byte packed floating-point return values
#define _FIXED_POINT_DATA_TYPES_
#ifdef __AVX2__
#ifdef __AVX512F__
#define _FPDT_AVX512_
#endif
#define _FPDT_AVX2_
#endif
#ifdef _FPDT_AVX512_
static cfl32x16 _fpdt_65535div3fx16 = _mm512_set1_ps(21845.0f);
static cfl32x16 _fpdt_2div65535fx16 = _mm512_set1_ps(3.0f / 65535.0f);
static cui512 _fpdt_shuffle16sAVX512 = { .m512i_u64 = { 0x00D0C090805040100u, 0x01D1C191815141110u, 0x02D2C292825242120u, 0x03D3C393835343130u, 0, 0, 0, 0 } };
#endif
#ifdef _FPDT_AVX2_
static cfl32x8 _fpdt_65535div3fx8 = _mm256_set1_ps(21845.0f);
static cfl32x8 _fpdt_rcp255fx8 = _mm256_set1_ps(1.0f / 255.0f);
static cfl32x8 _fpdt_3div65535fx8 = _mm256_set1_ps(3.0f / 65535.0f);
static cui256 _fpdt_1x16 = _mm256_set1_epi16(0x01);
static cui128 _fpdt_shuffle16sAVX0 = { .m128i_u64 = { 0x00D0C090805040100u, 0 } };
static cui128 _fpdt_shuffle16sAVX1 = { .m128i_u64 = { 0x01D1C191815141110u, 0 } };
#endif
static cfl32x4 _fpdt_32768fx4 = _mm_set_ps1(32768.0f);
static cfl32x4 _fpdt_65535div2fx4 = _mm_set_ps1(32767.5f);
static cfl32x4 _fpdt_65535fx4 = _mm_set_ps1(65535.0f);
static cfl32x4 _fpdt_256fx4 = _mm_set_ps1(256.0f);
static cfl32x4 _fpdt_255fx4 = _mm_set_ps1(255.0f);
static cfl32x4 _fpdt_128fx4 = _mm_set_ps1(128.0f);
static cfl32x4 _fpdt_rcp255fx4 = _mm_set_ps1(1.0f / 255.0f);
static cfl32x4 _fpdt_rcp256fx4 = _mm_set_ps1(1.0f / 256.0f);
static cfl32x4 _fpdt_rcp32768fx4 = _mm_set_ps1(1.0f / 32768.0f);
static cfl32x4 _fpdt_rcp65535fx4 = _mm_set_ps1(1.0f / 65535.0f);
static cfl32x4 _fpdt_2div65535fx4 = _mm_set_ps1(2.0f / 65535.0f);
static cui128 _fpdt_1x8 = _mm_set1_epi16(0x01);
static cui128 _fpdt_shuffle8s = { .m128i_u64 = { 0x0000000000C080400u, 0 } };
static cui128 _fpdt_shuffle16s = { .m128i_u64 = { 0x00D0C090805040100u, 0 } };
static cfl32 _fpdt_65535div2f = 32767.5f;
static cfl32 _fpdt_65535div128f = 65535.0f / 128.0f;
static cfl32 _fpdt_65535div256f = 65535.0f / 256.0f;
static cfl32 _fpdt_rcp16f = 1.0f / 16.0f;
static cfl32 _fpdt_rcp128f = 1.0f / 128.0f;
static cfl32 _fpdt_rcp255f = 1.0f / 255.0f;
static cfl32 _fpdt_rcp256f = 1.0f / 256.0f;
static cfl32 _fpdt_rcp512f = 1.0f / 512.0f;
static cfl32 _fpdt_rcp1024f = 1.0f / 1024.0f;
static cfl32 _fpdt_rcp4096f = 1.0f / 4096.0f;
static cfl32 _fpdt_rcp16384f = 1.0f / 16384.0f;
static cfl32 _fpdt_rcp32768f = 1.0f / 32768.0f;
static cfl32 _fpdt_rcp65535f = 1.0f / 65535.0f;
static cfl32 _fpdt_rcp65536f = 1.0f / 65536.0f;
static cfl32 _fpdt_rcp2p24_1f = 1.0f / 16777215.0f;
static cfl32 _fpdt_rcp2p24f = 1.0f / 16777216.0f;
static cfl32 _fpdt_3div65535f = 3.0f / 65535.0f;
static cfl32 _fpdt_2div65535f = 2.0f / 65535.0f;
static cfl32 _fpdt_2div2p24_1f = 2.0f / 16777215.0f;
static cfl32 _fpdt_128div65535f = 128.0f / 65535.0f;
static cfl32 _fpdt_256div65535f = 256.0f / 65535.0f;
static cfl64 _fpdt_rcp65536 = 1.0 / 65536.0;
static cfl64 _fpdt_rcp2p32_1 = 1.0 / 4294967295.0;
static cfl64 _fpdt_rcp2p32 = 1.0 / 4294967296.0;
static cfl64 _fpdt_2div2p32_1 = 2.0 / 4294967295.0;
#ifndef FPDT_NO_CUSTOM
// Data for types with a user-defineable range
struct __FPDT_DATA__ {
fl64 origin32 = -1.0;
fl64 range32 = 1.0;
fl64 maxDivRange32 = 4294967295.0;
fl64 rangeDivMax32 = _fpdt_rcp2p32_1;
#ifdef _24BIT_INTEGERS_
fl32 origin24 = -1.0f;
fl32 range24 = 1.0f;
fl32 maxDivRange24 = 16777215.0f;
fl32 rangeDivMax24 = _fpdt_rcp2p24_1f;
#endif
fl32 origin16 = -1.0f;
fl32 range16 = 1.0f;
fl32 maxDivRange16 = 65535.0f;
fl32 rangeDivMax16 = _fpdt_rcp65535f;
fl32 origin8 = -1.0f;
fl32 range8 = 1.0f;
fl32 maxDivRange8 = 255.0f;
fl32 rangeDivMax8 = _fpdt_rcp255f;
};
extern __FPDT_DATA__ __fpdt_data__;
// Normalised 8-bit : User-defineable decimal range
struct fp8n {
typedef const fp8n cfp8n;
ui8 data;
inline cfp8n toFixed(cfl32 &value) const { return (cfp8n &)ui8((value - __fpdt_data__.origin8) * __fpdt_data__.maxDivRange8); }
inline cfl32 toFloat(void) const { return fl32(data) * __fpdt_data__.rangeDivMax8 + __fpdt_data__.origin8; };
inline cfl32 toFloat(cfp8n &value) const { return fl32(value.data) * __fpdt_data__.rangeDivMax8 + __fpdt_data__.origin8; };
inline cui8 toFixedMod(cfp8n &value) const { return (value.data - ui8(__fpdt_data__.origin8 * __fpdt_data__.maxDivRange8)); }
inline cui8 toFixedMod(cfl32 &value) const { return ui8(value * __fpdt_data__.maxDivRange8); }
fp8n(void) = default;
fp8n(cfl32 floor, cfl32 ceiling) {
__fpdt_data__.origin8 = floor;
__fpdt_data__.range8 = ceiling - floor;
__fpdt_data__.maxDivRange8 = 255.0f / __fpdt_data__.range8;
__fpdt_data__.rangeDivMax8 = __fpdt_data__.range8 / 255.0f;
};
fp8n(cfl32 value, cfl32 floor, cfl32 ceiling) {
__fpdt_data__.origin8 = floor;
__fpdt_data__.range8 = ceiling - floor;
__fpdt_data__.maxDivRange8 = 255.0f / __fpdt_data__.range8;
__fpdt_data__.rangeDivMax8 = __fpdt_data__.range8 / 255.0f;
data = ui8((value - floor) * __fpdt_data__.maxDivRange8);
};
fp8n(cui8 value) { data = value; }
fp8n(cui16 value) { data = toFixed(fl32(value) * __fpdt_data__.rangeDivMax16 + __fpdt_data__.origin16).data; }
fp8n(cui32 value) { data = toFixed(fl32(fl64(value) * __fpdt_data__.rangeDivMax32 + __fpdt_data__.origin32)).data; }
fp8n(csi32 value) { data = (ui8 &)value; }
fp8n(cfl32 value) { data = toFixed(value).data; }
fp8n(cfl64 value) { data = ui8((value - fl64(__fpdt_data__.origin8)) * (255.0 / fl64(__fpdt_data__.range8))); }
operator ptr(void) const { return *this; }
operator cfl32(void) const { return fl32(data) * __fpdt_data__.rangeDivMax8 + __fpdt_data__.origin8; };
inline cfp8n &operator&(void) const { return *this; }
inline cfp8n operator~(void) const { return (cfp8n &)~data; }
inline cfp8n operator-(void) const { return (cfp8n &)~data; }
inline cbool operator!(void) const { return data == 0; }
inline cfp8n operator++(void) { data++; return *this; }
inline cfp8n operator++(int) { cui8 temp = data++; return (cfp8n &)temp; }
inline cfp8n operator--(void) { data--; return *this; }
inline cfp8n operator--(int) { cui8 temp = data--; return (cfp8n &)temp; }
inline cfp8n operator<<(csi32 &value) const { return (cfp8n &)(data << value); }
inline cfp8n operator>>(csi32 &value) const { return (cfp8n &)(data >> value); }
inline cfp8n operator<<=(csi32 &value) { return (cfp8n &)(data <<= value); }
inline cfp8n operator>>=(csi32 &value) { return (cfp8n &)(data >>= value); }
inline cbool operator==(cfp8n &value) const { return data == value.data; }
inline cbool operator!=(cfp8n &value) const { return data != value.data; }
inline cbool operator>=(cfp8n &value) const { return data >= value.data; }
inline cbool operator<=(cfp8n &value) const { return data <= value.data; }
inline cbool operator>(cfp8n &value) const { return data > value.data; }
inline cbool operator<(cfp8n &value) const { return data < value.data; }
inline cbool operator||(cfp8n &value) const { return data || value.data; }
inline cbool operator&&(cfp8n &value) const { return data && value.data; }
inline cfp8n operator+(cfp8n &value) const { return (cfp8n &)(data + toFixedMod(value)); }
inline cfp8n operator-(cfp8n &value) const { return (cfp8n &)(data - toFixedMod(value)); }
inline cfp8n operator*(cfp8n &value) const { return toFixed(toFloat() * toFloat(value)); }
inline cfp8n operator/(cfp8n &value) const { return toFixed(toFloat() / toFloat(value)); }
inline cfp8n operator%(cfp8n &value) const { return (cfp8n &)(data % toFixedMod(value)); }
inline cfp8n operator&(cfp8n &value) const { return (cfp8n &)(data & value.data); }
inline cfp8n operator|(cfp8n &value) const { return (cfp8n &)(data | value.data); }
inline cfp8n operator^(cfp8n &value) const { return (cfp8n &)(data ^ value.data); }
inline cfp8n operator+=(cfp8n &value) { return (cfp8n &)(data += toFixedMod(value)); }
inline cfp8n operator-=(cfp8n &value) { return (cfp8n &)(data -= toFixedMod(value)); }
inline cfp8n operator*=(cfp8n &value) { return *this = toFixed(toFloat() * toFloat(value)); }
inline cfp8n operator/=(cfp8n &value) { return *this = toFixed(toFloat() / toFloat(value)); }
inline cfp8n operator%=(cfp8n &value) { return (cfp8n &)(data %= toFixedMod(value)); }
inline cfp8n operator&=(cfp8n &value) { return (cfp8n &)(data &= value.data); }
inline cfp8n operator|=(cfp8n &value) { return (cfp8n &)(data |= value.data); }
inline cfp8n operator^=(cfp8n &value) { return (cfp8n &)(data ^= value.data); }
inline cbool operator==(cfl32 &value) const { return data == toFixed(value).data; }
inline cbool operator!=(cfl32 &value) const { return data != toFixed(value).data; }
inline cbool operator>=(cfl32 &value) const { return data <= toFixed(value).data; }
inline cbool operator<=(cfl32 &value) const { return data >= toFixed(value).data; }
inline cbool operator>(cfl32 &value) const { return data < toFixed(value).data; }
inline cbool operator<(cfl32 &value) const { return data > toFixed(value).data; }
inline cbool operator||(cfl32 &value) const { return data || toFixed(value).data; }
inline cbool operator&&(cfl32 &value) const { return data && toFixed(value).data; }
inline cfl32 operator+(cfl32 &value) const { return toFloat() + value; }
inline cfl32 operator-(cfl32 &value) const { return toFloat() - value; }
inline cfl32 operator*(cfl32 &value) const { return toFloat() * value; }
inline cfl32 operator/(cfl32 &value) const { return toFloat() / value; }
inline cfp8n operator%(cfl32 &value) const { return (cfp8n &)(data % toFixed(value).data); }
inline cfp8n operator&(cfl32 &value) const { return (cfp8n &)(data & toFixed(value).data); }
inline cfp8n operator|(cfl32 &value) const { return (cfp8n &)(data | toFixed(value).data); }
inline cfp8n operator^(cfl32 &value) const { return (cfp8n &)(data ^ toFixed(value).data); }
inline cfl32 operator+=(cfl32 &value) { cfl32 temp = toFloat() + value; *this = toFixed(temp); return temp; }
inline cfl32 operator-=(cfl32 &value) { cfl32 temp = toFloat() - value; *this = toFixed(temp); return temp; }
inline cfl32 operator*=(cfl32 &value) { cfl32 temp = toFloat() * value; *this = toFixed(temp); return temp; }
inline cfl32 operator/=(cfl32 &value) { cfl32 temp = toFloat() / value; *this = toFixed(temp); return temp; }
inline cfp8n operator%=(cfl32 &value) { return (cfp8n &)(data %= toFixed(value).data); }
inline cfp8n operator&=(cfl32 &value) { return (cfp8n &)(data &= toFixed(value).data); }
inline cfp8n operator|=(cfl32 &value) { return (cfp8n &)(data |= toFixed(value).data); }
inline cfp8n operator^=(cfl32 &value) { return (cfp8n &)(data ^= toFixed(value).data); }
};
// 4x normalised 8-bit : User-defineable decimal range
struct fp8nx4 {
typedef const fp8n cfp8n; typedef const fp8nx4 cfp8nx4;
union { ui32 data32; fp8n data[4]; ui8 data8[4]; };
inline cfp8n toFixed(cfl32 &value) const { return (cfp8n &)ui8((value - __fpdt_data__.origin8) * __fpdt_data__.maxDivRange8); }
inline cfp8nx4 toFixed4(cfl32x4 &value) const { return (cfp8nx4 &)_mm_shuffle_epi8(_mm_cvttps_epi32(_mm_mul_ps(_mm_sub_ps(value, _mm_set_ps1(__fpdt_data__.origin8)), _mm_set_ps1(__fpdt_data__.maxDivRange8))), _fpdt_shuffle8s); }
inline cfl32x4 toFloat4(void) const {
return _mm_add_ps(_mm_mul_ps(_mm_cvtepu32_ps(_mm_cvtepu8_epi32(_mm_cvtsi32_si128(data32))), _mm_set_ps1(__fpdt_data__.rangeDivMax8)), _mm_set_ps1(__fpdt_data__.origin8));
};
inline cfl32x4 toFloat4(cfp8nx4 &value) const {
return _mm_add_ps(_mm_mul_ps(_mm_cvtepu32_ps(_mm_cvtepu8_epi32(_mm_cvtsi32_si128(value.data32))), _mm_set_ps1(__fpdt_data__.rangeDivMax8)), _mm_set_ps1(__fpdt_data__.origin8));
};
inline cfp8nx4 toFixed4Mod(cfp8nx4 &value) const {
cfp8nx4 temp = (cfp8nx4 &)_mm_shuffle_epi8(_mm_cvttps_epi32(_mm_mul_ps(_mm_set_ps1(__fpdt_data__.origin8), _mm_set_ps1(__fpdt_data__.maxDivRange8))), _fpdt_shuffle8s);
return cfp8nx4{ ui8(data8[0] - temp.data8[0]), ui8(data8[1] - temp.data8[1]), ui8(data8[2] - temp.data8[2]), ui8(data8[3] - temp.data8[3]) };
}
inline cfp8nx4 toFixed4Mod(cfl32x4 &value) const {
return (cfp8nx4 &)_mm_shuffle_epi8(_mm_cvttps_epi32(_mm_mul_ps(value, _mm_set_ps1(__fpdt_data__.maxDivRange8))), _fpdt_shuffle8s);
}
fp8nx4(void) = default;
fp8nx4(cfl32 floor, cfl32 ceiling) {
__fpdt_data__.origin8 = floor;
__fpdt_data__.range8 = ceiling - floor;
__fpdt_data__.maxDivRange8 = 255.0f / __fpdt_data__.range8;
__fpdt_data__.rangeDivMax8 = __fpdt_data__.range8 / 255.0f;
};
fp8nx4(cfp8n value, cui8 index) { data[index] = value.data; }
fp8nx4(cui8 value, cui8 index) { data8[index] = value; }
fp8nx4(csi32 value, cui8 index) { data8[index] = (ui8 &)value; }
fp8nx4(cfl32 value, cui8 index) { data8[index] = toFixed(value).data; }
fp8nx4(cfp8n (&value)[4]) { data32 = (ui32 &)value[0]; }
fp8nx4(cui8 (&value)[4]) { data32 = (ui32 &)value[0]; }
fp8nx4(cfp8n value) { data[0] = data[1] = data[2] = data[3] = value; }
fp8nx4(cui8 value) { data8[0] = data8[1] = data8[2] = data8[3] = value; }
fp8nx4(cui32 value) { data32 = value; }
fp8nx4(csi32 value) { data32 = (ui32 &)value; }
fp8nx4(cfl32 value) { cfp8n temp = toFixed(value); data8[0] = data8[1] = data8[2] = data8[3] = temp.data; }
fp8nx4(cfl32x4 value) { *this = toFixed4(value); }
#ifdef _VECTOR_STRUCTURES_
fp8nx4(cVEC4Df value) { cSSE4Df32 temp = { .vector = value }; *this = toFixed4(temp.xmm); }
fp8nx4(cSSE4Df32 value) { *this = toFixed4(value.xmm); }
#endif
fp8nx4(cfp8n value0, cfp8n value1, cfp8n value2, cfp8n value3) { data[0] = value0; data[1] = value1; data[2] = value2; data[3] = value3; }
fp8nx4(cui8 value0, cui8 value1, cui8 value2, cui8 value3) { data8[0] = value0; data8[1] = value1; data8[2] = value2; data8[3] = value3; }
fp8nx4(csi32 value0, csi32 value1, csi32 value2, csi32 value3) { data8[0] = (ui8 &)value0; data8[1] = (ui8 &)value1; data8[2] = (ui8 &)value2; data8[3] = (ui8 &)value3; }
fp8nx4(cfl32 value, cui8 index, cfl32 floor, cfl32 ceiling) {
__fpdt_data__.origin8 = floor;
__fpdt_data__.range8 = ceiling - floor;
__fpdt_data__.maxDivRange8 = 255.0f / __fpdt_data__.range8;
__fpdt_data__.rangeDivMax8 = __fpdt_data__.range8 / 255.0f;
data8[index] = ui8((value - floor) * __fpdt_data__.maxDivRange8);
};
fp8nx4(cfl32x4 value, cfl32 floor, cfl32 ceiling) {
__fpdt_data__.origin8 = floor;
__fpdt_data__.range8 = ceiling - floor;
__fpdt_data__.maxDivRange8 = 255.0f / __fpdt_data__.range8;
__fpdt_data__.rangeDivMax8 = __fpdt_data__.range8 / 255.0f;
data32 = toFixed4(value).data32;
}
operator ptr(void) const { return *this; }
operator cfl32x4(void) const { return _mm_add_ps(_mm_mul_ps(_mm_cvtepu32_ps(_mm_cvtepu8_epi32(_mm_cvtsi32_si128(data32))), _mm_set_ps1(__fpdt_data__.rangeDivMax8)), _mm_set_ps1(__fpdt_data__.origin8)); }
inline cfp8nx4 &operator&(void) const { return *this; }
inline cfp8nx4 operator~(void) const { return (cfp8nx4 &)(data32 ^ 0x0FFFFFFFFu); }
inline cfp8nx4 operator-(void) const { return (cfp8nx4 &)(data32 ^ 0x0FFFFFFFFu); }
inline cbool operator!(void) const { return data32 == 0; }
inline cfp8nx4 operator++(void) { data[0]++; data[1]++; data[2]++; data[3]++; return *this; }
inline cfp8nx4 operator++(int) { cfp8nx4 temp = { data[0]++, data[1]++, data[2]++, data[3]++ }; return (cfp8nx4 &)temp; }
inline cfp8nx4 operator--(void) { data[0]--; data[1]--; data[2]--; data[3]--; return *this; }
inline cfp8nx4 operator--(int) { cfp8nx4 temp = { data[0]--, data[1]--, data[2]--, data[3]-- }; return (cfp8nx4 &)temp; }
inline cfp8nx4 operator<<(csi32 &value) const { return fp8nx4{ data8[0] << value, data8[1] << value, data8[2] << value, data8[3] << value }; }
inline cfp8nx4 operator>>(csi32 &value) const { return fp8nx4{ data8[0] >> value, data8[1] >> value, data8[2] >> value, data8[3] >> value }; }
inline cfp8nx4 operator<<=(csi32 &value) { return fp8nx4{ data8[0] <<= value, data8[1] <<= value, data8[2] <<= value, data8[3] <<= value }; }
inline cfp8nx4 operator>>=(csi32 &value) { return fp8nx4{ data8[0] >>= value, data8[1] >>= value, data8[2] >>= value, data8[3] >>= value }; }
// Each of the lower 4 bits represents the test result per variable
inline cui8 operator==(cfp8nx4 &value) const { return (data8[0] == value.data8[0]) | ((data8[1] == value.data8[1]) << 1) | ((data8[2] == value.data8[2]) << 2) | ((data8[3] == value.data8[3]) << 3); }
inline cui8 operator!=(cfp8nx4 &value) const { return (data8[0] != value.data8[0]) | ((data8[1] != value.data8[1]) << 1) | ((data8[2] != value.data8[2]) << 2) | ((data8[3] != value.data8[3]) << 3); }
inline cui8 operator>=(cfp8nx4 &value) const { return (data8[0] >= value.data8[0]) | ((data8[1] >= value.data8[1]) << 1) | ((data8[2] >= value.data8[2]) << 2) | ((data8[3] >= value.data8[3]) << 3); }
inline cui8 operator<=(cfp8nx4 &value) const { return (data8[0] <= value.data8[0]) | ((data8[1] <= value.data8[1]) << 1) | ((data8[2] <= value.data8[2]) << 2) | ((data8[3] <= value.data8[3]) << 3); }
inline cui8 operator>(cfp8nx4 &value) const { return (data8[0] > value.data8[0]) | ((data8[1] > value.data8[1]) << 1) | ((data8[2] > value.data8[2]) << 2) | ((data8[3] > value.data8[3]) << 3); }
inline cui8 operator<(cfp8nx4 &value) const { return (data8[0] < value.data8[0]) | ((data8[1] < value.data8[1]) << 1) | ((data8[2] < value.data8[2]) << 2) | ((data8[3] < value.data8[3]) << 3); }
inline cui8 operator||(cfp8nx4 &value) const { return (data8[0] || value.data8[0]) | ((data8[1] || value.data8[1]) << 1) | ((data8[2] || value.data8[2]) << 2) | ((data8[3] || value.data8[3]) << 3); }
inline cui8 operator&&(cfp8nx4 &value) const { return (data8[0] && value.data8[0]) | ((data8[1] && value.data8[1]) << 1) | ((data8[2] && value.data8[2]) << 2) | ((data8[3] && value.data8[3]) << 3); }
inline cfp8nx4 operator+(cfp8nx4 &value) const { return (cfp8nx4 &)_mm_add_epi8(_mm_cvtsi32_si128(data32), _mm_cvtsi32_si128(value.data32)); }
inline cfp8nx4 operator-(cfp8nx4 &value) const { return (cfp8nx4 &)_mm_sub_epi8(_mm_cvtsi32_si128(data32), _mm_cvtsi32_si128(value.data32)); }
inline cfp8nx4 operator*(cfp8nx4 &value) const { return toFixed4(_mm_mul_ps(toFloat4(), toFloat4(value))); }
inline cfp8nx4 operator/(cfp8nx4 &value) const { return toFixed4(_mm_div_ps(toFloat4(), toFloat4(value))); }
inline cfp8nx4 operator%(cfp8nx4 &value) const { cfp8nx4 temp = toFixed4Mod(value); return cfp8nx4{ data8[0] % temp.data8[0], data8[1] % temp.data8[1], data8[2] % temp.data8[2], data8[3] % temp.data8[3] }; }
inline cfp8nx4 operator&(cfp8nx4 &value) const { return (cfp8nx4 &)(data32 & value.data32); }
inline cfp8nx4 operator|(cfp8nx4 &value) const { return (cfp8nx4 &)(data32 | value.data32); }
inline cfp8nx4 operator^(cfp8nx4 &value) const { return (cfp8nx4 &)(data32 ^ value.data32); }
inline cfp8nx4 operator+=(cfp8nx4 &value) { data32 = (ui32 &)_mm_add_epi8(_mm_cvtsi32_si128(data32), _mm_cvtsi32_si128(value.data32)); return *this; }
inline cfp8nx4 operator-=(cfp8nx4 &value) { data32 = (ui32 &)_mm_sub_epi8(_mm_cvtsi32_si128(data32), _mm_cvtsi32_si128(value.data32)); return *this; }
inline cfp8nx4 operator*=(cfp8nx4 &value) { return *this = toFixed4(_mm_mul_ps(toFloat4(), toFloat4(value))); }
inline cfp8nx4 operator/=(cfp8nx4 &value) { return *this = toFixed4(_mm_div_ps(toFloat4(), toFloat4(value))); }
inline cfp8nx4 operator%=(cfp8nx4 &value) { cfp8nx4 temp = toFixed4Mod(value); return cfp8nx4{ data8[0] %= temp.data8[0], data8[1] %= temp.data8[1], data8[2] %= temp.data8[2], data8[3] %= temp.data8[3] }; }
inline cfp8nx4 operator&=(cfp8nx4 &value) { return (cfp8nx4 &)(data32 &= value.data32); }
inline cfp8nx4 operator|=(cfp8nx4 &value) { return (cfp8nx4 &)(data32 |= value.data32); }
inline cfp8nx4 operator^=(cfp8nx4 &value) { return (cfp8nx4 &)(data32 ^= value.data32); }
// Each of the lower 4 bits represents the test result per variable
inline cui8 operator==(cfl32x4 &value) const {
cfp8nx4 temp = toFixed4(value);
return (data8[0] == temp.data8[0]) | ((data8[1] == temp.data8[1]) << 1) | ((data8[2] == temp.data8[2]) << 2) | ((data8[3] == temp.data8[3]) << 3);
}
inline cui8 operator!=(cfl32x4 &value) const {
cfp8nx4 temp = toFixed4(value);
return (data8[0] != temp.data8[0]) | ((data8[1] != temp.data8[1]) << 1) | ((data8[2] != temp.data8[2]) << 2) | ((data8[3] != temp.data8[3]) << 3);
}
inline cui8 operator>=(cfl32x4 &value) const {
cfp8nx4 temp = toFixed4(value);
return (data8[0] >= temp.data8[0]) | ((data8[1] >= temp.data8[1]) << 1) | ((data8[2] >= temp.data8[2]) << 2) | ((data8[3] >= temp.data8[3]) << 3);
}
inline cui8 operator<=(cfl32x4 &value) const {
cfp8nx4 temp = toFixed4(value);
return (data8[0] <= temp.data8[0]) | ((data8[1] <= temp.data8[1]) << 1) | ((data8[2] <= temp.data8[2]) << 2) | ((data8[3] <= temp.data8[3]) << 3);
}
inline cui8 operator>(cfl32x4 &value) const {
cfp8nx4 temp = toFixed4(value);
return (data8[0] > temp.data8[0]) | ((data8[1] > temp.data8[1]) << 1) | ((data8[2] > temp.data8[2]) << 2) | ((data8[3] > temp.data8[3]) << 3);
}
inline cui8 operator<(cfl32x4 &value) const {
cfp8nx4 temp = toFixed4(value);
return (data8[0] < temp.data8[0]) | ((data8[1] < temp.data8[1]) << 1) | ((data8[2] < temp.data8[2]) << 2) | ((data8[3] < temp.data8[3]) << 3);
}
inline cui8 operator||(cfl32x4 &value) const {
cfp8nx4 temp = toFixed4(value);
return (data8[0] || temp.data8[0]) | ((data8[1] || temp.data8[1]) << 1) | ((data8[2] || temp.data8[2]) << 2) | ((data8[3] || temp.data8[3]) << 3);
}
inline cui8 operator&&(cfl32x4 &value) const {
cfp8nx4 temp = toFixed4(value);
return (data8[0] && temp.data8[0]) | ((data8[1] && temp.data8[1]) << 1) | ((data8[2] && temp.data8[2]) << 2) | ((data8[3] && temp.data8[3]) << 3);
}
inline cfp8nx4 operator+(cfl32x4 &value) const { return (cfp8nx4 &)_mm_add_epi8(_mm_cvtsi32_si128(data32), _mm_shuffle_epi8(_mm_cvttps_epi32(_mm_mul_ps(value, _fpdt_65535fx4)), _fpdt_shuffle8s)); }
inline cfp8nx4 operator-(cfl32x4 &value) const { return (cfp8nx4 &)_mm_sub_epi8(_mm_cvtsi32_si128(data32), _mm_shuffle_epi8(_mm_cvttps_epi32(_mm_mul_ps(value, _fpdt_65535fx4)), _fpdt_shuffle8s)); }
inline cfp8nx4 operator*(cfl32x4 &value) const { return toFixed4(_mm_mul_ps(toFloat4(), value)); }
inline cfp8nx4 operator/(cfl32x4 &value) const { return toFixed4(_mm_div_ps(toFloat4(), value)); }
inline cfp8nx4 operator%(cfl32x4 &value) const {
cfp8nx4 temp = toFixed4(value);
return fp8nx4{ data8[0] % temp.data8[0], data8[1] % temp.data8[1], data8[2] % temp.data8[2], data8[3] % temp.data8[3] };
}
inline cfp8nx4 operator&(cfl32x4 &value) const { return (cfp8nx4 &)(data32 & toFixed4(value).data32); }
inline cfp8nx4 operator|(cfl32x4 &value) const { return (cfp8nx4 &)(data32 | toFixed4(value).data32); }
inline cfp8nx4 operator^(cfl32x4 &value) const { return (cfp8nx4 &)(data32 ^ toFixed4(value).data32); }
inline cfp8nx4 operator+=(cfl32x4 &value) { data32 = (ui32 &)_mm_add_epi8(_mm_cvtsi32_si128(data32), _mm_shuffle_epi8(_mm_cvttps_epi32(_mm_mul_ps(value, _fpdt_65535fx4)), _fpdt_shuffle8s)); return *this; }
inline cfp8nx4 operator-=(cfl32x4 &value) { data32 = (ui32 &)_mm_sub_epi8(_mm_cvtsi32_si128(data32), _mm_shuffle_epi8(_mm_cvttps_epi32(_mm_mul_ps(value, _fpdt_65535fx4)), _fpdt_shuffle8s)); return *this; }
inline cfp8nx4 operator*=(cfl32x4 &value) { return *this = toFixed4(_mm_mul_ps(toFloat4(), value)); }
inline cfp8nx4 operator/=(cfl32x4 &value) { return *this = toFixed4(_mm_div_ps(toFloat4(), value)); }
inline cfp8nx4 operator%=(cfl32x4 &value) {
cfp8nx4 temp = toFixed4(value);
return *this = fp8nx4{ data8[0] % temp.data8[0], data8[1] % temp.data8[1], data8[2] % temp.data8[2], data8[3] % temp.data8[3] };
}
inline cfp8nx4 operator&=(cfl32x4 &value) { (cfp8nx4 &)(data32 &= toFixed4(value).data32); }
inline cfp8nx4 operator|=(cfl32x4 &value) { (cfp8nx4 &)(data32 |= toFixed4(value).data32); }
inline cfp8nx4 operator^=(cfl32x4 &value) { (cfp8nx4 &)(data32 ^= toFixed4(value).data32); }
};
// Normalised 16-bit : User-defineable decimal range
struct fp16n {
typedef const fp16n cfp16n;
ui16 data;
inline cfp16n toFixed(cfl32 &value) const { return (cfp16n &)ui16((value - __fpdt_data__.origin16) * __fpdt_data__.maxDivRange16); }
inline cfl32 toFloat(void) const { return fl32(data) * __fpdt_data__.rangeDivMax16 + __fpdt_data__.origin16; };
inline cfl32 toFloat(cfp16n &value) const { return fl32(value.data) * __fpdt_data__.rangeDivMax16 + __fpdt_data__.origin16; };
inline cui16 toFixedMod(cfp16n &value) const { return (value.data - ui16(__fpdt_data__.origin16 * __fpdt_data__.maxDivRange16)); }
inline cui16 toFixedMod(cfl32 &value) const { return ui16(value * __fpdt_data__.maxDivRange16); }
fp16n(void) {};
fp16n(cfl32 floor, cfl32 ceiling) {
__fpdt_data__.origin16 = floor;
__fpdt_data__.range16 = ceiling - floor;
__fpdt_data__.maxDivRange16 = 65535.0f / __fpdt_data__.range16;
__fpdt_data__.rangeDivMax16 = __fpdt_data__.range16 / 65535.0f;
};
fp16n(cfl32 value, cfl32 floor, cfl32 ceiling) {
__fpdt_data__.origin16 = floor;
__fpdt_data__.range16 = ceiling - floor;
__fpdt_data__.maxDivRange16 = 65535.0f / __fpdt_data__.range16;
__fpdt_data__.rangeDivMax16 = __fpdt_data__.range16 / 65535.0f;
data = ui16((value - floor) * __fpdt_data__.maxDivRange16);
};
fp16n(cui8 value) { data = toFixed(fl32(value) * __fpdt_data__.rangeDivMax8 + __fpdt_data__.origin8).data; }
fp16n(cui16 value) { data = value; }
fp16n(cui32 value) { data = toFixed(fl32(fl64(value) * __fpdt_data__.rangeDivMax32 + __fpdt_data__.origin32)).data; }
fp16n(csi32 value) { data = (ui16 &)value; }
fp16n(cfl32 value) { data = toFixed(value).data; }
fp16n(cfl64 value) { data = ui16((value - fl64(__fpdt_data__.origin16)) * (65535.0 / fl64(__fpdt_data__.range16))); }
operator ptr(void) const { return *this; }
operator cfl32(void) const { return fl32(data) * __fpdt_data__.rangeDivMax16 + __fpdt_data__.origin16; };
inline cfp16n &operator&(void) const { return *this; }
inline cfp16n operator~(void) const { return (cfp16n &)~data; }
inline cfp16n operator-(void) const { return (cfp16n &)~data; }
inline cbool operator!(void) const { return data == 0; }
inline cfp16n operator++(void) { data++; return *this; }
inline cfp16n operator++(int) { cui16 temp = data++; return (cfp16n &)temp; }
inline cfp16n operator--(void) { data--; return *this; }
inline cfp16n operator--(int) { cui16 temp = data--; return (cfp16n &)temp; }
inline cbool operator==(csi32 &value) const { return data == (ui16 &)data; }
inline cbool operator!=(csi32 &value) const { return data != (ui16 &)data; }
inline cbool operator>=(csi32 &value) const { return data >= (ui16 &)data; }
inline cbool operator<=(csi32 &value) const { return data <= (ui16 &)data; }
inline cbool operator>(csi32 &value) const { return data > (ui16 &)data; }
inline cbool operator<(csi32 &value) const { return data < (ui16 &)data; }
inline cbool operator||(csi32 &value) const { return data || (ui16 &)data; }
inline cbool operator&&(csi32 &value) const { return data && (ui16 &)data; }
inline cfp16n operator<<(csi32 &value) const { return (cfp16n &)(data << value); }
inline cfp16n operator>>(csi32 &value) const { return (cfp16n &)(data >> value); }
inline cfp16n operator<<=(csi32 &value) { return (cfp16n &)(data <<= value); }
inline cfp16n operator>>=(csi32 &value) { return (cfp16n &)(data >>= value); }
inline cbool operator==(cfp16n &value) const { return data == value.data; }
inline cbool operator!=(cfp16n &value) const { return data != value.data; }
inline cbool operator>=(cfp16n &value) const { return data >= value.data; }
inline cbool operator<=(cfp16n &value) const { return data <= value.data; }
inline cbool operator>(cfp16n &value) const { return data > value.data; }
inline cbool operator<(cfp16n &value) const { return data < value.data; }
inline cbool operator||(cfp16n &value) const { return data || value.data; }
inline cbool operator&&(cfp16n &value) const { return data && value.data; }
inline cfp16n operator+(cfp16n &value) const { return (cfp16n &)(data + toFixedMod(value)); }
inline cfp16n operator-(cfp16n &value) const { return (cfp16n &)(data - toFixedMod(value)); }
inline cfp16n operator*(cfp16n &value) const { return toFixed(toFloat() * toFloat(value)); }
inline cfp16n operator/(cfp16n &value) const { return toFixed(toFloat() / toFloat(value)); }
inline cfp16n operator%(cfp16n &value) const { return (cfp16n &)(data % toFixedMod(value)); }
inline cfp16n operator&(cfp16n &value) const { return (cfp16n &)(data & value.data); }
inline cfp16n operator|(cfp16n &value) const { return (cfp16n &)(data | value.data); }
inline cfp16n operator^(cfp16n &value) const { return (cfp16n &)(data ^ value.data); }
inline cfp16n operator+=(cfp16n &value) { return (cfp16n &)(data += toFixedMod(value)); }
inline cfp16n operator-=(cfp16n &value) { return (cfp16n &)(data -= toFixedMod(value)); }
inline cfp16n operator*=(cfp16n &value) { return *this = toFixed(toFloat() * toFloat(value)); }
inline cfp16n operator/=(cfp16n &value) { return *this = toFixed(toFloat() / toFloat(value)); }
inline cfp16n operator%=(cfp16n &value) { return (cfp16n &)(data %= toFixedMod(value)); }
inline cfp16n operator&=(cfp16n &value) { return (cfp16n &)(data &= value.data); }
inline cfp16n operator|=(cfp16n &value) { return (cfp16n &)(data |= value.data); }
inline cfp16n operator^=(cfp16n &value) { return (cfp16n &)(data ^= value.data); }
inline cbool operator==(cfl32 &value) const { return data == toFixed(value).data; }
inline cbool operator!=(cfl32 &value) const { return data != toFixed(value).data; }
inline cbool operator>=(cfl32 &value) const { return data <= toFixed(value).data; }
inline cbool operator<=(cfl32 &value) const { return data >= toFixed(value).data; }
inline cbool operator>(cfl32 &value) const { return data < toFixed(value).data; }
inline cbool operator<(cfl32 &value) const { return data > toFixed(value).data; }
inline cbool operator||(cfl32 &value) const { return data || toFixed(value).data; }
inline cbool operator&&(cfl32 &value) const { return data && toFixed(value).data; }
inline cfl32 operator+(cfl32 &value) const { return toFloat() + value; }
inline cfl32 operator-(cfl32 &value) const { return toFloat() - value; }
inline cfl32 operator*(cfl32 &value) const { return toFloat() * value; }
inline cfl32 operator/(cfl32 &value) const { return toFloat() / value; }
inline cfp16n operator%(cfl32 &value) const { return (cfp16n &)(data % toFixed(value).data); }
inline cfp16n operator&(cfl32 &value) const { return (cfp16n &)(data & toFixed(value).data); }
inline cfp16n operator|(cfl32 &value) const { return (cfp16n &)(data | toFixed(value).data); }
inline cfp16n operator^(cfl32 &value) const { return (cfp16n &)(data ^ toFixed(value).data); }
inline cfl32 operator+=(cfl32 &value) { cfl32 temp = toFloat() + value; *this = toFixed(temp); return temp; }
inline cfl32 operator-=(cfl32 &value) { cfl32 temp = toFloat() - value; *this = toFixed(temp); return temp; }
inline cfl32 operator*=(cfl32 &value) { cfl32 temp = toFloat() * value; *this = toFixed(temp); return temp; }
inline cfl32 operator/=(cfl32 &value) { cfl32 temp = toFloat() / value; *this = toFixed(temp); return temp; }
inline cfp16n operator%=(cfl32 &value) { return (cfp16n &)(data %= toFixed(value).data); }
inline cfp16n operator&=(cfl32 &value) { return (cfp16n &)(data &= toFixed(value).data); }
inline cfp16n operator|=(cfl32 &value) { return (cfp16n &)(data |= toFixed(value).data); }
inline cfp16n operator^=(cfl32 &value) { return (cfp16n &)(data ^= toFixed(value).data); }
};
// 4x normalised 16-bit : User-defineable decimal range
struct fp16nx4 {
typedef const fp16n cfp16n; typedef const fp16nx4 cfp16nx4;
union { ui64 data64; fp16n data[4]; ui16 data16[4]; };
inline cfp16n toFixed(cfl32 &value) const { return (cfp16n &)ui16((value - __fpdt_data__.origin16) * __fpdt_data__.maxDivRange16); }
inline cfp16nx4 toFixed4(cfl32x4 &value) const {
return (cfp16nx4 &)_mm_shuffle_epi8(_mm_cvttps_epi32( _mm_mul_ps(_mm_sub_ps(value, _mm_set_ps1(__fpdt_data__.origin16)), _mm_set_ps1(__fpdt_data__.maxDivRange16))), _fpdt_shuffle16s);
}
inline cfl32x4 toFloat4(void) const {
return _mm_add_ps(_mm_mul_ps(_mm_cvtepu32_ps(_mm_cvtepu16_epi32(_mm_cvtsi64_si128(data64))), _mm_set_ps1(__fpdt_data__.rangeDivMax16)), _mm_set_ps1(__fpdt_data__.origin16));
};
inline cfl32x4 toFloat4(cfp16nx4 &value) const {
return _mm_add_ps(_mm_mul_ps(_mm_cvtepu32_ps(_mm_cvtepu16_epi32(_mm_cvtsi64_si128(value.data64))), _mm_set_ps1(__fpdt_data__.rangeDivMax16)), _mm_set_ps1(__fpdt_data__.origin16));
};
inline cfp16nx4 toFixed4Mod(cfp16nx4 &value) const {
cfp16nx4 temp = (cfp16nx4 &)_mm_shuffle_epi8(_mm_cvttps_epi32(_mm_mul_ps(_mm_set_ps1(__fpdt_data__.origin16), _mm_set_ps1(__fpdt_data__.maxDivRange16))), _fpdt_shuffle16s);
return cfp16nx4{ ui16(data16[0] - temp.data16[0]), ui16(data16[1] - temp.data16[1]), ui16(data16[2] - temp.data16[2]), ui16(data16[3] - temp.data16[3]) };
}
inline cfp16nx4 toFixed4Mod(cfl32x4 &value) const {
return (cfp16nx4 &)_mm_shuffle_epi8(_mm_cvttps_epi32(_mm_mul_ps(value, _mm_set_ps1(__fpdt_data__.maxDivRange16))), _fpdt_shuffle16s);
}
fp16nx4(void) = default;
fp16nx4(cfl32 floor, cfl32 ceiling) {
__fpdt_data__.origin16 = floor;
__fpdt_data__.range16 = ceiling - floor;
__fpdt_data__.maxDivRange16 = 65535.0f / __fpdt_data__.range16;
__fpdt_data__.rangeDivMax16 = __fpdt_data__.range16 / 65535.0f;
};
fp16nx4(cfp16n value, cui8 index) { data[index] = value.data; }
fp16nx4(cui16 value, cui8 index) { data16[index] = value; }
fp16nx4(csi32 value, cui8 index) { data16[index] = (ui16 &)value; }
fp16nx4(cfl32 value, cui8 index) { data16[index] = ui16((value - __fpdt_data__.origin16) * __fpdt_data__.maxDivRange16); }
fp16nx4(cfp16n (&value)[4]) { data64 = (ui64 &)value[0]; }
fp16nx4(cui16 (&value)[4]) { data64 = (ui64 &)value[0]; }
fp16nx4(cfp16n value) { data[0] = data[1] = data[2] = data[3] = value; }
fp16nx4(cui16 value) { data16[0] = data16[1] = data16[2] = data16[3] = value; }
fp16nx4(csi32 value) { data16[0] = (ui16 &)value; data16[1] = (ui16 &)value; data16[2] = (ui16 &)value; data16[3] = (ui16 &)value; }
fp16nx4(cfl32 value) { cfp16n temp = toFixed(value); data16[0] = data16[1] = data16[2] = data16[3] = temp.data; }
fp16nx4(cui64 value) { data64 = value; }
fp16nx4(csi64 value) { data64 = (ui64 &)value; }
fp16nx4(cfl32x4 value) { *this = toFixed4(value); }
#ifdef _VECTOR_STRUCTURES_
fp16nx4(cVEC4Df value) { cSSE4Df32 temp = { .vector = value }; *this = toFixed4(temp.xmm); }
fp16nx4(cSSE4Df32 value) { *this = toFixed4(value.xmm); }
#endif
fp16nx4(cfp16n value0, cfp16n value1, cfp16n value2, cfp16n value3) { data[0] = value0; data[1] = value1; data[2] = value2; data[3] = value3; }
fp16nx4(cui16 value0, cui16 value1, cui16 value2, cui16 value3) { data16[0] = value0; data16[1] = value1; data16[2] = value2; data16[3] = value3; }
fp16nx4(csi32 value0, csi32 value1, csi32 value2, csi32 value3) { data16[0] = (ui16 &)value0; data16[1] = (ui16 &)value1; data16[2] = (ui16 &)value2; data16[3] = (ui16 &)value3; }
fp16nx4(cfl32 value, cui8 index, cfl32 floor, cfl32 ceiling) {
__fpdt_data__.origin16 = floor;
__fpdt_data__.range16 = ceiling - floor;
__fpdt_data__.maxDivRange16 = 65535.0f / __fpdt_data__.range16;
__fpdt_data__.rangeDivMax16 = __fpdt_data__.range16 / 65535.0f;
data16[index] = ui16((value - floor) * __fpdt_data__.maxDivRange16);
};
fp16nx4(cfl32x4 value, cfl32 floor, cfl32 ceiling) {
__fpdt_data__.origin16 = floor;
__fpdt_data__.range16 = ceiling - floor;
__fpdt_data__.maxDivRange16 = 65535.0f / __fpdt_data__.range16;
__fpdt_data__.rangeDivMax16 = __fpdt_data__.range16 / 65535.0f;
data64 = toFixed4(value).data64;
}
operator ptr(void) const { return *this; }
operator cfl32x4(void) const { return _mm_add_ps(_mm_mul_ps(_mm_cvtepu32_ps(_mm_cvtepu16_epi32(_mm_cvtsi64_si128(data64))), _mm_set_ps1(__fpdt_data__.rangeDivMax16)), _mm_set_ps1(__fpdt_data__.origin16)); }
inline cfp16nx4 &operator&(void) const { return *this; }
inline cfp16nx4 operator~(void) const { return (cfp16nx4 &)(data64 ^ 0x0FFFFFFFFFFFFFFFFu); }
inline cfp16nx4 operator-(void) const { return (cfp16nx4 &)(data64 ^ 0x0FFFFFFFFFFFFFFFFu); }
inline cbool operator!(void) const { return data64 == 0; }
inline cfp16nx4 operator++(void) { data[0]++; data[1]++; data[2]++; data[3]++; return *this; }
inline cfp16nx4 operator++(int) { cfp16nx4 temp = { data[0]++, data[1]++, data[2]++, data[3]++ }; return (cfp16nx4 &)temp; }
inline cfp16nx4 operator--(void) { data[0]--; data[1]--; data[2]--; data[3]--; return *this; }
inline cfp16nx4 operator--(int) { cfp16nx4 temp = { data[0]--, data[1]--, data[2]--, data[3]-- }; return (cfp16nx4 &)temp; }
inline cfp16nx4 operator<<(csi32 &value) const { return fp16nx4{ data16[0] << value, data16[1] << value, data16[2] << value, data16[3] << value }; }
inline cfp16nx4 operator>>(csi32 &value) const { return fp16nx4{ data16[0] >> value, data16[1] >> value, data16[2] >> value, data16[3] >> value }; }
inline cfp16nx4 operator<<=(csi32 &value) { return fp16nx4{ data16[0] <<= value, data16[1] <<= value, data16[2] <<= value, data16[3] <<= value }; }
inline cfp16nx4 operator>>=(csi32 &value) { return fp16nx4{ data16[0] >>= value, data16[1] >>= value, data16[2] >>= value, data16[3] >>= value }; }
// Each of the lower 4 bits represents the test result per variable
inline cui8 operator==(cfp16nx4 &value) const { return (data16[0] == value.data16[0]) | ((data16[1] == value.data16[1]) << 1) | ((data16[2] == value.data16[2]) << 2) | ((data16[3] == value.data16[3]) << 3); }
inline cui8 operator!=(cfp16nx4 &value) const { return (data16[0] != value.data16[0]) | ((data16[1] != value.data16[1]) << 1) | ((data16[2] != value.data16[2]) << 2) | ((data16[3] != value.data16[3]) << 3); }
inline cui8 operator>=(cfp16nx4 &value) const { return (data16[0] >= value.data16[0]) | ((data16[1] >= value.data16[1]) << 1) | ((data16[2] >= value.data16[2]) << 2) | ((data16[3] >= value.data16[3]) << 3); }
inline cui8 operator<=(cfp16nx4 &value) const { return (data16[0] <= value.data16[0]) | ((data16[1] <= value.data16[1]) << 1) | ((data16[2] <= value.data16[2]) << 2) | ((data16[3] <= value.data16[3]) << 3); }
inline cui8 operator>(cfp16nx4 &value) const { return (data16[0] > value.data16[0]) | ((data16[1] > value.data16[1]) << 1) | ((data16[2] > value.data16[2]) << 2) | ((data16[3] > value.data16[3]) << 3); }
inline cui8 operator<(cfp16nx4 &value) const { return (data16[0] < value.data16[0]) | ((data16[1] < value.data16[1]) << 1) | ((data16[2] < value.data16[2]) << 2) | ((data16[3] < value.data16[3]) << 3); }
inline cui8 operator||(cfp16nx4 &value) const { return (data16[0] || value.data16[0]) | ((data16[1] || value.data16[1]) << 1) | ((data16[2] || value.data16[2]) << 2) | ((data16[3] || value.data16[3]) << 3); }
inline cui8 operator&&(cfp16nx4 &value) const { return (data16[0] && value.data16[0]) | ((data16[1] && value.data16[1]) << 1) | ((data16[2] && value.data16[2]) << 2) | ((data16[3] && value.data16[3]) << 3); }
inline cfp16nx4 operator+(cfp16nx4 &value) const { return (cfp16nx4 &)_mm_add_epi8(_mm_cvtsi64_si128(data64), _mm_cvtsi64_si128(value.data64)); }
inline cfp16nx4 operator-(cfp16nx4 &value) const { return (cfp16nx4 &)_mm_sub_epi8(_mm_cvtsi64_si128(data64), _mm_cvtsi64_si128(value.data64)); }
inline cfp16nx4 operator*(cfp16nx4 &value) const { return toFixed4(_mm_mul_ps(toFloat4(), toFloat4(value))); }
inline cfp16nx4 operator/(cfp16nx4 &value) const { return toFixed4(_mm_div_ps(toFloat4(), toFloat4(value))); }
inline cfp16nx4 operator%(cfp16nx4 &value) const { cfp16nx4 temp = toFixed4Mod(value); return cfp16nx4{ data16[0] % temp.data16[0], data16[1] % temp.data16[1], data16[2] % temp.data16[2], data16[3] % temp.data16[3] }; }
inline cfp16nx4 operator&(cfp16nx4 &value) const { return (cfp16nx4 &)(data64 & value.data64); }
inline cfp16nx4 operator|(cfp16nx4 &value) const { return (cfp16nx4 &)(data64 | value.data64); }
inline cfp16nx4 operator^(cfp16nx4 &value) const { return (cfp16nx4 &)(data64 ^ value.data64); }
inline cfp16nx4 operator+=(cfp16nx4 &value) { data64 = (ui64 &)_mm_add_epi8(_mm_cvtsi64_si128(data64), _mm_cvtsi64_si128(value.data64)); return *this; }
inline cfp16nx4 operator-=(cfp16nx4 &value) { data64 = (ui64 &)_mm_sub_epi8(_mm_cvtsi64_si128(data64), _mm_cvtsi64_si128(value.data64)); return *this; }
inline cfp16nx4 operator*=(cfp16nx4 &value) { return *this = toFixed4(_mm_mul_ps(toFloat4(), toFloat4(value))); }
inline cfp16nx4 operator/=(cfp16nx4 &value) { return *this = toFixed4(_mm_div_ps(toFloat4(), toFloat4(value))); }
inline cfp16nx4 operator%=(cfp16nx4 &value) { cfp16nx4 temp = toFixed4Mod(value); return cfp16nx4{ data16[0] %= temp.data16[0], data16[1] %= temp.data16[1], data16[2] %= temp.data16[2], data16[3] %= temp.data16[3] }; }
inline cfp16nx4 operator&=(cfp16nx4 &value) { return (cfp16nx4 &)(data64 &= value.data64); }
inline cfp16nx4 operator|=(cfp16nx4 &value) { return (cfp16nx4 &)(data64 |= value.data64); }
inline cfp16nx4 operator^=(cfp16nx4 &value) { return (cfp16nx4 &)(data64 ^= value.data64); }
// Each of the lower 4 bits represents the test result per variable
inline cui8 operator==(cfl32x4 &value) const {
cfp16nx4 temp = toFixed4(value);
return (data16[0] == temp.data16[0]) | ((data16[1] == temp.data16[1]) << 1) | ((data16[2] == temp.data16[2]) << 2) | ((data16[3] == temp.data16[3]) << 3);
}
inline cui8 operator!=(cfl32x4 &value) const {
cfp16nx4 temp = toFixed4(value);
return (data16[0] != temp.data16[0]) | ((data16[1] != temp.data16[1]) << 1) | ((data16[2] != temp.data16[2]) << 2) | ((data16[3] != temp.data16[3]) << 3);
}
inline cui8 operator>=(cfl32x4 &value) const {
cfp16nx4 temp = toFixed4(value);
return (data16[0] >= temp.data16[0]) | ((data16[1] >= temp.data16[1]) << 1) | ((data16[2] >= temp.data16[2]) << 2) | ((data16[3] >= temp.data16[3]) << 3);
}
inline cui8 operator<=(cfl32x4 &value) const {
cfp16nx4 temp = toFixed4(value);
return (data16[0] <= temp.data16[0]) | ((data16[1] <= temp.data16[1]) << 1) | ((data16[2] <= temp.data16[2]) << 2) | ((data16[3] <= temp.data16[3]) << 3);
}
inline cui8 operator>(cfl32x4 &value) const {
cfp16nx4 temp = toFixed4(value);
return (data16[0] > temp.data16[0]) | ((data16[1] > temp.data16[1]) << 1) | ((data16[2] > temp.data16[2]) << 2) | ((data16[3] > temp.data16[3]) << 3);
}
inline cui8 operator<(cfl32x4 &value) const {
cfp16nx4 temp = toFixed4(value);
return (data16[0] < temp.data16[0]) | ((data16[1] < temp.data16[1]) << 1) | ((data16[2] < temp.data16[2]) << 2) | ((data16[3] < temp.data16[3]) << 3);
}
inline cui8 operator||(cfl32x4 &value) const {
cfp16nx4 temp = toFixed4(value);
return (data16[0] || temp.data16[0]) | ((data16[1] || temp.data16[1]) << 1) | ((data16[2] || temp.data16[2]) << 2) | ((data16[3] || temp.data16[3]) << 3);
}
inline cui8 operator&&(cfl32x4 &value) const {
cfp16nx4 temp = toFixed4(value);
return (data16[0] && temp.data16[0]) | ((data16[1] && temp.data16[1]) << 1) | ((data16[2] && temp.data16[2]) << 2) | ((data16[3] && temp.data16[3]) << 3);
}
inline cfp16nx4 operator+(cfl32x4 &value) const { return (cfp16nx4 &)_mm_add_epi16(_mm_cvtsi64_si128(data64), _mm_shuffle_epi8(_mm_cvttps_epi64(_mm_mul_ps(value, _fpdt_65535fx4)), _fpdt_shuffle16s)); }
inline cfp16nx4 operator-(cfl32x4 &value) const { return (cfp16nx4 &)_mm_sub_epi16(_mm_cvtsi64_si128(data64), _mm_shuffle_epi8(_mm_cvttps_epi64(_mm_mul_ps(value, _fpdt_65535fx4)), _fpdt_shuffle16s)); }
inline cfp16nx4 operator*(cfl32x4 &value) const { return toFixed4(_mm_mul_ps(toFloat4(), value)); }
inline cfp16nx4 operator/(cfl32x4 &value) const { return toFixed4(_mm_div_ps(toFloat4(), value)); }
inline cfp16nx4 operator%(cfl32x4 &value) const {
cfp16nx4 temp = toFixed4Mod(value);
return fp16nx4{ data16[0] % temp.data16[0], data16[1] % temp.data16[1], data16[2] % temp.data16[2], data16[3] % temp.data16[3] };
}
inline cfp16nx4 operator&(cfl32x4 &value) const { return (cfp16nx4 &)(data64 & toFixed4(value).data64); }
inline cfp16nx4 operator|(cfl32x4 &value) const { return (cfp16nx4 &)(data64 | toFixed4(value).data64); }
inline cfp16nx4 operator^(cfl32x4 &value) const { return (cfp16nx4 &)(data64 ^ toFixed4(value).data64); }
inline cfp16nx4 operator+=(cfl32x4 &value) { data64 = (ui64 &)_mm_add_epi16(_mm_cvtsi64_si128(data64), _mm_shuffle_epi8(_mm_cvttps_epi64(_mm_mul_ps(value, _fpdt_65535fx4)), _fpdt_shuffle16s)); return *this; }
inline cfp16nx4 operator-=(cfl32x4 &value) { data64 = (ui64 &)_mm_sub_epi16(_mm_cvtsi64_si128(data64), _mm_shuffle_epi8(_mm_cvttps_epi64(_mm_mul_ps(value, _fpdt_65535fx4)), _fpdt_shuffle16s)); return *this; }
inline cfp16nx4 operator*=(cfl32x4 &value) { return *this = toFixed4(_mm_mul_ps(toFloat4(), value)); }
inline cfp16nx4 operator/=(cfl32x4 &value) { return *this = toFixed4(_mm_div_ps(toFloat4(), value)); }
inline cfp16nx4 operator%=(cfl32x4 &value) {
cfp16nx4 temp = toFixed4Mod(value);
return *this = fp16nx4{ data16[0] % temp.data16[0], data16[1] % temp.data16[1], data16[2] % temp.data16[2], data16[3] % temp.data16[3] };
}
inline cfp16nx4 operator&=(cfl32x4 &value) { (cfp16nx4 &)(data64 &= toFixed4(value).data64); }
inline cfp16nx4 operator|=(cfl32x4 &value) { (cfp16nx4 &)(data64 |= toFixed4(value).data64); }
inline cfp16nx4 operator^=(cfl32x4 &value) { (cfp16nx4 &)(data64 ^= toFixed4(value).data64); }
};
#ifdef _24BIT_INTEGERS_
// Normalised 24-bit : User-defineable decimal range
struct fp24n {
typedef const fp24n cfp24n;
ui24 data;
inline cui24 toFixed(cfl32 &value) const { return ui24((value - __fpdt_data__.origin24) * __fpdt_data__.maxDivRange24); }
inline cfl32 toFloat(void) const { return fl32(data) * __fpdt_data__.rangeDivMax24 + __fpdt_data__.origin24; };
inline cfl32 toFloat(cfp24n &value) const { return fl32(value.data) * __fpdt_data__.rangeDivMax24 + __fpdt_data__.origin24; };
inline cui24 toFixedMod(cfp24n &value) const { return (value.data - ui24(__fpdt_data__.origin24 * __fpdt_data__.maxDivRange24)); }
inline cui24 toFixedMod(cfl32 &value) const { return ui24(value * __fpdt_data__.maxDivRange24); }
fp24n(void) = default;
fp24n(cfl32 floor, cfl32 ceiling) {
__fpdt_data__.origin24 = floor;
__fpdt_data__.range24 = ceiling - floor;
__fpdt_data__.maxDivRange24 = 16777215.0f / __fpdt_data__.range24;
__fpdt_data__.rangeDivMax24 = __fpdt_data__.range24 / 16777215.0f;
};
fp24n(cfl32 value, cfl32 floor, cfl32 ceiling) {
__fpdt_data__.origin24 = floor;
__fpdt_data__.range24 = ceiling - floor;
__fpdt_data__.maxDivRange24 = 16777215.0f / __fpdt_data__.range24;
__fpdt_data__.rangeDivMax24 = __fpdt_data__.range24 / 16777215.0f;
data = ui24((value - floor) * __fpdt_data__.maxDivRange24);
};
fp24n(cui8 value) { data = toFixed(fl32(value) * __fpdt_data__.rangeDivMax8 + __fpdt_data__.origin8); }
fp24n(cui16 value) { data = toFixed(fl32(value) * __fpdt_data__.rangeDivMax16 + __fpdt_data__.origin16); }
fp24n(cui24 value) { data = value; }
fp24n(cui32 value) { data = toFixed(fl32(fl64(value) * __fpdt_data__.rangeDivMax32 + __fpdt_data__.origin32)); }
fp24n(csi32 value) { data = (ui24 &)value; }
fp24n(cfl32 value) { data = toFixed(value); }
operator ptr(void) const { return *this; }
operator cfl32(void) const { return fl32(data) * __fpdt_data__.rangeDivMax24 + __fpdt_data__.origin24; };
inline cfp24n &operator&(void) const { return *this; }
inline cfp24n operator~(void) const { return (cfp24n &)~data; }
inline cfp24n operator-(void) const { return (cfp24n &)~data; }
inline cbool operator!(void) const { return data == 0; }
inline cfp24n operator++(void) { data++; return *this; }
inline cfp24n operator++(int) { cui24 temp = data++; return (cfp24n &)temp; }
inline cfp24n operator--(void) { data--; return *this; }
inline cfp24n operator--(int) { cui24 temp = data--; return (cfp24n &)temp; }
inline cbool operator==(csi32 &value) const { return data == (ui24 &)data; }
inline cbool operator!=(csi32 &value) const { return data != (ui24 &)data; }
inline cbool operator>=(csi32 &value) const { return data >= (ui24 &)data; }
inline cbool operator<=(csi32 &value) const { return data <= (ui24 &)data; }
inline cbool operator>(csi32 &value) const { return data > (ui24 &)data; }
inline cbool operator<(csi32 &value) const { return data < (ui24 &)data; }
inline cbool operator||(csi32 &value) const { return data || (ui24 &)data; }
inline cbool operator&&(csi32 &value) const { return data && (ui24 &)data; }
inline cfp24n operator<<(csi32 &value) const { return (cfp24n &)(data << value); }
inline cfp24n operator>>(csi32 &value) const { return (cfp24n &)(data >> value); }
inline cfp24n operator<<=(csi32 &value) { return (cfp24n &)(data <<= value); }
inline cfp24n operator>>=(csi32 &value) { return (cfp24n &)(data >>= value); }
inline cbool operator==(cfp24n &value) const { return data == value.data; }
inline cbool operator!=(cfp24n &value) const { return data != value.data; }
inline cbool operator>=(cfp24n &value) const { return data >= value.data; }
inline cbool operator<=(cfp24n &value) const { return data <= value.data; }
inline cbool operator>(cfp24n &value) const { return data > value.data; }
inline cbool operator<(cfp24n &value) const { return data < value.data; }
inline cbool operator||(cfp24n &value) const { return data || value.data; }
inline cbool operator&&(cfp24n &value) const { return data && value.data; }
inline cfp24n operator+(cfp24n &value) const { return (cfp24n &)(data + toFixedMod(value)); }
inline cfp24n operator-(cfp24n &value) const { return (cfp24n &)(data - toFixedMod(value)); }
inline cfp24n operator*(cfp24n &value) const { return toFixed(toFloat() * toFloat(value)); }
inline cfp24n operator/(cfp24n &value) const { return toFixed(toFloat() / toFloat(value)); }
inline cfp24n operator%(cfp24n &value) const { return (cfp24n &)(data % toFixedMod(value)); }
inline cfp24n operator&(cfp24n &value) const { return (cfp24n &)(data & value.data); }
inline cfp24n operator|(cfp24n &value) const { return (cfp24n &)(data | value.data); }
inline cfp24n operator^(cfp24n &value) const { return (cfp24n &)(data ^ value.data); }
inline cfp24n operator+=(cfp24n &value) { return (cfp24n &)(data += toFixedMod(value)); }
inline cfp24n operator-=(cfp24n &value) { return (cfp24n &)(data -= toFixedMod(value)); }
inline cfp24n operator*=(cfp24n &value) { return *this = toFixed(toFloat() * toFloat(value)); }
inline cfp24n operator/=(cfp24n &value) { return *this = toFixed(toFloat() / toFloat(value)); }
inline cfp24n operator%=(cfp24n &value) { return (cfp24n &)(data %= toFixedMod(value)); }
inline cfp24n operator&=(cfp24n &value) { return (cfp24n &)(data &= value.data); }
inline cfp24n operator|=(cfp24n &value) { return (cfp24n &)(data |= value.data); }
inline cfp24n operator^=(cfp24n &value) { return (cfp24n &)(data ^= value.data); }
inline cbool operator==(cfl32 &value) const { return data == toFixed(value); }
inline cbool operator!=(cfl32 &value) const { return data != toFixed(value); }
inline cbool operator>=(cfl32 &value) const { return data <= toFixed(value); }
inline cbool operator<=(cfl32 &value) const { return data >= toFixed(value); }
inline cbool operator>(cfl32 &value) const { return data < toFixed(value); }
inline cbool operator<(cfl32 &value) const { return data > toFixed(value); }
inline cbool operator||(cfl32 &value) const { return data || toFixed(value); }
inline cbool operator&&(cfl32 &value) const { return data && toFixed(value); }
inline cfl32 operator+(cfl32 &value) const { return toFloat() + value; }
inline cfl32 operator-(cfl32 &value) const { return toFloat() - value; }
inline cfl32 operator*(cfl32 &value) const { return toFloat() * value; }
inline cfl32 operator/(cfl32 &value) const { return toFloat() / value; }
inline cfp24n operator%(cfl32 &value) const { return (cfp24n &)(data % toFixed(value)); }
inline cfp24n operator&(cfl32 &value) const { return (cfp24n &)(data & toFixed(value)); }
inline cfp24n operator|(cfl32 &value) const { return (cfp24n &)(data | toFixed(value)); }
inline cfp24n operator^(cfl32 &value) const { return (cfp24n &)(data ^ toFixed(value)); }
inline cfl32 operator+=(cfl32 &value) { cfl32 temp = toFloat() + value; *this = toFixed(temp); return temp; }
inline cfl32 operator-=(cfl32 &value) { cfl32 temp = toFloat() - value; *this = toFixed(temp); return temp; }
inline cfl32 operator*=(cfl32 &value) { cfl32 temp = toFloat() * value; *this = toFixed(temp); return temp; }
inline cfl32 operator/=(cfl32 &value) { cfl32 temp = toFloat() / value; *this = toFixed(temp); return temp; }
inline cfp24n operator%=(cfl32 &value) { return (cfp24n &)(data %= toFixed(value)); }
inline cfp24n operator&=(cfl32 &value) { return (cfp24n &)(data &= toFixed(value)); }
inline cfp24n operator|=(cfl32 &value) { return (cfp24n &)(data |= toFixed(value)); }
inline cfp24n operator^=(cfl32 &value) { return (cfp24n &)(data ^= toFixed(value)); }
};
#endif // #ifdef _24BIT_INTEGERS_
// Normalised 32-bit : User-defineable decimal range
struct fp32n {
typedef const fp32n cfp32n;
ui32 data;
inline cui32 toFixed(cfl64 &value) const { return ui32((value - __fpdt_data__.origin32) * __fpdt_data__.maxDivRange32); }
inline cfl64 toFloat(void) const { return fl64(data) * __fpdt_data__.rangeDivMax32 + __fpdt_data__.origin32; };
inline cfl64 toFloat(cfp32n &value) const { return fl64(value.data) * __fpdt_data__.rangeDivMax32 + __fpdt_data__.origin32; };
inline cui32 toFixedMod(cfp32n &value) const { return (value.data - ui32(__fpdt_data__.origin32 * __fpdt_data__.maxDivRange32)); }
inline cui32 toFixedMod(cfl64 &value) const { return ui32(value * __fpdt_data__.maxDivRange32); }
fp32n(void) = default;
fp32n(cfl64 floor, cfl64 ceiling) {
__fpdt_data__.origin32 = floor;
__fpdt_data__.range32 = ceiling - floor;
__fpdt_data__.maxDivRange32 = 4294967296.0 / __fpdt_data__.range32;
__fpdt_data__.rangeDivMax32 = __fpdt_data__.range32 / 4294967296.0;
};
fp32n(cfl64 value, cfl64 floor, cfl64 ceiling) {
__fpdt_data__.origin32 = floor;
__fpdt_data__.range32 = ceiling - floor;
__fpdt_data__.maxDivRange32 = 4294967296.0 / __fpdt_data__.range32;
__fpdt_data__.rangeDivMax32 = __fpdt_data__.range32 / 4294967296.0;
data = ui32((value - floor) * __fpdt_data__.maxDivRange32);
};
fp32n(cui8 value) { data = toFixed(fl32(value) * __fpdt_data__.rangeDivMax8 + __fpdt_data__.origin8); }
fp32n(cui16 value) { data = toFixed(fl32(value) * __fpdt_data__.rangeDivMax16 + __fpdt_data__.origin16); }
#ifdef _24BIT_INTEGERS_
fp32n(cui24 value) { data = toFixed(fl32(value) * __fpdt_data__.rangeDivMax24 + __fpdt_data__.origin24); }
#endif
fp32n(cui32 value) { data = value; }
fp32n(csi32 value) { data = (ui32 &)value; }
fp32n(cfl64 value) { data = toFixed(value); }
operator ptr(void) const { return *this; }
operator cfl64(void) const { return fl64(data) * __fpdt_data__.rangeDivMax32 + __fpdt_data__.origin32; };
inline cfp32n &operator&(void) const { return *this; }
inline cfp32n operator~(void) const { return (cfp32n &)~data; }
inline cfp32n operator-(void) const { return (cfp32n &)~data; }
inline cbool operator!(void) const { return data == 0; }
inline cfp32n operator++(void) { data++; return *this; }
inline cfp32n operator++(int) { cui32 temp = data++; return (cfp32n &)temp; }
inline cfp32n operator--(void) { data--; return *this; }
inline cfp32n operator--(int) { cui32 temp = data--; return (cfp32n &)temp; }
inline cbool operator==(csi32 &value) const { return data == (ui32 &)data; }
inline cbool operator!=(csi32 &value) const { return data != (ui32 &)data; }
inline cbool operator>=(csi32 &value) const { return data >= (ui32 &)data; }
inline cbool operator<=(csi32 &value) const { return data <= (ui32 &)data; }
inline cbool operator>(csi32 &value) const { return data > (ui32 &)data; }
inline cbool operator<(csi32 &value) const { return data < (ui32 &)data; }
inline cbool operator||(csi32 &value) const { return data || (ui32 &)data; }
inline cbool operator&&(csi32 &value) const { return data && (ui32 &)data; }
inline cfp32n operator<<(csi32 &value) const { return (cfp32n &)(data << value); }
inline cfp32n operator>>(csi32 &value) const { return (cfp32n &)(data >> value); }
inline cfp32n operator<<=(csi32 &value) { return (cfp32n &)(data <<= value); }
inline cfp32n operator>>=(csi32 &value) { return (cfp32n &)(data >>= value); }
inline cbool operator==(cfp32n &value) const { return data == value.data; }
inline cbool operator!=(cfp32n &value) const { return data != value.data; }
inline cbool operator>=(cfp32n &value) const { return data >= value.data; }
inline cbool operator<=(cfp32n &value) const { return data <= value.data; }
inline cbool operator>(cfp32n &value) const { return data > value.data; }
inline cbool operator<(cfp32n &value) const { return data < value.data; }
inline cbool operator||(cfp32n &value) const { return data || value.data; }
inline cbool operator&&(cfp32n &value) const { return data && value.data; }
inline cfp32n operator+(cfp32n &value) const { return (cfp32n &)(data + toFixedMod(value)); }
inline cfp32n operator-(cfp32n &value) const { return (cfp32n &)(data - toFixedMod(value)); }
inline cfp32n operator*(cfp32n &value) const { return toFixed(toFloat() * toFloat(value)); }
inline cfp32n operator/(cfp32n &value) const { return toFixed(toFloat() / toFloat(value)); }
inline cfp32n operator%(cfp32n &value) const { return (cfp32n &)(data % toFixedMod(value)); }
inline cfp32n operator&(cfp32n &value) const { return (cfp32n &)(data & value.data); }
inline cfp32n operator|(cfp32n &value) const { return (cfp32n &)(data | value.data); }
inline cfp32n operator^(cfp32n &value) const { return (cfp32n &)(data ^ value.data); }
inline cfp32n operator+=(cfp32n &value) { return (cfp32n &)(data += toFixedMod(value)); }
inline cfp32n operator-=(cfp32n &value) { return (cfp32n &)(data -= toFixedMod(value)); }
inline cfp32n operator*=(cfp32n &value) { return data = toFixed(toFloat() * toFloat(value)); }
inline cfp32n operator/=(cfp32n &value) { return data = toFixed(toFloat() / toFloat(value)); }
inline cfp32n operator%=(cfp32n &value) { return (cfp32n &)(data %= toFixedMod(value)); }
inline cfp32n operator&=(cfp32n &value) { return (cfp32n &)(data &= value.data); }
inline cfp32n operator|=(cfp32n &value) { return (cfp32n &)(data |= value.data); }
inline cfp32n operator^=(cfp32n &value) { return (cfp32n &)(data ^= value.data); }
inline cbool operator==(cfl64 &value) const { return data == toFixed(value); }
inline cbool operator!=(cfl64 &value) const { return data != toFixed(value); }
inline cbool operator>=(cfl64 &value) const { return data <= toFixed(value); }
inline cbool operator<=(cfl64 &value) const { return data >= toFixed(value); }
inline cbool operator>(cfl64 &value) const { return data < toFixed(value); }
inline cbool operator<(cfl64 &value) const { return data > toFixed(value); }
inline cbool operator||(cfl64 &value) const { return data || toFixed(value); }
inline cbool operator&&(cfl64 &value) const { return data && toFixed(value); }
inline cfl64 operator+(cfl64 &value) const { return toFloat() + value; }
inline cfl64 operator-(cfl64 &value) const { return toFloat() - value; }
inline cfl64 operator*(cfl64 &value) const { return toFloat() * value; }
inline cfl64 operator/(cfl64 &value) const { return toFloat() / value; }
inline cfp32n operator%(cfl64 &value) const { return (cfp32n &)(data % toFixed(value)); }
inline cfp32n operator&(cfl64 &value) const { return (cfp32n &)(data & toFixed(value)); }
inline cfp32n operator|(cfl64 &value) const { return (cfp32n &)(data | toFixed(value)); }
inline cfp32n operator^(cfl64 &value) const { return (cfp32n &)(data ^ toFixed(value)); }
inline cfl64 operator+=(cfl64 &value) { cfl64 temp = toFloat() + value; *this = toFixed(temp); return temp; }
inline cfl64 operator-=(cfl64 &value) { cfl64 temp = toFloat() - value; *this = toFixed(temp); return temp; }
inline cfl64 operator*=(cfl64 &value) { cfl64 temp = toFloat() * value; *this = toFixed(temp); return temp; }
inline cfl64 operator/=(cfl64 &value) { cfl64 temp = toFloat() / value; *this = toFixed(temp); return temp; }
inline cfp32n operator%=(cfl64 &value) { return (cfp32n &)(data %= toFixed(value)); }
inline cfp32n operator&=(cfl64 &value) { return (cfp32n &)(data &= toFixed(value)); }
inline cfp32n operator|=(cfl64 &value) { return (cfp32n &)(data |= toFixed(value)); }
inline cfp32n operator^=(cfl64 &value) { return (cfp32n &)(data ^= toFixed(value)); }
};
#endif // #ifndef FPDT_NO_CUSTOM
// 8-bit, 0.8 : Decimal range of 0.0~0.99609375
struct f0p8 {
typedef const f0p8 cf0p8;
ui8 data;
inline cui8 toFixed(cfl32 &value) const { return ui8(value * 256.0f); }
inline cfl32 toFloat(void) const { return cfl32(data) * _fpdt_rcp256f; }
inline cfl32 toFloat(cf0p8 &value) const { return fl32(value.data) * _fpdt_rcp256f; }
f0p8(void) = default;
#ifndef FPDT_NO_CUSTOM
f0p8(const fp8n value) { data = toFixed(fl32(value) * __fpdt_data__.rangeDivMax8 + __fpdt_data__.origin8); }
f0p8(const fp16n value) { data = toFixed(fl32(value) * __fpdt_data__.rangeDivMax16 + __fpdt_data__.origin16); }
#ifdef _24BIT_INTEGERS_
f0p8(const fp24n value) { data = toFixed(fl32(value) * __fpdt_data__.rangeDivMax24 + __fpdt_data__.origin24); }
#endif
f0p8(const fp32n value) { data = toFixed(fl32(fl64(value) * __fpdt_data__.rangeDivMax32 + __fpdt_data__.origin32)); }
#endif