From 672aaae0e3352418a7976c7f10d858ebed2da3bd Mon Sep 17 00:00:00 2001 From: Mazet Laurent Date: Thu, 27 Nov 2025 17:36:49 +0100 Subject: [PATCH] initial commit --- BUGS | 22 + INSTALL | 182 ++++ INSTALL.LIBFB | 105 +++ Makeconf.in | 114 +++ Makefile.in | 62 ++ Makerule.in | 128 +++ README | 65 ++ aclocal.m4 | 71 ++ config.guess | 1754 +++++++++++++++++++++++++++++++++++++ config.sub | 1890 ++++++++++++++++++++++++++++++++++++++++ configure.ac | 263 ++++++ install-sh | 251 ++++++ mkinstalldirs | 40 + src/Makefile.in | 36 + src/create_fbtrellis.c | 398 +++++++++ src/create_fbtrellis.h | 47 + src/encoder.c | 109 +++ src/encoder.h | 56 ++ src/fbcoded.c | 218 +++++ src/fbcoded.h | 51 ++ src/fbinfo.c | 362 ++++++++ src/fbinfo.h | 74 ++ src/fbtrellis.c | 286 ++++++ src/fbtrellis.h | 110 +++ src/fbversion.h.in | 1 + src/interleaver.c | 56 ++ src/interleaver.h | 5 + src/logfbinfo.c | 363 ++++++++ src/logfbinfo.h | 58 ++ src/maxstar.c | 68 ++ src/maxstar.h | 32 + test/Makefile.in | 29 + test/convcode.c | 696 +++++++++++++++ 33 files changed, 8002 insertions(+) create mode 100644 BUGS create mode 100644 INSTALL create mode 100644 INSTALL.LIBFB create mode 100644 Makeconf.in create mode 100644 Makefile.in create mode 100644 Makerule.in create mode 100644 README create mode 100644 aclocal.m4 create mode 100755 config.guess create mode 100755 config.sub create mode 100644 configure.ac create mode 100755 install-sh create mode 100755 mkinstalldirs create mode 100644 src/Makefile.in create mode 100644 src/create_fbtrellis.c create mode 100644 src/create_fbtrellis.h create mode 100644 src/encoder.c create mode 100644 src/encoder.h create mode 100644 src/fbcoded.c create mode 100644 src/fbcoded.h create mode 100644 src/fbinfo.c create mode 100644 src/fbinfo.h create mode 100644 src/fbtrellis.c create mode 100644 src/fbtrellis.h create mode 100644 src/fbversion.h.in create mode 100644 src/interleaver.c create mode 100644 src/interleaver.h create mode 100644 src/logfbinfo.c create mode 100644 src/logfbinfo.h create mode 100644 src/maxstar.c create mode 100644 src/maxstar.h create mode 100644 test/Makefile.in create mode 100644 test/convcode.c diff --git a/BUGS b/BUGS new file mode 100644 index 0000000..ab315be --- /dev/null +++ b/BUGS @@ -0,0 +1,22 @@ +This file documents known bugs in LibForwardBackward and describes +where and how to report any bugs that you may find. + +Copyright (C) 2004 Laurent S. Mazet and Sebastien Simoens + +Known Causes of Trouble with LibForwardBackward +*********************************************** + + This section describes known problems that affect users of +LibForwardBackward. + +Actual Bugs We Haven't Fixed Yet +================================ + + * On cygwin, you can not compile dynamic library. + +Where to Report Bugs +==================== + + If you have found a bug send it to the actual maintener (aka me) to + + diff --git a/INSTALL b/INSTALL new file mode 100644 index 0000000..b42a17a --- /dev/null +++ b/INSTALL @@ -0,0 +1,182 @@ +Basic Installation +================== + + These are generic installation instructions. + + The `configure' shell script attempts to guess correct values for +various system-dependent variables used during compilation. It uses +those values to create a `Makefile' in each directory of the package. +It may also create one or more `.h' files containing system-dependent +definitions. Finally, it creates a shell script `config.status' that +you can run in the future to recreate the current configuration, a file +`config.cache' that saves the results of its tests to speed up +reconfiguring, and a file `config.log' containing compiler output +(useful mainly for debugging `configure'). + + If you need to do unusual things to compile the package, please try +to figure out how `configure' could check whether to do them, and mail +diffs or instructions to the address given in the `README' so they can +be considered for the next release. If at some point `config.cache' +contains results you don't want to keep, you may remove or edit it. + + The file `configure.in' is used to create `configure' by a program +called `autoconf'. You only need `configure.in' if you want to change +it or regenerate `configure' using a newer version of `autoconf'. + +The simplest way to compile this package is: + + 1. `cd' to the directory containing the package's source code and type + `./configure' to configure the package for your system. If you're + using `csh' on an old version of System V, you might need to type + `sh ./configure' instead to prevent `csh' from trying to execute + `configure' itself. + + Running `configure' takes awhile. While running, it prints some + messages telling which features it is checking for. + + 2. Type `make' to compile the package. + + 3. Optionally, type `make check' to run any self-tests that come with + the package. + + 4. Type `make install' to install the programs and any data files and + documentation. + + 5. You can remove the program binaries and object files from the + source code directory by typing `make clean'. To also remove the + files that `configure' created (so you can compile the package for + a different kind of computer), type `make distclean'. There is + also a `make maintainer-clean' target, but that is intended mainly + for the package's developers. If you use it, you may have to get + all sorts of other programs in order to regenerate files that came + with the distribution. + +Compilers and Options +===================== + + Some systems require unusual options for compilation or linking that +the `configure' script does not know about. You can give `configure' +initial values for variables by setting them in the environment. Using +a Bourne-compatible shell, you can do that on the command line like +this: + CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure + +Or on systems that have the `env' program, you can do it like this: + env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure + +Compiling For Multiple Architectures +==================================== + + You can compile the package for more than one kind of computer at the +same time, by placing the object files for each architecture in their +own directory. To do this, you must use a version of `make' that +supports the `VPATH' variable, such as GNU `make'. `cd' to the +directory where you want the object files and executables to go and run +the `configure' script. `configure' automatically checks for the +source code in the directory that `configure' is in and in `..'. + + If you have to use a `make' that does not supports the `VPATH' +variable, you have to compile the package for one architecture at a time +in the source code directory. After you have installed the package for +one architecture, use `make distclean' before reconfiguring for another +architecture. + +Installation Names +================== + + By default, `make install' will install the package's files in +`/usr/local/bin', `/usr/local/man', etc. You can specify an +installation prefix other than `/usr/local' by giving `configure' the +option `--prefix=PATH'. + + You can specify separate installation prefixes for +architecture-specific files and architecture-independent files. If you +give `configure' the option `--exec-prefix=PATH', the package will use +PATH as the prefix for installing programs and libraries. +Documentation and other data files will still use the regular prefix. + + In addition, if you use an unusual directory layout you can give +options like `--bindir=PATH' to specify different values for particular +kinds of files. Run `configure --help' for a list of the directories +you can set and what kinds of files go in them. + + If the package supports it, you can cause programs to be installed +with an extra prefix or suffix on their names by giving `configure' the +option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. + +Optional Features +================= + + Some packages pay attention to `--enable-FEATURE' options to +`configure', where FEATURE indicates an optional part of the package. +They may also pay attention to `--with-PACKAGE' options, where PACKAGE +is something like `gnu-as' or `x' (for the X Window System). The +`README' should mention any `--enable-' and `--with-' options that the +package recognizes. + + For packages that use the X Window System, `configure' can usually +find the X include and library files automatically, but if it doesn't, +you can use the `configure' options `--x-includes=DIR' and +`--x-libraries=DIR' to specify their locations. + +Specifying the System Type +========================== + + There may be some features `configure' can not figure out +automatically, but needs to determine by the type of host the package +will run on. Usually `configure' can figure that out, but if it prints +a message saying it can not guess the host type, give it the +`--host=TYPE' option. TYPE can either be a short name for the system +type, such as `sun4', or a canonical name with three fields: + CPU-COMPANY-SYSTEM + +See the file `config.sub' for the possible values of each field. If +`config.sub' isn't included in this package, then this package doesn't +need to know the host type. + + If you are building compiler tools for cross-compiling, you can also +use the `--target=TYPE' option to select the type of system they will +produce code for and the `--build=TYPE' option to select the type of +system on which you are compiling the package. + +Sharing Defaults +================ + + If you want to set default values for `configure' scripts to share, +you can create a site shell script called `config.site' that gives +default values for variables like `CC', `cache_file', and `prefix'. +`configure' looks for `PREFIX/share/config.site' if it exists, then +`PREFIX/etc/config.site' if it exists. Or, you can set the +`CONFIG_SITE' environment variable to the location of the site script. +A warning: not all `configure' scripts look for a site script. + +Operation Controls +================== + + `configure' recognizes the following options to control how it +operates. + +`--cache-file=FILE' + Use and save the results of the tests in FILE instead of + `./config.cache'. Set FILE to `/dev/null' to disable caching, for + debugging `configure'. + +`--help' + Print a summary of the options to `configure', and exit. + +`--quiet' +`--silent' +`-q' + Do not print messages saying which checks are being made. To + suppress all normal output, redirect it to `/dev/null' (any error + messages will still be shown). + +`--srcdir=DIR' + Look for the package's source code in directory DIR. Usually + `configure' can determine that directory automatically. + +`--version' + Print the version of Autoconf used to generate the `configure' + script, and exit. + +`configure' also accepts some other, not widely useful, options. diff --git a/INSTALL.LIBFB b/INSTALL.LIBFB new file mode 100644 index 0000000..45992c2 --- /dev/null +++ b/INSTALL.LIBFB @@ -0,0 +1,105 @@ +This file documents the installation of LibForwardBackward. + + +Installing LibForwardBackward +***************************** + + Here is the procedure for installing LibForwardBackward from scratch + on a Unix system. + + * Run the shell script `configure'. This will determine the features + your system has (or doesn't have) and create a file named + `Makefile' from each of the files named `Makefile.in'. + + Here is a summary of the configure options that are most + frequently used when building LibForwardBackward: + + `--prefix=PREFIX' + Install LibForwardBackward in subdirectories below PREFIX. + The default value of PREFIX is `/usr/local'. + + `--enable-builddir[=DIR]' + By default, objets and library are build into the build + directory. This options change the building directory to + DIR. The default value of DIR is /tmp/`whoami`/fb. + + `--enable-static' + Create static library. If you are planning to use + `--with-debug', or use compiled binaries on other Unix system, + you will probably want to use this option. By default, the + static library is build. To cancel its, you will use the + `--disable-static' option. + + `--enable-shared' + Create shared library. It will save many disk space when you + will build binaries. By default, the shared library is build. + To cancel its, you will use the `--disable-static' option. Be + careful that this option is not available on every system. + + `--enable-rpath' + Enable the usage of rpath command when linking dynamic binary + tests. It will facilitate the usage of those binaries. By + default, this options is on. + + `--with-debug' + Add debug information for begugging the library. + + `--with-profile' + Add profiling information for gprof. + + `--help' + Print a summary of the options recognized by the configure + script. + + See the file `INSTALL' for more information about the command line + options used by configure. That file also contains instructions + for compiling in a directory other than where the source is + located. + + * Run make. + + You will need a recent version of GNU Make. Modifying + LibForwardBackward's makefiles to work with other make programs + is probably not worth your time. We recommend you get and + compile GNU Make instead. + + To compile LibForwardBackward, you will need a recent version of + GNU Make. C compiler might to be a problem, anyversion of gcc is ok. + + * If you encounter errors while compiling LibForwardBackward, first + check the list of known problems below to see if there is a + workaround or solution for your problem. If not, see the file + BUGS for information about how to report bugs. + + * Once you have successfully compiled LibForwardBackward, run `make + install'. + + This will install a copy LibForwardBackward libraries, its header + files and its documentation in the destination directory. As + distributed, LibForwardBackward is installed in the following + directories. In the table below, PREFIX defaults to + `/usr/local', and VERSION stands for the current version number + of the library. + + `PREFIX/lib' + Libraries like libfb.a and libfb.so.VERSION + + `PREFIX/include/fb' + Include files distributed with LibForwardBackward. + + `PREFIX/doc/fb-VERSION' + Documentation files distributed with LibForwardBackward. + +Installation Problems +===================== + + This section contains a list of problems (and some apparent problems +that don't really mean anything is wrong) that may show up during +installation of LibForwardBackward. + + * On HP-UX if you get the message "- shared library must be position + independent. Use +z or +Z to recompile." when compiling shared + library, you will to recompile gcc with the option `--enable-shared' + to managed to build LibForwardBackward shared library. + + diff --git a/Makeconf.in b/Makeconf.in new file mode 100644 index 0000000..55095a8 --- /dev/null +++ b/Makeconf.in @@ -0,0 +1,114 @@ +## Package name + +PACK = @PACKAGE@-@VERSION@ + +## Directory for building + +BUILD_DIR = @BUILD_DIR@ + +BIN_BUILD_DIR = $(BUILD_DIR)/bin +LIB_BUILD_DIR = $(BUILD_DIR)/lib +OBJ_BUILD_DIR = $(BUILD_DIR)/obj + +BUILD_LIST_DIRS = $(BIN_BUILD_DIR) $(LIB_BUILD_DIR) $(OBJ_BUILD_DIR) + +## Directory for install + +install_list_dirs = $(includedir) $(libdir) + +## install program variables + +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ + +MKDIR = $(top_srcdir)/mkinstalldirs + +BASENAME = @BASENAME@ + +TAR = @TAR@ +COMPRESS = @COMPRESS@ + +## Compiler variables + +CC := @CC@ +CCINCS := -I$(top_srcdir)/src +CCFLAGS := @CCFLAGS@ +CCPICFLAG := @CCPICFLAG@ + +SH_LD = @SH_LD@ +SH_LDFLAGS = @LDFLAGS@ @SH_LDFLAGS@ @SONAME_FLAGS@ + +LD = @LD@ +LIBS = @LIBS@ -L$(top_srcdir)/src -l@LIBRARY@ -lm +LDFLAGS = @LDFLAGS@ +RLDFLAG = @RLD_FLAG@ + +STRIP = @STRIP@ + +AR = @AR@ +RANLIB = @RANLIB@ + +LN_S = @LN_S@ + +STATIC_LIBS = @STATIC_LIBS@ +SHARED_LIBS = @SHARED_LIBS@ + +EXECEXT = @EXECEXT@ + +## Library version + +VERSION = @VERSION@ + +## Compile command + +ifeq ($(SHARED_LIBS),true) +COMPILE = $(CC) -c $(CCFLAGS) $(CCPICFLAG) $(CCINCS) +LINK = $(LD) $(LIBS) $(LDFLAGS) $(RLDFLAG) +else +COMPILE = $(CC) -c $(CCFLAGS) $(CCINCS) +LINK = $(LD) $(LIBS) $(LDFLAGS) +endif + +SH_LINK = $(SH_LD) $(SH_LDFLAGS) +ST_LINK = $(AR) rc + +DEBUG = @DEBUG@ + +## Sources + +SOURCES = $(wildcard *.c) +OBJECTS = $(patsubst %.c,%.o,$(SOURCES)) +DEPENDS = $(SOURCES:.c=.d) +HEADERS = $(wildcard *.h) +CONFIGS = $(filter-out configure,$(patsubst %.in,%,$(wildcard *.in))) \ + config.cache config.log config.status + +## User functions + +removefile = files="$(2)"; \ + for f in $$files; do \ + if test -f $$f; then \ + echo "Deleting $(1): $$f"; \ + rm -f $$f; \ + fi; \ + done + +removelink = files="$(2)"; \ + for f in $$files; do \ + if test -h $$f; then \ + echo "Deleting $(1): $$f"; \ + rm -f $$f; \ + fi; \ + done + +removedir = dirs="$(2)"; \ + for d in $$dirs; do \ + if test -d $$d; then \ + echo "Removing $(1): $$d"; \ + rm -rf $$d; \ + fi; \ + done + +### Local Variables: *** +### mode: Makefile *** +### End: *** diff --git a/Makefile.in b/Makefile.in new file mode 100644 index 0000000..d69d139 --- /dev/null +++ b/Makefile.in @@ -0,0 +1,62 @@ +## Directory variables + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ + +## Directory for install + +prefix = @prefix@ +exec_prefix = @exec_prefix@ +libdir = @libdir@ +includedir = @includedir@/@PACKAGE@ + +## Program variables + +INSTALL = @INSTALL@ + +## Compiler variables + +include $(top_srcdir)/Makeconf + +## Specific variables + +## Archive tools + +TAR = @TAR@ +COMPRESS = @COMPRESS@ + +@SET_MAKE@ + +## Targets + +SUBDIRS = src test + +DIR = $(shell basename `cd $(top_srcdir); pwd`) + +TARGETS = + +## Generic Rules + +include $(top_srcdir)/Makerule + +## Specific rules + +purge: + @$(call removedir,"build directory",$(BUILD_LIST_DIRS) $(BUILD_DIR)) + +archive: purge + test -n "`which autoconf`" && autoconf + ./configure + test -n "`which cvs2cl.pl`" && cvs2cl.pl + -test -n "`which devtodo`" && devtodo -T + make package + +package: purge + ( cd ..; \ + test "$(DIR)" != "$(PACK)" && mv $(DIR) $(PACK); \ + find $(PACK) \( ! -regex '.*CVS.*' \) -a -type f | \ + xargs $(TAR) cf $(PACK).tar; \ + $(COMPRESS) -f $(PACK).tar; \ + test "$(DIR)" != "$(PACK)" && mv $(PACK) $(DIR); ) + +.PHONY: archive package diff --git a/Makerule.in b/Makerule.in new file mode 100644 index 0000000..fc0f586 --- /dev/null +++ b/Makerule.in @@ -0,0 +1,128 @@ +## General rules + +all: all-local all-recursive + +all-local: $(BUILD_LIST_DIRS) $(DEPENDS) $(OBJECTS) $(TARGETS) + +$(BUILD_LIST_DIRS) $(install_list_dirs):%: + @echo "Creating directory $@"; \ + $(MKDIR) $@ + +install: $(install_list_dirs) install-local install-recursive + +install-local: all $(XTRA_INST) + @if test -n "$(HEADERS)"; then \ + for header in `echo $(HEADERS)`; do \ + rm -f $(includedir)/$$header; \ + echo "Installing $$header in $(includedir)"; \ + $(INSTALL_DATA) $$header $(includedir); \ + done; \ + fi + @if test -n "$(SHLIBVER)"; then \ + rm -f $(libdir)/$(SHLIBVER); \ + echo "Installing $(SHLIBVER) in $(libdir)"; \ + $(INSTALL_PROGRAM) $(LIB_BUILD_DIR)/$(SHLIBVER) $(libdir); \ + fi + @if test -f "$(SHLIB)"; then \ + rm -f $(libdir)/$(SHLIB); \ + echo "Installing $(SHLIB) in $(libdir)"; \ + $(LN_S) $(SHLIBVER) $(libdir)/$(SHLIB); \ + fi + @if test -f "$(STLIB)"; then \ + rm -f $(libdir)/$(STLIB); \ + echo "Installing $(STLIB) in $(libdir)"; \ + $(INSTALL_DATA) $(LIB_BUILD_DIR)/$(STLIB) $(libdir); \ + fi + +depend: $(DEPENDS) + +clean: clean-recursive clean-local + +clean-local: + @$(call removefile,"backup file",*~) + @$(call removefile,"depend file",$(DEPENDS)) + @$(call removelink,"object link",$(OBJECTS)) + @$(call removefile,"object file",$(addprefix $(OBJ_BUILD_DIR)/,$(OBJECTS))) + @$(call removefile,"tmp file",$(TMPFILES)) + +purge: purge-recursive purge-local + +purge-local: clean-local + @$(call removefile,"config file",$(CONFIGS)) + @$(call removelink,"library link",$(SHLIBVER) $(SHLIB) $(STLIB)) + @$(call removefile,"library file",$(addprefix $(LIB_BUILD_DIR)/,$(SHLIBVER) $(SHLIB) $(STLIB))) + @$(call removelink,"binary link",$(PROGTESTS)) + @$(call removefile,"binary file",$(addprefix $(BIN_BUILD_DIR)/,$(PROGTESTS))) + +## Recursive generic rule + +%-recursive: + @for subdir in $(SUBDIRS); do \ + if [ -f "$$subdir/Makefile" ]; then \ + echo "Making $* in $$subdir"; \ + $(MAKE) -s -C $$subdir $* \ + || case "$(MFLAGS)" in *k*) fail=yes;; *) exit 1;; esac; \ + echo "Leaving $$subdir"; \ + fi; \ + done && test -z "$$fail" + +## Prerequisites rules + +ifneq (,$(wildcard *.d)) +include $(wildcard *.d) +endif + +## Rules for usual directory + +%.d: %.c + @set -e; \ + echo "Creating makefile for $<"; \ + $(CC) $(CCINCS) -MM $< \ + | sed 's,\($(*F)\)\.o[ :]*,\1.o $@ : ,g' > $@; \ + test -s $@ || rm -f $@ + +%.o: %.c + @echo "Compiling $<" + @rm -f $@ + @$(COMPILE) $< -o $(OBJ_BUILD_DIR)/$@ + @$(LN_S) -f $(OBJ_BUILD_DIR)/$@ $@ + +%.a: $(OBJECTS) + @echo "Creating static lib $@" + @rm -f $@ + @$(ST_LINK) $(LIB_BUILD_DIR)/$@ $^ + @$(RANLIB) $(LIB_BUILD_DIR)/$@ + @$(LN_S) -f $(LIB_BUILD_DIR)/$@ $@ + +%.so.$(VERSION): $(OBJECTS) + @echo "Creating dynamic library $@" + @rm -f $@ + $(SH_LINK) $^ -o $(LIB_BUILD_DIR)/$@ +ifneq (${DEBUG},true) + @echo "Sripping dynamic library $@" + @$(STRIP) $(LIB_BUILD_DIR)/$@ +endif + @$(LN_S) -f $(LIB_BUILD_DIR)/$@ $@ + +%.so: %.so.$(VERSION) + @echo "Creating dynamic library version $@" + @rm -f $@ + @$(LN_S) $< $@ + +prog_%$(EXECEXT): %.o + @echo "Creating program $@" + @rm -f $@ + @$(LINK) -lfb $< -o $(BIN_BUILD_DIR)/$@ +ifneq (${DEBUG},true) + @echo "Stripping program $@" + @$(STRIP) $(BIN_BUILD_DIR)/$@ +endif + @$(LN_S) -f $(BIN_BUILD_DIR)/$@ $@ + +## Phony rule + +.PHONY: all install + +### Local Variables: *** +### mode: Makefile *** +### End: *** diff --git a/README b/README new file mode 100644 index 0000000..db00d0d --- /dev/null +++ b/README @@ -0,0 +1,65 @@ +LibViterbi -- a generic Viterbi algorythm + +Copyright (C) 2004 Laurent S. Mazet and Sebastien Simoens + +Last updated: Wed Feb 25 18:17:50 MET 2004 + + +Overview +-------- + +LibForwardBackward provides a generic Forward-Backward algorithm and a +short toolbox for convolutional encoder. + +Installation and Bugs +--------------------- + +To compile LibForwardBackward, you will need a recent version of GNU +Make, and a decent version of gcc and sed. + +See the notes in the files INSTALL and INSTALL.LIBFB for more specific +installation instructions, including directions for installing +LibForwardBackward from a binary distribution. + +The file BUGS contains a recommended procedure for reporting bugs, as +well as a list of known problems and possible fixes. + +Documentation +------------- + +LibForwardBackward documentation will be available on the doc +directory. Some test programs are also available on the test +directory. + +Performance +----------- + +On a PIII-600MHz, I got these bitrates for (o171, o133) coder: +- standard, no optimization: 105kbps +- one branch optimization: 148kbps +- two predecessors optimization: 190kps +- full optimizations: 246kbps + +Implementation +-------------- + +LibForwardBackward is being developed with the Free Software +Foundation's make, sed and gcc on an Intel Pentium III system running +Linux/GNU. It should be possible to install it on any machine that +runs GCC. It may also be possible to install it using other +implementations of these tools, but it will most certainly require +much more work. Do yourself a favor and get the GNU development tools, +either via anonymous ftp from ftp.gnu.org or by writing the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA +02111-1307, USA. + +Additional Information +---------------------- + +None. + +-- +Laurent S. Mazet +laurent.mazet@motorola.com +Centre de Recherche de Motorola +France diff --git a/aclocal.m4 b/aclocal.m4 new file mode 100644 index 0000000..91718c0 --- /dev/null +++ b/aclocal.m4 @@ -0,0 +1,71 @@ +dnl aclocal.m4 -- extra macros for configuring LibForwardBackward +dnl +dnl Copyright (C) 2004 Laurent Mazet and Sebastien Simoens +dnl +dnl This file is part of LibForwardBackward. +dnl +dnl -------------------------------------------------------------------- +dnl +dnl Check to see if C compiler handles FLAG command line option. Add +dnl FLAG to CCFLAGS if the compiler accepts the flag. +dnl +AC_DEFUN(LIBFB_CC_FLAG, [ + ac_safe=`echo "$1" | sed 'y%./+-%__p_%'` + AC_MSG_CHECKING(whether ${CC-gcc} accepts $1) + AC_CACHE_VAL(libfb_cv_cc_flag_$ac_safe, [ + AC_LANG_SAVE + AC_LANG([C++]) + XCCFLAGS="$CCFLAGS" + CCFLAGS="$CCFLAGS $1" + AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],[eval "libfb_cv_cc_flag_$ac_safe=yes"],[eval "libfb_cv_cc_flag_$ac_safe=no"]) + CCFLAGS="$XCCFLAGS" + AC_LANG_RESTORE + ]) + if eval "test \"`echo '$libfb_cv_cc_flag_'$ac_safe`\" = yes"; then + AC_MSG_RESULT(yes) + CCFLAGS="$CCFLAGS $1" + else + AC_MSG_RESULT(no) + fi +]) +dnl +dnl Check to see if C linker handles LDFLAG command line option. Add +dnl LDFLAG to LDFLAGS if the linker accepts the flag. +dnl +AC_DEFUN(LIBFB_CC_LDFLAG, [ + ac_safe=`echo "$1" | sed 'y%./+-%__p_%'` + AC_MSG_CHECKING(whether ${CC-gcc} accepts $1) + AC_CACHE_VAL(libfb_cv_cc_ldflag_$ac_safe, [ + AC_LANG_SAVE + AC_LANG([C++]) + XLDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS $1" + AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],[eval "libfb_cv_cc_ldflag_$ac_safe=yes"],[eval "libfb_cv_cc_ldflag_$ac_safe=no"]) + LDFLAGS="$XLDFLAGS" + AC_LANG_RESTORE + ]) + if eval "test \"`echo '$libfb_cv_cc_ldflag_'$ac_safe`\" = yes"; then + AC_MSG_RESULT(yes) + LDFLAGS="$LDFLAGS $1" + else + AC_MSG_RESULT(no) + fi +]) +dnl +dnl Check if file changes +dnl +AC_DEFUN(LIBFB_CHECK_CHANGE, [ + orig="$1" + new="$2" + if test -f "$orig"; then + if test -z "`diff \"$orig\" \"$new\"`"; then + AC_MSG_RESULT("$orig is unchanged") + rm "$new" + else + rm "$orig" + mv "$new" "$orig" + fi + else + mv "$new" "$orig" + fi +]) diff --git a/config.guess b/config.guess new file mode 100755 index 0000000..7f76b62 --- /dev/null +++ b/config.guess @@ -0,0 +1,1754 @@ +#! /bin/sh +# Attempt to guess a canonical system name. +# Copyright 1992-2022 Free Software Foundation, Inc. + +# shellcheck disable=SC2006,SC2268 # see below for rationale + +timestamp='2022-01-09' + +# This file is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 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, see . +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that +# program. This Exception is an additional permission under section 7 +# of the GNU General Public License, version 3 ("GPLv3"). +# +# Originally written by Per Bothner; maintained since 2000 by Ben Elliston. +# +# You can get the latest version of this script from: +# https://git.savannah.gnu.org/cgit/config.git/plain/config.guess +# +# Please send patches to . + + +# The "shellcheck disable" line above the timestamp inhibits complaints +# about features and limitations of the classic Bourne shell that were +# superseded or lifted in POSIX. However, this script identifies a wide +# variety of pre-POSIX systems that do not have POSIX shells at all, and +# even some reasonably current systems (Solaris 10 as case-in-point) still +# have a pre-POSIX /bin/sh. + + +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] + +Output the configuration name of the system \`$me' is run on. + +Options: + -h, --help print this help, then exit + -t, --time-stamp print date of last modification, then exit + -v, --version print version number, then exit + +Report bugs and patches to ." + +version="\ +GNU config.guess ($timestamp) + +Originally written by Per Bothner. +Copyright 1992-2022 Free Software Foundation, Inc. + +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + +help=" +Try \`$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case $1 in + --time-stamp | --time* | -t ) + echo "$timestamp" ; exit ;; + --version | -v ) + echo "$version" ; exit ;; + --help | --h* | -h ) + echo "$usage"; exit ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + echo "$me: invalid option $1$help" >&2 + exit 1 ;; + * ) + break ;; + esac +done + +if test $# != 0; then + echo "$me: too many arguments$help" >&2 + exit 1 +fi + +# Just in case it came from the environment. +GUESS= + +# CC_FOR_BUILD -- compiler used by this script. Note that the use of a +# compiler to aid in system detection is discouraged as it requires +# temporary files to be created and, as you can see below, it is a +# headache to deal with in a portable fashion. + +# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still +# use `HOST_CC' if defined, but it is deprecated. + +# Portable tmp directory creation inspired by the Autoconf team. + +tmp= +# shellcheck disable=SC2172 +trap 'test -z "$tmp" || rm -fr "$tmp"' 0 1 2 13 15 + +set_cc_for_build() { + # prevent multiple calls if $tmp is already set + test "$tmp" && return 0 + : "${TMPDIR=/tmp}" + # shellcheck disable=SC2039,SC3028 + { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || + { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir "$tmp" 2>/dev/null) ; } || + { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir "$tmp" 2>/dev/null) && echo "Warning: creating insecure temp directory" >&2 ; } || + { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } + dummy=$tmp/dummy + case ${CC_FOR_BUILD-},${HOST_CC-},${CC-} in + ,,) echo "int x;" > "$dummy.c" + for driver in cc gcc c89 c99 ; do + if ($driver -c -o "$dummy.o" "$dummy.c") >/dev/null 2>&1 ; then + CC_FOR_BUILD=$driver + break + fi + done + if test x"$CC_FOR_BUILD" = x ; then + CC_FOR_BUILD=no_compiler_found + fi + ;; + ,,*) CC_FOR_BUILD=$CC ;; + ,*,*) CC_FOR_BUILD=$HOST_CC ;; + esac +} + +# This is needed to find uname on a Pyramid OSx when run in the BSD universe. +# (ghazi@noc.rutgers.edu 1994-08-24) +if test -f /.attbin/uname ; then + PATH=$PATH:/.attbin ; export PATH +fi + +UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown +UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown +UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown +UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown + +case $UNAME_SYSTEM in +Linux|GNU|GNU/*) + LIBC=unknown + + set_cc_for_build + cat <<-EOF > "$dummy.c" + #include + #if defined(__UCLIBC__) + LIBC=uclibc + #elif defined(__dietlibc__) + LIBC=dietlibc + #elif defined(__GLIBC__) + LIBC=gnu + #else + #include + /* First heuristic to detect musl libc. */ + #ifdef __DEFINED_va_list + LIBC=musl + #endif + #endif + EOF + cc_set_libc=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^LIBC' | sed 's, ,,g'` + eval "$cc_set_libc" + + # Second heuristic to detect musl libc. + if [ "$LIBC" = unknown ] && + command -v ldd >/dev/null && + ldd --version 2>&1 | grep -q ^musl; then + LIBC=musl + fi + + # If the system lacks a compiler, then just pick glibc. + # We could probably try harder. + if [ "$LIBC" = unknown ]; then + LIBC=gnu + fi + ;; +esac + +# Note: order is significant - the case branches are not exclusive. + +case $UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION in + *:NetBSD:*:*) + # NetBSD (nbsd) targets should (where applicable) match one or + # more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*, + # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently + # switched to ELF, *-*-netbsd* would select the old + # object file format. This provides both forward + # compatibility and a consistent mechanism for selecting the + # object file format. + # + # Note: NetBSD doesn't particularly care about the vendor + # portion of the name. We always set it to "unknown". + UNAME_MACHINE_ARCH=`(uname -p 2>/dev/null || \ + /sbin/sysctl -n hw.machine_arch 2>/dev/null || \ + /usr/sbin/sysctl -n hw.machine_arch 2>/dev/null || \ + echo unknown)` + case $UNAME_MACHINE_ARCH in + aarch64eb) machine=aarch64_be-unknown ;; + armeb) machine=armeb-unknown ;; + arm*) machine=arm-unknown ;; + sh3el) machine=shl-unknown ;; + sh3eb) machine=sh-unknown ;; + sh5el) machine=sh5le-unknown ;; + earmv*) + arch=`echo "$UNAME_MACHINE_ARCH" | sed -e 's,^e\(armv[0-9]\).*$,\1,'` + endian=`echo "$UNAME_MACHINE_ARCH" | sed -ne 's,^.*\(eb\)$,\1,p'` + machine=${arch}${endian}-unknown + ;; + *) machine=$UNAME_MACHINE_ARCH-unknown ;; + esac + # The Operating System including object format, if it has switched + # to ELF recently (or will in the future) and ABI. + case $UNAME_MACHINE_ARCH in + earm*) + os=netbsdelf + ;; + arm*|i386|m68k|ns32k|sh3*|sparc|vax) + set_cc_for_build + if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep -q __ELF__ + then + # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). + # Return netbsd for either. FIX? + os=netbsd + else + os=netbsdelf + fi + ;; + *) + os=netbsd + ;; + esac + # Determine ABI tags. + case $UNAME_MACHINE_ARCH in + earm*) + expr='s/^earmv[0-9]/-eabi/;s/eb$//' + abi=`echo "$UNAME_MACHINE_ARCH" | sed -e "$expr"` + ;; + esac + # The OS release + # Debian GNU/NetBSD machines have a different userland, and + # thus, need a distinct triplet. However, they do not need + # kernel version information, so it can be replaced with a + # suitable tag, in the style of linux-gnu. + case $UNAME_VERSION in + Debian*) + release='-gnu' + ;; + *) + release=`echo "$UNAME_RELEASE" | sed -e 's/[-_].*//' | cut -d. -f1,2` + ;; + esac + # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: + # contains redundant information, the shorter form: + # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. + GUESS=$machine-${os}${release}${abi-} + ;; + *:Bitrig:*:*) + UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'` + GUESS=$UNAME_MACHINE_ARCH-unknown-bitrig$UNAME_RELEASE + ;; + *:OpenBSD:*:*) + UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` + GUESS=$UNAME_MACHINE_ARCH-unknown-openbsd$UNAME_RELEASE + ;; + *:SecBSD:*:*) + UNAME_MACHINE_ARCH=`arch | sed 's/SecBSD.//'` + GUESS=$UNAME_MACHINE_ARCH-unknown-secbsd$UNAME_RELEASE + ;; + *:LibertyBSD:*:*) + UNAME_MACHINE_ARCH=`arch | sed 's/^.*BSD\.//'` + GUESS=$UNAME_MACHINE_ARCH-unknown-libertybsd$UNAME_RELEASE + ;; + *:MidnightBSD:*:*) + GUESS=$UNAME_MACHINE-unknown-midnightbsd$UNAME_RELEASE + ;; + *:ekkoBSD:*:*) + GUESS=$UNAME_MACHINE-unknown-ekkobsd$UNAME_RELEASE + ;; + *:SolidBSD:*:*) + GUESS=$UNAME_MACHINE-unknown-solidbsd$UNAME_RELEASE + ;; + *:OS108:*:*) + GUESS=$UNAME_MACHINE-unknown-os108_$UNAME_RELEASE + ;; + macppc:MirBSD:*:*) + GUESS=powerpc-unknown-mirbsd$UNAME_RELEASE + ;; + *:MirBSD:*:*) + GUESS=$UNAME_MACHINE-unknown-mirbsd$UNAME_RELEASE + ;; + *:Sortix:*:*) + GUESS=$UNAME_MACHINE-unknown-sortix + ;; + *:Twizzler:*:*) + GUESS=$UNAME_MACHINE-unknown-twizzler + ;; + *:Redox:*:*) + GUESS=$UNAME_MACHINE-unknown-redox + ;; + mips:OSF1:*.*) + GUESS=mips-dec-osf1 + ;; + alpha:OSF1:*:*) + # Reset EXIT trap before exiting to avoid spurious non-zero exit code. + trap '' 0 + case $UNAME_RELEASE in + *4.0) + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` + ;; + *5.*) + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` + ;; + esac + # According to Compaq, /usr/sbin/psrinfo has been available on + # OSF/1 and Tru64 systems produced since 1995. I hope that + # covers most systems running today. This code pipes the CPU + # types through head -n 1, so we only detect the type of CPU 0. + ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` + case $ALPHA_CPU_TYPE in + "EV4 (21064)") + UNAME_MACHINE=alpha ;; + "EV4.5 (21064)") + UNAME_MACHINE=alpha ;; + "LCA4 (21066/21068)") + UNAME_MACHINE=alpha ;; + "EV5 (21164)") + UNAME_MACHINE=alphaev5 ;; + "EV5.6 (21164A)") + UNAME_MACHINE=alphaev56 ;; + "EV5.6 (21164PC)") + UNAME_MACHINE=alphapca56 ;; + "EV5.7 (21164PC)") + UNAME_MACHINE=alphapca57 ;; + "EV6 (21264)") + UNAME_MACHINE=alphaev6 ;; + "EV6.7 (21264A)") + UNAME_MACHINE=alphaev67 ;; + "EV6.8CB (21264C)") + UNAME_MACHINE=alphaev68 ;; + "EV6.8AL (21264B)") + UNAME_MACHINE=alphaev68 ;; + "EV6.8CX (21264D)") + UNAME_MACHINE=alphaev68 ;; + "EV6.9A (21264/EV69A)") + UNAME_MACHINE=alphaev69 ;; + "EV7 (21364)") + UNAME_MACHINE=alphaev7 ;; + "EV7.9 (21364A)") + UNAME_MACHINE=alphaev79 ;; + esac + # A Pn.n version is a patched version. + # A Vn.n version is a released version. + # A Tn.n version is a released field test version. + # A Xn.n version is an unreleased experimental baselevel. + # 1.2 uses "1.2" for uname -r. + OSF_REL=`echo "$UNAME_RELEASE" | sed -e 's/^[PVTX]//' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz` + GUESS=$UNAME_MACHINE-dec-osf$OSF_REL + ;; + Amiga*:UNIX_System_V:4.0:*) + GUESS=m68k-unknown-sysv4 + ;; + *:[Aa]miga[Oo][Ss]:*:*) + GUESS=$UNAME_MACHINE-unknown-amigaos + ;; + *:[Mm]orph[Oo][Ss]:*:*) + GUESS=$UNAME_MACHINE-unknown-morphos + ;; + *:OS/390:*:*) + GUESS=i370-ibm-openedition + ;; + *:z/VM:*:*) + GUESS=s390-ibm-zvmoe + ;; + *:OS400:*:*) + GUESS=powerpc-ibm-os400 + ;; + arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) + GUESS=arm-acorn-riscix$UNAME_RELEASE + ;; + arm*:riscos:*:*|arm*:RISCOS:*:*) + GUESS=arm-unknown-riscos + ;; + SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) + GUESS=hppa1.1-hitachi-hiuxmpp + ;; + Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) + # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. + case `(/bin/universe) 2>/dev/null` in + att) GUESS=pyramid-pyramid-sysv3 ;; + *) GUESS=pyramid-pyramid-bsd ;; + esac + ;; + NILE*:*:*:dcosx) + GUESS=pyramid-pyramid-svr4 + ;; + DRS?6000:unix:4.0:6*) + GUESS=sparc-icl-nx6 + ;; + DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) + case `/usr/bin/uname -p` in + sparc) GUESS=sparc-icl-nx7 ;; + esac + ;; + s390x:SunOS:*:*) + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` + GUESS=$UNAME_MACHINE-ibm-solaris2$SUN_REL + ;; + sun4H:SunOS:5.*:*) + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` + GUESS=sparc-hal-solaris2$SUN_REL + ;; + sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` + GUESS=sparc-sun-solaris2$SUN_REL + ;; + i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*) + GUESS=i386-pc-auroraux$UNAME_RELEASE + ;; + i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) + set_cc_for_build + SUN_ARCH=i386 + # If there is a compiler, see if it is configured for 64-bit objects. + # Note that the Sun cc does not turn __LP64__ into 1 like gcc does. + # This test works for both compilers. + if test "$CC_FOR_BUILD" != no_compiler_found; then + if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \ + (CCOPTS="" $CC_FOR_BUILD -m64 -E - 2>/dev/null) | \ + grep IS_64BIT_ARCH >/dev/null + then + SUN_ARCH=x86_64 + fi + fi + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` + GUESS=$SUN_ARCH-pc-solaris2$SUN_REL + ;; + sun4*:SunOS:6*:*) + # According to config.sub, this is the proper way to canonicalize + # SunOS6. Hard to guess exactly what SunOS6 will be like, but + # it's likely to be more like Solaris than SunOS4. + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` + GUESS=sparc-sun-solaris3$SUN_REL + ;; + sun4*:SunOS:*:*) + case `/usr/bin/arch -k` in + Series*|S4*) + UNAME_RELEASE=`uname -v` + ;; + esac + # Japanese Language versions have a version number like `4.1.3-JL'. + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/-/_/'` + GUESS=sparc-sun-sunos$SUN_REL + ;; + sun3*:SunOS:*:*) + GUESS=m68k-sun-sunos$UNAME_RELEASE + ;; + sun*:*:4.2BSD:*) + UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` + test "x$UNAME_RELEASE" = x && UNAME_RELEASE=3 + case `/bin/arch` in + sun3) + GUESS=m68k-sun-sunos$UNAME_RELEASE + ;; + sun4) + GUESS=sparc-sun-sunos$UNAME_RELEASE + ;; + esac + ;; + aushp:SunOS:*:*) + GUESS=sparc-auspex-sunos$UNAME_RELEASE + ;; + # The situation for MiNT is a little confusing. The machine name + # can be virtually everything (everything which is not + # "atarist" or "atariste" at least should have a processor + # > m68000). The system name ranges from "MiNT" over "FreeMiNT" + # to the lowercase version "mint" (or "freemint"). Finally + # the system name "TOS" denotes a system which is actually not + # MiNT. But MiNT is downward compatible to TOS, so this should + # be no problem. + atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) + GUESS=m68k-atari-mint$UNAME_RELEASE + ;; + atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) + GUESS=m68k-atari-mint$UNAME_RELEASE + ;; + *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) + GUESS=m68k-atari-mint$UNAME_RELEASE + ;; + milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) + GUESS=m68k-milan-mint$UNAME_RELEASE + ;; + hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) + GUESS=m68k-hades-mint$UNAME_RELEASE + ;; + *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) + GUESS=m68k-unknown-mint$UNAME_RELEASE + ;; + m68k:machten:*:*) + GUESS=m68k-apple-machten$UNAME_RELEASE + ;; + powerpc:machten:*:*) + GUESS=powerpc-apple-machten$UNAME_RELEASE + ;; + RISC*:Mach:*:*) + GUESS=mips-dec-mach_bsd4.3 + ;; + RISC*:ULTRIX:*:*) + GUESS=mips-dec-ultrix$UNAME_RELEASE + ;; + VAX*:ULTRIX*:*:*) + GUESS=vax-dec-ultrix$UNAME_RELEASE + ;; + 2020:CLIX:*:* | 2430:CLIX:*:*) + GUESS=clipper-intergraph-clix$UNAME_RELEASE + ;; + mips:*:*:UMIPS | mips:*:*:RISCos) + set_cc_for_build + sed 's/^ //' << EOF > "$dummy.c" +#ifdef __cplusplus +#include /* for printf() prototype */ + int main (int argc, char *argv[]) { +#else + int main (argc, argv) int argc; char *argv[]; { +#endif + #if defined (host_mips) && defined (MIPSEB) + #if defined (SYSTYPE_SYSV) + printf ("mips-mips-riscos%ssysv\\n", argv[1]); exit (0); + #endif + #if defined (SYSTYPE_SVR4) + printf ("mips-mips-riscos%ssvr4\\n", argv[1]); exit (0); + #endif + #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) + printf ("mips-mips-riscos%sbsd\\n", argv[1]); exit (0); + #endif + #endif + exit (-1); + } +EOF + $CC_FOR_BUILD -o "$dummy" "$dummy.c" && + dummyarg=`echo "$UNAME_RELEASE" | sed -n 's/\([0-9]*\).*/\1/p'` && + SYSTEM_NAME=`"$dummy" "$dummyarg"` && + { echo "$SYSTEM_NAME"; exit; } + GUESS=mips-mips-riscos$UNAME_RELEASE + ;; + Motorola:PowerMAX_OS:*:*) + GUESS=powerpc-motorola-powermax + ;; + Motorola:*:4.3:PL8-*) + GUESS=powerpc-harris-powermax + ;; + Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) + GUESS=powerpc-harris-powermax + ;; + Night_Hawk:Power_UNIX:*:*) + GUESS=powerpc-harris-powerunix + ;; + m88k:CX/UX:7*:*) + GUESS=m88k-harris-cxux7 + ;; + m88k:*:4*:R4*) + GUESS=m88k-motorola-sysv4 + ;; + m88k:*:3*:R3*) + GUESS=m88k-motorola-sysv3 + ;; + AViiON:dgux:*:*) + # DG/UX returns AViiON for all architectures + UNAME_PROCESSOR=`/usr/bin/uname -p` + if test "$UNAME_PROCESSOR" = mc88100 || test "$UNAME_PROCESSOR" = mc88110 + then + if test "$TARGET_BINARY_INTERFACE"x = m88kdguxelfx || \ + test "$TARGET_BINARY_INTERFACE"x = x + then + GUESS=m88k-dg-dgux$UNAME_RELEASE + else + GUESS=m88k-dg-dguxbcs$UNAME_RELEASE + fi + else + GUESS=i586-dg-dgux$UNAME_RELEASE + fi + ;; + M88*:DolphinOS:*:*) # DolphinOS (SVR3) + GUESS=m88k-dolphin-sysv3 + ;; + M88*:*:R3*:*) + # Delta 88k system running SVR3 + GUESS=m88k-motorola-sysv3 + ;; + XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) + GUESS=m88k-tektronix-sysv3 + ;; + Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) + GUESS=m68k-tektronix-bsd + ;; + *:IRIX*:*:*) + IRIX_REL=`echo "$UNAME_RELEASE" | sed -e 's/-/_/g'` + GUESS=mips-sgi-irix$IRIX_REL + ;; + ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. + GUESS=romp-ibm-aix # uname -m gives an 8 hex-code CPU id + ;; # Note that: echo "'`uname -s`'" gives 'AIX ' + i*86:AIX:*:*) + GUESS=i386-ibm-aix + ;; + ia64:AIX:*:*) + if test -x /usr/bin/oslevel ; then + IBM_REV=`/usr/bin/oslevel` + else + IBM_REV=$UNAME_VERSION.$UNAME_RELEASE + fi + GUESS=$UNAME_MACHINE-ibm-aix$IBM_REV + ;; + *:AIX:2:3) + if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then + set_cc_for_build + sed 's/^ //' << EOF > "$dummy.c" + #include + + main() + { + if (!__power_pc()) + exit(1); + puts("powerpc-ibm-aix3.2.5"); + exit(0); + } +EOF + if $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"` + then + GUESS=$SYSTEM_NAME + else + GUESS=rs6000-ibm-aix3.2.5 + fi + elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then + GUESS=rs6000-ibm-aix3.2.4 + else + GUESS=rs6000-ibm-aix3.2 + fi + ;; + *:AIX:*:[4567]) + IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` + if /usr/sbin/lsattr -El "$IBM_CPU_ID" | grep ' POWER' >/dev/null 2>&1; then + IBM_ARCH=rs6000 + else + IBM_ARCH=powerpc + fi + if test -x /usr/bin/lslpp ; then + IBM_REV=`/usr/bin/lslpp -Lqc bos.rte.libc | \ + awk -F: '{ print $3 }' | sed s/[0-9]*$/0/` + else + IBM_REV=$UNAME_VERSION.$UNAME_RELEASE + fi + GUESS=$IBM_ARCH-ibm-aix$IBM_REV + ;; + *:AIX:*:*) + GUESS=rs6000-ibm-aix + ;; + ibmrt:4.4BSD:*|romp-ibm:4.4BSD:*) + GUESS=romp-ibm-bsd4.4 + ;; + ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and + GUESS=romp-ibm-bsd$UNAME_RELEASE # 4.3 with uname added to + ;; # report: romp-ibm BSD 4.3 + *:BOSX:*:*) + GUESS=rs6000-bull-bosx + ;; + DPX/2?00:B.O.S.:*:*) + GUESS=m68k-bull-sysv3 + ;; + 9000/[34]??:4.3bsd:1.*:*) + GUESS=m68k-hp-bsd + ;; + hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) + GUESS=m68k-hp-bsd4.4 + ;; + 9000/[34678]??:HP-UX:*:*) + HPUX_REV=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*.[0B]*//'` + case $UNAME_MACHINE in + 9000/31?) HP_ARCH=m68000 ;; + 9000/[34]??) HP_ARCH=m68k ;; + 9000/[678][0-9][0-9]) + if test -x /usr/bin/getconf; then + sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` + sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` + case $sc_cpu_version in + 523) HP_ARCH=hppa1.0 ;; # CPU_PA_RISC1_0 + 528) HP_ARCH=hppa1.1 ;; # CPU_PA_RISC1_1 + 532) # CPU_PA_RISC2_0 + case $sc_kernel_bits in + 32) HP_ARCH=hppa2.0n ;; + 64) HP_ARCH=hppa2.0w ;; + '') HP_ARCH=hppa2.0 ;; # HP-UX 10.20 + esac ;; + esac + fi + if test "$HP_ARCH" = ""; then + set_cc_for_build + sed 's/^ //' << EOF > "$dummy.c" + + #define _HPUX_SOURCE + #include + #include + + int main () + { + #if defined(_SC_KERNEL_BITS) + long bits = sysconf(_SC_KERNEL_BITS); + #endif + long cpu = sysconf (_SC_CPU_VERSION); + + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1"); break; + case CPU_PA_RISC2_0: + #if defined(_SC_KERNEL_BITS) + switch (bits) + { + case 64: puts ("hppa2.0w"); break; + case 32: puts ("hppa2.0n"); break; + default: puts ("hppa2.0"); break; + } break; + #else /* !defined(_SC_KERNEL_BITS) */ + puts ("hppa2.0"); break; + #endif + default: puts ("hppa1.0"); break; + } + exit (0); + } +EOF + (CCOPTS="" $CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null) && HP_ARCH=`"$dummy"` + test -z "$HP_ARCH" && HP_ARCH=hppa + fi ;; + esac + if test "$HP_ARCH" = hppa2.0w + then + set_cc_for_build + + # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating + # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler + # generating 64-bit code. GNU and HP use different nomenclature: + # + # $ CC_FOR_BUILD=cc ./config.guess + # => hppa2.0w-hp-hpux11.23 + # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess + # => hppa64-hp-hpux11.23 + + if echo __LP64__ | (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | + grep -q __LP64__ + then + HP_ARCH=hppa2.0w + else + HP_ARCH=hppa64 + fi + fi + GUESS=$HP_ARCH-hp-hpux$HPUX_REV + ;; + ia64:HP-UX:*:*) + HPUX_REV=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*.[0B]*//'` + GUESS=ia64-hp-hpux$HPUX_REV + ;; + 3050*:HI-UX:*:*) + set_cc_for_build + sed 's/^ //' << EOF > "$dummy.c" + #include + int + main () + { + long cpu = sysconf (_SC_CPU_VERSION); + /* The order matters, because CPU_IS_HP_MC68K erroneously returns + true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct + results, however. */ + if (CPU_IS_PA_RISC (cpu)) + { + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; + case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; + default: puts ("hppa-hitachi-hiuxwe2"); break; + } + } + else if (CPU_IS_HP_MC68K (cpu)) + puts ("m68k-hitachi-hiuxwe2"); + else puts ("unknown-hitachi-hiuxwe2"); + exit (0); + } +EOF + $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"` && + { echo "$SYSTEM_NAME"; exit; } + GUESS=unknown-hitachi-hiuxwe2 + ;; + 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:*) + GUESS=hppa1.1-hp-bsd + ;; + 9000/8??:4.3bsd:*:*) + GUESS=hppa1.0-hp-bsd + ;; + *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) + GUESS=hppa1.0-hp-mpeix + ;; + hp7??:OSF1:*:* | hp8?[79]:OSF1:*:*) + GUESS=hppa1.1-hp-osf + ;; + hp8??:OSF1:*:*) + GUESS=hppa1.0-hp-osf + ;; + i*86:OSF1:*:*) + if test -x /usr/sbin/sysversion ; then + GUESS=$UNAME_MACHINE-unknown-osf1mk + else + GUESS=$UNAME_MACHINE-unknown-osf1 + fi + ;; + parisc*:Lites*:*:*) + GUESS=hppa1.1-hp-lites + ;; + C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) + GUESS=c1-convex-bsd + ;; + C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit ;; + C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) + GUESS=c34-convex-bsd + ;; + C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) + GUESS=c38-convex-bsd + ;; + C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) + GUESS=c4-convex-bsd + ;; + CRAY*Y-MP:*:*:*) + CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` + GUESS=ymp-cray-unicos$CRAY_REL + ;; + CRAY*[A-Z]90:*:*:*) + echo "$UNAME_MACHINE"-cray-unicos"$UNAME_RELEASE" \ + | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ + -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ + -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*TS:*:*:*) + CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` + GUESS=t90-cray-unicos$CRAY_REL + ;; + CRAY*T3E:*:*:*) + CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` + GUESS=alphaev5-cray-unicosmk$CRAY_REL + ;; + CRAY*SV1:*:*:*) + CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` + GUESS=sv1-cray-unicos$CRAY_REL + ;; + *:UNICOS/mp:*:*) + CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` + GUESS=craynv-cray-unicosmp$CRAY_REL + ;; + F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) + FUJITSU_PROC=`uname -m | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz` + FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'` + FUJITSU_REL=`echo "$UNAME_RELEASE" | sed -e 's/ /_/'` + GUESS=${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL} + ;; + 5000:UNIX_System_V:4.*:*) + FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'` + FUJITSU_REL=`echo "$UNAME_RELEASE" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/ /_/'` + GUESS=sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL} + ;; + i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) + GUESS=$UNAME_MACHINE-pc-bsdi$UNAME_RELEASE + ;; + sparc*:BSD/OS:*:*) + GUESS=sparc-unknown-bsdi$UNAME_RELEASE + ;; + *:BSD/OS:*:*) + GUESS=$UNAME_MACHINE-unknown-bsdi$UNAME_RELEASE + ;; + arm:FreeBSD:*:*) + UNAME_PROCESSOR=`uname -p` + set_cc_for_build + if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep -q __ARM_PCS_VFP + then + FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` + GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL-gnueabi + else + FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` + GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL-gnueabihf + fi + ;; + *:FreeBSD:*:*) + UNAME_PROCESSOR=`/usr/bin/uname -p` + case $UNAME_PROCESSOR in + amd64) + UNAME_PROCESSOR=x86_64 ;; + i386) + UNAME_PROCESSOR=i586 ;; + esac + FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` + GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL + ;; + i*:CYGWIN*:*) + GUESS=$UNAME_MACHINE-pc-cygwin + ;; + *:MINGW64*:*) + GUESS=$UNAME_MACHINE-pc-mingw64 + ;; + *:MINGW*:*) + GUESS=$UNAME_MACHINE-pc-mingw32 + ;; + *:MSYS*:*) + GUESS=$UNAME_MACHINE-pc-msys + ;; + i*:PW*:*) + GUESS=$UNAME_MACHINE-pc-pw32 + ;; + *:SerenityOS:*:*) + GUESS=$UNAME_MACHINE-pc-serenity + ;; + *:Interix*:*) + case $UNAME_MACHINE in + x86) + GUESS=i586-pc-interix$UNAME_RELEASE + ;; + authenticamd | genuineintel | EM64T) + GUESS=x86_64-unknown-interix$UNAME_RELEASE + ;; + IA64) + GUESS=ia64-unknown-interix$UNAME_RELEASE + ;; + esac ;; + i*:UWIN*:*) + GUESS=$UNAME_MACHINE-pc-uwin + ;; + amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) + GUESS=x86_64-pc-cygwin + ;; + prep*:SunOS:5.*:*) + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` + GUESS=powerpcle-unknown-solaris2$SUN_REL + ;; + *:GNU:*:*) + # the GNU system + GNU_ARCH=`echo "$UNAME_MACHINE" | sed -e 's,[-/].*$,,'` + GNU_REL=`echo "$UNAME_RELEASE" | sed -e 's,/.*$,,'` + GUESS=$GNU_ARCH-unknown-$LIBC$GNU_REL + ;; + *:GNU/*:*:*) + # other systems with GNU libc and userland + GNU_SYS=`echo "$UNAME_SYSTEM" | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]"` + GNU_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` + GUESS=$UNAME_MACHINE-unknown-$GNU_SYS$GNU_REL-$LIBC + ;; + *:Minix:*:*) + GUESS=$UNAME_MACHINE-unknown-minix + ;; + aarch64:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + aarch64_be:Linux:*:*) + UNAME_MACHINE=aarch64_be + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + alpha:Linux:*:*) + case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' /proc/cpuinfo 2>/dev/null` in + EV5) UNAME_MACHINE=alphaev5 ;; + EV56) UNAME_MACHINE=alphaev56 ;; + PCA56) UNAME_MACHINE=alphapca56 ;; + PCA57) UNAME_MACHINE=alphapca56 ;; + EV6) UNAME_MACHINE=alphaev6 ;; + EV67) UNAME_MACHINE=alphaev67 ;; + EV68*) UNAME_MACHINE=alphaev68 ;; + esac + objdump --private-headers /bin/sh | grep -q ld.so.1 + if test "$?" = 0 ; then LIBC=gnulibc1 ; fi + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + arc:Linux:*:* | arceb:Linux:*:* | arc32:Linux:*:* | arc64:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + arm*:Linux:*:*) + set_cc_for_build + if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep -q __ARM_EABI__ + then + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + else + if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep -q __ARM_PCS_VFP + then + GUESS=$UNAME_MACHINE-unknown-linux-${LIBC}eabi + else + GUESS=$UNAME_MACHINE-unknown-linux-${LIBC}eabihf + fi + fi + ;; + avr32*:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + cris:Linux:*:*) + GUESS=$UNAME_MACHINE-axis-linux-$LIBC + ;; + crisv32:Linux:*:*) + GUESS=$UNAME_MACHINE-axis-linux-$LIBC + ;; + e2k:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + frv:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + hexagon:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + i*86:Linux:*:*) + GUESS=$UNAME_MACHINE-pc-linux-$LIBC + ;; + ia64:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + k1om:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + loongarch32:Linux:*:* | loongarch64:Linux:*:* | loongarchx32:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + m32r*:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + m68*:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + mips:Linux:*:* | mips64:Linux:*:*) + set_cc_for_build + IS_GLIBC=0 + test x"${LIBC}" = xgnu && IS_GLIBC=1 + sed 's/^ //' << EOF > "$dummy.c" + #undef CPU + #undef mips + #undef mipsel + #undef mips64 + #undef mips64el + #if ${IS_GLIBC} && defined(_ABI64) + LIBCABI=gnuabi64 + #else + #if ${IS_GLIBC} && defined(_ABIN32) + LIBCABI=gnuabin32 + #else + LIBCABI=${LIBC} + #endif + #endif + + #if ${IS_GLIBC} && defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6 + CPU=mipsisa64r6 + #else + #if ${IS_GLIBC} && !defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6 + CPU=mipsisa32r6 + #else + #if defined(__mips64) + CPU=mips64 + #else + CPU=mips + #endif + #endif + #endif + + #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) + MIPS_ENDIAN=el + #else + #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) + MIPS_ENDIAN= + #else + MIPS_ENDIAN= + #endif + #endif +EOF + cc_set_vars=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^CPU\|^MIPS_ENDIAN\|^LIBCABI'` + eval "$cc_set_vars" + test "x$CPU" != x && { echo "$CPU${MIPS_ENDIAN}-unknown-linux-$LIBCABI"; exit; } + ;; + mips64el:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + openrisc*:Linux:*:*) + GUESS=or1k-unknown-linux-$LIBC + ;; + or32:Linux:*:* | or1k*:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + padre:Linux:*:*) + GUESS=sparc-unknown-linux-$LIBC + ;; + parisc64:Linux:*:* | hppa64:Linux:*:*) + GUESS=hppa64-unknown-linux-$LIBC + ;; + parisc:Linux:*:* | hppa:Linux:*:*) + # Look for CPU level + case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in + PA7*) GUESS=hppa1.1-unknown-linux-$LIBC ;; + PA8*) GUESS=hppa2.0-unknown-linux-$LIBC ;; + *) GUESS=hppa-unknown-linux-$LIBC ;; + esac + ;; + ppc64:Linux:*:*) + GUESS=powerpc64-unknown-linux-$LIBC + ;; + ppc:Linux:*:*) + GUESS=powerpc-unknown-linux-$LIBC + ;; + ppc64le:Linux:*:*) + GUESS=powerpc64le-unknown-linux-$LIBC + ;; + ppcle:Linux:*:*) + GUESS=powerpcle-unknown-linux-$LIBC + ;; + riscv32:Linux:*:* | riscv32be:Linux:*:* | riscv64:Linux:*:* | riscv64be:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + s390:Linux:*:* | s390x:Linux:*:*) + GUESS=$UNAME_MACHINE-ibm-linux-$LIBC + ;; + sh64*:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + sh*:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + sparc:Linux:*:* | sparc64:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + tile*:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + vax:Linux:*:*) + GUESS=$UNAME_MACHINE-dec-linux-$LIBC + ;; + x86_64:Linux:*:*) + set_cc_for_build + LIBCABI=$LIBC + if test "$CC_FOR_BUILD" != no_compiler_found; then + if (echo '#ifdef __ILP32__'; echo IS_X32; echo '#endif') | \ + (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_X32 >/dev/null + then + LIBCABI=${LIBC}x32 + fi + fi + GUESS=$UNAME_MACHINE-pc-linux-$LIBCABI + ;; + xtensa*:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + i*86:DYNIX/ptx:4*:*) + # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. + # earlier versions are messed up and put the nodename in both + # sysname and nodename. + GUESS=i386-sequent-sysv4 + ;; + i*86:UNIX_SV:4.2MP:2.*) + # Unixware is an offshoot of SVR4, but it has its own version + # number series starting with 2... + # I am not positive that other SVR4 systems won't match this, + # I just have to hope. -- rms. + # Use sysv4.2uw... so that sysv4* matches it. + GUESS=$UNAME_MACHINE-pc-sysv4.2uw$UNAME_VERSION + ;; + i*86:OS/2:*:*) + # If we were able to find `uname', then EMX Unix compatibility + # is probably installed. + GUESS=$UNAME_MACHINE-pc-os2-emx + ;; + i*86:XTS-300:*:STOP) + GUESS=$UNAME_MACHINE-unknown-stop + ;; + i*86:atheos:*:*) + GUESS=$UNAME_MACHINE-unknown-atheos + ;; + i*86:syllable:*:*) + GUESS=$UNAME_MACHINE-pc-syllable + ;; + i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*) + GUESS=i386-unknown-lynxos$UNAME_RELEASE + ;; + i*86:*DOS:*:*) + GUESS=$UNAME_MACHINE-pc-msdosdjgpp + ;; + i*86:*:4.*:*) + UNAME_REL=`echo "$UNAME_RELEASE" | sed 's/\/MP$//'` + if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then + GUESS=$UNAME_MACHINE-univel-sysv$UNAME_REL + else + GUESS=$UNAME_MACHINE-pc-sysv$UNAME_REL + fi + ;; + i*86:*:5:[678]*) + # UnixWare 7.x, OpenUNIX and OpenServer 6. + case `/bin/uname -X | grep "^Machine"` in + *486*) UNAME_MACHINE=i486 ;; + *Pentium) UNAME_MACHINE=i586 ;; + *Pent*|*Celeron) UNAME_MACHINE=i686 ;; + esac + GUESS=$UNAME_MACHINE-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} + ;; + i*86:*:3.2:*) + if test -f /usr/options/cb.name; then + UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then + UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` + (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 + (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ + && UNAME_MACHINE=i586 + (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \ + && UNAME_MACHINE=i686 + (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ + && UNAME_MACHINE=i686 + GUESS=$UNAME_MACHINE-pc-sco$UNAME_REL + else + GUESS=$UNAME_MACHINE-pc-sysv32 + fi + ;; + pc:*:*:*) + # Left here for compatibility: + # uname -m prints for DJGPP always 'pc', but it prints nothing about + # the processor, so we play safe by assuming i586. + # Note: whatever this is, it MUST be the same as what config.sub + # prints for the "djgpp" host, or else GDB configure will decide that + # this is a cross-build. + GUESS=i586-pc-msdosdjgpp + ;; + Intel:Mach:3*:*) + GUESS=i386-pc-mach3 + ;; + paragon:*:*:*) + GUESS=i860-intel-osf1 + ;; + i860:*:4.*:*) # i860-SVR4 + if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then + GUESS=i860-stardent-sysv$UNAME_RELEASE # Stardent Vistra i860-SVR4 + else # Add other i860-SVR4 vendors below as they are discovered. + GUESS=i860-unknown-sysv$UNAME_RELEASE # Unknown i860-SVR4 + fi + ;; + mini*:CTIX:SYS*5:*) + # "miniframe" + GUESS=m68010-convergent-sysv + ;; + mc68k:UNIX:SYSTEM5:3.51m) + GUESS=m68k-convergent-sysv + ;; + M680?0:D-NIX:5.3:*) + GUESS=m68k-diab-dnix + ;; + M68*:*:R3V[5678]*:*) + test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; + 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) + OS_REL='' + test -r /etc/.relid \ + && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4.3"$OS_REL"; exit; } + /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ + && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } ;; + 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4; exit; } ;; + NCR*:*:4.2:* | MPRAS*:*:4.2:*) + OS_REL='.3' + test -r /etc/.relid \ + && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4.3"$OS_REL"; exit; } + /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ + && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } + /bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \ + && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } ;; + m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) + GUESS=m68k-unknown-lynxos$UNAME_RELEASE + ;; + mc68030:UNIX_System_V:4.*:*) + GUESS=m68k-atari-sysv4 + ;; + TSUNAMI:LynxOS:2.*:*) + GUESS=sparc-unknown-lynxos$UNAME_RELEASE + ;; + rs6000:LynxOS:2.*:*) + GUESS=rs6000-unknown-lynxos$UNAME_RELEASE + ;; + PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*) + GUESS=powerpc-unknown-lynxos$UNAME_RELEASE + ;; + SM[BE]S:UNIX_SV:*:*) + GUESS=mips-dde-sysv$UNAME_RELEASE + ;; + RM*:ReliantUNIX-*:*:*) + GUESS=mips-sni-sysv4 + ;; + RM*:SINIX-*:*:*) + GUESS=mips-sni-sysv4 + ;; + *:SINIX-*:*:*) + if uname -p 2>/dev/null >/dev/null ; then + UNAME_MACHINE=`(uname -p) 2>/dev/null` + GUESS=$UNAME_MACHINE-sni-sysv4 + else + GUESS=ns32k-sni-sysv + fi + ;; + PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort + # says + GUESS=i586-unisys-sysv4 + ;; + *:UNIX_System_V:4*:FTX*) + # From Gerald Hewes . + # How about differentiating between stratus architectures? -djm + GUESS=hppa1.1-stratus-sysv4 + ;; + *:*:*:FTX*) + # From seanf@swdc.stratus.com. + GUESS=i860-stratus-sysv4 + ;; + i*86:VOS:*:*) + # From Paul.Green@stratus.com. + GUESS=$UNAME_MACHINE-stratus-vos + ;; + *:VOS:*:*) + # From Paul.Green@stratus.com. + GUESS=hppa1.1-stratus-vos + ;; + mc68*:A/UX:*:*) + GUESS=m68k-apple-aux$UNAME_RELEASE + ;; + news*:NEWS-OS:6*:*) + GUESS=mips-sony-newsos6 + ;; + R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) + if test -d /usr/nec; then + GUESS=mips-nec-sysv$UNAME_RELEASE + else + GUESS=mips-unknown-sysv$UNAME_RELEASE + fi + ;; + BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. + GUESS=powerpc-be-beos + ;; + BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. + GUESS=powerpc-apple-beos + ;; + BePC:BeOS:*:*) # BeOS running on Intel PC compatible. + GUESS=i586-pc-beos + ;; + BePC:Haiku:*:*) # Haiku running on Intel PC compatible. + GUESS=i586-pc-haiku + ;; + x86_64:Haiku:*:*) + GUESS=x86_64-unknown-haiku + ;; + SX-4:SUPER-UX:*:*) + GUESS=sx4-nec-superux$UNAME_RELEASE + ;; + SX-5:SUPER-UX:*:*) + GUESS=sx5-nec-superux$UNAME_RELEASE + ;; + SX-6:SUPER-UX:*:*) + GUESS=sx6-nec-superux$UNAME_RELEASE + ;; + SX-7:SUPER-UX:*:*) + GUESS=sx7-nec-superux$UNAME_RELEASE + ;; + SX-8:SUPER-UX:*:*) + GUESS=sx8-nec-superux$UNAME_RELEASE + ;; + SX-8R:SUPER-UX:*:*) + GUESS=sx8r-nec-superux$UNAME_RELEASE + ;; + SX-ACE:SUPER-UX:*:*) + GUESS=sxace-nec-superux$UNAME_RELEASE + ;; + Power*:Rhapsody:*:*) + GUESS=powerpc-apple-rhapsody$UNAME_RELEASE + ;; + *:Rhapsody:*:*) + GUESS=$UNAME_MACHINE-apple-rhapsody$UNAME_RELEASE + ;; + arm64:Darwin:*:*) + GUESS=aarch64-apple-darwin$UNAME_RELEASE + ;; + *:Darwin:*:*) + UNAME_PROCESSOR=`uname -p` + case $UNAME_PROCESSOR in + unknown) UNAME_PROCESSOR=powerpc ;; + esac + if command -v xcode-select > /dev/null 2> /dev/null && \ + ! xcode-select --print-path > /dev/null 2> /dev/null ; then + # Avoid executing cc if there is no toolchain installed as + # cc will be a stub that puts up a graphical alert + # prompting the user to install developer tools. + CC_FOR_BUILD=no_compiler_found + else + set_cc_for_build + fi + if test "$CC_FOR_BUILD" != no_compiler_found; then + if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ + (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_64BIT_ARCH >/dev/null + then + case $UNAME_PROCESSOR in + i386) UNAME_PROCESSOR=x86_64 ;; + powerpc) UNAME_PROCESSOR=powerpc64 ;; + esac + fi + # On 10.4-10.6 one might compile for PowerPC via gcc -arch ppc + if (echo '#ifdef __POWERPC__'; echo IS_PPC; echo '#endif') | \ + (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_PPC >/dev/null + then + UNAME_PROCESSOR=powerpc + fi + elif test "$UNAME_PROCESSOR" = i386 ; then + # uname -m returns i386 or x86_64 + UNAME_PROCESSOR=$UNAME_MACHINE + fi + GUESS=$UNAME_PROCESSOR-apple-darwin$UNAME_RELEASE + ;; + *:procnto*:*:* | *:QNX:[0123456789]*:*) + UNAME_PROCESSOR=`uname -p` + if test "$UNAME_PROCESSOR" = x86; then + UNAME_PROCESSOR=i386 + UNAME_MACHINE=pc + fi + GUESS=$UNAME_PROCESSOR-$UNAME_MACHINE-nto-qnx$UNAME_RELEASE + ;; + *:QNX:*:4*) + GUESS=i386-pc-qnx + ;; + NEO-*:NONSTOP_KERNEL:*:*) + GUESS=neo-tandem-nsk$UNAME_RELEASE + ;; + NSE-*:NONSTOP_KERNEL:*:*) + GUESS=nse-tandem-nsk$UNAME_RELEASE + ;; + NSR-*:NONSTOP_KERNEL:*:*) + GUESS=nsr-tandem-nsk$UNAME_RELEASE + ;; + NSV-*:NONSTOP_KERNEL:*:*) + GUESS=nsv-tandem-nsk$UNAME_RELEASE + ;; + NSX-*:NONSTOP_KERNEL:*:*) + GUESS=nsx-tandem-nsk$UNAME_RELEASE + ;; + *:NonStop-UX:*:*) + GUESS=mips-compaq-nonstopux + ;; + BS2000:POSIX*:*:*) + GUESS=bs2000-siemens-sysv + ;; + DS/*:UNIX_System_V:*:*) + GUESS=$UNAME_MACHINE-$UNAME_SYSTEM-$UNAME_RELEASE + ;; + *:Plan9:*:*) + # "uname -m" is not consistent, so use $cputype instead. 386 + # is converted to i386 for consistency with other x86 + # operating systems. + if test "${cputype-}" = 386; then + UNAME_MACHINE=i386 + elif test "x${cputype-}" != x; then + UNAME_MACHINE=$cputype + fi + GUESS=$UNAME_MACHINE-unknown-plan9 + ;; + *:TOPS-10:*:*) + GUESS=pdp10-unknown-tops10 + ;; + *:TENEX:*:*) + GUESS=pdp10-unknown-tenex + ;; + KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) + GUESS=pdp10-dec-tops20 + ;; + XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) + GUESS=pdp10-xkl-tops20 + ;; + *:TOPS-20:*:*) + GUESS=pdp10-unknown-tops20 + ;; + *:ITS:*:*) + GUESS=pdp10-unknown-its + ;; + SEI:*:*:SEIUX) + GUESS=mips-sei-seiux$UNAME_RELEASE + ;; + *:DragonFly:*:*) + DRAGONFLY_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` + GUESS=$UNAME_MACHINE-unknown-dragonfly$DRAGONFLY_REL + ;; + *:*VMS:*:*) + UNAME_MACHINE=`(uname -p) 2>/dev/null` + case $UNAME_MACHINE in + A*) GUESS=alpha-dec-vms ;; + I*) GUESS=ia64-dec-vms ;; + V*) GUESS=vax-dec-vms ;; + esac ;; + *:XENIX:*:SysV) + GUESS=i386-pc-xenix + ;; + i*86:skyos:*:*) + SKYOS_REL=`echo "$UNAME_RELEASE" | sed -e 's/ .*$//'` + GUESS=$UNAME_MACHINE-pc-skyos$SKYOS_REL + ;; + i*86:rdos:*:*) + GUESS=$UNAME_MACHINE-pc-rdos + ;; + i*86:Fiwix:*:*) + GUESS=$UNAME_MACHINE-pc-fiwix + ;; + *:AROS:*:*) + GUESS=$UNAME_MACHINE-unknown-aros + ;; + x86_64:VMkernel:*:*) + GUESS=$UNAME_MACHINE-unknown-esx + ;; + amd64:Isilon\ OneFS:*:*) + GUESS=x86_64-unknown-onefs + ;; + *:Unleashed:*:*) + GUESS=$UNAME_MACHINE-unknown-unleashed$UNAME_RELEASE + ;; +esac + +# Do we have a guess based on uname results? +if test "x$GUESS" != x; then + echo "$GUESS" + exit +fi + +# No uname command or uname output not recognized. +set_cc_for_build +cat > "$dummy.c" < +#include +#endif +#if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__) +#if defined (vax) || defined (__vax) || defined (__vax__) || defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__) +#include +#if defined(_SIZE_T_) || defined(SIGLOST) +#include +#endif +#endif +#endif +main () +{ +#if defined (sony) +#if defined (MIPSEB) + /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, + I don't know.... */ + printf ("mips-sony-bsd\n"); exit (0); +#else +#include + printf ("m68k-sony-newsos%s\n", +#ifdef NEWSOS4 + "4" +#else + "" +#endif + ); exit (0); +#endif +#endif + +#if defined (NeXT) +#if !defined (__ARCHITECTURE__) +#define __ARCHITECTURE__ "m68k" +#endif + int version; + version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; + if (version < 4) + printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); + else + printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); + exit (0); +#endif + +#if defined (MULTIMAX) || defined (n16) +#if defined (UMAXV) + printf ("ns32k-encore-sysv\n"); exit (0); +#else +#if defined (CMU) + printf ("ns32k-encore-mach\n"); exit (0); +#else + printf ("ns32k-encore-bsd\n"); exit (0); +#endif +#endif +#endif + +#if defined (__386BSD__) + printf ("i386-pc-bsd\n"); exit (0); +#endif + +#if defined (sequent) +#if defined (i386) + printf ("i386-sequent-dynix\n"); exit (0); +#endif +#if defined (ns32000) + printf ("ns32k-sequent-dynix\n"); exit (0); +#endif +#endif + +#if defined (_SEQUENT_) + struct utsname un; + + uname(&un); + if (strncmp(un.version, "V2", 2) == 0) { + printf ("i386-sequent-ptx2\n"); exit (0); + } + if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ + printf ("i386-sequent-ptx1\n"); exit (0); + } + printf ("i386-sequent-ptx\n"); exit (0); +#endif + +#if defined (vax) +#if !defined (ultrix) +#include +#if defined (BSD) +#if BSD == 43 + printf ("vax-dec-bsd4.3\n"); exit (0); +#else +#if BSD == 199006 + printf ("vax-dec-bsd4.3reno\n"); exit (0); +#else + printf ("vax-dec-bsd\n"); exit (0); +#endif +#endif +#else + printf ("vax-dec-bsd\n"); exit (0); +#endif +#else +#if defined(_SIZE_T_) || defined(SIGLOST) + struct utsname un; + uname (&un); + printf ("vax-dec-ultrix%s\n", un.release); exit (0); +#else + printf ("vax-dec-ultrix\n"); exit (0); +#endif +#endif +#endif +#if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__) +#if defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__) +#if defined(_SIZE_T_) || defined(SIGLOST) + struct utsname *un; + uname (&un); + printf ("mips-dec-ultrix%s\n", un.release); exit (0); +#else + printf ("mips-dec-ultrix\n"); exit (0); +#endif +#endif +#endif + +#if defined (alliant) && defined (i860) + printf ("i860-alliant-bsd\n"); exit (0); +#endif + + exit (1); +} +EOF + +$CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null && SYSTEM_NAME=`"$dummy"` && + { echo "$SYSTEM_NAME"; exit; } + +# Apollos put the system type in the environment. +test -d /usr/apollo && { echo "$ISP-apollo-$SYSTYPE"; exit; } + +echo "$0: unable to guess system type" >&2 + +case $UNAME_MACHINE:$UNAME_SYSTEM in + mips:Linux | mips64:Linux) + # If we got here on MIPS GNU/Linux, output extra information. + cat >&2 <&2 <&2 </dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null` + +hostinfo = `(hostinfo) 2>/dev/null` +/bin/universe = `(/bin/universe) 2>/dev/null` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` +/bin/arch = `(/bin/arch) 2>/dev/null` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` + +UNAME_MACHINE = "$UNAME_MACHINE" +UNAME_RELEASE = "$UNAME_RELEASE" +UNAME_SYSTEM = "$UNAME_SYSTEM" +UNAME_VERSION = "$UNAME_VERSION" +EOF +fi + +exit 1 + +# Local variables: +# eval: (add-hook 'before-save-hook 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/config.sub b/config.sub new file mode 100755 index 0000000..dba16e8 --- /dev/null +++ b/config.sub @@ -0,0 +1,1890 @@ +#! /bin/sh +# Configuration validation subroutine script. +# Copyright 1992-2022 Free Software Foundation, Inc. + +# shellcheck disable=SC2006,SC2268 # see below for rationale + +timestamp='2022-01-03' + +# This file is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 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, see . +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that +# program. This Exception is an additional permission under section 7 +# of the GNU General Public License, version 3 ("GPLv3"). + + +# Please send patches to . +# +# Configuration subroutine to validate and canonicalize a configuration type. +# Supply the specified configuration type as an argument. +# If it is invalid, we print an error message on stderr and exit with code 1. +# Otherwise, we print the canonical config type on stdout and succeed. + +# You can get the latest version of this script from: +# https://git.savannah.gnu.org/cgit/config.git/plain/config.sub + +# This file is supposed to be the same for all GNU packages +# and recognize all the CPU types, system types and aliases +# that are meaningful with *any* GNU software. +# Each package is responsible for reporting which valid configurations +# it does not support. The user should be able to distinguish +# a failure to support a valid configuration from a meaningless +# configuration. + +# The goal of this file is to map all the various variations of a given +# machine specification into a single specification in the form: +# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM +# or in some cases, the newer four-part form: +# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM +# It is wrong to echo any other type of specification. + +# The "shellcheck disable" line above the timestamp inhibits complaints +# about features and limitations of the classic Bourne shell that were +# superseded or lifted in POSIX. However, this script identifies a wide +# variety of pre-POSIX systems that do not have POSIX shells at all, and +# even some reasonably current systems (Solaris 10 as case-in-point) still +# have a pre-POSIX /bin/sh. + +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] CPU-MFR-OPSYS or ALIAS + +Canonicalize a configuration name. + +Options: + -h, --help print this help, then exit + -t, --time-stamp print date of last modification, then exit + -v, --version print version number, then exit + +Report bugs and patches to ." + +version="\ +GNU config.sub ($timestamp) + +Copyright 1992-2022 Free Software Foundation, Inc. + +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + +help=" +Try \`$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case $1 in + --time-stamp | --time* | -t ) + echo "$timestamp" ; exit ;; + --version | -v ) + echo "$version" ; exit ;; + --help | --h* | -h ) + echo "$usage"; exit ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + echo "$me: invalid option $1$help" >&2 + exit 1 ;; + + *local*) + # First pass through any local machine types. + echo "$1" + exit ;; + + * ) + break ;; + esac +done + +case $# in + 0) echo "$me: missing argument$help" >&2 + exit 1;; + 1) ;; + *) echo "$me: too many arguments$help" >&2 + exit 1;; +esac + +# Split fields of configuration type +# shellcheck disable=SC2162 +saved_IFS=$IFS +IFS="-" read field1 field2 field3 field4 <&2 + exit 1 + ;; + *-*-*-*) + basic_machine=$field1-$field2 + basic_os=$field3-$field4 + ;; + *-*-*) + # Ambiguous whether COMPANY is present, or skipped and KERNEL-OS is two + # parts + maybe_os=$field2-$field3 + case $maybe_os in + nto-qnx* | linux-* | uclinux-uclibc* \ + | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* \ + | netbsd*-eabi* | kopensolaris*-gnu* | cloudabi*-eabi* \ + | storm-chaos* | os2-emx* | rtmk-nova*) + basic_machine=$field1 + basic_os=$maybe_os + ;; + android-linux) + basic_machine=$field1-unknown + basic_os=linux-android + ;; + *) + basic_machine=$field1-$field2 + basic_os=$field3 + ;; + esac + ;; + *-*) + # A lone config we happen to match not fitting any pattern + case $field1-$field2 in + decstation-3100) + basic_machine=mips-dec + basic_os= + ;; + *-*) + # Second component is usually, but not always the OS + case $field2 in + # Prevent following clause from handling this valid os + sun*os*) + basic_machine=$field1 + basic_os=$field2 + ;; + zephyr*) + basic_machine=$field1-unknown + basic_os=$field2 + ;; + # Manufacturers + dec* | mips* | sequent* | encore* | pc533* | sgi* | sony* \ + | att* | 7300* | 3300* | delta* | motorola* | sun[234]* \ + | unicom* | ibm* | next | hp | isi* | apollo | altos* \ + | convergent* | ncr* | news | 32* | 3600* | 3100* \ + | hitachi* | c[123]* | convex* | sun | crds | omron* | dg \ + | ultra | tti* | harris | dolphin | highlevel | gould \ + | cbm | ns | masscomp | apple | axis | knuth | cray \ + | microblaze* | sim | cisco \ + | oki | wec | wrs | winbond) + basic_machine=$field1-$field2 + basic_os= + ;; + *) + basic_machine=$field1 + basic_os=$field2 + ;; + esac + ;; + esac + ;; + *) + # Convert single-component short-hands not valid as part of + # multi-component configurations. + case $field1 in + 386bsd) + basic_machine=i386-pc + basic_os=bsd + ;; + a29khif) + basic_machine=a29k-amd + basic_os=udi + ;; + adobe68k) + basic_machine=m68010-adobe + basic_os=scout + ;; + alliant) + basic_machine=fx80-alliant + basic_os= + ;; + altos | altos3068) + basic_machine=m68k-altos + basic_os= + ;; + am29k) + basic_machine=a29k-none + basic_os=bsd + ;; + amdahl) + basic_machine=580-amdahl + basic_os=sysv + ;; + amiga) + basic_machine=m68k-unknown + basic_os= + ;; + amigaos | amigados) + basic_machine=m68k-unknown + basic_os=amigaos + ;; + amigaunix | amix) + basic_machine=m68k-unknown + basic_os=sysv4 + ;; + apollo68) + basic_machine=m68k-apollo + basic_os=sysv + ;; + apollo68bsd) + basic_machine=m68k-apollo + basic_os=bsd + ;; + aros) + basic_machine=i386-pc + basic_os=aros + ;; + aux) + basic_machine=m68k-apple + basic_os=aux + ;; + balance) + basic_machine=ns32k-sequent + basic_os=dynix + ;; + blackfin) + basic_machine=bfin-unknown + basic_os=linux + ;; + cegcc) + basic_machine=arm-unknown + basic_os=cegcc + ;; + convex-c1) + basic_machine=c1-convex + basic_os=bsd + ;; + convex-c2) + basic_machine=c2-convex + basic_os=bsd + ;; + convex-c32) + basic_machine=c32-convex + basic_os=bsd + ;; + convex-c34) + basic_machine=c34-convex + basic_os=bsd + ;; + convex-c38) + basic_machine=c38-convex + basic_os=bsd + ;; + cray) + basic_machine=j90-cray + basic_os=unicos + ;; + crds | unos) + basic_machine=m68k-crds + basic_os= + ;; + da30) + basic_machine=m68k-da30 + basic_os= + ;; + decstation | pmax | pmin | dec3100 | decstatn) + basic_machine=mips-dec + basic_os= + ;; + delta88) + basic_machine=m88k-motorola + basic_os=sysv3 + ;; + dicos) + basic_machine=i686-pc + basic_os=dicos + ;; + djgpp) + basic_machine=i586-pc + basic_os=msdosdjgpp + ;; + ebmon29k) + basic_machine=a29k-amd + basic_os=ebmon + ;; + es1800 | OSE68k | ose68k | ose | OSE) + basic_machine=m68k-ericsson + basic_os=ose + ;; + gmicro) + basic_machine=tron-gmicro + basic_os=sysv + ;; + go32) + basic_machine=i386-pc + basic_os=go32 + ;; + h8300hms) + basic_machine=h8300-hitachi + basic_os=hms + ;; + h8300xray) + basic_machine=h8300-hitachi + basic_os=xray + ;; + h8500hms) + basic_machine=h8500-hitachi + basic_os=hms + ;; + harris) + basic_machine=m88k-harris + basic_os=sysv3 + ;; + hp300 | hp300hpux) + basic_machine=m68k-hp + basic_os=hpux + ;; + hp300bsd) + basic_machine=m68k-hp + basic_os=bsd + ;; + hppaosf) + basic_machine=hppa1.1-hp + basic_os=osf + ;; + hppro) + basic_machine=hppa1.1-hp + basic_os=proelf + ;; + i386mach) + basic_machine=i386-mach + basic_os=mach + ;; + isi68 | isi) + basic_machine=m68k-isi + basic_os=sysv + ;; + m68knommu) + basic_machine=m68k-unknown + basic_os=linux + ;; + magnum | m3230) + basic_machine=mips-mips + basic_os=sysv + ;; + merlin) + basic_machine=ns32k-utek + basic_os=sysv + ;; + mingw64) + basic_machine=x86_64-pc + basic_os=mingw64 + ;; + mingw32) + basic_machine=i686-pc + basic_os=mingw32 + ;; + mingw32ce) + basic_machine=arm-unknown + basic_os=mingw32ce + ;; + monitor) + basic_machine=m68k-rom68k + basic_os=coff + ;; + morphos) + basic_machine=powerpc-unknown + basic_os=morphos + ;; + moxiebox) + basic_machine=moxie-unknown + basic_os=moxiebox + ;; + msdos) + basic_machine=i386-pc + basic_os=msdos + ;; + msys) + basic_machine=i686-pc + basic_os=msys + ;; + mvs) + basic_machine=i370-ibm + basic_os=mvs + ;; + nacl) + basic_machine=le32-unknown + basic_os=nacl + ;; + ncr3000) + basic_machine=i486-ncr + basic_os=sysv4 + ;; + netbsd386) + basic_machine=i386-pc + basic_os=netbsd + ;; + netwinder) + basic_machine=armv4l-rebel + basic_os=linux + ;; + news | news700 | news800 | news900) + basic_machine=m68k-sony + basic_os=newsos + ;; + news1000) + basic_machine=m68030-sony + basic_os=newsos + ;; + necv70) + basic_machine=v70-nec + basic_os=sysv + ;; + nh3000) + basic_machine=m68k-harris + basic_os=cxux + ;; + nh[45]000) + basic_machine=m88k-harris + basic_os=cxux + ;; + nindy960) + basic_machine=i960-intel + basic_os=nindy + ;; + mon960) + basic_machine=i960-intel + basic_os=mon960 + ;; + nonstopux) + basic_machine=mips-compaq + basic_os=nonstopux + ;; + os400) + basic_machine=powerpc-ibm + basic_os=os400 + ;; + OSE68000 | ose68000) + basic_machine=m68000-ericsson + basic_os=ose + ;; + os68k) + basic_machine=m68k-none + basic_os=os68k + ;; + paragon) + basic_machine=i860-intel + basic_os=osf + ;; + parisc) + basic_machine=hppa-unknown + basic_os=linux + ;; + psp) + basic_machine=mipsallegrexel-sony + basic_os=psp + ;; + pw32) + basic_machine=i586-unknown + basic_os=pw32 + ;; + rdos | rdos64) + basic_machine=x86_64-pc + basic_os=rdos + ;; + rdos32) + basic_machine=i386-pc + basic_os=rdos + ;; + rom68k) + basic_machine=m68k-rom68k + basic_os=coff + ;; + sa29200) + basic_machine=a29k-amd + basic_os=udi + ;; + sei) + basic_machine=mips-sei + basic_os=seiux + ;; + sequent) + basic_machine=i386-sequent + basic_os= + ;; + sps7) + basic_machine=m68k-bull + basic_os=sysv2 + ;; + st2000) + basic_machine=m68k-tandem + basic_os= + ;; + stratus) + basic_machine=i860-stratus + basic_os=sysv4 + ;; + sun2) + basic_machine=m68000-sun + basic_os= + ;; + sun2os3) + basic_machine=m68000-sun + basic_os=sunos3 + ;; + sun2os4) + basic_machine=m68000-sun + basic_os=sunos4 + ;; + sun3) + basic_machine=m68k-sun + basic_os= + ;; + sun3os3) + basic_machine=m68k-sun + basic_os=sunos3 + ;; + sun3os4) + basic_machine=m68k-sun + basic_os=sunos4 + ;; + sun4) + basic_machine=sparc-sun + basic_os= + ;; + sun4os3) + basic_machine=sparc-sun + basic_os=sunos3 + ;; + sun4os4) + basic_machine=sparc-sun + basic_os=sunos4 + ;; + sun4sol2) + basic_machine=sparc-sun + basic_os=solaris2 + ;; + sun386 | sun386i | roadrunner) + basic_machine=i386-sun + basic_os= + ;; + sv1) + basic_machine=sv1-cray + basic_os=unicos + ;; + symmetry) + basic_machine=i386-sequent + basic_os=dynix + ;; + t3e) + basic_machine=alphaev5-cray + basic_os=unicos + ;; + t90) + basic_machine=t90-cray + basic_os=unicos + ;; + toad1) + basic_machine=pdp10-xkl + basic_os=tops20 + ;; + tpf) + basic_machine=s390x-ibm + basic_os=tpf + ;; + udi29k) + basic_machine=a29k-amd + basic_os=udi + ;; + ultra3) + basic_machine=a29k-nyu + basic_os=sym1 + ;; + v810 | necv810) + basic_machine=v810-nec + basic_os=none + ;; + vaxv) + basic_machine=vax-dec + basic_os=sysv + ;; + vms) + basic_machine=vax-dec + basic_os=vms + ;; + vsta) + basic_machine=i386-pc + basic_os=vsta + ;; + vxworks960) + basic_machine=i960-wrs + basic_os=vxworks + ;; + vxworks68) + basic_machine=m68k-wrs + basic_os=vxworks + ;; + vxworks29k) + basic_machine=a29k-wrs + basic_os=vxworks + ;; + xbox) + basic_machine=i686-pc + basic_os=mingw32 + ;; + ymp) + basic_machine=ymp-cray + basic_os=unicos + ;; + *) + basic_machine=$1 + basic_os= + ;; + esac + ;; +esac + +# Decode 1-component or ad-hoc basic machines +case $basic_machine in + # Here we handle the default manufacturer of certain CPU types. It is in + # some cases the only manufacturer, in others, it is the most popular. + w89k) + cpu=hppa1.1 + vendor=winbond + ;; + op50n) + cpu=hppa1.1 + vendor=oki + ;; + op60c) + cpu=hppa1.1 + vendor=oki + ;; + ibm*) + cpu=i370 + vendor=ibm + ;; + orion105) + cpu=clipper + vendor=highlevel + ;; + mac | mpw | mac-mpw) + cpu=m68k + vendor=apple + ;; + pmac | pmac-mpw) + cpu=powerpc + vendor=apple + ;; + + # Recognize the various machine names and aliases which stand + # for a CPU type and a company and sometimes even an OS. + 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) + cpu=m68000 + vendor=att + ;; + 3b*) + cpu=we32k + vendor=att + ;; + bluegene*) + cpu=powerpc + vendor=ibm + basic_os=cnk + ;; + decsystem10* | dec10*) + cpu=pdp10 + vendor=dec + basic_os=tops10 + ;; + decsystem20* | dec20*) + cpu=pdp10 + vendor=dec + basic_os=tops20 + ;; + delta | 3300 | motorola-3300 | motorola-delta \ + | 3300-motorola | delta-motorola) + cpu=m68k + vendor=motorola + ;; + dpx2*) + cpu=m68k + vendor=bull + basic_os=sysv3 + ;; + encore | umax | mmax) + cpu=ns32k + vendor=encore + ;; + elxsi) + cpu=elxsi + vendor=elxsi + basic_os=${basic_os:-bsd} + ;; + fx2800) + cpu=i860 + vendor=alliant + ;; + genix) + cpu=ns32k + vendor=ns + ;; + h3050r* | hiux*) + cpu=hppa1.1 + vendor=hitachi + basic_os=hiuxwe2 + ;; + hp3k9[0-9][0-9] | hp9[0-9][0-9]) + cpu=hppa1.0 + vendor=hp + ;; + hp9k2[0-9][0-9] | hp9k31[0-9]) + cpu=m68000 + vendor=hp + ;; + hp9k3[2-9][0-9]) + cpu=m68k + vendor=hp + ;; + hp9k6[0-9][0-9] | hp6[0-9][0-9]) + cpu=hppa1.0 + vendor=hp + ;; + hp9k7[0-79][0-9] | hp7[0-79][0-9]) + cpu=hppa1.1 + vendor=hp + ;; + hp9k78[0-9] | hp78[0-9]) + # FIXME: really hppa2.0-hp + cpu=hppa1.1 + vendor=hp + ;; + hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) + # FIXME: really hppa2.0-hp + cpu=hppa1.1 + vendor=hp + ;; + hp9k8[0-9][13679] | hp8[0-9][13679]) + cpu=hppa1.1 + vendor=hp + ;; + hp9k8[0-9][0-9] | hp8[0-9][0-9]) + cpu=hppa1.0 + vendor=hp + ;; + i*86v32) + cpu=`echo "$1" | sed -e 's/86.*/86/'` + vendor=pc + basic_os=sysv32 + ;; + i*86v4*) + cpu=`echo "$1" | sed -e 's/86.*/86/'` + vendor=pc + basic_os=sysv4 + ;; + i*86v) + cpu=`echo "$1" | sed -e 's/86.*/86/'` + vendor=pc + basic_os=sysv + ;; + i*86sol2) + cpu=`echo "$1" | sed -e 's/86.*/86/'` + vendor=pc + basic_os=solaris2 + ;; + j90 | j90-cray) + cpu=j90 + vendor=cray + basic_os=${basic_os:-unicos} + ;; + iris | iris4d) + cpu=mips + vendor=sgi + case $basic_os in + irix*) + ;; + *) + basic_os=irix4 + ;; + esac + ;; + miniframe) + cpu=m68000 + vendor=convergent + ;; + *mint | mint[0-9]* | *MiNT | *MiNT[0-9]*) + cpu=m68k + vendor=atari + basic_os=mint + ;; + news-3600 | risc-news) + cpu=mips + vendor=sony + basic_os=newsos + ;; + next | m*-next) + cpu=m68k + vendor=next + case $basic_os in + openstep*) + ;; + nextstep*) + ;; + ns2*) + basic_os=nextstep2 + ;; + *) + basic_os=nextstep3 + ;; + esac + ;; + np1) + cpu=np1 + vendor=gould + ;; + op50n-* | op60c-*) + cpu=hppa1.1 + vendor=oki + basic_os=proelf + ;; + pa-hitachi) + cpu=hppa1.1 + vendor=hitachi + basic_os=hiuxwe2 + ;; + pbd) + cpu=sparc + vendor=tti + ;; + pbb) + cpu=m68k + vendor=tti + ;; + pc532) + cpu=ns32k + vendor=pc532 + ;; + pn) + cpu=pn + vendor=gould + ;; + power) + cpu=power + vendor=ibm + ;; + ps2) + cpu=i386 + vendor=ibm + ;; + rm[46]00) + cpu=mips + vendor=siemens + ;; + rtpc | rtpc-*) + cpu=romp + vendor=ibm + ;; + sde) + cpu=mipsisa32 + vendor=sde + basic_os=${basic_os:-elf} + ;; + simso-wrs) + cpu=sparclite + vendor=wrs + basic_os=vxworks + ;; + tower | tower-32) + cpu=m68k + vendor=ncr + ;; + vpp*|vx|vx-*) + cpu=f301 + vendor=fujitsu + ;; + w65) + cpu=w65 + vendor=wdc + ;; + w89k-*) + cpu=hppa1.1 + vendor=winbond + basic_os=proelf + ;; + none) + cpu=none + vendor=none + ;; + leon|leon[3-9]) + cpu=sparc + vendor=$basic_machine + ;; + leon-*|leon[3-9]-*) + cpu=sparc + vendor=`echo "$basic_machine" | sed 's/-.*//'` + ;; + + *-*) + # shellcheck disable=SC2162 + saved_IFS=$IFS + IFS="-" read cpu vendor <&2 + exit 1 + ;; + esac + ;; +esac + +# Here we canonicalize certain aliases for manufacturers. +case $vendor in + digital*) + vendor=dec + ;; + commodore*) + vendor=cbm + ;; + *) + ;; +esac + +# Decode manufacturer-specific aliases for certain operating systems. + +if test x$basic_os != x +then + +# First recognize some ad-hoc cases, or perhaps split kernel-os, or else just +# set os. +case $basic_os in + gnu/linux*) + kernel=linux + os=`echo "$basic_os" | sed -e 's|gnu/linux|gnu|'` + ;; + os2-emx) + kernel=os2 + os=`echo "$basic_os" | sed -e 's|os2-emx|emx|'` + ;; + nto-qnx*) + kernel=nto + os=`echo "$basic_os" | sed -e 's|nto-qnx|qnx|'` + ;; + *-*) + # shellcheck disable=SC2162 + saved_IFS=$IFS + IFS="-" read kernel os <&2 + exit 1 + ;; +esac + +# As a final step for OS-related things, validate the OS-kernel combination +# (given a valid OS), if there is a kernel. +case $kernel-$os in + linux-gnu* | linux-dietlibc* | linux-android* | linux-newlib* \ + | linux-musl* | linux-relibc* | linux-uclibc* ) + ;; + uclinux-uclibc* ) + ;; + -dietlibc* | -newlib* | -musl* | -relibc* | -uclibc* ) + # These are just libc implementations, not actual OSes, and thus + # require a kernel. + echo "Invalid configuration \`$1': libc \`$os' needs explicit kernel." 1>&2 + exit 1 + ;; + kfreebsd*-gnu* | kopensolaris*-gnu*) + ;; + vxworks-simlinux | vxworks-simwindows | vxworks-spe) + ;; + nto-qnx*) + ;; + os2-emx) + ;; + *-eabi* | *-gnueabi*) + ;; + -*) + # Blank kernel with real OS is always fine. + ;; + *-*) + echo "Invalid configuration \`$1': Kernel \`$kernel' not known to work with OS \`$os'." 1>&2 + exit 1 + ;; +esac + +# Here we handle the case where we know the os, and the CPU type, but not the +# manufacturer. We pick the logical manufacturer. +case $vendor in + unknown) + case $cpu-$os in + *-riscix*) + vendor=acorn + ;; + *-sunos*) + vendor=sun + ;; + *-cnk* | *-aix*) + vendor=ibm + ;; + *-beos*) + vendor=be + ;; + *-hpux*) + vendor=hp + ;; + *-mpeix*) + vendor=hp + ;; + *-hiux*) + vendor=hitachi + ;; + *-unos*) + vendor=crds + ;; + *-dgux*) + vendor=dg + ;; + *-luna*) + vendor=omron + ;; + *-genix*) + vendor=ns + ;; + *-clix*) + vendor=intergraph + ;; + *-mvs* | *-opened*) + vendor=ibm + ;; + *-os400*) + vendor=ibm + ;; + s390-* | s390x-*) + vendor=ibm + ;; + *-ptx*) + vendor=sequent + ;; + *-tpf*) + vendor=ibm + ;; + *-vxsim* | *-vxworks* | *-windiss*) + vendor=wrs + ;; + *-aux*) + vendor=apple + ;; + *-hms*) + vendor=hitachi + ;; + *-mpw* | *-macos*) + vendor=apple + ;; + *-*mint | *-mint[0-9]* | *-*MiNT | *-MiNT[0-9]*) + vendor=atari + ;; + *-vos*) + vendor=stratus + ;; + esac + ;; +esac + +echo "$cpu-$vendor-${kernel:+$kernel-}$os" +exit + +# Local variables: +# eval: (add-hook 'before-save-hook 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..2fe9cd1 --- /dev/null +++ b/configure.ac @@ -0,0 +1,263 @@ +dnl Process this file with autoconf to produce a configure script. + +AC_INIT +AC_CONFIG_SRCDIR([src/fbtrellis.h]) + +AC_CANONICAL_HOST + +dnl Generate config.h + +dnl Minimum Autoconf version required. +AC_PREREQ([2.71]) + +dnl Version code +V_MAJOR=1 +V_MINOR=0 +V_MICRO=0 + +VERSION=${V_MAJOR}.${V_MINOR}.${V_MICRO} +AC_SUBST(VERSION) + +dnl Package name +PACKAGE=fb +AC_SUBST(PACKAGE) + +dnl Library name +LIBRARY=fb +AC_SUBST(LIBRARY) + +dnl Check C compiler + +AC_PROG_CC + +dnl Check compileur options + +OLDCCFLAGS="$CCFLAGS" +CCFLAGS="" +LIBFB_CC_FLAG(-O3) +if test "$libfb_cv_cc_flag__O3" = "no"; then + LIBFB_CC_FLAG(-O2) + if test "$libfb_cv_cc_flag__O2" = "no"; then + CCFLAGS="$OLDCCFLAGS" + fi +fi + +LIBFB_CC_FLAG(-pipe) + +LIBFB_CC_FLAG(-Wall) + +dnl Checks for programs. + +AC_PROG_INSTALL +AC_PROG_MAKE_SET +AC_PROG_LN_S +AC_PROG_RANLIB + +AC_CHECK_PROGS(AR, ar) +if test "$AR" = ""; then + if $STATIC_LIBS; then + AC_MSG_ERROR([Unable to found ar]); + fi +fi +AC_SUBST(AR) + +AC_CHECK_PROGS(STRIP, strip) +if test "$STRIP" = ""; then + AC_MSG_WARN([Unable to found strip]); +fi +AC_SUBST(STRIP) + +AC_CHECK_PROGS(BASENAME, basename) +if test "$BASENAME" = ""; then + AC_MSG_ERROR([Unable to found basename]); +fi +AC_SUBST(BASENAME) + +AC_CHECK_PROGS(TAR, gtar tar) +if test -z "$TAR"; then + AC_MSG_WARN([Unable to found tar]); +fi +AC_SUBST(TAR) + +AC_CHECK_PROGS(COMPRESS, bzip2 gzip compress) +if test -z "$COMPRESS"; then + AC_MSG_WARN([Unable to found compress]); +fi +AC_SUBST(COMPRESS) + +dnl Checks for libraries. + +dnl Checks for header files. + +dnl Checks for typedefs, structures, and compiler characteristics. + +dnl Check options + +### Usage of a temporary directory + +BUILD_DIR="build" +AC_ARG_ENABLE(builddir, + [ --enable-builddir= use for object files], + [case "$enableval" in + no) + ;; + yes) + BUILD_DIR="/tmp/`whoami`/$PACKAGE" + ;; + *) + BUILD_DIR="$enableval" + ;; + esac], []) +changequote(,)dnl +BUILD_DIR=`echo $BUILD_DIR | sed -e 's%^\([^/]\)%$(top_srcdir)/\1%'` +changequote([,])dnl +AC_SUBST(BUILD_DIR) + +### Enable creation of static libraries. + +AC_ARG_ENABLE(static, + [ --enable-static create static libraries], + [if test "$enableval" = no; then STATIC_LIBS=false; + else STATIC_LIBS=true; fi], + STATIC_LIBS=true) +AC_SUBST(STATIC_LIBS) + +### enable debugging information + +AC_ARG_WITH(debug, + [ --with-debug add debug information], + [if test "$withval" = no; then DEBUG=false; + else DEBUG=true; fi], + DEBUG=false) +AC_SUBST(DEBUG) + +### with profiling information + +AC_ARG_WITH(profile, + [ --with-profile add profiling information (for gprof)], + [if test "$withval" = no; then PROFILE=false; + else PROFILE=true; fi], + PROFILE=false) + +if test "$PROFILE" = true; then + DEBUG=true +fi + +## check debugging flags + +if test "$DEBUG" = true; then + LIBFB_CC_FLAG(-ggdb3) + if test "$libfb_cv_cc_flag__ggdb3" = "no"; then + LIBFB_CC_FLAG(-g) + if test "$libfb_cv_cc_flag__g" = "no"; then + AC_MSG_ERROR([Can't add debugging information with this compiler!]) + fi + fi +fi + +## check profiling flags + +if test "$PROFILE" = true; then + LIBFB_CC_LDFLAG(-pg) + if test "$libfb_cv_cc_ldflag__pg" = "no"; then + AC_MSG_ERROR([Can't add profiling information with this compiler!]) + fi +fi + +### Enable creation of shared libraries. Currently only works with +### gcc on some systems. + +AC_ARG_ENABLE(shared, + [ --enable-shared create shared libraries (not all systems)], + [if test "$enableval" = no; then SHARED_LIBS=false; + else SHARED_LIBS=true; fi], + SHARED_LIBS=true) +AC_SUBST(SHARED_LIBS) + +dnl Some check for cygwin + +case "$host" in + *-*-cygwin*) + SHARED_LIBS=false + ;; +esac + +if $STATIC_LIBS || $SHARED_LIBS; then + true +else + AC_MSG_ERROR([You can't disable building static AND shared libraries!]) +fi + +### + +use_rpath=true +AC_ARG_ENABLE(rpath, + [ --enable-rpath add -rpath to link command for shared libraries], + [if test "$enableval" = no; then use_rpath=false; fi], []) + +CCPICFLAG=-fPIC +SHLEXT=so +STLEXT=a +SH_LD="$CC" +SH_LDFLAGS=-shared +SONAME_FLAGS= +RLD_FLAG= +EXECEXT="" +case "$host" in + *-*-386bsd* | *-*-openbsd* | *-*-netbsd* | *-*-freebsd*) + SH_LD=ld + SH_LDFLAGS=-Bshareable + ;; + *-*-cygwin*) + EXECEXT=".exe" + ;; + *-*-linux*) + SONAME_FLAGS='-Xlinker -soname -Xlinker $(shell $(BASENAME) $@)' + RLD_FLAG='-Xlinker -rpath -Xlinker $(shell cd $(LIB_BUILD_DIR); pwd)' + ;; + hppa*-hp-hpux*) + SHLEXT=sl + SH_LDFLAGS="-shared -fPIC" + RLD_FLAG='-Xlinker +b -Xlinker $(shell cd $(LIB_BUILD_DIR); pwd)' + ;; + sparc-sun-solaris2* | i386-pc-solaris2*) + RLD_FLAG='-Xlinker -R -Xlinker $(shell cd $(LIB_BUILD_DIR); pwd)' + ;; + *) + if $SHARED_LIBS; then + AC_MSG_ERROR([I don't know how to handle this machine. Correct me first!]) + fi + ;; +esac + +if $use_rpath; then + true +else + RLD_FLAG= +fi + +AC_SUBST(CCFLAGS) +AC_SUBST(CCPICFLAG) +AC_SUBST(SHLEXT) +AC_SUBST(STLEXT) +AC_SUBST(SH_LD) +AC_SUBST(SH_LDFLAGS) +AC_SUBST(SONAME_FLAGS) +AC_SUBST(RLD_FLAG) +AC_SUBST(EXECEXT) + +dnl Set CC and LD variable + +LD=$CC +AC_SUBST(LD) + +dnl Generate ouputs + +AC_CONFIG_FILES([ Makeconf + Makefile + Makerule + src/fbversion.h + src/Makefile + test/Makefile +]) +AC_OUTPUT diff --git a/install-sh b/install-sh new file mode 100755 index 0000000..e9de238 --- /dev/null +++ b/install-sh @@ -0,0 +1,251 @@ +#!/bin/sh +# +# install - install a program, script, or datafile +# This comes from X11R5 (mit/util/scripts/install.sh). +# +# Copyright 1991 by the Massachusetts Institute of Technology +# +# Permission to use, copy, modify, distribute, and sell this software and its +# documentation for any purpose is hereby granted without fee, provided that +# the above copyright notice appear in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation, and that the name of M.I.T. not be used in advertising or +# publicity pertaining to distribution of the software without specific, +# written prior permission. M.I.T. makes no representations about the +# suitability of this software for any purpose. It is provided "as is" +# without express or implied warranty. +# +# Calling this script install-sh is preferred over install.sh, to prevent +# `make' implicit rules from creating a file called install from it +# when there is no Makefile. +# +# This script is compatible with the BSD install script, but was written +# from scratch. It can only install one file at a time, a restriction +# shared with many OS's install programs. + + +# set DOITPROG to echo to test this script + +# Don't use :- since 4.3BSD and earlier shells don't like it. +doit="${DOITPROG-}" + + +# put in absolute paths if you don't have them in your path; or use env. vars. + +mvprog="${MVPROG-mv}" +cpprog="${CPPROG-cp}" +chmodprog="${CHMODPROG-chmod}" +chownprog="${CHOWNPROG-chown}" +chgrpprog="${CHGRPPROG-chgrp}" +stripprog="${STRIPPROG-strip}" +rmprog="${RMPROG-rm}" +mkdirprog="${MKDIRPROG-mkdir}" + +transformbasename="" +transform_arg="" +instcmd="$mvprog" +chmodcmd="$chmodprog 0755" +chowncmd="" +chgrpcmd="" +stripcmd="" +rmcmd="$rmprog -f" +mvcmd="$mvprog" +src="" +dst="" +dir_arg="" + +while [ x"$1" != x ]; do + case $1 in + -c) instcmd="$cpprog" + shift + continue;; + + -d) dir_arg=true + shift + continue;; + + -m) chmodcmd="$chmodprog $2" + shift + shift + continue;; + + -o) chowncmd="$chownprog $2" + shift + shift + continue;; + + -g) chgrpcmd="$chgrpprog $2" + shift + shift + continue;; + + -s) stripcmd="$stripprog" + shift + continue;; + + -t=*) transformarg=`echo $1 | sed 's/-t=//'` + shift + continue;; + + -b=*) transformbasename=`echo $1 | sed 's/-b=//'` + shift + continue;; + + *) if [ x"$src" = x ] + then + src=$1 + else + # this colon is to work around a 386BSD /bin/sh bug + : + dst=$1 + fi + shift + continue;; + esac +done + +if [ x"$src" = x ] +then + echo "install: no input file specified" + exit 1 +else + true +fi + +if [ x"$dir_arg" != x ]; then + dst=$src + src="" + + if [ -d $dst ]; then + instcmd=: + chmodcmd="" + else + instcmd=mkdir + fi +else + +# Waiting for this to be detected by the "$instcmd $src $dsttmp" command +# might cause directories to be created, which would be especially bad +# if $src (and thus $dsttmp) contains '*'. + + if [ -f $src -o -d $src ] + then + true + else + echo "install: $src does not exist" + exit 1 + fi + + if [ x"$dst" = x ] + then + echo "install: no destination specified" + exit 1 + else + true + fi + +# If destination is a directory, append the input filename; if your system +# does not like double slashes in filenames, you may need to add some logic + + if [ -d $dst ] + then + dst="$dst"/`basename $src` + else + true + fi +fi + +## this sed command emulates the dirname command +dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` + +# Make sure that the destination directory exists. +# this part is taken from Noah Friedman's mkinstalldirs script + +# Skip lots of stat calls in the usual case. +if [ ! -d "$dstdir" ]; then +defaultIFS=' +' +IFS="${IFS-${defaultIFS}}" + +oIFS="${IFS}" +# Some sh's can't handle IFS=/ for some reason. +IFS='%' +set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` +IFS="${oIFS}" + +pathcomp='' + +while [ $# -ne 0 ] ; do + pathcomp="${pathcomp}${1}" + shift + + if [ ! -d "${pathcomp}" ] ; + then + $mkdirprog "${pathcomp}" + else + true + fi + + pathcomp="${pathcomp}/" +done +fi + +if [ x"$dir_arg" != x ] +then + $doit $instcmd $dst && + + if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi && + if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi && + if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi && + if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi +else + +# If we're going to rename the final executable, determine the name now. + + if [ x"$transformarg" = x ] + then + dstfile=`basename $dst` + else + dstfile=`basename $dst $transformbasename | + sed $transformarg`$transformbasename + fi + +# don't allow the sed command to completely eliminate the filename + + if [ x"$dstfile" = x ] + then + dstfile=`basename $dst` + else + true + fi + +# Make a temp file name in the proper directory. + + dsttmp=$dstdir/#inst.$$# + +# Move or copy the file name to the temp name + + $doit $instcmd $src $dsttmp && + + trap "rm -f ${dsttmp}" 0 && + +# and set any options; do chmod last to preserve setuid bits + +# If any of these fail, we abort the whole thing. If we want to +# ignore errors from any of these, just make sure not to ignore +# errors from the above "$doit $instcmd $src $dsttmp" command. + + if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi && + if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi && + if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi && + if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi && + +# Now rename the file to the real destination. + + $doit $rmcmd -f $dstdir/$dstfile && + $doit $mvcmd $dsttmp $dstdir/$dstfile + +fi && + + +exit 0 diff --git a/mkinstalldirs b/mkinstalldirs new file mode 100755 index 0000000..06503d3 --- /dev/null +++ b/mkinstalldirs @@ -0,0 +1,40 @@ +#! /bin/sh +# mkinstalldirs --- make directory hierarchy +# Author: Noah Friedman +# Created: 1993-05-16 +# Public domain + +# $Id: mkinstalldirs 2253 2006-08-29 08:42:29Z alm002 $ + +errstatus=0 + +for file +do + set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` + shift + + pathcomp= + for d + do + pathcomp="$pathcomp$d" + case "$pathcomp" in + -* ) pathcomp=./$pathcomp ;; + esac + + if test ! -d "$pathcomp"; then + echo "mkdir $pathcomp" + + mkdir "$pathcomp" || lasterr=$? + + if test ! -d "$pathcomp"; then + errstatus=$lasterr + fi + fi + + pathcomp="$pathcomp/" + done +done + +exit $errstatus + +# mkinstalldirs ends here diff --git a/src/Makefile.in b/src/Makefile.in new file mode 100644 index 0000000..08ceb65 --- /dev/null +++ b/src/Makefile.in @@ -0,0 +1,36 @@ +## Directory variables + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ + +## Directory for install + +prefix = @prefix@ +exec_prefix = @exec_prefix@ +libdir = @libdir@ +includedir = @includedir@/@PACKAGE@ + +## Program variables + +INSTALL = @INSTALL@ + +## Generic variables + +include $(top_srcdir)/Makeconf + +## Specific variables + +ifeq ($(SHARED_LIBS),true) +SHLIB = lib@LIBRARY@.@SHLEXT@ +SHLIBVER = $(SHLIB).@VERSION@ +endif + +ifeq ($(STATIC_LIBS),true) +STLIB = lib@LIBRARY@.@STLEXT@ +endif + +TARGETS = $(OBJECTS) $(SHLIBVER) $(SHLIB) $(STLIB) + +## Generic rules + +include $(top_srcdir)/Makerule diff --git a/src/create_fbtrellis.c b/src/create_fbtrellis.c new file mode 100644 index 0000000..62c4c02 --- /dev/null +++ b/src/create_fbtrellis.c @@ -0,0 +1,398 @@ +/* -*- C -*- */ + +/* + +Copyright (C) 2004 Laurent Mazet + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, 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; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +In addition to the terms of the GPL, you are permitted to link +this program with any Open Source program, as defined by the +Open Source Initiative (www.opensource.org) + +*/ + +/* Generic trellis constructors */ + +#include +#include + +#include "fbtrellis.h" + +#include "create_fbtrellis.h" + +/* Trellis creation from convolutionnal encoder */ +fb_trellis *create_fb_trellis_from_poly (int nb_inputs, int nb_outputs, + int *constrain_lengths, + int *generators, + int nb_feedbacks, + int *feedbacks, + int history_size, + fb_type type, + fb_impl_type impl_type) { + int *input_index, *exit_index, *state_mask; + int *prev_subcoder_pos, **genpoly, **fbpoly; + int *fb_pos, *fb_res, *fb_line, *reg, *output; + fb_trellis *tr; + int i, j; + int t, p, nb_fb, tmp, state, input; + int k, l, m, n, u, v; + + /* change variable names */ + k = nb_inputs; + n = nb_outputs; + l = nb_feedbacks/k; + + /* compute the real constrain length */ + v = 0; + for (i=0; i0; t--, p>>=1) + genpoly[prev_subcoder_pos[i] + t][j] = p&1; + + /* build a feedback table */ + fbpoly = (int**) malloc(v * sizeof(int*)); + fbpoly[0] = (int*) malloc(v * k*l * sizeof(int)); + for (i=0; i0; t--, p>>=1) + fbpoly[prev_subcoder_pos[j] + t][i*k+j] = p&1; + + /* build index position for feedback */ + fb_pos = (int*) malloc (k*l * sizeof(int)); + fb_res = fb_line = (int*) malloc (k*l * sizeof(int)); + nb_fb = 0; + for (i=0; inb_states; state++) { + + /* for all input symbols */ + for (input=0; inputnb_preds; input++) { + + /* create a full size register to insert state bits and input bits */ + for (i=0; i=0; i--) { + /* input as register */ + if (state_mask[i] == 0) { + reg[i] = t&1; + t >>= 1; + } + /* state as register */ + else { + reg[i] = u&1; + u >>= 1; + } + } + + /* feedback */ + if (nb_fb) { + for (j=0; jnextStates[state][input] = tmp; + + /* previous state */ + for (i=0, tmp=0; iprevStates[tr->nextStates[state][input]][tmp] = state; + + /* output as register */ + for (j=0; joutputs[state][input] = tmp; + + /* create the foward symbol */ + for (i=0, tmp=0; ioutput_forwards[tr->nextStates[state][input]][tmp] = + tr->outputs[state][input]; + + /* create the input symbol */ + tr->input_forwards[tr->nextStates[state][input]][tmp] = input; + } + } + + /* Free all blocks */ + free (input_index); + free (exit_index); + free (state_mask); + free (prev_subcoder_pos); + free (genpoly[0]); + free (genpoly); + free (fbpoly[0]); + free (fbpoly); + free (fb_pos); + free (fb_line); + free (reg); + free (output); + + return tr; +} + +/* Display a trellis structure */ +void display_fb_trellis_structure (fb_trellis *tr) { + int i, j; + + /* type */ + printf ("type: %d\n", tr->type); + + /* nb_inputs */ + printf ("nb_inputs: %d\n", tr->nb_inputs); + + /* nb_outputs */ + printf ("nb_outputs: %d\n", tr->nb_outputs); + + /* nb_preds */ + printf ("nb_preds: %d\n", tr->nb_preds); + + /* nb_states */ + printf ("nb_states: %d\n", tr->nb_states); + + /* history_size */ + printf ("history_size: %d\n", tr->history_size); + + /* current_index */ + printf ("current_index: %d\n", tr->current_index); + + /* error_code */ + printf ("error_code: %d\n", tr->error_code); + + /* nextStates */ + printf ("nextStates:\n"); + for (i=0; inb_states; i++) { + for (j=0; jnb_preds; j++) + printf ("% 5d", tr->nextStates[i][j]); + printf ("\n"); + } + + /* prevStates */ + printf ("prevStates:\n"); + for (i=0; inb_states; i++) { + for (j=0; jnb_preds; j++) + printf ("% 5d", tr->prevStates[i][j]); + printf ("\n"); + } + + /* outputs */ + printf ("outputs:\n"); + for (i=0; inb_states; i++) { + for (j=0; jnb_preds; j++) + printf ("% 5d", tr->outputs[i][j]); + printf ("\n"); + } + + /* input_forwards */ + printf ("input_forwards:\n"); + for (i=0; inb_states; i++) { + for (j=0; jnb_preds; j++) + printf ("% 5d", tr->input_forwards[i][j]); + printf ("\n"); + } + + /* output_forwards */ + printf ("output_forwards:\n"); + for (i=0; inb_states; i++) { + for (j=0; jnb_preds; j++) + printf ("% 5d", tr->output_forwards[i][j]); + printf ("\n"); + } +} + +/* Display trellis memory */ +void display_fb_trellis_memory (fb_trellis *tr, char *format) { + char default_format[] = " %f"; + char *_format; + int i, j; + + _format = (format == NULL) ? default_format : format; + + /* alpha */ + printf ("alpha:\n"); + for (i=0; inb_states; i++) { + for (j=0; jhistory_size+1; j++) + printf (_format, tr->alpha[i][j]); + printf ("\n"); + } + + /* beta */ + printf ("beta:\n"); + for (i=0; inb_states; i++) { + for (j=0; jhistory_size+1; j++) + printf (_format, tr->beta[i][j]); + printf ("\n"); + } + + /* gamma */ + printf ("gamma:\n"); + for (i=0; inb_states; i++) { + for (j=0; jnb_preds; j++) + printf (_format, tr->gamma[i][j]); + printf ("\n"); + } + + switch (tr->type) { + case FB_INFO: + /* gamma tilde */ + printf("Gamma Tilde[0]:\n"); + for (i=0; inb_states; i++) { + for (j=0; jnb_preds; j++) + printf (_format, tr->gamti[0][i][j]); + printf ("\n"); + } + + /* sigma tilde */ + printf("Sigma Tilde[0]:\n"); + for (i=0; inb_states; i++) { + for (j=0; jnb_preds; j++) + printf (_format, tr->sigti[0][i][j]); + printf ("\n"); + } + /* extr */ + printf ("extr:\n"); + for (i=0; inb_inputs; i++) { + for (j=0; jhistory_size; j++) + printf (_format, tr->extr[i][j]); + printf ("\n"); + } + + /* app */ + printf ("app info bits:\n"); + for (i=0; inb_inputs; i++) { + for (j=0; jhistory_size; j++) + printf (_format, tr->app_info[i][j]); + printf ("\n"); + } + /* app */ + printf ("app coded bits:\n"); + for (i=0; inb_outputs; i++) { + for (j=0; jhistory_size; j++) + printf (_format, tr->app_coded[i][j]); + printf ("\n"); + } + + break; + + case FB_CODED: + + /* extr */ + printf ("extr:\n"); + for (i=0; inb_outputs; i++) { + for (j=0; jhistory_size; j++) + printf (_format, tr->extr[i][j]); + printf ("\n"); + } + + /* app */ + printf ("app:\n"); + for (i=0; inb_outputs; i++) { + for (j=0; jhistory_size; j++) + printf (_format, tr->app_coded[i][j]); + printf ("\n"); + } + } + + /* lambda */ + printf ("lambda:\n"); + for (i=0; inb_states; i++) { + for (j=0; jhistory_size+1; j++) + printf (_format, tr->lambda[i][j]); + printf ("\n"); + } +} diff --git a/src/create_fbtrellis.h b/src/create_fbtrellis.h new file mode 100644 index 0000000..22e8100 --- /dev/null +++ b/src/create_fbtrellis.h @@ -0,0 +1,47 @@ +/* -*- C -*- */ + +/* + +Copyright (C) 2004 Laurent Mazet + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, 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; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +In addition to the terms of the GPL, you are permitted to link +this program with any Open Source program, as defined by the +Open Source Initiative (www.opensource.org) + +*/ + +/* Generic trellis constructors */ + +#if !defined(__CREATE_FBTRELLIS_H__) +#define __CREATE_FBTRELLIS_H__ + +#include "fbtrellis.h" + +fb_trellis *create_fb_trellis_from_poly (int nb_inputs, int nb_outputs, + int *constrain_lengths, + int *generators, + int nb_feedbacks, + int *feedbacks, + int history_size, + fb_type type, + fb_impl_type impl_type); + +void display_fb_trellis_structure (fb_trellis *tr); + +void display_fb_trellis_memory (fb_trellis *tr, char *format); + +#endif /* __CREATE_FBTRELLIS_H__ */ diff --git a/src/encoder.c b/src/encoder.c new file mode 100644 index 0000000..70bd6e8 --- /dev/null +++ b/src/encoder.c @@ -0,0 +1,109 @@ +/* -*- C -*- */ + +/* + +Copyright (C) 2003 Laurent Mazet + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, 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; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +In addition to the terms of the GPL, you are permitted to link +this program with any Open Source program, as defined by the +Open Source Initiative (www.opensource.org) + +*/ + +/* Generic encoder */ + +#include +#include + +#include "encoder.h" + +/* Convolutionnal encoder allocation */ +conv_encoder *alloc_conv_encoder (int nb_unprotected_bits, int nb_inputs, + int nb_registers, int nb_coders, + int *coders) { + conv_encoder *enc; + + enc = (conv_encoder*) malloc (sizeof(conv_encoder)); + + enc->nb_unprotected_bits = nb_unprotected_bits; + enc->nb_inputs = nb_inputs; + enc->nb_coders = nb_coders; + + enc->coders = (int*) malloc(nb_coders*sizeof(int)); + memcpy(enc->coders, coders, nb_coders*sizeof(int)); + + enc->nb_registers = nb_registers; + reset_conv_encoder (enc); + + return enc; +} + +/* Convolutionnal encoder reset */ +void reset_conv_encoder (conv_encoder *enc) { + + enc->registers = 0; +} + +/* Convolutionnal encoder free */ +void free_conv_encoder (conv_encoder *enc) { + + free (enc->coders); + free (enc); +} + +/* Convolutionnal encoding */ +void conv_encoding (bit *y, bit *x, int xlen, conv_encoder *enc) { + + int i, j, k; + int inlen = xlen / (enc->nb_inputs + enc->nb_unprotected_bits); + int buf_size = enc->nb_registers + enc->nb_inputs; + int xpos, ypos; + + xpos = ypos = 0; + for (i=0; inb_unprotected_bits; j++) + y[ypos++] = x[xpos++]; + + /* get the input bits */ + for (j=0; jnb_inputs; j++) + input = (input << 1) | x[xpos++]; + + /* put them into the register field */ + enc->registers |= input << enc->nb_registers; + + /* for all encoders */ + for (j=0; jnb_coders; j++) { + int bit = 0; + + /* do the convolution */ + int bits = enc->registers & enc->coders[j]; + + /* do an addition modulo 2 */ + for (k=0; (k>=1) + bit ^= bits & 1; + + y[ypos++] = bit; + } + + /* move bits into the register field */ + enc->registers >>= enc->nb_inputs; + + } +} diff --git a/src/encoder.h b/src/encoder.h new file mode 100644 index 0000000..8a30de8 --- /dev/null +++ b/src/encoder.h @@ -0,0 +1,56 @@ +/* -*- C -*- */ + +/* + +Copyright (C) 2003 Laurent Mazet + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, 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; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +In addition to the terms of the GPL, you are permitted to link +this program with any Open Source program, as defined by the +Open Source Initiative (www.opensource.org) + +*/ + +/* Generic encoder */ + +#if !defined(__ENCODER_H__) +#define __ENCODER_H__ + +/* Bit definition */ +typedef char bit; + +/* Convolutional encoder definition */ +typedef struct { + int nb_unprotected_bits; + int nb_inputs; + int nb_registers; + int registers; + int nb_coders; + int *coders; +} conv_encoder; + +/* Convolution encoder functions */ + +conv_encoder *alloc_conv_encoder (int nb_unprotected_bits, int nb_inputs, int nb_registers, + int nb_coders, int *coders); + +void reset_conv_encoder (conv_encoder *enc); + +void free_conv_encoder (conv_encoder *enc); + +void conv_encoding (bit *y, bit *x, int xlen, conv_encoder *enc); + +#endif /* __ENCODER_H__ */ diff --git a/src/fbcoded.c b/src/fbcoded.c new file mode 100644 index 0000000..df5e080 --- /dev/null +++ b/src/fbcoded.c @@ -0,0 +1,218 @@ +/* -*- C -*- */ + +/* + +Copyright (C) 2004 Laurent Mazet and Sebastien Simoens + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, 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; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +In addition to the terms of the GPL, you are permitted to link +this program with any Open Source program, as defined by the +Open Source Initiative (www.opensource.org) + +*/ + +#include + +#include "fbtrellis.h" +#include "fbcoded.h" + +int fb_coded_alpha (fb_trellis *tr, fb_metric_t *apriori, + fb_metric_t *metrics) { + fb_metric_t sum_alpha = (fb_metric_t)0; + int l, k, n; + + /* tr->gamma[i][j] will contain the product of apriori and + * observations for the considered transition of the (K/N) encoder + * + * p(c1) * ... * p(cN) * p(c1|Y) * ... * p(cN|Y) + */ + for (k=0; knb_states; k++) + for (l=0; lnb_preds; l++) { + int output_symb = tr->output_forwards[k][l]; + + tr->gamma[k][l] = 1; + for (n=tr->nb_outputs-1; n>-1; n--, output_symb>>=1) + tr->gamma[k][l] *= ((output_symb&1) == 0) ? + apriori[n]*metrics[n] : (1-apriori[n])*(1-metrics[n]); + } + + /* Recursive computation of alpha(k,t+1) by summing over the 2^K + * predecessors: + * alpha(k, t+1) = sum_l (alpha(k'(k,l), t) * gamma_t(k, l)) + */ + + for (k=0; knb_states; k++) { + tr->alpha[k][tr->current_index+1] = (fb_metric_t)0; + for (l=0; lnb_preds; l++) + tr->alpha[k][tr->current_index+1] += + tr->alpha[tr->prevStates[k][l]][tr->current_index] * tr->gamma[k][l]; + } + + /* Normalize alpha + */ + for (k=0; knb_states; k++) + sum_alpha += tr->alpha[k][tr->current_index+1]; + + if (sum_alpha == (fb_metric_t)0) { + fb_metric_t equi_alpha = (fb_metric_t)1 / tr->nb_states; + tr->error_code = FB_CODED_SUM_ALPHA_ZERO; + for (k=0; knb_states; k++) + tr->alpha[k][tr->current_index+1] = equi_alpha; + } + else + for (k=0; knb_states; k++) + tr->alpha[k][tr->current_index+1] /= sum_alpha; + + tr->current_index++; + + return tr->error_code; +} + +int fb_coded_beta (fb_trellis *tr, fb_metric_t *apriori, + fb_metric_t *metrics) { + fb_metric_t sum_beta = (fb_metric_t)0; + int l, k, n; + + tr->current_index--; + /* tr->gamma[i][j] will contain the product of apriori and + * observations for the considered transition of the (K/N) encoder + * + * p(c1) * ... * p(cK) * p(c1|Y) * ... * p(cN|Y) + */ + for (k=0; knb_states; k++) + for (l=0; lnb_preds; l++) { + int output_symb = tr->outputs[k][l]; + + tr->gamma[k][l] = 1; + for (n=tr->nb_outputs-1; n>-1; n--, output_symb>>=1) + tr->gamma[k][l] *= ((output_symb&1) == 0) ? + apriori[n]*metrics[n] : (1-apriori[n])*(1-metrics[n]); + } + + /* Recursive computation of beta(k,t+1) by summing over the 2^K + * predecessors: + * beta(k, t+1) = sum_l (beta(k'(k,l), t) * gamma_t(k, l)) + */ + + for (k=0; knb_states; k++) { + tr->beta[k][tr->current_index] = (fb_metric_t)0; + for (l=0; lnb_preds; l++) + tr->beta[k][tr->current_index] += + tr->beta[tr->nextStates[k][l]][tr->current_index+1] * tr->gamma[k][l]; + } + + /* Normalize beta + */ + for (k=0; knb_states; k++) + sum_beta += tr->beta[k][tr->current_index]; + + if (sum_beta == (fb_metric_t)0) { + fb_metric_t equi_beta = (fb_metric_t)1 / tr->nb_states; + tr->error_code = FB_CODED_SUM_BETA_ZERO; + for (k=0; knb_states; k++) + tr->beta[k][tr->current_index] = equi_beta; + } + else + for (k=0; knb_states; k++) + tr->beta[k][tr->current_index] /= sum_beta; + + return tr->error_code; +} + +int fb_coded_gamma (fb_trellis *tr, fb_metric_t *apriori, + fb_metric_t *metrics) { + int i, k, l, n; + + /* tr->gamti[i][k][l] will contain the product of apriori and + * observations for the considered transition of the (K/N) encoder + * + * p(c1) * ... * p(cN) * p(c1|Y) * ... * p(cN|Y) + */ + + for (k=0; knb_states; k++) + for (l=0; lnb_preds; l++) { + int output_symb = tr->output_forwards[k][l]; + for (i=0; inb_outputs; i++) { + tr->gamti[i][k][l] = 1; + for (n=tr->nb_outputs-1; n>-1; n--, output_symb>>=1) + if (n != i) + tr->gamti[i][k][l] *= ((output_symb&1) == 0) ? + apriori[n]*metrics[n] : (1-apriori[n])*(1-metrics[n]); + } + /* Compute gamma by multiplying one (the first) of the gamma tilde + * by observation and apriori + */ + output_symb = tr->output_forwards[k][l]; + output_symb >>= tr->nb_outputs-1; + + tr->gamma[k][l] = tr->gamti[0][k][l] * + (((output_symb&1) == 0) ? apriori[0] : 1-apriori[0]); + } + + return tr->error_code; +} + +int fb_coded_sigma (fb_trellis *tr, int index) { + int i, k, l; + + /* Compute sigma and sigma tilde + */ + + for (k=0; knb_states; k++) + for (l=0; lnb_preds; l++) { + tr->sigma[k][l] = tr->gamma[k][l] * + tr->alpha[tr->prevStates[k][l]][index] * + tr->beta[k][index+1]; + for (i=0; inb_outputs; i++) + tr->sigti[i][k][l] = tr->gamti[i][k][l] * + tr->alpha[tr->prevStates[k][l]][index] * + tr->beta[k][index+1]; + } + + return tr->error_code; +} + +int fb_coded_extr (fb_trellis *tr, int index) { + int i, k, l; + + /* Extrinsic for the coded bits + */ + fb_metric_t *extr_0,*extr_1; + + extr_0 = (fb_metric_t *)calloc(tr->nb_outputs,sizeof(fb_metric_t)); + extr_1 = (fb_metric_t *)calloc(tr->nb_outputs,sizeof(fb_metric_t)); + + for (k=0; knb_states; k++) { + for (l=0; lnb_preds; l++) + { + int output_symb = tr->output_forwards[k][l]; + for (i=tr->nb_outputs-1; i>-1; i--, output_symb>>=1) + if ((output_symb&1) == 0) + extr_0[i] += tr->sigti[i][k][l]; + else + extr_1[i] += tr->sigti[i][k][l]; + } + } + for (i=0; inb_outputs; i++) + tr->extr[i][index] = extr_0[i]/(extr_0[i]+extr_1[i]); + + free(extr_0); + free(extr_1); + + return tr->error_code; +} + + diff --git a/src/fbcoded.h b/src/fbcoded.h new file mode 100644 index 0000000..5c372ad --- /dev/null +++ b/src/fbcoded.h @@ -0,0 +1,51 @@ +/* -*- C -*- */ + +/* + +Copyright (C) 2004 Laurent Mazet and Sebastien Simoens + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, 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; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +In addition to the terms of the GPL, you are permitted to link +this program with any Open Source program, as defined by the +Open Source Initiative (www.opensource.org) + +*/ + +#if !defined (__FBCODED_C__) +#define __FBCODED_C__ 1 + +/* Alpha recursion with aprioris on the coded bits: */ +int fb_coded_alpha (fb_trellis *tr, fb_metric_t *apriori, + fb_metric_t *metrics); + +/* Beta recursion with aprioris on the coded bits: */ +int fb_coded_beta (fb_trellis *tr, fb_metric_t *apriori, + fb_metric_t *metrics); + +/* Gamma and Gamma tilde computation with aprioris on the coded + bits: */ +int fb_coded_gamma (fb_trellis *tr, fb_metric_t *apriori, + fb_metric_t *metrics); + +/* Sigma and Sigma tilde computation from Gamma and Gamma tilde with + aprioris on the coded bits: */ +int fb_coded_sigma (fb_trellis *tr, int index); + +/* Extrinsics computation for the coded bits from the Sigma tilde with + aprioris on the coded bits: */ +int fb_coded_extr (fb_trellis *tr, int index); + +#endif /* __FBCODED_C__ */ diff --git a/src/fbinfo.c b/src/fbinfo.c new file mode 100644 index 0000000..a8c37a5 --- /dev/null +++ b/src/fbinfo.c @@ -0,0 +1,362 @@ +/* -*- C -*- */ + +/* + +Copyright (C) 2004 Laurent Mazet and Sebastien Simoens + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, 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; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +In addition to the terms of the GPL, you are permitted to link +this program with any Open Source program, as defined by the +Open Source Initiative (www.opensource.org) + +*/ + +#include +#include +#include "fbtrellis.h" +#include "fbcoded.h" + +int fb_info_alpha (fb_trellis *tr, fb_metric_t *apriori, + fb_metric_t *metrics) { + fb_metric_t sum_alpha = (fb_metric_t)0; + int l, k, n; + + /* tr->gamma[i][j] will contain the product of apriori and + * observations for the considered transition of the (K/N) encoder + * + * p(b1) * ... * p(bK) * p(c1|Y) * ... * p(cN|Y) + */ + for (k=0; knb_states; k++) + for (l=0; lnb_preds; l++) { + int input_symb = tr->input_forwards[k][l]; + int output_symb = tr->output_forwards[k][l]; + + tr->gamma[k][l] = 1; + for (n=tr->nb_inputs-1; n>-1; n--, input_symb>>=1) + tr->gamma[k][l] *= ((input_symb&1) == 0) ? apriori[n] : 1-apriori[n]; + + for (n=tr->nb_outputs-1; n>-1; n--, output_symb>>=1) + tr->gamma[k][l] *= ((output_symb&1) == 0) ? metrics[n] : 1-metrics[n]; + } + + /* Recursive computation of alpha(k,t+1) by summing over the 2^K + * predecessors: + * alpha(k, t+1) = sum_l (alpha(k'(k,l), t) * gamma_t(k, l)) + */ + + for (k=0; knb_states; k++) { + tr->alpha[k][tr->current_index+1] = (fb_metric_t)0; + for (l=0; lnb_preds; l++) + tr->alpha[k][tr->current_index+1] += + tr->alpha[tr->prevStates[k][l]][tr->current_index] * tr->gamma[k][l]; + } + + /* Normalize alpha + */ + for (k=0; knb_states; k++) + sum_alpha += tr->alpha[k][tr->current_index+1]; + + if (sum_alpha == 0) { + fb_metric_t equi_alpha = (fb_metric_t)1 / tr->nb_states; + tr->error_code = FB_INFO_SUM_ALPHA_ZERO; + for (k=0; knb_states; k++) + tr->alpha[k][tr->current_index+1] = equi_alpha; + } + else + for (k=0; knb_states; k++) + tr->alpha[k][tr->current_index+1] /= sum_alpha; + + tr->current_index++; + + return tr->error_code; +} + +int fb_info_beta (fb_trellis *tr, fb_metric_t *apriori, + fb_metric_t *metrics) { + fb_metric_t sum_beta = (fb_metric_t)0; + int l, k, n; + + tr->current_index--; + + /* tr->gamma[i][j] will contain the product of apriori and + * observations for the considered transition of the (K/N) encoder + * + * p(b1) * ... * p(bK) * p(c1|Y) * ... * p(cN|Y) + */ + for (k=0; knb_states; k++) + for (l=0; lnb_preds; l++) { + int input_symb = l; + int output_symb = tr->outputs[k][l]; + + tr->gamma[k][l] = 1; + for (n=tr->nb_inputs-1; n>-1; n--, input_symb>>=1) + tr->gamma[k][l] *= ((input_symb&1) == 0) ? apriori[n] : 1-apriori[n]; + + for (n=tr->nb_outputs-1; n>-1; n--, output_symb>>=1) + tr->gamma[k][l] *= ((output_symb&1) == 0) ? metrics[n] : 1-metrics[n]; + } + + /* Recursive computation of beta(k,t+1) by summing over the 2^K + * predecessors: + * beta(k, t+1) = sum_l (beta(k'(k,l), t) * gamma_t(k, l)) + */ + + for (k=0; knb_states; k++) { + tr->beta[k][tr->current_index] = (fb_metric_t)0; + for (l=0; lnb_preds; l++) + tr->beta[k][tr->current_index] += + tr->beta[tr->nextStates[k][l]][tr->current_index+1] * tr->gamma[k][l]; + } + + /* Normalize beta + */ + for (k=0; knb_states; k++) + sum_beta += tr->beta[k][tr->current_index]; + + if (sum_beta == (fb_metric_t)0) { + fb_metric_t equi_beta = (fb_metric_t)1 / tr->nb_states; + tr->error_code = FB_INFO_SUM_BETA_ZERO; + for (k=0; knb_states; k++) + tr->beta[k][tr->current_index] = equi_beta; + } + else + for (k=0; knb_states; k++) + tr->beta[k][tr->current_index] /= sum_beta; + + return tr->error_code; +} + +int fb_lambda (fb_trellis *tr, int index) { + fb_metric_t sum_lambda = 0; + int k; + + /* Compute lambda + */ + for (k=0; knb_states; k++) + tr->lambda[k][index] = + tr->alpha[k][index] * tr->beta[k][index]; + + /* Normalize lambda + */ + for (k=0; knb_states; k++) + sum_lambda += tr->lambda[k][index]; + + if (sum_lambda == (fb_metric_t)0) { + fb_metric_t equi_lambda = (fb_metric_t)1 / tr->nb_states; + tr->error_code = FB_INFO_SUM_LAMBDA_ZERO; + for (k=0; knb_states; k++) + tr->lambda[k][index] = equi_lambda; + } + else + for (k=0; knb_states; k++) + tr->lambda[k][index] /= sum_lambda; + + return tr->error_code; +} + +int fb_info_gamma_sc (fb_trellis *tr, fb_metric_t *apriori, + fb_metric_t *metrics) { + int i, k, l, n; + + /* tr->gamti[i][k][l] will contain the product of apriori and + * observations for the considered transition of the (K/N) encoder + * + * p(b1|Y) * ... * p(bK|Y) * p(c1|Y) * ... * p(cN|Y) + * + */ + + for (k=0; knb_states; k++) + for (l=0; lnb_preds; l++) { + int input_symb = tr->input_forwards[k][l]; + int output_symb = tr->output_forwards[k][l]; + for (i=0; inb_inputs; i++) { + tr->gamti[i][k][l] = 1; + for (n=tr->nb_inputs-1; n>-1; n--, input_symb>>=1) + if (n != i) + tr->gamti[i][k][l] *= + (((input_symb&1) == 0) ? apriori[n] : 1-apriori[n]); + for (n=tr->nb_outputs-1; n>-1; n--, output_symb>>=1) + if (n != i) + tr->gamti[i][k][l] *= + (((output_symb&1) == 0) ? metrics[n] : 1-metrics[n]); + } + + /* Compute gamma by multiplying one ( arbitrarily, the first) of the gamma tilde + * by its observation and apriori + */ + input_symb = tr->input_forwards[k][l]; + output_symb = tr->output_forwards[k][l]; + + input_symb >>= tr->nb_inputs-1; + output_symb >>= tr->nb_outputs-1; + + tr->gamma[k][l] = tr->gamti[0][k][l] * + (((input_symb&1) == 0) ? apriori[0] : (1-apriori[0])) * + (((output_symb&1) == 0) ? metrics[0] : (1-metrics[0])); + } + + return tr->error_code; +} + +int fb_info_gamma_nsc (fb_trellis *tr, fb_metric_t *apriori, + fb_metric_t *metrics) { + int i, k, l, n; + + /* tr->gamti[i][k][l] will contain the product of apriori and + * observations for the considered transition of the (K/N) encoder + * + * p(b1|Y) * ... * p(bK|Y) * p(c1|Y) * ... * p(cN|Y) + * + */ + + for (k=0; knb_states; k++) + for (l=0; lnb_preds; l++) { + int input_symb = tr->input_forwards[k][l]; + int output_symb = tr->output_forwards[k][l]; + for (i=0; inb_inputs; i++) { + tr->gamti[i][k][l] = 1; + for (n=tr->nb_inputs-1; n>-1; n--, input_symb>>=1) + if (n != i) + tr->gamti[i][k][l] *= + (((input_symb&1) == 0) ? apriori[n] : 1-apriori[n]); + + for (n=tr->nb_outputs-1; n>-1; n--, output_symb>>=1) + tr->gamti[i][k][l] *= + (((output_symb&1) == 0) ? metrics[n] : 1-metrics[n]); + } + /* Compute gamma by multiplying one (arbitrarily, the first) of the gamma tilde + * by observation and apriori + */ + input_symb = tr->input_forwards[k][l]; + input_symb >>= tr->nb_inputs-1; + + tr->gamma[k][l] = tr->gamti[0][k][l] * + (((input_symb&1) == 0) ? apriori[0] : 1-apriori[0]); + } + + return tr->error_code; +} + +int fb_info_sigma (fb_trellis *tr, int index) { + int i, k, l; + + /* Compute sigma tilde + */ + for (k=0; knb_states; k++) + for (l=0; lnb_preds; l++) { + tr->sigma[k][l] = tr->gamma[k][l] * + tr->alpha[tr->prevStates[k][l]][index] * + tr->beta[k][index+1]; + for (i=0; inb_inputs; i++) + tr->sigti[i][k][l] = tr->gamti[i][k][l] * + tr->alpha[tr->prevStates[k][l]][index] * + tr->beta[k][index+1]; + } + return tr->error_code; +} + +int fb_info_extr (fb_trellis *tr, int index) { + int i, k, l; + + /* Extrinsic for the information bits + */ + fb_metric_t *extr_0,*extr_1; + + extr_0 = (fb_metric_t *)calloc(tr->nb_inputs,sizeof(fb_metric_t)); + extr_1 = (fb_metric_t *)calloc(tr->nb_inputs,sizeof(fb_metric_t)); + + for (k=0; knb_states; k++) { + for (l=0; lnb_preds; l++) + { + int input_symb = tr->input_forwards[k][l]; + for (i=tr->nb_inputs-1; i>-1; i--, input_symb>>=1) + if ((input_symb&1) == 0) + extr_0[i] += tr->sigti[i][k][l]; + else + extr_1[i] += tr->sigti[i][k][l]; + } + } + for (i=0; inb_inputs; i++) + tr->extr[i][index] = extr_0[i]/(extr_0[i]+extr_1[i]); + + free(extr_0); + free(extr_1); + + return tr->error_code; +} + +int fb_info_app_sc (fb_trellis *tr, fb_metric_t *apriori, + fb_metric_t *metrics, int index) { + int i; + fb_metric_t app_0,app_1; + + /* Normalized APP for the information bits + */ + for (i=0; inb_inputs; i++) { + app_0 = apriori[i] * metrics[i] * tr->extr[i][index]; + app_1 = (1-apriori[i]) * (1-metrics[i]) * (1 - tr->extr[i][index]); + /*printf("app_0=%f ; app_1= %f ; metric=%f; apriori=%f; extr=%f\n",app_0,app_1,metrics[i],apriori[i],tr->extr[i][index]);*/ + tr->app_info[i][index] = app_0/(app_0+app_1); + } + + return tr->error_code; +} + +int fb_info_app_nsc (fb_trellis *tr, fb_metric_t *apriori, int index) { + int i; + fb_metric_t app_0,app_1; + /* APP for the information bits + */ + for (i=0; inb_inputs; i++) { + app_0 = apriori[i] * tr->extr[i][index]; + app_1 = (1-apriori[i]) * (1 - tr->extr[i][index]); + tr->app_info[i][index] = app_0/(app_0+app_1); + } + + return tr->error_code; +} + +int fb_app_coded (fb_trellis *tr, int index) { + int i, k, l; + + /* If only extrinsics for the information bits are available, * + * the APPs of the coded bits can still be computed directly from gamma */ + fb_metric_t *app_0,*app_1; + + app_0 = (fb_metric_t *)calloc(tr->nb_outputs,sizeof(fb_metric_t)); + app_1 = (fb_metric_t *)calloc(tr->nb_outputs,sizeof(fb_metric_t)); + + for (k=0; knb_states; k++) { + for (l=0; lnb_preds; l++) + { + int output_symb = tr->output_forwards[k][l]; + for (i=tr->nb_outputs-1; i>-1; i--, output_symb>>=1) + if ((output_symb&1) == 0) + app_0[i] += tr->sigma[k][l]; + else + app_1[i] += tr->sigma[k][l]; + } + } + for (i=0; inb_outputs; i++) + tr->app_coded[i][index] = app_0[i]/(app_0[i]+app_1[i]); + + free(app_0); + free(app_1); + + return tr->error_code; +} + + diff --git a/src/fbinfo.h b/src/fbinfo.h new file mode 100644 index 0000000..bcf161b --- /dev/null +++ b/src/fbinfo.h @@ -0,0 +1,74 @@ +/* -*- C -*- */ + +/* + +Copyright (C) 2004 Laurent Mazet and Sebastien Simoens + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, 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; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +In addition to the terms of the GPL, you are permitted to link +this program with any Open Source program, as defined by the +Open Source Initiative (www.opensource.org) + +*/ + +#if !defined (__FBINFO_C__) +#define __FBINFO_C__ 1 + +#include "fbtrellis.h" + +/* Alpha recursion with aprioris on the information bits: */ +int fb_info_alpha (fb_trellis *tr, fb_metric_t *apriori, + fb_metric_t *metrics); + +/* Beta recursion with aprioris on the information bits: */ +int fb_info_beta (fb_trellis *tr, fb_metric_t *apriori, + fb_metric_t *metrics); + +/* Lambda Computation */ +int fb_lambda (fb_trellis *tr, int index); + +/* Gamma and Gamma tilde computation for systematic code + with aprioris on the info bits: */ +int fb_info_gamma_sc (fb_trellis *tr, fb_metric_t *apriori, + fb_metric_t *metrics); + +/* Gamma and Gamma tilde computation for non-systematic code + with aprioris on the info bits: */ +int fb_info_gamma_nsc (fb_trellis *tr, fb_metric_t *apriori, + fb_metric_t *metrics); + +/* Sigma and Sigma tilde computation from Gamma and Gamma tilde + with aprioris on the info bits: */ +int fb_info_sigma (fb_trellis *tr, int index); + +/* Extrinsics computation for the info bits from the sigma tilde + with aprioris on the info bits: */ +int fb_info_extr (fb_trellis *tr, int index); + +/* Info bits APP computation for a systematic code from the info bits + extrinsics and the aprioris on the info bits: */ +int fb_info_app_sc (fb_trellis *tr, fb_metric_t *apriori, + fb_metric_t *metrics, int index); + +/* Info bits APP computation for a non-systematic code from the info + bits extrinsics and the aprioris on the info bits: */ +int fb_info_app_nsc (fb_trellis *tr, fb_metric_t *apriori, int index); + +/* Coded bits APPs computation directly from sigma without requiring + extrinsics computation: */ +int fb_app_coded (fb_trellis *tr, int index); + +#endif /* __FBINFO_C__ */ diff --git a/src/fbtrellis.c b/src/fbtrellis.c new file mode 100644 index 0000000..568041e --- /dev/null +++ b/src/fbtrellis.c @@ -0,0 +1,286 @@ +/* -*- C -*- */ + +/* + +Copyright (C) 2004 Laurent Mazet and Sebastien Simoens + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, 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; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +In addition to the terms of the GPL, you are permitted to link +this program with any Open Source program, as defined by the +Open Source Initiative (www.opensource.org) + +*/ + +#if !defined (__FBTRELLIS_C__) +#define __FBTRELLIS_C__ 1 + +#include +#include +#include +#include "fbtrellis.h" + +/* Trellis reset */ + +void reset_fb_trellis (fb_trellis *tr, trellis_closing_type trel_clos_type) { + int i, j; + + double log_eps = log(DBL_EPSILON); + + if (tr->impl_type == MAP) + for (i=0; inb_states; i++) + for (j=0; jhistory_size+1; j++) + tr->alpha[i][j] = tr->beta[i][j] = 0; + else + for (i=0; inb_states; i++) + for (j=0; jhistory_size+1; j++) + tr->alpha[i][j] = tr->beta[i][j] = (fb_metric_t)log_eps; + + if (tr->impl_type == MAP) + tr->alpha[0][0] = (fb_metric_t)1; + else + tr->alpha[0][0] = (fb_metric_t)0; + + if (trel_clos_type == TRELLIS_CLOSED_TO_ZERO_STATE) + if (tr->impl_type == MAP) + tr->beta[0][tr->history_size] = (fb_metric_t)1.0; /* closed trellis */ + else + tr->beta[0][tr->history_size] = (fb_metric_t)0.0; /* closed trellis */ + else + if (tr->impl_type == MAP) + for (j=0; jnb_states; j++) + /*If trellis is not closed, assume equiprobable end states */ + tr->beta[j][tr->history_size] = (fb_metric_t)1.0/(fb_metric_t)tr->nb_states; + else + for (j=0; jnb_states; j++) + /*If trellis is not closed, assume equiprobable end states */ + tr->beta[j][tr->history_size] = log((fb_metric_t)1.0/(fb_metric_t)tr->nb_states); + tr->current_index = 0; + tr->error_code = FB_NO_ERR_WARN; +} + +/* FB Trellis allocation */ + +fb_trellis *alloc_fb_trellis(int nb_inputs, int nb_outputs, int nb_preds, + int nb_states, int history_size, fb_type type, fb_impl_type impl_type) { + + fb_trellis *tr; + int i, j; + tr = (fb_trellis*) malloc (sizeof(fb_trellis)); + + tr->type = type; + tr->impl_type = impl_type; + tr->nb_inputs = nb_inputs; + tr->nb_outputs = nb_outputs; + tr->nb_preds = nb_preds; + tr->nb_states = nb_states; + + tr->history_size = history_size; + tr->nextStates = (int**) malloc(nb_states * sizeof(int*)); + tr->nextStates[0] = (int*) malloc(nb_states*nb_preds * sizeof(int)); + for (i=0; inextStates[i] = tr->nextStates[0] + i*nb_preds; + + tr->prevStates = (int**) malloc(nb_states * sizeof(int*)); + tr->prevStates[0] = (int*) malloc(nb_states*nb_preds * sizeof(int)); + for (i=0; iprevStates[i] = tr->prevStates[0] + i*nb_preds; + + tr->outputs = (int**) malloc(nb_states * sizeof(int*)); + tr->outputs[0] = (int*) malloc(nb_states*nb_preds * sizeof(int)); + for (i=0; ioutputs[i] = tr->outputs[0] + i*nb_preds; + + tr->input_forwards = (int**) malloc(nb_states * sizeof(int*)); + tr->input_forwards[0] = (int*) malloc(nb_states*nb_preds * sizeof(int)); + for (i=0; iinput_forwards[i] = tr->input_forwards[0] + i*nb_preds; + + tr->output_forwards = (int**) malloc(nb_states * sizeof(int*)); + tr->output_forwards[0] = (int*) malloc(nb_states*nb_preds * sizeof(int)); + for (i=0; ioutput_forwards[i] = tr->output_forwards[0] + i*nb_preds; + + tr->alpha = (fb_metric_t**) malloc(nb_states * sizeof(fb_metric_t*)); + tr->alpha[0] = (fb_metric_t*) malloc(nb_states*(history_size+1) * + sizeof(fb_metric_t)); + for (i=0; ialpha[i] = tr->alpha[0] + i*(history_size+1); + + tr->beta = (fb_metric_t**) malloc(nb_states * sizeof(fb_metric_t*)); + tr->beta[0] = (fb_metric_t*) malloc(nb_states*(history_size+1) * + sizeof(fb_metric_t)); + for (i=0; ibeta[i] = tr->beta[0] + i*(history_size+1); + + tr->gamma = (fb_metric_t**) malloc(nb_states * sizeof(fb_metric_t*)); + tr->gamma[0] = (fb_metric_t*) malloc(nb_states*nb_preds * + sizeof(fb_metric_t)); + for (i=0; igamma[i] = tr->gamma[0] + i*nb_preds; + + tr->sigma = (fb_metric_t**) malloc(nb_states * sizeof(fb_metric_t*)); + tr->sigma[0] = (fb_metric_t*) malloc(nb_states*nb_preds * + sizeof(fb_metric_t)); + for (i=0; isigma[i] = tr->sigma[0] + i*nb_preds; + + tr->lambda = (fb_metric_t**) malloc(nb_states * sizeof(fb_metric_t*)); + tr->lambda[0] = (fb_metric_t*) malloc(nb_states*(history_size+1) * + sizeof(fb_metric_t)); + for (i=0; ilambda[i] = tr->lambda[0] + i*(history_size+1); + + switch (type) { + case FB_INFO: + + tr->gamti = (fb_metric_t***) malloc(nb_inputs * sizeof(fb_metric_t**)); + tr->gamti[0]= (fb_metric_t**) malloc(nb_inputs*nb_states*sizeof(fb_metric_t*)); + tr->gamti[0][0] = (fb_metric_t*) malloc(nb_inputs*nb_states*nb_preds * + sizeof(fb_metric_t)); + for (i=0; igamti[i] = tr->gamti[0] + i*nb_states; + for (j=0; jgamti[i][j] = tr->gamti[0][0] + (i*nb_states+j)*nb_preds; + } + + tr->sigti = (fb_metric_t***) malloc(nb_inputs * sizeof(fb_metric_t**)); + tr->sigti[0] = (fb_metric_t**) malloc(nb_inputs*nb_states * + sizeof(fb_metric_t*)); + tr->sigti[0][0] = (fb_metric_t*) malloc(nb_inputs*nb_states*nb_preds * + sizeof(fb_metric_t)); + for (i=0; isigti[i] = tr->sigti[0] + i*nb_states; + for (j=0; jsigti[i][j] = tr->sigti[0][0] + (i*nb_states+j)*nb_preds; + } + + tr->extr = (fb_metric_t**) malloc(nb_inputs * sizeof(fb_metric_t*)); + tr->extr[0] = (fb_metric_t*) malloc(nb_inputs*history_size * + sizeof(fb_metric_t)); + for (i=0; iextr[i] = tr->extr[0] + i*history_size; + + break; + + case FB_CODED: + + tr->gamti = (fb_metric_t***) malloc(nb_outputs * sizeof(fb_metric_t**)); + tr->gamti[0]= (fb_metric_t**) malloc(nb_outputs*nb_states * + sizeof(fb_metric_t*)); + tr->gamti[0][0] = (fb_metric_t*) malloc(nb_outputs*nb_states*nb_preds * + sizeof(fb_metric_t)); + for (i=0; igamti[i] = tr->gamti[0] + i*nb_states; + for (j=0; jgamti[i][j] = tr->gamti[0][0] + (i*nb_states+j)*nb_preds; + } + + tr->sigti = (fb_metric_t***) malloc(nb_outputs * sizeof(fb_metric_t**)); + tr->sigti[0] = (fb_metric_t**) malloc(nb_outputs*nb_states * + sizeof(fb_metric_t*)); + tr->sigti[0][0] = (fb_metric_t*) malloc(nb_outputs*nb_states*nb_preds * + sizeof(fb_metric_t)); + for (i=0; isigti[i] = tr->sigti[0] + i*nb_states; + for (j=0; jsigti[i][j] = tr->sigti[0][0] + (i*nb_states+j)*nb_preds; + } + + tr->extr = (fb_metric_t**) malloc(nb_outputs * sizeof(fb_metric_t*)); + tr->extr[0] = (fb_metric_t*) malloc(nb_outputs*(history_size) * + sizeof(fb_metric_t)); + for (i=0; iextr[i] = tr->extr[0] + i*(history_size); + + break; + + } + + tr->app_info = (fb_metric_t**) malloc(nb_inputs * sizeof(fb_metric_t*)); + tr->app_info[0] = (fb_metric_t*) malloc(nb_inputs*(history_size) * + sizeof(fb_metric_t)); + for (i=0; iapp_info[i] = tr->app_info[0] + i*(history_size); + + tr->app_coded = (fb_metric_t**) malloc(nb_outputs * sizeof(fb_metric_t*)); + tr->app_coded[0] = (fb_metric_t*) malloc(nb_outputs*(history_size) * + sizeof(fb_metric_t)); + for (i=0; iapp_coded[i] = tr->app_coded[0] + i*(history_size); + + /*By default the trellis is assumed closed when resetting the beta: */ + reset_fb_trellis (tr, TRELLIS_CLOSED_TO_ZERO_STATE); + + return tr; +} + +void free_fb_trellis (fb_trellis *tr) { + + free (tr->nextStates[0]); + free (tr->nextStates); + + free (tr->prevStates[0]); + free (tr->prevStates); + + free (tr->outputs[0]); + free (tr->outputs); + + free (tr->input_forwards[0]); + free (tr->input_forwards); + + free (tr->output_forwards[0]); + free (tr->output_forwards); + + free (tr->alpha[0]); + free (tr->alpha); + + free (tr->beta[0]); + free (tr->beta); + + free (tr->gamma[0]); + free (tr->gamma); + + free (tr->gamti[0][0]); + free (tr->gamti[0]); + free (tr->gamti); + + free (tr->sigma[0]); + free (tr->sigma); + + free (tr->sigti[0][0]); + free (tr->sigti[0]); + free (tr->sigti); + + free (tr->extr[0]); + free (tr->extr); + + free (tr->app_info[0]); + free (tr->app_info); + + free (tr->app_coded[0]); + free (tr->app_coded); + + free (tr->lambda[0]); + free (tr->lambda); + + free (tr); +} + +#endif /* __FBTRELLIS_C__ */ diff --git a/src/fbtrellis.h b/src/fbtrellis.h new file mode 100644 index 0000000..c3e0847 --- /dev/null +++ b/src/fbtrellis.h @@ -0,0 +1,110 @@ +/* -*- C -*- */ + +/* + +Copyright (C) 2004 Laurent Mazet and Sebastien Simoens + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, 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; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +In addition to the terms of the GPL, you are permitted to link +this program with any Open Source program, as defined by the +Open Source Initiative (www.opensource.org) + +*/ + +/* Generic Forward-Backward Decoder. */ + +#if !defined(__FBTRELLIS_H__) +#define __FBTRELLIS_H__ + + +/*#include "fbversion.h" + #if !defined(__FBTRELLIS_H__) + extern const char *FB_Version; + #else + const char *FB_Version = FBVERSION; + #endif +*/ + +/* metric type definition */ +typedef double fb_metric_t; +#define FBMAXMETRIC MAXDOUBLE + +/* Trellis definition: + * =================== + * + * + * - error_code: error code + */ +typedef enum {FB_INFO = 0, FB_CODED} fb_type; +typedef enum {TRELLIS_NOT_CLOSED = 0, TRELLIS_CLOSED_TO_ZERO_STATE} trellis_closing_type; +typedef enum {MAP, LOGMAP, MAXLOGMAP} fb_impl_type; + +typedef struct fb_trellis { + + fb_type type; + + int nb_inputs; + int nb_outputs; + int nb_preds; + int nb_states; + fb_impl_type impl_type; + + int history_size; + + int **nextStates; + int **prevStates; + + int **outputs; + + int **input_forwards; + int **output_forwards; + + fb_metric_t **alpha; + fb_metric_t **beta; + fb_metric_t **gamma; + fb_metric_t **sigma; + fb_metric_t ***gamti; + fb_metric_t ***sigti; + fb_metric_t **lambda; + + fb_metric_t **app_info; + fb_metric_t **app_coded; + fb_metric_t **extr; + + int current_index; + + int error_code; +} fb_trellis; + +fb_trellis *alloc_fb_trellis(int nb_inputs, int nb_outputs, int nb_preds, + int nb_states, int history_size, fb_type type, fb_impl_type impl_type); + +void reset_fb_trellis (fb_trellis *tr, trellis_closing_type trel_clos_type); + +void free_fb_trellis (fb_trellis *tr); + +/* Error codes */ +#define FB_NO_ERR_WARN 0 + +#define FB_INFO_SUM_ALPHA_ZERO -1 +#define FB_INFO_SUM_BETA_ZERO -1 +#define FB_INFO_SUM_LAMBDA_ZERO -1 + +#define FB_CODED_SUM_ALPHA_ZERO -16 +#define FB_CODED_SUM_BETA_ZERO -17 +#define FB_CODED_SUM_LAMBDA_ZERO -18 + +#endif /* __FBTRELLIS_H__ */ diff --git a/src/fbversion.h.in b/src/fbversion.h.in new file mode 100644 index 0000000..29372a4 --- /dev/null +++ b/src/fbversion.h.in @@ -0,0 +1 @@ +#define FBVERSION "@VERSION@" diff --git a/src/interleaver.c b/src/interleaver.c new file mode 100644 index 0000000..42b2502 --- /dev/null +++ b/src/interleaver.c @@ -0,0 +1,56 @@ +#include +#include +#include +#include + +/* unsigned long resetrandom(unsigned long int seed) { */ + +/* // the random generators are initialized: */ +/* if (!seed) seed = clock(); */ +/* srand48 (seed); */ +/* srand (seed); */ + +/* return (seed); */ +/* } */ + +int *gen_random_interleaver(int size) +{ + + /* This function generates a random permutation + * using a random draw without replacement */ + int i,j,k,l,tmp_size,relative_position; + + int *tmp_array,*intlv_vect; + + /* In tmp_array[i] is set to 1 if the index i was already generated */ + tmp_array = (int *)calloc(size,sizeof(int)); + intlv_vect = (int *)calloc(size,sizeof(int)); + /* srand(clock()); */ + + for (i=0,tmp_size=size;i + +extern int* gen_random_interleaver(int size); + +/* extern unsigned long resetrandom(unsigned long int seed); */ diff --git a/src/logfbinfo.c b/src/logfbinfo.c new file mode 100644 index 0000000..9c3919c --- /dev/null +++ b/src/logfbinfo.c @@ -0,0 +1,363 @@ +/* -*- C -*- */ + +/* + +Copyright (C) 2004 Laurent Mazet and Sebastien Simoens + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, 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; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +In addition to the terms of the GPL, you are permitted to link +this program with any Open Source program, as defined by the +Open Source Initiative (www.opensource.org) + +*/ + +#include +#include +#include "fbtrellis.h" +#include "fbcoded.h" +#include "maxstar.h" + +int logfb_info_alpha (fb_trellis *tr, fb_metric_t *apriori, + fb_metric_t *metrics) { + fb_metric_t sum_alpha = (fb_metric_t)0; + int l, k, n; + + /* tr->gamma[i][j] will contain the product of apriori and + * observations for the considered transition of the (K/N) encoder + * + * p(b1) * ... * p(bK) * p(c1|Y) * ... * p(cN|Y) + */ + for (k=0; knb_states; k++) + for (l=0; lnb_preds; l++) { + int input_symb = tr->input_forwards[k][l]; + int output_symb = tr->output_forwards[k][l]; + + tr->gamma[k][l] = 0; + for (n=tr->nb_inputs-1; n>-1; n--, input_symb>>=1) + tr->gamma[k][l] += ((input_symb&1) == 0) ? (-maxstar(0,apriori[n],tr->impl_type)) : (apriori[n]-maxstar(0,apriori[n],tr->impl_type)); + + for (n=tr->nb_outputs-1; n>-1; n--, output_symb>>=1) + tr->gamma[k][l] += ((output_symb&1) == 0) ? (-maxstar(0,metrics[n],tr->impl_type)) : (metrics[n]-maxstar(0,metrics[n],tr->impl_type)); + } + + /* Recursive computation of alpha(k,t+1) by summing over the 2^K + * predecessors: + * alpha(k, t+1) = sum_l (alpha(k'(k,l), t) * gamma_t(k, l)) + */ + + for (k=0; knb_states; k++) { + tr->alpha[k][tr->current_index+1] = maxstar(tr->alpha[tr->prevStates[k][0]][tr->current_index] + tr->gamma[k][0], tr->alpha[tr->prevStates[k][1]][tr->current_index] + tr->gamma[k][1], tr->impl_type); + if (tr->nb_preds>2) + for (l=2; lnb_preds; l++) + tr->alpha[k][tr->current_index+1] = maxstar(tr->alpha[k][tr->current_index+1], tr->alpha[tr->prevStates[k][l]][tr->current_index] + tr->gamma[k][l], tr->impl_type); + } + + + /* Normalize alpha + */ + sum_alpha = tr->alpha[0][tr->current_index+1]; + for (k=1; knb_states; k++) + sum_alpha = maxstar(sum_alpha, tr->alpha[k][tr->current_index+1], tr->impl_type); + for (k=0; knb_states; k++) + tr->alpha[k][tr->current_index+1] -= sum_alpha; + + tr->current_index++; + + return tr->error_code; +} + +int logfb_info_beta (fb_trellis *tr, fb_metric_t *apriori, + fb_metric_t *metrics) { + fb_metric_t sum_beta = (fb_metric_t)0; + int l, k, n; + + tr->current_index--; + + /* tr->gamma[i][j] will contain the product of apriori and + * observations for the considered transition of the (K/N) encoder + * + * p(b1) * ... * p(bK) * p(c1|Y) * ... * p(cN|Y) + */ + for (k=0; knb_states; k++) + for (l=0; lnb_preds; l++) { + int input_symb = l; + int output_symb = tr->outputs[k][l]; + + tr->gamma[k][l] = 0; + for (n=tr->nb_inputs-1; n>-1; n--, input_symb>>=1) + tr->gamma[k][l] += ((input_symb&1) == 0) ? (-maxstar(0,apriori[n],tr->impl_type)) : (apriori[n]-maxstar(0,apriori[n],tr->impl_type)); + + for (n=tr->nb_outputs-1; n>-1; n--, output_symb>>=1) + tr->gamma[k][l] += ((output_symb&1) == 0) ? (-maxstar(0,metrics[n],tr->impl_type)) : (metrics[n]-maxstar(0,metrics[n],tr->impl_type)); + } + + /* Recursive computation of beta(k,t+1) by summing over the 2^K + * predecessors: + * beta(k, t+1) = sum_l (beta(k'(k,l), t) * gamma_t(k, l)) + */ + + for (k=0; knb_states; k++) { + tr->beta[k][tr->current_index] = maxstar(tr->beta[tr->nextStates[k][0]][tr->current_index+1] + tr->gamma[k][0], tr->beta[tr->nextStates[k][1]][tr->current_index+1] + tr->gamma[k][1], tr->impl_type); + + if (tr->nb_preds>2) + for (l=1; lnb_preds; l++) + tr->beta[k][tr->current_index] = maxstar(tr->beta[k][tr->current_index], tr->beta[tr->nextStates[k][l]][tr->current_index+1] + tr->gamma[k][l], tr->impl_type); + } + + /* Normalize beta + */ + sum_beta = tr->beta[0][tr->current_index]; + for (k=1; knb_states; k++) + sum_beta = maxstar(sum_beta, tr->beta[k][tr->current_index], tr->impl_type); + for (k=0; knb_states; k++) + tr->beta[k][tr->current_index] -= sum_beta; + + return tr->error_code; +} + +int logfb_lambda (fb_trellis *tr, int index) { + fb_metric_t sum_lambda = 0; + int k; + + /* Compute lambda + */ + for (k=0; knb_states; k++) + tr->lambda[k][index] = + tr->alpha[k][index] + tr->beta[k][index]; + + /* Normalize lambda + */ + sum_lambda = tr->lambda[0][index]; + for (k=1; knb_states; k++) + sum_lambda = maxstar(sum_lambda, tr->lambda[k][index], tr->impl_type); + + for (k=0; knb_states; k++) + tr->lambda[k][index] -= sum_lambda; + + return tr->error_code; +} + +int logfb_info_gamma_sc (fb_trellis *tr, fb_metric_t *apriori, + fb_metric_t *metrics) { + int i, k, l, n; + + /* tr->gamti[i][k][l] will contain the product of apriori and + * observations for the considered transition of the (K/N) encoder + * + * p(b1|Y) * ... * p(bK|Y) * p(c1|Y) * ... * p(cN|Y) + * + */ + + for (k=0; knb_states; k++) + for (l=0; lnb_preds; l++) { + int input_symb = tr->input_forwards[k][l]; + int output_symb = tr->output_forwards[k][l]; + for (i=0; inb_inputs; i++) { + tr->gamti[i][k][l] = 0; + for (n=tr->nb_inputs-1; n>-1; n--, input_symb>>=1) + if (n != i) + tr->gamti[i][k][l] += + ((input_symb&1) == 0) ? (-maxstar(0, apriori[n], tr->impl_type)) : (apriori[n]-maxstar(0, apriori[n], tr->impl_type)); + for (n=tr->nb_outputs-1; n>-1; n--, output_symb>>=1) + if (n != i) + tr->gamti[i][k][l] += + ((output_symb&1) == 0) ? (-maxstar(0,metrics[n],tr->impl_type)) : (metrics[n]-maxstar(0, metrics[n], tr->impl_type)); + } + + /* Compute gamma by multiplying one ( arbitrarily, the first) of the gamma tilde + * by its observation and apriori + */ + input_symb = tr->input_forwards[k][l]; + output_symb = tr->output_forwards[k][l]; + + input_symb >>= tr->nb_inputs-1; + output_symb >>= tr->nb_outputs-1; + + tr->gamma[k][l] = tr->gamti[0][k][l] + + (((input_symb&1) == 0) ? (-maxstar(0, apriori[0], tr->impl_type)) : (apriori[0]-maxstar(0, apriori[0], tr->impl_type))) + (((output_symb&1) == 0) ? (-maxstar(0,metrics[0],tr->impl_type)) : (metrics[0]-maxstar(0, metrics[0], tr->impl_type))); + } + + return tr->error_code; +} + +int logfb_info_gamma_nsc (fb_trellis *tr, fb_metric_t *apriori, + fb_metric_t *metrics) { + int i, k, l, n; + + /* tr->gamti[i][k][l] will contain the product of apriori and + * observations for the considered transition of the (K/N) encoder + * + * p(b1|Y) * ... * p(bK|Y) * p(c1|Y) * ... * p(cN|Y) + * + */ + + for (k=0; knb_states; k++) + for (l=0; lnb_preds; l++) { + int input_symb = tr->input_forwards[k][l]; + int output_symb = tr->output_forwards[k][l]; + for (i=0; inb_inputs; i++) { + tr->gamti[i][k][l] = 0; + for (n=tr->nb_inputs-1; n>-1; n--, input_symb>>=1) + if (n != i) + tr->gamti[i][k][l] += + ((input_symb&1) == 0) ? (-maxstar(0,apriori[n],tr->impl_type)) : (apriori[n]-maxstar(0,apriori[n],tr->impl_type)); + for (n=tr->nb_outputs-1; n>-1; n--, output_symb>>=1) + tr->gamti[i][k][l] += + ((output_symb&1) == 0) ? (-maxstar(0,metrics[n],tr->impl_type)) : (metrics[n]-maxstar(0,metrics[n],tr->impl_type)); + } + /* Compute gamma by multiplying one (arbitrarily, the first) of the gamma tilde + * by observation and apriori + */ + input_symb = tr->input_forwards[k][l]; + input_symb >>= tr->nb_inputs-1; + + tr->gamma[k][l] = tr->gamti[0][k][l] + + ((input_symb&1) == 0) ? (-maxstar(0,apriori[0],tr->impl_type)) : (apriori[0]-maxstar(0,metrics[0],tr->impl_type)); + } + + return tr->error_code; +} + +int logfb_info_sigma (fb_trellis *tr, int index) { + int i, k, l; + + /* Compute sigma tilde + */ + for (k=0; knb_states; k++) + for (l=0; lnb_preds; l++) { + tr->sigma[k][l] = tr->gamma[k][l] + + tr->alpha[tr->prevStates[k][l]][index] + + tr->beta[k][index+1]; + for (i=0; inb_inputs; i++) + tr->sigti[i][k][l] = tr->gamti[i][k][l] + + tr->alpha[tr->prevStates[k][l]][index] + + tr->beta[k][index+1]; + } + return tr->error_code; +} + +int logfb_info_extr (fb_trellis *tr, int index) { + int i, k, l; + + /* Extrinsic for the information bits + */ + fb_metric_t *extr_0,*extr_1, sum_extr; + char *init_extr0, *init_extr1; + + extr_0 = (fb_metric_t *)calloc(tr->nb_inputs,sizeof(fb_metric_t)); + extr_1 = (fb_metric_t *)calloc(tr->nb_inputs,sizeof(fb_metric_t)); + init_extr0 = (char *)calloc(tr->nb_inputs,sizeof(char)); + init_extr1 = (char *)calloc(tr->nb_inputs,sizeof(char)); + + for (k=0; knb_states; k++) { + for (l=0; lnb_preds; l++) { + int input_symb = tr->input_forwards[k][l]; + + for (i=tr->nb_inputs-1; i>-1; i--, input_symb>>=1) { + if ((input_symb&1) == 0) + if (init_extr0[i] == 0) { + extr_0[i] = tr->sigti[i][k][l]; + init_extr0[i] = 1; + } + else + extr_0[i] = maxstar(extr_0[i], tr->sigti[i][k][l], tr->impl_type); + else + if (init_extr1[i] == 0) { + extr_1[i] = tr->sigti[i][k][l]; + init_extr1[i] = 1; + } + else + extr_1[i] = maxstar(extr_1[i], tr->sigti[i][k][l], tr->impl_type); + } + } + } + /* + for (i=0; inb_inputs; i++) { + sum_extr = maxstar(extr_0[i],extr_1[i],tr->impl_type); + extr_0[i] -= sum_extr; + extr_1[i] -= sum_extr; + } + */ + for (i=0; inb_inputs; i++) + tr->extr[i][index] = extr_1[i] - extr_0[i]; + + free(extr_0); + free(extr_1); + free(init_extr0); + free(init_extr1); + + return tr->error_code; +} + +int logfb_info_app_sc (fb_trellis *tr, fb_metric_t *apriori, + fb_metric_t *metrics, int index) { + int i; + for (i=0; inb_inputs; i++) { + tr->app_info[i][index] = apriori[i] + metrics[i] + tr->extr[i][index]; + } + + return tr->error_code; +} + +int logfb_info_app_nsc (fb_trellis *tr, fb_metric_t *apriori, int index) { + int i; + /* APP for the information bits + */ + for (i=0; inb_inputs; i++) + tr->app_info[i][index] = apriori[i] + tr->extr[i][index]; + + return tr->error_code; +} + +int logfb_app_coded (fb_trellis *tr, int index) { + int i, k, l; + + /* If only extrinsics for the information bits are available, * + * the APPs of the coded bits can still be computed directly from gamma */ + fb_metric_t *app_0,*app_1; + + app_0 = (fb_metric_t *)calloc(tr->nb_outputs,sizeof(fb_metric_t)); + app_1 = (fb_metric_t *)calloc(tr->nb_outputs,sizeof(fb_metric_t)); + + for (k=0; knb_states; k++) { + for (l=0; lnb_preds; l++) { + int output_symb = tr->output_forwards[k][l]; + for (i=tr->nb_outputs-1; i>-1; i--, output_symb>>=1) { + if ((k == 0) && (l == 0)) { + if ((output_symb&1) == 0) + app_0[i] = tr->sigma[k][l]; + else + app_1[i] = tr->sigma[k][l]; + } + else { + if ((output_symb&1) == 0) + app_0[i] = maxstar(app_0[i], tr->sigma[k][l], tr->impl_type); + else + app_1[i] = maxstar(app_1[i], tr->sigma[k][l], tr->impl_type); + } + } + } + } + for (i=0; inb_outputs; i++) + tr->app_coded[i][index] = app_1[i] - app_0[i]; + + free(app_0); + free(app_1); + + return tr->error_code; +} + + diff --git a/src/logfbinfo.h b/src/logfbinfo.h new file mode 100644 index 0000000..f636816 --- /dev/null +++ b/src/logfbinfo.h @@ -0,0 +1,58 @@ +/* -*- C -*- */ + +/* + +Copyright (C) 2004 Laurent Mazet and Sebastien Simoens + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, 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; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +In addition to the terms of the GPL, you are permitted to link +this program with any Open Source program, as defined by the +Open Source Initiative (www.opensource.org) + +*/ + +#if !defined (__LOGFBINFO_H__) +#define __LOGFBINFO_H__ 1 + +#include "fbtrellis.h" + +/*Alpha recursion with aprioris on the information bits: */ +int logfb_info_alpha (fb_trellis *tr, fb_metric_t *apriori, + fb_metric_t *metrics); +/*Beta recursion with aprioris on the information bits: */ +int logfb_info_beta (fb_trellis *tr, fb_metric_t *apriori, + fb_metric_t *metrics); +/* Lambda Computation */ +int logfb_lambda (fb_trellis *tr, int index); +/* Gamma and Gamma tilde computation for systematic code with aprioris on the info bits: */ +int logfb_info_gamma_sc (fb_trellis *tr, fb_metric_t *apriori, + fb_metric_t *metrics); +/* Gamma and Gamma tilde computation for non-systematic code with aprioris on the info bits: */ +int logfb_info_gamma_nsc (fb_trellis *tr, fb_metric_t *apriori, + fb_metric_t *metrics); +/* Sigma and Sigma tilde computation from Gamma and Gamma tilde with aprioris on the info bits: */ +int logfb_info_sigma (fb_trellis *tr, int index); +/* Extrinsics computation for the info bits from the sigma tilde with aprioris on the info bits: */ +int logfb_info_extr (fb_trellis *tr, int index); +/* Info bits APP computation for a systematic code from the info bits extrinsics and the aprioris on the info bits: */ +int logfb_info_app_sc (fb_trellis *tr, fb_metric_t *apriori, + fb_metric_t *metrics, int index); +/* Info bits APP computation for a non-systematic code from the info bits extrinsics and the aprioris on the info bits: */ +int logfb_info_app_nsc (fb_trellis *tr, fb_metric_t *apriori, int index); +/* Coded bits APPs computation directly from sigma without requiring extrinsics computation: */ +int logfb_app_coded (fb_trellis *tr, int index); + +#endif /* __LOGFBINFO_H__ */ diff --git a/src/maxstar.c b/src/maxstar.c new file mode 100644 index 0000000..d5ecb80 --- /dev/null +++ b/src/maxstar.c @@ -0,0 +1,68 @@ +/* -*- C -*- */ + +/* + +Copyright (C) 2004 Laurent Mazet and Sebastien Simoens + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, 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; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +In addition to the terms of the GPL, you are permitted to link +this program with any Open Source program, as defined by the +Open Source Initiative (www.opensource.org) + +*/ + +#include "fbtrellis.h" + +#define max(x,y) ((x>y) ? x: y) + +static double l2c2[7][3] = { + { 1.1664970e-01, 4.3934196e-03, 6.9273909e-01 }, + { 7.4705892e-02, 9.1104768e-02, 6.4666461e-01 }, + { 3.5412325e-02, 2.4559118e-01, 4.9357575e-01 }, + { 1.4437650e-02, 3.6895054e-01, 3.1155705e-01 }, + { 5.5242908e-03, 4.3902663e-01, 1.7355873e-01 }, + { 2.0623271e-03, 4.7314287e-01, 8.9406360e-02 }, + { 7.6281904e-04, 4.8854447e-01, 4.3733797e-02 } }; + +// This function returns log(cosh(x/2))-log(2) +double log2cosh2(double x) +{ + double y = 0; + if (x < 0) + x = -x; + + if (x < 7) { + double *p = l2c2[(int)x]; + y = (*(p++)) * x; + y += (*(p++)); + y *= x; + y += (*(p++)); + } + else if (x < 16) + y = 4.9994745e-01*x + 7.0563935e-04; + else + y = 0.5*x; + + return y; +} + +double maxstar (double x1, double x2, fb_impl_type impl_type) { + if (impl_type == LOGMAP) + return (x1+x2)*0.5+log2cosh2(x1-x2); + else + return max(x1,x2); +} + diff --git a/src/maxstar.h b/src/maxstar.h new file mode 100644 index 0000000..2c6b843 --- /dev/null +++ b/src/maxstar.h @@ -0,0 +1,32 @@ +/* -*- C -*- */ + +/* + +Copyright (C) 2004 Laurent Mazet and Sebastien Simoens + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, 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; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +In addition to the terms of the GPL, you are permitted to link +this program with any Open Source program, as defined by the +Open Source Initiative (www.opensource.org) + +*/ + +#if !defined (__MAXSTAR_H__) +#define __MAXSTAR_H__ 1 + +/*To implement a MAX LOG MAP, set max_log_map=1, else a LOG MAP will be seleccted */ +extern double maxstar(double x1, double x2, fb_impl_type impl_type); +#endif diff --git a/test/Makefile.in b/test/Makefile.in new file mode 100644 index 0000000..9e8c560 --- /dev/null +++ b/test/Makefile.in @@ -0,0 +1,29 @@ +## Directory variables + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ + +## Directory for install + +prefix = @prefix@ +exec_prefix = @exec_prefix@ +libdir = @libdir@ +includedir = @includedir@/@PACKAGE@ + +## Program variables + +INSTALL = @INSTALL@ + +## Generic variables + +include $(top_srcdir)/Makeconf + +## Specific variables + +PROGTESTS = $(addprefix prog_,$(SOURCES:.c=$(EXECEXT))) + +TARGETS = $(OBJECTS) $(PROGTESTS) + +## Generic rules + +include $(top_srcdir)/Makerule diff --git a/test/convcode.c b/test/convcode.c new file mode 100644 index 0000000..354dc74 --- /dev/null +++ b/test/convcode.c @@ -0,0 +1,696 @@ +/* -*- C -*- */ + +/* + +Copyright (C) 2003 Laurent Mazet + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, 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; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +In addition to the terms of the GPL, you are permitted to link +this program with any Open Source program, as defined by the +Open Source Initiative (www.opensource.org) + +*/ + +/* Program test for Forward Backward decoding */ + +#include +#include +#include + +#include "fbtrellis.h" +#include "create_fbtrellis.h" +#include "fbinfo.h" +#include "logfbinfo.h" +#include "fbcoded.h" +#include "interleaver.h" + +#define DEBUG 9 +/* DEBUG == 1: NRNSC K=3 (5,7) test vector */ +/* DEBUG == 2: RSC K=3 (1,5/7) test vector */ +/* DEBUG == 3: NRNSC K=3 (5,7) BER vs EsNO computation */ +/* DEBUG == 4: RSC K=3 (1,5/7) BER vs EsNO computation */ +/* DEBUG == 5: NRNSC K=7 (133,171) BER vs EsNO computation */ +/* DEBUG == 6: PCC Turbo-Code K=3 (1,5/7) BER vs EsNO computation */ +/* DEBUG == 7: Same as DEBUG==1 except extrinsics and app are for the coded bits */ +/* DEBUG == 8: same as 6, with log-map decoding */ +/* DEBUG == 9: same as 6, with max-log-map decoding */ + +typedef char bit; + +/* Pseudo-random bit sequence */ +void bit_gene (bit * a, int n) { + int i; + + for (i=0; i < n; i++) + *(a++) = rand()&1; +} + +/* Gaussian random variable */ +double randn (void) { + static int iset = 0; + static double gset; + double fac,v1,v2,rsq; + + if (iset) { + iset = 0; + return gset; + } + + do { + v1 = 2.0*drand48()-1.0; + v2 = 2.0*drand48()-1.0; + rsq = v1*v1+v2*v2; + } while ((rsq >= 1) || (rsq == 0)); + fac = sqrt(-2*log(rsq)/rsq); + gset = v1*fac; + iset = 1; + + return v2*fac; +} + +int main(int argc, char* argv[]) { + fb_trellis *tr; + bit *b, *c; + fb_metric_t *metrics, *apriori; + + /* int nb_inputs = 2; */ + /* int nb_outputs = 2; */ + /* int constrain_lengths[2] = {3, 4}; */ + /* int generators[4] = {5, 7, 15, 11}; */ + /* int nb_feedbacks = 2; */ + /* int feedbacks[2] = { 5, 14}; */ + + /* By default, we assume aprioris and extrinsics relate to info bits. * + * This has an impact on trellis memory allocation */ + + fb_impl_type impl_type = MAP; +#if (DEBUG == 1) + fb_type fbtype = FB_INFO; + int nb_bits=6; + int nb_inputs = 1; + int nb_outputs = 2; + int constrain_lengths[1] = {3}; + int generators[2] = {7,5}; + trellis_closing_type trel_clos_type=TRELLIS_CLOSED_TO_ZERO_STATE; + int nb_feedbacks = 0; + int *feedbacks = NULL; + int nb_EsNO = 1; + double EsNO[1] = {20}; /*dB*/ + double ber[1] = {0}; + int nb_pkt=1; +#elif DEBUG == 2 + fb_type fbtype = FB_INFO; + int nb_bits=6; + int nb_inputs = 1; + int nb_outputs = 2; + int constrain_lengths[1] = {3}; + int generators[2] = {7, 5}; //{7,5}; + int nb_feedbacks = 1; + int feedbacks[1] = {7}; + trellis_closing_type trel_clos_type=TRELLIS_CLOSED_TO_ZERO_STATE; + int nb_EsNO = 1; + double EsNO[1] = {20}; /*dB*/ + double ber[1] = {0}; + int nb_pkt=1; +#elif DEBUG == 3 + fb_type fbtype = FB_INFO; + int nb_bits=1000; + int nb_inputs = 1; + int nb_outputs = 2; + int constrain_lengths[1] = {3}; + int generators[2] = {7,5}; + int nb_feedbacks = 0; + int *feedbacks = NULL; + trellis_closing_type trel_clos_type=TRELLIS_CLOSED_TO_ZERO_STATE; + int nb_EsNO=8; + double EsNO[8] = {-2,-1,0,1,2,3,4,5}; + double ber[8] = {0,0,0,0,0,0,0,0}; + int nb_pkt=1000; +#elif DEBUG == 4 + fb_type fbtype = FB_INFO; + int nb_bits=1000; + int nb_inputs = 1; + int nb_outputs = 2; + int constrain_lengths[1] = {3}; + int generators[2] = {7,5}; + int nb_feedbacks = 1; + int feedbacks[1] = {7}; + trellis_closing_type trel_clos_type=TRELLIS_CLOSED_TO_ZERO_STATE; + int nb_EsNO=8; + double EsNO[8] = {-2,-1,0,1,2,3,4,5}; + double ber[8] = {0,0,0,0,0,0,0,0}; + int nb_pkt=1000; +#elif DEBUG == 5 + fb_type fbtype = FB_INFO; + int nb_bits=1000; + int nb_inputs = 1; + int nb_outputs = 2; + int constrain_lengths[1] = {7}; + int generators[2] = {133,171}; + int nb_feedbacks = 0; + int *feedbacks = NULL; + trellis_closing_type trel_clos_type=TRELLIS_CLOSED_TO_ZERO_STATE; + int nb_EsNO=8; + double EsNO[8] = {-2,-1,0,1,2,3,4,5}; + double ber[8] = {0,0,0,0,0,0,0,0}; + int nb_pkt=1000; +#elif DEBUG == 6 + fb_type fbtype = FB_INFO; + int nb_bits=4; + int nb_inputs = 1; + int nb_outputs = 2; + int constrain_lengths[1] = {3}; + int generators[2] = {7,5}; + int nb_feedbacks = 1; + int feedbacks[1] = {7}; + trellis_closing_type trel_clos_type=TRELLIS_NOT_CLOSED; /*We do not close the trellis for turbo-code */ + /* int nb_EsNO=3; + double EsNO[3] = {-5, -4, -3.5}; + double ber[3] = {0, 0, 0};*/ + int nb_EsNO=1; + double EsNO[1] = {0}; + double ber[1] = {0}; + int nb_pkt=1; + int nb_iter=1; + int iter; + int *interleaver; + fb_metric_t *metrics1,*metrics2,*tmp_app; + bit *b1; /* Information interleaved bits at input of second encoder */ + bit *c1; /* Coded bits generated by second encoder */ +#elif (DEBUG==7) + fb_type fbtype = FB_CODED; + int nb_bits=6; + int nb_inputs = 1; + int nb_outputs = 2; + int constrain_lengths[1] = {3}; + int generators[2] = {7,5}; + trellis_closing_type trel_clos_type=TRELLIS_CLOSED_TO_ZERO_STATE; + int nb_feedbacks = 0; + int *feedbacks = NULL; + int nb_EsNO = 1; + double EsNO[1] = {20}; /*dB*/ + double ber[1] = {0}; + int nb_pkt=1; +#elif (DEBUG==8) + fb_type fbtype = FB_INFO; + impl_type = LOGMAP; + int nb_bits=1000; + int nb_inputs = 1; + int nb_outputs = 2; + int constrain_lengths[1] = {3}; + int generators[2] = {7,5}; + int nb_feedbacks = 1; + int feedbacks[1] = {7}; + trellis_closing_type trel_clos_type=TRELLIS_NOT_CLOSED; /*We do not close the trellis for turbo-code */ + int nb_EsNO=3; + double EsNO[3] = {-5, -4, -3.5}; + double ber[3] = {0, 0, 0}; + /*int nb_EsNO=1; + double EsNO[1] = {0}; + double ber[1] = {0};*/ + int nb_pkt=100; + int nb_iter=8; + int iter; + int *interleaver; + fb_metric_t *metrics1,*metrics2,*tmp_app; + bit *b1; /* Information interleaved bits at input of second encoder */ + bit *c1; /* Coded bits generated by second encoder */ +#elif (DEBUG==9) + fb_type fbtype = FB_INFO; + impl_type = MAXLOGMAP; + int nb_bits=1000; + int nb_inputs = 1; + int nb_outputs = 2; + int constrain_lengths[1] = {3}; + int generators[2] = {7,5}; + int nb_feedbacks = 1; + int feedbacks[1] = {7}; + trellis_closing_type trel_clos_type=TRELLIS_NOT_CLOSED; /*We do not close the trellis for turbo-code */ + int nb_EsNO=3; + double EsNO[3] = {-5, -4, -3.5}; + double ber[3] = {0, 0, 0}; + /*int nb_EsNO=1; + double EsNO[1] = {0}; + double ber[1] = {0};*/ + int nb_pkt=100; + int nb_iter=8; + int iter; + int *interleaver; + fb_metric_t *metrics1,*metrics2,*tmp_app; + bit *b1; /* Information interleaved bits at input of second encoder */ + bit *c1; /* Coded bits generated by second encoder */ +#endif + int history_size; + int i, j, k, input, output, state; + int snr_index, pkt_index; + double sigma; /* Noise Standard Deviation */ + + history_size = nb_bits / nb_inputs; + tr = create_fb_trellis_from_poly (nb_inputs, nb_outputs, constrain_lengths, + generators, nb_feedbacks, feedbacks, + history_size, fbtype, impl_type); + /* By default the trellis is closed. We must therefore reset it explicitely * + * for turbo-codes */ + reset_fb_trellis (tr, trel_clos_type); + + display_fb_trellis_structure (tr); + /*display_fb_trellis_memory(tr,"%2.4f ");*/ + +#if (DEBUG != 6) && (DEBUG != 8) && (DEBUG != 9) + int nb_cbits = nb_bits*nb_outputs/nb_inputs; +#elif (DEBUG == 6) || (DEBUG == 8) || (DEBUG == 9) + int nb_cbits = 2*nb_bits*nb_outputs/nb_inputs-nb_bits; + b1 = (bit*) malloc (nb_bits * sizeof(bit)); + c1 = (bit*) malloc (nb_cbits * sizeof(bit)); +#endif + b = (bit*) malloc (nb_bits * sizeof(bit)); + c = (bit*) malloc (nb_cbits * sizeof(bit)); + + /* Metrics of coded bits */ + metrics = (fb_metric_t*) malloc (nb_cbits * sizeof(fb_metric_t)); + +#if (DEBUG != 7) + /* Apriori info bits */ + apriori = (fb_metric_t*) malloc (nb_bits * sizeof(fb_metric_t)); +#else + /* Apriori coded bits */ + apriori = (fb_metric_t*) malloc (nb_outputs*nb_bits* sizeof(fb_metric_t)); +#endif + +#if (DEBUG == 6)|| (DEBUG == 8) || (DEBUG == 9) + /*For turbo-decoding, we create two vectors of metrics */ + /*Each containing both the metrics of systematic bits and the metrics */ + /*of coded bits for the respective constituent encoder */ + metrics1 = (fb_metric_t*) malloc (nb_outputs*nb_bits* sizeof(fb_metric_t)); + metrics2 = (fb_metric_t*) malloc (nb_outputs*nb_bits* sizeof(fb_metric_t)); + + tmp_app = (fb_metric_t*) malloc (nb_bits * sizeof(fb_metric_t)); + + interleaver = gen_random_interleaver(nb_bits); + /* For debugging purpose, we can decide not to put an interleaver */ + /* for (i=0;ioutputs[state][input]; + /* printf("Output Symbol: %d\n",output); */ + state = tr->nextStates[state][input]; + for (j=0; j>=1) + c[k+nb_outputs-1-j] = output&1; + } +#elif ((DEBUG == 2) || (DEBUG == 4)) + /* RSC: Compute coded bits from the trellis (tail excluded ! ) and trellis description*/ + for (i=0, k=0, state=0; i<(nb_bits-constrain_lengths[0]+1); i+=nb_inputs, k+=nb_outputs) { + /* create input symbol*/ + for (j=0, input=0; joutputs[state][input]; + state = tr->nextStates[state][input]; + /* create coded bits */ + for (j=0; j>=1) + c[k+nb_outputs-1-j] = output&1; + } + /*Tail Bits are inserted dependent on the state of the encoder */ + for (i=nb_bits-constrain_lengths[0]+1; inextStates[state][0] < tr->nextStates[state][1]) ? 0 : 1; + output = tr->outputs[state][b[i]]; + /* printf("Output Symbol: %d\n",output); */ + state = tr->nextStates[state][b[i]]; + for (j=0; j>=1) + c[k+nb_outputs-1-j] = output&1; + } +#elif (DEBUG == 6) || (DEBUG == 8) ||(DEBUG == 9) + /* PCCC Turbo-Encoder */ + + /* RSC: Compute coded bits from the input bits and trellis description*/ + for (i=0, k=0, state=0; ioutputs[state][input]; + /* printf("Output Symbol: %d\n",output); */ + state = tr->nextStates[state][input]; + for (j=0; j>=1) + c[k+nb_outputs-1-j] = output&1; + } + + /* Interleave the information bits */ + for (i=0;ioutputs[state][input]; + /* printf("Output Symbol: %d\n",output); */ + state = tr->nextStates[state][input]; + for (j=0; j>=1) + c1[k+nb_outputs-1-j] = output&1; + } + /*Form the Turbo-code by concatenating the non-systematic bits of the second encoder + *at the end of the codeword */ + i=nb_bits*nb_outputs; /*Starting Index*/ + for (j=0;j=0; i--) + fb_info_beta (tr, &apriori[i*nb_inputs], &metrics[i*nb_outputs]); + /* lambda */ + for (i=0; i=0; i--) + fb_info_beta (tr, &apriori[i*nb_inputs], &metrics[i*nb_outputs]); + /* lambda */ + for (i=0; i=0; i--) + fb_coded_beta (tr, &apriori[i*nb_outputs], &metrics[i*nb_outputs]); + + /* lambda */ + for (i=0; i=0; i--) + fb_info_beta (tr, &apriori[i*nb_inputs], &metrics1[i*nb_outputs]); + /*printf("Beta recursion completed \n");*/ + for (i=0; i=0; i--) + logfb_info_beta (tr, &apriori[i*nb_inputs], &metrics1[i*nb_outputs]); + /*printf("Beta recursion completed \n");*/ + for (i=0; inb_inputs; j++) + printf("%f ", tr->app[j][i]); + if (i != history_size-1) + printf("; "); + } + printf("EXTR:\n"); + for (i=0; inb_inputs; j++) + printf("%f ", tr->extr[j][i]); + if (i != history_size-1) + printf("; "); + } + printf("\nAPPs and EXT computed \n"); */ + + /* The interleaved extrinsics will become the aprioris for the second constituent encoder */ + for (i=0;iextr[0][interleaver[i]]; + } + + /*printf("Iteration: %d , 2nd half-iteration\n",iter);*/ + + /* Second half-iteration: do not forget to reset the trellis! */ + reset_fb_trellis (tr, trel_clos_type); +#if (DEBUG == 6) + /* alpha */ + for (i=0; i=0; i--) + fb_info_beta (tr, &apriori[i*nb_inputs], &metrics2[i*nb_outputs]); + for (i=0; i=0; i--) + logfb_info_beta (tr, &apriori[i*nb_inputs], &metrics2[i*nb_outputs]); + for (i=0; iextr[0][i]; + /* Also deinterleave the APPs */ + tmp_app[interleaver[i]]=tr->app_info[0][i]; + + } + for (i=0;iapp_info[0][i] = tmp_app[i]; + } + /*display_fb_trellis_memory(tr, "%2.4f ");*/ + } + +#endif +#if (DEBUG<3) || (DEBUG == 7) + display_fb_trellis_memory(tr,"%2.4f "); + + printf("Extrinsec:\n"); + for (i=0; inb_inputs; j++) + printf("%f ", tr->extr[j][i]); + if (i != history_size-1) + printf("; "); + } + printf("\n"); + + printf("APP info bits:\n"); + for (i=0; inb_inputs; j++) + printf("%f ", tr->app_info[j][i]); + if (i != history_size-1) + printf("; "); + } + printf("\n"); + + printf("APP coded bits:\n"); + for (i=0; inb_outputs; j++) + printf("%f ", tr->app_coded[j][i]); + if (i != history_size-1) + printf("; "); + } + printf("\n"); + +#endif + int bit_index; + /* Compute the BER */ + for (i=0; inb_inputs; j++) { + bit_index = i*tr->nb_inputs+j; +#if (DEBUG != 8) && (DEBUG != 9) + if ((tr->app_info[j][i]<0.5) != b[bit_index]) ber[snr_index]++; +#elif (DEBUG == 8) || (DEBUG == 9) + if ((tr->app_info[j][i]>0) != b[bit_index]) ber[snr_index]++; +#endif + } + } + } /* end for pkt_index */ + ber[snr_index] = ber[snr_index]/nb_bits/nb_pkt; + printf("EsNO = %1.2f BER = %e\n",EsNO[snr_index],ber[snr_index]); + } /* end for snr_index */ + +/* frees */ + free (b); + free (c); + free (metrics); + free (apriori); + free_fb_trellis (tr); + + return 0; +} + -- 2.30.2