@@ -284,24 +284,14 @@ impl<F: Field> BitstreamDecoder<F> {
284
284
/// Fields related to application of the FSE table.
285
285
#[ derive( Clone , Debug ) ]
286
286
pub struct FseDecoder {
287
- /// Boolean that is set if a symbol is emitted on this row. When we apply an FSE table to an
288
- /// incoming bitstream, we skip the first leading 0s and a sentinel bits. This can be 8 bits as
289
- /// well, meaning that an entire byte is skipped. After skipping these bits, we read AL number
290
- /// of bits to know our the first state to start from.
291
- ///
292
- /// The ``is_emit`` column can never be set on the first row of the HuffmanCode tag, as the
293
- /// first row is either:
294
- /// - 7 leading 0s and a sentinel bit OR
295
- /// - leading 0s, sentinel and reading AL bits to find the first state.
296
- is_emit : Column < Advice > ,
297
- /// Number of symbols we have emitted.
298
- num_emitted : Column < Advice > ,
299
287
/// The FSE state we are at.
300
288
state : Column < Advice > ,
301
289
/// The baseline value at ``state``.
302
290
baseline : Column < Advice > ,
303
291
/// The symbol emitted while transitioning from ``state`` to a new state.
304
292
symbol : Column < Advice > ,
293
+ /// Number of symbols we have emitted.
294
+ num_emitted : Column < Advice > ,
305
295
/// An accumulator that keeps a count of the number of states assigned for each symbol,
306
296
/// including the symbol that is decoded on the current row.
307
297
n_acc : Column < Advice > ,
@@ -486,11 +476,10 @@ impl<F: Field> SubCircuitConfig<F> for DecompressionCircuitConfig<F> {
486
476
}
487
477
} ;
488
478
let fse_decoder = FseDecoder {
489
- is_emit : meta. advice_column ( ) ,
490
- num_emitted : meta. advice_column ( ) ,
491
479
state : meta. advice_column ( ) ,
492
480
baseline : meta. advice_column ( ) ,
493
481
symbol : meta. advice_column ( ) ,
482
+ num_emitted : meta. advice_column ( ) ,
494
483
n_acc : meta. advice_column ( ) ,
495
484
} ;
496
485
let lstream = meta. advice_column ( ) ;
@@ -2007,19 +1996,6 @@ impl<F: Field> SubCircuitConfig<F> for DecompressionCircuitConfig<F> {
2007
1996
// the bitstream to find the initial state in the FSE table.
2008
1997
// - Only from the third row onwards, do we start emitting symbols (weights).
2009
1998
2010
- cb. require_zero (
2011
- "is_emit == false on the first row" ,
2012
- meta. query_advice ( fse_decoder. is_emit , Rotation :: cur ( ) ) ,
2013
- ) ;
2014
- cb. require_zero (
2015
- "is_emit == false on the second row" ,
2016
- meta. query_advice ( fse_decoder. is_emit , Rotation :: next ( ) ) ,
2017
- ) ;
2018
- cb. require_equal (
2019
- "is_emit == true from the third row onwards" ,
2020
- meta. query_advice ( fse_decoder. is_emit , Rotation ( 2 ) ) ,
2021
- 1 . expr ( ) ,
2022
- ) ;
2023
1999
cb. require_zero (
2024
2000
"num_emitted starts at 0 from the second row" ,
2025
2001
meta. query_advice ( fse_decoder. num_emitted , Rotation :: next ( ) ) ,
@@ -2059,24 +2035,6 @@ impl<F: Field> SubCircuitConfig<F> for DecompressionCircuitConfig<F> {
2059
2035
] ) )
2060
2036
} ,
2061
2037
) ;
2062
- meta. create_gate (
2063
- "DecompressionCircuit: ZstdBlockHuffmanCode (other rows)" ,
2064
- |meta| {
2065
- let mut cb = BaseConstraintBuilder :: default ( ) ;
2066
-
2067
- cb. require_boolean (
2068
- "is_emit only transitions from 0 -> 1" ,
2069
- meta. query_advice ( fse_decoder. is_emit , Rotation :: cur ( ) )
2070
- - meta. query_advice ( fse_decoder. is_emit , Rotation :: prev ( ) ) ,
2071
- ) ;
2072
-
2073
- cb. gate ( and:: expr ( [
2074
- meta. query_fixed ( q_enable, Rotation :: cur ( ) ) ,
2075
- meta. query_advice ( tag_gadget. is_huffman_code , Rotation :: cur ( ) ) ,
2076
- not:: expr ( meta. query_advice ( tag_gadget. is_tag_change , Rotation :: cur ( ) ) ) ,
2077
- ] ) )
2078
- } ,
2079
- ) ;
2080
2038
meta. create_gate (
2081
2039
"DecompressionCircuit: ZstdBlockHuffmanCode (wherever we emit a symbol)" ,
2082
2040
|meta| {
@@ -2103,7 +2061,8 @@ impl<F: Field> SubCircuitConfig<F> for DecompressionCircuitConfig<F> {
2103
2061
cb. gate ( and:: expr ( [
2104
2062
meta. query_fixed ( q_enable, Rotation :: cur ( ) ) ,
2105
2063
meta. query_advice ( tag_gadget. is_huffman_code , Rotation :: cur ( ) ) ,
2106
- meta. query_advice ( fse_decoder. is_emit , Rotation :: cur ( ) ) ,
2064
+ not:: expr ( meta. query_advice ( tag_gadget. is_tag_change , Rotation :: cur ( ) ) ) ,
2065
+ not:: expr ( meta. query_advice ( tag_gadget. is_tag_change , Rotation :: prev ( ) ) ) ,
2107
2066
] ) )
2108
2067
} ,
2109
2068
) ;
@@ -2263,7 +2222,8 @@ impl<F: Field> SubCircuitConfig<F> for DecompressionCircuitConfig<F> {
2263
2222
let condition = and:: expr ( [
2264
2223
meta. query_fixed ( q_enable, Rotation :: cur ( ) ) ,
2265
2224
meta. query_advice ( tag_gadget. is_huffman_code , Rotation :: cur ( ) ) ,
2266
- meta. query_advice ( fse_decoder. is_emit , Rotation :: cur ( ) ) ,
2225
+ not:: expr ( meta. query_advice ( tag_gadget. is_tag_change , Rotation :: cur ( ) ) ) ,
2226
+ not:: expr ( meta. query_advice ( tag_gadget. is_tag_change , Rotation :: prev ( ) ) ) ,
2267
2227
] ) ;
2268
2228
let start = meta. query_advice ( bitstream_decoder. bit_index_start , Rotation :: cur ( ) ) ;
2269
2229
let end = meta. query_advice ( bitstream_decoder. bit_index_end , Rotation :: cur ( ) ) ;
@@ -2288,7 +2248,8 @@ impl<F: Field> SubCircuitConfig<F> for DecompressionCircuitConfig<F> {
2288
2248
let condition = and:: expr ( [
2289
2249
meta. query_fixed ( q_enable, Rotation :: cur ( ) ) ,
2290
2250
meta. query_advice ( tag_gadget. is_huffman_code , Rotation :: cur ( ) ) ,
2291
- meta. query_advice ( fse_decoder. is_emit , Rotation :: cur ( ) ) ,
2251
+ not:: expr ( meta. query_advice ( tag_gadget. is_tag_change , Rotation :: cur ( ) ) ) ,
2252
+ not:: expr ( meta. query_advice ( tag_gadget. is_tag_change , Rotation :: prev ( ) ) ) ,
2292
2253
] ) ;
2293
2254
[
2294
2255
meta. query_advice ( huffman_tree_config. huffman_tree_idx , Rotation :: cur ( ) ) ,
0 commit comments