717
Define-funktions for reading and storing in machine independent format
721
/* Optimized store functions for Intel x86 */
722
#if defined(__i386__)
723
#define sint2korr(A) (*((int16_t *) (A)))
724
#define sint3korr(A) ((int32_t) ((((uchar) (A)[2]) & 128) ? \
725
(((uint32_t) 255L << 24) | \
726
(((uint32_t) (uchar) (A)[2]) << 16) |\
727
(((uint32_t) (uchar) (A)[1]) << 8) | \
728
((uint32_t) (uchar) (A)[0])) : \
729
(((uint32_t) (uchar) (A)[2]) << 16) |\
730
(((uint32_t) (uchar) (A)[1]) << 8) | \
731
((uint32_t) (uchar) (A)[0])))
732
#define sint4korr(A) (*((long *) (A)))
733
#define uint2korr(A) (*((uint16_t *) (A)))
734
#if defined(HAVE_purify)
735
#define uint3korr(A) (uint32_t) (((uint32_t) ((uchar) (A)[0])) +\
736
(((uint32_t) ((uchar) (A)[1])) << 8) +\
737
(((uint32_t) ((uchar) (A)[2])) << 16))
742
Please, note, uint3korr reads 4 bytes (not 3) !
743
It means, that you have to provide enough allocated space !
745
#define uint3korr(A) (long) (*((unsigned int *) (A)) & 0xFFFFFF)
746
#endif /* HAVE_purify */
747
#define uint4korr(A) (*((uint32_t *) (A)))
748
#define uint5korr(A) ((uint64_t)(((uint32_t) ((uchar) (A)[0])) +\
749
(((uint32_t) ((uchar) (A)[1])) << 8) +\
750
(((uint32_t) ((uchar) (A)[2])) << 16) +\
751
(((uint32_t) ((uchar) (A)[3])) << 24)) +\
752
(((uint64_t) ((uchar) (A)[4])) << 32))
753
#define uint6korr(A) ((uint64_t)(((uint32_t) ((uchar) (A)[0])) + \
754
(((uint32_t) ((uchar) (A)[1])) << 8) + \
755
(((uint32_t) ((uchar) (A)[2])) << 16) + \
756
(((uint32_t) ((uchar) (A)[3])) << 24)) + \
757
(((uint64_t) ((uchar) (A)[4])) << 32) + \
758
(((uint64_t) ((uchar) (A)[5])) << 40))
759
#define uint8korr(A) (*((uint64_t *) (A)))
760
#define sint8korr(A) (*((int64_t *) (A)))
761
#define int2store(T,A) *((uint16_t*) (T))= (uint16_t) (A)
762
#define int3store(T,A) do { *(T)= (uchar) ((A));\
763
*(T+1)=(uchar) (((uint) (A) >> 8));\
764
*(T+2)=(uchar) (((A) >> 16)); } while (0)
765
#define int4store(T,A) *((long *) (T))= (long) (A)
766
#define int5store(T,A) do { *(T)= (uchar)((A));\
767
*((T)+1)=(uchar) (((A) >> 8));\
768
*((T)+2)=(uchar) (((A) >> 16));\
769
*((T)+3)=(uchar) (((A) >> 24)); \
770
*((T)+4)=(uchar) (((A) >> 32)); } while(0)
771
#define int6store(T,A) do { *(T)= (uchar)((A)); \
772
*((T)+1)=(uchar) (((A) >> 8)); \
773
*((T)+2)=(uchar) (((A) >> 16)); \
774
*((T)+3)=(uchar) (((A) >> 24)); \
775
*((T)+4)=(uchar) (((A) >> 32)); \
776
*((T)+5)=(uchar) (((A) >> 40)); } while(0)
777
#define int8store(T,A) *((uint64_t *) (T))= (uint64_t) (A)
783
#define doubleget(V,M) \
784
do { doubleget_union _tmp; \
785
_tmp.m[0] = *((long*)(M)); \
786
_tmp.m[1] = *(((long*) (M))+1); \
787
(V) = _tmp.v; } while(0)
788
#define doublestore(T,V) do { *((long *) T) = ((doubleget_union *)&V)->m[0]; \
789
*(((long *) T)+1) = ((doubleget_union *)&V)->m[1]; \
791
#define float4get(V,M) do { *((float *) &(V)) = *((float*) (M)); } while(0)
792
#define float8get(V,M) doubleget((V),(M))
793
#define float4store(V,M) memcpy(V, (&M), sizeof(float))
794
#define floatstore(T,V) memcpy((T), (&V), sizeof(float))
795
#define floatget(V,M) memcpy(&V, (M), sizeof(float))
796
#define float8store(V,M) doublestore((V),(M))
800
We're here if it's not a IA-32 architecture (Win32 and UNIX IA-32 defines
803
#define sint2korr(A) (int16_t) (((int16_t) ((uchar) (A)[0])) +\
804
((int16_t) ((int16_t) (A)[1]) << 8))
805
#define sint3korr(A) ((int32_t) ((((uchar) (A)[2]) & 128) ? \
806
(((uint32_t) 255L << 24) | \
807
(((uint32_t) (uchar) (A)[2]) << 16) |\
808
(((uint32_t) (uchar) (A)[1]) << 8) | \
809
((uint32_t) (uchar) (A)[0])) : \
810
(((uint32_t) (uchar) (A)[2]) << 16) |\
811
(((uint32_t) (uchar) (A)[1]) << 8) | \
812
((uint32_t) (uchar) (A)[0])))
813
#define sint4korr(A) (int32_t) (((int32_t) ((uchar) (A)[0])) +\
814
(((int32_t) ((uchar) (A)[1]) << 8)) +\
815
(((int32_t) ((uchar) (A)[2]) << 16)) +\
816
(((int32_t) ((int16_t) (A)[3]) << 24)))
817
#define sint8korr(A) (int64_t) uint8korr(A)
818
#define uint2korr(A) (uint16_t) (((uint16_t) ((uchar) (A)[0])) +\
819
((uint16_t) ((uchar) (A)[1]) << 8))
820
#define uint3korr(A) (uint32_t) (((uint32_t) ((uchar) (A)[0])) +\
821
(((uint32_t) ((uchar) (A)[1])) << 8) +\
822
(((uint32_t) ((uchar) (A)[2])) << 16))
823
#define uint4korr(A) (uint32_t) (((uint32_t) ((uchar) (A)[0])) +\
824
(((uint32_t) ((uchar) (A)[1])) << 8) +\
825
(((uint32_t) ((uchar) (A)[2])) << 16) +\
826
(((uint32_t) ((uchar) (A)[3])) << 24))
827
#define uint5korr(A) ((uint64_t)(((uint32_t) ((uchar) (A)[0])) +\
828
(((uint32_t) ((uchar) (A)[1])) << 8) +\
829
(((uint32_t) ((uchar) (A)[2])) << 16) +\
830
(((uint32_t) ((uchar) (A)[3])) << 24)) +\
831
(((uint64_t) ((uchar) (A)[4])) << 32))
832
#define uint6korr(A) ((uint64_t)(((uint32_t) ((uchar) (A)[0])) + \
833
(((uint32_t) ((uchar) (A)[1])) << 8) + \
834
(((uint32_t) ((uchar) (A)[2])) << 16) + \
835
(((uint32_t) ((uchar) (A)[3])) << 24)) + \
836
(((uint64_t) ((uchar) (A)[4])) << 32) + \
837
(((uint64_t) ((uchar) (A)[5])) << 40))
838
#define uint8korr(A) ((uint64_t)(((uint32_t) ((uchar) (A)[0])) +\
839
(((uint32_t) ((uchar) (A)[1])) << 8) +\
840
(((uint32_t) ((uchar) (A)[2])) << 16) +\
841
(((uint32_t) ((uchar) (A)[3])) << 24)) +\
842
(((uint64_t) (((uint32_t) ((uchar) (A)[4])) +\
843
(((uint32_t) ((uchar) (A)[5])) << 8) +\
844
(((uint32_t) ((uchar) (A)[6])) << 16) +\
845
(((uint32_t) ((uchar) (A)[7])) << 24))) <<\
847
#define int2store(T,A) do { uint def_temp= (uint) (A) ;\
848
*((uchar*) (T))= (uchar)(def_temp); \
849
*((uchar*) (T)+1)=(uchar)((def_temp >> 8)); \
851
#define int3store(T,A) do { /*lint -save -e734 */\
852
*((uchar*)(T))=(uchar) ((A));\
853
*((uchar*) (T)+1)=(uchar) (((A) >> 8));\
854
*((uchar*)(T)+2)=(uchar) (((A) >> 16)); \
855
/*lint -restore */} while(0)
856
#define int4store(T,A) do { *((char *)(T))=(char) ((A));\
857
*(((char *)(T))+1)=(char) (((A) >> 8));\
858
*(((char *)(T))+2)=(char) (((A) >> 16));\
859
*(((char *)(T))+3)=(char) (((A) >> 24)); } while(0)
860
#define int5store(T,A) do { *((char *)(T))= (char)((A)); \
861
*(((char *)(T))+1)= (char)(((A) >> 8)); \
862
*(((char *)(T))+2)= (char)(((A) >> 16)); \
863
*(((char *)(T))+3)= (char)(((A) >> 24)); \
864
*(((char *)(T))+4)= (char)(((A) >> 32)); \
866
#define int6store(T,A) do { *((char *)(T))= (char)((A)); \
867
*(((char *)(T))+1)= (char)(((A) >> 8)); \
868
*(((char *)(T))+2)= (char)(((A) >> 16)); \
869
*(((char *)(T))+3)= (char)(((A) >> 24)); \
870
*(((char *)(T))+4)= (char)(((A) >> 32)); \
871
*(((char *)(T))+5)= (char)(((A) >> 40)); \
873
#define int8store(T,A) do { uint def_temp= (uint) (A), def_temp2= (uint) ((A) >> 32); \
874
int4store((T),def_temp); \
875
int4store((T+4),def_temp2); } while(0)
876
#ifdef WORDS_BIGENDIAN
877
#define float4store(T,A) do { *(T)= ((uchar *) &A)[3];\
878
*((T)+1)=(char) ((uchar *) &A)[2];\
879
*((T)+2)=(char) ((uchar *) &A)[1];\
880
*((T)+3)=(char) ((uchar *) &A)[0]; } while(0)
882
#define float4get(V,M) do { float def_temp;\
883
((uchar*) &def_temp)[0]=(M)[3];\
884
((uchar*) &def_temp)[1]=(M)[2];\
885
((uchar*) &def_temp)[2]=(M)[1];\
886
((uchar*) &def_temp)[3]=(M)[0];\
887
(V)=def_temp; } while(0)
888
#define float8store(T,V) do { *(T)= ((uchar *) &V)[7];\
889
*((T)+1)=(char) ((uchar *) &V)[6];\
890
*((T)+2)=(char) ((uchar *) &V)[5];\
891
*((T)+3)=(char) ((uchar *) &V)[4];\
892
*((T)+4)=(char) ((uchar *) &V)[3];\
893
*((T)+5)=(char) ((uchar *) &V)[2];\
894
*((T)+6)=(char) ((uchar *) &V)[1];\
895
*((T)+7)=(char) ((uchar *) &V)[0]; } while(0)
897
#define float8get(V,M) do { double def_temp;\
898
((uchar*) &def_temp)[0]=(M)[7];\
899
((uchar*) &def_temp)[1]=(M)[6];\
900
((uchar*) &def_temp)[2]=(M)[5];\
901
((uchar*) &def_temp)[3]=(M)[4];\
902
((uchar*) &def_temp)[4]=(M)[3];\
903
((uchar*) &def_temp)[5]=(M)[2];\
904
((uchar*) &def_temp)[6]=(M)[1];\
905
((uchar*) &def_temp)[7]=(M)[0];\
906
(V) = def_temp; } while(0)
908
#define float4get(V,M) memcpy(&V, (M), sizeof(float))
909
#define float4store(V,M) memcpy(V, (&M), sizeof(float))
911
#if defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN)
912
#define doublestore(T,V) do { *(((char*)T)+0)=(char) ((uchar *) &V)[4];\
913
*(((char*)T)+1)=(char) ((uchar *) &V)[5];\
914
*(((char*)T)+2)=(char) ((uchar *) &V)[6];\
915
*(((char*)T)+3)=(char) ((uchar *) &V)[7];\
916
*(((char*)T)+4)=(char) ((uchar *) &V)[0];\
917
*(((char*)T)+5)=(char) ((uchar *) &V)[1];\
918
*(((char*)T)+6)=(char) ((uchar *) &V)[2];\
919
*(((char*)T)+7)=(char) ((uchar *) &V)[3]; }\
921
#define doubleget(V,M) do { double def_temp;\
922
((uchar*) &def_temp)[0]=(M)[4];\
923
((uchar*) &def_temp)[1]=(M)[5];\
924
((uchar*) &def_temp)[2]=(M)[6];\
925
((uchar*) &def_temp)[3]=(M)[7];\
926
((uchar*) &def_temp)[4]=(M)[0];\
927
((uchar*) &def_temp)[5]=(M)[1];\
928
((uchar*) &def_temp)[6]=(M)[2];\
929
((uchar*) &def_temp)[7]=(M)[3];\
930
(V) = def_temp; } while(0)
931
#endif /* __FLOAT_WORD_ORDER */
933
#define float8get(V,M) doubleget((V),(M))
934
#define float8store(V,M) doublestore((V),(M))
935
#endif /* WORDS_BIGENDIAN */
937
#endif /* __i386__ */
940
Macro for reading 32-bit integer from network byte order (big-endian)
941
from unaligned memory location.
943
#define int4net(A) (int32_t) (((uint32_t) ((uchar) (A)[3])) |\
944
(((uint32_t) ((uchar) (A)[2])) << 8) |\
945
(((uint32_t) ((uchar) (A)[1])) << 16) |\
946
(((uint32_t) ((uchar) (A)[0])) << 24))
948
Define-funktions for reading and storing in machine format from/to
949
short/long to/from some place in memory V should be a (not
950
register) variable, M is a pointer to byte
953
#ifdef WORDS_BIGENDIAN
955
#define ushortget(V,M) do { V = (uint16_t) (((uint16_t) ((uchar) (M)[1]))+\
956
((uint16_t) ((uint16_t) (M)[0]) << 8)); } while(0)
957
#define shortget(V,M) do { V = (short) (((short) ((uchar) (M)[1]))+\
958
((short) ((short) (M)[0]) << 8)); } while(0)
959
#define longget(V,M) do { int32_t def_temp;\
960
((uchar*) &def_temp)[0]=(M)[0];\
961
((uchar*) &def_temp)[1]=(M)[1];\
962
((uchar*) &def_temp)[2]=(M)[2];\
963
((uchar*) &def_temp)[3]=(M)[3];\
964
(V)=def_temp; } while(0)
965
#define ulongget(V,M) do { uint32_t def_temp;\
966
((uchar*) &def_temp)[0]=(M)[0];\
967
((uchar*) &def_temp)[1]=(M)[1];\
968
((uchar*) &def_temp)[2]=(M)[2];\
969
((uchar*) &def_temp)[3]=(M)[3];\
970
(V)=def_temp; } while(0)
971
#define shortstore(T,A) do { uint def_temp=(uint) (A) ;\
972
*(((char*)T)+1)=(char)(def_temp); \
973
*(((char*)T)+0)=(char)(def_temp >> 8); } while(0)
974
#define longstore(T,A) do { *(((char*)T)+3)=((A));\
975
*(((char*)T)+2)=(((A) >> 8));\
976
*(((char*)T)+1)=(((A) >> 16));\
977
*(((char*)T)+0)=(((A) >> 24)); } while(0)
979
#define floatget(V,M) memcpy(&V, (M), sizeof(float))
980
#define floatstore(T, V) memcpy((T), (&V), sizeof(float))
981
#define doubleget(V, M) memcpy(&V, (M), sizeof(double))
982
#define doublestore(T, V) memcpy((T), &V, sizeof(double))
983
#define int64_tget(V, M) memcpy(&V, (M), sizeof(uint64_t))
984
#define int64_tstore(T, V) memcpy((T), &V, sizeof(uint64_t))
988
#define ushortget(V,M) do { V = uint2korr(M); } while(0)
989
#define shortget(V,M) do { V = sint2korr(M); } while(0)
990
#define longget(V,M) do { V = sint4korr(M); } while(0)
991
#define ulongget(V,M) do { V = uint4korr(M); } while(0)
992
#define shortstore(T,V) int2store(T,V)
993
#define longstore(T,V) int4store(T,V)
995
#define floatstore(T,V) memcpy((T), (&V), sizeof(float))
996
#define floatget(V,M) memcpy(&V, (M), sizeof(float))
999
#define doubleget(V, M) memcpy(&V, (M), sizeof(double))
1000
#define doublestore(T,V) memcpy((T), &V, sizeof(double))
1001
#endif /* doubleget */
1002
#define int64_tget(V,M) memcpy(&V, (M), sizeof(uint64_t))
1003
#define int64_tstore(T,V) memcpy((T), &V, sizeof(uint64_t))
1005
#endif /* WORDS_BIGENDIAN */
1007
695
/* my_sprintf was here. RIP */