File tree 5 files changed +136
-67
lines changed
5 files changed +136
-67
lines changed Original file line number Diff line number Diff line change @@ -1033,15 +1033,18 @@ export namespace NativeMath {
1033
1033
}
1034
1034
1035
1035
export function seedRandom ( value : i64 ) : void {
1036
- assert ( value ) ;
1037
1036
random_seeded = true ;
1038
1037
random_state0_64 = murmurHash3 ( value ) ;
1039
1038
random_state1_64 = murmurHash3 ( ~ random_state0_64 ) ;
1040
1039
random_state0_32 = splitMix32 ( < u32 > value ) ;
1041
1040
random_state1_32 = splitMix32 ( random_state0_32 ) ;
1041
+ assert (
1042
+ random_state0_64 != 0 && random_state1_64 != 0 &&
1043
+ random_state0_32 != 0 && random_state1_32 != 0
1044
+ ) ;
1042
1045
}
1043
1046
1044
- export function random ( ) : f64 { // see: v8/src/base/random-number-generator.cc
1047
+ export function random ( ) : f64 { // see: v8/src/base/utils/ random-number-generator.cc
1045
1048
if ( ! random_seeded ) throw new Error ( "PRNG must be seeded." ) ;
1046
1049
var s1 = random_state0_64 ;
1047
1050
var s0 = random_state1_64 ;
@@ -1051,7 +1054,7 @@ export namespace NativeMath {
1051
1054
s1 ^= s0 ;
1052
1055
s1 ^= s0 >> 26 ;
1053
1056
random_state1_64 = s1 ;
1054
- var r = ( ( s0 + s1 ) & 0x000FFFFFFFFFFFFF ) | 0x3FF0000000000000 ;
1057
+ var r = ( s0 >> 12 ) | 0x3FF0000000000000 ;
1055
1058
return reinterpret < f64 > ( r ) - 1 ;
1056
1059
}
1057
1060
Original file line number Diff line number Diff line change 4151
4151
i32.xor
4152
4152
)
4153
4153
(func $~lib/math/NativeMath.seedRandom (; 97 ;) (type $FUNCSIG$vj ) (param $0 i64 )
4154
- local.get $0
4155
- i64.eqz
4156
- if
4157
- i32.const 0
4158
- i32.const 3160
4159
- i32.const 1036
4160
- i32.const 4
4161
- call $~lib/builtins/abort
4162
- unreachable
4163
- end
4164
4154
i32.const 1
4165
4155
global.set $~lib/math/random_seeded
4166
4156
local.get $0
4178
4168
global.get $~lib/math/random_state0_32
4179
4169
call $~lib/math/splitMix32
4180
4170
global.set $~lib/math/random_state1_32
4171
+ global.get $~lib/math/random_state1_32
4172
+ i32.const 0
4173
+ i32.ne
4174
+ i32.const 0
4175
+ global.get $~lib/math/random_state0_32
4176
+ i32.const 0
4177
+ global.get $~lib/math/random_state1_64
4178
+ i64.const 0
4179
+ i64.ne
4180
+ i32.const 0
4181
+ global.get $~lib/math/random_state0_64
4182
+ i64.const 0
4183
+ i64.ne
4184
+ select
4185
+ select
4186
+ select
4187
+ i32.eqz
4188
+ if
4189
+ i32.const 0
4190
+ i32.const 3160
4191
+ i32.const 1041
4192
+ i32.const 4
4193
+ call $~lib/builtins/abort
4194
+ unreachable
4195
+ end
4181
4196
)
4182
4197
(func $~lib/util/sort/insertionSort<f32> (; 98 ;) (type $FUNCSIG$viii ) (param $0 i32 ) (param $1 i32 ) (param $2 i32 )
4183
4198
(local $3 i32 )
5709
5724
if
5710
5725
i32.const 3936
5711
5726
i32.const 3160
5712
- i32.const 1045
5727
+ i32.const 1048
5713
5728
i32.const 24
5714
5729
call $~lib/builtins/abort
5715
5730
unreachable
5735
5750
i64.const 26
5736
5751
i64.shr_u
5737
5752
i64.xor
5738
- local.tee $0
5739
5753
global.set $~lib/math/random_state1_64
5740
- local.get $0
5741
5754
local.get $1
5742
- i64.add
5743
- i64.const 4503599627370495
5744
- i64.and
5755
+ i64.const 12
5756
+ i64.shr_u
5745
5757
i64.const 4607182418800017408
5746
5758
i64.or
5747
5759
f64.reinterpret_i64
Original file line number Diff line number Diff line change 6529
6529
i32.xor
6530
6530
)
6531
6531
(func $~lib/math/NativeMath.seedRandom (; 129 ;) (type $FUNCSIG$vj ) (param $0 i64 )
6532
- local.get $0
6533
- i64.eqz
6534
- if
6535
- i32.const 0
6536
- i32.const 3160
6537
- i32.const 1036
6538
- i32.const 4
6539
- call $~lib/builtins/abort
6540
- unreachable
6541
- end
6542
6532
i32.const 1
6543
6533
global.set $~lib/math/random_seeded
6544
6534
local.get $0
6556
6546
global.get $~lib/math/random_state0_32
6557
6547
call $~lib/math/splitMix32
6558
6548
global.set $~lib/math/random_state1_32
6549
+ global.get $~lib/math/random_state0_64
6550
+ i64.const 0
6551
+ i64.ne
6552
+ if (result i32 )
6553
+ global.get $~lib/math/random_state1_64
6554
+ i64.const 0
6555
+ i64.ne
6556
+ else
6557
+ i32.const 0
6558
+ end
6559
+ if (result i32 )
6560
+ global.get $~lib/math/random_state0_32
6561
+ i32.const 0
6562
+ i32.ne
6563
+ else
6564
+ i32.const 0
6565
+ end
6566
+ if (result i32 )
6567
+ global.get $~lib/math/random_state1_32
6568
+ i32.const 0
6569
+ i32.ne
6570
+ else
6571
+ i32.const 0
6572
+ end
6573
+ i32.eqz
6574
+ if
6575
+ i32.const 0
6576
+ i32.const 3160
6577
+ i32.const 1041
6578
+ i32.const 4
6579
+ call $~lib/builtins/abort
6580
+ unreachable
6581
+ end
6559
6582
)
6560
6583
(func $~lib/util/sort/insertionSort<f32> (; 130 ;) (type $FUNCSIG$viii ) (param $0 i32 ) (param $1 i32 ) (param $2 i32 )
6561
6584
(local $3 i32 )
8842
8865
if
8843
8866
i32.const 3936
8844
8867
i32.const 3160
8845
- i32.const 1045
8868
+ i32.const 1048
8846
8869
i32.const 24
8847
8870
call $~lib/builtins/abort
8848
8871
unreachable
8878
8901
local.get $0
8879
8902
global.set $~lib/math/random_state1_64
8880
8903
local.get $1
8881
- local.get $0
8882
- i64.add
8883
- i64.const 4503599627370495
8884
- i64.and
8904
+ i64.const 12
8905
+ i64.shr_u
8885
8906
i64.const 4607182418800017408
8886
8907
i64.or
8887
8908
local.set $2
Original file line number Diff line number Diff line change 8039
8039
i32.xor
8040
8040
)
8041
8041
(func $~lib/math/NativeMath.seedRandom (; 130 ;) (type $FUNCSIG$vj) (param $0 i64)
8042
- local.get $0
8043
- i64.eqz
8044
- if
8045
- i32.const 0
8046
- i32.const 144
8047
- i32.const 1036
8048
- i32.const 4
8049
- call $~lib/builtins/abort
8050
- unreachable
8051
- end
8052
8042
i32.const 1
8053
8043
global.set $~lib/math/random_seeded
8054
8044
local.get $0
8066
8056
global.get $~lib/math/random_state0_32
8067
8057
call $~lib/math/splitMix32
8068
8058
global.set $~lib/math/random_state1_32
8059
+ global.get $~lib/math/random_state1_32
8060
+ i32.const 0
8061
+ i32.ne
8062
+ i32.const 0
8063
+ global.get $~lib/math/random_state0_32
8064
+ i32.const 0
8065
+ global.get $~lib/math/random_state1_64
8066
+ i64.const 0
8067
+ i64.ne
8068
+ i32.const 0
8069
+ global.get $~lib/math/random_state0_64
8070
+ i64.const 0
8071
+ i64.ne
8072
+ select
8073
+ select
8074
+ select
8075
+ i32.eqz
8076
+ if
8077
+ i32.const 0
8078
+ i32.const 144
8079
+ i32.const 1041
8080
+ i32.const 4
8081
+ call $~lib/builtins/abort
8082
+ unreachable
8083
+ end
8069
8084
)
8070
8085
(func $~lib/math/NativeMath.random (; 131 ;) (type $FUNCSIG$d) (result f64)
8071
8086
(local $0 i64)
8075
8090
if
8076
8091
i32.const 184
8077
8092
i32.const 144
8078
- i32.const 1045
8093
+ i32.const 1048
8079
8094
i32.const 24
8080
8095
call $~lib/builtins/abort
8081
8096
unreachable
8101
8116
i64.const 26
8102
8117
i64.shr_u
8103
8118
i64.xor
8104
- local.tee $0
8105
8119
global.set $~lib/math/random_state1_64
8106
- local.get $0
8107
8120
local.get $1
8108
- i64.add
8109
- i64.const 4503599627370495
8110
- i64.and
8121
+ i64.const 12
8122
+ i64.shr_u
8111
8123
i64.const 4607182418800017408
8112
8124
i64.or
8113
8125
f64.reinterpret_i64
8122
8134
if
8123
8135
i32.const 184
8124
8136
i32.const 144
8125
- i32.const 2319
8137
+ i32.const 2322
8126
8138
i32.const 24
8127
8139
call $~lib/builtins/abort
8128
8140
unreachable
Original file line number Diff line number Diff line change 10130
10130
i32.xor
10131
10131
)
10132
10132
(func $~lib/math/NativeMath.seedRandom (; 133 ;) (type $FUNCSIG$vj) (param $0 i64)
10133
- local.get $0
10134
- i64.eqz
10135
- if
10136
- i32.const 0
10137
- i32.const 144
10138
- i32.const 1036
10139
- i32.const 4
10140
- call $~lib/builtins/abort
10141
- unreachable
10142
- end
10143
10133
i32.const 1
10144
10134
global.set $~lib/math/random_seeded
10145
10135
local.get $0
10157
10147
global.get $~lib/math/random_state0_32
10158
10148
call $~lib/math/splitMix32
10159
10149
global.set $~lib/math/random_state1_32
10150
+ global.get $~lib/math/random_state0_64
10151
+ i64.const 0
10152
+ i64.ne
10153
+ if (result i32)
10154
+ global.get $~lib/math/random_state1_64
10155
+ i64.const 0
10156
+ i64.ne
10157
+ else
10158
+ i32.const 0
10159
+ end
10160
+ if (result i32)
10161
+ global.get $~lib/math/random_state0_32
10162
+ i32.const 0
10163
+ i32.ne
10164
+ else
10165
+ i32.const 0
10166
+ end
10167
+ if (result i32)
10168
+ global.get $~lib/math/random_state1_32
10169
+ i32.const 0
10170
+ i32.ne
10171
+ else
10172
+ i32.const 0
10173
+ end
10174
+ i32.eqz
10175
+ if
10176
+ i32.const 0
10177
+ i32.const 144
10178
+ i32.const 1041
10179
+ i32.const 4
10180
+ call $~lib/builtins/abort
10181
+ unreachable
10182
+ end
10160
10183
)
10161
10184
(func $~lib/math/NativeMath.random (; 134 ;) (type $FUNCSIG$d) (result f64)
10162
10185
(local $0 i64)
10167
10190
if
10168
10191
i32.const 184
10169
10192
i32.const 144
10170
- i32.const 1045
10193
+ i32.const 1048
10171
10194
i32.const 24
10172
10195
call $~lib/builtins/abort
10173
10196
unreachable
10203
10226
local.get $0
10204
10227
global.set $~lib/math/random_state1_64
10205
10228
local.get $1
10206
- local.get $0
10207
- i64.add
10208
- i64.const 4503599627370495
10209
- i64.and
10229
+ i64.const 12
10230
+ i64.shr_u
10210
10231
i64.const 4607182418800017408
10211
10232
i64.or
10212
10233
local.set $2
10224
10245
if
10225
10246
i32.const 184
10226
10247
i32.const 144
10227
- i32.const 2319
10248
+ i32.const 2322
10228
10249
i32.const 24
10229
10250
call $~lib/builtins/abort
10230
10251
unreachable
You can’t perform that action at this time.
0 commit comments