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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
|
/* This is a software fixed-point library.
Copyright (C) 2007-2019 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.
You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */
#ifndef _FIXED_BIT_H
#define _FIXED_BIT_H
#ifdef LIBGCC2_GNU_PREFIX
#define LIBGCC2_FIXEDBIT_GNU_PREFIX
#endif
/* To use this file we need to define one of the following:
QQ_MODE, UQQ_MODE, HQ_MODE, UHQ_MODE, SQ_MODE, USQ_MODE, DQ_MODE, UDQ_MODE,
TQ_MODE, UTQ_MODE, HA_MODE, UHA_MODE, SA_MODE, USA_MODE, DA_MODE, UDA_MODE,
TA_MODE, UTA_MODE.
Then, all operators for this machine mode will be created.
Or, we need to define FROM_* TO_* for conversions from one mode to another
mode. The mode could be one of the following:
Fract: QQ, UQQ, HQ, UHQ, SQ, USQ, DQ, UDQ, TQ, UTQ
Accum: HA, UHA, SA, USA, DA, UDA, TA, UTA
Signed integer: QI, HI, SI, DI, TI
Unsigned integer: UQI, UHI, USI, UDI, UTI
Floating-point: SF, DF
Ex: If we define FROM_QQ and TO_SI, the conversion from QQ to SI is
generated. */
#ifdef __LIBGCC_HAS_SF_MODE__
#define LIBGCC2_HAS_SF_MODE 1
#else
#define LIBGCC2_HAS_SF_MODE 0
#endif
#ifdef __LIBGCC_HAS_DF_MODE__
#define LIBGCC2_HAS_DF_MODE 1
#else
#define LIBGCC2_HAS_DF_MODE 0
#endif
typedef int QItype __attribute__ ((mode (QI)));
typedef unsigned int UQItype __attribute__ ((mode (QI)));
typedef int HItype __attribute__ ((mode (HI)));
typedef unsigned int UHItype __attribute__ ((mode (HI)));
typedef _Fract QQtype __attribute__ ((mode (QQ)));
typedef unsigned _Fract UQQtype __attribute__ ((mode (UQQ)));
typedef _Fract HQtype __attribute__ ((mode (HQ)));
typedef unsigned _Fract UHQtype __attribute__ ((mode (UHQ)));
typedef _Fract HAtype __attribute__ ((mode (HA)));
typedef unsigned _Fract UHAtype __attribute__ ((mode (UHA)));
#define HAVE_QQ 1
#define HAVE_UQQ 1
#define HAVE_HQ 1
#define HAVE_UHQ 1
#define HAVE_HA 1
#define HAVE_UHA 1
#define HAVE_QI 1
#define HAVE_UQI 1
#define HAVE_HI 1
#define HAVE_UHI 1
#if MIN_UNITS_PER_WORD > 1
/* These typedefs are usually forbidden on dsp's with UNITS_PER_WORD 1. */
typedef int SItype __attribute__ ((mode (SI)));
typedef unsigned int USItype __attribute__ ((mode (SI)));
typedef _Fract SQtype __attribute__ ((mode (SQ)));
typedef unsigned _Fract USQtype __attribute__ ((mode (USQ)));
typedef _Fract SAtype __attribute__ ((mode (SA)));
typedef unsigned _Fract USAtype __attribute__ ((mode (USA)));
#define HAVE_SQ 1
#define HAVE_USQ 1
#define HAVE_SA 1
#define HAVE_USA 1
#define HAVE_SI 1
#define HAVE_USI 1
#if LONG_LONG_TYPE_SIZE > 32
/* These typedefs are usually forbidden on archs with UNITS_PER_WORD 2. */
typedef int DItype __attribute__ ((mode (DI)));
typedef unsigned int UDItype __attribute__ ((mode (DI)));
typedef _Fract DQtype __attribute__ ((mode (DQ)));
typedef unsigned _Fract UDQtype __attribute__ ((mode (UDQ)));
typedef _Fract DAtype __attribute__ ((mode (DA)));
typedef unsigned _Fract UDAtype __attribute__ ((mode (UDA)));
#define HAVE_DQ 1
#define HAVE_UDQ 1
#define HAVE_DA 1
#define HAVE_UDA 1
#define HAVE_DI 1
#define HAVE_UDI 1
#if MIN_UNITS_PER_WORD > 4
/* These typedefs are usually forbidden on archs with UNITS_PER_WORD 4. */
typedef int TItype __attribute__ ((mode (TI)));
typedef unsigned int UTItype __attribute__ ((mode (TI)));
typedef _Fract TQtype __attribute__ ((mode (TQ)));
typedef unsigned _Fract UTQtype __attribute__ ((mode (UTQ)));
typedef _Fract TAtype __attribute__ ((mode (TA)));
typedef unsigned _Fract UTAtype __attribute__ ((mode (UTA)));
#define HAVE_TQ 1
#define HAVE_UTQ 1
#define HAVE_TA 1
#define HAVE_UTA 1
#define HAVE_TI 1
#define HAVE_UTI 1
#endif
#endif
#endif
#if LIBGCC2_HAS_SF_MODE
typedef float SFtype __attribute__ ((mode (SF)));
#define HAVE_SF 1
#endif
#if LIBGCC2_HAS_DF_MODE
typedef float DFtype __attribute__ ((mode (DF)));
#define HAVE_DF 1
#endif
typedef int word_type __attribute__ ((mode (__word__)));
/* Based on modes, we create many defines. */
#if defined (QQ_MODE) && (HAVE_QQ == 1)
#define FIXED_SIZE 1 /* in bytes. */
#define INT_C_TYPE QItype
#define UINT_C_TYPE UQItype
#define DINT_C_TYPE HItype
#define DUINT_C_TYPE UHItype
#define MODE_NAME QQ
#define MODE_NAME_S qq
#define MODE_UNSIGNED 0
#endif
#if defined (UQQ_MODE) && (HAVE_UQQ == 1)
#define FIXED_SIZE 1 /* in bytes. */
#define INT_C_TYPE UQItype
#define UINT_C_TYPE UQItype
#define DINT_C_TYPE UHItype
#define DUINT_C_TYPE UHItype
#define MODE_NAME UQQ
#define MODE_NAME_S uqq
#define MODE_UNSIGNED 1
#endif
#if defined (HQ_MODE) && (HAVE_HQ == 1)
#define FIXED_SIZE 2 /* in bytes. */
#define INT_C_TYPE HItype
#define UINT_C_TYPE UHItype
#if HAVE_SI == 1
#define DINT_C_TYPE SItype
#define DUINT_C_TYPE USItype
#else
#define HINT_C_TYPE QItype
#define HUINT_C_TYPE UQItype
#endif
#define MODE_NAME HQ
#define MODE_NAME_S hq
#define MODE_UNSIGNED 0
#endif
#if defined (UHQ_MODE) && (HAVE_UHQ == 1)
#define FIXED_SIZE 2 /* in bytes. */
#define INT_C_TYPE UHItype
#define UINT_C_TYPE UHItype
#if HAVE_SI == 1
#define DINT_C_TYPE USItype
#define DUINT_C_TYPE USItype
#else
#define HINT_C_TYPE UQItype
#define HUINT_C_TYPE UQItype
#endif
#define MODE_NAME UHQ
#define MODE_NAME_S uhq
#define MODE_UNSIGNED 1
#endif
#if defined (SQ_MODE) && (HAVE_SQ == 1)
#define FIXED_SIZE 4 /* in bytes. */
#define INT_C_TYPE SItype
#define UINT_C_TYPE USItype
#if HAVE_DI == 1
#define DINT_C_TYPE DItype
#define DUINT_C_TYPE UDItype
#else
#define HINT_C_TYPE HItype
#define HUINT_C_TYPE UHItype
#endif
#define MODE_NAME SQ
#define MODE_NAME_S sq
#define MODE_UNSIGNED 0
#endif
#if defined (USQ_MODE) && (HAVE_USQ == 1)
#define FIXED_SIZE 4 /* in bytes. */
#define INT_C_TYPE USItype
#define UINT_C_TYPE USItype
#if HAVE_DI == 1
#define DINT_C_TYPE UDItype
#define DUINT_C_TYPE UDItype
#else
#define HINT_C_TYPE UHItype
#define HUINT_C_TYPE UHItype
#endif
#define MODE_NAME USQ
#define MODE_NAME_S usq
#define MODE_UNSIGNED 1
#endif
#if defined (DQ_MODE) && (HAVE_DQ == 1)
#define FIXED_SIZE 8 /* in bytes. */
#define INT_C_TYPE DItype
#define UINT_C_TYPE UDItype
#if HAVE_TI == 1
#define DINT_C_TYPE TItype
#define DUINT_C_TYPE UTItype
#else
#define HINT_C_TYPE SItype
#define HUINT_C_TYPE USItype
#endif
#define MODE_NAME DQ
#define MODE_NAME_S dq
#define MODE_UNSIGNED 0
#endif
#if defined (UDQ_MODE) && (HAVE_UDQ == 1)
#define FIXED_SIZE 8 /* in bytes. */
#define INT_C_TYPE UDItype
#define UINT_C_TYPE UDItype
#if HAVE_TI == 1
#define DINT_C_TYPE UTItype
#define DUINT_C_TYPE UTItype
#else
#define HINT_C_TYPE USItype
#define HUINT_C_TYPE USItype
#endif
#define MODE_NAME UDQ
#define MODE_NAME_S udq
#define MODE_UNSIGNED 1
#endif
#if defined (TQ_MODE) && (HAVE_TQ == 1)
#define FIXED_SIZE 16 /* in bytes. */
#define INT_C_TYPE TItype
#define UINT_C_TYPE UTItype
#define HINT_C_TYPE DItype
#define HUINT_C_TYPE UDItype
#define MODE_NAME TQ
#define MODE_NAME_S tq
#define MODE_UNSIGNED 0
#endif
#if defined (UTQ_MODE) && (HAVE_UTQ == 1)
#define FIXED_SIZE 16 /* in bytes. */
#define INT_C_TYPE UTItype
#define UINT_C_TYPE UTItype
#define HINT_C_TYPE UDItype
#define HUINT_C_TYPE UDItype
#define MODE_NAME UTQ
#define MODE_NAME_S utq
#define MODE_UNSIGNED 1
#endif
#if defined (HA_MODE) && (HAVE_HA == 1)
#define FIXED_SIZE 2 /* in bytes. */
#define INT_C_TYPE HItype
#define UINT_C_TYPE UHItype
#if HAVE_SI == 1
#define DINT_C_TYPE SItype
#define DUINT_C_TYPE USItype
#else
#define HINT_C_TYPE QItype
#define HUINT_C_TYPE UQItype
#endif
#define MODE_NAME HA
#define MODE_NAME_S ha
#define MODE_UNSIGNED 0
#endif
#if defined (UHA_MODE) && (HAVE_UHA == 1)
#define FIXED_SIZE 2 /* in bytes. */
#define INT_C_TYPE UHItype
#define UINT_C_TYPE UHItype
#if HAVE_SI == 1
#define DINT_C_TYPE USItype
#define DUINT_C_TYPE USItype
#else
#define HINT_C_TYPE UQItype
#define HUINT_C_TYPE UQItype
#endif
#define MODE_NAME UHA
#define MODE_NAME_S uha
#define MODE_UNSIGNED 1
#endif
#if defined (SA_MODE) && (HAVE_SA == 1)
#define FIXED_SIZE 4 /* in bytes. */
#define INT_C_TYPE SItype
#define UINT_C_TYPE USItype
#if HAVE_DI == 1
#define DINT_C_TYPE DItype
#define DUINT_C_TYPE UDItype
#else
#define HINT_C_TYPE HItype
#define HUINT_C_TYPE UHItype
#endif
#define MODE_NAME SA
#define MODE_NAME_S sa
#define MODE_UNSIGNED 0
#endif
#if defined (USA_MODE) && (HAVE_USA == 1)
#define FIXED_SIZE 4 /* in bytes. */
#define INT_C_TYPE USItype
#define UINT_C_TYPE USItype
#if HAVE_DI == 1
#define DINT_C_TYPE UDItype
#define DUINT_C_TYPE UDItype
#else
#define HINT_C_TYPE UHItype
#define HUINT_C_TYPE UHItype
#endif
#define MODE_NAME USA
#define MODE_NAME_S usa
#define MODE_UNSIGNED 1
#endif
#if defined (DA_MODE) && (HAVE_DA == 1)
#define FIXED_SIZE 8 /* in bytes. */
#define INT_C_TYPE DItype
#define UINT_C_TYPE UDItype
#if HAVE_TI == 1
#define DINT_C_TYPE TItype
#define DUINT_C_TYPE UTItype
#else
#define HINT_C_TYPE SItype
#define HUINT_C_TYPE USItype
#endif
#define MODE_NAME DA
#define MODE_NAME_S da
#define MODE_UNSIGNED 0
#endif
#if defined (UDA_MODE) && (HAVE_UDA == 1)
#define FIXED_SIZE 8 /* in bytes. */
#define INT_C_TYPE UDItype
#define UINT_C_TYPE UDItype
#if HAVE_TI == 1
#define DINT_C_TYPE UTItype
#define DUINT_C_TYPE UTItype
#else
#define HINT_C_TYPE USItype
#define HUINT_C_TYPE USItype
#endif
#define MODE_NAME UDA
#define MODE_NAME_S uda
#define MODE_UNSIGNED 1
#endif
#if defined (TA_MODE) && (HAVE_TA == 1)
#define FIXED_SIZE 16 /* in bytes. */
#define INT_C_TYPE TItype
#define UINT_C_TYPE UTItype
#define HINT_C_TYPE DItype
#define HUINT_C_TYPE UDItype
#define MODE_NAME TA
#define MODE_NAME_S ta
#define MODE_UNSIGNED 0
#endif
#if defined (UTA_MODE) && (HAVE_UTA == 1)
#define FIXED_SIZE 16 /* in bytes. */
#define INT_C_TYPE UTItype
#define UINT_C_TYPE UTItype
#define HINT_C_TYPE UDItype
#define HUINT_C_TYPE UDItype
#define MODE_NAME UTA
#define MODE_NAME_S uta
#define MODE_UNSIGNED 1
#endif
/* The following defines are based on the previous defines. */
#if defined (HINT_C_TYPE)
#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__
struct INTstruct {HINT_C_TYPE high, low;};
#else
struct INTstruct {HINT_C_TYPE low, high;};
#endif
typedef union
{
struct INTstruct s;
INT_C_TYPE ll;
} INTunion;
#endif
#define FIXED_WIDTH (FIXED_SIZE * __CHAR_BIT__) /* in bits. */
#define FIXED_C_TYPE1(NAME) NAME ## type
#define FIXED_C_TYPE2(NAME) FIXED_C_TYPE1(NAME)
#define FIXED_C_TYPE FIXED_C_TYPE2(MODE_NAME)
#define FBITS1(NAME) __ ## NAME ## _FBIT__
#define FBITS2(NAME) FBITS1(NAME)
#define FBITS FBITS2(MODE_NAME)
#define IBITS1(NAME) __ ## NAME ## _IBIT__
#define IBITS2(NAME) IBITS1(NAME)
#define IBITS IBITS2(MODE_NAME)
#define I_F_BITS (FBITS + IBITS)
#ifdef LIBGCC2_FIXEDBIT_GNU_PREFIX
#define FIXED_OP(OP,MODE,NUM) __gnu_ ## OP ## MODE ## NUM
#else
#define FIXED_OP(OP,MODE,NUM) __ ## OP ## MODE ## NUM
#endif
#define FIXED_SATURATE1_TEMP(NAME) FIXED_OP(saturate1,NAME,)
#define FIXED_SATURATE2_TEMP(NAME) FIXED_OP(saturate2,NAME,)
#define FIXED_MULHELPER_TEMP(NAME) FIXED_OP(mulhelper,NAME,)
#define FIXED_DIVHELPER_TEMP(NAME) FIXED_OP(divhelper,NAME,)
#define FIXED_ASHLHELPER_TEMP(NAME) FIXED_OP(ashlhelper,NAME,)
#define FIXED_ADD_TEMP(NAME) FIXED_OP(add,NAME,3)
#define FIXED_SSADD_TEMP(NAME) FIXED_OP(ssadd,NAME,3)
#define FIXED_USADD_TEMP(NAME) FIXED_OP(usadd,NAME,3)
#define FIXED_SUB_TEMP(NAME) FIXED_OP(sub,NAME,3)
#define FIXED_SSSUB_TEMP(NAME) FIXED_OP(sssub,NAME,3)
#define FIXED_USSUB_TEMP(NAME) FIXED_OP(ussub,NAME,3)
#define FIXED_MUL_TEMP(NAME) FIXED_OP(mul,NAME,3)
#define FIXED_SSMUL_TEMP(NAME) FIXED_OP(ssmul,NAME,3)
#define FIXED_USMUL_TEMP(NAME) FIXED_OP(usmul,NAME,3)
#define FIXED_DIV_TEMP(NAME) FIXED_OP(div,NAME,3)
#define FIXED_UDIV_TEMP(NAME) FIXED_OP(udiv,NAME,3)
#define FIXED_SSDIV_TEMP(NAME) FIXED_OP(ssdiv,NAME,3)
#define FIXED_USDIV_TEMP(NAME) FIXED_OP(usdiv,NAME,3)
#define FIXED_NEG_TEMP(NAME) FIXED_OP(neg,NAME,2)
#define FIXED_SSNEG_TEMP(NAME) FIXED_OP(ssneg,NAME,2)
#define FIXED_USNEG_TEMP(NAME) FIXED_OP(usneg,NAME,2)
#define FIXED_ASHL_TEMP(NAME) FIXED_OP(ashl,NAME,3)
#define FIXED_ASHR_TEMP(NAME) FIXED_OP(ashr,NAME,3)
#define FIXED_LSHR_TEMP(NAME) FIXED_OP(lshr,NAME,3)
#define FIXED_SSASHL_TEMP(NAME) FIXED_OP(ssashl,NAME,3)
#define FIXED_USASHL_TEMP(NAME) FIXED_OP(usashl,NAME,3)
#define FIXED_CMP_TEMP(NAME) FIXED_OP(cmp,NAME,2)
#if defined (MODE_NAME)
#if defined (DINT_C_TYPE)
#define FIXED_SATURATE1 FIXED_SATURATE1_TEMP(MODE_NAME_S)
#else
#define FIXED_SATURATE2 FIXED_SATURATE2_TEMP(MODE_NAME_S)
#endif
#define FIXED_MULHELPER FIXED_MULHELPER_TEMP(MODE_NAME_S)
#define FIXED_DIVHELPER FIXED_DIVHELPER_TEMP(MODE_NAME_S)
#define FIXED_ASHLHELPER FIXED_ASHLHELPER_TEMP(MODE_NAME_S)
#define FIXED_ADD FIXED_ADD_TEMP(MODE_NAME_S)
#define FIXED_SUB FIXED_SUB_TEMP(MODE_NAME_S)
#define FIXED_MUL FIXED_MUL_TEMP(MODE_NAME_S)
#define FIXED_NEG FIXED_NEG_TEMP(MODE_NAME_S)
#define FIXED_ASHL FIXED_ASHL_TEMP(MODE_NAME_S)
#define FIXED_CMP FIXED_CMP_TEMP(MODE_NAME_S)
/* The following functions are for all fixed-point modes. */
#if defined (DINT_C_TYPE)
extern void FIXED_SATURATE1 (DINT_C_TYPE *);
#else
extern void FIXED_SATURATE2 (INT_C_TYPE *, INT_C_TYPE *);
#endif
extern FIXED_C_TYPE FIXED_MULHELPER (FIXED_C_TYPE, FIXED_C_TYPE, word_type);
extern FIXED_C_TYPE FIXED_DIVHELPER (FIXED_C_TYPE, FIXED_C_TYPE, word_type);
extern FIXED_C_TYPE FIXED_ASHLHELPER (FIXED_C_TYPE, word_type, word_type);
extern FIXED_C_TYPE FIXED_ADD (FIXED_C_TYPE, FIXED_C_TYPE);
extern FIXED_C_TYPE FIXED_SUB (FIXED_C_TYPE, FIXED_C_TYPE);
extern FIXED_C_TYPE FIXED_MUL (FIXED_C_TYPE, FIXED_C_TYPE);
extern FIXED_C_TYPE FIXED_NEG (FIXED_C_TYPE);
extern FIXED_C_TYPE FIXED_ASHL (FIXED_C_TYPE, word_type);
extern word_type FIXED_CMP (FIXED_C_TYPE, FIXED_C_TYPE);
#endif
#if MODE_UNSIGNED == 0 /* Signed types. */
#define PADDING_BITS (FIXED_WIDTH - 1 - I_F_BITS)
#define NONPADDING_BITS (1 + I_F_BITS)
#if defined (MODE_NAME)
#define FIXED_DIV FIXED_DIV_TEMP(MODE_NAME_S)
#define FIXED_ASHR FIXED_ASHR_TEMP(MODE_NAME_S)
#define FIXED_SSADD FIXED_SSADD_TEMP(MODE_NAME_S)
#define FIXED_SSSUB FIXED_SSSUB_TEMP(MODE_NAME_S)
#define FIXED_SSMUL FIXED_SSMUL_TEMP(MODE_NAME_S)
#define FIXED_SSDIV FIXED_SSDIV_TEMP(MODE_NAME_S)
#define FIXED_SSNEG FIXED_SSNEG_TEMP(MODE_NAME_S)
#define FIXED_SSASHL FIXED_SSASHL_TEMP(MODE_NAME_S)
/* The following functions are for signed fixed-point modes. */
extern FIXED_C_TYPE FIXED_DIV (FIXED_C_TYPE, FIXED_C_TYPE);
extern FIXED_C_TYPE FIXED_ASHR (FIXED_C_TYPE, word_type);
extern FIXED_C_TYPE FIXED_SSADD (FIXED_C_TYPE, FIXED_C_TYPE);
extern FIXED_C_TYPE FIXED_SSSUB (FIXED_C_TYPE, FIXED_C_TYPE);
extern FIXED_C_TYPE FIXED_SSMUL (FIXED_C_TYPE, FIXED_C_TYPE);
extern FIXED_C_TYPE FIXED_SSDIV (FIXED_C_TYPE, FIXED_C_TYPE);
extern FIXED_C_TYPE FIXED_SSNEG (FIXED_C_TYPE);
extern FIXED_C_TYPE FIXED_SSASHL (FIXED_C_TYPE, word_type);
#endif
#else /* Unsigned types. */
#define PADDING_BITS (FIXED_WIDTH - I_F_BITS)
#define NONPADDING_BITS (I_F_BITS)
#if defined (MODE_NAME)
#define FIXED_UDIV FIXED_UDIV_TEMP(MODE_NAME_S)
#define FIXED_LSHR FIXED_LSHR_TEMP(MODE_NAME_S)
#define FIXED_USDIV FIXED_USDIV_TEMP(MODE_NAME_S)
#define FIXED_USADD FIXED_USADD_TEMP(MODE_NAME_S)
#define FIXED_USSUB FIXED_USSUB_TEMP(MODE_NAME_S)
#define FIXED_USMUL FIXED_USMUL_TEMP(MODE_NAME_S)
#define FIXED_USNEG FIXED_USNEG_TEMP(MODE_NAME_S)
#define FIXED_USASHL FIXED_USASHL_TEMP(MODE_NAME_S)
/* The following functions are for unsigned fixed-point modes. */
extern FIXED_C_TYPE FIXED_UDIV (FIXED_C_TYPE, FIXED_C_TYPE);
extern FIXED_C_TYPE FIXED_LSHR (FIXED_C_TYPE, word_type);
extern FIXED_C_TYPE FIXED_USADD (FIXED_C_TYPE, FIXED_C_TYPE);
extern FIXED_C_TYPE FIXED_USSUB (FIXED_C_TYPE, FIXED_C_TYPE);
extern FIXED_C_TYPE FIXED_USMUL (FIXED_C_TYPE, FIXED_C_TYPE);
extern FIXED_C_TYPE FIXED_USDIV (FIXED_C_TYPE, FIXED_C_TYPE);
extern FIXED_C_TYPE FIXED_USNEG (FIXED_C_TYPE);
extern FIXED_C_TYPE FIXED_USASHL (FIXED_C_TYPE, word_type);
#endif
#endif /* End of testing MODE_UNSIGNED. */
/* This define is to check if this mode have any padding bits. */
#define HAVE_PADDING_BITS (PADDING_BITS > 0)
/* ------------------------------------------------------------------------ */
/* The following defines are for conversions. */
#if defined (FROM_QI) && HAVE_QI == 1
#define FROM_TYPE 1 /* Signed integer. */
#define FROM_INT_C_TYPE QItype
#define FROM_SINT_C_TYPE QItype
#define FROM_UINT_C_TYPE UQItype
#define FROM_MODE_NAME_S qi
#define FROM_INT_SIZE 1 /* in bytes. */
#elif defined (FROM_HI) && HAVE_HI == 1
#define FROM_TYPE 1 /* Signed integer. */
#define FROM_INT_C_TYPE HItype
#define FROM_SINT_C_TYPE HItype
#define FROM_UINT_C_TYPE UHItype
#define FROM_MODE_NAME_S hi
#define FROM_INT_SIZE 2 /* in bytes. */
#elif defined (FROM_SI) && HAVE_SI == 1
#define FROM_TYPE 1 /* Signed integer. */
#define FROM_INT_C_TYPE SItype
#define FROM_SINT_C_TYPE SItype
#define FROM_UINT_C_TYPE USItype
#define FROM_MODE_NAME_S si
#define FROM_INT_SIZE 4 /* in bytes. */
#elif defined (FROM_DI) && HAVE_DI == 1
#define FROM_TYPE 1 /* Signed integer. */
#define FROM_INT_C_TYPE DItype
#define FROM_SINT_C_TYPE DItype
#define FROM_UINT_C_TYPE UDItype
#define FROM_MODE_NAME_S di
#define FROM_INT_SIZE 8 /* in bytes. */
#elif defined (FROM_TI) && HAVE_TI == 1
#define FROM_TYPE 1 /* Signed integer. */
#define FROM_INT_C_TYPE TItype
#define FROM_SINT_C_TYPE TItype
#define FROM_UINT_C_TYPE UTItype
#define FROM_MODE_NAME_S ti
#define FROM_INT_SIZE 16 /* in bytes. */
#elif defined (FROM_UQI) && HAVE_UQI == 1
#define FROM_TYPE 2 /* Unsigned integer. */
#define FROM_INT_C_TYPE QItype
#define FROM_SINT_C_TYPE QItype
#define FROM_UINT_C_TYPE UQItype
#define FROM_MODE_NAME_S qi
#define FROM_INT_SIZE 1 /* in bytes. */
#elif defined (FROM_UHI) && HAVE_UHI == 1
#define FROM_TYPE 2 /* Unsigned integer. */
#define FROM_INT_C_TYPE UHItype
#define FROM_SINT_C_TYPE HItype
#define FROM_UINT_C_TYPE UHItype
#define FROM_MODE_NAME_S hi
#define FROM_INT_SIZE 2 /* in bytes. */
#elif defined (FROM_USI) && HAVE_USI == 1
#define FROM_TYPE 2 /* Unsigned integer. */
#define FROM_INT_C_TYPE USItype
#define FROM_SINT_C_TYPE SItype
#define FROM_UINT_C_TYPE USItype
#define FROM_MODE_NAME_S si
#define FROM_INT_SIZE 4 /* in bytes. */
#elif defined (FROM_UDI) && HAVE_UDI == 1
#define FROM_TYPE 2 /* Unsigned integer. */
#define FROM_INT_C_TYPE UDItype
#define FROM_SINT_C_TYPE DItype
#define FROM_UINT_C_TYPE UDItype
#define FROM_MODE_NAME_S di
#define FROM_INT_SIZE 8 /* in bytes. */
#elif defined (FROM_UTI) && HAVE_UTI == 1
#define FROM_TYPE 2 /* Unsigned integer. */
#define FROM_INT_C_TYPE UTItype
#define FROM_SINT_C_TYPE TItype
#define FROM_UINT_C_TYPE UTItype
#define FROM_MODE_NAME_S ti
#define FROM_INT_SIZE 16 /* in bytes. */
#elif defined (FROM_SF) && HAVE_SF == 1
#define FROM_TYPE 3 /* Floating-point. */
#define FROM_FLOAT_C_TYPE SFtype
#define FROM_MODE_NAME_S sf
#elif defined (FROM_DF) && HAVE_DF == 1
#define FROM_TYPE 3 /* Floating-point. */
#define FROM_FLOAT_C_TYPE DFtype
#define FROM_MODE_NAME_S df
#elif defined (FROM_QQ) && HAVE_QQ == 1
#define FROM_TYPE 4 /* Fixed-point. */
#define FROM_MODE_NAME QQ
#define FROM_MODE_NAME_S qq
#define FROM_INT_C_TYPE QItype
#define FROM_SINT_C_TYPE QItype
#define FROM_UINT_C_TYPE UQItype
#define FROM_MODE_UNSIGNED 0
#define FROM_FIXED_SIZE 1 /* in bytes. */
#elif defined (FROM_HQ) && HAVE_HQ == 1
#define FROM_TYPE 4 /* Fixed-point. */
#define FROM_MODE_NAME HQ
#define FROM_MODE_NAME_S hq
#define FROM_INT_C_TYPE HItype
#define FROM_SINT_C_TYPE HItype
#define FROM_UINT_C_TYPE UHItype
#define FROM_MODE_UNSIGNED 0
#define FROM_FIXED_SIZE 2 /* in bytes. */
#elif defined (FROM_SQ) && HAVE_SQ == 1
#define FROM_TYPE 4 /* Fixed-point. */
#define FROM_MODE_NAME SQ
#define FROM_MODE_NAME_S sq
#define FROM_INT_C_TYPE SItype
#define FROM_SINT_C_TYPE SItype
#define FROM_UINT_C_TYPE USItype
#define FROM_MODE_UNSIGNED 0
#define FROM_FIXED_SIZE 4 /* in bytes. */
#elif defined (FROM_DQ) && HAVE_DQ == 1
#define FROM_TYPE 4 /* Fixed-point. */
#define FROM_MODE_NAME DQ
#define FROM_MODE_NAME_S dq
#define FROM_INT_C_TYPE DItype
#define FROM_SINT_C_TYPE DItype
#define FROM_UINT_C_TYPE UDItype
#define FROM_MODE_UNSIGNED 0
#define FROM_FIXED_SIZE 8 /* in bytes. */
#elif defined (FROM_TQ) && HAVE_TQ == 1
#define FROM_TYPE 4 /* Fixed-point. */
#define FROM_MODE_NAME TQ
#define FROM_MODE_NAME_S tq
#define FROM_INT_C_TYPE TItype
#define FROM_SINT_C_TYPE TItype
#define FROM_UINT_C_TYPE UTItype
#define FROM_MODE_UNSIGNED 0
#define FROM_FIXED_SIZE 16 /* in bytes. */
#elif defined (FROM_UQQ) && HAVE_UQQ == 1
#define FROM_TYPE 4 /* Fixed-point. */
#define FROM_MODE_NAME UQQ
#define FROM_MODE_NAME_S uqq
#define FROM_INT_C_TYPE UQItype
#define FROM_SINT_C_TYPE QItype
#define FROM_UINT_C_TYPE UQItype
#define FROM_MODE_UNSIGNED 1
#define FROM_FIXED_SIZE 1 /* in bytes. */
#elif defined (FROM_UHQ) && HAVE_UHQ == 1
#define FROM_TYPE 4 /* Fixed-point. */
#define FROM_MODE_NAME UHQ
#define FROM_MODE_NAME_S uhq
#define FROM_INT_C_TYPE UHItype
#define FROM_SINT_C_TYPE HItype
#define FROM_UINT_C_TYPE UHItype
#define FROM_MODE_UNSIGNED 1
#define FROM_FIXED_SIZE 2 /* in bytes. */
#elif defined (FROM_USQ) && HAVE_USQ == 1
#define FROM_TYPE 4 /* Fixed-point. */
#define FROM_MODE_NAME USQ
#define FROM_MODE_NAME_S usq
#define FROM_INT_C_TYPE USItype
#define FROM_SINT_C_TYPE SItype
#define FROM_UINT_C_TYPE USItype
#define FROM_MODE_UNSIGNED 1
#define FROM_FIXED_SIZE 4 /* in bytes. */
#elif defined (FROM_UDQ) && HAVE_UDQ == 1
#define FROM_TYPE 4 /* Fixed-point. */
#define FROM_MODE_NAME UDQ
#define FROM_MODE_NAME_S udq
#define FROM_INT_C_TYPE UDItype
#define FROM_SINT_C_TYPE DItype
#define FROM_UINT_C_TYPE UDItype
#define FROM_MODE_UNSIGNED 1
#define FROM_FIXED_SIZE 8 /* in bytes. */
#elif defined (FROM_UTQ) && HAVE_UTQ == 1
#define FROM_TYPE 4 /* Fixed-point. */
#define FROM_MODE_NAME UTQ
#define FROM_MODE_NAME_S utq
#define FROM_INT_C_TYPE UTItype
#define FROM_SINT_C_TYPE TItype
#define FROM_UINT_C_TYPE UTItype
#define FROM_MODE_UNSIGNED 1
#define FROM_FIXED_SIZE 16 /* in bytes. */
#elif defined (FROM_HA) && HAVE_HA == 1
#define FROM_TYPE 4 /* Fixed-point. */
#define FROM_MODE_NAME HA
#define FROM_MODE_NAME_S ha
#define FROM_INT_C_TYPE HItype
#define FROM_SINT_C_TYPE HItype
#define FROM_UINT_C_TYPE UHItype
#define FROM_MODE_UNSIGNED 0
#define FROM_FIXED_SIZE 2 /* in bytes. */
#elif defined (FROM_SA) && HAVE_SA == 1
#define FROM_TYPE 4 /* Fixed-point. */
#define FROM_MODE_NAME SA
#define FROM_MODE_NAME_S sa
#define FROM_INT_C_TYPE SItype
#define FROM_SINT_C_TYPE SItype
#define FROM_UINT_C_TYPE USItype
#define FROM_MODE_UNSIGNED 0
#define FROM_FIXED_SIZE 4 /* in bytes. */
#elif defined (FROM_DA) && HAVE_DA == 1
#define FROM_TYPE 4 /* Fixed-point. */
#define FROM_MODE_NAME DA
#define FROM_MODE_NAME_S da
#define FROM_INT_C_TYPE DItype
#define FROM_SINT_C_TYPE DItype
#define FROM_UINT_C_TYPE UDItype
#define FROM_MODE_UNSIGNED 0
#define FROM_FIXED_SIZE 8 /* in bytes. */
#elif defined (FROM_TA) && HAVE_TA == 1
#define FROM_TYPE 4 /* Fixed-point. */
#define FROM_MODE_NAME TA
#define FROM_MODE_NAME_S ta
#define FROM_INT_C_TYPE TItype
#define FROM_SINT_C_TYPE TItype
#define FROM_UINT_C_TYPE UTItype
#define FROM_MODE_UNSIGNED 0
#define FROM_FIXED_SIZE 16 /* in bytes. */
#elif defined (FROM_UHA) && HAVE_UHA == 1
#define FROM_TYPE 4 /* Fixed-point. */
#define FROM_MODE_NAME UHA
#define FROM_MODE_NAME_S uha
#define FROM_INT_C_TYPE UHItype
#define FROM_SINT_C_TYPE HItype
#define FROM_UINT_C_TYPE UHItype
#define FROM_MODE_UNSIGNED 1
#define FROM_FIXED_SIZE 2 /* in bytes. */
#elif defined (FROM_USA) && HAVE_USA == 1
#define FROM_TYPE 4 /* Fixed-point. */
#define FROM_MODE_NAME USA
#define FROM_MODE_NAME_S usa
#define FROM_INT_C_TYPE USItype
#define FROM_SINT_C_TYPE SItype
#define FROM_UINT_C_TYPE USItype
#define FROM_MODE_UNSIGNED 1
#define FROM_FIXED_SIZE 4 /* in bytes. */
#elif defined (FROM_UDA) && HAVE_UDA == 1
#define FROM_TYPE 4 /* Fixed-point. */
#define FROM_MODE_NAME UDA
#define FROM_MODE_NAME_S uda
#define FROM_INT_C_TYPE UDItype
#define FROM_SINT_C_TYPE DItype
#define FROM_UINT_C_TYPE UDItype
#define FROM_MODE_UNSIGNED 1
#define FROM_FIXED_SIZE 8 /* in bytes. */
#elif defined (FROM_UTA) && HAVE_UTA == 1
#define FROM_TYPE 4 /* Fixed-point. */
#define FROM_MODE_NAME UTA
#define FROM_MODE_NAME_S uta
#define FROM_INT_C_TYPE UTItype
#define FROM_SINT_C_TYPE TItype
#define FROM_UINT_C_TYPE UTItype
#define FROM_MODE_UNSIGNED 1
#define FROM_FIXED_SIZE 16 /* in bytes. */
#endif
#if defined (TO_QI) && HAVE_QI == 1 && !defined (FROM_QI)
#define TO_TYPE 1 /* Signed integer. */
#define TO_INT_C_TYPE QItype
#define TO_SINT_C_TYPE QItype
#define TO_UINT_C_TYPE UQItype
#define TO_MODE_NAME_S qi
#elif defined (TO_HI) && HAVE_HI == 1 && !defined (FROM_HI)
#define TO_TYPE 1 /* Signed integer. */
#define TO_INT_C_TYPE HItype
#define TO_SINT_C_TYPE HItype
#define TO_UINT_C_TYPE UHItype
#define TO_MODE_NAME_S hi
#elif defined (TO_SI) && HAVE_SI == 1 && !defined (FROM_SI)
#define TO_TYPE 1 /* Signed integer. */
#define TO_INT_C_TYPE SItype
#define TO_SINT_C_TYPE SItype
#define TO_UINT_C_TYPE USItype
#define TO_MODE_NAME_S si
#elif defined (TO_DI) && HAVE_DI == 1 && !defined (FROM_DI)
#define TO_TYPE 1 /* Signed integer. */
#define TO_INT_C_TYPE DItype
#define TO_SINT_C_TYPE DItype
#define TO_UINT_C_TYPE UDItype
#define TO_MODE_NAME_S di
#elif defined (TO_TI) && HAVE_TI == 1 && !defined (FROM_TI)
#define TO_TYPE 1 /* Signed integer. */
#define TO_INT_C_TYPE TItype
#define TO_SINT_C_TYPE TItype
#define TO_UINT_C_TYPE UTItype
#define TO_MODE_NAME_S ti
#elif defined (TO_UQI) && HAVE_UQI == 1 && !defined (FROM_UQI)
#define TO_TYPE 2 /* Unsigned integer. */
#define TO_INT_C_TYPE UQItype
#define TO_SINT_C_TYPE QItype
#define TO_UINT_C_TYPE UQItype
#define TO_MODE_NAME_S qi
#elif defined (TO_UHI) && HAVE_UHI == 1 && !defined (FROM_UHI)
#define TO_TYPE 2 /* Unsigned integer. */
#define TO_INT_C_TYPE UHItype
#define TO_SINT_C_TYPE HItype
#define TO_UINT_C_TYPE UHItype
#define TO_MODE_NAME_S hi
#elif defined (TO_USI) && HAVE_USI == 1 && !defined (FROM_USI)
#define TO_TYPE 2 /* Unsigned integer. */
#define TO_INT_C_TYPE USItype
#define TO_SINT_C_TYPE SItype
#define TO_UINT_C_TYPE USItype
#define TO_MODE_NAME_S si
#elif defined (TO_UDI) && HAVE_UDI == 1 && !defined (FROM_UDI)
#define TO_TYPE 2 /* Unsigned integer. */
#define TO_INT_C_TYPE UDItype
#define TO_SINT_C_TYPE DItype
#define TO_UINT_C_TYPE UDItype
#define TO_MODE_NAME_S di
#elif defined (TO_UTI) && HAVE_UTI == 1 && !defined (FROM_UTI)
#define TO_TYPE 2 /* Unsigned integer. */
#define TO_INT_C_TYPE UTItype
#define TO_SINT_C_TYPE TItype
#define TO_UINT_C_TYPE UTItype
#define TO_MODE_NAME_S ti
#elif defined (TO_SF) && HAVE_SF == 1 && !defined (FROM_SF)
#define TO_TYPE 3 /* Floating-point. */
#define TO_FLOAT_C_TYPE SFtype
#define TO_MODE_NAME_S sf
#elif defined (TO_DF) && HAVE_DF == 1 && !defined (FROM_DF)
#define TO_TYPE 3 /* Floating-point. */
#define TO_FLOAT_C_TYPE DFtype
#define TO_MODE_NAME_S df
#elif defined (TO_QQ) && HAVE_QQ == 1 && !defined (FROM_QQ)
#define TO_TYPE 4 /* Fixed-point. */
#define TO_MODE_NAME QQ
#define TO_MODE_NAME_S qq
#define TO_INT_C_TYPE QItype
#define TO_SINT_C_TYPE QItype
#define TO_UINT_C_TYPE UQItype
#define TO_MODE_UNSIGNED 0
#define TO_FIXED_SIZE 1 /* in bytes. */
#elif defined (TO_HQ) && HAVE_HQ == 1 && !defined (FROM_HQ)
#define TO_TYPE 4 /* Fixed-point. */
#define TO_MODE_NAME HQ
#define TO_MODE_NAME_S hq
#define TO_INT_C_TYPE HItype
#define TO_SINT_C_TYPE HItype
#define TO_UINT_C_TYPE UHItype
#define TO_MODE_UNSIGNED 0
#define TO_FIXED_SIZE 2 /* in bytes. */
#elif defined (TO_SQ) && HAVE_SQ == 1 && !defined (FROM_SQ)
#define TO_TYPE 4 /* Fixed-point. */
#define TO_MODE_NAME SQ
#define TO_MODE_NAME_S sq
#define TO_INT_C_TYPE SItype
#define TO_SINT_C_TYPE SItype
#define TO_UINT_C_TYPE USItype
#define TO_MODE_UNSIGNED 0
#define TO_FIXED_SIZE 4 /* in bytes. */
#elif defined (TO_DQ) && HAVE_DQ == 1 && !defined (FROM_DQ)
#define TO_TYPE 4 /* Fixed-point. */
#define TO_MODE_NAME DQ
#define TO_MODE_NAME_S dq
#define TO_INT_C_TYPE DItype
#define TO_SINT_C_TYPE DItype
#define TO_UINT_C_TYPE UDItype
#define TO_MODE_UNSIGNED 0
#define TO_FIXED_SIZE 8 /* in bytes. */
#elif defined (TO_TQ) && HAVE_TQ == 1 && !defined (FROM_TQ)
#define TO_TYPE 4 /* Fixed-point. */
#define TO_MODE_NAME TQ
#define TO_MODE_NAME_S tq
#define TO_INT_C_TYPE TItype
#define TO_SINT_C_TYPE TItype
#define TO_UINT_C_TYPE UTItype
#define TO_MODE_UNSIGNED 0
#define TO_FIXED_SIZE 16 /* in bytes. */
#elif defined (TO_UQQ) && HAVE_UQQ == 1 && !defined (FROM_UQQ)
#define TO_TYPE 4 /* Fixed-point. */
#define TO_MODE_NAME UQQ
#define TO_MODE_NAME_S uqq
#define TO_INT_C_TYPE UQItype
#define TO_SINT_C_TYPE QItype
#define TO_UINT_C_TYPE UQItype
#define TO_MODE_UNSIGNED 1
#define TO_FIXED_SIZE 1 /* in bytes. */
#elif defined (TO_UHQ) && HAVE_UHQ == 1 && !defined (FROM_UHQ)
#define TO_TYPE 4 /* Fixed-point. */
#define TO_MODE_NAME UHQ
#define TO_MODE_NAME_S uhq
#define TO_INT_C_TYPE UHItype
#define TO_SINT_C_TYPE HItype
#define TO_UINT_C_TYPE UHItype
#define TO_MODE_UNSIGNED 1
#define TO_FIXED_SIZE 2 /* in bytes. */
#elif defined (TO_USQ) && HAVE_USQ == 1 && !defined (FROM_USQ)
#define TO_TYPE 4 /* Fixed-point. */
#define TO_MODE_NAME USQ
#define TO_MODE_NAME_S usq
#define TO_INT_C_TYPE USItype
#define TO_SINT_C_TYPE SItype
#define TO_UINT_C_TYPE USItype
#define TO_MODE_UNSIGNED 1
#define TO_FIXED_SIZE 4 /* in bytes. */
#elif defined (TO_UDQ) && HAVE_UDQ == 1 && !defined (FROM_UDQ)
#define TO_TYPE 4 /* Fixed-point. */
#define TO_MODE_NAME UDQ
#define TO_MODE_NAME_S udq
#define TO_INT_C_TYPE UDItype
#define TO_SINT_C_TYPE DItype
#define TO_UINT_C_TYPE UDItype
#define TO_MODE_UNSIGNED 1
#define TO_FIXED_SIZE 8 /* in bytes. */
#elif defined (TO_UTQ) && HAVE_UTQ == 1 && !defined (FROM_UTQ)
#define TO_TYPE 4 /* Fixed-point. */
#define TO_MODE_NAME UTQ
#define TO_MODE_NAME_S utq
#define TO_INT_C_TYPE UTItype
#define TO_SINT_C_TYPE TItype
#define TO_UINT_C_TYPE UTItype
#define TO_MODE_UNSIGNED 1
#define TO_FIXED_SIZE 16 /* in bytes. */
#elif defined (TO_HA) && HAVE_HA == 1 && !defined (FROM_HA)
#define TO_TYPE 4 /* Fixed-point. */
#define TO_MODE_NAME HA
#define TO_MODE_NAME_S ha
#define TO_INT_C_TYPE HItype
#define TO_SINT_C_TYPE HItype
#define TO_UINT_C_TYPE UHItype
#define TO_MODE_UNSIGNED 0
#define TO_FIXED_SIZE 2 /* in bytes. */
#elif defined (TO_SA) && HAVE_SA == 1 && !defined (FROM_SA)
#define TO_TYPE 4 /* Fixed-point. */
#define TO_MODE_NAME SA
#define TO_MODE_NAME_S sa
#define TO_INT_C_TYPE SItype
#define TO_SINT_C_TYPE SItype
#define TO_UINT_C_TYPE USItype
#define TO_MODE_UNSIGNED 0
#define TO_FIXED_SIZE 4 /* in bytes. */
#elif defined (TO_DA) && HAVE_DA == 1 && !defined (FROM_DA)
#define TO_TYPE 4 /* Fixed-point. */
#define TO_MODE_NAME DA
#define TO_MODE_NAME_S da
#define TO_INT_C_TYPE DItype
#define TO_SINT_C_TYPE DItype
#define TO_UINT_C_TYPE UDItype
#define TO_MODE_UNSIGNED 0
#define TO_FIXED_SIZE 8 /* in bytes. */
#elif defined (TO_TA) && HAVE_TA == 1 && !defined (FROM_TA)
#define TO_TYPE 4 /* Fixed-point. */
#define TO_MODE_NAME TA
#define TO_MODE_NAME_S ta
#define TO_INT_C_TYPE TItype
#define TO_SINT_C_TYPE TItype
#define TO_UINT_C_TYPE UTItype
#define TO_MODE_UNSIGNED 0
#define TO_FIXED_SIZE 16 /* in bytes. */
#elif defined (TO_UHA) && HAVE_UHA == 1 && !defined (FROM_UHA)
#define TO_TYPE 4 /* Fixed-point. */
#define TO_MODE_NAME UHA
#define TO_MODE_NAME_S uha
#define TO_INT_C_TYPE UHItype
#define TO_SINT_C_TYPE HItype
#define TO_UINT_C_TYPE UHItype
#define TO_MODE_UNSIGNED 1
#define TO_FIXED_SIZE 2 /* in bytes. */
#elif defined (TO_USA) && HAVE_USA == 1 && !defined (FROM_USA)
#define TO_TYPE 4 /* Fixed-point. */
#define TO_MODE_NAME USA
#define TO_MODE_NAME_S usa
#define TO_INT_C_TYPE USItype
#define TO_SINT_C_TYPE SItype
#define TO_UINT_C_TYPE USItype
#define TO_MODE_UNSIGNED 1
#define TO_FIXED_SIZE 4 /* in bytes. */
#elif defined (TO_UDA) && HAVE_UDA == 1 && !defined (FROM_UDA)
#define TO_TYPE 4 /* Fixed-point. */
#define TO_MODE_NAME UDA
#define TO_MODE_NAME_S uda
#define TO_INT_C_TYPE UDItype
#define TO_SINT_C_TYPE DItype
#define TO_UINT_C_TYPE UDItype
#define TO_MODE_UNSIGNED 1
#define TO_FIXED_SIZE 8 /* in bytes. */
#elif defined (TO_UTA) && HAVE_UTA == 1 && !defined (FROM_UTA)
#define TO_TYPE 4 /* Fixed-point. */
#define TO_MODE_NAME UTA
#define TO_MODE_NAME_S uta
#define TO_INT_C_TYPE UTItype
#define TO_SINT_C_TYPE TItype
#define TO_UINT_C_TYPE UTItype
#define TO_MODE_UNSIGNED 1
#define TO_FIXED_SIZE 16 /* in bytes. */
#endif
#if defined (FROM_MODE_NAME_S) && defined (TO_MODE_NAME_S)
#if FROM_TYPE == 1 /* Signed integer. */
#define FROM_INT_WIDTH (FROM_INT_SIZE * __CHAR_BIT__)
#endif
#if FROM_TYPE == 2 /* Unsigned integer. */
#define FROM_INT_WIDTH (FROM_INT_SIZE * __CHAR_BIT__)
#endif
#if FROM_TYPE == 4 /* Fixed-point. */
#define FROM_FIXED_C_TYPE FIXED_C_TYPE2(FROM_MODE_NAME)
#define FROM_FBITS FBITS2(FROM_MODE_NAME)
#define FROM_FIXED_WIDTH (FROM_FIXED_SIZE * __CHAR_BIT__)
#define FROM_FBITS FBITS2(FROM_MODE_NAME)
#define FROM_IBITS IBITS2(FROM_MODE_NAME)
#define FROM_I_F_BITS (FROM_FBITS + FROM_IBITS)
#if FROM_MODE_UNSIGNED == 0 /* Signed types. */
#define FROM_PADDING_BITS (FROM_FIXED_WIDTH - 1 - FROM_I_F_BITS)
#define FROM_NONPADDING_BITS (1 + FROM_I_F_BITS)
#else /* Unsigned types. */
#define FROM_PADDING_BITS (FROM_FIXED_WIDTH - FROM_I_F_BITS)
#define FROM_NONPADDING_BITS (FROM_I_F_BITS)
#endif
#define FROM_HAVE_PADDING_BITS (FROM_PADDING_BITS > 0)
#endif /* FROM_TYPE == 4 */
#if TO_TYPE == 4 /* Fixed-point. */
#define TO_FIXED_C_TYPE FIXED_C_TYPE2(TO_MODE_NAME)
#define TO_FBITS FBITS2(TO_MODE_NAME)
#define TO_FIXED_WIDTH (TO_FIXED_SIZE * __CHAR_BIT__)
#define TO_FBITS FBITS2(TO_MODE_NAME)
#define TO_IBITS IBITS2(TO_MODE_NAME)
#define TO_I_F_BITS (TO_FBITS + TO_IBITS)
#if TO_MODE_UNSIGNED == 0 /* Signed types. */
#define TO_PADDING_BITS (TO_FIXED_WIDTH - 1 - TO_I_F_BITS)
#define TO_NONPADDING_BITS (1 + TO_I_F_BITS)
#else /* Unsigned types. */
#define TO_PADDING_BITS (TO_FIXED_WIDTH - TO_I_F_BITS)
#define TO_NONPADDING_BITS (TO_I_F_BITS)
#endif
#define TO_HAVE_PADDING_BITS (TO_PADDING_BITS > 0)
#endif /* TO_TYPE == 4 */
#ifdef LIBGCC2_FIXEDBIT_GNU_PREFIX
#define FIXED_CONVERT_OP(OP,FROM,TO) __gnu_ ## OP ## FROM ## TO
#define FIXED_CONVERT_OP2(OP,FROM,TO) __gnu_ ## OP ## FROM ## TO ## 2
#else
#define FIXED_CONVERT_OP(OP,FROM,TO) __ ## OP ## FROM ## TO
#define FIXED_CONVERT_OP2(OP,FROM,TO) __ ## OP ## FROM ## TO ## 2
#endif
#define FRACT_TEMP(N1,N2) FIXED_CONVERT_OP(fract,N1,N2)
#define FRACT2_TEMP(N1,N2) FIXED_CONVERT_OP2(fract,N1,N2)
#define SATFRACT_TEMP(N1,N2) FIXED_CONVERT_OP(satfract,N1,N2)
#define SATFRACT2_TEMP(N1,N2) FIXED_CONVERT_OP2(satfract,N1,N2)
#define FRACTUNS_TEMP(N1,N2) FIXED_CONVERT_OP(fractuns,N1,N2)
#define SATFRACTUNS_TEMP(N1,N2) FIXED_CONVERT_OP(satfractuns,N1,N2)
/* Define conversions from fixed-point to fixed-point. */
#if FROM_TYPE == 4 && TO_TYPE == 4
#if FROM_FIXED_SIZE > TO_FIXED_SIZE
#define BIG_SINT_C_TYPE FROM_SINT_C_TYPE
#define BIG_UINT_C_TYPE FROM_UINT_C_TYPE
#define BIG_WIDTH FROM_FIXED_WIDTH
#else
#define BIG_SINT_C_TYPE TO_SINT_C_TYPE
#define BIG_UINT_C_TYPE TO_UINT_C_TYPE
#define BIG_WIDTH TO_FIXED_WIDTH
#endif
/* Check if FROM* and TO* are in the same machine class. */
#if ((FROM_MODE_UNSIGNED == TO_MODE_UNSIGNED) \
&& ((FROM_IBITS == 0) == (TO_IBITS == 0)))
/* Same modes: append '2' to conversion function names */
#define FRACT FRACT2_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
#define SATFRACT SATFRACT2_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
#else
/* Different modes: don't append '2' to conversion function names */
#define FRACT FRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
#define SATFRACT SATFRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
#endif
extern TO_FIXED_C_TYPE FRACT (FROM_FIXED_C_TYPE);
extern TO_FIXED_C_TYPE SATFRACT (FROM_FIXED_C_TYPE);
#endif /* FROM_TYPE == 4 && TO_TYPE == 4 */
/* Define conversions from fixed-point to signed integer. */
#if FROM_TYPE == 4 && TO_TYPE == 1
#define FRACT FRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
extern TO_INT_C_TYPE FRACT (FROM_FIXED_C_TYPE);
#endif /* FROM_TYPE == 4 && TO_TYPE == 1 */
/* Define conversions from fixed-point to unsigned integer. */
#if FROM_TYPE == 4 && TO_TYPE == 2
#define FRACTUNS FRACTUNS_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
extern TO_INT_C_TYPE FRACTUNS (FROM_FIXED_C_TYPE);
#endif /* FROM_TYPE == 4 && TO_TYPE == 2 */
/* Define conversions from fixed-point to floating-point. */
#if FROM_TYPE == 4 && TO_TYPE == 3
#define BASE1(NUM) 0x1.0p ## NUM
#define BASE2(NUM) BASE1(NUM)
#define BASE BASE2(FROM_FBITS)
#define FRACT FRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
extern TO_FLOAT_C_TYPE FRACT (FROM_FIXED_C_TYPE);
#endif /* FROM_TYPE == 4 && TO_TYPE == 3 */
/* Define conversions from signed integer to fixed-point. */
#if FROM_TYPE == 1 && TO_TYPE == 4
#if FROM_INT_SIZE > TO_FIXED_SIZE
#define BIG_SINT_C_TYPE FROM_SINT_C_TYPE
#define BIG_UINT_C_TYPE FROM_UINT_C_TYPE
#define BIG_WIDTH FROM_INT_WIDTH
#else
#define BIG_SINT_C_TYPE TO_SINT_C_TYPE
#define BIG_UINT_C_TYPE TO_UINT_C_TYPE
#define BIG_WIDTH TO_FIXED_WIDTH
#endif
#define FRACT FRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
#define SATFRACT SATFRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
extern TO_FIXED_C_TYPE FRACT (FROM_INT_C_TYPE);
extern TO_FIXED_C_TYPE SATFRACT (FROM_INT_C_TYPE);
#endif /* FROM_TYPE == 1 && TO_TYPE == 4 */
/* Define conversions from unsigned integer to fixed-point. */
#if FROM_TYPE == 2 && TO_TYPE == 4
#if FROM_INT_SIZE > TO_FIXED_SIZE
#define BIG_SINT_C_TYPE FROM_SINT_C_TYPE
#define BIG_UINT_C_TYPE FROM_UINT_C_TYPE
#define BIG_WIDTH FROM_INT_WIDTH
#else
#define BIG_SINT_C_TYPE TO_SINT_C_TYPE
#define BIG_UINT_C_TYPE TO_UINT_C_TYPE
#define BIG_WIDTH TO_FIXED_WIDTH
#endif
#define FRACTUNS FRACTUNS_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
#define SATFRACTUNS SATFRACTUNS_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
extern TO_FIXED_C_TYPE FRACTUNS (FROM_INT_C_TYPE);
extern TO_FIXED_C_TYPE SATFRACTUNS (FROM_INT_C_TYPE);
#endif /* FROM_TYPE == 2 && TO_TYPE == 4 */
/* Define conversions from floating-point to fixed-point. */
#if FROM_TYPE == 3 && TO_TYPE == 4
#define BASE1(NUM) (0x1.0p ## NUM)
#define BASE2(NUM) BASE1(NUM)
#define BASE BASE2(TO_FBITS)
#define FIXED_MAX1(NUM1,NUM2) (0x1.0p ## NUM1 - 0x1.0p- ## NUM2)
#define FIXED_MAX2(NUM1,NUM2) FIXED_MAX1(NUM1,NUM2)
#define FIXED_MAX FIXED_MAX2(TO_IBITS,TO_FBITS)
#define FIXED_MIN1(NUM) (-0x1.0p ## NUM)
#define FIXED_MIN2(NUM) FIXED_MIN1(NUM)
#if TO_MODE_UNSIGNED == 0
#define FIXED_MIN FIXED_MIN2(TO_IBITS)
#else
#define FIXED_MIN 0.0
#endif
#define FRACT FRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
#define SATFRACT SATFRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
extern TO_FIXED_C_TYPE FRACT (FROM_FLOAT_C_TYPE);
extern TO_FIXED_C_TYPE SATFRACT (FROM_FLOAT_C_TYPE);
#endif /* FROM_TYPE == 3 && TO_TYPE == 4 */
#endif /* defined (FROM_MODE_NAME_S) && defined (TO_MODE_NAME_S) */
#endif /* _FIXED_BIT_H */
|