/
pf_items.c
2809 lines (2290 loc) · 69.8 KB
/
pf_items.c
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) 2001-2012, Parrot Foundation.
=head1 NAME
src/packfile/pf_items.c - Fetch/store packfile data
=head1 DESCRIPTION
Low level packfile functions to fetch and store Parrot data, i.e.
C<INTVAL>, C<FLOATVAL>, C<STRING> ...
C<< PF_fetch_<item>() >> functions retrieve the datatype item from the
opcode stream and convert byteordering or binary format on the fly,
depending on the packfile header.
C<< PF_store_<item>() >> functions write the datatype item to the stream
as is. These functions don't check the available size.
C<< PF_size_<item>() >> functions return the store size of item in
C<opcode_t> units.
C<BE> and C<be> are short for "Big-endian", while C<LE> and C<le> are short
for "little endian".
=head2 Functions
=over 4
=cut
*/
#include "parrot/parrot.h"
#include "parrot/bswap.h"
#include "pf_items.str"
/* HEADERIZER HFILE: include/parrot/packfile.h */
/* HEADERIZER BEGIN: static */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
static void cvt_num10_num16(
ARGOUT(unsigned char *dest),
ARGIN(const unsigned char *src),
ARGIN(const PackFile_Header *header))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(*dest);
static void cvt_num10_num16ppc(
ARGOUT(unsigned char *dest),
ARGIN(const unsigned char *src),
ARGIN(const PackFile_Header *header))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(*dest);
static void cvt_num10_num4(
ARGOUT(unsigned char *dest),
ARGIN(const unsigned char *src),
ARGIN(const PackFile_Header *header))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(*dest);
static void cvt_num10_num8(
ARGOUT(unsigned char *dest),
ARGIN(const unsigned char *src),
ARGIN(const PackFile_Header *header))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(*dest);
static void cvt_num16_num10(
ARGOUT(unsigned char *dest),
ARGIN(const unsigned char *src),
ARGIN(const PackFile_Header *header))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(*dest);
static void cvt_num16_num16ppc(
ARGOUT(unsigned char *dest),
ARGIN(const unsigned char *src),
ARGIN(const PackFile_Header *header))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(*dest);
static void cvt_num16_num4(
ARGOUT(unsigned char *dest),
ARGIN(const unsigned char *src),
ARGIN(const PackFile_Header *header))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(*dest);
static void cvt_num16_num8(
ARGOUT(unsigned char *dest),
ARGIN(const unsigned char *src),
ARGIN(const PackFile_Header *header))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(*dest);
static void cvt_num16ppc_num10(
ARGOUT(unsigned char *dest),
ARGIN(const unsigned char *src),
ARGIN(const PackFile_Header *header))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(*dest);
static void cvt_num16ppc_num16(
ARGOUT(unsigned char *dest),
ARGIN(const unsigned char *src),
ARGIN(const PackFile_Header *header))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(*dest);
static void cvt_num16ppc_num4(
ARGOUT(unsigned char *dest),
ARGIN(const unsigned char *src),
ARGIN(const PackFile_Header *header))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(*dest);
static void cvt_num16ppc_num8(
ARGOUT(unsigned char *dest),
ARGIN(const unsigned char *src),
ARGIN(const PackFile_Header *header))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(*dest);
static void cvt_num4_num10(
ARGOUT(unsigned char *dest),
ARGIN(const unsigned char *src),
ARGIN(const PackFile_Header *header))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(*dest);
static void cvt_num4_num16(
ARGOUT(unsigned char *dest),
ARGIN(const unsigned char *src),
ARGIN(const PackFile_Header *header))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(*dest);
static void cvt_num4_num16ppc(
ARGOUT(unsigned char *dest),
ARGIN(const unsigned char *src),
ARGIN(const PackFile_Header *header))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(*dest);
static void cvt_num4_num8(
ARGOUT(unsigned char *dest),
ARGIN(const unsigned char *src),
ARGIN(const PackFile_Header *header))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(*dest);
static void cvt_num8_num10(
ARGOUT(unsigned char *dest),
ARGIN(const unsigned char *src),
ARGIN(const PackFile_Header *header))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(*dest);
static void cvt_num8_num16(
ARGOUT(unsigned char *dest),
ARGIN(const unsigned char *src),
ARGIN(const PackFile_Header *header))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(*dest);
static void cvt_num8_num16ppc(
ARGOUT(unsigned char *dest),
ARGIN(const unsigned char *src),
ARGIN(const PackFile_Header *header))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(*dest);
static void cvt_num8_num4(
ARGOUT(unsigned char *dest),
ARGIN(const unsigned char *src),
ARGIN(const PackFile_Header *header))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(*dest);
PARROT_INLINE
static void fetch_buf_12(
ARGOUT(unsigned char *rb),
ARGIN(const unsigned char *b),
ARGIN(const PackFile_Header *header))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(*rb);
PARROT_INLINE
static void fetch_buf_16(
ARGOUT(unsigned char *rb),
ARGIN(const unsigned char *b),
ARGIN(const PackFile_Header *header))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(*rb);
PARROT_INLINE
static void fetch_buf_32(
ARGOUT(unsigned char *rb),
ARGIN(const unsigned char *b),
ARGIN(const PackFile_Header *header))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(*rb);
PARROT_INLINE
static void fetch_buf_4(
ARGOUT(unsigned char *rb),
ARGIN(const unsigned char *b),
ARGIN(const PackFile_Header *header))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(*rb);
PARROT_INLINE
static void fetch_buf_8(
ARGOUT(unsigned char *rb),
ARGIN(const unsigned char *b),
ARGIN(const PackFile_Header *header))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(*rb);
PARROT_INLINE
static void fetch_buf_be_12(
ARGOUT(unsigned char *rb),
ARGIN(const unsigned char *b))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
FUNC_MODIFIES(*rb);
PARROT_INLINE
static void fetch_buf_be_16(
ARGOUT(unsigned char *rb),
ARGIN(const unsigned char *b))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
FUNC_MODIFIES(*rb);
PARROT_INLINE
static void fetch_buf_be_32(
ARGOUT(unsigned char *rb),
ARGIN(const unsigned char *b))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
FUNC_MODIFIES(*rb);
PARROT_INLINE
static void fetch_buf_be_4(
ARGOUT(unsigned char *rb),
ARGIN(const unsigned char *b))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
FUNC_MODIFIES(*rb);
PARROT_INLINE
static void fetch_buf_be_8(
ARGOUT(unsigned char *rb),
ARGIN(const unsigned char *b))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
FUNC_MODIFIES(*rb);
PARROT_INLINE
static void fetch_buf_le_12(
ARGOUT(unsigned char *rb),
ARGIN(const unsigned char *b))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
FUNC_MODIFIES(*rb);
PARROT_INLINE
static void fetch_buf_le_16(
ARGOUT(unsigned char *rb),
ARGIN(const unsigned char *b))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
FUNC_MODIFIES(*rb);
PARROT_INLINE
static void fetch_buf_le_32(
ARGOUT(unsigned char *rb),
ARGIN(const unsigned char *b))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
FUNC_MODIFIES(*rb);
PARROT_INLINE
static void fetch_buf_le_4(
ARGOUT(unsigned char *rb),
ARGIN(const unsigned char *b))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
FUNC_MODIFIES(*rb);
PARROT_INLINE
static void fetch_buf_le_8(
ARGOUT(unsigned char *rb),
ARGIN(const unsigned char *b))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
FUNC_MODIFIES(*rb);
PARROT_INLINE
PARROT_WARN_UNUSED_RESULT
PARROT_CONST_FUNCTION
static INTVAL fetch_iv_be(INTVAL w);
PARROT_INLINE
PARROT_WARN_UNUSED_RESULT
PARROT_CONST_FUNCTION
static INTVAL fetch_iv_le(INTVAL w);
PARROT_INLINE
PARROT_WARN_UNUSED_RESULT
PARROT_CONST_FUNCTION
static opcode_t fetch_op_be(opcode_t w);
PARROT_WARN_UNUSED_RESULT
static opcode_t fetch_op_be_4(ARGIN(const unsigned char *b))
__attribute__nonnull__(1);
PARROT_WARN_UNUSED_RESULT
static opcode_t fetch_op_be_8(ARGIN(const unsigned char *b))
__attribute__nonnull__(1);
PARROT_INLINE
PARROT_WARN_UNUSED_RESULT
PARROT_CONST_FUNCTION
static opcode_t fetch_op_le(opcode_t w);
PARROT_WARN_UNUSED_RESULT
static opcode_t fetch_op_le_4(ARGIN(const unsigned char *b))
__attribute__nonnull__(1);
PARROT_WARN_UNUSED_RESULT
static opcode_t fetch_op_le_8(ARGIN(const unsigned char *b))
__attribute__nonnull__(1);
#define ASSERT_ARGS_cvt_num10_num16 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(dest) \
, PARROT_ASSERT_ARG(src) \
, PARROT_ASSERT_ARG(header))
#define ASSERT_ARGS_cvt_num10_num16ppc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(dest) \
, PARROT_ASSERT_ARG(src) \
, PARROT_ASSERT_ARG(header))
#define ASSERT_ARGS_cvt_num10_num4 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(dest) \
, PARROT_ASSERT_ARG(src) \
, PARROT_ASSERT_ARG(header))
#define ASSERT_ARGS_cvt_num10_num8 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(dest) \
, PARROT_ASSERT_ARG(src) \
, PARROT_ASSERT_ARG(header))
#define ASSERT_ARGS_cvt_num16_num10 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(dest) \
, PARROT_ASSERT_ARG(src) \
, PARROT_ASSERT_ARG(header))
#define ASSERT_ARGS_cvt_num16_num16ppc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(dest) \
, PARROT_ASSERT_ARG(src) \
, PARROT_ASSERT_ARG(header))
#define ASSERT_ARGS_cvt_num16_num4 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(dest) \
, PARROT_ASSERT_ARG(src) \
, PARROT_ASSERT_ARG(header))
#define ASSERT_ARGS_cvt_num16_num8 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(dest) \
, PARROT_ASSERT_ARG(src) \
, PARROT_ASSERT_ARG(header))
#define ASSERT_ARGS_cvt_num16ppc_num10 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(dest) \
, PARROT_ASSERT_ARG(src) \
, PARROT_ASSERT_ARG(header))
#define ASSERT_ARGS_cvt_num16ppc_num16 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(dest) \
, PARROT_ASSERT_ARG(src) \
, PARROT_ASSERT_ARG(header))
#define ASSERT_ARGS_cvt_num16ppc_num4 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(dest) \
, PARROT_ASSERT_ARG(src) \
, PARROT_ASSERT_ARG(header))
#define ASSERT_ARGS_cvt_num16ppc_num8 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(dest) \
, PARROT_ASSERT_ARG(src) \
, PARROT_ASSERT_ARG(header))
#define ASSERT_ARGS_cvt_num4_num10 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(dest) \
, PARROT_ASSERT_ARG(src) \
, PARROT_ASSERT_ARG(header))
#define ASSERT_ARGS_cvt_num4_num16 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(dest) \
, PARROT_ASSERT_ARG(src) \
, PARROT_ASSERT_ARG(header))
#define ASSERT_ARGS_cvt_num4_num16ppc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(dest) \
, PARROT_ASSERT_ARG(src) \
, PARROT_ASSERT_ARG(header))
#define ASSERT_ARGS_cvt_num4_num8 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(dest) \
, PARROT_ASSERT_ARG(src) \
, PARROT_ASSERT_ARG(header))
#define ASSERT_ARGS_cvt_num8_num10 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(dest) \
, PARROT_ASSERT_ARG(src) \
, PARROT_ASSERT_ARG(header))
#define ASSERT_ARGS_cvt_num8_num16 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(dest) \
, PARROT_ASSERT_ARG(src) \
, PARROT_ASSERT_ARG(header))
#define ASSERT_ARGS_cvt_num8_num16ppc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(dest) \
, PARROT_ASSERT_ARG(src) \
, PARROT_ASSERT_ARG(header))
#define ASSERT_ARGS_cvt_num8_num4 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(dest) \
, PARROT_ASSERT_ARG(src) \
, PARROT_ASSERT_ARG(header))
#define ASSERT_ARGS_fetch_buf_12 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(rb) \
, PARROT_ASSERT_ARG(b) \
, PARROT_ASSERT_ARG(header))
#define ASSERT_ARGS_fetch_buf_16 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(rb) \
, PARROT_ASSERT_ARG(b) \
, PARROT_ASSERT_ARG(header))
#define ASSERT_ARGS_fetch_buf_32 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(rb) \
, PARROT_ASSERT_ARG(b) \
, PARROT_ASSERT_ARG(header))
#define ASSERT_ARGS_fetch_buf_4 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(rb) \
, PARROT_ASSERT_ARG(b) \
, PARROT_ASSERT_ARG(header))
#define ASSERT_ARGS_fetch_buf_8 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(rb) \
, PARROT_ASSERT_ARG(b) \
, PARROT_ASSERT_ARG(header))
#define ASSERT_ARGS_fetch_buf_be_12 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(rb) \
, PARROT_ASSERT_ARG(b))
#define ASSERT_ARGS_fetch_buf_be_16 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(rb) \
, PARROT_ASSERT_ARG(b))
#define ASSERT_ARGS_fetch_buf_be_32 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(rb) \
, PARROT_ASSERT_ARG(b))
#define ASSERT_ARGS_fetch_buf_be_4 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(rb) \
, PARROT_ASSERT_ARG(b))
#define ASSERT_ARGS_fetch_buf_be_8 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(rb) \
, PARROT_ASSERT_ARG(b))
#define ASSERT_ARGS_fetch_buf_le_12 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(rb) \
, PARROT_ASSERT_ARG(b))
#define ASSERT_ARGS_fetch_buf_le_16 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(rb) \
, PARROT_ASSERT_ARG(b))
#define ASSERT_ARGS_fetch_buf_le_32 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(rb) \
, PARROT_ASSERT_ARG(b))
#define ASSERT_ARGS_fetch_buf_le_4 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(rb) \
, PARROT_ASSERT_ARG(b))
#define ASSERT_ARGS_fetch_buf_le_8 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(rb) \
, PARROT_ASSERT_ARG(b))
#define ASSERT_ARGS_fetch_iv_be __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_fetch_iv_le __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_fetch_op_be __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_fetch_op_be_4 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(b))
#define ASSERT_ARGS_fetch_op_be_8 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(b))
#define ASSERT_ARGS_fetch_op_le __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_fetch_op_le_4 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(b))
#define ASSERT_ARGS_fetch_op_le_8 __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(b))
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: static */
/*
* round val up to whole size, return result in bytes
*/
#define ROUND_UP_B(val, size) ((((val) + ((size) - 1))/(size)) * (size))
/*
* round val up to whole opcode_t, return result in opcodes
*/
#define ROUND_UP(val, size) (((val) + ((size) - 1))/(size))
/*
* offset not in ptr diff, but in byte
*/
#define OFFS(pf, cursor) ((pf) ? ((const char *)(cursor) - (const char *)((pf)->src)) : 0)
#define PF_NEEDS_ENDIANIZE(header) header->byteorder != PARROT_BIGENDIAN
#define PF_IS_BIGENDIAN(header) header->byteorder != 0
#define ROUND_NUM_TO(num, type, prec) /* TODO: not yet */
/*
* low level FLOATVAL fetch and convert functions (see packfile.h)
*
* Floattype 0 = IEEE-754 8 byte double (binary64)
* Floattype 1 = Intel 80-bit long double stored in 12 byte (i386)
* or aligned to 16 byte (x86_64/ia64)
* Floattype 2 = IEEE-754 128 bit quad precision stored in 16 byte,
* Sparc64 quad-float or __float128, gcc since 4.3 (binary128)
* Floattype 3 = IEEE-754 4 byte float (binary32)
* Floattype 4 = PowerPC 16 byte double-double (-mlong-double-128)
* not yet:
* Floattype 5 = IEEE-754 2 byte half-precision float (binary16)
* Floattype 6 = MIPS64 16 byte long double
* Floattype 7 = AIX 16 byte long double
*
*/
/*
=item C<static void cvt_num10_num8(unsigned char *dest, const unsigned char
*src, const PackFile_Header *header)>
Converts intel 80-bit long double to IEEE 754 LE 8-byte double.
On 64bit intel the size is 16 byte, on 32bit intel 12 byte.
Tested ok.
=cut
*/
static void
cvt_num10_num8(ARGOUT(unsigned char *dest),
ARGIN(const unsigned char *src),
ARGIN(const PackFile_Header *header))
{
ASSERT_ARGS(cvt_num10_num8)
/*
padding + 10-byte double (80 bits):
unused 2 byte on i386, 6 byte on x86_84/ia64
sign 1 bit 79
exp 15 bits 78-64 bias 16383
intbit 1 bit 63 set if normalized
man 63 bits 62-0
to 8-byte double (64 bits):
sign 1 bit 63
exp 11 bits 62-52 bias 1023
man 52 bits 51-0
+-------+-------+-------+-------+-------+-------+--...--+-------+
|src[11]|src[10]|src[9] |src[8] |src[7] |src[6] | ... |src[0] |
| unused |S| Exp |i| Fract |
+-------+-------+-------+-------+-------+-------+--...--+-------+
|<-----16------>|1|<-----15---->|1|<---------63 bits----------->|
<-------------->|<----------------80 bits----------------------->
+-------+-------+-------+-------+-------+-------+-------+-------+
|dest[7]|dest[6]|dest[5]|dest[4]|dest[3]|dest[2]|dest[1]|dest[0]|
S| E | F |
+-------+-------+-------+-------+-------+-------+-------+-------+
1|<---11-->|<---------------------52 bits---------------------->|
<----------------------------64 bits---------------------------->
8-byte DOUBLE FLOATING-POINT
*/
unsigned char b[10];
int expo, i, sign;
# ifdef __LCC__
int expo2;
# endif
if (PF_IS_BIGENDIAN(header)) {
SWAB_10(b, src);
}
else
memcpy(b, src, 10);
memset(dest, 0, 8);
/* exponents 15 -> 11 bits */
sign = b[9] & 0x80;
expo = ((b[9] & 0x7f)<< 8 | b[8]);
if (expo == 0) {
nul:
if (sign)
dest[7] |= 0x80;
return;
}
# ifdef __LCC__
/* Yet again, LCC blows up mysteriously until a temporary variable is
* added. */
expo2 = expo - 16383;
expo = expo2;
# else
expo -= 16383; /* - bias */
# endif
expo += 1023; /* + bias 8byte */
if (expo <= 0) /* underflow */
goto nul;
if (expo > 0x7ff) { /* inf/nan */
dest[7] = 0x7f;
dest[6] = b[7] == 0xc0 ? 0xf8 : 0xf0 ;
goto nul;
}
expo <<= 4;
dest[6] = (expo & 0xff);
dest[7] = (expo & 0x7f00) >> 8;
if (sign)
dest[7] |= 0x80;
/* long double frac 63 bits => 52 bits
b[7] &= 0x7f; reset integer bit 63 */
for (i = 0; i < 6; ++i) {
dest[i+1] |= (i==5 ? b[7] & 0x7f : b[i+2]) >> 3;
dest[i] |= (b[i+2] & 0x1f) << 5;
}
dest[0] |= b[1] >> 3;
#if PARROT_BIGENDIAN
# if HAS_INT64
*(Parrot_UInt8*)dest = bswap64(*(Parrot_UInt8*)dest);
# else
bswap64(dest, dest);
# endif
#endif
}
/*
=item C<static void cvt_num16_num8(unsigned char *dest, const unsigned char
*src, const PackFile_Header *header)>
Converts IEEE 754 16-byte long double to IEEE 754 8 byte double.
First variant ok, 2nd with too low precision.
=cut
*/
static void
cvt_num16_num8(ARGOUT(unsigned char *dest),
ARGIN(const unsigned char *src),
ARGIN(const PackFile_Header *header))
{
ASSERT_ARGS(cvt_num16_num8)
if ((FLOATTYPE == FLOATTYPE_16) && (sizeof(double) == 8)) {
FLOATVAL ld;
double d;
if (PF_NEEDS_ENDIANIZE(header)) {
unsigned char rb[16];
SWAB_16(rb, src);
memcpy(&ld, rb, 16);
}
else
memcpy(&ld, src, 16);
d = (double)ld; /* native compiler cast. Beware: the other direction cannot be casted */
memcpy(dest, &d, 8);
return;
}
else {
unsigned char b[16];
int expo, i, sign;
# ifdef __LCC__
int expo2;
# endif
if (PF_IS_BIGENDIAN(header)) {
SWAB_16(b, src);
}
else
memcpy(b, src, 16);
/* Have only 12-byte long double, or no long double at all. Need to disect it */
/*
16-byte quad double (128 bits):
sign 1 bit 127
exp 15 bits 126-112 bias 16383
man 112 bits 111-0
to 8-byte double (64 bits):
sign 1 bit 63
exp 11 bits 62-52 bias 1023
man 52 bits 51-0
+-------+-------+-------+-------+-------+-------+--...--+-------+
|src[15]|src[14]|src[13]|src[12]|src[11]|src[10]| ... |src[0] |
S| E | F |
+-------+-------+-------+-------+-------+-------+--...--+-------+
1|<-----15----->|<----------------112 bits--------------------->|
<---------------------------128 bits---------------------------->
16-byte LONG DOUBLE FLOATING-POINT (__float128 or Sparc 64-bit)
+-------+-------+-------+-------+-------+-------+-------+-------+
|dest[7]|dest[6]|dest[5]|dest[4]|dest[3]|dest[2]|dest[1]|dest[0]|
S| E | F |
+-------+-------+-------+-------+-------+-------+-------+-------+
1|<---11-- >|<--------------------52 bits---------------------->|
<----------------------------64 bits---------------------------->
8-byte DOUBLE FLOATING-POINT
*/
memset(dest, 0, 8);
sign = b[15] & 0x80; /* 10000000 */
/* 15->11 exponents bits */
expo = ((b[15] & 0x7f)<< 8 | b[14]);
if (expo == 0) {
nul:
if (sign)
dest[7] |= 0x80;
return;
}
# ifdef __LCC__
/* LCC blows up mysteriously until a temporary variable is
* added. */
expo2 = expo - 16383;
expo = expo2;
# else
expo -= 16383; /* - same bias as with 80-bit */
# endif
expo += 1023; /* + bias 8byte */
if (expo <= 0) /* underflow */
goto nul;
if (expo > 0x7ff) { /* overflow, inf/nan */
dest[7] = 0x7f;
dest[6] |= b[7] == 0xc0 ? 0xf8 : 0xf0 ;
goto nul;
}
expo <<= 4;
dest[6] |= (expo & 0xff);
dest[7] = (expo & 0x7f00) >> 8;
if (sign)
dest[7] |= 0x80;
/* bypass if mantissa is zero, well bytes 13-12,11-4 */
# ifdef HAS_INT64
if (*(const Parrot_UInt2*)&b[12] || *(const Parrot_UInt8*)&b[4])
# else
if (*(const Parrot_UInt4*)&b[10] || *(const Parrot_UInt4*)&b[6])
# endif
{
/* b[13] => dest[6]; => dest[0] */
for (i = 0; i < 6; ++i) {
dest[i+1] |= (i==5 ? b[13] & 0xf0 : b[i+9]) >> 4;
dest[i] |= (b[i+8] & 0xf) << 4;
}
dest[0] |= (b[7] & 0xf0) >> 4;
}
}
#if PARROT_BIGENDIAN
# if HAS_INT64
*(Parrot_UInt8*)dest = bswap64(*(Parrot_UInt8*)dest);
# else
bswap64(dest, dest);
# endif
#endif
}
/*
=item C<static void cvt_num4_num8(unsigned char *dest, const unsigned char *src,
const PackFile_Header *header)>
Converts IEEE 754 4-byte float to IEEE 754 8 byte double.
Not yet tested.
=cut
*/
static void
cvt_num4_num8(ARGOUT(unsigned char *dest),
ARGIN(const unsigned char *src),
ARGIN(const PackFile_Header *header))
{
union {
float f;
Parrot_UInt4 i;
} u;
double d;
if (PF_NEEDS_ENDIANIZE(header))
u.i = bswap32(*(const Parrot_UInt4*)src);
else {
memcpy(&u.f, src, 4);
}
d = (double)u.f;
ROUND_NUM_TO(d, double, PARROT_FLT_DIG);
memcpy(dest, &d, 8);
}
/*
=item C<static void cvt_num16_num10(unsigned char *dest, const unsigned char
*src, const PackFile_Header *header)>
Converts IEEE 754 LE 16-byte long double to i386 LE 80-bit long double.
See http://babbage.cs.qc.cuny.edu/IEEE-754/References.xhtml
Tested ok.
=cut
*/
#if (FLOATTYPE == FLOATTYPE_10)
static void
cvt_num16_num10(ARGOUT(unsigned char *dest),
ARGIN(const unsigned char *src),
ARGIN(const PackFile_Header *header))
{
ASSERT_ARGS(cvt_num16_num10)
/*
16-byte double (128 bits):
sign 1 bit 127
exp 15 bits 126-112 bias 16383
man 112 bits 111-0
to 12-byte double (96 bits):
unused 16 bits 95-80
sign 1 bit 79
exp 15 bits 78-64 bias 16383
intbit 1 bit 63 set if normalized
man 63 bits 62-0
+-------+-------+-------+-------+-------+-------+--...--+-------+
|src[15]|src[14]|src[13]|src[12]|src[11]|src[10]| ... |src[0] |
S| E | F |
+-------+-------+-------+-------+-------+-------+--...--+-------+
1|<-----15----->|<----------------112 bits--------------------->|
<---------------------------128 bits---------------------------->
16-byte QUAD DOUBLE FLOATING-POINT (__float128 or BE 64-bit)
+-------+-------+-------+-------+-------+-------+--...--+-------+
|dest[11]dest[10]dest[9]|dest[8]|dest[7]|dest[6]| ... |dest[0]|
| unused |S| Exp | Fract |
+-------+-------+-------+-------+-------+-------+--...--+-------+
|<-----16------>|1|<-----15---->|<-----------64 bits----------->|
<-------------->|<----------------80 bits----------------------->
12-byte LONG DOUBLE FLOATING-POINT (intel special)
*/
unsigned char b[16];
if (PF_IS_BIGENDIAN(header)) {
SWAB_16(b, src);
}
else
memcpy(b, src, 16);
memset(dest, 0, 12);
/* simply copy over sign + exp, TODO: need to check -inf */
dest[8] = b[15];
dest[9] = b[14];
/* and copy the rest */
memcpy(&dest[0], &b[0], 8);
dest[7] |= 0x80; /* set integer bit 63 */
#if PARROT_BIGENDIAN
memcpy(b, dest, 10);
SWAB_10(dest, b);
#endif
}
/*
=item C<static void cvt_num8_num10(unsigned char *dest, const unsigned char
*src, const PackFile_Header *header)>
Converts i386 8-byte double to i386 80bit long double.
Tested ok.
=cut
*/
static void
cvt_num8_num10(ARGOUT(unsigned char *dest), ARGIN(const unsigned char *src), ARGIN(const PackFile_Header *header))
{
ASSERT_ARGS(cvt_num8_num10)
long double ld;
union {
double d;
unsigned char c[8];
} u;
if (PF_NEEDS_ENDIANIZE(header)) { /* swab to native */
#if HAS_INT64
*(Parrot_UInt8*)u.c = bswap64(*(const Parrot_UInt8*)src);
#else
bswap64(u.c, src);
#endif
}
else {
memcpy(&u.d, src, 8);
}
ld = (long double)u.d; /* compiler cast */
ROUND_NUM_TO(ld, long double, PARROT_DBL_DIG);
memcpy(dest, &ld, 12);
}
/*
=item C<static void cvt_num4_num10(unsigned char *dest, const unsigned char
*src, const PackFile_Header *header)>
Converts i386 4-byte float to i386 80bit long double.
Tested ok.
=cut
*/
static void
cvt_num4_num10(ARGOUT(unsigned char *dest), ARGIN(const unsigned char *src), ARGIN(const PackFile_Header *header))
{
long double ld;
union {
float f;
Parrot_UInt4 i;
} u;
if (PF_NEEDS_ENDIANIZE(header))
u.i = bswap32(*(const Parrot_UInt4*)src);
else {
memcpy(&u.f, src, 4);
}
ld = (long double)u.f; /* compiler cast */
ROUND_NUM_TO(ld, long double, PARROT_FLT_DIG);
memcpy(dest, &ld, sizeof(long double));
}
#endif
/*
=item C<static void cvt_num10_num16(unsigned char *dest, const unsigned char
*src, const PackFile_Header *header)>
Converts i386 LE 10-byte long double to IEEE 754 LE 16-byte quad double.
Not yet properly rounded.