Skip to content

Commit

Permalink
Merge pull request #1073 from antmicro:rle-cleanup
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 549649756
  • Loading branch information
copybara-github committed Jul 20, 2023
2 parents f2096b6 + f8e2d3d commit 56be50e
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 129 deletions.
101 changes: 91 additions & 10 deletions xls/modules/rle/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -31,45 +31,57 @@ package(
)

xls_dslx_library(
name = "rle_dslx",
srcs = ["rle.x"],
name = "rle_common_dslx",
srcs = [
"rle_common.x",
],
)

xls_dslx_library(
name = "rle_enc_dslx",
srcs = [
"rle_enc.x",
],
deps = [
":rle_common_dslx",
],
)

xls_dslx_test(
name = "rle_dslx_test",
name = "rle_enc_dslx_test",
dslx_test_args = {
"compare": "none",
},
library = "rle_dslx",
library = "rle_enc_dslx",
)

xls_dslx_test(
name = "rle_dslx_ir_test",
name = "rle_enc_dslx_ir_test",
dslx_test_args = {
"compare": "interpreter",
},
library = "rle_dslx",
library = "rle_enc_dslx",
)

xls_dslx_test(
name = "rle_dslx_jit_test",
name = "rle_enc_dslx_jit_test",
dslx_test_args = {
"compare": "jit",
},
library = "rle_dslx",
library = "rle_enc_dslx",
)

xls_dslx_ir(
name = "rle_enc_ir",
dslx_top = "RunLengthEncoder32",
ir_file = "rle_enc.ir",
library = "rle_dslx",
library = "rle_enc_dslx",
)

xls_ir_opt_ir(
name = "rle_enc_opt_ir",
src = "rle_enc.ir",
top = "__rle__RunLengthEncoder32__RunLengthEncoder_0__2_32_next",
top = "__rle_enc__RunLengthEncoder32__RunLengthEncoder_0__2_32_next",
)

xls_ir_verilog(
Expand All @@ -93,3 +105,72 @@ xls_benchmark_ir(
"delay_model": "unit",
},
)

xls_dslx_library(
name = "rle_dec_dslx",
srcs = [
"rle_dec.x",
],
deps = [
":rle_common_dslx",
],
)

xls_dslx_test(
name = "rle_dec_dslx_test",
dslx_test_args = {
"compare": "none",
},
library = "rle_dec_dslx",
)

xls_dslx_test(
name = "rle_dec_dslx_ir_test",
dslx_test_args = {
"compare": "interpreter",
},
library = "rle_dec_dslx",
)

xls_dslx_test(
name = "rle_dec_dslx_jit_test",
dslx_test_args = {
"compare": "jit",
},
library = "rle_dec_dslx",
)

xls_dslx_ir(
name = "rle_dec_ir",
dslx_top = "RunLengthDecoder32",
ir_file = "rle_dec.ir",
library = "rle_dec_dslx",
)

xls_ir_opt_ir(
name = "rle_dec_opt_ir",
src = "rle_dec.ir",
top = "__rle_dec__RunLengthDecoder32__RunLengthDecoder_0__2_32_next",
)

xls_ir_verilog(
name = "rle_dec_verilog",
src = ":rle_dec_opt_ir.opt.ir",
codegen_args = {
"module_name": "rle_dec",
"delay_model": "unit",
"pipeline_stages": "2",
"reset": "rst",
"use_system_verilog": "false",
},
verilog_file = "rle_dec.v",
)

xls_benchmark_ir(
name = "rle_dec_ir_benchmark",
src = ":rle_dec_opt_ir.opt.ir",
benchmark_ir_args = {
"pipeline_stages": "2",
"delay_model": "unit",
},
)
34 changes: 34 additions & 0 deletions xls/modules/rle/rle_common.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2023 The XLS Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// This file defines RLE common data structures
//

// Structure contains uncompressed symbols.
// Structure is used as an input and an output to and from
// a preprocessing stage as well as an input to a RLE encoder.
// It is also used as an output from RLE decoder.
pub struct PlainData<SYMB_WIDTH: u32> {
symbol: bits[SYMB_WIDTH], // symbol
last: bool, // flush RLE
}

// Structure contains compressed (symbol, counter) pairs.
// Structure is used as an output from RLE encoder and
// as an input to RLE decoder.
pub struct CompressedData<SYMBOL_WIDTH: u32, COUNT_WIDTH: u32> {
symbol: bits[SYMBOL_WIDTH], // symbol
count: bits[COUNT_WIDTH], // symbol counter
last: bool, // flush RLE
}
13 changes: 3 additions & 10 deletions xls/modules/rle_dec/rle_dec.x → xls/modules/rle/rle_dec.x
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,10 @@


import std
import xls.modules.rle.rle_common as rle_common

pub struct DecInData<SYMBOL_WIDTH: u32, COUNT_WIDTH: u32> {
symbol: bits[SYMBOL_WIDTH], // compressed symbol
count: bits[COUNT_WIDTH], // symbol count
last: bool, // if this is the last symbol
}

pub struct DecOutData<SYMBOL_WIDTH: u32> {
symbol: bits[SYMBOL_WIDTH], // input symbol to compress
last: bool, // if this is the last symbol
}
type DecInData = rle_common::CompressedData;
type DecOutData = rle_common::PlainData;

// structure to preserve the state of an RLE decoder
struct RunLengthDecoderState<SYMBOL_WIDTH: u32, COUNT_WIDTH: u32> {
Expand Down
15 changes: 3 additions & 12 deletions xls/modules/rle/rle.x → xls/modules/rle/rle_enc.x
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,10 @@
// (output channel) ────────────────────────┘ └───────────┘ └────

import std
import xls.modules.rle.rle_common as rle_common

// structure containing input data for an RLE encoder
pub struct EncInData<SYMBOL_WIDTH: u32> {
symbol: bits[SYMBOL_WIDTH], // input symbol to compress
last: bool, // if this is the last symbol
}

// structure containing output data from an RLE encoder
pub struct EncOutData<SYMBOL_WIDTH: u32, COUNT_WIDTH: u32> {
symbol: bits[SYMBOL_WIDTH], // compressed symbol
count: bits[COUNT_WIDTH], // symbol count
last: bool, // if this is the last symbol
}
type EncInData = rle_common::PlainData;
type EncOutData = rle_common::CompressedData;

// structure to preserve the state of an RLE encoder
struct RunLengthEncoderState<SYMBOL_WIDTH: u32, COUNT_WIDTH: u32> {
Expand Down
97 changes: 0 additions & 97 deletions xls/modules/rle_dec/BUILD

This file was deleted.

0 comments on commit 56be50e

Please sign in to comment.