From 31482cbcebac855e9c7fccf0cf70c25cd6233cf4 Mon Sep 17 00:00:00 2001 From: Yury Gribov Date: Fri, 10 Jun 2016 21:32:45 +0300 Subject: [PATCH] Implement sign extension LPM for BLIF target --- tgt-blif/Makefile.in | 2 +- tgt-blif/lpm.cc | 3 +++ tgt-blif/lpm_sign_ext.cc | 58 ++++++++++++++++++++++++++++++++++++++++ tgt-blif/priv.h | 1 + 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 tgt-blif/lpm_sign_ext.cc diff --git a/tgt-blif/Makefile.in b/tgt-blif/Makefile.in index 88a984b04..2a18dccdc 100644 --- a/tgt-blif/Makefile.in +++ b/tgt-blif/Makefile.in @@ -44,7 +44,7 @@ CXXFLAGS = @WARNING_FLAGS@ @WARNING_FLAGS_CXX@ @CXXFLAGS@ LDFLAGS = @LDFLAGS@ O = blif.o constants.o logic_gate.o lpm.o lpm_add.o lpm_cmp_eq.o lpm_cmp_gt.o \ - lpm_ff.o lpm_mux.o lpm_part_vp.o lpm_re_logic.o nex_data.o + lpm_ff.o lpm_mux.o lpm_part_vp.o lpm_re_logic.o lpm_sign_ext.o nex_data.o all: dep blif.tgt diff --git a/tgt-blif/lpm.cc b/tgt-blif/lpm.cc index 3b0a4fba6..157a70aee 100644 --- a/tgt-blif/lpm.cc +++ b/tgt-blif/lpm.cc @@ -108,6 +108,9 @@ int print_lpm(FILE*fd, ivl_lpm_t net) case IVL_LPM_SUB: rc += print_lpm_sub(fd, net); break; + case IVL_LPM_SIGN_EXT: + rc += print_lpm_sign_ext(fd, net); + break; default: fprintf(fd, "# XXXX ivl_lpm_type(net) --> %d\n", ivl_lpm_type(net)); fprintf(stderr, "%s:%u: sorry: ivl_lpm_type(net)==%d not implemented.\n", diff --git a/tgt-blif/lpm_sign_ext.cc b/tgt-blif/lpm_sign_ext.cc new file mode 100644 index 000000000..311eddee6 --- /dev/null +++ b/tgt-blif/lpm_sign_ext.cc @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2016 Yury Gribov (tetra2005@gmail.com) + * + * This source code is free software; you can redistribute it + * and/or modify it in source code form under the terms of the GNU + * General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + + +# include "priv.h" +# include "nex_data.h" +# include + +/* + * Implement IVL_LPM_SIGN_EXT devices + */ +int print_lpm_sign_ext(FILE*fd, ivl_lpm_t net) +{ + fprintf(fd, "# %s:%u: IVL_LPM_SIGN_EXT: width=%u\n", + ivl_lpm_file(net), ivl_lpm_lineno(net), ivl_lpm_width(net)); + + ivl_nexus_t q_nex = ivl_lpm_q(net); + ivl_nexus_t d_nex = ivl_lpm_data(net,0); + + blif_nex_data_t*q_ned = blif_nex_data_t::get_nex_data(q_nex); + blif_nex_data_t*d_ned = blif_nex_data_t::get_nex_data(d_nex); + + unsigned inw = d_ned->get_width(); + unsigned outw = ivl_lpm_width(net); + +//printf("Shift: LPM width = %u, output width = %zd, input width = %u\n", outw, q_ned->get_width(), inw); + + assert(outw == q_ned->get_width()); + assert(inw < outw); + + for (unsigned idx = 0 ; idx < outw ; idx += 1) { + unsigned idx_in = idx < inw ? idx : inw - 1; + + fprintf(fd, ".names %s%s %s%s\n", + d_ned->get_name(), d_ned->get_name_index(idx_in), + q_ned->get_name(), q_ned->get_name_index(idx)); + fprintf(fd, "1 1\n"); + } + + return 0; +} + diff --git a/tgt-blif/priv.h b/tgt-blif/priv.h index 3bd6a1f02..7a068fd8c 100644 --- a/tgt-blif/priv.h +++ b/tgt-blif/priv.h @@ -40,6 +40,7 @@ extern int print_lpm_cmp_ne(FILE*fd, ivl_lpm_t net); extern int print_lpm_mux(FILE*fd, ivl_lpm_t net); extern int print_lpm_part_vp(FILE*fd, ivl_lpm_t net); extern int print_lpm_re_logic(FILE*fd, ivl_lpm_t net); +extern int print_lpm_sign_ext(FILE*fd, ivl_lpm_t net); /* * Emit all the constants for a model. This works by scanning the