Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
crc32.c File Reference
#include "zutil.h"
#include "crc32.h"

Go to the source code of this file.

Macros

#define N   5
#define W   4
#define POLY   0xedb88320 /* p(x) reflected, with x^32 implied */

Functions

local z_crc_t multmodp (z_crc_t a, z_crc_t b)
local z_crc_t x2nmodp (z_off64_t n, unsigned k)
const z_crc_t FAR *ZEXPORT get_crc_table (void)
unsigned long ZEXPORT crc32_z (unsigned long crc, const unsigned char FAR *buf, z_size_t len)
unsigned long ZEXPORT crc32 (unsigned long crc, const unsigned char FAR *buf, uInt len)
uLong ZEXPORT crc32_combine64 (uLong crc1, uLong crc2, z_off64_t len2)
uLong ZEXPORT crc32_combine (uLong crc1, uLong crc2, z_off_t len2)
uLong ZEXPORT crc32_combine_gen64 (z_off64_t len2)
uLong ZEXPORT crc32_combine_gen (z_off_t len2)
uLong ZEXPORT crc32_combine_op (uLong crc1, uLong crc2, uLong op)

Macro Definition Documentation

◆ N

#define N   5

Definition at line 57 of file crc32.c.

Referenced by G4ChargeExchange::ApplyYourself(), G4LFission::ApplyYourself(), G4CascadeFinalStateAlgorithm::BetaKopylov(), G4HadPhaseSpaceKopylov::BetaKopylov(), G4HETCFragment::BetaRand(), G4GNASHTransitions::CalculateProbability(), G4PreCompoundTransitions::CalculateProbability(), G4NeutrinoNucleusModel::CalculateQEratioA(), G4QuasiElRatios::ChExElCoef(), G4QuasiElRatios::ChExer(), G4ComponentGGHadronNucleusXsc::ComputeCrossSections(), G4PhotoNuclearCrossSection::ComputeElementXSection(), crc32_z(), G4FermiPhaseSpaceDecay::Decay(), G4TClassicalRK4< T_Equation, N >::DumbStepper(), G4TExplicitEuler< T_Equation, N >::DumbStepper(), G4TSimpleHeum< T_Equation, N >::DumbStepper(), G4TSimpleRunge< T_Equation, N >::DumbStepper(), G4INCL::HornerEvaluator< M >::eval(), G4INCL::HornerEvaluator< 1 >::eval(), G4PreCompoundAlpha::FactorialFactor(), G4PreCompoundDeuteron::FactorialFactor(), G4PreCompoundHe3::FactorialFactor(), G4PreCompoundIon::FactorialFactor(), G4PreCompoundTriton::FactorialFactor(), G4CascadeFinalStateAlgorithm::FillUsingKopylov(), G4Abla::fissionDistri(), G4ElectroNuclearCrossSection::G4ElectroNuclearCrossSection(), G4GEMChannelVI::G4GEMChannelVI(), G4Isotope::G4Isotope(), G4LevelManager::G4LevelManager(), G4PhotoNuclearCrossSection::G4PhotoNuclearCrossSection(), G4TCashKarpRKF45< T_Equation, N >::G4TCashKarpRKF45(), G4TClassicalRK4< T_Equation, N >::G4TClassicalRK4(), G4TDormandPrince45< T_Equation, N >::G4TDormandPrince45(), G4TDormandPrince45< T_Equation, N >::G4TDormandPrince45(), G4TExplicitEuler< T_Equation, N >::G4TExplicitEuler(), G4TSimpleHeum< T_Equation, N >::G4TSimpleHeum(), G4TSimpleRunge< T_Equation, N >::G4TSimpleRunge(), G4INCL::PhaseSpaceKopylov::generate(), G4HadPhaseSpaceKopylov::GenerateMultiBody(), G4NistElementBuilder::GetAtomicMass(), G4NistManager::GetAtomicMass(), G4ComponentSAIDTotalXS::GetChargeExchangeCrossSection(), G4QuasiElRatios::GetChExFactor(), G4ChipsKaonZeroElasticXS::GetChipsCrossSection(), G4ChipsKaonZeroInelasticXS::GetChipsCrossSection(), G4ChipsComponentXS::GetElasticElementCrossSection(), G4ComponentSAIDTotalXS::GetElasticElementCrossSection(), G4ComponentSAIDTotalXS::GetElasticIsotopeCrossSection(), G4ElectroNuclearCrossSection::GetElementCrossSection(), G4QuasiElRatios::GetElTot(), G4DNADiracRMatrixExcitationModel::GetExtendedTotalCrossSection(), G4PairingCorrection::GetFissionPairingCorrection(), G4Abla::gethyperbinding(), G4PSStepChecker3D::GetIndex(), G4ChipsComponentXS::GetInelasticElementCrossSection(), G4ComponentSAIDTotalXS::GetInelasticElementCrossSection(), G4ComponentSAIDTotalXS::GetInelasticIsotopeCrossSection(), G4ChipsKaonZeroElasticXS::GetIsoCrossSection(), G4ChipsKaonZeroInelasticXS::GetIsoCrossSection(), G4NistElementBuilder::GetIsotopeAbundance(), G4NistManager::GetIsotopeAbundance(), G4NistElementBuilder::GetIsotopeMass(), G4NistManager::GetIsotopeMass(), G4MuonicAtomHelper::GetLinApprox(), G4LightIonQMDNucleus::GetNuclearMass(), G4QMDNucleus::GetNuclearMass(), G4CameronGilbertPairingCorrections::GetPairingCorrection(), G4CameronShellPlusPairingCorrections::GetPairingCorrection(), G4CameronTruranHilfPairingCorrections::GetPairingCorrection(), G4CookPairingCorrections::GetPairingCorrection(), G4PairingCorrection::GetPairingCorrection(), G4CameronGilbertShellCorrections::GetShellCorrection(), G4CameronTruranHilfShellCorrections::GetShellCorrection(), G4CookShellCorrections::GetShellCorrection(), G4ShellCorrection::GetShellCorrection(), G4HETCFragment::GetSpinFactor(), G4DNARelativisticIonisationModel::GetTotalCrossSection(), G4ChipsComponentXS::GetTotalElementCrossSection(), G4ComponentSAIDTotalXS::GetTotalElementCrossSection(), G4ComponentSAIDTotalXS::GetTotalIsotopeCrossSection(), G4FastVector< G4Track, G4TrackFastVectorSize >::Initialize(), G4TDormandPrince45< T_Equation, N >::Interpolate4thOrder(), G4TDormandPrince45< T_Equation, N >::Interpolate5thOrder(), G4GDMLReadMaterials::IsotopeRead(), G4PreCompoundAlpha::operator!=(), G4PreCompoundDeuteron::operator!=(), G4PreCompoundHe3::operator!=(), G4PreCompoundTriton::operator!=(), G4PreCompoundIon::ProbabilityDistributionFunction(), G4PreCompoundNucleon::ProbabilityDistributionFunction(), G4ChipsElasticModel::SampleInvariantT(), G4XrayReflection::SaveHenkeDataAsMaterialProperty(), G4QuasiElRatios::Scatter(), HepTool::Evaluator::setSystemOfUnits(), G4TDormandPrince45< T_Equation, N >::SetupInterpolation5thOrder(), G4TMagErrorStepper< T_Stepper, T_Equation, N >::Stepper(), G4TCashKarpRKF45< T_Equation, N >::StepWithError(), G4TDormandPrince45< T_Equation, N >::StepWithError(), G4TDormandPrince45< T_Equation, N >::StepWithFinalDerivate(), and G4NistElementBuilder::~G4NistElementBuilder().

◆ POLY

#define POLY   0xedb88320 /* p(x) reflected, with x^32 implied */

Definition at line 149 of file crc32.c.

Referenced by multmodp().

◆ W

Function Documentation

◆ crc32()

unsigned long ZEXPORT crc32 ( unsigned long crc,
const unsigned char FAR * buf,
uInt len )

Definition at line 1015 of file crc32.c.

1016 {
1017 return crc32_z(crc, buf, len);
1018}
unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf, z_size_t len)
Definition crc32.c:694

◆ crc32_combine()

uLong ZEXPORT crc32_combine ( uLong crc1,
uLong crc2,
z_off_t len2 )

Definition at line 1029 of file crc32.c.

1029 {
1030 return crc32_combine64(crc1, crc2, (z_off64_t)len2);
1031}
uLong ZEXPORT crc32_combine64(uLong crc1, uLong crc2, z_off64_t len2)
Definition crc32.c:1021

◆ crc32_combine64()

uLong ZEXPORT crc32_combine64 ( uLong crc1,
uLong crc2,
z_off64_t len2 )

Definition at line 1021 of file crc32.c.

1021 {
1022#ifdef DYNAMIC_CRC_TABLE
1023 once(&made, make_crc_table);
1024#endif /* DYNAMIC_CRC_TABLE */
1025 return multmodp(x2nmodp(len2, 3), crc1) ^ (crc2 & 0xffffffff);
1026}
local z_crc_t x2nmodp(z_off64_t n, unsigned k)
Definition crc32.c:176
local z_crc_t multmodp(z_crc_t a, z_crc_t b)
Definition crc32.c:155

Referenced by crc32_combine().

◆ crc32_combine_gen()

uLong ZEXPORT crc32_combine_gen ( z_off_t len2)

Definition at line 1042 of file crc32.c.

1042 {
1043 return crc32_combine_gen64((z_off64_t)len2);
1044}
uLong ZEXPORT crc32_combine_gen64(z_off64_t len2)
Definition crc32.c:1034

◆ crc32_combine_gen64()

uLong ZEXPORT crc32_combine_gen64 ( z_off64_t len2)

Definition at line 1034 of file crc32.c.

1034 {
1035#ifdef DYNAMIC_CRC_TABLE
1036 once(&made, make_crc_table);
1037#endif /* DYNAMIC_CRC_TABLE */
1038 return x2nmodp(len2, 3);
1039}

Referenced by crc32_combine_gen().

◆ crc32_combine_op()

uLong ZEXPORT crc32_combine_op ( uLong crc1,
uLong crc2,
uLong op )

Definition at line 1047 of file crc32.c.

1047 {
1048 return multmodp(op, crc1) ^ (crc2 & 0xffffffff);
1049}

◆ crc32_z()

unsigned long ZEXPORT crc32_z ( unsigned long crc,
const unsigned char FAR * buf,
z_size_t len )

Definition at line 694 of file crc32.c.

695 {
696 /* Return initial CRC, if requested. */
697 if (buf == Z_NULL) return 0;
698
699#ifdef DYNAMIC_CRC_TABLE
700 once(&made, make_crc_table);
701#endif /* DYNAMIC_CRC_TABLE */
702
703 /* Pre-condition the CRC */
704 crc = (~crc) & 0xffffffff;
705
706#ifdef W
707
708 /* If provided enough bytes, do a braided CRC calculation. */
709 if (len >= N * W + W - 1) {
710 z_size_t blks;
711 z_word_t const *words;
712 unsigned endian;
713 int k;
714
715 /* Compute the CRC up to a z_word_t boundary. */
716 while (len && ((z_size_t)buf & (W - 1)) != 0) {
717 len--;
718 crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
719 }
720
721 /* Compute the CRC on as many N z_word_t blocks as are available. */
722 blks = len / (N * W);
723 len -= blks * N * W;
724 words = (z_word_t const *)buf;
725
726 /* Do endian check at execution time instead of compile time, since ARM
727 processors can change the endianness at execution time. If the
728 compiler knows what the endianness will be, it can optimize out the
729 check and the unused branch. */
730 endian = 1;
731 if (*(unsigned char *)&endian) {
732 /* Little endian. */
733
734 z_crc_t crc0;
735 z_word_t word0;
736#if N > 1
737 z_crc_t crc1;
738 z_word_t word1;
739#if N > 2
740 z_crc_t crc2;
741 z_word_t word2;
742#if N > 3
743 z_crc_t crc3;
744 z_word_t word3;
745#if N > 4
746 z_crc_t crc4;
747 z_word_t word4;
748#if N > 5
749 z_crc_t crc5;
750 z_word_t word5;
751#endif
752#endif
753#endif
754#endif
755#endif
756
757 /* Initialize the CRC for each braid. */
758 crc0 = crc;
759#if N > 1
760 crc1 = 0;
761#if N > 2
762 crc2 = 0;
763#if N > 3
764 crc3 = 0;
765#if N > 4
766 crc4 = 0;
767#if N > 5
768 crc5 = 0;
769#endif
770#endif
771#endif
772#endif
773#endif
774
775 /*
776 Process the first blks-1 blocks, computing the CRCs on each braid
777 independently.
778 */
779 while (--blks) {
780 /* Load the word for each braid into registers. */
781 word0 = crc0 ^ words[0];
782#if N > 1
783 word1 = crc1 ^ words[1];
784#if N > 2
785 word2 = crc2 ^ words[2];
786#if N > 3
787 word3 = crc3 ^ words[3];
788#if N > 4
789 word4 = crc4 ^ words[4];
790#if N > 5
791 word5 = crc5 ^ words[5];
792#endif
793#endif
794#endif
795#endif
796#endif
797 words += N;
798
799 /* Compute and update the CRC for each word. The loop should
800 get unrolled. */
801 crc0 = crc_braid_table[0][word0 & 0xff];
802#if N > 1
803 crc1 = crc_braid_table[0][word1 & 0xff];
804#if N > 2
805 crc2 = crc_braid_table[0][word2 & 0xff];
806#if N > 3
807 crc3 = crc_braid_table[0][word3 & 0xff];
808#if N > 4
809 crc4 = crc_braid_table[0][word4 & 0xff];
810#if N > 5
811 crc5 = crc_braid_table[0][word5 & 0xff];
812#endif
813#endif
814#endif
815#endif
816#endif
817 for (k = 1; k < W; k++) {
818 crc0 ^= crc_braid_table[k][(word0 >> (k << 3)) & 0xff];
819#if N > 1
820 crc1 ^= crc_braid_table[k][(word1 >> (k << 3)) & 0xff];
821#if N > 2
822 crc2 ^= crc_braid_table[k][(word2 >> (k << 3)) & 0xff];
823#if N > 3
824 crc3 ^= crc_braid_table[k][(word3 >> (k << 3)) & 0xff];
825#if N > 4
826 crc4 ^= crc_braid_table[k][(word4 >> (k << 3)) & 0xff];
827#if N > 5
828 crc5 ^= crc_braid_table[k][(word5 >> (k << 3)) & 0xff];
829#endif
830#endif
831#endif
832#endif
833#endif
834 }
835 }
836
837 /*
838 Process the last block, combining the CRCs of the N braids at the
839 same time.
840 */
841 crc = crc_word(crc0 ^ words[0]);
842#if N > 1
843 crc = crc_word(crc1 ^ words[1] ^ crc);
844#if N > 2
845 crc = crc_word(crc2 ^ words[2] ^ crc);
846#if N > 3
847 crc = crc_word(crc3 ^ words[3] ^ crc);
848#if N > 4
849 crc = crc_word(crc4 ^ words[4] ^ crc);
850#if N > 5
851 crc = crc_word(crc5 ^ words[5] ^ crc);
852#endif
853#endif
854#endif
855#endif
856#endif
857 words += N;
858 }
859 else {
860 /* Big endian. */
861
862 z_word_t crc0, word0, comb;
863#if N > 1
864 z_word_t crc1, word1;
865#if N > 2
866 z_word_t crc2, word2;
867#if N > 3
868 z_word_t crc3, word3;
869#if N > 4
870 z_word_t crc4, word4;
871#if N > 5
872 z_word_t crc5, word5;
873#endif
874#endif
875#endif
876#endif
877#endif
878
879 /* Initialize the CRC for each braid. */
880 crc0 = byte_swap(crc);
881#if N > 1
882 crc1 = 0;
883#if N > 2
884 crc2 = 0;
885#if N > 3
886 crc3 = 0;
887#if N > 4
888 crc4 = 0;
889#if N > 5
890 crc5 = 0;
891#endif
892#endif
893#endif
894#endif
895#endif
896
897 /*
898 Process the first blks-1 blocks, computing the CRCs on each braid
899 independently.
900 */
901 while (--blks) {
902 /* Load the word for each braid into registers. */
903 word0 = crc0 ^ words[0];
904#if N > 1
905 word1 = crc1 ^ words[1];
906#if N > 2
907 word2 = crc2 ^ words[2];
908#if N > 3
909 word3 = crc3 ^ words[3];
910#if N > 4
911 word4 = crc4 ^ words[4];
912#if N > 5
913 word5 = crc5 ^ words[5];
914#endif
915#endif
916#endif
917#endif
918#endif
919 words += N;
920
921 /* Compute and update the CRC for each word. The loop should
922 get unrolled. */
923 crc0 = crc_braid_big_table[0][word0 & 0xff];
924#if N > 1
925 crc1 = crc_braid_big_table[0][word1 & 0xff];
926#if N > 2
927 crc2 = crc_braid_big_table[0][word2 & 0xff];
928#if N > 3
929 crc3 = crc_braid_big_table[0][word3 & 0xff];
930#if N > 4
931 crc4 = crc_braid_big_table[0][word4 & 0xff];
932#if N > 5
933 crc5 = crc_braid_big_table[0][word5 & 0xff];
934#endif
935#endif
936#endif
937#endif
938#endif
939 for (k = 1; k < W; k++) {
940 crc0 ^= crc_braid_big_table[k][(word0 >> (k << 3)) & 0xff];
941#if N > 1
942 crc1 ^= crc_braid_big_table[k][(word1 >> (k << 3)) & 0xff];
943#if N > 2
944 crc2 ^= crc_braid_big_table[k][(word2 >> (k << 3)) & 0xff];
945#if N > 3
946 crc3 ^= crc_braid_big_table[k][(word3 >> (k << 3)) & 0xff];
947#if N > 4
948 crc4 ^= crc_braid_big_table[k][(word4 >> (k << 3)) & 0xff];
949#if N > 5
950 crc5 ^= crc_braid_big_table[k][(word5 >> (k << 3)) & 0xff];
951#endif
952#endif
953#endif
954#endif
955#endif
956 }
957 }
958
959 /*
960 Process the last block, combining the CRCs of the N braids at the
961 same time.
962 */
963 comb = crc_word_big(crc0 ^ words[0]);
964#if N > 1
965 comb = crc_word_big(crc1 ^ words[1] ^ comb);
966#if N > 2
967 comb = crc_word_big(crc2 ^ words[2] ^ comb);
968#if N > 3
969 comb = crc_word_big(crc3 ^ words[3] ^ comb);
970#if N > 4
971 comb = crc_word_big(crc4 ^ words[4] ^ comb);
972#if N > 5
973 comb = crc_word_big(crc5 ^ words[5] ^ comb);
974#endif
975#endif
976#endif
977#endif
978#endif
979 words += N;
980 crc = byte_swap(comb);
981 }
982
983 /*
984 Update the pointer to the remaining bytes to process.
985 */
986 buf = (unsigned char const *)words;
987 }
988
989#endif /* W */
990
991 /* Complete the computation of the CRC on any remaining bytes. */
992 while (len >= 8) {
993 len -= 8;
994 crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
995 crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
996 crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
997 crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
998 crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
999 crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
1000 crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
1001 crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
1002 }
1003 while (len) {
1004 len--;
1005 crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
1006 }
1007
1008 /* Return the CRC, post-conditioned. */
1009 return crc ^ 0xffffffff;
1010}
#define N
Definition crc32.c:57
#define W
Definition crc32.c:85
local const z_crc_t FAR crc_table[]
Definition crc32.h:5
#define Z_NULL
Definition zlib.h:212

Referenced by crc32().

◆ get_crc_table()

const z_crc_t FAR *ZEXPORT get_crc_table ( void )

Definition at line 549 of file crc32.c.

549 {
550#ifdef DYNAMIC_CRC_TABLE
551 once(&made, make_crc_table);
552#endif /* DYNAMIC_CRC_TABLE */
553 return (const z_crc_t FAR *)crc_table;
554}

◆ multmodp()

local z_crc_t multmodp ( z_crc_t a,
z_crc_t b )

Definition at line 155 of file crc32.c.

155 {
156 z_crc_t m, p;
157
158 m = (z_crc_t)1 << 31;
159 p = 0;
160 for (;;) {
161 if (a & m) {
162 p ^= b;
163 if ((a & (m - 1)) == 0)
164 break;
165 }
166 m >>= 1;
167 b = b & 1 ? (b >> 1) ^ POLY : b >> 1;
168 }
169 return p;
170}
#define POLY
Definition crc32.c:149

Referenced by crc32_combine64(), crc32_combine_op(), and x2nmodp().

◆ x2nmodp()

local z_crc_t x2nmodp ( z_off64_t n,
unsigned k )

Definition at line 176 of file crc32.c.

176 {
177 z_crc_t p;
178
179 p = (z_crc_t)1 << 31; /* x^0 == 1 */
180 while (n) {
181 if (n & 1)
182 p = multmodp(x2n_table[k & 31], p);
183 n >>= 1;
184 k++;
185 }
186 return p;
187}
local const z_crc_t FAR x2n_table[]
Definition crc32.h:9439

Referenced by crc32_combine64(), and crc32_combine_gen64().