forked from espressif/arduino-esp32
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathc6x-compat.h
executable file
·1758 lines (1336 loc) · 41.1 KB
/
c6x-compat.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
/*
* Copyright (c) 2006-2010 Tensilica Inc. ALL RIGHTS RESERVED.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef __C6X_COMPAT__H
#define __C6X_COMPAT__H
/* Unimplemented functions _gmpy, _gmpy4, _xormpy, _lssub, _cmpy, _cmpyr,
_cmpyr1, _ddotpl2r, _ddotph2r */
typedef long long C6X_COMPAT_LONG40;
#define _memd8(a) (*((double*)(a)))
#define _memd8_const(a) (*((const double*)(a)))
#define _amemd8(a) (*((double*)(a)))
#define _amemd8_const(a) (*((const double*)(a)))
#define _mem8(a) (*((unsigned long long*)(a)))
#define _mem8_const(a) (*((const unsigned long long*)(a)))
#define _mem4(a) (*((unsigned*)(a)))
#define _mem4_const(a) (*((const unsigned*)(a)))
#define _amem4_const(a) (*((const unsigned*)(a)))
/* NOTE: To emulate a C6X properly you should define global variables
for your Xtensa with these names. Some of the emulation routines
will set these values. */
extern int _carry;
extern int _overflow;
// Utility routines
#define TESTBIT(x,n) (((x) >> (n)) & 1)
#define NSA_BITS 32
static inline unsigned int norm_shift_amt_U_and_non_U(int is_signed, int inp) {
int j=0, k=0;
int x=inp;
if (is_signed) {
/* Invert signed val if negative */
x= TESTBIT(x,(NSA_BITS-1))? ~x: x;
x= (x&1)|(x<<1); /* Shift up to return count-1 */
if (x ==0)
return NSA_BITS-1;
}
if (x ==0)
return NSA_BITS;
/* Now count leading zeros */
for (j=0, k=NSA_BITS-1; k>=0; j++, k--) {
if (TESTBIT(x,k))
return j;
}
return NSA_BITS;
}
static inline long long
orig_L40_set( long long L40_var1) {
long long L40_var_out;
L40_var_out = L40_var1 & 0x000000ffffffffffLL;
if( L40_var1 & 0x8000000000LL)
L40_var_out = L40_var_out | 0xffffff0000000000LL;
return( L40_var_out);
}
static inline signed long long
util_saturate_n_no_state(signed long long t, int n)
{
signed long long maxv, minv;
maxv = (1LL << (n-1)) - 1;
minv = (-1LL << (n-1));
if (t > maxv) {
t = maxv;
} else if (t < minv) {
t = minv;
}
return t;
}
static inline signed long long
util_saturate_n_sgn(signed long long t, int n)
{
signed long long result;
signed long long maxv, minv;
maxv = (1LL << (n-1)) - 1;
minv = (-1LL << (n-1));
if (t > 0) {
result = maxv;
_overflow = 1;
} else if (t < 0) {
result = minv;
_overflow = 1;
} else {
result = 0;
}
return result;
}
/* well-behaved signed shift right (left on negative) with
saturation */
static inline signed long long
util_shift_right_saturate_n(signed long long t, int shval, int n)
{
/* n should be <= 62 */
long long result;
signed long long mask;
int actual_shift = shval;
long long shft = actual_shift > 0 ? actual_shift : -actual_shift;
if (t == 0 || actual_shift == 0)
return t;
if (actual_shift >= n) {
return (t < 0) ? -1 : 0;
}
if (actual_shift <= -n) {
return util_saturate_n_sgn(t, n);
}
if (actual_shift > 0) {
return t >> actual_shift;
}
/* actual_shift < 0. Check for saturation after shift. */
mask = (-1LL << (n-shft-1));
if (t > 0 && ((mask & t) != 0)) {
return util_saturate_n_sgn(t, n);
}
if (t < 0 && ((mask & t) != mask)) {
return util_saturate_n_sgn(t, n);
}
result = t << shft;
return result;
}
/* Implemented c6x standard C compatibility functions (alphabetical
order) */
static inline int _abs(int src1) {
if ((unsigned) src1 == (unsigned) 0x80000000) {
return 0x7fffffff;
}
return abs(src1);
}
static inline int _abs2(int src1) {
short s1[2],r[2];
int result;
*((int*)s1) = src1;
if ((unsigned short) s1[1] == (unsigned short) 0x8000) r[1] = 0x7fff;
else r[1] = abs(s1[1]);
if ((unsigned short) s1[0] == (unsigned short) 0x8000) r[0] = 0x7fff;
else r[0] = abs(s1[0]);
result = *(int*)r;
return result;
}
static inline int _add2(int src1, int src2) {
short s1[2], s2[2], r[2];
int result;
*((int*)s1) = src1;
*((int*)s2) = src2;
r[0] = s1[0] + s2[0];
r[1] = s1[1] + s2[1];
result = *(int*)r;
return result;
}
static inline int _add4(int src1, int src2) {
char c1[4], c2[4], r[4];
int result;
*((int*)c1) = src1;
*((int*)c2) = src2;
r[0] = c1[0] + c2[0];
r[1] = c1[1] + c2[1];
r[2] = c1[2] + c2[2];
r[3] = c1[3] + c2[3];
result = *(int*)r;
return result;
}
static inline long long _addsub(unsigned int src1, unsigned int src2)
{
int res_lo;
int res_hi;
res_hi = src1+src2;
res_lo = src1-src2;
return (((unsigned long long) res_hi) << 32) | ((unsigned int) res_lo) ;
}
static inline long long _addsub2(unsigned int src1, unsigned int src2)
{
short s1[2], s2[2], ra[2], rs[2];
int res_lo;
int res_hi;
*((int*)s1) = src1;
*((int*)s2) = src2;
ra[0] = s1[0] + s2[0];
ra[1] = s1[1] + s2[1];
rs[0] = s1[0] - s2[0];
rs[1] = s1[1] - s2[1];
res_hi = *(int*)ra;
res_lo = *(int*)rs;
return (((unsigned long long) res_hi) << 32) | ((unsigned int) res_lo) ;
}
static inline int _avg2(int src1, int src2) {
int low = (((int)1 + (short) src1 + (short) src2) >> 1) & 0XFFFF;
int high1 = src1 >> 16;
int high2 = src2 >> 16;
int high = ((high1 + high2 + 1) >> 1)<< 16;
return high | low;
}
static inline unsigned int _avgu4(unsigned int src1, unsigned int src2) {
unsigned int res0 = ((src1 & 0xFF) + (src2 & 0xFF) + 1) >> 1;
unsigned int res1 = (((src1 & 0xFF00) >> 8) + ((src2 & 0xFF00) >> 8) + 1) >> 1;
unsigned int res2 = (((src1 & 0xFF0000) >> 16) + ((src2 & 0xFF0000) >> 16) + 1) >> 1;
unsigned int res3 = (((src1 & 0xFF000000) >> 24) + ((src2 & 0xFF000000) >> 24) + 1) >> 1;
return (res3 << 24) | (res2 << 16) | (res1 << 8) | res0;
}
static inline int TEN_popc (unsigned char b)
{
int i, result = 0;
for (i = 0; i < 8; i++){
if (b & 0x1)
result++;
b >>= 1;
}
return result;
}
static inline unsigned int _bitc4(unsigned int src1)
{
unsigned int res0 = TEN_popc(src1 & 0xFF);
unsigned int res1 = TEN_popc((src1 & 0xFF00) >> 8);
unsigned int res2 = TEN_popc((src1 & 0xFF0000) >> 16);
unsigned int res3 = TEN_popc((src1 & 0xFF000000) >> 24);
return (res3 << 24) | (res2 << 16) | (res1 << 8) | res0;
}
static inline unsigned int _bitr(unsigned int src) {
int i;
unsigned r = 0;
for (i = 0; i< 32; ++i) {
r = r | (((src >> i) & 1)<<(31-i));
}
return r;
}
static inline unsigned int _clr(unsigned int src2, int csta, int cstb)
{
csta &= 0x1f;
cstb &= 0x1f;
if (csta > cstb)
return src2;
else {
unsigned int mask = (((1 << (cstb - csta)) << 1) - 1) << csta;
return src2 & (~mask);
}
}
static inline unsigned int _clrr(unsigned int src2, int src1)
{
unsigned int csta = (src1 >> 5) & 0x1f;
unsigned int cstb = src1 & 0x1f;
if (csta > cstb)
return src2;
else {
unsigned int mask = (((1 << (cstb - csta)) << 1) - 1) << csta;
return src2 & (~mask);
}
}
static inline int _cmpeq2(int src1, int src2) {
short s1[2], s2[2];
int r0, r1;
int result;
*((int*)s1) = src1;
*((int*)s2) = src2;
r0 = s1[0] == s2[0] ? 1 : 0;
r1 = s1[1] == s2[1] ? 1 : 0;
result = (r1 << 1) | r0;
return result;
}
static inline int _cmpeq4(int src1, int src2) {
char s1[4], s2[4];
int r0, r1, r2, r3;
int result;
*((int*)s1) = src1;
*((int*)s2) = src2;
r0 = s1[0] == s2[0] ? 1 : 0;
r1 = s1[1] == s2[1] ? 1 : 0;
r2 = s1[2] == s2[2] ? 1 : 0;
r3 = s1[3] == s2[3] ? 1 : 0;
result = (r3 << 3) | (r2 << 2) | (r1 << 1) | r0;
return result;
}
static inline int _cmpgt2(int src1, int src2) {
short s1[2], s2[2];
int r1, r0;
int result;
*((int*)s1) = src1;
*((int*)s2) = src2;
r0 = s1[0] > s2[0] ? 1 : 0;
r1 = s1[1] > s2[1] ? 1 : 0;
result = (r1<<1) | r0;
return result;
}
static inline unsigned int _cmpgtu4(unsigned int src1, unsigned int src2) {
unsigned int s1_0 = (src1 & 0xFF);
unsigned int s1_1 = (src1 & 0xFF00) >> 8;
unsigned int s1_2 = (src1 & 0xFF0000) >> 16;
unsigned int s1_3 = (src1 & 0xFF000000) >> 24;
unsigned int s2_0 = (src2 & 0xFF);
unsigned int s2_1 = (src2 & 0xFF00) >> 8;
unsigned int s2_2 = (src2 & 0xFF0000) >> 16;
unsigned int s2_3 = (src2 & 0xFF000000) >> 24;
unsigned int result = 0;
if (s1_0 > s2_0)
result |= 0x1;
if (s1_1 > s2_1)
result |= 0x2;
if (s1_2 > s2_2)
result |= 0x4;
if (s1_3 > s2_3)
result |= 0x8;
return result;
}
static inline long long _ddotp4(unsigned int src1, unsigned int src2) {
unsigned int res0, res1;
short s1_0 = (src1 & 0xffff);
short s1_1 = (src1 & 0xfff0000) >> 16;
unsigned short s2_0 = (src2 & 0xff);
unsigned short s2_1 = (src2 & 0xff00) >> 8;
unsigned short s2_2 = (src2 & 0xff0000) >> 16;
unsigned short s2_3 = (src2 & 0xff000000) >> 24;
res0 = ((int)s1_0) * s2_0 + ((int)s1_1) * s2_1;
res1 = ((int)s1_0) * s2_2 + ((int)s1_1) * s2_3;
return (res1 << 16) | res0;
}
static inline long long _ddotph2(long long src1_o_src1_e, unsigned int src2)
{
unsigned int src1_o = src1_o_src1_e >> 32;
unsigned int src1_e = src1_o_src1_e & 0xFFFFFFFF;
short ls1_o = src1_o & 0XFFFF;
short hs1_o = src1_o >> 16;
// short ls1_e = src1_e & 0XFFFF;
short hs1_e = src1_e >> 16;
short ls2 = src2 & 0XFFFF;
short hs2 = src2 >> 16;
unsigned long long res_hi = ls2 * ls1_o + hs2 * hs1_o;
unsigned int res_lo = ls1_o * hs2 + hs1_e * ls2;
return (res_hi << 32) | res_lo;
}
static inline long long _ddotpl2(long long src1_o_src1_e, unsigned int src2)
{
unsigned int src1_o = src1_o_src1_e >> 32;
unsigned int src1_e = src1_o_src1_e & 0xFFFFFFFF;
short ls1_o = src1_o & 0XFFFF;
// short hs1_o = src1_o >> 16;
short ls1_e = src1_e & 0XFFFF;
short hs1_e = src1_e >> 16;
short ls2 = src2 & 0XFFFF;
short hs2 = src2 >> 16;
unsigned long long res_hi = ls2 * hs1_e + hs2 * ls1_o;
unsigned res_lo = hs1_e * hs2 + ls1_e * ls2;
return (res_hi << 32) | res_lo;
}
static inline unsigned int _deal(unsigned int src)
{
int i;
unsigned short lo = 0, hi = 0;
for (i = 0; i < 32; i+= 2) {
lo >>= 1;
lo |= (src & 0x1) << 15;
src >>= 1;
hi >>= 1;
hi |= (src & 0x1) << 15;
src >>= 1;
}
return (hi << 16) | lo;
}
static inline long long _dmv(unsigned int src1, unsigned int src2)
{
return (((long long) src1) << 32) | src2;
}
static inline int _dotpn2(int src1, int src2) {
short int s1_h = src1>>16;
short int s1_l = src1;
short int s2_h = src2>>16;
short int s2_l = src2;
return s1_h * s2_h - s1_l * s2_l;
}
static inline int _dotp2(int src1, int src2) {
short int s1_h = src1>>16;
short int s1_l = src1;
short int s2_h = src2>>16;
short int s2_l = src2;
return s1_h * s2_h + s1_l * s2_l;
}
static inline int _dotpnrsu2(int src1, unsigned int src2)
{
short ls1 = src1 & 0XFFFF;
unsigned short ls2 = src2 & 0XFFFF;
short hs1 = src1 >> 16;
unsigned short hs2 = src2 >> 16;
int result = (((long long) (int)(hs1 * hs2)) - ((long long) (int)(ls1 * ls2)) + (1 << 15)) >> 16;
return result;
}
static inline int _dotprsu2(int src1, unsigned int src2) {
short ls1 = src1 & 0XFFFF;
unsigned short ls2 = (src2 & 0XFFFF);
short hs1 = src1 >> 16;
unsigned short hs2 = (src2 >> 16);
int result = (((long long) (int) (ls1 * ls2)) + ((long long) (int) (hs1 * hs2)) + (1LL << 15)) >> 16;
return result;
}
static inline int _dotpsu4(int src1, unsigned int src2) {
int result;
signed char s1_0 = (src1 & 0xff);
signed char s1_1 = (src1 & 0xff00) >> 8;
signed char s1_2 = (src1 & 0xff0000) >> 16;
signed char s1_3 = (src1 & 0xff000000) >> 24;
unsigned int s2_0 = (src2 & 0xff);
unsigned int s2_1 = (src2 & 0xff00) >> 8;
unsigned int s2_2 = (src2 & 0xff0000) >> 16;
unsigned int s2_3 = (src2 & 0xff000000) >> 24;
result = s1_0 * s2_0 + s1_1 * s2_1 + s1_2 * s2_2 + s1_3 * s2_3;
return result;
}
static inline unsigned int _dotpu4(unsigned int src1, unsigned int src2) {
unsigned char v1_0 = src1 & 0xff;
unsigned char v1_1 = (src1>>8) & 0xff;
unsigned char v1_2 = (src1>>16) & 0xff;
unsigned char v1_3 = (src1>>24) & 0xff;
unsigned char v2_0 = src2 & 0xff;
unsigned char v2_1 = (src2>>8) & 0xff;
unsigned char v2_2 = (src2>>16) & 0xff;
unsigned char v2_3 = (src2>>24) & 0xff;
unsigned v = v1_0 * v2_0 + v1_1 * v2_1 + v1_2 * v2_2 + v1_3 * v2_3;
return v;
}
static inline long long _dpack2(unsigned int src1, unsigned int src2){
unsigned short s1[2], s2[2];
*((int*)s1) = src1;
*((int*)s2) = src2;
return ((unsigned long long) s1[1] << 48) | ((unsigned long long) s2[1] << 32) | ((unsigned long long) s1[0] << 16) | ((unsigned long long) s2[0]);
}
static inline long long _dpackx2(unsigned int src1, unsigned int src2){
unsigned short s1[2], s2[2];
*((int*)s1) = src1;
*((int*)s2) = src2;
return ((unsigned long long) s2[0] << 48) | ((unsigned long long) s1[1] << 32) | ((unsigned long long) s1[0] << 16) | ((unsigned long long) s2[1]);
}
static inline int _ext(int src2, unsigned int csta, unsigned int cstb)
{
return (src2 << csta) >> cstb;
}
static inline int _extr(int src2, int src1)
{
unsigned int csta = (src1 >> 5) & 0x1f;
unsigned int cstb = src1 & 0x1f;
return (src2 << csta) >> cstb;
}
static inline unsigned int _extu(unsigned int src2, unsigned int csta, unsigned int cstb)
{
return (src2 << csta) >> cstb;
}
static inline unsigned int _extur(unsigned int src2, int src1)
{
unsigned int csta = (src1 >> 5) & 0x1f;
unsigned int cstb = src1 & 0x1f;
return (src2 << csta) >> cstb;
}
static inline unsigned long long _hi(double src) {
unsigned long long v;
*(double*)&v = src;
return v>>32;
}
static inline unsigned int _hill (long long src)
{
return (unsigned int) (src >> 32);
}
static inline double _itod(unsigned hi, unsigned lo) {
double v;
unsigned long long ll = ((((unsigned long long)(hi))<<32) | (unsigned long long)((unsigned)lo));
*((unsigned long long *)&v) = ll;
return v;
}
static inline long long _itoll(unsigned int src2, unsigned int src1)
{
return (((long long) src2) << 32) | src1;
}
static inline C6X_COMPAT_LONG40 _labs(C6X_COMPAT_LONG40 src2)
{
long long maxv = (1LL << (40 -1)) - 1;
long long minv = (-1LL << (40 - 1));
C6X_COMPAT_LONG40 lres = orig_L40_set(src2);
lres = lres < 0 ? -lres : lres;
if (lres > maxv) lres = maxv;
else if (lres < minv) lres = minv;
return lres;
}
static inline C6X_COMPAT_LONG40 _ldotp2(int src1, int src2) {
return (C6X_COMPAT_LONG40) _dotp2(src1, src2);
}
static inline unsigned int _lmbd(unsigned int src1, unsigned int src2)
{
return norm_shift_amt_U_and_non_U(0,(((int) (src1 << 31)) >> 31) ^ (~src2));
}
static inline unsigned int _lnorm(C6X_COMPAT_LONG40 src2) {
if (src2 == 0)
return 39;
else {
int hi = (int)(src2 >> 32);
int lo = (int)src2;
long long temp = (unsigned long long)(unsigned)lo | (unsigned long long)hi << 32;
temp = orig_L40_set(temp);
if (temp == 0) return 0;
int cnt = 0;
while (((temp >> 39) & 1) == ((temp >> 38) & 1)) {
temp <<= 1;
cnt++;
}
return cnt;
}
}
static inline unsigned long long _lo(double src) {
unsigned long long v;
*(double*)&v = src;
return v;
}
static inline unsigned int _loll (long long src)
{
return (unsigned int) src;
}
static inline C6X_COMPAT_LONG40 _lsadd(int src1, C6X_COMPAT_LONG40 src2)
{
long long maxv = (1LL << (40 -1)) - 1;
long long minv = (-1LL << (40 - 1));
int hi = (int)(src2 >> 32);
int lo = (int)src2;
long long src2_int = (unsigned long long)(unsigned)lo | (unsigned long long)hi << 32;
long long src2_int2 = orig_L40_set(src2_int);
long long res = src1 + src2_int2;
if (res > maxv) {
res = maxv;
_overflow = 1;
}
else if (res < minv) {
res = minv;
_overflow = 1;
}
long long res2 = orig_L40_set(res);
res2 = (signed char)(res2 >> 32);
C6X_COMPAT_LONG40 lres = (((C6X_COMPAT_LONG40) res2) << 32) | ((unsigned int)res);
return lres;
}
static inline int _max2 (int src1, int src2) {
short s1[2], s2[2], r[2];
int result;
*((int*)s1) = src1;
*((int*)s2) = src2;
r[0] = s1[0] > s2[0] ? s1[0] : s2[0];
r[1] = s1[1] > s2[1] ? s1[1] : s2[1];
result = *(int*)r;
return result;
}
static inline unsigned int _maxu4(unsigned int src1, unsigned int src2) {
unsigned int res0, res1, res2, res3;
unsigned int s1_0 = res0 = (src1 & 0xFF);
unsigned int s1_1 = res1 = (src1 & 0xFF00) >> 8;
unsigned int s1_2 = res2 = (src1 & 0xFF0000) >> 16;
unsigned int s1_3 = res3 = (src1 & 0xFF000000) >> 24;
unsigned int s2_0 = (src2 & 0xFF);
unsigned int s2_1 = (src2 & 0xFF00) >> 8;
unsigned int s2_2 = (src2 & 0xFF0000) >> 16;
unsigned int s2_3 = (src2 & 0xFF000000) >> 24;
// unsigned int res = 0;
if (s1_0 < s2_0)
res0 = s2_0;
if (s1_1 < s2_1)
res1 = s2_1;
if (s1_2 < s2_2)
res2 = s2_2;
if (s1_3 < s2_3)
res3 = s2_3;
return (res3 << 24) | (res2 << 16) | (res1 << 8) | res0;
}
static inline int _min2(int src1, int src2) {
short s1[2], s2[2], r[2];
int result;
*((int*)s1) = src1;
*((int*)s2) = src2;
r[0] = s1[0] < s2[0] ? s1[0] : s2[0];
r[1] = s1[1] < s2[1] ? s1[1] : s2[1];
result = *(int*)r;
return result;
}
static inline unsigned int _minu4(unsigned int src1, unsigned int src2) {
unsigned int res0, res1, res2, res3;
unsigned int s1_0 = res0 = (src1 & 0xFF);
unsigned int s1_1 = res1 = (src1 & 0xFF00) >> 8;
unsigned int s1_2 = res2 = (src1 & 0xFF0000) >> 16;
unsigned int s1_3 = res3 = (src1 & 0xFF000000) >> 24;
unsigned int s2_0 = (src2 & 0xFF);
unsigned int s2_1 = (src2 & 0xFF00) >> 8;
unsigned int s2_2 = (src2 & 0xFF0000) >> 16;
unsigned int s2_3 = (src2 & 0xFF000000) >> 24;
// unsigned int res = 0;
if (s1_0 > s2_0)
res0 = s2_0;
if (s1_1 > s2_1)
res1 = s2_1;
if (s1_2 > s2_2)
res2 = s2_2;
if (s1_3 > s2_3)
res3 = s2_3;
return (res3 << 24) | (res2 << 16) | (res1 << 8) | res0;
}
static inline int _mpy(int src1, int src2) {
return (short) src1 * (short) src2;
}
static inline int _mpyh(int src1, int src2) {
return (short) (src1 >> 16) * (short) (src2 >> 16);
}
static inline long long _mpyhill (int src1, int src2)
{
short s1 = src1 >> 16;
return ((long long) src2) * s1;
}
static inline int _mpyhir(int src1, int src2)
{
short s1 = src1 >> 16;
long long result = ((long long) src2) * s1 + (1 << 14);
result >>= 15;
return result;
}
static inline int _mpyhl(int src1, int src2) {
return (short) (src1 >> 16) * (short) (src2);
}
static inline unsigned int _mpyhlu(unsigned int src1, unsigned int src2) {
return (unsigned short) (src1 >> 16) * (unsigned short) (src2);
}
static inline int _mpyhslu(int src1, unsigned int src2) {
return (short) (src1 >> 16) * (unsigned short) src2;
}
static inline int _mpyhsu(int src1, unsigned int src2) {
return (short) (src1 >>16) * (unsigned short) (src2 >>16);
}
static inline unsigned int _mpyhu(unsigned int src1, unsigned int src2) {
return (unsigned short) (src1 >>16) * (unsigned short) (src2 >> 16);
}
static inline int _mpyhuls(unsigned int src1, int src2) {
return (unsigned short) (src1 >>16) * (signed short) (src2);
}
static inline int _mpyhus(unsigned int src1, int src2) {
return (unsigned short) (src1 >> 16) * (short) (src2 >>16);
}
static inline long long _mpyidll (int src1, int src2)
{
return (long long) src1 * src2;
}
static inline int _mpylh(int src1, int src2) {
return (signed short) (src1 & 0xffff) * (signed short) (src2 >> 16);
}
static inline unsigned int _mpylhu(unsigned int src1, unsigned int src2) {
return (unsigned short) src1 * (unsigned short) (src2 >> 16);
}
static inline long long _mpylill (int src1, int src2)
{
return ((long long) src2) * ((short)src1);
}
static inline int _mpylir(int src1, int src2)
{
short s1 = src1;
long long result = ((long long) src2) * s1 + (1 << 14);
result >>= 15;
return result;
}
static inline int _mpylshu(int src1, unsigned int src2) {
return (short) src1 * (unsigned short) (src2 >> 16);
}
static inline int _mpyluhs(unsigned int src1, int src2) {
return (unsigned short) src1 * (short) (src2 >> 16);
}
static inline int _mpysu(int src1, unsigned int src2) {
return (short) src1 * (unsigned short) src2;
}
static inline long long _mpysu4ll (int src1, unsigned int src2) {
unsigned short res0, res1, res2, res3;
signed char s1_0 = (src1 & 0xff);
signed char s1_1 = (src1 & 0xff00) >> 8;
signed char s1_2 = (src1 & 0xff0000) >> 16;
signed char s1_3 = (src1 & 0xff000000) >> 24;
unsigned short s2_0 = (src2 & 0xff);
unsigned short s2_1 = (src2 & 0xff00) >> 8;
unsigned short s2_2 = (src2 & 0xff0000) >> 16;
unsigned short s2_3 = (src2 & 0xff000000) >> 24;
res0 = s1_0 * s2_0;
res1 = s1_1 * s2_1;
res2 = s1_2 * s2_2;
res3 = s1_3 * s2_3;
return (((unsigned long long) res3) << 48)
| (((unsigned long long) res2) << 32)
| (((unsigned long long) res1) << 16)
| res0;
}
static inline unsigned int _mpyu(unsigned int src1, unsigned int src2) {
unsigned v = (unsigned short)src1 * (unsigned short)src2;
return v;
}
static inline int _mpyus(unsigned int src1, int src2) {
return (unsigned short) src1 * (short) src2;
}
static inline long long _mpyu4ll (unsigned int src1, unsigned int src2) {
unsigned short res0, res1, res2, res3;
unsigned char s1_0 = (src1 & 0xff);
unsigned char s1_1 = (src1 & 0xff00) >> 8;
unsigned char s1_2 = (src1 & 0xff0000) >> 16;
unsigned char s1_3 = (src1 & 0xff000000) >> 24;
unsigned short s2_0 = (src2 & 0xff);
unsigned short s2_1 = (src2 & 0xff00) >> 8;
unsigned short s2_2 = (src2 & 0xff0000) >> 16;
unsigned short s2_3 = (src2 & 0xff000000) >> 24;
res0 = s1_0 * s2_0;
res1 = s1_1 * s2_1;
res2 = s1_2 * s2_2;
res3 = s1_3 * s2_3;
return (((unsigned long long) res3) << 48)
| (((unsigned long long) res2) << 32)
| (((unsigned long long) res1) << 16)
| res0;
}
static inline long long _mpy2ir(unsigned int src1, unsigned int src2)
{
if ((src1 == 0x8000) && (src2 == 0x80000000)) {
_overflow = 1;
return 0;
}
else {
short ls1 = src1 & 0xffff;
short hs1 = src1 >> 16;
unsigned long long hi = (((long long) hs1) * (int) src2 + (1 << 14)) >> 15;
unsigned long long lo = ((((long long) ls1) * (int) src2 + (1 << 14)) >> 15) & 0xFFFFFFFF;
return (hi << 32) | lo;
}
}
static inline long long _mpy2ll (int src1, int src2) {
short ls1 = src1 & 0xffff;
short hs1 = src1 >> 16;
short ls2 = src2 & 0xffff;
short hs2 = src2 >> 16;
unsigned long long hi = hs1 * hs2;
unsigned long long lo = (ls1 * ls2) & 0xFFFFFFFF;
return (hi << 32) | lo;
}
static inline int _mpy32(int src1, int src2)
{
return src1 * src2;