603
611
typedef unsigned char uchar; /* Short for unsigned char */
607
typedef signed char int8; /* Signed integer >= 8 bits */
610
typedef unsigned char uint8; /* Unsigned integer >= 8 bits */
616
typedef unsigned short uint16;
623
typedef unsigned int uint32;
625
#elif SIZEOF_LONG == 4
630
typedef unsigned long uint32;
633
#error Neither int or long is of 4 bytes width
636
614
#if !defined(HAVE_ULONG) && !defined(__USE_MISC)
637
typedef uint32_t ulong; /* Short for unsigned long */
639
#ifndef int64_t_defined
641
Using [unsigned] long long is preferable as [u]int64_t because we use
642
[unsigned] long long unconditionally in many places,
643
for example in constants with [U]LL suffix.
645
typedef int64_t int64_t;
615
typedef unsigned long ulong; /* Short for unsigned long */
648
618
#define MY_ERRPTR ((void*)(intptr)1)
695
665
/* Optimized store functions for Intel x86 */
696
666
#if defined(__i386__)
697
#define sint2korr(A) (*((int16 *) (A)))
698
#define sint3korr(A) ((int32) ((((uchar) (A)[2]) & 128) ? \
699
(((uint32) 255L << 24) | \
700
(((uint32) (uchar) (A)[2]) << 16) |\
701
(((uint32) (uchar) (A)[1]) << 8) | \
702
((uint32) (uchar) (A)[0])) : \
703
(((uint32) (uchar) (A)[2]) << 16) |\
704
(((uint32) (uchar) (A)[1]) << 8) | \
705
((uint32) (uchar) (A)[0])))
667
#define sint2korr(A) (*((int16_t *) (A)))
668
#define sint3korr(A) ((int32_t) ((((uchar) (A)[2]) & 128) ? \
669
(((uint32_t) 255L << 24) | \
670
(((uint32_t) (uchar) (A)[2]) << 16) |\
671
(((uint32_t) (uchar) (A)[1]) << 8) | \
672
((uint32_t) (uchar) (A)[0])) : \
673
(((uint32_t) (uchar) (A)[2]) << 16) |\
674
(((uint32_t) (uchar) (A)[1]) << 8) | \
675
((uint32_t) (uchar) (A)[0])))
706
676
#define sint4korr(A) (*((long *) (A)))
707
#define uint2korr(A) (*((uint16 *) (A)))
677
#define uint2korr(A) (*((uint16_t *) (A)))
708
678
#if defined(HAVE_purify)
709
#define uint3korr(A) (uint32) (((uint32) ((uchar) (A)[0])) +\
710
(((uint32) ((uchar) (A)[1])) << 8) +\
711
(((uint32) ((uchar) (A)[2])) << 16))
679
#define uint3korr(A) (uint32_t) (((uint32_t) ((uchar) (A)[0])) +\
680
(((uint32_t) ((uchar) (A)[1])) << 8) +\
681
(((uint32_t) ((uchar) (A)[2])) << 16))
719
689
#define uint3korr(A) (long) (*((unsigned int *) (A)) & 0xFFFFFF)
720
690
#endif /* HAVE_purify */
721
#define uint4korr(A) (*((uint32 *) (A)))
722
#define uint5korr(A) ((uint64_t)(((uint32) ((uchar) (A)[0])) +\
723
(((uint32) ((uchar) (A)[1])) << 8) +\
724
(((uint32) ((uchar) (A)[2])) << 16) +\
725
(((uint32) ((uchar) (A)[3])) << 24)) +\
691
#define uint4korr(A) (*((uint32_t *) (A)))
692
#define uint5korr(A) ((uint64_t)(((uint32_t) ((uchar) (A)[0])) +\
693
(((uint32_t) ((uchar) (A)[1])) << 8) +\
694
(((uint32_t) ((uchar) (A)[2])) << 16) +\
695
(((uint32_t) ((uchar) (A)[3])) << 24)) +\
726
696
(((uint64_t) ((uchar) (A)[4])) << 32))
727
#define uint6korr(A) ((uint64_t)(((uint32) ((uchar) (A)[0])) + \
728
(((uint32) ((uchar) (A)[1])) << 8) + \
729
(((uint32) ((uchar) (A)[2])) << 16) + \
730
(((uint32) ((uchar) (A)[3])) << 24)) + \
697
#define uint6korr(A) ((uint64_t)(((uint32_t) ((uchar) (A)[0])) + \
698
(((uint32_t) ((uchar) (A)[1])) << 8) + \
699
(((uint32_t) ((uchar) (A)[2])) << 16) + \
700
(((uint32_t) ((uchar) (A)[3])) << 24)) + \
731
701
(((uint64_t) ((uchar) (A)[4])) << 32) + \
732
702
(((uint64_t) ((uchar) (A)[5])) << 40))
733
703
#define uint8korr(A) (*((uint64_t *) (A)))
734
704
#define sint8korr(A) (*((int64_t *) (A)))
735
#define int2store(T,A) *((uint16*) (T))= (uint16) (A)
705
#define int2store(T,A) *((uint16_t*) (T))= (uint16_t) (A)
736
706
#define int3store(T,A) do { *(T)= (uchar) ((A));\
737
707
*(T+1)=(uchar) (((uint) (A) >> 8));\
738
708
*(T+2)=(uchar) (((A) >> 16)); } while (0)
774
744
We're here if it's not a IA-32 architecture (Win32 and UNIX IA-32 defines
775
745
were done before)
777
#define sint2korr(A) (int16) (((int16) ((uchar) (A)[0])) +\
778
((int16) ((int16) (A)[1]) << 8))
779
#define sint3korr(A) ((int32) ((((uchar) (A)[2]) & 128) ? \
780
(((uint32) 255L << 24) | \
781
(((uint32) (uchar) (A)[2]) << 16) |\
782
(((uint32) (uchar) (A)[1]) << 8) | \
783
((uint32) (uchar) (A)[0])) : \
784
(((uint32) (uchar) (A)[2]) << 16) |\
785
(((uint32) (uchar) (A)[1]) << 8) | \
786
((uint32) (uchar) (A)[0])))
787
#define sint4korr(A) (int32) (((int32) ((uchar) (A)[0])) +\
788
(((int32) ((uchar) (A)[1]) << 8)) +\
789
(((int32) ((uchar) (A)[2]) << 16)) +\
790
(((int32) ((int16) (A)[3]) << 24)))
747
#define sint2korr(A) (int16_t) (((int16_t) ((uchar) (A)[0])) +\
748
((int16_t) ((int16_t) (A)[1]) << 8))
749
#define sint3korr(A) ((int32_t) ((((uchar) (A)[2]) & 128) ? \
750
(((uint32_t) 255L << 24) | \
751
(((uint32_t) (uchar) (A)[2]) << 16) |\
752
(((uint32_t) (uchar) (A)[1]) << 8) | \
753
((uint32_t) (uchar) (A)[0])) : \
754
(((uint32_t) (uchar) (A)[2]) << 16) |\
755
(((uint32_t) (uchar) (A)[1]) << 8) | \
756
((uint32_t) (uchar) (A)[0])))
757
#define sint4korr(A) (int32_t) (((int32_t) ((uchar) (A)[0])) +\
758
(((int32_t) ((uchar) (A)[1]) << 8)) +\
759
(((int32_t) ((uchar) (A)[2]) << 16)) +\
760
(((int32_t) ((int16_t) (A)[3]) << 24)))
791
761
#define sint8korr(A) (int64_t) uint8korr(A)
792
#define uint2korr(A) (uint16) (((uint16) ((uchar) (A)[0])) +\
793
((uint16) ((uchar) (A)[1]) << 8))
794
#define uint3korr(A) (uint32) (((uint32) ((uchar) (A)[0])) +\
795
(((uint32) ((uchar) (A)[1])) << 8) +\
796
(((uint32) ((uchar) (A)[2])) << 16))
797
#define uint4korr(A) (uint32) (((uint32) ((uchar) (A)[0])) +\
798
(((uint32) ((uchar) (A)[1])) << 8) +\
799
(((uint32) ((uchar) (A)[2])) << 16) +\
800
(((uint32) ((uchar) (A)[3])) << 24))
801
#define uint5korr(A) ((uint64_t)(((uint32) ((uchar) (A)[0])) +\
802
(((uint32) ((uchar) (A)[1])) << 8) +\
803
(((uint32) ((uchar) (A)[2])) << 16) +\
804
(((uint32) ((uchar) (A)[3])) << 24)) +\
762
#define uint2korr(A) (uint16_t) (((uint16_t) ((uchar) (A)[0])) +\
763
((uint16_t) ((uchar) (A)[1]) << 8))
764
#define uint3korr(A) (uint32_t) (((uint32_t) ((uchar) (A)[0])) +\
765
(((uint32_t) ((uchar) (A)[1])) << 8) +\
766
(((uint32_t) ((uchar) (A)[2])) << 16))
767
#define uint4korr(A) (uint32_t) (((uint32_t) ((uchar) (A)[0])) +\
768
(((uint32_t) ((uchar) (A)[1])) << 8) +\
769
(((uint32_t) ((uchar) (A)[2])) << 16) +\
770
(((uint32_t) ((uchar) (A)[3])) << 24))
771
#define uint5korr(A) ((uint64_t)(((uint32_t) ((uchar) (A)[0])) +\
772
(((uint32_t) ((uchar) (A)[1])) << 8) +\
773
(((uint32_t) ((uchar) (A)[2])) << 16) +\
774
(((uint32_t) ((uchar) (A)[3])) << 24)) +\
805
775
(((uint64_t) ((uchar) (A)[4])) << 32))
806
#define uint6korr(A) ((uint64_t)(((uint32) ((uchar) (A)[0])) + \
807
(((uint32) ((uchar) (A)[1])) << 8) + \
808
(((uint32) ((uchar) (A)[2])) << 16) + \
809
(((uint32) ((uchar) (A)[3])) << 24)) + \
776
#define uint6korr(A) ((uint64_t)(((uint32_t) ((uchar) (A)[0])) + \
777
(((uint32_t) ((uchar) (A)[1])) << 8) + \
778
(((uint32_t) ((uchar) (A)[2])) << 16) + \
779
(((uint32_t) ((uchar) (A)[3])) << 24)) + \
810
780
(((uint64_t) ((uchar) (A)[4])) << 32) + \
811
781
(((uint64_t) ((uchar) (A)[5])) << 40))
812
#define uint8korr(A) ((uint64_t)(((uint32) ((uchar) (A)[0])) +\
813
(((uint32) ((uchar) (A)[1])) << 8) +\
814
(((uint32) ((uchar) (A)[2])) << 16) +\
815
(((uint32) ((uchar) (A)[3])) << 24)) +\
816
(((uint64_t) (((uint32) ((uchar) (A)[4])) +\
817
(((uint32) ((uchar) (A)[5])) << 8) +\
818
(((uint32) ((uchar) (A)[6])) << 16) +\
819
(((uint32) ((uchar) (A)[7])) << 24))) <<\
782
#define uint8korr(A) ((uint64_t)(((uint32_t) ((uchar) (A)[0])) +\
783
(((uint32_t) ((uchar) (A)[1])) << 8) +\
784
(((uint32_t) ((uchar) (A)[2])) << 16) +\
785
(((uint32_t) ((uchar) (A)[3])) << 24)) +\
786
(((uint64_t) (((uint32_t) ((uchar) (A)[4])) +\
787
(((uint32_t) ((uchar) (A)[5])) << 8) +\
788
(((uint32_t) ((uchar) (A)[6])) << 16) +\
789
(((uint32_t) ((uchar) (A)[7])) << 24))) <<\
821
791
#define int2store(T,A) do { uint def_temp= (uint) (A) ;\
822
792
*((uchar*) (T))= (uchar)(def_temp); \
879
849
((uchar*) &def_temp)[7]=(M)[0];\
880
850
(V) = def_temp; } while(0)
882
#define float4get(V,M) memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(float))
883
#define float4store(V,M) memcpy_fixed((uchar*) V,(uchar*) (&M),sizeof(float))
852
#define float4get(V,M) memcpy((uchar*) &V,(uchar*) (M),sizeof(float))
853
#define float4store(V,M) memcpy((uchar*) V,(uchar*) (&M),sizeof(float))
885
855
#if defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN)
886
856
#define doublestore(T,V) do { *(((char*)T)+0)=(char) ((uchar *) &V)[4];\
927
897
#ifdef WORDS_BIGENDIAN
929
#define ushortget(V,M) do { V = (uint16) (((uint16) ((uchar) (M)[1]))+\
930
((uint16) ((uint16) (M)[0]) << 8)); } while(0)
899
#define ushortget(V,M) do { V = (uint16_t) (((uint16_t) ((uchar) (M)[1]))+\
900
((uint16_t) ((uint16_t) (M)[0]) << 8)); } while(0)
931
901
#define shortget(V,M) do { V = (short) (((short) ((uchar) (M)[1]))+\
932
902
((short) ((short) (M)[0]) << 8)); } while(0)
933
#define longget(V,M) do { int32 def_temp;\
903
#define longget(V,M) do { int32_t def_temp;\
934
904
((uchar*) &def_temp)[0]=(M)[0];\
935
905
((uchar*) &def_temp)[1]=(M)[1];\
936
906
((uchar*) &def_temp)[2]=(M)[2];\
937
907
((uchar*) &def_temp)[3]=(M)[3];\
938
908
(V)=def_temp; } while(0)
939
#define ulongget(V,M) do { uint32 def_temp;\
909
#define ulongget(V,M) do { uint32_t def_temp;\
940
910
((uchar*) &def_temp)[0]=(M)[0];\
941
911
((uchar*) &def_temp)[1]=(M)[1];\
942
912
((uchar*) &def_temp)[2]=(M)[2];\
950
920
*(((char*)T)+1)=(((A) >> 16));\
951
921
*(((char*)T)+0)=(((A) >> 24)); } while(0)
953
#define floatget(V,M) memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(float))
954
#define floatstore(T,V) memcpy_fixed((uchar*) (T),(uchar*)(&V),sizeof(float))
955
#define doubleget(V,M) memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(double))
956
#define doublestore(T,V) memcpy_fixed((uchar*) (T),(uchar*) &V,sizeof(double))
957
#define int64_tget(V,M) memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(uint64_t))
958
#define int64_tstore(T,V) memcpy_fixed((uchar*) (T),(uchar*) &V,sizeof(uint64_t))
923
#define floatget(V,M) memcpy((uchar*) &V,(uchar*) (M), sizeof(float))
924
#define floatstore(T,V) memcpy((uchar*) (T),(uchar*)(&V), sizeof(float))
925
#define doubleget(V,M) memcpy((uchar*) &V,(uchar*) (M), sizeof(double))
926
#define doublestore(T,V) memcpy((uchar*) (T),(uchar*) &V, sizeof(double))
927
#define int64_tget(V,M) memcpy((uchar*) &V,(uchar*) (M), sizeof(uint64_t))
928
#define int64_tstore(T,V) memcpy((uchar*) (T),(uchar*) &V, sizeof(uint64_t))
966
936
#define shortstore(T,V) int2store(T,V)
967
937
#define longstore(T,V) int4store(T,V)
968
938
#ifndef floatstore
969
#define floatstore(T,V) memcpy_fixed((uchar*) (T),(uchar*) (&V),sizeof(float))
970
#define floatget(V,M) memcpy_fixed((uchar*) &V, (uchar*) (M), sizeof(float))
939
#define floatstore(T,V) memcpy((uchar*) (T),(uchar*) (&V),sizeof(float))
940
#define floatget(V,M) memcpy((uchar*) &V, (uchar*) (M), sizeof(float))
972
942
#ifndef doubleget
973
#define doubleget(V,M) memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(double))
974
#define doublestore(T,V) memcpy_fixed((uchar*) (T),(uchar*) &V,sizeof(double))
943
#define doubleget(V,M) memcpy((uchar*) &V,(uchar*) (M),sizeof(double))
944
#define doublestore(T,V) memcpy((uchar*) (T),(uchar*) &V,sizeof(double))
975
945
#endif /* doubleget */
976
#define int64_tget(V,M) memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(uint64_t))
977
#define int64_tstore(T,V) memcpy_fixed((uchar*) (T),(uchar*) &V,sizeof(uint64_t))
946
#define int64_tget(V,M) memcpy((uchar*) &V,(uchar*) (M),sizeof(uint64_t))
947
#define int64_tstore(T,V) memcpy((uchar*) (T),(uchar*) &V,sizeof(uint64_t))
979
949
#endif /* WORDS_BIGENDIAN */