@@ -168,15 +168,13 @@ PHPAPI zend_class_entry *random_ce_Random_Engine_CombinedLCG;
168
168
PHPAPI zend_class_entry * random_ce_Random_Engine_MersenneTwister ;
169
169
PHPAPI zend_class_entry * random_ce_Random_Engine_PCG64 ;
170
170
PHPAPI zend_class_entry * random_ce_Random_Engine_Secure ;
171
- PHPAPI zend_class_entry * random_ce_Random_Engine_XorShift128Plus ;
172
171
PHPAPI zend_class_entry * random_ce_Random_Engine_Xoshiro256StarStar ;
173
172
PHPAPI zend_class_entry * random_ce_Random_Randomizer ;
174
173
175
174
static zend_object_handlers random_engine_combinedlcg_object_handlers ;
176
175
static zend_object_handlers random_engine_mersennetwister_object_handlers ;
177
176
static zend_object_handlers random_engine_pcg64_object_handlers ;
178
177
static zend_object_handlers random_engine_secure_object_handlers ;
179
- static zend_object_handlers random_engine_xorshift128plus_object_handlers ;
180
178
static zend_object_handlers random_engine_xoshiro256starstar_object_handlers ;
181
179
static zend_object_handlers random_randomizer_object_handlers ;
182
180
@@ -768,80 +766,6 @@ const php_random_engine_algo php_random_engine_algo_user = {
768
766
769
767
/* User end */
770
768
771
- /* XorShift128Plus begin */
772
-
773
- static inline size_t xorshift128plus_dynamic_generate_size (void * state ) {
774
- return sizeof (uint64_t );
775
- }
776
-
777
- static uint64_t xorshift128plus_generate (void * state , bool * engine_unsafe ) {
778
- php_random_engine_state_xorshift128plus * s = state ;
779
- uint64_t s0 , s1 , r ;
780
-
781
- s1 = s -> s [0 ];
782
- s0 = s -> s [1 ];
783
- r = s0 + s1 ;
784
- s -> s [0 ] = s0 ;
785
- s1 ^= s1 << 23 ;
786
- s -> s [1 ] = s1 ^ s0 ^ (s1 >> 18 ) ^ (s0 >> 5 );
787
-
788
- return r ;
789
- }
790
-
791
- static void xorshift128plus_seed (void * state , const uint64_t seed ) {
792
- php_random_engine_state_xorshift128plus * s = state ;
793
- uint64_t sd = seed ;
794
-
795
- s -> s [0 ] = splitmix64 (& sd );
796
- s -> s [1 ] = splitmix64 (& sd );
797
- }
798
-
799
- static int xorshift128plus_serialize (void * state , HashTable * data ) {
800
- php_random_engine_state_xorshift128plus * s = state ;
801
- zval tmp ;
802
- int i ;
803
-
804
- for (i = 0 ; i < 2 ; i ++ ) {
805
- ZVAL_STR (& tmp , zend_strpprintf (0 , "%" PRIu64 , s -> s [i ]));
806
- zend_hash_next_index_insert (data , & tmp );
807
- }
808
-
809
- return SUCCESS ;
810
- }
811
-
812
- static int xorshift128plus_unserialize (void * state , HashTable * data ) {
813
- php_random_engine_state_xorshift128plus * s = state ;
814
- zval * tmp ;
815
- int i ;
816
-
817
- for (i = 0 ; i < 2 ; i ++ ) {
818
- tmp = zend_hash_index_find (data , i );
819
- if (!tmp || Z_TYPE_P (tmp ) != IS_STRING ) {
820
- return FAILURE ;
821
- }
822
-
823
- s -> s [i ] = strtoull (ZSTR_VAL (Z_STR_P (tmp )), NULL , 10 );
824
- }
825
-
826
- return SUCCESS ;
827
- }
828
-
829
- static zend_object * php_random_engine_xorshift128plus_new (zend_class_entry * ce ) {
830
- return php_random_engine_common_init (ce , & php_random_engine_algo_xorshift128plus , & random_engine_xorshift128plus_object_handlers );
831
- }
832
-
833
- const php_random_engine_algo php_random_engine_algo_xorshift128plus = {
834
- sizeof (uint64_t ),
835
- xorshift128plus_dynamic_generate_size ,
836
- sizeof (php_random_engine_state_xorshift128plus ),
837
- xorshift128plus_generate ,
838
- xorshift128plus_seed ,
839
- xorshift128plus_serialize ,
840
- xorshift128plus_unserialize
841
- };
842
-
843
- /* XorShift128Plus end */
844
-
845
769
/* Xoshiro256StarStar start */
846
770
847
771
static inline size_t xoshiro256starstar_dynamic_generate_size (void * state ) {
@@ -1642,76 +1566,6 @@ PHP_METHOD(Random_Engine_PCG64, jump)
1642
1566
}
1643
1567
/* }}} */
1644
1568
1645
- /* {{{ Construct object */
1646
- PHP_METHOD (Random_Engine_XorShift128Plus , __construct )
1647
- {
1648
- php_random_engine * engine = Z_RANDOM_ENGINE_P (ZEND_THIS );
1649
- php_random_engine_state_xorshift128plus * state = engine -> state ;
1650
- zend_string * str_seed = NULL ;
1651
- zend_long int_seed = 0 ;
1652
- bool seed_is_null = true;
1653
- int i , j ;
1654
-
1655
- ZEND_PARSE_PARAMETERS_START (0 , 1 )
1656
- Z_PARAM_OPTIONAL ;
1657
- Z_PARAM_STR_OR_LONG_OR_NULL (str_seed , int_seed , seed_is_null );
1658
- ZEND_PARSE_PARAMETERS_END ();
1659
-
1660
- if (seed_is_null ) {
1661
- for (i = 0 ; i < 2 ; i ++ ) {
1662
- if (php_random_bytes_silent (& state -> s [i ], sizeof (uint64_t )) == FAILURE ) {
1663
- zend_throw_exception (spl_ce_RuntimeException , "Random number generate failed" , 0 );
1664
- RETURN_THROWS ();
1665
- }
1666
- }
1667
- } else {
1668
- if (str_seed ) {
1669
- /* char (8 bit) * 16 = 128 bits */
1670
- if (ZSTR_LEN (str_seed ) == 16 ) {
1671
- /* Endianness safe copy */
1672
- for (i = 0 ; i < 2 ; i ++ ) {
1673
- state -> s [i ] = 0 ;
1674
- for (j = 0 ; j < 8 ; j ++ ) {
1675
- state -> s [i ] += ((uint64_t ) (unsigned char ) ZSTR_VAL (str_seed )[(i * 8 ) + j ]) << (j * 8 );
1676
- }
1677
- }
1678
- } else {
1679
- zend_argument_value_error (1 , "state strings must be 16 bytes" );
1680
- RETURN_THROWS ();
1681
- }
1682
- } else {
1683
- engine -> algo -> seed (state , int_seed );
1684
- }
1685
- }
1686
- }
1687
- /* }}} */
1688
-
1689
- /* {{{ Jump a state */
1690
- PHP_METHOD (Random_Engine_XorShift128Plus , jump )
1691
- {
1692
- php_random_engine * engine = Z_RANDOM_ENGINE_P (ZEND_THIS );
1693
- php_random_engine_state_xorshift128plus * s = engine -> state ;
1694
- static const uint64_t jmp [] = { 0x8a5cd789635d2dff , 0x121fd2155c472f96 };
1695
- uint64_t s0 = 0 , s1 = 0 ;
1696
- int i , j ;
1697
-
1698
- ZEND_PARSE_PARAMETERS_NONE ();
1699
-
1700
- for (i = 0 ; i < sizeof (jmp ) / sizeof (* jmp ); i ++ ) {
1701
- for (j = 0 ; j < 64 ; j ++ ) {
1702
- if (jmp [i ] & 1ULL << j ) {
1703
- s0 ^= s -> s [0 ];
1704
- s1 ^= s -> s [1 ];
1705
- }
1706
- engine -> algo -> generate (engine -> state , NULL );
1707
- }
1708
- }
1709
-
1710
- s -> s [0 ] = s0 ;
1711
- s -> s [1 ] = s1 ;
1712
- }
1713
- /* }}} */
1714
-
1715
1569
/* {{{ Construct object */
1716
1570
PHP_METHOD (Random_Engine_Xoshiro256StarStar , __construct )
1717
1571
{
@@ -2060,15 +1914,7 @@ PHP_MINIT_FUNCTION(random)
2060
1914
random_engine_secure_object_handlers .offset = XtOffsetOf (php_random_engine , std );
2061
1915
random_engine_secure_object_handlers .free_obj = php_random_engine_common_free_obj ;
2062
1916
random_engine_secure_object_handlers .clone_obj = NULL ;
2063
-
2064
- /* Random\Engine\XorShift128Plus */
2065
- random_ce_Random_Engine_XorShift128Plus = register_class_Random_Engine_XorShift128Plus (random_ce_Random_SeedableEngine , random_ce_Random_SerializableEngine );
2066
- random_ce_Random_Engine_XorShift128Plus -> create_object = php_random_engine_xorshift128plus_new ;
2067
- memcpy (& random_engine_xorshift128plus_object_handlers , zend_get_std_object_handlers (), sizeof (zend_object_handlers ));
2068
- random_engine_xorshift128plus_object_handlers .offset = XtOffsetOf (php_random_engine , std );
2069
- random_engine_xorshift128plus_object_handlers .free_obj = php_random_engine_common_free_obj ;
2070
- random_engine_xorshift128plus_object_handlers .clone_obj = php_random_engine_common_clone_obj ;
2071
-
1917
+
2072
1918
/* Random\Engine\Xoshiro256StarStar */
2073
1919
random_ce_Random_Engine_Xoshiro256StarStar = register_class_Random_Engine_Xoshiro256StarStar (random_ce_Random_SeedableEngine , random_ce_Random_SerializableEngine );
2074
1920
random_ce_Random_Engine_Xoshiro256StarStar -> create_object = php_random_engine_xoshiro256starstar_new ;
0 commit comments