From: Andrew Waterman Date: Mon, 20 Jun 2011 03:47:29 +0000 (-0700) Subject: temporary undoing of renaming X-Git-Url: https://git.libre-soc.org/?p=riscv-isa-sim.git;a=commitdiff_plain;h=77452a26e7d95d29dbaa797595ae683f03a3345b temporary undoing of renaming --- diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..89b65a1 --- /dev/null +++ b/COPYING @@ -0,0 +1,34 @@ +========================================================================== +Copyright License +========================================================================== + +Copyright (c) 2008, Christopher Batten +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions, and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions, and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of the Massachusetts Institute of Technology nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY Christopher Batten ''AS IS'' AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Christopher Batten BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +THE POSSIBILITY OF SUCH DAMAGE. + diff --git a/Makefile.in b/Makefile.in new file mode 100644 index 0000000..53dfb60 --- /dev/null +++ b/Makefile.in @@ -0,0 +1,466 @@ +#========================================================================= +# Toplevel Makefile for the Modular C++ Build System +#========================================================================= +# Please read the documenation in 'mcppbs-doc.txt' for more details on +# how the Modular C++ Build System works. For most projects, a developer +# will not need to make any changes to this makefile. The key targets +# are as follows: +# +# - default : build all libraries and programs +# - check : build and run all unit tests +# - install : install headers, project library, and some programs +# - clean : remove all generated content (except autoconf files) +# - dist : make a source tarball +# - distcheck : make a source tarball, untar it, check it, clean it +# - distclean : remove everything +# + +#------------------------------------------------------------------------- +# Basic setup +#------------------------------------------------------------------------- + +# Remove all default implicit rules since they can cause subtle bugs +# and they just make things run slower +.SUFFIXES: +% : %,v +% : RCS/%,v +% : RCS/% +% : s.% +% : SCCS/s.% + +# Default is to build the prereqs of the all target (defined at bottom) +default : all +.PHONY : default + +project_name := @PACKAGE_TARNAME@ +src_dir := @srcdir@ +scripts_dir := $(src_dir)/scripts + +# If the version information is not in the configure script, then we +# assume that we are in a working directory. We use the vcs-version.sh +# script in the scripts directory to generate an appropriate version +# string. Currently the way things are setup we have to run this script +# everytime we run make so the script needs to be as fast as possible. + +ifeq (@PACKAGE_VERSION@,?) + project_ver:=$(shell $(scripts_dir)/vcs-version.sh $(src_dir)) +else + project_ver:=@PACKAGE_VERSION@ +endif + +# Installation directories + +prefix := @prefix@ +enable_stow := @enable_stow@ + +ifeq ($(enable_stow),yes) + stow_pkg_dir := $(prefix)/pkgs + DESTDIR ?= $(stow_pkg_dir)/$(project_name)-$(project_ver) +else + DESTDIR ?= $(prefix) +endif + +install_hdrs_dir := $(DESTDIR)/include/$(project_name) +install_libs_dir := $(DESTDIR)/lib/$(project_name) +install_exes_dir := $(DESTDIR)/bin + +#------------------------------------------------------------------------- +# List of subprojects +#------------------------------------------------------------------------- + +sprojs := @subprojects@ +sprojs_enabled := @subprojects_enabled@ + +sprojs_include := -I. $(addprefix -I$(src_dir)/, $(sprojs_enabled)) +VPATH := $(addprefix $(src_dir)/, $(sprojs_enabled)) + +#------------------------------------------------------------------------- +# Programs and flags +#------------------------------------------------------------------------- + +# C++ compiler +# - CPPFLAGS : flags for the preprocessor (eg. -I,-D) +# - CXXFLAGS : flags for C++ compiler (eg. -Wall,-g,-O3) + +CC := @CC@ +CXX := @CXX@ +CPPFLAGS := @CPPFLAGS@ +CXXFLAGS := @CXXFLAGS@ +COMPILE := $(CXX) -MMD -MP $(CPPFLAGS) $(CXXFLAGS) \ + $(sprojs_include) +COMPILE_C := $(CC) -MMD -MP $(CPPFLAGS) $(CXXFLAGS) \ + $(sprojs_include) +# Linker +# - LDFLAGS : Flags for the linker (eg. -L) +# - LIBS : Library flags (eg. -l) + +LD := $(CXX) +LDFLAGS := @LDFLAGS@ +LIBS := @LIBS@ +LINK := $(LD) $(LDFLAGS) + +# Library creation + +AR := @AR@ +RANLIB := @RANLIB@ + +# Host simulator + +RUN := @RUN@ +RUNFLAGS := @RUNFLAGS@ + +# Installation + +MKINSTALLDIRS := $(scripts_dir)/mk-install-dirs.sh +INSTALL := @INSTALL@ +INSTALL_HDR := $(INSTALL) -m 444 +INSTALL_LIB := $(INSTALL) -m 644 +INSTALL_EXE := $(INSTALL) -m 555 +STOW := @stow@ + +#------------------------------------------------------------------------- +# Include subproject makefile fragments +#------------------------------------------------------------------------- + +sprojs_mk = $(addsuffix .mk, $(sprojs_enabled)) + +-include $(sprojs_mk) + +dist_junk += $(sprojs_mk) + +#------------------------------------------------------------------------- +# Reverse list helper function +#------------------------------------------------------------------------- +# This function is used by the subproject template to reverse the list +# of dependencies. It uses recursion to perform the reversal. +# +# Arguments: +# $(1) : space separated input list +# retval : input list in reverse order +# + +reverse_list = $(call reverse_list_h,$(1),) +define reverse_list_h + $(if $(strip $(1)), \ + $(call reverse_list_h, \ + $(wordlist 2,$(words $(1)),$(1)), \ + $(firstword $(1)) $(2)), \ + $(2)) +endef + +#------------------------------------------------------------------------- +# Template for per subproject rules +#------------------------------------------------------------------------- +# The template is instantiated for each of the subprojects. It relies on +# subprojects defining a certain set of make variables which are all +# prefixed with the subproject name. Since subproject names can have +# dashes in them (and the make variables are assumed to only use +# underscores) the template takes two arguments - one with the regular +# subproject name and one with dashes replaced with underscores. +# +# Arguments: +# $(1) : real subproject name (ie with dashes) +# $(2) : normalized subproject name (ie dashes replaced with underscores) +# + +define subproject_template + +# In some (rare) cases, a subproject might not have any actual object +# files. It might only include header files or program sources. To keep +# things consistent we still want a library for this subproject, so in +# this spectial case we create a dummy source file and thus the build +# system will create a library for this subproject with just the +# corresponding dummy object file. + +ifeq ($$(strip $$($(2)_srcs) $$($(2)_c_srcs)),) +$(2)_srcs += _$(1).cc +$(2)_junk += _$(1).cc +endif + +_$(1).cc : + echo "int _$(2)( int arg ) { return arg; }" > $$@ + +# Build the object files for this subproject + +$(2)_objs := $$(patsubst %.cc, %.o, $$($(2)_srcs)) +$(2)_c_objs := $$(patsubst %.c, %.o, $$($(2)_c_srcs)) +$(2)_deps := $$(patsubst %.o, %.d, $$($(2)_objs)) +$(2)_c_deps := $$(patsubst %.o, %.d, $$($(2)_c_objs)) +$$($(2)_objs) : %.o : %.cc + $(COMPILE) -c $$< +$$($(2)_c_objs) : %.o : %.c + $(COMPILE_C) -c $$< + +$(2)_junk += $$($(2)_objs) $$($(2)_c_objs) $$($(2)_deps) $$($(2)_c_deps) + +# Build a library for this subproject + +lib$(1).a : $$($(2)_objs) $$($(2)_c_objs) + $(AR) rcv $$@ $$^ + $(RANLIB) $$@ + +$(2)_junk += lib$(1).a + +# Reverse the dependency list so that a given subproject only depends on +# subprojects listed to its right. This is the correct order for linking +# the list of subproject libraries. + +$(2)_reverse_deps := $$(call reverse_list,$$($(2)_subproject_deps)) + +# Build unit tests + +$(2)_test_objs := $$(patsubst %.cc, %.o, $$($(2)_test_srcs)) +$(2)_test_deps := $$(patsubst %.o, %.d, $$($(2)_test_objs)) +$(2)_test_exes := $$(patsubst %.t.cc, %-utst, $$($(2)_test_srcs)) +$(2)_test_outs := $$(patsubst %, %.out, $$($(2)_test_exes)) +$(2)_test_libs := $(1) $$($(2)_reverse_deps) utst +$(2)_test_libnames := $$(patsubst %, lib%.a, $$($(2)_test_libs)) +$(2)_test_libarg := -L. $$(patsubst %, -l%, $$($(2)_test_libs)) + +$$($(2)_test_objs) : %.o : %.cc + $(COMPILE) -c $$< + +$$($(2)_test_exes) : %-utst : %.t.o $$($(2)_test_libnames) + $(LINK) -o $$@ $$< $$($(2)_test_libarg) $(LIBS) + +$(2)_deps += $$($(2)_test_deps) +$(2)_junk += \ + $$($(2)_test_objs) $$($(2)_test_deps) \ + $$($(2)_test_exes) *.junk-dat + +# Run unit tests + +$$($(2)_test_outs) : %.out : % + $(RUN) $(RUNFLAGS) ./$$< default | tee $$@ + +$(2)_junk += $$($(2)_test_outs) + +# Build programs + +$(2)_prog_objs := $$(patsubst %.cc, %.o, $$($(2)_prog_srcs)) +$(2)_prog_deps := $$(patsubst %.o, %.d, $$($(2)_prog_objs)) +$(2)_prog_exes := $$(patsubst %.cc, %, $$($(2)_prog_srcs)) +$(2)_prog_libs := $(1) $$($(2)_reverse_deps) +$(2)_prog_libnames := $$(patsubst %, lib%.a, $$($(2)_prog_libs)) +$(2)_prog_libarg := -L. $$(patsubst %, -l%, $$($(2)_prog_libs)) + +$$($(2)_prog_objs) : %.o : %.cc + $(COMPILE) -c $$< + +$$($(2)_prog_exes) : % : %.o $$($(2)_prog_libnames) + $(LINK) -o $$@ $$< $$($(2)_prog_libarg) $(LIBS) + +$(2)_deps += $$($(2)_prog_deps) +$(2)_junk += $$($(2)_prog_objs) $$($(2)_prog_deps) $$($(2)_prog_exes) + +# Build programs which will be installed + +$(2)_install_prog_objs := $$(patsubst %.cc, %.o, $$($(2)_install_prog_srcs)) +$(2)_install_prog_deps := $$(patsubst %.o, %.d, $$($(2)_install_prog_objs)) +$(2)_install_prog_exes := $$(patsubst %.cc, %, $$($(2)_install_prog_srcs)) + +$$($(2)_install_prog_objs) : %.o : %.cc + $(COMPILE) -c $$< + +$$($(2)_install_prog_exes) : % : %.o $$($(2)_prog_libnames) + $(LINK) -o $$@ $$< $$($(2)_prog_libarg) $(LIBS) + +$(2)_deps += $$($(2)_install_prog_deps) +$(2)_junk += \ + $$($(2)_install_prog_objs) $$($(2)_install_prog_deps) \ + $$($(2)_install_prog_exes) + +# Subproject specific targets + +all-$(1) : lib$(1).a $$($(2)_install_prog_exes) + +check-$(1) : $$($(2)_test_outs) + echo; grep -h -e'Unit Tests' -e'FAILED' -e'Segementation' $$^; echo + +clean-$(1) : + rm -rf $$($(2)_junk) + +.PHONY : all-$(1) check-$(1) clean-$(1) + +# Update running variables + +libs += lib$(1).a +objs += $$($(2)_objs) +srcs += $$(addprefix $(src_dir)/$(1)/, $$($(2)_srcs)) +hdrs += $$(addprefix $(src_dir)/$(1)/, $$($(2)_hdrs)) +junk += $$($(2)_junk) +deps += $$($(2)_deps) + +test_outs += $$($(2)_test_outs) + +install_hdrs += $$(addprefix $(src_dir)/$(1)/, $$($(2)_hdrs)) +install_libs += lib$(1).a +install_exes += $$($(2)_install_prog_exes) + +endef + +# Iterate over the subprojects and call the template for each one + +$(foreach sproj,$(sprojs_enabled), \ + $(eval $(call subproject_template,$(sproj),$(subst -,_,$(sproj))))) + +#------------------------------------------------------------------------- +# Autodependency files +#------------------------------------------------------------------------- + +-include $(deps) + +deps : $(deps) +.PHONY : deps + +#------------------------------------------------------------------------- +# Check +#------------------------------------------------------------------------- + +check : $(test_outs) + echo; grep -h -e'Unit Tests' -e'FAILED' -e'Segementation' $^; echo + +.PHONY : check + +#------------------------------------------------------------------------- +# Installation +#------------------------------------------------------------------------- + +install-hdrs : $(install_hdrs) + $(MKINSTALLDIRS) $(install_hdrs_dir) + for file in $(install_hdrs); \ + do \ + $(INSTALL_HDR) $$file $(install_hdrs_dir); \ + done + +install-libs : $(install_libs) + $(MKINSTALLDIRS) $(install_libs_dir) + for file in $(install_libs); \ + do \ + $(INSTALL_LIB) $$file $(install_libs_dir); \ + done + +install-exes : $(install_exes) + $(MKINSTALLDIRS) $(install_exes_dir) + for file in $(install_exes); \ + do \ + $(INSTALL_EXE) $$file $(install_exes_dir); \ + done + +install : install-hdrs install-libs install-exes +ifeq ($(enable_stow),yes) + $(MKINSTALLDIRS) $(stow_pkg_dir) + cd $(stow_pkg_dir) && \ + $(STOW) --delete $(project_name)-* && \ + $(STOW) $(project_name)-$(project_ver) +endif + +.PHONY : install install-hdrs install-libs install-exes + +#------------------------------------------------------------------------- +# Regenerate configure information +#------------------------------------------------------------------------- + +configure_prereq = \ + $(src_dir)/configure.ac \ + $(src_dir)/aclocal.m4 \ + $(join $(addprefix $(src_dir)/, $(sprojs_enabled)), \ + $(patsubst %, /%.ac, $(sprojs_enabled))) + +$(src_dir)/configure : $(configure_prereq) + cd $(src_dir) && autoconf && autoheader + +config.status : $(src_dir)/configure + ./config.status --recheck + +sprojs_mk_in = \ + $(join $(addprefix $(src_dir)/, $(sprojs_enabled)), \ + $(patsubst %, /%.mk.in, $(sprojs_enabled))) + +Makefile : $(src_dir)/Makefile.in $(sprojs_mk_in) config.status + ./config.status + +dist_junk += config.status config.h Makefile config.log + +#------------------------------------------------------------------------- +# Distribution +#------------------------------------------------------------------------- +# The distribution tarball is named project-ver.tar.gz and it includes +# both enabled and disabled subprojects. + +dist_files = \ + $(sprojs) \ + README \ + style-guide.txt \ + mcppbs-uguide.txt \ + scripts \ + configure.ac \ + aclocal.m4 \ + configure \ + config.h.in \ + Makefile.in \ + +dist_dir := $(project_name)-$(project_ver) +dist_tgz := $(project_name)-$(project_ver).tar.gz + +# Notice that when we make the distribution we rewrite the configure.ac +# script with the current version and we rerun autoconf in the new +# source directory so that the distribution will have the proper version +# information. We also rewrite the "Version : " line in the README. + +dist : + rm -rf $(dist_dir) + mkdir $(dist_dir) + tar -C $(src_dir) -cf - $(dist_files) | tar -C $(dist_dir) -xpf - + sed -i.bak 's/^\(# Version :\).*/\1 $(project_ver)/' $(dist_dir)/README + sed -i.bak 's/\( proj_version,\).*/\1 [$(project_ver)])/' $(dist_dir)/configure.ac + cd $(dist_dir) && \ + autoconf && autoheader && \ + rm -rf autom4te.cache configure.ac.bak README.bak + tar -czvf $(dist_tgz) $(dist_dir) + rm -rf $(dist_dir) + +# You can use the distcheck target to try untarring the distribution and +# then running configure, make, make check, and make distclean. A +# "directory is not empty" error means distclean is not removing +# everything. + +distcheck : dist + rm -rf $(dist_dir) + tar -xzvf $(dist_tgz) + mkdir -p $(dist_dir)/build + cd $(dist_dir)/build; ../configure; make; make check; make distclean + rm -rf $(dist_dir) + +junk += $(project_name)-*.tar.gz + +.PHONY : dist distcheck + +#------------------------------------------------------------------------- +# Default +#------------------------------------------------------------------------- + +all : $(install_hdrs) $(install_libs) $(install_exes) +.PHONY : all + +#------------------------------------------------------------------------- +# Makefile debugging +#------------------------------------------------------------------------- +# This handy rule will display the contents of any make variable by +# using the target debug-. So for example, make debug-junk will +# display the contents of the junk variable. + +debug-% : + @echo $* = $($*) + +#------------------------------------------------------------------------- +# Clean up junk +#------------------------------------------------------------------------- + +clean : + rm -rf *~ \#* $(junk) + +distclean : + rm -rf *~ \#* $(junk) $(dist_junk) + +.PHONY : clean distclean diff --git a/README b/README new file mode 100644 index 0000000..676eff7 --- /dev/null +++ b/README @@ -0,0 +1,61 @@ +========================================================================== +RISC-V ISA Simulator +========================================================================== +# Author : Andrew Waterman +# Date : June 19, 2011 +# Version : (under version control) + +The RISC-V ISA Simulator implements a functional model of one or more +RISC-V processors. + +-------------------------------------------------------------------------- +Build Steps +-------------------------------------------------------------------------- + + % mkdir build + % cd build + % ../configure + % make + % [sudo] make install + +-------------------------------------------------------------------------- +Usage +-------------------------------------------------------------------------- + +The riscv-isa-run program is not usually invoked directly; rather, fesvr, the +Front-End Server, invokes riscv-isa-run. fesvr and riscv-pk must be installed +to simulate a RISC-V user program using riscv-isa-run. + +-------------------------------------------------------------------------- +Compiling and Running a Simple C Program +-------------------------------------------------------------------------- + +Install riscv-isa-run (see Build Steps), then install the following additional +packages: riscv-fesvr, riscv-gcc, riscv-pk. + +Write a short C program and name it hello.c. Then, compile it into a RISC-V +ELF binary named hello: + + % riscv-gcc -o hello hello.c + +Now you can simulate the program: + + % riscv-fesvr hello + +-------------------------------------------------------------------------- +Simulating a New Instruction +-------------------------------------------------------------------------- + +Adding an instruction to the simulator requires two steps: + + 1. Describe the instruction's functional behavior in the file + riscv/insns/.h. Examine other instructions + in that directory as a starting point. + + 2. Add the instruction to the riscv-opcodes package: + + % cd ../riscv-opcodes + % vi opcodes // add a line for the new instruction + % make install + + 3. Rebuild the simulator. diff --git a/aclocal.m4 b/aclocal.m4 new file mode 100644 index 0000000..15353f2 --- /dev/null +++ b/aclocal.m4 @@ -0,0 +1,345 @@ +#========================================================================= +# Local Autoconf Macros +#========================================================================= +# This file contains the macros for the Modular C++ Build System and +# additional autoconf macros which developers can use in their +# configure.ac scripts. Please read the documentation in +# 'mcppbs-doc.txt' for more details on how the Modular C++ Build System +# works. The documenation for each macro should include information +# about the author, date, and copyright. + +#------------------------------------------------------------------------- +# MCPPBS_PROG_INSTALL +#------------------------------------------------------------------------- +# This macro will add an --enable-stow command line option to the +# configure script. When enabled, this macro will first check to see if +# the stow program is available and if so it will set the $stow shell +# variable to the binary name and the $enable_stow shell variable to +# "yes". These variables can be used in a makefile to conditionally use +# stow for installation. +# +# This macro uses two environment variables to help setup default stow +# locations. The $STOW_PREFIX is used for stowing native built packages. +# The packages are staged in $STOW_PREFIX/pkgs and then symlinks are +# created from within $STOW_PREFIX into the pkgs subdirectory. If you +# only do native builds then this is all you need to set. If you don't +# set $STOW_PREFIX then the default is just the normal default prefix +# which is almost always /usr/local. +# +# For non-native builds we probably want to install the packages in a +# different location which includes the host architecture name as part +# of the prefix. For these kind of builds, we can specify the $STOW_ROOT +# environment variable and the effective prefix will be +# $STOW_ROOT/${host_alias} where ${host_alias} is specified on the +# configure command line with "--host". +# +# Here is an example setup: +# +# STOW_ROOT="$HOME/install" +# STOW_ARCH="i386-macosx10.4" +# STOW_PREFIX="${STOW_ROOT}/${STOW_ARCH}" +# + +AC_DEFUN([MCPPBS_PROG_INSTALL], +[ + + # Configure command line option + + AC_ARG_ENABLE(stow, + AS_HELP_STRING(--enable-stow,[Enable stow-based install]), + [enable_stow="yes"],[enable_stow="no"]) + + AC_SUBST([enable_stow]) + + # Environment variables + + AC_ARG_VAR([STOW_ROOT], [Root for non-native stow-based installs]) + AC_ARG_VAR([STOW_PREFIX], [Prefix for stow-based installs]) + + # Check for install script + + AC_PROG_INSTALL + + # Deterimine if native build and set prefix appropriately + + AS_IF([ test ${enable_stow} = "yes" ], + [ + AC_CHECK_PROGS([stow],[stow],[no]) + AS_IF([ test ${stow} = "no" ], + [ + AC_MSG_ERROR([Cannot use --enable-stow since stow is not available]) + ]) + + # Check if native or non-native build + + AS_IF([ test "${build}" = "${host}" ], + [ + + # build == host so this is a native build. Make sure --prefix not + # set and $STOW_PREFIX is set, then set prefix=$STOW_PREFIX. + + AS_IF([ test "${prefix}" = "NONE" && test -n "${STOW_PREFIX}" ], + [ + prefix="${STOW_PREFIX}" + AC_MSG_NOTICE([Using \$STOW_PREFIX from environment]) + AC_MSG_NOTICE([prefix=${prefix}]) + ]) + + ],[ + + # build != host so this is a non-native build. Make sure --prefix + # not set and $STOW_ROOT is set, then set + # prefix=$STOW_ROOT/${host_alias}. + + AS_IF([ test "${prefix}" = "NONE" && test -n "${STOW_ROOT}" ], + [ + prefix="${STOW_ROOT}/${host_alias}" + AC_MSG_NOTICE([Using \$STOW_ROOT from environment]) + AC_MSG_NOTICE([prefix=${prefix}]) + ]) + + ]) + + ]) + +]) + +#------------------------------------------------------------------------- +# MCPPBS_PROG_RUN +# ------------------------------------------------------------------------- +# If we are doing a non-native build then we look for an isa simulator +# to use for running tests. We set the RUN substitution variable to be +# empty for native builds or to the name of the isa simulator for +# non-native builds. Thus a makefile can run compiled programs +# regardless if we are doing a native or non-native build like this: +# +# $(RUN) $(RUNFLAGS) ./test-program +# + +AC_DEFUN([MCPPBS_PROG_RUN], +[ + AS_IF([ test "${build}" != "${host}" ], + [ + AC_CHECK_TOOLS([RUN],[isa-run run],[no]) + AS_IF([ test ${RUN} = "no" ], + [ + AC_MSG_ERROR([Cannot find simulator for target ${target_alias}]) + ]) + ],[ + RUN="" + ]) + AC_SUBST([RUN]) + AC_SUBST([RUNFLAGS]) +]) + +#------------------------------------------------------------------------- +# MCPPBS_SUBPROJECTS([ sproj1, sproj2, ... ]) +#------------------------------------------------------------------------- +# The developer should call this macro with a list of the subprojects +# which make up this project. One should order the list such that any +# given subproject only depends on subprojects listed before it. The +# subproject names can also include an * suffix which indicates that +# this is an optional subproject. Optional subprojects are only included +# as part of the project build if enabled on the configure command line +# with a --enable- flag. The user can also specify that all +# optional subprojects should be included in the build with the +# --enable-optional-subprojects flag. +# +# Subproject names can also include a ** suffix which indicates that it +# is an optional subproject, but there is a group with the same name. +# Thus the --enable- command line option will enable not just the +# subproject sproj but all of the subprojects which are in the group. +# There is no error checking to make sure that if you use the ** suffix +# you actually define a group so be careful. +# +# Both required and optional subprojects should have a 'subproject.ac' +# file. The script's filename should be the abbreivated subproject name +# (assuming the subproject name is sproj then we would use 'sproj.ac') +# The MCPPBS_SUBPROJECTS macro includes the 'subproject.ac' files for +# enabled subprojects. Whitespace and newlines are allowed within the +# list. +# +# Author : Christopher Batten +# Date : September 10, 2008 + +AC_DEFUN([MCPPBS_SUBPROJECTS], +[ + + # Add command line argument to enable all optional subprojects + + AC_ARG_ENABLE(optional-subprojects, + AS_HELP_STRING([--enable-optional-subprojects], + [Enable all optional subprojects])) + + # Loop through the subprojects given in the macro argument + + m4_foreach([MCPPBS_SPROJ],[$1], + [ + + # Determine if this is a required or an optional subproject + + m4_define([MCPPBS_IS_REQ], + m4_bmatch(MCPPBS_SPROJ,[\*+],[false],[true])) + + # Determine if there is a group with the same name + + m4_define([MCPPBS_IS_GROUP], + m4_bmatch(MCPPBS_SPROJ,[\*\*],[true],[false])) + + # Create variations of the subproject name suitable for use as a CPP + # enabled define, a shell enabled variable, and a shell function + + m4_define([MCPPBS_SPROJ_NORM], + m4_normalize(m4_bpatsubsts(MCPPBS_SPROJ,[*],[]))) + + m4_define([MCPPBS_SPROJ_DEFINE], + m4_toupper(m4_bpatsubst(MCPPBS_SPROJ_NORM[]_ENABLED,[-],[_]))) + + m4_define([MCPPBS_SPROJ_FUNC], + m4_bpatsubst(_mpbp_[]MCPPBS_SPROJ_NORM[]_configure,[-],[_])) + + m4_define([MCPPBS_SPROJ_UNDERSCORES], + m4_bpatsubsts(MCPPBS_SPROJ,[-],[_])) + + m4_define([MCPPBS_SPROJ_SHVAR], + m4_bpatsubst(enable_[]MCPPBS_SPROJ_NORM[]_sproj,[-],[_])) + + # Add subproject to our running list + + subprojects="$subprojects MCPPBS_SPROJ_NORM" + + # Process the subproject appropriately. If enabled add it to the + # $enabled_subprojects running shell variable, set a + # SUBPROJECT_ENABLED C define, and include the appropriate + # 'subproject.ac'. + + m4_if(MCPPBS_IS_REQ,[true], + [ + AC_MSG_NOTICE([configuring default subproject : MCPPBS_SPROJ_NORM]) + AC_CONFIG_FILES(MCPPBS_SPROJ_NORM[].mk:MCPPBS_SPROJ_NORM[]/MCPPBS_SPROJ_NORM[].mk.in) + MCPPBS_SPROJ_SHVAR="yes" + subprojects_enabled="$subprojects_enabled MCPPBS_SPROJ_NORM" + AC_DEFINE(MCPPBS_SPROJ_DEFINE,, + [Define if subproject MCPPBS_SPROJ_NORM is enabled]) + m4_include(MCPPBS_SPROJ_NORM[]/MCPPBS_SPROJ_NORM[].ac) + ],[ + + # For optional subprojects we capture the 'subproject.ac' as a + # shell function so that in the MCPPBS_GROUP macro we can just + # call this shell function instead of reading in 'subproject.ac' + # again. + + MCPPBS_SPROJ_FUNC () + { + AC_MSG_NOTICE([configuring optional subproject : MCPPBS_SPROJ_NORM]) + AC_CONFIG_FILES(MCPPBS_SPROJ_NORM[].mk:MCPPBS_SPROJ_NORM[]/MCPPBS_SPROJ_NORM[].mk.in) + MCPPBS_SPROJ_SHVAR="yes" + subprojects_enabled="$subprojects_enabled MCPPBS_SPROJ_NORM" + AC_DEFINE(MCPPBS_SPROJ_DEFINE,, + [Define if subproject MCPPBS_SPROJ_NORM is enabled]) + m4_include(MCPPBS_SPROJ_NORM[]/MCPPBS_SPROJ_NORM[].ac) + }; + + # Optional subprojects add --enable-subproject command line + # options, _if_ the subproject name is not also a group name. + + m4_if(MCPPBS_IS_GROUP,[false], + [ + AC_ARG_ENABLE(MCPPBS_SPROJ_NORM, + AS_HELP_STRING(--enable-MCPPBS_SPROJ_NORM, + [Subproject MCPPBS_SPROJ_NORM]), + [MCPPBS_SPROJ_SHVAR="yes"],[MCPPBS_SPROJ_SHVAR="no"]) + + AS_IF([test "$MCPPBS_SPROJ_SHVAR" = "yes"], + [ + eval "MCPPBS_SPROJ_FUNC" + ],[ + AC_MSG_NOTICE([processing optional subproject : MCPPBS_SPROJ_NORM]) + ]) + + ],[ + + # If the subproject name is also a group name then we need to + # make sure that we set the shell variable for that subproject to + # no so that the group code knows we haven't run it yet. + + AC_MSG_NOTICE([processing optional subproject : MCPPBS_SPROJ_NORM]) + MCPPBS_SPROJ_SHVAR="no" + + ]) + + # Always execute the subproject configure code if we are enabling + # all subprojects. + + AS_IF([ test "$enable_optional_subprojects" = "yes" \ + && test "$MCPPBS_SPROJ_SHVAR" = "no" ], + [ + eval "MCPPBS_SPROJ_FUNC" + ]) + + ]) + + ]) + + # Output make variables + + AC_SUBST([subprojects]) + AC_SUBST([subprojects_enabled]) + +]) + +#------------------------------------------------------------------------- +# MCPPBS_GROUP( [group-name], [ sproj1, sproj2, ... ] ) +#------------------------------------------------------------------------- +# This macro creates a subproject group with the given group-name. When +# a user specifies --enable- the listed subprojects will be +# enabled. Groups can have the same name as a subproject and in that +# case whenever a user specifies --enable- the subprojects +# listed in the corresponding group will also be enabled. Groups are +# useful for specifying related subprojects which are usually enabled +# together, as well as for specifying that a specific optional +# subproject has dependencies on other optional subprojects. +# +# Author : Christopher Batten +# Date : September 10, 2008 + +AC_DEFUN([MCPPBS_GROUP], +[ + + m4_define([MCPPBS_GROUP_NORM], + m4_normalize([$1])) + + m4_define([MCPPBS_GROUP_SHVAR], + m4_bpatsubst(enable_[]MCPPBS_GROUP_NORM[]_group,[-],[_])) + + AC_ARG_ENABLE(MCPPBS_GROUP_NORM, + AS_HELP_STRING(--enable-MCPPBS_GROUP_NORM, + [Group MCPPBS_GROUP_NORM: $2]), + [MCPPBS_GROUP_SHVAR="yes"],[MCPPBS_GROUP_SHVAR="no"]) + + AS_IF([test "$MCPPBS_GROUP_SHVAR" = "yes" ], + [ + AC_MSG_NOTICE([configuring optional group : MCPPBS_GROUP_NORM]) + ]) + + m4_foreach([MCPPBS_SPROJ],[$2], + [ + + m4_define([MCPPBS_SPROJ_NORM], + m4_normalize(MCPPBS_SPROJ)) + + m4_define([MCPPBS_SPROJ_SHVAR], + m4_bpatsubst(enable_[]MCPPBS_SPROJ_NORM[]_sproj,[-],[_])) + + m4_define([MCPPBS_SPROJ_FUNC], + m4_bpatsubst(_mpbp_[]MCPPBS_SPROJ_NORM[]_configure,[-],[_])) + + AS_IF([ test "$MCPPBS_GROUP_SHVAR" = "yes" \ + && test "$MCPPBS_SPROJ_SHVAR" = "no" ], + [ + eval "MCPPBS_SPROJ_FUNC" + ]) + + ]) + +]) diff --git a/config.h.in b/config.h.in new file mode 100644 index 0000000..e592810 --- /dev/null +++ b/config.h.in @@ -0,0 +1,46 @@ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the home page for this package. */ +#undef PACKAGE_URL + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Define if subproject MCPPBS_SPROJ_NORM is enabled */ +#undef RISCV_ENABLED + +/* Define if 64-bit mode is supported */ +#undef RISCV_ENABLE_64BIT + +/* Define if floating-point instructions are supported */ +#undef RISCV_ENABLE_FPU + +/* Define if instruction compression is supported */ +#undef RISCV_ENABLE_RVC + +/* Define if vector processor is supported */ +#undef RISCV_ENABLE_VEC + +/* Define if libopcodes exists */ +#undef RISCV_HAVE_LIBOPCODES + +/* Define if subproject MCPPBS_SPROJ_NORM is enabled */ +#undef SOFTFLOAT_ENABLED + +/* Define if subproject MCPPBS_SPROJ_NORM is enabled */ +#undef SOFTFLOAT_RISCV_ENABLED + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS diff --git a/configure b/configure new file mode 100755 index 0000000..ea16b08 --- /dev/null +++ b/configure @@ -0,0 +1,5561 @@ +#! /bin/sh +# Guess values for system-dependent variables and create Makefiles. +# Generated by GNU Autoconf 2.64 for RISC-V ISA Simulator ?. +# +# Report bugs to . +# +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, +# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software +# Foundation, Inc. +# +# This configure script is free software; the Free Software Foundation +# gives unlimited permission to copy, distribute and modify it. +## -------------------- ## +## M4sh Initialization. ## +## -------------------- ## + +# Be more Bourne compatible +DUALCASE=1; export DUALCASE # for MKS sh +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : + emulate sh + NULLCMD=: + # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in #( + *posix*) : + set -o posix ;; #( + *) : + ;; +esac +fi + + +as_nl=' +' +export as_nl +# Printing a long string crashes Solaris 7 /usr/bin/printf. +as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo +# Prefer a ksh shell builtin over an external printf program on Solaris, +# but without wasting forks for bash or zsh. +if test -z "$BASH_VERSION$ZSH_VERSION" \ + && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='print -r --' + as_echo_n='print -rn --' +elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='printf %s\n' + as_echo_n='printf %s' +else + if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then + as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' + as_echo_n='/usr/ucb/echo -n' + else + as_echo_body='eval expr "X$1" : "X\\(.*\\)"' + as_echo_n_body='eval + arg=$1; + case $arg in #( + *"$as_nl"*) + expr "X$arg" : "X\\(.*\\)$as_nl"; + arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; + esac; + expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" + ' + export as_echo_n_body + as_echo_n='sh -c $as_echo_n_body as_echo' + fi + export as_echo_body + as_echo='sh -c $as_echo_body as_echo' +fi + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + PATH_SEPARATOR=: + (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { + (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || + PATH_SEPARATOR=';' + } +fi + + +# IFS +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent editors from complaining about space-tab. +# (If _AS_PATH_WALK were called with IFS unset, it would disable word +# splitting by setting IFS to empty value.) +IFS=" "" $as_nl" + +# Find who we are. Look in the path if we contain no directory separator. +case $0 in #(( + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break + done +IFS=$as_save_IFS + + ;; +esac +# We did not find ourselves, most probably we were run as `sh COMMAND' +# in which case we are not to be found in the path. +if test "x$as_myself" = x; then + as_myself=$0 +fi +if test ! -f "$as_myself"; then + $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + exit 1 +fi + +# Unset variables that we do not need and which cause bugs (e.g. in +# pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" +# suppresses any "Segmentation fault" message there. '((' could +# trigger a bug in pdksh 5.2.14. +for as_var in BASH_ENV ENV MAIL MAILPATH +do eval test x\${$as_var+set} = xset \ + && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : +done +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +LC_ALL=C +export LC_ALL +LANGUAGE=C +export LANGUAGE + +# CDPATH. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +if test "x$CONFIG_SHELL" = x; then + as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : + emulate sh + NULLCMD=: + # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which + # is contrary to our usage. Disable this feature. + alias -g '\${1+\"\$@\"}'='\"\$@\"' + setopt NO_GLOB_SUBST +else + case \`(set -o) 2>/dev/null\` in #( + *posix*) : + set -o posix ;; #( + *) : + ;; +esac +fi +" + as_required="as_fn_return () { (exit \$1); } +as_fn_success () { as_fn_return 0; } +as_fn_failure () { as_fn_return 1; } +as_fn_ret_success () { return 0; } +as_fn_ret_failure () { return 1; } + +exitcode=0 +as_fn_success || { exitcode=1; echo as_fn_success failed.; } +as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; } +as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; } +as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; } +if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then : + +else + exitcode=1; echo positional parameters were not saved. +fi +test x\$exitcode = x0 || exit 1" + as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO + as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO + eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && + test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1 +test \$(( 1 + 1 )) = 2 || exit 1" + if (eval "$as_required") 2>/dev/null; then : + as_have_required=yes +else + as_have_required=no +fi + if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then : + +else + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +as_found=false +for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + as_found=: + case $as_dir in #( + /*) + for as_base in sh bash ksh sh5; do + # Try only shells that exist, to save several forks. + as_shell=$as_dir/$as_base + if { test -f "$as_shell" || test -f "$as_shell.exe"; } && + { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then : + CONFIG_SHELL=$as_shell as_have_required=yes + if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then : + break 2 +fi +fi + done;; + esac + as_found=false +done +$as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } && + { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then : + CONFIG_SHELL=$SHELL as_have_required=yes +fi; } +IFS=$as_save_IFS + + + if test "x$CONFIG_SHELL" != x; then : + # We cannot yet assume a decent shell, so we have to provide a + # neutralization value for shells without unset; and this also + # works around shells that cannot unset nonexistent variables. + BASH_ENV=/dev/null + ENV=/dev/null + (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV + export CONFIG_SHELL + exec "$CONFIG_SHELL" "$as_myself" ${1+"$@"} +fi + + if test x$as_have_required = xno; then : + $as_echo "$0: This script requires a shell more modern than all" + $as_echo "$0: the shells that I found on your system." + if test x${ZSH_VERSION+set} = xset ; then + $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should" + $as_echo "$0: be upgraded to zsh 4.3.4 or later." + else + $as_echo "$0: Please tell bug-autoconf@gnu.org and Andrew Waterman +$0: about your system, including any error possibly output +$0: before this message. Then install a modern shell, or +$0: manually run the script under such a shell if you do +$0: have one." + fi + exit 1 +fi +fi +fi +SHELL=${CONFIG_SHELL-/bin/sh} +export SHELL +# Unset more variables known to interfere with behavior of common tools. +CLICOLOR_FORCE= GREP_OPTIONS= +unset CLICOLOR_FORCE GREP_OPTIONS + +## --------------------- ## +## M4sh Shell Functions. ## +## --------------------- ## +# as_fn_unset VAR +# --------------- +# Portably unset VAR. +as_fn_unset () +{ + { eval $1=; unset $1;} +} +as_unset=as_fn_unset + +# as_fn_set_status STATUS +# ----------------------- +# Set $? to STATUS, without forking. +as_fn_set_status () +{ + return $1 +} # as_fn_set_status + +# as_fn_exit STATUS +# ----------------- +# Exit the shell with STATUS, even in a "trap 0" or "set -e" context. +as_fn_exit () +{ + set +e + as_fn_set_status $1 + exit $1 +} # as_fn_exit + +# as_fn_mkdir_p +# ------------- +# Create "$as_dir" as a directory, including parents if necessary. +as_fn_mkdir_p () +{ + + case $as_dir in #( + -*) as_dir=./$as_dir;; + esac + test -d "$as_dir" || eval $as_mkdir_p || { + as_dirs= + while :; do + case $as_dir in #( + *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( + *) as_qdir=$as_dir;; + esac + as_dirs="'$as_qdir' $as_dirs" + as_dir=`$as_dirname -- "$as_dir" || +$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_dir" : 'X\(//\)[^/]' \| \ + X"$as_dir" : 'X\(//\)$' \| \ + X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$as_dir" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + test -d "$as_dir" && break + done + test -z "$as_dirs" || eval "mkdir $as_dirs" + } || test -d "$as_dir" || as_fn_error "cannot create directory $as_dir" + + +} # as_fn_mkdir_p +# as_fn_append VAR VALUE +# ---------------------- +# Append the text in VALUE to the end of the definition contained in VAR. Take +# advantage of any shell optimizations that allow amortized linear growth over +# repeated appends, instead of the typical quadratic growth present in naive +# implementations. +if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : + eval 'as_fn_append () + { + eval $1+=\$2 + }' +else + as_fn_append () + { + eval $1=\$$1\$2 + } +fi # as_fn_append + +# as_fn_arith ARG... +# ------------------ +# Perform arithmetic evaluation on the ARGs, and store the result in the +# global $as_val. Take advantage of shells that can avoid forks. The arguments +# must be portable across $(()) and expr. +if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : + eval 'as_fn_arith () + { + as_val=$(( $* )) + }' +else + as_fn_arith () + { + as_val=`expr "$@" || test $? -eq 1` + } +fi # as_fn_arith + + +# as_fn_error ERROR [LINENO LOG_FD] +# --------------------------------- +# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are +# provided, also output the error to LOG_FD, referencing LINENO. Then exit the +# script with status $?, using 1 if that was 0. +as_fn_error () +{ + as_status=$?; test $as_status -eq 0 && as_status=1 + if test "$3"; then + as_lineno=${as_lineno-"$2"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + $as_echo "$as_me:${as_lineno-$LINENO}: error: $1" >&$3 + fi + $as_echo "$as_me: error: $1" >&2 + as_fn_exit $as_status +} # as_fn_error + +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + +if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then + as_dirname=dirname +else + as_dirname=false +fi + +as_me=`$as_basename -- "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + + + as_lineno_1=$LINENO as_lineno_1a=$LINENO + as_lineno_2=$LINENO as_lineno_2a=$LINENO + eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" && + test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || { + # Blame Lee E. McMahon (1931-1989) for sed's syntax. :-) + sed -n ' + p + /[$]LINENO/= + ' <$as_myself | + sed ' + s/[$]LINENO.*/&-/ + t lineno + b + :lineno + N + :loop + s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ + t loop + s/-\n.*// + ' >$as_me.lineno && + chmod +x "$as_me.lineno" || + { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } + + # Don't try to exec as it changes $[0], causing all sort of problems + # (the dirname of $[0] is not the place where we might find the + # original and so on. Autoconf is especially sensitive to this). + . "./$as_me.lineno" + # Exit status is that of the last command. + exit +} + +ECHO_C= ECHO_N= ECHO_T= +case `echo -n x` in #((((( +-n*) + case `echo 'xy\c'` in + *c*) ECHO_T=' ';; # ECHO_T is single tab character. + xy) ECHO_C='\c';; + *) echo `echo ksh88 bug on AIX 6.1` > /dev/null + ECHO_T=' ';; + esac;; +*) + ECHO_N='-n';; +esac + +rm -f conf$$ conf$$.exe conf$$.file +if test -d conf$$.dir; then + rm -f conf$$.dir/conf$$.file +else + rm -f conf$$.dir + mkdir conf$$.dir 2>/dev/null +fi +if (echo >conf$$.file) 2>/dev/null; then + if ln -s conf$$.file conf$$ 2>/dev/null; then + as_ln_s='ln -s' + # ... but there are two gotchas: + # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. + # In both cases, we have to default to `cp -p'. + ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || + as_ln_s='cp -p' + elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln + else + as_ln_s='cp -p' + fi +else + as_ln_s='cp -p' +fi +rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file +rmdir conf$$.dir 2>/dev/null + +if mkdir -p . 2>/dev/null; then + as_mkdir_p='mkdir -p "$as_dir"' +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + +if test -x / >/dev/null 2>&1; then + as_test_x='test -x' +else + if ls -dL / >/dev/null 2>&1; then + as_ls_L_option=L + else + as_ls_L_option= + fi + as_test_x=' + eval sh -c '\'' + if test -d "$1"; then + test -d "$1/."; + else + case $1 in #( + -*)set "./$1";; + esac; + case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #(( + ???[sx]*):;;*)false;;esac;fi + '\'' sh + ' +fi +as_executable_p=$as_test_x + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + + +exec 7<&0 &1 + +# Name of the host. +# hostname on some systems (SVR3.2, Linux) returns a bogus exit status, +# so uname gets run too. +ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` + +# +# Initializations. +# +ac_default_prefix=/usr/local +ac_clean_files= +ac_config_libobj_dir=. +LIBOBJS= +cross_compiling=no +subdirs= +MFLAGS= +MAKEFLAGS= + +# Identity of this package. +PACKAGE_NAME='RISC-V ISA Simulator' +PACKAGE_TARNAME='riscv-isa-run' +PACKAGE_VERSION='?' +PACKAGE_STRING='RISC-V ISA Simulator ?' +PACKAGE_BUGREPORT='Andrew Waterman' +PACKAGE_URL='' + +ac_unique_file="riscv/common.h" +ac_subst_vars='LTLIBOBJS +LIBOBJS +subprojects_enabled +subprojects +EGREP +GREP +CPP +RUNFLAGS +ac_ct_RUN +RUN +stow +INSTALL_DATA +INSTALL_SCRIPT +INSTALL_PROGRAM +STOW_PREFIX +STOW_ROOT +enable_stow +RANLIB +AR +ac_ct_CXX +CXXFLAGS +CXX +OBJEXT +EXEEXT +ac_ct_CC +CPPFLAGS +LDFLAGS +CFLAGS +CC +host_os +host_vendor +host_cpu +host +build_os +build_vendor +build_cpu +build +target_alias +host_alias +build_alias +LIBS +ECHO_T +ECHO_N +ECHO_C +DEFS +mandir +localedir +libdir +psdir +pdfdir +dvidir +htmldir +infodir +docdir +oldincludedir +includedir +localstatedir +sharedstatedir +sysconfdir +datadir +datarootdir +libexecdir +sbindir +bindir +program_transform_name +prefix +exec_prefix +PACKAGE_URL +PACKAGE_BUGREPORT +PACKAGE_STRING +PACKAGE_VERSION +PACKAGE_TARNAME +PACKAGE_NAME +PATH_SEPARATOR +SHELL' +ac_subst_files='' +ac_user_opts=' +enable_option_checking +enable_stow +enable_optional_subprojects +enable_fpu +enable_64bit +enable_rvc +enable_vec +' + ac_precious_vars='build_alias +host_alias +target_alias +CC +CFLAGS +LDFLAGS +LIBS +CPPFLAGS +CXX +CXXFLAGS +CCC +STOW_ROOT +STOW_PREFIX +CPP' + + +# Initialize some variables set by options. +ac_init_help= +ac_init_version=false +ac_unrecognized_opts= +ac_unrecognized_sep= +# The variables have the same names as the options, with +# dashes changed to underlines. +cache_file=/dev/null +exec_prefix=NONE +no_create= +no_recursion= +prefix=NONE +program_prefix=NONE +program_suffix=NONE +program_transform_name=s,x,x, +silent= +site= +srcdir= +verbose= +x_includes=NONE +x_libraries=NONE + +# Installation directory options. +# These are left unexpanded so users can "make install exec_prefix=/foo" +# and all the variables that are supposed to be based on exec_prefix +# by default will actually change. +# Use braces instead of parens because sh, perl, etc. also accept them. +# (The list follows the same order as the GNU Coding Standards.) +bindir='${exec_prefix}/bin' +sbindir='${exec_prefix}/sbin' +libexecdir='${exec_prefix}/libexec' +datarootdir='${prefix}/share' +datadir='${datarootdir}' +sysconfdir='${prefix}/etc' +sharedstatedir='${prefix}/com' +localstatedir='${prefix}/var' +includedir='${prefix}/include' +oldincludedir='/usr/include' +docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' +infodir='${datarootdir}/info' +htmldir='${docdir}' +dvidir='${docdir}' +pdfdir='${docdir}' +psdir='${docdir}' +libdir='${exec_prefix}/lib' +localedir='${datarootdir}/locale' +mandir='${datarootdir}/man' + +ac_prev= +ac_dashdash= +for ac_option +do + # If the previous option needs an argument, assign it. + if test -n "$ac_prev"; then + eval $ac_prev=\$ac_option + ac_prev= + continue + fi + + case $ac_option in + *=*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; + *) ac_optarg=yes ;; + esac + + # Accept the important Cygnus configure options, so we can diagnose typos. + + case $ac_dashdash$ac_option in + --) + ac_dashdash=yes ;; + + -bindir | --bindir | --bindi | --bind | --bin | --bi) + ac_prev=bindir ;; + -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) + bindir=$ac_optarg ;; + + -build | --build | --buil | --bui | --bu) + ac_prev=build_alias ;; + -build=* | --build=* | --buil=* | --bui=* | --bu=*) + build_alias=$ac_optarg ;; + + -cache-file | --cache-file | --cache-fil | --cache-fi \ + | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) + ac_prev=cache_file ;; + -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ + | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) + cache_file=$ac_optarg ;; + + --config-cache | -C) + cache_file=config.cache ;; + + -datadir | --datadir | --datadi | --datad) + ac_prev=datadir ;; + -datadir=* | --datadir=* | --datadi=* | --datad=*) + datadir=$ac_optarg ;; + + -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \ + | --dataroo | --dataro | --datar) + ac_prev=datarootdir ;; + -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \ + | --dataroot=* | --dataroo=* | --dataro=* | --datar=*) + datarootdir=$ac_optarg ;; + + -disable-* | --disable-*) + ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error "invalid feature name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"enable_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval enable_$ac_useropt=no ;; + + -docdir | --docdir | --docdi | --doc | --do) + ac_prev=docdir ;; + -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*) + docdir=$ac_optarg ;; + + -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv) + ac_prev=dvidir ;; + -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*) + dvidir=$ac_optarg ;; + + -enable-* | --enable-*) + ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error "invalid feature name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"enable_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval enable_$ac_useropt=\$ac_optarg ;; + + -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ + | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ + | --exec | --exe | --ex) + ac_prev=exec_prefix ;; + -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ + | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ + | --exec=* | --exe=* | --ex=*) + exec_prefix=$ac_optarg ;; + + -gas | --gas | --ga | --g) + # Obsolete; use --with-gas. + with_gas=yes ;; + + -help | --help | --hel | --he | -h) + ac_init_help=long ;; + -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) + ac_init_help=recursive ;; + -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) + ac_init_help=short ;; + + -host | --host | --hos | --ho) + ac_prev=host_alias ;; + -host=* | --host=* | --hos=* | --ho=*) + host_alias=$ac_optarg ;; + + -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht) + ac_prev=htmldir ;; + -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \ + | --ht=*) + htmldir=$ac_optarg ;; + + -includedir | --includedir | --includedi | --included | --include \ + | --includ | --inclu | --incl | --inc) + ac_prev=includedir ;; + -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ + | --includ=* | --inclu=* | --incl=* | --inc=*) + includedir=$ac_optarg ;; + + -infodir | --infodir | --infodi | --infod | --info | --inf) + ac_prev=infodir ;; + -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) + infodir=$ac_optarg ;; + + -libdir | --libdir | --libdi | --libd) + ac_prev=libdir ;; + -libdir=* | --libdir=* | --libdi=* | --libd=*) + libdir=$ac_optarg ;; + + -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ + | --libexe | --libex | --libe) + ac_prev=libexecdir ;; + -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ + | --libexe=* | --libex=* | --libe=*) + libexecdir=$ac_optarg ;; + + -localedir | --localedir | --localedi | --localed | --locale) + ac_prev=localedir ;; + -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*) + localedir=$ac_optarg ;; + + -localstatedir | --localstatedir | --localstatedi | --localstated \ + | --localstate | --localstat | --localsta | --localst | --locals) + ac_prev=localstatedir ;; + -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ + | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*) + localstatedir=$ac_optarg ;; + + -mandir | --mandir | --mandi | --mand | --man | --ma | --m) + ac_prev=mandir ;; + -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) + mandir=$ac_optarg ;; + + -nfp | --nfp | --nf) + # Obsolete; use --without-fp. + with_fp=no ;; + + -no-create | --no-create | --no-creat | --no-crea | --no-cre \ + | --no-cr | --no-c | -n) + no_create=yes ;; + + -no-recursion | --no-recursion | --no-recursio | --no-recursi \ + | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) + no_recursion=yes ;; + + -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ + | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ + | --oldin | --oldi | --old | --ol | --o) + ac_prev=oldincludedir ;; + -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ + | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ + | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) + oldincludedir=$ac_optarg ;; + + -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) + ac_prev=prefix ;; + -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) + prefix=$ac_optarg ;; + + -program-prefix | --program-prefix | --program-prefi | --program-pref \ + | --program-pre | --program-pr | --program-p) + ac_prev=program_prefix ;; + -program-prefix=* | --program-prefix=* | --program-prefi=* \ + | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) + program_prefix=$ac_optarg ;; + + -program-suffix | --program-suffix | --program-suffi | --program-suff \ + | --program-suf | --program-su | --program-s) + ac_prev=program_suffix ;; + -program-suffix=* | --program-suffix=* | --program-suffi=* \ + | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) + program_suffix=$ac_optarg ;; + + -program-transform-name | --program-transform-name \ + | --program-transform-nam | --program-transform-na \ + | --program-transform-n | --program-transform- \ + | --program-transform | --program-transfor \ + | --program-transfo | --program-transf \ + | --program-trans | --program-tran \ + | --progr-tra | --program-tr | --program-t) + ac_prev=program_transform_name ;; + -program-transform-name=* | --program-transform-name=* \ + | --program-transform-nam=* | --program-transform-na=* \ + | --program-transform-n=* | --program-transform-=* \ + | --program-transform=* | --program-transfor=* \ + | --program-transfo=* | --program-transf=* \ + | --program-trans=* | --program-tran=* \ + | --progr-tra=* | --program-tr=* | --program-t=*) + program_transform_name=$ac_optarg ;; + + -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd) + ac_prev=pdfdir ;; + -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*) + pdfdir=$ac_optarg ;; + + -psdir | --psdir | --psdi | --psd | --ps) + ac_prev=psdir ;; + -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*) + psdir=$ac_optarg ;; + + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil) + silent=yes ;; + + -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) + ac_prev=sbindir ;; + -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ + | --sbi=* | --sb=*) + sbindir=$ac_optarg ;; + + -sharedstatedir | --sharedstatedir | --sharedstatedi \ + | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ + | --sharedst | --shareds | --shared | --share | --shar \ + | --sha | --sh) + ac_prev=sharedstatedir ;; + -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ + | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ + | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ + | --sha=* | --sh=*) + sharedstatedir=$ac_optarg ;; + + -site | --site | --sit) + ac_prev=site ;; + -site=* | --site=* | --sit=*) + site=$ac_optarg ;; + + -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) + ac_prev=srcdir ;; + -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) + srcdir=$ac_optarg ;; + + -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ + | --syscon | --sysco | --sysc | --sys | --sy) + ac_prev=sysconfdir ;; + -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ + | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) + sysconfdir=$ac_optarg ;; + + -target | --target | --targe | --targ | --tar | --ta | --t) + ac_prev=target_alias ;; + -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) + target_alias=$ac_optarg ;; + + -v | -verbose | --verbose | --verbos | --verbo | --verb) + verbose=yes ;; + + -version | --version | --versio | --versi | --vers | -V) + ac_init_version=: ;; + + -with-* | --with-*) + ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error "invalid package name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"with_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval with_$ac_useropt=\$ac_optarg ;; + + -without-* | --without-*) + ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error "invalid package name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"with_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval with_$ac_useropt=no ;; + + --x) + # Obsolete; use --with-x. + with_x=yes ;; + + -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ + | --x-incl | --x-inc | --x-in | --x-i) + ac_prev=x_includes ;; + -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ + | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) + x_includes=$ac_optarg ;; + + -x-libraries | --x-libraries | --x-librarie | --x-librari \ + | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) + ac_prev=x_libraries ;; + -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ + | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) + x_libraries=$ac_optarg ;; + + -*) as_fn_error "unrecognized option: \`$ac_option' +Try \`$0 --help' for more information." + ;; + + *=*) + ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` + # Reject names that are not valid shell variable names. + case $ac_envvar in #( + '' | [0-9]* | *[!_$as_cr_alnum]* ) + as_fn_error "invalid variable name: \`$ac_envvar'" ;; + esac + eval $ac_envvar=\$ac_optarg + export $ac_envvar ;; + + *) + # FIXME: should be removed in autoconf 3.0. + $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2 + expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && + $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2 + : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option} + ;; + + esac +done + +if test -n "$ac_prev"; then + ac_option=--`echo $ac_prev | sed 's/_/-/g'` + as_fn_error "missing argument to $ac_option" +fi + +if test -n "$ac_unrecognized_opts"; then + case $enable_option_checking in + no) ;; + fatal) as_fn_error "unrecognized options: $ac_unrecognized_opts" ;; + *) $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; + esac +fi + +# Check all directory arguments for consistency. +for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ + datadir sysconfdir sharedstatedir localstatedir includedir \ + oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ + libdir localedir mandir +do + eval ac_val=\$$ac_var + # Remove trailing slashes. + case $ac_val in + */ ) + ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'` + eval $ac_var=\$ac_val;; + esac + # Be sure to have absolute directory names. + case $ac_val in + [\\/$]* | ?:[\\/]* ) continue;; + NONE | '' ) case $ac_var in *prefix ) continue;; esac;; + esac + as_fn_error "expected an absolute directory name for --$ac_var: $ac_val" +done + +# There might be people who depend on the old broken behavior: `$host' +# used to hold the argument of --host etc. +# FIXME: To remove some day. +build=$build_alias +host=$host_alias +target=$target_alias + +# FIXME: To remove some day. +if test "x$host_alias" != x; then + if test "x$build_alias" = x; then + cross_compiling=maybe + $as_echo "$as_me: WARNING: If you wanted to set the --build type, don't use --host. + If a cross compiler is detected then cross compile mode will be used." >&2 + elif test "x$build_alias" != "x$host_alias"; then + cross_compiling=yes + fi +fi + +ac_tool_prefix= +test -n "$host_alias" && ac_tool_prefix=$host_alias- + +test "$silent" = yes && exec 6>/dev/null + + +ac_pwd=`pwd` && test -n "$ac_pwd" && +ac_ls_di=`ls -di .` && +ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || + as_fn_error "working directory cannot be determined" +test "X$ac_ls_di" = "X$ac_pwd_ls_di" || + as_fn_error "pwd does not report name of working directory" + + +# Find the source files, if location was not specified. +if test -z "$srcdir"; then + ac_srcdir_defaulted=yes + # Try the directory containing this script, then the parent directory. + ac_confdir=`$as_dirname -- "$as_myself" || +$as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_myself" : 'X\(//\)[^/]' \| \ + X"$as_myself" : 'X\(//\)$' \| \ + X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$as_myself" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + srcdir=$ac_confdir + if test ! -r "$srcdir/$ac_unique_file"; then + srcdir=.. + fi +else + ac_srcdir_defaulted=no +fi +if test ! -r "$srcdir/$ac_unique_file"; then + test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." + as_fn_error "cannot find sources ($ac_unique_file) in $srcdir" +fi +ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" +ac_abs_confdir=`( + cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error "$ac_msg" + pwd)` +# When building in place, set srcdir=. +if test "$ac_abs_confdir" = "$ac_pwd"; then + srcdir=. +fi +# Remove unnecessary trailing slashes from srcdir. +# Double slashes in file names in object file debugging info +# mess up M-x gdb in Emacs. +case $srcdir in +*/) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;; +esac +for ac_var in $ac_precious_vars; do + eval ac_env_${ac_var}_set=\${${ac_var}+set} + eval ac_env_${ac_var}_value=\$${ac_var} + eval ac_cv_env_${ac_var}_set=\${${ac_var}+set} + eval ac_cv_env_${ac_var}_value=\$${ac_var} +done + +# +# Report the --help message. +# +if test "$ac_init_help" = "long"; then + # Omit some internal or obsolete options to make the list less imposing. + # This message is too long to be a string in the A/UX 3.1 sh. + cat <<_ACEOF +\`configure' configures RISC-V ISA Simulator ? to adapt to many kinds of systems. + +Usage: $0 [OPTION]... [VAR=VALUE]... + +To assign environment variables (e.g., CC, CFLAGS...), specify them as +VAR=VALUE. See below for descriptions of some of the useful variables. + +Defaults for the options are specified in brackets. + +Configuration: + -h, --help display this help and exit + --help=short display options specific to this package + --help=recursive display the short help of all the included packages + -V, --version display version information and exit + -q, --quiet, --silent do not print \`checking...' messages + --cache-file=FILE cache test results in FILE [disabled] + -C, --config-cache alias for \`--cache-file=config.cache' + -n, --no-create do not create output files + --srcdir=DIR find the sources in DIR [configure dir or \`..'] + +Installation directories: + --prefix=PREFIX install architecture-independent files in PREFIX + [$ac_default_prefix] + --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX + [PREFIX] + +By default, \`make install' will install all the files in +\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify +an installation prefix other than \`$ac_default_prefix' using \`--prefix', +for instance \`--prefix=\$HOME'. + +For better control, use the options below. + +Fine tuning of the installation directories: + --bindir=DIR user executables [EPREFIX/bin] + --sbindir=DIR system admin executables [EPREFIX/sbin] + --libexecdir=DIR program executables [EPREFIX/libexec] + --sysconfdir=DIR read-only single-machine data [PREFIX/etc] + --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] + --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --libdir=DIR object code libraries [EPREFIX/lib] + --includedir=DIR C header files [PREFIX/include] + --oldincludedir=DIR C header files for non-gcc [/usr/include] + --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] + --datadir=DIR read-only architecture-independent data [DATAROOTDIR] + --infodir=DIR info documentation [DATAROOTDIR/info] + --localedir=DIR locale-dependent data [DATAROOTDIR/locale] + --mandir=DIR man documentation [DATAROOTDIR/man] + --docdir=DIR documentation root [DATAROOTDIR/doc/riscv-isa-run] + --htmldir=DIR html documentation [DOCDIR] + --dvidir=DIR dvi documentation [DOCDIR] + --pdfdir=DIR pdf documentation [DOCDIR] + --psdir=DIR ps documentation [DOCDIR] +_ACEOF + + cat <<\_ACEOF + +System types: + --build=BUILD configure for building on BUILD [guessed] + --host=HOST cross-compile to build programs to run on HOST [BUILD] +_ACEOF +fi + +if test -n "$ac_init_help"; then + case $ac_init_help in + short | recursive ) echo "Configuration of RISC-V ISA Simulator ?:";; + esac + cat <<\_ACEOF + +Optional Features: + --disable-option-checking ignore unrecognized --enable/--with options + --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) + --enable-FEATURE[=ARG] include FEATURE [ARG=yes] + --enable-stow Enable stow-based install + --enable-optional-subprojects + Enable all optional subprojects + --disable-fpu Disable floating-point + --disable-64bit Disable 64-bit mode + --enable-rvc Enable instruction compression + --disable-vec Disable vector processor + +Some influential environment variables: + CC C compiler command + CFLAGS C compiler flags + LDFLAGS linker flags, e.g. -L if you have libraries in a + nonstandard directory + LIBS libraries to pass to the linker, e.g. -l + CPPFLAGS C/C++/Objective C preprocessor flags, e.g. -I if + you have headers in a nonstandard directory + CXX C++ compiler command + CXXFLAGS C++ compiler flags + STOW_ROOT Root for non-native stow-based installs + STOW_PREFIX Prefix for stow-based installs + CPP C preprocessor + +Use these variables to override the choices made by `configure' or to help +it to find libraries and programs with nonstandard names/locations. + +Report bugs to . +_ACEOF +ac_status=$? +fi + +if test "$ac_init_help" = "recursive"; then + # If there are subdirs, report their specific --help. + for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue + test -d "$ac_dir" || + { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } || + continue + ac_builddir=. + +case "$ac_dir" in +.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; +*) + ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` + # A ".." for each directory in $ac_dir_suffix. + ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` + case $ac_top_builddir_sub in + "") ac_top_builddir_sub=. ac_top_build_prefix= ;; + *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; + esac ;; +esac +ac_abs_top_builddir=$ac_pwd +ac_abs_builddir=$ac_pwd$ac_dir_suffix +# for backward compatibility: +ac_top_builddir=$ac_top_build_prefix + +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix + + cd "$ac_dir" || { ac_status=$?; continue; } + # Check for guested configure. + if test -f "$ac_srcdir/configure.gnu"; then + echo && + $SHELL "$ac_srcdir/configure.gnu" --help=recursive + elif test -f "$ac_srcdir/configure"; then + echo && + $SHELL "$ac_srcdir/configure" --help=recursive + else + $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 + fi || ac_status=$? + cd "$ac_pwd" || { ac_status=$?; break; } + done +fi + +test -n "$ac_init_help" && exit $ac_status +if $ac_init_version; then + cat <<\_ACEOF +RISC-V ISA Simulator configure ? +generated by GNU Autoconf 2.64 + +Copyright (C) 2009 Free Software Foundation, Inc. +This configure script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it. +_ACEOF + exit +fi + +## ------------------------ ## +## Autoconf initialization. ## +## ------------------------ ## + +# ac_fn_c_try_compile LINENO +# -------------------------- +# Try to compile conftest.$ac_ext, and return whether this succeeded. +ac_fn_c_try_compile () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + rm -f conftest.$ac_objext + if { { ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compile") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + return $ac_retval + +} # ac_fn_c_try_compile + +# ac_fn_cxx_try_compile LINENO +# ---------------------------- +# Try to compile conftest.$ac_ext, and return whether this succeeded. +ac_fn_cxx_try_compile () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + rm -f conftest.$ac_objext + if { { ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compile") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { + test -z "$ac_cxx_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + return $ac_retval + +} # ac_fn_cxx_try_compile + +# ac_fn_c_try_cpp LINENO +# ---------------------- +# Try to preprocess conftest.$ac_ext, and return whether this succeeded. +ac_fn_c_try_cpp () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if { { ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } >/dev/null && { + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || + test ! -s conftest.err + }; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + return $ac_retval + +} # ac_fn_c_try_cpp + +# ac_fn_c_try_run LINENO +# ---------------------- +# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes +# that executables *can* be run. +ac_fn_c_try_run () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { ac_try='./conftest$ac_exeext' + { { case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; }; then : + ac_retval=0 +else + $as_echo "$as_me: program exited with status $ac_status" >&5 + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=$ac_status +fi + rm -rf conftest.dSYM conftest_ipa8_conftest.oo + eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + return $ac_retval + +} # ac_fn_c_try_run + +# ac_fn_c_try_link LINENO +# ----------------------- +# Try to link conftest.$ac_ext, and return whether this succeeded. +ac_fn_c_try_link () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + rm -f conftest.$ac_objext conftest$ac_exeext + if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && { + test "$cross_compiling" = yes || + $as_test_x conftest$ac_exeext + }; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information + # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would + # interfere with the next link command; also delete a directory that is + # left behind by Apple's compiler. We do this before executing the actions. + rm -rf conftest.dSYM conftest_ipa8_conftest.oo + eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + return $ac_retval + +} # ac_fn_c_try_link +cat >config.log <<_ACEOF +This file contains any messages produced by compilers while +running configure, to aid debugging if configure makes a mistake. + +It was created by RISC-V ISA Simulator $as_me ?, which was +generated by GNU Autoconf 2.64. Invocation command line was + + $ $0 $@ + +_ACEOF +exec 5>>config.log +{ +cat <<_ASUNAME +## --------- ## +## Platform. ## +## --------- ## + +hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` +uname -m = `(uname -m) 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 || echo unknown` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` + +/bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` +/usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown` +/bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` +/bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` + +_ASUNAME + +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + $as_echo "PATH: $as_dir" + done +IFS=$as_save_IFS + +} >&5 + +cat >&5 <<_ACEOF + + +## ----------- ## +## Core tests. ## +## ----------- ## + +_ACEOF + + +# Keep a trace of the command line. +# Strip out --no-create and --no-recursion so they do not pile up. +# Strip out --silent because we don't want to record it for future runs. +# Also quote any args containing shell meta-characters. +# Make two passes to allow for proper duplicate-argument suppression. +ac_configure_args= +ac_configure_args0= +ac_configure_args1= +ac_must_keep_next=false +for ac_pass in 1 2 +do + for ac_arg + do + case $ac_arg in + -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil) + continue ;; + *\'*) + ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + case $ac_pass in + 1) as_fn_append ac_configure_args0 " '$ac_arg'" ;; + 2) + as_fn_append ac_configure_args1 " '$ac_arg'" + if test $ac_must_keep_next = true; then + ac_must_keep_next=false # Got value, back to normal. + else + case $ac_arg in + *=* | --config-cache | -C | -disable-* | --disable-* \ + | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ + | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ + | -with-* | --with-* | -without-* | --without-* | --x) + case "$ac_configure_args0 " in + "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; + esac + ;; + -* ) ac_must_keep_next=true ;; + esac + fi + as_fn_append ac_configure_args " '$ac_arg'" + ;; + esac + done +done +{ ac_configure_args0=; unset ac_configure_args0;} +{ ac_configure_args1=; unset ac_configure_args1;} + +# When interrupted or exit'd, cleanup temporary files, and complete +# config.log. We remove comments because anyway the quotes in there +# would cause problems or look ugly. +# WARNING: Use '\'' to represent an apostrophe within the trap. +# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. +trap 'exit_status=$? + # Save into config.log some information that might help in debugging. + { + echo + + cat <<\_ASBOX +## ---------------- ## +## Cache variables. ## +## ---------------- ## +_ASBOX + echo + # The following way of writing the cache mishandles newlines in values, +( + for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do + eval ac_val=\$$ac_var + case $ac_val in #( + *${as_nl}*) + case $ac_var in #( + *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 +$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; + esac + case $ac_var in #( + _ | IFS | as_nl) ;; #( + BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( + *) { eval $ac_var=; unset $ac_var;} ;; + esac ;; + esac + done + (set) 2>&1 | + case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( + *${as_nl}ac_space=\ *) + sed -n \ + "s/'\''/'\''\\\\'\'''\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" + ;; #( + *) + sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" + ;; + esac | + sort +) + echo + + cat <<\_ASBOX +## ----------------- ## +## Output variables. ## +## ----------------- ## +_ASBOX + echo + for ac_var in $ac_subst_vars + do + eval ac_val=\$$ac_var + case $ac_val in + *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + esac + $as_echo "$ac_var='\''$ac_val'\''" + done | sort + echo + + if test -n "$ac_subst_files"; then + cat <<\_ASBOX +## ------------------- ## +## File substitutions. ## +## ------------------- ## +_ASBOX + echo + for ac_var in $ac_subst_files + do + eval ac_val=\$$ac_var + case $ac_val in + *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + esac + $as_echo "$ac_var='\''$ac_val'\''" + done | sort + echo + fi + + if test -s confdefs.h; then + cat <<\_ASBOX +## ----------- ## +## confdefs.h. ## +## ----------- ## +_ASBOX + echo + cat confdefs.h + echo + fi + test "$ac_signal" != 0 && + $as_echo "$as_me: caught signal $ac_signal" + $as_echo "$as_me: exit $exit_status" + } >&5 + rm -f core *.core core.conftest.* && + rm -f -r conftest* confdefs* conf$$* $ac_clean_files && + exit $exit_status +' 0 +for ac_signal in 1 2 13 15; do + trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal +done +ac_signal=0 + +# confdefs.h avoids OS command line length limits that DEFS can exceed. +rm -f -r conftest* confdefs.h + +$as_echo "/* confdefs.h */" > confdefs.h + +# Predefined preprocessor variables. + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_NAME "$PACKAGE_NAME" +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_TARNAME "$PACKAGE_TARNAME" +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_VERSION "$PACKAGE_VERSION" +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_STRING "$PACKAGE_STRING" +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_URL "$PACKAGE_URL" +_ACEOF + + +# Let the site file select an alternate cache file if it wants to. +# Prefer an explicitly selected file to automatically selected ones. +ac_site_file1=NONE +ac_site_file2=NONE +if test -n "$CONFIG_SITE"; then + ac_site_file1=$CONFIG_SITE +elif test "x$prefix" != xNONE; then + ac_site_file1=$prefix/share/config.site + ac_site_file2=$prefix/etc/config.site +else + ac_site_file1=$ac_default_prefix/share/config.site + ac_site_file2=$ac_default_prefix/etc/config.site +fi +for ac_site_file in "$ac_site_file1" "$ac_site_file2" +do + test "x$ac_site_file" = xNONE && continue + if test -r "$ac_site_file"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 +$as_echo "$as_me: loading site script $ac_site_file" >&6;} + sed 's/^/| /' "$ac_site_file" >&5 + . "$ac_site_file" + fi +done + +if test -r "$cache_file"; then + # Some versions of bash will fail to source /dev/null (special + # files actually), so we avoid doing that. + if test -f "$cache_file"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 +$as_echo "$as_me: loading cache $cache_file" >&6;} + case $cache_file in + [\\/]* | ?:[\\/]* ) . "$cache_file";; + *) . "./$cache_file";; + esac + fi +else + { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 +$as_echo "$as_me: creating cache $cache_file" >&6;} + >$cache_file +fi + +# Check that the precious variables saved in the cache have kept the same +# value. +ac_cache_corrupted=false +for ac_var in $ac_precious_vars; do + eval ac_old_set=\$ac_cv_env_${ac_var}_set + eval ac_new_set=\$ac_env_${ac_var}_set + eval ac_old_val=\$ac_cv_env_${ac_var}_value + eval ac_new_val=\$ac_env_${ac_var}_value + case $ac_old_set,$ac_new_set in + set,) + { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 +$as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,set) + { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 +$as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,);; + *) + if test "x$ac_old_val" != "x$ac_new_val"; then + # differences in whitespace do not lead to failure. + ac_old_val_w=`echo x $ac_old_val` + ac_new_val_w=`echo x $ac_new_val` + if test "$ac_old_val_w" != "$ac_new_val_w"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 +$as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} + ac_cache_corrupted=: + else + { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 +$as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} + eval $ac_var=\$ac_old_val + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 +$as_echo "$as_me: former value: \`$ac_old_val'" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 +$as_echo "$as_me: current value: \`$ac_new_val'" >&2;} + fi;; + esac + # Pass precious variables to config.status. + if test "$ac_new_set" = set; then + case $ac_new_val in + *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; + *) ac_arg=$ac_var=$ac_new_val ;; + esac + case " $ac_configure_args " in + *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. + *) as_fn_append ac_configure_args " '$ac_arg'" ;; + esac + fi +done +if $ac_cache_corrupted; then + { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 +$as_echo "$as_me: error: changes in the environment can compromise the build" >&2;} + as_fn_error "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5 +fi +## -------------------- ## +## Main body of script. ## +## -------------------- ## + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + +ac_aux_dir= +for ac_dir in scripts "$srcdir"/scripts; do + for ac_t in install-sh install.sh shtool; do + if test -f "$ac_dir/$ac_t"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/$ac_t -c" + break 2 + fi + done +done +if test -z "$ac_aux_dir"; then + as_fn_error "cannot find install-sh, install.sh, or shtool in scripts \"$srcdir\"/scripts" "$LINENO" 5 +fi + +# These three variables are undocumented and unsupported, +# and are intended to be withdrawn in a future Autoconf release. +# They can cause serious problems if a builder's source tree is in a directory +# whose full name contains unusual characters. +ac_config_guess="$SHELL $ac_aux_dir/config.guess" # Please don't use this var. +ac_config_sub="$SHELL $ac_aux_dir/config.sub" # Please don't use this var. +ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. + + +# Make sure we can run config.sub. +$SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 || + as_fn_error "cannot run $SHELL $ac_aux_dir/config.sub" "$LINENO" 5 + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking build system type" >&5 +$as_echo_n "checking build system type... " >&6; } +if test "${ac_cv_build+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_build_alias=$build_alias +test "x$ac_build_alias" = x && + ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"` +test "x$ac_build_alias" = x && + as_fn_error "cannot guess build type; you must specify one" "$LINENO" 5 +ac_cv_build=`$SHELL "$ac_aux_dir/config.sub" $ac_build_alias` || + as_fn_error "$SHELL $ac_aux_dir/config.sub $ac_build_alias failed" "$LINENO" 5 + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5 +$as_echo "$ac_cv_build" >&6; } +case $ac_cv_build in +*-*-*) ;; +*) as_fn_error "invalid value of canonical build" "$LINENO" 5;; +esac +build=$ac_cv_build +ac_save_IFS=$IFS; IFS='-' +set x $ac_cv_build +shift +build_cpu=$1 +build_vendor=$2 +shift; shift +# Remember, the first character of IFS is used to create $*, +# except with old shells: +build_os=$* +IFS=$ac_save_IFS +case $build_os in *\ *) build_os=`echo "$build_os" | sed 's/ /-/g'`;; esac + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking host system type" >&5 +$as_echo_n "checking host system type... " >&6; } +if test "${ac_cv_host+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test "x$host_alias" = x; then + ac_cv_host=$ac_cv_build +else + ac_cv_host=`$SHELL "$ac_aux_dir/config.sub" $host_alias` || + as_fn_error "$SHELL $ac_aux_dir/config.sub $host_alias failed" "$LINENO" 5 +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_host" >&5 +$as_echo "$ac_cv_host" >&6; } +case $ac_cv_host in +*-*-*) ;; +*) as_fn_error "invalid value of canonical host" "$LINENO" 5;; +esac +host=$ac_cv_host +ac_save_IFS=$IFS; IFS='-' +set x $ac_cv_host +shift +host_cpu=$1 +host_vendor=$2 +shift; shift +# Remember, the first character of IFS is used to create $*, +# except with old shells: +host_os=$* +IFS=$ac_save_IFS +case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac + + + +#------------------------------------------------------------------------- +# Checks for programs +#------------------------------------------------------------------------- + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. +set dummy ${ac_tool_prefix}gcc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_CC+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CC="${ac_tool_prefix}gcc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_CC"; then + ac_ct_CC=$CC + # Extract the first word of "gcc", so it can be a program name with args. +set dummy gcc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_ac_ct_CC+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_CC="gcc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +$as_echo "$ac_ct_CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +else + CC="$ac_cv_prog_CC" +fi + +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. +set dummy ${ac_tool_prefix}cc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_CC+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CC="${ac_tool_prefix}cc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + fi +fi +if test -z "$CC"; then + # Extract the first word of "cc", so it can be a program name with args. +set dummy cc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_CC+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else + ac_prog_rejected=no +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then + ac_prog_rejected=yes + continue + fi + ac_cv_prog_CC="cc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +if test $ac_prog_rejected = yes; then + # We found a bogon in the path, so make sure we never use it. + set dummy $ac_cv_prog_CC + shift + if test $# != 0; then + # We chose a different compiler from the bogus one. + # However, it has the same basename, so the bogon will be chosen + # first if we set CC to just the basename; use the full file name. + shift + ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" + fi +fi +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + for ac_prog in cl.exe + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_CC+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CC="$ac_tool_prefix$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$CC" && break + done +fi +if test -z "$CC"; then + ac_ct_CC=$CC + for ac_prog in cl.exe +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_ac_ct_CC+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_CC="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +$as_echo "$ac_ct_CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$ac_ct_CC" && break +done + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +fi + +fi + + +test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error "no acceptable C compiler found in \$PATH +See \`config.log' for more details." "$LINENO" 5; } + +# Provide some information about the compiler. +$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 +set X $ac_compile +ac_compiler=$2 +for ac_option in --version -v -V -qversion; do + { { ac_try="$ac_compiler $ac_option >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compiler $ac_option >&5") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + sed '10a\ +... rest of stderr output deleted ... + 10q' conftest.err >conftest.er1 + cat conftest.er1 >&5 + rm -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } +done + +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +FILE *f = fopen ("conftest.out", "w"); + return ferror (f) || fclose (f) != 0; + + ; + return 0; +} +_ACEOF +ac_clean_files_save=$ac_clean_files +ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out conftest.out" +# Try to create an executable without -o first, disregard a.out. +# It will help us diagnose broken compilers, and finding out an intuition +# of exeext. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5 +$as_echo_n "checking for C compiler default output file name... " >&6; } +ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` + +# The possible output files: +ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*" + +ac_rmfiles= +for ac_file in $ac_files +do + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; + * ) ac_rmfiles="$ac_rmfiles $ac_file";; + esac +done +rm -f $ac_rmfiles + +if { { ac_try="$ac_link_default" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link_default") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then : + # Autoconf-2.13 could set the ac_cv_exeext variable to `no'. +# So ignore a value of `no', otherwise this would lead to `EXEEXT = no' +# in a Makefile. We should not override ac_cv_exeext if it was cached, +# so that the user can short-circuit this test for compilers unknown to +# Autoconf. +for ac_file in $ac_files '' +do + test -f "$ac_file" || continue + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) + ;; + [ab].out ) + # We found the default executable, but exeext='' is most + # certainly right. + break;; + *.* ) + if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no; + then :; else + ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + fi + # We set ac_cv_exeext here because the later test for it is not + # safe: cross compilers may not add the suffix if given an `-o' + # argument, so we may need to know it at that point already. + # Even if this section looks crufty: it has the advantage of + # actually working. + break;; + * ) + break;; + esac +done +test "$ac_cv_exeext" = no && ac_cv_exeext= + +else + ac_file='' +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 +$as_echo "$ac_file" >&6; } +if test -z "$ac_file"; then : + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +{ as_fn_set_status 77 +as_fn_error "C compiler cannot create executables +See \`config.log' for more details." "$LINENO" 5; }; } +fi +ac_exeext=$ac_cv_exeext + +# Check that the compiler produces executables we can run. If not, either +# the compiler is broken, or we cross compile. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5 +$as_echo_n "checking whether the C compiler works... " >&6; } +# If not cross compiling, check that we can run a simple program. +if test "$cross_compiling" != yes; then + if { ac_try='./$ac_file' + { { case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; }; then + cross_compiling=no + else + if test "$cross_compiling" = maybe; then + cross_compiling=yes + else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error "cannot run C compiled programs. +If you meant to cross compile, use \`--host'. +See \`config.log' for more details." "$LINENO" 5; } + fi + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out conftest.out +ac_clean_files=$ac_clean_files_save +# Check that the compiler produces executables we can run. If not, either +# the compiler is broken, or we cross compile. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 +$as_echo_n "checking whether we are cross compiling... " >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 +$as_echo "$cross_compiling" >&6; } + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5 +$as_echo_n "checking for suffix of executables... " >&6; } +if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then : + # If both `conftest.exe' and `conftest' are `present' (well, observable) +# catch `conftest.exe'. For instance with Cygwin, `ls conftest' will +# work properly (i.e., refer to `conftest.exe'), while it won't with +# `rm'. +for ac_file in conftest.exe conftest conftest.*; do + test -f "$ac_file" || continue + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; + *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + break;; + * ) break;; + esac +done +else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error "cannot compute suffix of executables: cannot compile and link +See \`config.log' for more details." "$LINENO" 5; } +fi +rm -f conftest$ac_cv_exeext +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 +$as_echo "$ac_cv_exeext" >&6; } + +rm -f conftest.$ac_ext +EXEEXT=$ac_cv_exeext +ac_exeext=$EXEEXT +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 +$as_echo_n "checking for suffix of object files... " >&6; } +if test "${ac_cv_objext+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.o conftest.obj +if { { ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compile") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then : + for ac_file in conftest.o conftest.obj conftest.*; do + test -f "$ac_file" || continue; + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;; + *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` + break;; + esac +done +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error "cannot compute suffix of object files: cannot compile +See \`config.log' for more details." "$LINENO" 5; } +fi +rm -f conftest.$ac_cv_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5 +$as_echo "$ac_cv_objext" >&6; } +OBJEXT=$ac_cv_objext +ac_objext=$OBJEXT +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5 +$as_echo_n "checking whether we are using the GNU C compiler... " >&6; } +if test "${ac_cv_c_compiler_gnu+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +#ifndef __GNUC__ + choke me +#endif + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_compiler_gnu=yes +else + ac_compiler_gnu=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_cv_c_compiler_gnu=$ac_compiler_gnu + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 +$as_echo "$ac_cv_c_compiler_gnu" >&6; } +if test $ac_compiler_gnu = yes; then + GCC=yes +else + GCC= +fi +ac_test_CFLAGS=${CFLAGS+set} +ac_save_CFLAGS=$CFLAGS +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 +$as_echo_n "checking whether $CC accepts -g... " >&6; } +if test "${ac_cv_prog_cc_g+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_save_c_werror_flag=$ac_c_werror_flag + ac_c_werror_flag=yes + ac_cv_prog_cc_g=no + CFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_g=yes +else + CFLAGS="" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + +else + ac_c_werror_flag=$ac_save_c_werror_flag + CFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_g=yes +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_c_werror_flag=$ac_save_c_werror_flag +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 +$as_echo "$ac_cv_prog_cc_g" >&6; } +if test "$ac_test_CFLAGS" = set; then + CFLAGS=$ac_save_CFLAGS +elif test $ac_cv_prog_cc_g = yes; then + if test "$GCC" = yes; then + CFLAGS="-g -O2" + else + CFLAGS="-g" + fi +else + if test "$GCC" = yes; then + CFLAGS="-O2" + else + CFLAGS= + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5 +$as_echo_n "checking for $CC option to accept ISO C89... " >&6; } +if test "${ac_cv_prog_cc_c89+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_cv_prog_cc_c89=no +ac_save_CC=$CC +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#include +#include +/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ +struct buf { int x; }; +FILE * (*rcsopen) (struct buf *, struct stat *, int); +static char *e (p, i) + char **p; + int i; +{ + return p[i]; +} +static char *f (char * (*g) (char **, int), char **p, ...) +{ + char *s; + va_list v; + va_start (v,p); + s = g (p, va_arg (v,int)); + va_end (v); + return s; +} + +/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has + function prototypes and stuff, but not '\xHH' hex character constants. + These don't provoke an error unfortunately, instead are silently treated + as 'x'. The following induces an error, until -std is added to get + proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an + array size at least. It's necessary to write '\x00'==0 to get something + that's true only with -std. */ +int osf4_cc_array ['\x00' == 0 ? 1 : -1]; + +/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters + inside strings and character constants. */ +#define FOO(x) 'x' +int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; + +int test (int i, double x); +struct s1 {int (*f) (int a);}; +struct s2 {int (*f) (double a);}; +int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); +int argc; +char **argv; +int +main () +{ +return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; + ; + return 0; +} +_ACEOF +for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ + -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" +do + CC="$ac_save_CC $ac_arg" + if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_c89=$ac_arg +fi +rm -f core conftest.err conftest.$ac_objext + test "x$ac_cv_prog_cc_c89" != "xno" && break +done +rm -f conftest.$ac_ext +CC=$ac_save_CC + +fi +# AC_CACHE_VAL +case "x$ac_cv_prog_cc_c89" in + x) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +$as_echo "none needed" >&6; } ;; + xno) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +$as_echo "unsupported" >&6; } ;; + *) + CC="$CC $ac_cv_prog_cc_c89" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 +$as_echo "$ac_cv_prog_cc_c89" >&6; } ;; +esac +if test "x$ac_cv_prog_cc_c89" != xno; then : + +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu +if test -z "$CXX"; then + if test -n "$CCC"; then + CXX=$CCC + else + if test -n "$ac_tool_prefix"; then + for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_CXX+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CXX"; then + ac_cv_prog_CXX="$CXX" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CXX="$ac_tool_prefix$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CXX=$ac_cv_prog_CXX +if test -n "$CXX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CXX" >&5 +$as_echo "$CXX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$CXX" && break + done +fi +if test -z "$CXX"; then + ac_ct_CXX=$CXX + for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_ac_ct_CXX+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_CXX"; then + ac_cv_prog_ac_ct_CXX="$ac_ct_CXX" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_CXX="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CXX=$ac_cv_prog_ac_ct_CXX +if test -n "$ac_ct_CXX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CXX" >&5 +$as_echo "$ac_ct_CXX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$ac_ct_CXX" && break +done + + if test "x$ac_ct_CXX" = x; then + CXX="g++" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CXX=$ac_ct_CXX + fi +fi + + fi +fi +# Provide some information about the compiler. +$as_echo "$as_me:${as_lineno-$LINENO}: checking for C++ compiler version" >&5 +set X $ac_compile +ac_compiler=$2 +for ac_option in --version -v -V -qversion; do + { { ac_try="$ac_compiler $ac_option >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compiler $ac_option >&5") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + sed '10a\ +... rest of stderr output deleted ... + 10q' conftest.err >conftest.er1 + cat conftest.er1 >&5 + rm -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } +done + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C++ compiler" >&5 +$as_echo_n "checking whether we are using the GNU C++ compiler... " >&6; } +if test "${ac_cv_cxx_compiler_gnu+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +#ifndef __GNUC__ + choke me +#endif + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + ac_compiler_gnu=yes +else + ac_compiler_gnu=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_cv_cxx_compiler_gnu=$ac_compiler_gnu + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cxx_compiler_gnu" >&5 +$as_echo "$ac_cv_cxx_compiler_gnu" >&6; } +if test $ac_compiler_gnu = yes; then + GXX=yes +else + GXX= +fi +ac_test_CXXFLAGS=${CXXFLAGS+set} +ac_save_CXXFLAGS=$CXXFLAGS +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX accepts -g" >&5 +$as_echo_n "checking whether $CXX accepts -g... " >&6; } +if test "${ac_cv_prog_cxx_g+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_save_cxx_werror_flag=$ac_cxx_werror_flag + ac_cxx_werror_flag=yes + ac_cv_prog_cxx_g=no + CXXFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + ac_cv_prog_cxx_g=yes +else + CXXFLAGS="" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + +else + ac_cxx_werror_flag=$ac_save_cxx_werror_flag + CXXFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + ac_cv_prog_cxx_g=yes +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_cxx_werror_flag=$ac_save_cxx_werror_flag +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cxx_g" >&5 +$as_echo "$ac_cv_prog_cxx_g" >&6; } +if test "$ac_test_CXXFLAGS" = set; then + CXXFLAGS=$ac_save_CXXFLAGS +elif test $ac_cv_prog_cxx_g = yes; then + if test "$GXX" = yes; then + CXXFLAGS="-g -O2" + else + CXXFLAGS="-g" + fi +else + if test "$GXX" = yes; then + CXXFLAGS="-O2" + else + CXXFLAGS= + fi +fi +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}ar", so it can be a program name with args. +set dummy ${ac_tool_prefix}ar; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_AR+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$AR"; then + ac_cv_prog_AR="$AR" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_AR="${ac_tool_prefix}ar" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +AR=$ac_cv_prog_AR +if test -n "$AR"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AR" >&5 +$as_echo "$AR" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_AR"; then + ac_ct_AR=$AR + # Extract the first word of "ar", so it can be a program name with args. +set dummy ar; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_ac_ct_AR+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_AR"; then + ac_cv_prog_ac_ct_AR="$ac_ct_AR" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_AR="ar" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_AR=$ac_cv_prog_ac_ct_AR +if test -n "$ac_ct_AR"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AR" >&5 +$as_echo "$ac_ct_AR" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_AR" = x; then + AR="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + AR=$ac_ct_AR + fi +else + AR="$ac_cv_prog_AR" +fi + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args. +set dummy ${ac_tool_prefix}ranlib; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_RANLIB+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$RANLIB"; then + ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +RANLIB=$ac_cv_prog_RANLIB +if test -n "$RANLIB"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5 +$as_echo "$RANLIB" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_RANLIB"; then + ac_ct_RANLIB=$RANLIB + # Extract the first word of "ranlib", so it can be a program name with args. +set dummy ranlib; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_ac_ct_RANLIB+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_RANLIB"; then + ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_RANLIB="ranlib" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB +if test -n "$ac_ct_RANLIB"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5 +$as_echo "$ac_ct_RANLIB" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_RANLIB" = x; then + RANLIB="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + RANLIB=$ac_ct_RANLIB + fi +else + RANLIB="$ac_cv_prog_RANLIB" +fi + + +#------------------------------------------------------------------------- +# MCPPBS specific program checks +#------------------------------------------------------------------------- +# These macros check to see if we can do a stow-based install and also +# check for an isa simulator suitable for running the unit test programs +# via the makefile. + +# Find a good install program. We prefer a C program (faster), +# so one script is as good as another. But avoid the broken or +# incompatible versions: +# SysV /etc/install, /usr/sbin/install +# SunOS /usr/etc/install +# IRIX /sbin/install +# AIX /bin/install +# AmigaOS /C/install, which installs bootblocks on floppy discs +# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag +# AFS /usr/afsws/bin/install, which mishandles nonexistent args +# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" +# OS/2's system install, which has a completely different semantic +# ./install, which can be erroneously created by make from ./install.sh. +# Reject install programs that cannot install multiple files. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5 +$as_echo_n "checking for a BSD-compatible install... " >&6; } +if test -z "$INSTALL"; then +if test "${ac_cv_path_install+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + # Account for people who put trailing slashes in PATH elements. +case $as_dir/ in #(( + ./ | .// | /[cC]/* | \ + /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \ + ?:[\\/]os2[\\/]install[\\/]* | ?:[\\/]OS2[\\/]INSTALL[\\/]* | \ + /usr/ucb/* ) ;; + *) + # OSF1 and SCO ODT 3.0 have their own names for install. + # Don't use installbsd from OSF since it installs stuff as root + # by default. + for ac_prog in ginstall scoinst install; do + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; }; then + if test $ac_prog = install && + grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then + # AIX install. It has an incompatible calling convention. + : + elif test $ac_prog = install && + grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then + # program-specific install script used by HP pwplus--don't use. + : + else + rm -rf conftest.one conftest.two conftest.dir + echo one > conftest.one + echo two > conftest.two + mkdir conftest.dir + if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" && + test -s conftest.one && test -s conftest.two && + test -s conftest.dir/conftest.one && + test -s conftest.dir/conftest.two + then + ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c" + break 3 + fi + fi + fi + done + done + ;; +esac + + done +IFS=$as_save_IFS + +rm -rf conftest.one conftest.two conftest.dir + +fi + if test "${ac_cv_path_install+set}" = set; then + INSTALL=$ac_cv_path_install + else + # As a last resort, use the slow shell script. Don't cache a + # value for INSTALL within a source directory, because that will + # break other packages using the cache if that directory is + # removed, or if the value is a relative name. + INSTALL=$ac_install_sh + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5 +$as_echo "$INSTALL" >&6; } + +# Use test -z because SunOS4 sh mishandles braces in ${var-val}. +# It thinks the first close brace ends the variable substitution. +test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' + +test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' + +test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' + + + + # Configure command line option + + # Check whether --enable-stow was given. +if test "${enable_stow+set}" = set; then : + enableval=$enable_stow; enable_stow="yes" +else + enable_stow="no" +fi + + + + + # Environment variables + + + + + # Check for install script + + + + # Deterimine if native build and set prefix appropriately + + if test ${enable_stow} = "yes" ; then : + + for ac_prog in stow +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_stow+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$stow"; then + ac_cv_prog_stow="$stow" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_stow="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +stow=$ac_cv_prog_stow +if test -n "$stow"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $stow" >&5 +$as_echo "$stow" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$stow" && break +done +test -n "$stow" || stow="no" + + if test ${stow} = "no" ; then : + + as_fn_error "Cannot use --enable-stow since stow is not available" "$LINENO" 5 + +fi + + # Check if native or non-native build + + if test "${build}" = "${host}" ; then : + + + # build == host so this is a native build. Make sure --prefix not + # set and $STOW_PREFIX is set, then set prefix=$STOW_PREFIX. + + if test "${prefix}" = "NONE" && test -n "${STOW_PREFIX}" ; then : + + prefix="${STOW_PREFIX}" + { $as_echo "$as_me:${as_lineno-$LINENO}: Using \$STOW_PREFIX from environment" >&5 +$as_echo "$as_me: Using \$STOW_PREFIX from environment" >&6;} + { $as_echo "$as_me:${as_lineno-$LINENO}: prefix=${prefix}" >&5 +$as_echo "$as_me: prefix=${prefix}" >&6;} + +fi + + +else + + + # build != host so this is a non-native build. Make sure --prefix + # not set and $STOW_ROOT is set, then set + # prefix=$STOW_ROOT/${host_alias}. + + if test "${prefix}" = "NONE" && test -n "${STOW_ROOT}" ; then : + + prefix="${STOW_ROOT}/${host_alias}" + { $as_echo "$as_me:${as_lineno-$LINENO}: Using \$STOW_ROOT from environment" >&5 +$as_echo "$as_me: Using \$STOW_ROOT from environment" >&6;} + { $as_echo "$as_me:${as_lineno-$LINENO}: prefix=${prefix}" >&5 +$as_echo "$as_me: prefix=${prefix}" >&6;} + +fi + + +fi + + +fi + + + + if test "${build}" != "${host}" ; then : + + if test -n "$ac_tool_prefix"; then + for ac_prog in isa-run run + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_RUN+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$RUN"; then + ac_cv_prog_RUN="$RUN" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_RUN="$ac_tool_prefix$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +RUN=$ac_cv_prog_RUN +if test -n "$RUN"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RUN" >&5 +$as_echo "$RUN" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$RUN" && break + done +fi +if test -z "$RUN"; then + ac_ct_RUN=$RUN + for ac_prog in isa-run run +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_ac_ct_RUN+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_RUN"; then + ac_cv_prog_ac_ct_RUN="$ac_ct_RUN" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_RUN="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_RUN=$ac_cv_prog_ac_ct_RUN +if test -n "$ac_ct_RUN"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RUN" >&5 +$as_echo "$ac_ct_RUN" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$ac_ct_RUN" && break +done + + if test "x$ac_ct_RUN" = x; then + RUN="no" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + RUN=$ac_ct_RUN + fi +fi + + if test ${RUN} = "no" ; then : + + as_fn_error "Cannot find simulator for target ${target_alias}" "$LINENO" 5 + +fi + +else + + RUN="" + +fi + + + + +#------------------------------------------------------------------------- +# Checks for header files +#------------------------------------------------------------------------- + + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5 +$as_echo_n "checking how to run the C preprocessor... " >&6; } +# On Suns, sometimes $CPP names a directory. +if test -n "$CPP" && test -d "$CPP"; then + CPP= +fi +if test -z "$CPP"; then + if test "${ac_cv_prog_CPP+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + # Double quotes because CPP needs to be expanded + for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" + do + ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + +else + # Broken: fails on valid input. +continue +fi +rm -f conftest.err conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + # Broken: success on invalid input. +continue +else + # Passes both tests. +ac_preproc_ok=: +break +fi +rm -f conftest.err conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.err conftest.$ac_ext +if $ac_preproc_ok; then : + break +fi + + done + ac_cv_prog_CPP=$CPP + +fi + CPP=$ac_cv_prog_CPP +else + ac_cv_prog_CPP=$CPP +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5 +$as_echo "$CPP" >&6; } +ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + +else + # Broken: fails on valid input. +continue +fi +rm -f conftest.err conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + # Broken: success on invalid input. +continue +else + # Passes both tests. +ac_preproc_ok=: +break +fi +rm -f conftest.err conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.err conftest.$ac_ext +if $ac_preproc_ok; then : + +else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error "C preprocessor \"$CPP\" fails sanity check +See \`config.log' for more details." "$LINENO" 5; } +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 +$as_echo_n "checking for grep that handles long lines and -e... " >&6; } +if test "${ac_cv_path_GREP+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -z "$GREP"; then + ac_path_GREP_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in grep ggrep; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" + { test -f "$ac_path_GREP" && $as_test_x "$ac_path_GREP"; } || continue +# Check for GNU ac_path_GREP and select it if it is found. + # Check for GNU $ac_path_GREP +case `"$ac_path_GREP" --version 2>&1` in +*GNU*) + ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; +*) + ac_count=0 + $as_echo_n 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + $as_echo 'GREP' >> "conftest.nl" + "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_GREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_GREP="$ac_path_GREP" + ac_path_GREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_GREP_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_GREP"; then + as_fn_error "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 + fi +else + ac_cv_path_GREP=$GREP +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 +$as_echo "$ac_cv_path_GREP" >&6; } + GREP="$ac_cv_path_GREP" + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5 +$as_echo_n "checking for egrep... " >&6; } +if test "${ac_cv_path_EGREP+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 + then ac_cv_path_EGREP="$GREP -E" + else + if test -z "$EGREP"; then + ac_path_EGREP_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in egrep; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" + { test -f "$ac_path_EGREP" && $as_test_x "$ac_path_EGREP"; } || continue +# Check for GNU ac_path_EGREP and select it if it is found. + # Check for GNU $ac_path_EGREP +case `"$ac_path_EGREP" --version 2>&1` in +*GNU*) + ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; +*) + ac_count=0 + $as_echo_n 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + $as_echo 'EGREP' >> "conftest.nl" + "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_EGREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_EGREP="$ac_path_EGREP" + ac_path_EGREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_EGREP_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_EGREP"; then + as_fn_error "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 + fi +else + ac_cv_path_EGREP=$EGREP +fi + + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5 +$as_echo "$ac_cv_path_EGREP" >&6; } + EGREP="$ac_cv_path_EGREP" + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 +$as_echo_n "checking for ANSI C header files... " >&6; } +if test "${ac_cv_header_stdc+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#include +#include + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_header_stdc=yes +else + ac_cv_header_stdc=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +if test $ac_cv_header_stdc = yes; then + # SunOS 4.x string.h does not declare mem*, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "memchr" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "free" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. + if test "$cross_compiling" = yes; then : + : +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#if ((' ' & 0x0FF) == 0x020) +# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') +# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) +#else +# define ISLOWER(c) \ + (('a' <= (c) && (c) <= 'i') \ + || ('j' <= (c) && (c) <= 'r') \ + || ('s' <= (c) && (c) <= 'z')) +# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) +#endif + +#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) +int +main () +{ + int i; + for (i = 0; i < 256; i++) + if (XOR (islower (i), ISLOWER (i)) + || toupper (i) != TOUPPER (i)) + return 2; + return 0; +} +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + +else + ac_cv_header_stdc=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5 +$as_echo "$ac_cv_header_stdc" >&6; } +if test $ac_cv_header_stdc = yes; then + +$as_echo "#define STDC_HEADERS 1" >>confdefs.h + +fi + + +#------------------------------------------------------------------------- +# Default compiler flags +#------------------------------------------------------------------------- + +CFLAGS="-Wall -O2" + +CXXFLAGS="-Wall -O2 -Wno-pmf-conversions" + + +#------------------------------------------------------------------------- +# MCPPBS subproject list +#------------------------------------------------------------------------- +# Order list so that subprojects only depend on those listed earlier. +# The '*' suffix indicates an optional subproject. The '**' suffix +# indicates an optional subproject which is also the name of a group. + + + + # Add command line argument to enable all optional subprojects + + # Check whether --enable-optional-subprojects was given. +if test "${enable_optional_subprojects+set}" = set; then : + enableval=$enable_optional_subprojects; +fi + + + # Loop through the subprojects given in the macro argument + + + + # Determine if this is a required or an optional subproject + + + + # Determine if there is a group with the same name + + + + # Create variations of the subproject name suitable for use as a CPP + # enabled define, a shell enabled variable, and a shell function + + + + + + + + + + + + # Add subproject to our running list + + subprojects="$subprojects riscv" + + # Process the subproject appropriately. If enabled add it to the + # $enabled_subprojects running shell variable, set a + # SUBPROJECT_ENABLED C define, and include the appropriate + # 'subproject.ac'. + + + { $as_echo "$as_me:${as_lineno-$LINENO}: configuring default subproject : riscv" >&5 +$as_echo "$as_me: configuring default subproject : riscv" >&6;} + ac_config_files="$ac_config_files riscv.mk:riscv/riscv.mk.in" + + enable_riscv_sproj="yes" + subprojects_enabled="$subprojects_enabled riscv" + +$as_echo "#define RISCV_ENABLED /**/" >>confdefs.h + + # Check whether --enable-fpu was given. +if test "${enable_fpu+set}" = set; then : + enableval=$enable_fpu; +fi + +if test "x$enable_fpu" != "xno"; then : + + +$as_echo "#define RISCV_ENABLE_FPU /**/" >>confdefs.h + + +fi + +# Check whether --enable-64bit was given. +if test "${enable_64bit+set}" = set; then : + enableval=$enable_64bit; +fi + +if test "x$enable_64bit" != "xno"; then : + + +$as_echo "#define RISCV_ENABLE_64BIT /**/" >>confdefs.h + + +fi + +# Check whether --enable-rvc was given. +if test "${enable_rvc+set}" = set; then : + enableval=$enable_rvc; +fi + +if test "x$enable_rvc" = "xyes"; then : + + +$as_echo "#define RISCV_ENABLE_RVC /**/" >>confdefs.h + + +fi + +# Check whether --enable-vec was given. +if test "${enable_vec+set}" = set; then : + enableval=$enable_vec; +fi + +if test "x$enable_vec" != "xno"; then : + + +$as_echo "#define RISCV_ENABLE_VEC /**/" >>confdefs.h + + +fi + +libopc=`dirname \`which riscv-gcc\``/../`$ac_config_guess`/riscv/lib/libopcodes.a +as_ac_File=`$as_echo "ac_cv_file_$libopc" | $as_tr_sh` +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $libopc" >&5 +$as_echo_n "checking for $libopc... " >&6; } +if { as_var=$as_ac_File; eval "test \"\${$as_var+set}\" = set"; }; then : + $as_echo_n "(cached) " >&6 +else + test "$cross_compiling" = yes && + as_fn_error "cannot check for file existence when cross compiling" "$LINENO" 5 +if test -r "$libopc"; then + eval "$as_ac_File=yes" +else + eval "$as_ac_File=no" +fi +fi +eval ac_res=\$$as_ac_File + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } +eval as_val=\$$as_ac_File + if test "x$as_val" = x""yes; then : + +cat >>confdefs.h <<_ACEOF +#define `$as_echo "HAVE_$libopc" | $as_tr_cpp` 1 +_ACEOF +have_libopcodes="yes" +else + have_libopcodes="no" +fi + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing bfd_init" >&5 +$as_echo_n "checking for library containing bfd_init... " >&6; } +if test "${ac_cv_search_bfd_init+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_func_search_save_LIBS=$LIBS +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char bfd_init (); +int +main () +{ +return bfd_init (); + ; + return 0; +} +_ACEOF +for ac_lib in '' bfd; do + if test -z "$ac_lib"; then + ac_res="none required" + else + ac_res=-l$ac_lib + LIBS="-l$ac_lib $ac_func_search_save_LIBS" + fi + if ac_fn_c_try_link "$LINENO"; then : + ac_cv_search_bfd_init=$ac_res +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext + if test "${ac_cv_search_bfd_init+set}" = set; then : + break +fi +done +if test "${ac_cv_search_bfd_init+set}" = set; then : + +else + ac_cv_search_bfd_init=no +fi +rm conftest.$ac_ext +LIBS=$ac_func_search_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_bfd_init" >&5 +$as_echo "$ac_cv_search_bfd_init" >&6; } +ac_res=$ac_cv_search_bfd_init +if test "$ac_res" != no; then : + test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" + +else + have_libopcodes="no" +fi + + +if test "$have_libopcodes" = "no"; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Could not find opcodes library" >&5 +$as_echo "$as_me: WARNING: Could not find opcodes library" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Build will not include disassembly support" >&5 +$as_echo "$as_me: WARNING: Build will not include disassembly support" >&2;} + +else + + LIBS="$libopc $LIBS" + +$as_echo "#define RISCV_HAVE_LIBOPCODES /**/" >>confdefs.h + + +fi + + + + + + # Determine if this is a required or an optional subproject + + + + # Determine if there is a group with the same name + + + + # Create variations of the subproject name suitable for use as a CPP + # enabled define, a shell enabled variable, and a shell function + + + + + + + + + + + + # Add subproject to our running list + + subprojects="$subprojects softfloat" + + # Process the subproject appropriately. If enabled add it to the + # $enabled_subprojects running shell variable, set a + # SUBPROJECT_ENABLED C define, and include the appropriate + # 'subproject.ac'. + + + { $as_echo "$as_me:${as_lineno-$LINENO}: configuring default subproject : softfloat" >&5 +$as_echo "$as_me: configuring default subproject : softfloat" >&6;} + ac_config_files="$ac_config_files softfloat.mk:softfloat/softfloat.mk.in" + + enable_softfloat_sproj="yes" + subprojects_enabled="$subprojects_enabled softfloat" + +$as_echo "#define SOFTFLOAT_ENABLED /**/" >>confdefs.h + + + + + + + # Determine if this is a required or an optional subproject + + + + # Determine if there is a group with the same name + + + + # Create variations of the subproject name suitable for use as a CPP + # enabled define, a shell enabled variable, and a shell function + + + + + + + + + + + + # Add subproject to our running list + + subprojects="$subprojects softfloat_riscv" + + # Process the subproject appropriately. If enabled add it to the + # $enabled_subprojects running shell variable, set a + # SUBPROJECT_ENABLED C define, and include the appropriate + # 'subproject.ac'. + + + { $as_echo "$as_me:${as_lineno-$LINENO}: configuring default subproject : softfloat_riscv" >&5 +$as_echo "$as_me: configuring default subproject : softfloat_riscv" >&6;} + ac_config_files="$ac_config_files softfloat_riscv.mk:softfloat_riscv/softfloat_riscv.mk.in" + + enable_softfloat_riscv_sproj="yes" + subprojects_enabled="$subprojects_enabled softfloat_riscv" + +$as_echo "#define SOFTFLOAT_RISCV_ENABLED /**/" >>confdefs.h + + + + + + + # Output make variables + + + + + + +#------------------------------------------------------------------------- +# MCPPBS subproject groups +#------------------------------------------------------------------------- +# If a group has the same name as a subproject then you must add the +# '**' suffix in the subproject list above. The list of subprojects in a +# group should be ordered so that subprojets only depend on those listed +# earlier. Here is an example: +# +# MCPPBS_GROUP( [group-name], [sproja,sprojb,...] ) +# + +#------------------------------------------------------------------------- +# Output +#------------------------------------------------------------------------- + +ac_config_headers="$ac_config_headers config.h" + +ac_config_files="$ac_config_files Makefile" + +cat >confcache <<\_ACEOF +# This file is a shell script that caches the results of configure +# tests run on this system so they can be shared between configure +# scripts and configure runs, see configure's option --config-cache. +# It is not useful on other systems. If it contains results you don't +# want to keep, you may remove or edit it. +# +# config.status only pays attention to the cache file if you give it +# the --recheck option to rerun configure. +# +# `ac_cv_env_foo' variables (set or unset) will be overridden when +# loading this file, other *unset* `ac_cv_foo' will be assigned the +# following values. + +_ACEOF + +# The following way of writing the cache mishandles newlines in values, +# but we know of no workaround that is simple, portable, and efficient. +# So, we kill variables containing newlines. +# Ultrix sh set writes to stderr and can't be redirected directly, +# and sets the high bit in the cache file unless we assign to the vars. +( + for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do + eval ac_val=\$$ac_var + case $ac_val in #( + *${as_nl}*) + case $ac_var in #( + *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 +$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; + esac + case $ac_var in #( + _ | IFS | as_nl) ;; #( + BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( + *) { eval $ac_var=; unset $ac_var;} ;; + esac ;; + esac + done + + (set) 2>&1 | + case $as_nl`(ac_space=' '; set) 2>&1` in #( + *${as_nl}ac_space=\ *) + # `set' does not quote correctly, so add quotes: double-quote + # substitution turns \\\\ into \\, and sed turns \\ into \. + sed -n \ + "s/'/'\\\\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" + ;; #( + *) + # `set' quotes correctly as required by POSIX, so do not add quotes. + sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" + ;; + esac | + sort +) | + sed ' + /^ac_cv_env_/b end + t clear + :clear + s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ + t end + s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ + :end' >>confcache +if diff "$cache_file" confcache >/dev/null 2>&1; then :; else + if test -w "$cache_file"; then + test "x$cache_file" != "x/dev/null" && + { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5 +$as_echo "$as_me: updating cache $cache_file" >&6;} + cat confcache >$cache_file + else + { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5 +$as_echo "$as_me: not updating unwritable cache $cache_file" >&6;} + fi +fi +rm -f confcache + +test "x$prefix" = xNONE && prefix=$ac_default_prefix +# Let make expand exec_prefix. +test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' + +DEFS=-DHAVE_CONFIG_H + +ac_libobjs= +ac_ltlibobjs= +for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue + # 1. Remove the extension, and $U if already installed. + ac_script='s/\$U\././;s/\.o$//;s/\.obj$//' + ac_i=`$as_echo "$ac_i" | sed "$ac_script"` + # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR + # will be set to the directory where LIBOBJS objects are built. + as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext" + as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo' +done +LIBOBJS=$ac_libobjs + +LTLIBOBJS=$ac_ltlibobjs + + + +: ${CONFIG_STATUS=./config.status} +ac_write_fail=0 +ac_clean_files_save=$ac_clean_files +ac_clean_files="$ac_clean_files $CONFIG_STATUS" +{ $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5 +$as_echo "$as_me: creating $CONFIG_STATUS" >&6;} +as_write_fail=0 +cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1 +#! $SHELL +# Generated by $as_me. +# Run this file to recreate the current configuration. +# Compiler output produced by configure, useful for debugging +# configure, is in config.log if it exists. + +debug=false +ac_cs_recheck=false +ac_cs_silent=false + +SHELL=\${CONFIG_SHELL-$SHELL} +export SHELL +_ASEOF +cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1 +## -------------------- ## +## M4sh Initialization. ## +## -------------------- ## + +# Be more Bourne compatible +DUALCASE=1; export DUALCASE # for MKS sh +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : + emulate sh + NULLCMD=: + # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in #( + *posix*) : + set -o posix ;; #( + *) : + ;; +esac +fi + + +as_nl=' +' +export as_nl +# Printing a long string crashes Solaris 7 /usr/bin/printf. +as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo +# Prefer a ksh shell builtin over an external printf program on Solaris, +# but without wasting forks for bash or zsh. +if test -z "$BASH_VERSION$ZSH_VERSION" \ + && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='print -r --' + as_echo_n='print -rn --' +elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='printf %s\n' + as_echo_n='printf %s' +else + if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then + as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' + as_echo_n='/usr/ucb/echo -n' + else + as_echo_body='eval expr "X$1" : "X\\(.*\\)"' + as_echo_n_body='eval + arg=$1; + case $arg in #( + *"$as_nl"*) + expr "X$arg" : "X\\(.*\\)$as_nl"; + arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; + esac; + expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" + ' + export as_echo_n_body + as_echo_n='sh -c $as_echo_n_body as_echo' + fi + export as_echo_body + as_echo='sh -c $as_echo_body as_echo' +fi + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + PATH_SEPARATOR=: + (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { + (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || + PATH_SEPARATOR=';' + } +fi + + +# IFS +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent editors from complaining about space-tab. +# (If _AS_PATH_WALK were called with IFS unset, it would disable word +# splitting by setting IFS to empty value.) +IFS=" "" $as_nl" + +# Find who we are. Look in the path if we contain no directory separator. +case $0 in #(( + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break + done +IFS=$as_save_IFS + + ;; +esac +# We did not find ourselves, most probably we were run as `sh COMMAND' +# in which case we are not to be found in the path. +if test "x$as_myself" = x; then + as_myself=$0 +fi +if test ! -f "$as_myself"; then + $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + exit 1 +fi + +# Unset variables that we do not need and which cause bugs (e.g. in +# pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" +# suppresses any "Segmentation fault" message there. '((' could +# trigger a bug in pdksh 5.2.14. +for as_var in BASH_ENV ENV MAIL MAILPATH +do eval test x\${$as_var+set} = xset \ + && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : +done +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +LC_ALL=C +export LC_ALL +LANGUAGE=C +export LANGUAGE + +# CDPATH. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + + +# as_fn_error ERROR [LINENO LOG_FD] +# --------------------------------- +# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are +# provided, also output the error to LOG_FD, referencing LINENO. Then exit the +# script with status $?, using 1 if that was 0. +as_fn_error () +{ + as_status=$?; test $as_status -eq 0 && as_status=1 + if test "$3"; then + as_lineno=${as_lineno-"$2"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + $as_echo "$as_me:${as_lineno-$LINENO}: error: $1" >&$3 + fi + $as_echo "$as_me: error: $1" >&2 + as_fn_exit $as_status +} # as_fn_error + + +# as_fn_set_status STATUS +# ----------------------- +# Set $? to STATUS, without forking. +as_fn_set_status () +{ + return $1 +} # as_fn_set_status + +# as_fn_exit STATUS +# ----------------- +# Exit the shell with STATUS, even in a "trap 0" or "set -e" context. +as_fn_exit () +{ + set +e + as_fn_set_status $1 + exit $1 +} # as_fn_exit + +# as_fn_unset VAR +# --------------- +# Portably unset VAR. +as_fn_unset () +{ + { eval $1=; unset $1;} +} +as_unset=as_fn_unset +# as_fn_append VAR VALUE +# ---------------------- +# Append the text in VALUE to the end of the definition contained in VAR. Take +# advantage of any shell optimizations that allow amortized linear growth over +# repeated appends, instead of the typical quadratic growth present in naive +# implementations. +if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : + eval 'as_fn_append () + { + eval $1+=\$2 + }' +else + as_fn_append () + { + eval $1=\$$1\$2 + } +fi # as_fn_append + +# as_fn_arith ARG... +# ------------------ +# Perform arithmetic evaluation on the ARGs, and store the result in the +# global $as_val. Take advantage of shells that can avoid forks. The arguments +# must be portable across $(()) and expr. +if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : + eval 'as_fn_arith () + { + as_val=$(( $* )) + }' +else + as_fn_arith () + { + as_val=`expr "$@" || test $? -eq 1` + } +fi # as_fn_arith + + +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + +if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then + as_dirname=dirname +else + as_dirname=false +fi + +as_me=`$as_basename -- "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + +ECHO_C= ECHO_N= ECHO_T= +case `echo -n x` in #((((( +-n*) + case `echo 'xy\c'` in + *c*) ECHO_T=' ';; # ECHO_T is single tab character. + xy) ECHO_C='\c';; + *) echo `echo ksh88 bug on AIX 6.1` > /dev/null + ECHO_T=' ';; + esac;; +*) + ECHO_N='-n';; +esac + +rm -f conf$$ conf$$.exe conf$$.file +if test -d conf$$.dir; then + rm -f conf$$.dir/conf$$.file +else + rm -f conf$$.dir + mkdir conf$$.dir 2>/dev/null +fi +if (echo >conf$$.file) 2>/dev/null; then + if ln -s conf$$.file conf$$ 2>/dev/null; then + as_ln_s='ln -s' + # ... but there are two gotchas: + # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. + # In both cases, we have to default to `cp -p'. + ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || + as_ln_s='cp -p' + elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln + else + as_ln_s='cp -p' + fi +else + as_ln_s='cp -p' +fi +rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file +rmdir conf$$.dir 2>/dev/null + + +# as_fn_mkdir_p +# ------------- +# Create "$as_dir" as a directory, including parents if necessary. +as_fn_mkdir_p () +{ + + case $as_dir in #( + -*) as_dir=./$as_dir;; + esac + test -d "$as_dir" || eval $as_mkdir_p || { + as_dirs= + while :; do + case $as_dir in #( + *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( + *) as_qdir=$as_dir;; + esac + as_dirs="'$as_qdir' $as_dirs" + as_dir=`$as_dirname -- "$as_dir" || +$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_dir" : 'X\(//\)[^/]' \| \ + X"$as_dir" : 'X\(//\)$' \| \ + X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$as_dir" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + test -d "$as_dir" && break + done + test -z "$as_dirs" || eval "mkdir $as_dirs" + } || test -d "$as_dir" || as_fn_error "cannot create directory $as_dir" + + +} # as_fn_mkdir_p +if mkdir -p . 2>/dev/null; then + as_mkdir_p='mkdir -p "$as_dir"' +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + +if test -x / >/dev/null 2>&1; then + as_test_x='test -x' +else + if ls -dL / >/dev/null 2>&1; then + as_ls_L_option=L + else + as_ls_L_option= + fi + as_test_x=' + eval sh -c '\'' + if test -d "$1"; then + test -d "$1/."; + else + case $1 in #( + -*)set "./$1";; + esac; + case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #(( + ???[sx]*):;;*)false;;esac;fi + '\'' sh + ' +fi +as_executable_p=$as_test_x + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + + +exec 6>&1 +## ----------------------------------- ## +## Main body of $CONFIG_STATUS script. ## +## ----------------------------------- ## +_ASEOF +test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1 + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +# Save the log message, to keep $0 and so on meaningful, and to +# report actual input values of CONFIG_FILES etc. instead of their +# values after options handling. +ac_log=" +This file was extended by RISC-V ISA Simulator $as_me ?, which was +generated by GNU Autoconf 2.64. Invocation command line was + + CONFIG_FILES = $CONFIG_FILES + CONFIG_HEADERS = $CONFIG_HEADERS + CONFIG_LINKS = $CONFIG_LINKS + CONFIG_COMMANDS = $CONFIG_COMMANDS + $ $0 $@ + +on `(hostname || uname -n) 2>/dev/null | sed 1q` +" + +_ACEOF + +case $ac_config_files in *" +"*) set x $ac_config_files; shift; ac_config_files=$*;; +esac + +case $ac_config_headers in *" +"*) set x $ac_config_headers; shift; ac_config_headers=$*;; +esac + + +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +# Files that config.status was made for. +config_files="$ac_config_files" +config_headers="$ac_config_headers" + +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +ac_cs_usage="\ +\`$as_me' instantiates files and other configuration actions +from templates according to the current configuration. Unless the files +and actions are specified as TAGs, all are instantiated by default. + +Usage: $0 [OPTION]... [TAG]... + + -h, --help print this help, then exit + -V, --version print version number and configuration settings, then exit + -q, --quiet, --silent + do not print progress messages + -d, --debug don't remove temporary files + --recheck update $as_me by reconfiguring in the same conditions + --file=FILE[:TEMPLATE] + instantiate the configuration file FILE + --header=FILE[:TEMPLATE] + instantiate the configuration header FILE + +Configuration files: +$config_files + +Configuration headers: +$config_headers + +Report bugs to ." + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +ac_cs_version="\\ +RISC-V ISA Simulator config.status ? +configured by $0, generated by GNU Autoconf 2.64, + with options \\"`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\" + +Copyright (C) 2009 Free Software Foundation, Inc. +This config.status script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it." + +ac_pwd='$ac_pwd' +srcdir='$srcdir' +INSTALL='$INSTALL' +test -n "\$AWK" || AWK=awk +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +# The default lists apply if the user does not specify any file. +ac_need_defaults=: +while test $# != 0 +do + case $1 in + --*=*) + ac_option=`expr "X$1" : 'X\([^=]*\)='` + ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'` + ac_shift=: + ;; + *) + ac_option=$1 + ac_optarg=$2 + ac_shift=shift + ;; + esac + + case $ac_option in + # Handling of the options. + -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) + ac_cs_recheck=: ;; + --version | --versio | --versi | --vers | --ver | --ve | --v | -V ) + $as_echo "$ac_cs_version"; exit ;; + --debug | --debu | --deb | --de | --d | -d ) + debug=: ;; + --file | --fil | --fi | --f ) + $ac_shift + case $ac_optarg in + *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + as_fn_append CONFIG_FILES " '$ac_optarg'" + ac_need_defaults=false;; + --header | --heade | --head | --hea ) + $ac_shift + case $ac_optarg in + *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + as_fn_append CONFIG_HEADERS " '$ac_optarg'" + ac_need_defaults=false;; + --he | --h) + # Conflict between --help and --header + as_fn_error "ambiguous option: \`$1' +Try \`$0 --help' for more information.";; + --help | --hel | -h ) + $as_echo "$ac_cs_usage"; exit ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil | --si | --s) + ac_cs_silent=: ;; + + # This is an error. + -*) as_fn_error "unrecognized option: \`$1' +Try \`$0 --help' for more information." ;; + + *) as_fn_append ac_config_targets " $1" + ac_need_defaults=false ;; + + esac + shift +done + +ac_configure_extra_args= + +if $ac_cs_silent; then + exec 6>/dev/null + ac_configure_extra_args="$ac_configure_extra_args --silent" +fi + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +if \$ac_cs_recheck; then + set X '$SHELL' '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion + shift + \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6 + CONFIG_SHELL='$SHELL' + export CONFIG_SHELL + exec "\$@" +fi + +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +exec 5>>config.log +{ + echo + sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX +## Running $as_me. ## +_ASBOX + $as_echo "$ac_log" +} >&5 + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 + +# Handling of arguments. +for ac_config_target in $ac_config_targets +do + case $ac_config_target in + "riscv.mk") CONFIG_FILES="$CONFIG_FILES riscv.mk:riscv/riscv.mk.in" ;; + "softfloat.mk") CONFIG_FILES="$CONFIG_FILES softfloat.mk:softfloat/softfloat.mk.in" ;; + "softfloat_riscv.mk") CONFIG_FILES="$CONFIG_FILES softfloat_riscv.mk:softfloat_riscv/softfloat_riscv.mk.in" ;; + "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; + "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; + + *) as_fn_error "invalid argument: \`$ac_config_target'" "$LINENO" 5;; + esac +done + + +# If the user did not use the arguments to specify the items to instantiate, +# then the envvar interface is used. Set only those that are not. +# We use the long form for the default assignment because of an extremely +# bizarre bug on SunOS 4.1.3. +if $ac_need_defaults; then + test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files + test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers +fi + +# Have a temporary directory for convenience. Make it in the build tree +# simply because there is no reason against having it here, and in addition, +# creating and moving files from /tmp can sometimes cause problems. +# Hook for its removal unless debugging. +# Note that there is a small window in which the directory will not be cleaned: +# after its creation but before its name has been assigned to `$tmp'. +$debug || +{ + tmp= + trap 'exit_status=$? + { test -z "$tmp" || test ! -d "$tmp" || rm -fr "$tmp"; } && exit $exit_status +' 0 + trap 'as_fn_exit 1' 1 2 13 15 +} +# Create a (secure) tmp directory for tmp files. + +{ + tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` && + test -n "$tmp" && test -d "$tmp" +} || +{ + tmp=./conf$$-$RANDOM + (umask 077 && mkdir "$tmp") +} || as_fn_error "cannot create a temporary directory in ." "$LINENO" 5 + +# Set up the scripts for CONFIG_FILES section. +# No need to generate them if there are no CONFIG_FILES. +# This happens for instance with `./config.status config.h'. +if test -n "$CONFIG_FILES"; then + + +ac_cr=`echo X | tr X '\015'` +# On cygwin, bash can eat \r inside `` if the user requested igncr. +# But we know of no other shell where ac_cr would be empty at this +# point, so we can use a bashism as a fallback. +if test "x$ac_cr" = x; then + eval ac_cr=\$\'\\r\' +fi +ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' /dev/null` +if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then + ac_cs_awk_cr='\r' +else + ac_cs_awk_cr=$ac_cr +fi + +echo 'BEGIN {' >"$tmp/subs1.awk" && +_ACEOF + + +{ + echo "cat >conf$$subs.awk <<_ACEOF" && + echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' && + echo "_ACEOF" +} >conf$$subs.sh || + as_fn_error "could not make $CONFIG_STATUS" "$LINENO" 5 +ac_delim_num=`echo "$ac_subst_vars" | grep -c '$'` +ac_delim='%!_!# ' +for ac_last_try in false false false false false :; do + . ./conf$$subs.sh || + as_fn_error "could not make $CONFIG_STATUS" "$LINENO" 5 + + ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X` + if test $ac_delim_n = $ac_delim_num; then + break + elif $ac_last_try; then + as_fn_error "could not make $CONFIG_STATUS" "$LINENO" 5 + else + ac_delim="$ac_delim!$ac_delim _$ac_delim!! " + fi +done +rm -f conf$$subs.sh + +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +cat >>"\$tmp/subs1.awk" <<\\_ACAWK && +_ACEOF +sed -n ' +h +s/^/S["/; s/!.*/"]=/ +p +g +s/^[^!]*!// +:repl +t repl +s/'"$ac_delim"'$// +t delim +:nl +h +s/\(.\{148\}\).*/\1/ +t more1 +s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/ +p +n +b repl +:more1 +s/["\\]/\\&/g; s/^/"/; s/$/"\\/ +p +g +s/.\{148\}// +t nl +:delim +h +s/\(.\{148\}\).*/\1/ +t more2 +s/["\\]/\\&/g; s/^/"/; s/$/"/ +p +b +:more2 +s/["\\]/\\&/g; s/^/"/; s/$/"\\/ +p +g +s/.\{148\}// +t delim +' >$CONFIG_STATUS || ac_write_fail=1 +rm -f conf$$subs.awk +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +_ACAWK +cat >>"\$tmp/subs1.awk" <<_ACAWK && + for (key in S) S_is_set[key] = 1 + FS = "" + +} +{ + line = $ 0 + nfields = split(line, field, "@") + substed = 0 + len = length(field[1]) + for (i = 2; i < nfields; i++) { + key = field[i] + keylen = length(key) + if (S_is_set[key]) { + value = S[key] + line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3) + len += length(value) + length(field[++i]) + substed = 1 + } else + len += 1 + keylen + } + + print line +} + +_ACAWK +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then + sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g" +else + cat +fi < "$tmp/subs1.awk" > "$tmp/subs.awk" \ + || as_fn_error "could not setup config files machinery" "$LINENO" 5 +_ACEOF + +# VPATH may cause trouble with some makes, so we remove $(srcdir), +# ${srcdir} and @srcdir@ from VPATH if srcdir is ".", strip leading and +# trailing colons and then remove the whole line if VPATH becomes empty +# (actually we leave an empty line to preserve line numbers). +if test "x$srcdir" = x.; then + ac_vpsub='/^[ ]*VPATH[ ]*=/{ +s/:*\$(srcdir):*/:/ +s/:*\${srcdir}:*/:/ +s/:*@srcdir@:*/:/ +s/^\([^=]*=[ ]*\):*/\1/ +s/:*$// +s/^[^=]*=[ ]*$// +}' +fi + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +fi # test -n "$CONFIG_FILES" + +# Set up the scripts for CONFIG_HEADERS section. +# No need to generate them if there are no CONFIG_HEADERS. +# This happens for instance with `./config.status Makefile'. +if test -n "$CONFIG_HEADERS"; then +cat >"$tmp/defines.awk" <<\_ACAWK || +BEGIN { +_ACEOF + +# Transform confdefs.h into an awk script `defines.awk', embedded as +# here-document in config.status, that substitutes the proper values into +# config.h.in to produce config.h. + +# Create a delimiter string that does not exist in confdefs.h, to ease +# handling of long lines. +ac_delim='%!_!# ' +for ac_last_try in false false :; do + ac_t=`sed -n "/$ac_delim/p" confdefs.h` + if test -z "$ac_t"; then + break + elif $ac_last_try; then + as_fn_error "could not make $CONFIG_HEADERS" "$LINENO" 5 + else + ac_delim="$ac_delim!$ac_delim _$ac_delim!! " + fi +done + +# For the awk script, D is an array of macro values keyed by name, +# likewise P contains macro parameters if any. Preserve backslash +# newline sequences. + +ac_word_re=[_$as_cr_Letters][_$as_cr_alnum]* +sed -n ' +s/.\{148\}/&'"$ac_delim"'/g +t rset +:rset +s/^[ ]*#[ ]*define[ ][ ]*/ / +t def +d +:def +s/\\$// +t bsnl +s/["\\]/\\&/g +s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ +D["\1"]=" \3"/p +s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2"/p +d +:bsnl +s/["\\]/\\&/g +s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ +D["\1"]=" \3\\\\\\n"\\/p +t cont +s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2\\\\\\n"\\/p +t cont +d +:cont +n +s/.\{148\}/&'"$ac_delim"'/g +t clear +:clear +s/\\$// +t bsnlc +s/["\\]/\\&/g; s/^/"/; s/$/"/p +d +:bsnlc +s/["\\]/\\&/g; s/^/"/; s/$/\\\\\\n"\\/p +b cont +' >$CONFIG_STATUS || ac_write_fail=1 + +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 + for (key in D) D_is_set[key] = 1 + FS = "" +} +/^[\t ]*#[\t ]*(define|undef)[\t ]+$ac_word_re([\t (]|\$)/ { + line = \$ 0 + split(line, arg, " ") + if (arg[1] == "#") { + defundef = arg[2] + mac1 = arg[3] + } else { + defundef = substr(arg[1], 2) + mac1 = arg[2] + } + split(mac1, mac2, "(") #) + macro = mac2[1] + prefix = substr(line, 1, index(line, defundef) - 1) + if (D_is_set[macro]) { + # Preserve the white space surrounding the "#". + print prefix "define", macro P[macro] D[macro] + next + } else { + # Replace #undef with comments. This is necessary, for example, + # in the case of _POSIX_SOURCE, which is predefined and required + # on some systems where configure will not decide to define it. + if (defundef == "undef") { + print "/*", prefix defundef, macro, "*/" + next + } + } +} +{ print } +_ACAWK +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 + as_fn_error "could not setup config headers machinery" "$LINENO" 5 +fi # test -n "$CONFIG_HEADERS" + + +eval set X " :F $CONFIG_FILES :H $CONFIG_HEADERS " +shift +for ac_tag +do + case $ac_tag in + :[FHLC]) ac_mode=$ac_tag; continue;; + esac + case $ac_mode$ac_tag in + :[FHL]*:*);; + :L* | :C*:*) as_fn_error "invalid tag \`$ac_tag'" "$LINENO" 5;; + :[FH]-) ac_tag=-:-;; + :[FH]*) ac_tag=$ac_tag:$ac_tag.in;; + esac + ac_save_IFS=$IFS + IFS=: + set x $ac_tag + IFS=$ac_save_IFS + shift + ac_file=$1 + shift + + case $ac_mode in + :L) ac_source=$1;; + :[FH]) + ac_file_inputs= + for ac_f + do + case $ac_f in + -) ac_f="$tmp/stdin";; + *) # Look for the file first in the build tree, then in the source tree + # (if the path is not absolute). The absolute path cannot be DOS-style, + # because $ac_f cannot contain `:'. + test -f "$ac_f" || + case $ac_f in + [\\/$]*) false;; + *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; + esac || + as_fn_error "cannot find input file: \`$ac_f'" "$LINENO" 5;; + esac + case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac + as_fn_append ac_file_inputs " '$ac_f'" + done + + # Let's still pretend it is `configure' which instantiates (i.e., don't + # use $as_me), people would be surprised to read: + # /* config.h. Generated by config.status. */ + configure_input='Generated from '` + $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g' + `' by configure.' + if test x"$ac_file" != x-; then + configure_input="$ac_file. $configure_input" + { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5 +$as_echo "$as_me: creating $ac_file" >&6;} + fi + # Neutralize special characters interpreted by sed in replacement strings. + case $configure_input in #( + *\&* | *\|* | *\\* ) + ac_sed_conf_input=`$as_echo "$configure_input" | + sed 's/[\\\\&|]/\\\\&/g'`;; #( + *) ac_sed_conf_input=$configure_input;; + esac + + case $ac_tag in + *:-:* | *:-) cat >"$tmp/stdin" \ + || as_fn_error "could not create $ac_file" "$LINENO" 5 ;; + esac + ;; + esac + + ac_dir=`$as_dirname -- "$ac_file" || +$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$ac_file" : 'X\(//\)[^/]' \| \ + X"$ac_file" : 'X\(//\)$' \| \ + X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$ac_file" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + as_dir="$ac_dir"; as_fn_mkdir_p + ac_builddir=. + +case "$ac_dir" in +.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; +*) + ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` + # A ".." for each directory in $ac_dir_suffix. + ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` + case $ac_top_builddir_sub in + "") ac_top_builddir_sub=. ac_top_build_prefix= ;; + *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; + esac ;; +esac +ac_abs_top_builddir=$ac_pwd +ac_abs_builddir=$ac_pwd$ac_dir_suffix +# for backward compatibility: +ac_top_builddir=$ac_top_build_prefix + +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix + + + case $ac_mode in + :F) + # + # CONFIG_FILE + # + + case $INSTALL in + [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;; + *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;; + esac +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +# If the template does not know about datarootdir, expand it. +# FIXME: This hack should be removed a few years after 2.60. +ac_datarootdir_hack=; ac_datarootdir_seen= +ac_sed_dataroot=' +/datarootdir/ { + p + q +} +/@datadir@/p +/@docdir@/p +/@infodir@/p +/@localedir@/p +/@mandir@/p' +case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in +*datarootdir*) ac_datarootdir_seen=yes;; +*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 +$as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 + ac_datarootdir_hack=' + s&@datadir@&$datadir&g + s&@docdir@&$docdir&g + s&@infodir@&$infodir&g + s&@localedir@&$localedir&g + s&@mandir@&$mandir&g + s&\\\${datarootdir}&$datarootdir&g' ;; +esac +_ACEOF + +# Neutralize VPATH when `$srcdir' = `.'. +# Shell code in configure.ac might set extrasub. +# FIXME: do we really want to maintain this feature? +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +ac_sed_extra="$ac_vpsub +$extrasub +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +:t +/@[a-zA-Z_][a-zA-Z_0-9]*@/!b +s|@configure_input@|$ac_sed_conf_input|;t t +s&@top_builddir@&$ac_top_builddir_sub&;t t +s&@top_build_prefix@&$ac_top_build_prefix&;t t +s&@srcdir@&$ac_srcdir&;t t +s&@abs_srcdir@&$ac_abs_srcdir&;t t +s&@top_srcdir@&$ac_top_srcdir&;t t +s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t +s&@builddir@&$ac_builddir&;t t +s&@abs_builddir@&$ac_abs_builddir&;t t +s&@abs_top_builddir@&$ac_abs_top_builddir&;t t +s&@INSTALL@&$ac_INSTALL&;t t +$ac_datarootdir_hack +" +eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$tmp/subs.awk" >$tmp/out \ + || as_fn_error "could not create $ac_file" "$LINENO" 5 + +test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && + { ac_out=`sed -n '/\${datarootdir}/p' "$tmp/out"`; test -n "$ac_out"; } && + { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' "$tmp/out"`; test -z "$ac_out"; } && + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir' +which seems to be undefined. Please make sure it is defined." >&5 +$as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' +which seems to be undefined. Please make sure it is defined." >&2;} + + rm -f "$tmp/stdin" + case $ac_file in + -) cat "$tmp/out" && rm -f "$tmp/out";; + *) rm -f "$ac_file" && mv "$tmp/out" "$ac_file";; + esac \ + || as_fn_error "could not create $ac_file" "$LINENO" 5 + ;; + :H) + # + # CONFIG_HEADER + # + if test x"$ac_file" != x-; then + { + $as_echo "/* $configure_input */" \ + && eval '$AWK -f "$tmp/defines.awk"' "$ac_file_inputs" + } >"$tmp/config.h" \ + || as_fn_error "could not create $ac_file" "$LINENO" 5 + if diff "$ac_file" "$tmp/config.h" >/dev/null 2>&1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5 +$as_echo "$as_me: $ac_file is unchanged" >&6;} + else + rm -f "$ac_file" + mv "$tmp/config.h" "$ac_file" \ + || as_fn_error "could not create $ac_file" "$LINENO" 5 + fi + else + $as_echo "/* $configure_input */" \ + && eval '$AWK -f "$tmp/defines.awk"' "$ac_file_inputs" \ + || as_fn_error "could not create -" "$LINENO" 5 + fi + ;; + + + esac + +done # for ac_tag + + +as_fn_exit 0 +_ACEOF +ac_clean_files=$ac_clean_files_save + +test $ac_write_fail = 0 || + as_fn_error "write failure creating $CONFIG_STATUS" "$LINENO" 5 + + +# configure is writing to config.log, and then calls config.status. +# config.status does its own redirection, appending to config.log. +# Unfortunately, on DOS this fails, as config.log is still kept open +# by configure, so config.status won't be able to write to it; its +# output is simply discarded. So we exec the FD to /dev/null, +# effectively closing config.log, so it can be properly (re)opened and +# appended to by config.status. When coming back to configure, we +# need to make the FD available again. +if test "$no_create" != yes; then + ac_cs_success=: + ac_config_status_args= + test "$silent" = yes && + ac_config_status_args="$ac_config_status_args --quiet" + exec 5>/dev/null + $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false + exec 5>>config.log + # Use ||, not &&, to avoid exiting from the if with $? = 1, which + # would make configure fail if this is the last instruction. + $ac_cs_success || as_fn_exit $? +fi +if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 +$as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} +fi + diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..42aa634 --- /dev/null +++ b/configure.ac @@ -0,0 +1,103 @@ +#========================================================================= +# Toplevel configure.ac for the Modular C++ Build System +#========================================================================= +# Please read the documenation in 'mcppbs-doc.txt' for more details on +# how the Modular C++ Build System works. For most new projects, a +# developer will only need to make the following changes: +# +# - change the project metadata listed right below +# - update the list of subprojects via the 'MCPPBS_SUBPROJECTS' macro +# - possibly add subproject groups if needed to ease configuration +# - add more configure checks for platform specific configuration +# + +#------------------------------------------------------------------------- +# Project metadata +#------------------------------------------------------------------------- + +m4_define( proj_name, [RISC-V ISA Simulator]) +m4_define( proj_maintainer, [Andrew Waterman]) +m4_define( proj_abbreviation, [riscv-isa-run]) + +#------------------------------------------------------------------------- +# Project version information +#------------------------------------------------------------------------- +# Version information is meant to be managed through a version control +# system's tags and revision numbers. In a working copy the version will +# not be defined here (you should just use the version control system's +# mechanisms). When we make a distribution then we can set the version +# here as formed by the scripts/vcs-version.sh script so that the +# distribution knows what version it came from. If you are not using +# version control then it is fine to set this directly. + +m4_define( proj_version, [?]) + +#------------------------------------------------------------------------- +# Setup +#------------------------------------------------------------------------- + +AC_INIT(proj_name,proj_version,proj_maintainer,proj_abbreviation) +AC_CONFIG_SRCDIR([riscv/common.h]) +AC_CONFIG_AUX_DIR([scripts]) +AC_CANONICAL_BUILD +AC_CANONICAL_HOST + +#------------------------------------------------------------------------- +# Checks for programs +#------------------------------------------------------------------------- + +AC_PROG_CC +AC_PROG_CXX +AC_CHECK_TOOL([AR],[ar]) +AC_CHECK_TOOL([RANLIB],[ranlib]) + +#------------------------------------------------------------------------- +# MCPPBS specific program checks +#------------------------------------------------------------------------- +# These macros check to see if we can do a stow-based install and also +# check for an isa simulator suitable for running the unit test programs +# via the makefile. + +MCPPBS_PROG_INSTALL +MCPPBS_PROG_RUN + +#------------------------------------------------------------------------- +# Checks for header files +#------------------------------------------------------------------------- + +AC_HEADER_STDC + +#------------------------------------------------------------------------- +# Default compiler flags +#------------------------------------------------------------------------- + +AC_SUBST([CFLAGS], ["-Wall -O2"]) +AC_SUBST([CXXFLAGS],["-Wall -O2 -Wno-pmf-conversions"]) + +#------------------------------------------------------------------------- +# MCPPBS subproject list +#------------------------------------------------------------------------- +# Order list so that subprojects only depend on those listed earlier. +# The '*' suffix indicates an optional subproject. The '**' suffix +# indicates an optional subproject which is also the name of a group. + +MCPPBS_SUBPROJECTS([ riscv, softfloat, softfloat_riscv ]) + +#------------------------------------------------------------------------- +# MCPPBS subproject groups +#------------------------------------------------------------------------- +# If a group has the same name as a subproject then you must add the +# '**' suffix in the subproject list above. The list of subprojects in a +# group should be ordered so that subprojets only depend on those listed +# earlier. Here is an example: +# +# MCPPBS_GROUP( [group-name], [sproja,sprojb,...] ) +# + +#------------------------------------------------------------------------- +# Output +#------------------------------------------------------------------------- + +AC_CONFIG_HEADERS([config.h]) +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT diff --git a/riscv/common.h b/riscv/common.h new file mode 100644 index 0000000..801baf8 --- /dev/null +++ b/riscv/common.h @@ -0,0 +1,9 @@ +#ifndef _RISCV_COMMON_H +#define _RISCV_COMMON_H + +#define static_assert(x) switch (x) case 0: case (x): + +#define likely(x) __builtin_expect(x, 1) +#define unlikely(x) __builtin_expect(x, 0) + +#endif diff --git a/riscv/decode.h b/riscv/decode.h new file mode 100644 index 0000000..f78c8f4 --- /dev/null +++ b/riscv/decode.h @@ -0,0 +1,301 @@ +#ifndef _RISCV_DECODE_H +#define _RISCV_DECODE_H + +#define __STDC_LIMIT_MACROS +#include +#include "common.h" +#include "config.h" + +typedef int int128_t __attribute__((mode(TI))); +typedef unsigned int uint128_t __attribute__((mode(TI))); + +typedef int64_t sreg_t; +typedef uint64_t reg_t; +typedef uint64_t freg_t; + +const int OPCODE_BITS = 7; + +const int XPRID_BITS = 5; +const int NXPR = 1 << XPRID_BITS; + +const int FPR_BITS = 64; +const int FPRID_BITS = 5; +const int NFPR = 1 << FPRID_BITS; + +const int IMM_BITS = 12; +const int IMMLO_BITS = 7; +const int TARGET_BITS = 25; +const int FUNCT_BITS = 3; +const int FUNCTR_BITS = 7; +const int FFUNCT_BITS = 2; +const int RM_BITS = 3; +const int BIGIMM_BITS = 20; +const int BRANCH_ALIGN_BITS = 1; +const int JUMP_ALIGN_BITS = 1; + +#define SR_ET 0x0000000000000001ULL +#define SR_EF 0x0000000000000002ULL +#define SR_EV 0x0000000000000004ULL +#define SR_EC 0x0000000000000008ULL +#define SR_PS 0x0000000000000010ULL +#define SR_S 0x0000000000000020ULL +#define SR_UX 0x0000000000000040ULL +#define SR_SX 0x0000000000000080ULL +#define SR_IM 0x000000000000FF00ULL +#define SR_VM 0x0000000000010000ULL +#define SR_ZERO ~(SR_ET|SR_EF|SR_EV|SR_EC|SR_PS|SR_S|SR_UX|SR_SX|SR_IM|SR_VM) +#define SR_IM_SHIFT 8 +#define IPI_IRQ 5 +#define TIMER_IRQ 7 + +#define CAUSE_EXCCODE 0x000000FF +#define CAUSE_IP 0x0000FF00 +#define CAUSE_EXCCODE_SHIFT 0 +#define CAUSE_IP_SHIFT 8 + +#define FP_RD_NE 0 +#define FP_RD_0 1 +#define FP_RD_DN 2 +#define FP_RD_UP 3 +#define FP_RD_NMM 4 + +#define FSR_RD_SHIFT 5 +#define FSR_RD (0x7 << FSR_RD_SHIFT) + +#define FPEXC_NX 0x01 +#define FPEXC_UF 0x02 +#define FPEXC_OF 0x04 +#define FPEXC_DZ 0x08 +#define FPEXC_NV 0x10 + +#define FSR_AEXC_SHIFT 0 +#define FSR_NVA (FPEXC_NV << FSR_AEXC_SHIFT) +#define FSR_OFA (FPEXC_OF << FSR_AEXC_SHIFT) +#define FSR_UFA (FPEXC_UF << FSR_AEXC_SHIFT) +#define FSR_DZA (FPEXC_DZ << FSR_AEXC_SHIFT) +#define FSR_NXA (FPEXC_NX << FSR_AEXC_SHIFT) +#define FSR_AEXC (FSR_NVA | FSR_OFA | FSR_UFA | FSR_DZA | FSR_NXA) + +#define FSR_ZERO ~(FSR_RD | FSR_AEXC) + +// note: bit fields are in little-endian order +struct itype_t +{ + unsigned opcode : OPCODE_BITS; + unsigned funct : FUNCT_BITS; + signed imm12 : IMM_BITS; + unsigned rs1 : XPRID_BITS; + unsigned rd : XPRID_BITS; +}; + +struct btype_t +{ + unsigned opcode : OPCODE_BITS; + unsigned funct : FUNCT_BITS; + unsigned immlo : IMMLO_BITS; + unsigned rs2 : XPRID_BITS; + unsigned rs1 : XPRID_BITS; + signed immhi : IMM_BITS-IMMLO_BITS; +}; + +struct jtype_t +{ + unsigned jump_opcode : OPCODE_BITS; + signed target : TARGET_BITS; +}; + +struct rtype_t +{ + unsigned opcode : OPCODE_BITS; + unsigned funct : FUNCT_BITS; + unsigned functr : FUNCTR_BITS; + unsigned rs2 : XPRID_BITS; + unsigned rs1 : XPRID_BITS; + unsigned rd : XPRID_BITS; +}; + +struct ltype_t +{ + unsigned opcode : OPCODE_BITS; + unsigned bigimm : BIGIMM_BITS; + unsigned rd : XPRID_BITS; +}; + +struct ftype_t +{ + unsigned opcode : OPCODE_BITS; + unsigned ffunct : FFUNCT_BITS; + unsigned rm : RM_BITS; + unsigned rs3 : FPRID_BITS; + unsigned rs2 : FPRID_BITS; + unsigned rs1 : FPRID_BITS; + unsigned rd : FPRID_BITS; +}; + +union insn_t +{ + itype_t itype; + jtype_t jtype; + rtype_t rtype; + btype_t btype; + ltype_t ltype; + ftype_t ftype; + uint32_t bits; +}; + +#include +class do_writeback +{ +public: + do_writeback(reg_t* _rf, int _rd) : rf(_rf), rd(_rd) {} + + const do_writeback& operator = (reg_t rhs) + { +#if 0 + printf("R[%x] <= %llx\n",rd,(long long)rhs); +#endif + rf[rd] = rhs; + rf[0] = 0; + return *this; + } + + operator reg_t() { return rf[rd]; } + +private: + reg_t* rf; + int rd; +}; + +#define throw_illegal_instruction \ + ({ if (utmode) throw trap_vector_illegal_instruction; \ + else throw trap_illegal_instruction; }) + +// helpful macros, etc +#define RS1 XPR[insn.rtype.rs1] +#define RS2 XPR[insn.rtype.rs2] +#define RD do_writeback(XPR,insn.rtype.rd) +#define RA do_writeback(XPR,1) +#define FRS1 FPR[insn.ftype.rs1] +#define FRS2 FPR[insn.ftype.rs2] +#define FRS3 FPR[insn.ftype.rs3] +#define FRD FPR[insn.ftype.rd] +#define BIGIMM insn.ltype.bigimm +#define SIMM insn.itype.imm12 +#define BIMM ((signed)insn.btype.immlo | (insn.btype.immhi << IMMLO_BITS)) +#define SHAMT (insn.itype.imm12 & 0x3F) +#define SHAMTW (insn.itype.imm12 & 0x1F) +#define TARGET insn.jtype.target +#define BRANCH_TARGET (pc + (BIMM << BRANCH_ALIGN_BITS)) +#define JUMP_TARGET (pc + (TARGET << JUMP_ALIGN_BITS)) +#define RM ({ int rm = insn.ftype.rm; \ + if(rm == 7) rm = (fsr & FSR_RD) >> FSR_RD_SHIFT; \ + if(rm > 4) throw_illegal_instruction; \ + rm; }) + +#define require_supervisor if(unlikely(!(sr & SR_S))) throw trap_privileged_instruction +#define xpr64 (xprlen == 64) +#define require_xpr64 if(unlikely(!xpr64)) throw_illegal_instruction +#define require_xpr32 if(unlikely(xpr64)) throw_illegal_instruction +#define require_fp if(unlikely(!(sr & SR_EF))) throw trap_fp_disabled +#define require_vector \ + ({ if(!(sr & SR_EV)) throw trap_vector_disabled; \ + else if (!utmode && (vecbanks_count < 3)) throw trap_vector_bank; \ + }) +#define cmp_trunc(reg) (reg_t(reg) << (64-xprlen)) +#define set_fp_exceptions ({ set_fsr(fsr | \ + (softfloat_exceptionFlags << FSR_AEXC_SHIFT)); \ + softfloat_exceptionFlags = 0; }) + +#define sext32(x) ((sreg_t)(int32_t)(x)) +#define zext32(x) ((reg_t)(uint32_t)(x)) +#define sext_xprlen(x) ((sreg_t(x) << (64-xprlen)) >> (64-xprlen)) +#define zext_xprlen(x) ((reg_t(x) << (64-xprlen)) >> (64-xprlen)) + +#ifndef RISCV_ENABLE_RVC +# define set_pc(x) \ + do { if((x) & (sizeof(insn_t)-1)) \ + { badvaddr = (x); throw trap_instruction_address_misaligned; } \ + npc = (x); \ + } while(0) +#else +# define set_pc(x) \ + do { if((x) & ((sr & SR_EC) ? 1 : 3)) \ + { badvaddr = (x); throw trap_instruction_address_misaligned; } \ + npc = (x); \ + } while(0) +#endif + +// RVC stuff + +#define INSN_IS_RVC(x) (((x) & 0x3) < 0x3) +#define insn_length(x) (INSN_IS_RVC(x) ? 2 : 4) +#define require_rvc if(!(sr & SR_EC)) throw_illegal_instruction + +#define CRD_REGNUM ((insn.bits >> 5) & 0x1f) +#define CRD do_writeback(XPR, CRD_REGNUM) +#define CRS1 XPR[(insn.bits >> 10) & 0x1f] +#define CRS2 XPR[(insn.bits >> 5) & 0x1f] +#define CIMM6 ((int32_t)((insn.bits >> 10) & 0x3f) << 26 >> 26) +#define CIMM5U ((insn.bits >> 5) & 0x1f) +#define CIMM5 ((int32_t)CIMM5U << 27 >> 27) +#define CIMM10 ((int32_t)((insn.bits >> 5) & 0x3ff) << 22 >> 22) +#define CBRANCH_TARGET (pc + (CIMM5 << BRANCH_ALIGN_BITS)) +#define CJUMP_TARGET (pc + (CIMM10 << JUMP_ALIGN_BITS)) + +static const int rvc_rs1_regmap[8] = { 20, 21, 2, 3, 4, 5, 6, 7 }; +#define rvc_rd_regmap rvc_rs1_regmap +#define rvc_rs2b_regmap rvc_rs1_regmap +static const int rvc_rs2_regmap[8] = { 20, 21, 2, 3, 4, 5, 6, 0 }; +#define CRDS XPR[rvc_rd_regmap[(insn.bits >> 13) & 0x7]] +#define FCRDS FPR[rvc_rd_regmap[(insn.bits >> 13) & 0x7]] +#define CRS1S XPR[rvc_rs1_regmap[(insn.bits >> 10) & 0x7]] +#define CRS2S XPR[rvc_rs2_regmap[(insn.bits >> 13) & 0x7]] +#define CRS2BS XPR[rvc_rs2b_regmap[(insn.bits >> 5) & 0x7]] +#define FCRS2S FPR[rvc_rs2_regmap[(insn.bits >> 13) & 0x7]] + +// vector stuff +#define VL vl + +#define UT_RS1(idx) uts[idx]->XPR[insn.rtype.rs1] +#define UT_RS2(idx) uts[idx]->XPR[insn.rtype.rs2] +#define UT_RD(idx) do_writeback(uts[idx]->XPR,insn.rtype.rd) +#define UT_RA(idx) do_writeback(uts[idx]->XPR,1) +#define UT_FRS1(idx) uts[idx]->FPR[insn.ftype.rs1] +#define UT_FRS2(idx) uts[idx]->FPR[insn.ftype.rs2] +#define UT_FRS3(idx) uts[idx]->FPR[insn.ftype.rs3] +#define UT_FRD(idx) uts[idx]->FPR[insn.ftype.rd] +#define UT_RM(idx) ((insn.ftype.rm != 7) ? insn.ftype.rm : \ + ((uts[idx]->fsr & FSR_RD) >> FSR_RD_SHIFT)) + +#define UT_LOOP_START for (int i=0;i +#include +#include +#include +#include + +enum +{ + APP_CMD_READ_MEM, + APP_CMD_WRITE_MEM, + APP_CMD_READ_CONTROL_REG, + APP_CMD_WRITE_CONTROL_REG, + APP_CMD_START, + APP_CMD_STOP, + APP_CMD_ACK, + APP_CMD_NACK +}; + +#define APP_DATA_ALIGN 8 +#define APP_MAX_DATA_SIZE 1024 +struct packet +{ + uint16_t cmd; + uint16_t seqno; + uint32_t data_size; + uint64_t addr; + uint8_t data[APP_MAX_DATA_SIZE]; +}; + +htif_t::htif_t(int _tohost_fd, int _fromhost_fd) + : sim(NULL), tohost_fd(_tohost_fd), fromhost_fd(_fromhost_fd), seqno(1) +{ +} + +htif_t::~htif_t() +{ + close(tohost_fd); + close(fromhost_fd); +} + +void htif_t::init(sim_t* _sim) +{ + sim = _sim; +} + +void htif_t::wait_for_start() +{ + while(wait_for_packet() != APP_CMD_START); +} + +void htif_t::wait_for_fromhost_write() +{ + while(wait_for_packet() != APP_CMD_WRITE_CONTROL_REG); +} + +void htif_t::send_packet(packet* p) +{ + int bytes = write(tohost_fd,p,offsetof(packet,data)+p->data_size); + if((size_t)bytes != offsetof(packet,data) + p->data_size) + { + const char* error = bytes == -1 ? strerror(errno) : "not all bytes sent"; + fprintf(stderr,"HTIF error: %s\n", error); + exit(-1); + } +} + +void htif_t::nack(uint16_t nack_seqno) +{ + packet p = {APP_CMD_NACK,nack_seqno,0,0}; + send_packet(&p); +} + +int htif_t::wait_for_packet() +{ + while(1) + { + packet p; + int bytes = read(fromhost_fd,&p,sizeof(p)); + if(bytes < (int)offsetof(packet,data)) + { + const char* error = bytes == -1 ? strerror(errno) : "too few bytes read"; + fprintf(stderr,"HTIF error: %s\n", error); + exit(-1); + } + + if(p.seqno != seqno) + { + nack(p.seqno); + continue; + } + + packet ackpacket = {APP_CMD_ACK,seqno,0,0}; + + switch(p.cmd) + { + case APP_CMD_START: + break; + case APP_CMD_STOP: + sim->stop(); + break; + case APP_CMD_READ_MEM: + assert(p.addr % APP_DATA_ALIGN == 0); + assert(p.data_size % APP_DATA_ALIGN == 0); + assert(p.data_size <= APP_MAX_DATA_SIZE); + assert(p.addr <= sim->memsz && p.addr+p.data_size <= sim->memsz); + ackpacket.data_size = p.data_size; + + static_assert(APP_DATA_ALIGN >= sizeof(uint64_t)) + for(size_t i = 0; i < p.data_size/8; i++) + ((uint64_t*)ackpacket.data)[i] = sim->mmu->load_uint64(p.addr+i*8); + break; + case APP_CMD_WRITE_MEM: + assert(p.addr % APP_DATA_ALIGN == 0); + assert(p.data_size % APP_DATA_ALIGN == 0); + assert(p.data_size <= bytes - offsetof(packet,data)); + assert(p.addr <= sim->memsz && p.addr+p.data_size <= sim->memsz); + + for(size_t i = 0; i < p.data_size/8; i++) + sim->mmu->store_uint64(p.addr+i*8, ((uint64_t*)p.data)[i]); + break; + case APP_CMD_READ_CONTROL_REG: + assert(p.addr == 16); + assert(p.data_size == sizeof(reg_t)); + ackpacket.data_size = sizeof(reg_t); + memcpy(ackpacket.data,&sim->tohost,sizeof(reg_t)); + break; + case APP_CMD_WRITE_CONTROL_REG: + assert(p.addr == 17); + assert(p.data_size == sizeof(reg_t)); + sim->tohost = 0; + memcpy(&sim->fromhost,p.data,sizeof(reg_t)); + break; + } + + send_packet(&ackpacket); + seqno++; + return p.cmd; + } +} + diff --git a/riscv/htif.h b/riscv/htif.h new file mode 100644 index 0000000..0106695 --- /dev/null +++ b/riscv/htif.h @@ -0,0 +1,35 @@ +#ifndef _HTIF_H +#define _HTIF_H + +#include + +class sim_t; +struct packet; + +// this class implements the host-target interface for program loading, etc. +class htif_t +{ +public: + htif_t(int _tohost_fd, int _fromhost_fd); + ~htif_t(); + void init(sim_t* _sim); + + // wait for host to send start command + void wait_for_start(); + + // we block on the host if the target machine reads the fromhost register, + // which provides determinism in tohost/fromhost communication. + void wait_for_fromhost_write(); + +private: + sim_t* sim; + int tohost_fd; + int fromhost_fd; + uint16_t seqno; + + void nack(uint16_t seqno); + void send_packet(packet* p); + int wait_for_packet(); +}; + +#endif diff --git a/riscv/icsim.cc b/riscv/icsim.cc new file mode 100644 index 0000000..308e7ed --- /dev/null +++ b/riscv/icsim.cc @@ -0,0 +1,100 @@ +#include "icsim.h" +#include +#include +#include + +icsim_t::icsim_t(size_t _sets, size_t _ways, size_t _linesz, const char* _name) + : sets(_sets), ways(_ways), linesz(_linesz), idx_mask(_sets-1), name(_name) +{ + if(sets == 0 || (sets & (sets-1))) + throw std::logic_error("sets not a power of 2"); + if(linesz == 0 || (linesz & (linesz-1))) + throw std::logic_error("linesz not a power of 2"); + + idx_shift = 0; + while(_linesz >>= 1) + idx_shift++; + + tags = new uint64_t[sets*ways]; + memset(tags, 0, sets*ways*sizeof(uint64_t)); + + read_accesses = 0; + read_misses = 0; + bytes_read = 0; + write_accesses = 0; + write_misses = 0; + bytes_written = 0; + writebacks = 0; +} + +icsim_t::icsim_t(const icsim_t& rhs) + : sets(rhs.sets), ways(rhs.ways), linesz(rhs.linesz), + idx_shift(rhs.idx_shift), idx_mask(rhs.idx_mask), name(rhs.name) +{ + tags = new uint64_t[sets*ways]; + memcpy(tags, rhs.tags, sets*ways*sizeof(uint64_t)); +} + +icsim_t::~icsim_t() +{ + delete [] tags; +} + +void icsim_t::print_stats() +{ + if(read_accesses + write_accesses == 0) + return; + + float mr = 100.0f*(read_misses+write_misses)/(read_accesses+write_accesses); + + std::cout << std::setprecision(3) << std::fixed; + std::cout << name << " "; + std::cout << "Bytes Read: " << bytes_read << std::endl; + std::cout << name << " "; + std::cout << "Bytes Written: " << bytes_written << std::endl; + std::cout << name << " "; + std::cout << "Read Accesses: " << read_accesses << std::endl; + std::cout << name << " "; + std::cout << "Write Accesses: " << write_accesses << std::endl; + std::cout << name << " "; + std::cout << "Read Misses: " << read_misses << std::endl; + std::cout << name << " "; + std::cout << "Write Misses: " << write_misses << std::endl; + std::cout << name << " "; + std::cout << "Writebacks: " << writebacks << std::endl; + std::cout << name << " "; + std::cout << "Miss Rate: " << mr << '%' << std::endl; + + float cr = read_accesses == 0 ? 0.0f : 100.0f*bytes_read/(4*read_accesses); + if(name == "I$") + { + std::cout << name << " "; + std::cout << "RVC compression ratio: " << cr << '%' << std::endl; + } +} + +void icsim_t::tick(uint64_t pc, int insnlen, bool store) +{ + store ? write_accesses++ : read_accesses++; + (store ? bytes_written : bytes_read) += insnlen; + + size_t idx = (pc >> idx_shift) & idx_mask; + size_t tag = (pc >> idx_shift) | VALID; + + for(size_t i = 0; i < ways; i++) + { + if(tag == (tags[idx + i*sets] & ~DIRTY)) // hit + { + if(store) + tags[idx + i*sets] |= DIRTY; + return; + } + } + + store ? write_misses++ : read_misses++; + + size_t way = lfsr.next() % ways; + if((tags[idx + way*sets] & (VALID | DIRTY)) == (VALID | DIRTY)) + writebacks++; + tags[idx + way*sets] = tag; +} diff --git a/riscv/icsim.h b/riscv/icsim.h new file mode 100644 index 0000000..ec6eae4 --- /dev/null +++ b/riscv/icsim.h @@ -0,0 +1,55 @@ +#ifndef _RISCV_ICSIM_H +#define _RISCV_ICSIM_H + +// this file models a simple cache to estimate hit/miss rates. +// it is currently unused. + +#include +#include +#include + +class lfsr_t +{ +public: + lfsr_t() : reg(1) {} + lfsr_t(const lfsr_t& lfsr) : reg(lfsr.reg) {} + uint32_t next() { return reg = (reg>>1)^(-(reg&1) & 0xd0000001); } +private: + uint32_t reg; +}; + +class icsim_t +{ +public: + icsim_t(size_t sets, size_t ways, size_t linesz, const char* name); + icsim_t(const icsim_t& rhs); + ~icsim_t(); + + void tick(uint64_t pc, int insnlen, bool store); + void print_stats(); +private: + lfsr_t lfsr; + + size_t sets; + size_t ways; + size_t linesz; + size_t idx_shift; + size_t idx_mask; + + uint64_t* tags; + + uint64_t read_accesses; + uint64_t read_misses; + uint64_t bytes_read; + uint64_t write_accesses; + uint64_t write_misses; + uint64_t bytes_written; + uint64_t writebacks; + + std::string name; + + static const uint64_t VALID = 1ULL << 63; + static const uint64_t DIRTY = 1ULL << 62; +}; + +#endif diff --git a/riscv/insn_header.h b/riscv/insn_header.h new file mode 100644 index 0000000..9ea3586 --- /dev/null +++ b/riscv/insn_header.h @@ -0,0 +1,7 @@ +#include "processor.h" +#include "config.h" +#include "sim.h" +#include "softfloat.h" +#include "platform.h" // softfloat isNaNF32UI, etc. +#include "internals.h" // ditto +#include diff --git a/riscv/insns/add.h b/riscv/insns/add.h new file mode 100644 index 0000000..34d49ff --- /dev/null +++ b/riscv/insns/add.h @@ -0,0 +1 @@ +RD = sext_xprlen(RS1 + RS2); diff --git a/riscv/insns/addi.h b/riscv/insns/addi.h new file mode 100644 index 0000000..88881e5 --- /dev/null +++ b/riscv/insns/addi.h @@ -0,0 +1 @@ +RD = sext_xprlen(RS1 + SIMM); diff --git a/riscv/insns/addiw.h b/riscv/insns/addiw.h new file mode 100644 index 0000000..23ae278 --- /dev/null +++ b/riscv/insns/addiw.h @@ -0,0 +1,2 @@ +require_xpr64; +RD = sext32(SIMM + RS1); diff --git a/riscv/insns/addw.h b/riscv/insns/addw.h new file mode 100644 index 0000000..4e2ed56 --- /dev/null +++ b/riscv/insns/addw.h @@ -0,0 +1,2 @@ +require_xpr64; +RD = sext32(RS1 + RS2); diff --git a/riscv/insns/amoadd_d.h b/riscv/insns/amoadd_d.h new file mode 100644 index 0000000..b8450bf --- /dev/null +++ b/riscv/insns/amoadd_d.h @@ -0,0 +1,4 @@ +require_xpr64; +reg_t v = mmu.load_uint64(RS1); +mmu.store_uint64(RS1, RS2 + v); +RD = v; diff --git a/riscv/insns/amoadd_w.h b/riscv/insns/amoadd_w.h new file mode 100644 index 0000000..033b3c8 --- /dev/null +++ b/riscv/insns/amoadd_w.h @@ -0,0 +1,3 @@ +reg_t v = mmu.load_int32(RS1); +mmu.store_uint32(RS1, RS2 + v); +RD = v; diff --git a/riscv/insns/amoand_d.h b/riscv/insns/amoand_d.h new file mode 100644 index 0000000..586eb7f --- /dev/null +++ b/riscv/insns/amoand_d.h @@ -0,0 +1,4 @@ +require_xpr64; +reg_t v = mmu.load_uint64(RS1); +mmu.store_uint64(RS1, RS2 & v); +RD = v; diff --git a/riscv/insns/amoand_w.h b/riscv/insns/amoand_w.h new file mode 100644 index 0000000..18a9249 --- /dev/null +++ b/riscv/insns/amoand_w.h @@ -0,0 +1,3 @@ +reg_t v = mmu.load_int32(RS1); +mmu.store_uint32(RS1, RS2 & v); +RD = v; diff --git a/riscv/insns/amomax_d.h b/riscv/insns/amomax_d.h new file mode 100644 index 0000000..1a0bc8a --- /dev/null +++ b/riscv/insns/amomax_d.h @@ -0,0 +1,4 @@ +require_xpr64; +sreg_t v = mmu.load_int64(RS1); +mmu.store_uint64(RS1, std::max(sreg_t(RS2),v)); +RD = v; diff --git a/riscv/insns/amomax_w.h b/riscv/insns/amomax_w.h new file mode 100644 index 0000000..ff9c2da --- /dev/null +++ b/riscv/insns/amomax_w.h @@ -0,0 +1,3 @@ +int32_t v = mmu.load_int32(RS1); +mmu.store_uint32(RS1, std::max(int32_t(RS2),v)); +RD = v; diff --git a/riscv/insns/amomaxu_d.h b/riscv/insns/amomaxu_d.h new file mode 100644 index 0000000..ccfaf1d --- /dev/null +++ b/riscv/insns/amomaxu_d.h @@ -0,0 +1,4 @@ +require_xpr64; +reg_t v = mmu.load_uint64(RS1); +mmu.store_uint64(RS1, std::max(RS2,v)); +RD = v; diff --git a/riscv/insns/amomaxu_w.h b/riscv/insns/amomaxu_w.h new file mode 100644 index 0000000..075847d --- /dev/null +++ b/riscv/insns/amomaxu_w.h @@ -0,0 +1,3 @@ +uint32_t v = mmu.load_int32(RS1); +mmu.store_uint32(RS1, std::max(uint32_t(RS2),v)); +RD = (int32_t)v; diff --git a/riscv/insns/amomin_d.h b/riscv/insns/amomin_d.h new file mode 100644 index 0000000..4f3b6d6 --- /dev/null +++ b/riscv/insns/amomin_d.h @@ -0,0 +1,4 @@ +require_xpr64; +sreg_t v = mmu.load_int64(RS1); +mmu.store_uint64(RS1, std::min(sreg_t(RS2),v)); +RD = v; diff --git a/riscv/insns/amomin_w.h b/riscv/insns/amomin_w.h new file mode 100644 index 0000000..529ad50 --- /dev/null +++ b/riscv/insns/amomin_w.h @@ -0,0 +1,3 @@ +int32_t v = mmu.load_int32(RS1); +mmu.store_uint32(RS1, std::min(int32_t(RS2),v)); +RD = v; diff --git a/riscv/insns/amominu_d.h b/riscv/insns/amominu_d.h new file mode 100644 index 0000000..c09c51a --- /dev/null +++ b/riscv/insns/amominu_d.h @@ -0,0 +1,4 @@ +require_xpr64; +reg_t v = mmu.load_uint64(RS1); +mmu.store_uint64(RS1, std::min(RS2,v)); +RD = v; diff --git a/riscv/insns/amominu_w.h b/riscv/insns/amominu_w.h new file mode 100644 index 0000000..d8d6377 --- /dev/null +++ b/riscv/insns/amominu_w.h @@ -0,0 +1,3 @@ +uint32_t v = mmu.load_int32(RS1); +mmu.store_uint32(RS1, std::min(uint32_t(RS2),v)); +RD = (int32_t)v; diff --git a/riscv/insns/amoor_d.h b/riscv/insns/amoor_d.h new file mode 100644 index 0000000..76a4508 --- /dev/null +++ b/riscv/insns/amoor_d.h @@ -0,0 +1,4 @@ +require_xpr64; +reg_t v = mmu.load_uint64(RS1); +mmu.store_uint64(RS1, RS2 | v); +RD = v; diff --git a/riscv/insns/amoor_w.h b/riscv/insns/amoor_w.h new file mode 100644 index 0000000..741fbef --- /dev/null +++ b/riscv/insns/amoor_w.h @@ -0,0 +1,3 @@ +reg_t v = mmu.load_int32(RS1); +mmu.store_uint32(RS1, RS2 | v); +RD = v; diff --git a/riscv/insns/amoswap_d.h b/riscv/insns/amoswap_d.h new file mode 100644 index 0000000..43e3538 --- /dev/null +++ b/riscv/insns/amoswap_d.h @@ -0,0 +1,4 @@ +require_xpr64; +reg_t v = mmu.load_uint64(RS1); +mmu.store_uint64(RS1, RS2); +RD = v; diff --git a/riscv/insns/amoswap_w.h b/riscv/insns/amoswap_w.h new file mode 100644 index 0000000..30e6102 --- /dev/null +++ b/riscv/insns/amoswap_w.h @@ -0,0 +1,3 @@ +reg_t v = mmu.load_int32(RS1); +mmu.store_uint32(RS1, RS2); +RD = v; diff --git a/riscv/insns/and.h b/riscv/insns/and.h new file mode 100644 index 0000000..88ac1d8 --- /dev/null +++ b/riscv/insns/and.h @@ -0,0 +1 @@ +RD = RS1 & RS2; diff --git a/riscv/insns/andi.h b/riscv/insns/andi.h new file mode 100644 index 0000000..5caea16 --- /dev/null +++ b/riscv/insns/andi.h @@ -0,0 +1 @@ +RD = SIMM & RS1; diff --git a/riscv/insns/beq.h b/riscv/insns/beq.h new file mode 100644 index 0000000..7b26488 --- /dev/null +++ b/riscv/insns/beq.h @@ -0,0 +1,2 @@ +if(cmp_trunc(RS1) == cmp_trunc(RS2)) + set_pc(BRANCH_TARGET); diff --git a/riscv/insns/bge.h b/riscv/insns/bge.h new file mode 100644 index 0000000..dca544b --- /dev/null +++ b/riscv/insns/bge.h @@ -0,0 +1,2 @@ +if(sreg_t(cmp_trunc(RS1)) >= sreg_t(cmp_trunc(RS2))) + set_pc(BRANCH_TARGET); diff --git a/riscv/insns/bgeu.h b/riscv/insns/bgeu.h new file mode 100644 index 0000000..6325466 --- /dev/null +++ b/riscv/insns/bgeu.h @@ -0,0 +1,2 @@ +if(cmp_trunc(RS1) >= cmp_trunc(RS2)) + set_pc(BRANCH_TARGET); diff --git a/riscv/insns/blt.h b/riscv/insns/blt.h new file mode 100644 index 0000000..d84fd7a --- /dev/null +++ b/riscv/insns/blt.h @@ -0,0 +1,2 @@ +if(sreg_t(cmp_trunc(RS1)) < sreg_t(cmp_trunc(RS2))) + set_pc(BRANCH_TARGET); diff --git a/riscv/insns/bltu.h b/riscv/insns/bltu.h new file mode 100644 index 0000000..250fd4f --- /dev/null +++ b/riscv/insns/bltu.h @@ -0,0 +1,2 @@ +if(cmp_trunc(RS1) < cmp_trunc(RS2)) + set_pc(BRANCH_TARGET); diff --git a/riscv/insns/bne.h b/riscv/insns/bne.h new file mode 100644 index 0000000..f775721 --- /dev/null +++ b/riscv/insns/bne.h @@ -0,0 +1,2 @@ +if(cmp_trunc(RS1) != cmp_trunc(RS2)) + set_pc(BRANCH_TARGET); diff --git a/riscv/insns/break.h b/riscv/insns/break.h new file mode 100644 index 0000000..7fd3d66 --- /dev/null +++ b/riscv/insns/break.h @@ -0,0 +1 @@ +throw trap_breakpoint; diff --git a/riscv/insns/c_add.h b/riscv/insns/c_add.h new file mode 100644 index 0000000..2170d69 --- /dev/null +++ b/riscv/insns/c_add.h @@ -0,0 +1,2 @@ +require_rvc; +CRD = CRS1 + CRS2; diff --git a/riscv/insns/c_add3.h b/riscv/insns/c_add3.h new file mode 100644 index 0000000..914c85d --- /dev/null +++ b/riscv/insns/c_add3.h @@ -0,0 +1,2 @@ +require_rvc; +CRDS = CRS1S + CRS2BS; diff --git a/riscv/insns/c_addi.h b/riscv/insns/c_addi.h new file mode 100644 index 0000000..448e31a --- /dev/null +++ b/riscv/insns/c_addi.h @@ -0,0 +1,10 @@ +require_rvc; +if(CRD_REGNUM == 0) +{ + reg_t temp = CRS1; + if(CIMM6 & 0x20) + RA = npc; + set_pc(temp); +} +else + CRD = sext_xprlen(CRS2 + CIMM6); diff --git a/riscv/insns/c_addiw.h b/riscv/insns/c_addiw.h new file mode 100644 index 0000000..6a1e0a3 --- /dev/null +++ b/riscv/insns/c_addiw.h @@ -0,0 +1,3 @@ +require_rvc; +require_xpr64; +CRD = sext32(CRS2 + CIMM6); diff --git a/riscv/insns/c_and3.h b/riscv/insns/c_and3.h new file mode 100644 index 0000000..b506d6a --- /dev/null +++ b/riscv/insns/c_and3.h @@ -0,0 +1,2 @@ +require_rvc; +CRDS = CRS1S & CRS2BS; diff --git a/riscv/insns/c_beq.h b/riscv/insns/c_beq.h new file mode 100644 index 0000000..031d96d --- /dev/null +++ b/riscv/insns/c_beq.h @@ -0,0 +1,3 @@ +require_rvc; +if(cmp_trunc(CRS1S) == cmp_trunc(CRS2S)) + set_pc(CBRANCH_TARGET); diff --git a/riscv/insns/c_bne.h b/riscv/insns/c_bne.h new file mode 100644 index 0000000..caf9229 --- /dev/null +++ b/riscv/insns/c_bne.h @@ -0,0 +1,3 @@ +require_rvc; +if(cmp_trunc(CRS1S) != cmp_trunc(CRS2S)) + set_pc(CBRANCH_TARGET); diff --git a/riscv/insns/c_fld.h b/riscv/insns/c_fld.h new file mode 100644 index 0000000..a726039 --- /dev/null +++ b/riscv/insns/c_fld.h @@ -0,0 +1,3 @@ +require_rvc; +require_fp; +FCRDS = mmu.load_int64(CRS1S+CIMM5*8); diff --git a/riscv/insns/c_flw.h b/riscv/insns/c_flw.h new file mode 100644 index 0000000..cdb7221 --- /dev/null +++ b/riscv/insns/c_flw.h @@ -0,0 +1,3 @@ +require_rvc; +require_fp; +FCRDS = mmu.load_int32(CRS1S+CIMM5*4); diff --git a/riscv/insns/c_fsd.h b/riscv/insns/c_fsd.h new file mode 100644 index 0000000..20814fd --- /dev/null +++ b/riscv/insns/c_fsd.h @@ -0,0 +1,3 @@ +require_rvc; +require_fp; +mmu.store_uint64(CRS1S+CIMM5*8, FCRS2S); diff --git a/riscv/insns/c_fsw.h b/riscv/insns/c_fsw.h new file mode 100644 index 0000000..1d21629 --- /dev/null +++ b/riscv/insns/c_fsw.h @@ -0,0 +1,3 @@ +require_rvc; +require_fp; +mmu.store_uint32(CRS1S+CIMM5*4, FCRS2S); diff --git a/riscv/insns/c_j.h b/riscv/insns/c_j.h new file mode 100644 index 0000000..5ba9c73 --- /dev/null +++ b/riscv/insns/c_j.h @@ -0,0 +1,2 @@ +require_rvc; +set_pc(CJUMP_TARGET); diff --git a/riscv/insns/c_ld.h b/riscv/insns/c_ld.h new file mode 100644 index 0000000..f9c07af --- /dev/null +++ b/riscv/insns/c_ld.h @@ -0,0 +1,3 @@ +require_rvc; +require_xpr64; +CRDS = mmu.load_int64(CRS1S+CIMM5*8); diff --git a/riscv/insns/c_ld0.h b/riscv/insns/c_ld0.h new file mode 100644 index 0000000..f51a966 --- /dev/null +++ b/riscv/insns/c_ld0.h @@ -0,0 +1,3 @@ +require_rvc; +require_xpr64; +CRD = mmu.load_int64(CRS1); diff --git a/riscv/insns/c_ldsp.h b/riscv/insns/c_ldsp.h new file mode 100644 index 0000000..1fbd9bd --- /dev/null +++ b/riscv/insns/c_ldsp.h @@ -0,0 +1,3 @@ +require_rvc; +require_xpr64; +CRD = mmu.load_int64(XPR[30]+CIMM6*8); diff --git a/riscv/insns/c_li.h b/riscv/insns/c_li.h new file mode 100644 index 0000000..e65614e --- /dev/null +++ b/riscv/insns/c_li.h @@ -0,0 +1,2 @@ +require_rvc; +CRD = CIMM6; diff --git a/riscv/insns/c_lw.h b/riscv/insns/c_lw.h new file mode 100644 index 0000000..4796ab8 --- /dev/null +++ b/riscv/insns/c_lw.h @@ -0,0 +1,2 @@ +require_rvc; +CRDS = mmu.load_int32(CRS1S+CIMM5*4); diff --git a/riscv/insns/c_lw0.h b/riscv/insns/c_lw0.h new file mode 100644 index 0000000..d263a80 --- /dev/null +++ b/riscv/insns/c_lw0.h @@ -0,0 +1,2 @@ +require_rvc; +CRD = mmu.load_int32(CRS1); diff --git a/riscv/insns/c_lwsp.h b/riscv/insns/c_lwsp.h new file mode 100644 index 0000000..318342a --- /dev/null +++ b/riscv/insns/c_lwsp.h @@ -0,0 +1,2 @@ +require_rvc; +CRD = mmu.load_int32(XPR[30]+CIMM6*4); diff --git a/riscv/insns/c_move.h b/riscv/insns/c_move.h new file mode 100644 index 0000000..b0aef33 --- /dev/null +++ b/riscv/insns/c_move.h @@ -0,0 +1,2 @@ +require_rvc; +CRD = CRS1; diff --git a/riscv/insns/c_or3.h b/riscv/insns/c_or3.h new file mode 100644 index 0000000..143e2ae --- /dev/null +++ b/riscv/insns/c_or3.h @@ -0,0 +1,2 @@ +require_rvc; +CRDS = CRS1S | CRS2BS; diff --git a/riscv/insns/c_sd.h b/riscv/insns/c_sd.h new file mode 100644 index 0000000..b2eb456 --- /dev/null +++ b/riscv/insns/c_sd.h @@ -0,0 +1,3 @@ +require_rvc; +require_xpr64; +mmu.store_uint64(CRS1S+CIMM5*8, CRS2S); diff --git a/riscv/insns/c_sdsp.h b/riscv/insns/c_sdsp.h new file mode 100644 index 0000000..ca97d51 --- /dev/null +++ b/riscv/insns/c_sdsp.h @@ -0,0 +1,3 @@ +require_rvc; +require_xpr64; +mmu.store_uint64(XPR[30]+CIMM6*8, CRS2); diff --git a/riscv/insns/c_slli.h b/riscv/insns/c_slli.h new file mode 100644 index 0000000..5026767 --- /dev/null +++ b/riscv/insns/c_slli.h @@ -0,0 +1,5 @@ +require_rvc; +if(xpr64) + CRDS = CRDS << CIMM5U; +else + CRDS = sext32(CRDS << CIMM5U); diff --git a/riscv/insns/c_slli32.h b/riscv/insns/c_slli32.h new file mode 100644 index 0000000..1e3e958 --- /dev/null +++ b/riscv/insns/c_slli32.h @@ -0,0 +1,3 @@ +require_rvc; +require_xpr64; +CRDS = CRDS << (32+CIMM5U); diff --git a/riscv/insns/c_slliw.h b/riscv/insns/c_slliw.h new file mode 100644 index 0000000..9e428f5 --- /dev/null +++ b/riscv/insns/c_slliw.h @@ -0,0 +1,3 @@ +require_rvc; +require_xpr64; +CRDS = sext32(CRDS << CIMM5U); diff --git a/riscv/insns/c_srai.h b/riscv/insns/c_srai.h new file mode 100644 index 0000000..aa33424 --- /dev/null +++ b/riscv/insns/c_srai.h @@ -0,0 +1,5 @@ +require_rvc; +if(xpr64) + CRDS = sreg_t(CRDS) >> CIMM5U; +else + CRDS = sext32(int32_t(CRDS) >> CIMM5U); diff --git a/riscv/insns/c_srai32.h b/riscv/insns/c_srai32.h new file mode 100644 index 0000000..ca7b024 --- /dev/null +++ b/riscv/insns/c_srai32.h @@ -0,0 +1,3 @@ +require_rvc; +require_xpr64; +CRDS = sreg_t(CRDS) >> (32+CIMM5U); diff --git a/riscv/insns/c_srli.h b/riscv/insns/c_srli.h new file mode 100644 index 0000000..56e0681 --- /dev/null +++ b/riscv/insns/c_srli.h @@ -0,0 +1,5 @@ +require_rvc; +if(xpr64) + CRDS = CRDS >> CIMM5U; +else + CRDS = sext32(uint32_t(CRDS) >> CIMM5U); diff --git a/riscv/insns/c_srli32.h b/riscv/insns/c_srli32.h new file mode 100644 index 0000000..4f5b8ea --- /dev/null +++ b/riscv/insns/c_srli32.h @@ -0,0 +1,3 @@ +require_rvc; +require_xpr64; +CRDS = CRDS >> (32+CIMM5U); diff --git a/riscv/insns/c_sub.h b/riscv/insns/c_sub.h new file mode 100644 index 0000000..9fd8932 --- /dev/null +++ b/riscv/insns/c_sub.h @@ -0,0 +1,2 @@ +require_rvc; +CRD = CRS1 - CRS2; diff --git a/riscv/insns/c_sub3.h b/riscv/insns/c_sub3.h new file mode 100644 index 0000000..53afc84 --- /dev/null +++ b/riscv/insns/c_sub3.h @@ -0,0 +1,2 @@ +require_rvc; +CRDS = CRS1S - CRS2BS; diff --git a/riscv/insns/c_sw.h b/riscv/insns/c_sw.h new file mode 100644 index 0000000..f604adf --- /dev/null +++ b/riscv/insns/c_sw.h @@ -0,0 +1,2 @@ +require_rvc; +mmu.store_uint32(CRS1S+CIMM5*4, CRS2S); diff --git a/riscv/insns/c_swsp.h b/riscv/insns/c_swsp.h new file mode 100644 index 0000000..0508f12 --- /dev/null +++ b/riscv/insns/c_swsp.h @@ -0,0 +1,2 @@ +require_rvc; +mmu.store_uint32(XPR[30]+CIMM6*4, CRS2); diff --git a/riscv/insns/cflush.h b/riscv/insns/cflush.h new file mode 100644 index 0000000..5117ca0 --- /dev/null +++ b/riscv/insns/cflush.h @@ -0,0 +1 @@ +require_supervisor; diff --git a/riscv/insns/di.h b/riscv/insns/di.h new file mode 100644 index 0000000..31280d5 --- /dev/null +++ b/riscv/insns/di.h @@ -0,0 +1,4 @@ +require_supervisor; +uint32_t temp = sr; +set_sr(sr & ~SR_ET); +RD = temp; diff --git a/riscv/insns/div.h b/riscv/insns/div.h new file mode 100644 index 0000000..82a4066 --- /dev/null +++ b/riscv/insns/div.h @@ -0,0 +1,6 @@ +if(RS2 == 0) + RD = UINT64_MAX; +else if(sreg_t(RS1) == INT64_MIN && sreg_t(RS2) == -1) + RD = RS1; +else + RD = sext_xprlen(sext_xprlen(RS1) / sext_xprlen(RS2)); diff --git a/riscv/insns/divu.h b/riscv/insns/divu.h new file mode 100644 index 0000000..681afd2 --- /dev/null +++ b/riscv/insns/divu.h @@ -0,0 +1,4 @@ +if(RS2 == 0) + RD = UINT64_MAX; +else + RD = sext_xprlen(zext_xprlen(RS1) / zext_xprlen(RS2)); diff --git a/riscv/insns/divuw.h b/riscv/insns/divuw.h new file mode 100644 index 0000000..0ceb040 --- /dev/null +++ b/riscv/insns/divuw.h @@ -0,0 +1,5 @@ +require_xpr64; +if(RS2 == 0) + RD = UINT64_MAX; +else + RD = sext32(zext32(RS1) / zext32(RS2)); diff --git a/riscv/insns/divw.h b/riscv/insns/divw.h new file mode 100644 index 0000000..51c3d80 --- /dev/null +++ b/riscv/insns/divw.h @@ -0,0 +1,7 @@ +require_xpr64; +if(RS2 == 0) + RD = UINT64_MAX; +else if(int32_t(RS1) == INT32_MIN && int32_t(RS2) == -1) + RD = RS1; +else + RD = sext32(int32_t(RS1) / int32_t(RS2)); diff --git a/riscv/insns/ei.h b/riscv/insns/ei.h new file mode 100644 index 0000000..8306aeb --- /dev/null +++ b/riscv/insns/ei.h @@ -0,0 +1,4 @@ +require_supervisor; +uint32_t temp = sr; +set_sr(sr | SR_ET); +RD = temp; diff --git a/riscv/insns/eret.h b/riscv/insns/eret.h new file mode 100644 index 0000000..46d5bed --- /dev/null +++ b/riscv/insns/eret.h @@ -0,0 +1,5 @@ +require_supervisor; +if(sr & SR_ET) + throw trap_illegal_instruction; +set_sr(((sr & SR_PS) ? sr : (sr & ~SR_S)) | SR_ET); +set_pc(epc); diff --git a/riscv/insns/fadd_d.h b/riscv/insns/fadd_d.h new file mode 100644 index 0000000..48c76a7 --- /dev/null +++ b/riscv/insns/fadd_d.h @@ -0,0 +1,4 @@ +require_fp; +softfloat_roundingMode = RM; +FRD = f64_add(FRS1, FRS2); +set_fp_exceptions; diff --git a/riscv/insns/fadd_s.h b/riscv/insns/fadd_s.h new file mode 100644 index 0000000..2fd5429 --- /dev/null +++ b/riscv/insns/fadd_s.h @@ -0,0 +1,4 @@ +require_fp; +softfloat_roundingMode = RM; +FRD = f32_add(FRS1, FRS2); +set_fp_exceptions; diff --git a/riscv/insns/fcvt_d_l.h b/riscv/insns/fcvt_d_l.h new file mode 100644 index 0000000..68c0482 --- /dev/null +++ b/riscv/insns/fcvt_d_l.h @@ -0,0 +1,5 @@ +require_xpr64; +require_fp; +softfloat_roundingMode = RM; +FRD = i64_to_f64(RS1); +set_fp_exceptions; diff --git a/riscv/insns/fcvt_d_lu.h b/riscv/insns/fcvt_d_lu.h new file mode 100644 index 0000000..2032758 --- /dev/null +++ b/riscv/insns/fcvt_d_lu.h @@ -0,0 +1,5 @@ +require_xpr64; +require_fp; +softfloat_roundingMode = RM; +FRD = ui64_to_f64(RS1); +set_fp_exceptions; diff --git a/riscv/insns/fcvt_d_s.h b/riscv/insns/fcvt_d_s.h new file mode 100644 index 0000000..6b1a09c --- /dev/null +++ b/riscv/insns/fcvt_d_s.h @@ -0,0 +1,4 @@ +require_fp; +softfloat_roundingMode = RM; +FRD = f32_to_f64(FRS1); +set_fp_exceptions; diff --git a/riscv/insns/fcvt_d_w.h b/riscv/insns/fcvt_d_w.h new file mode 100644 index 0000000..52abd75 --- /dev/null +++ b/riscv/insns/fcvt_d_w.h @@ -0,0 +1,4 @@ +require_fp; +softfloat_roundingMode = RM; +FRD = i32_to_f64((int32_t)RS1); +set_fp_exceptions; diff --git a/riscv/insns/fcvt_d_wu.h b/riscv/insns/fcvt_d_wu.h new file mode 100644 index 0000000..61a8a78 --- /dev/null +++ b/riscv/insns/fcvt_d_wu.h @@ -0,0 +1,4 @@ +require_fp; +softfloat_roundingMode = RM; +FRD = ui32_to_f64((uint32_t)RS1); +set_fp_exceptions; diff --git a/riscv/insns/fcvt_l_d.h b/riscv/insns/fcvt_l_d.h new file mode 100644 index 0000000..206ba4f --- /dev/null +++ b/riscv/insns/fcvt_l_d.h @@ -0,0 +1,5 @@ +require_xpr64; +require_fp; +softfloat_roundingMode = RM; +RD = f64_to_i64(FRS1, RM, true); +set_fp_exceptions; diff --git a/riscv/insns/fcvt_l_s.h b/riscv/insns/fcvt_l_s.h new file mode 100644 index 0000000..e05f476 --- /dev/null +++ b/riscv/insns/fcvt_l_s.h @@ -0,0 +1,5 @@ +require_xpr64; +require_fp; +softfloat_roundingMode = RM; +RD = f32_to_i64(FRS1, RM, true); +set_fp_exceptions; diff --git a/riscv/insns/fcvt_lu_d.h b/riscv/insns/fcvt_lu_d.h new file mode 100644 index 0000000..44c3dd6 --- /dev/null +++ b/riscv/insns/fcvt_lu_d.h @@ -0,0 +1,5 @@ +require_xpr64; +require_fp; +softfloat_roundingMode = RM; +RD = f64_to_ui64(FRS1, RM, true); +set_fp_exceptions; diff --git a/riscv/insns/fcvt_lu_s.h b/riscv/insns/fcvt_lu_s.h new file mode 100644 index 0000000..13de436 --- /dev/null +++ b/riscv/insns/fcvt_lu_s.h @@ -0,0 +1,5 @@ +require_xpr64; +require_fp; +softfloat_roundingMode = RM; +RD = f32_to_ui64(FRS1, RM, true); +set_fp_exceptions; diff --git a/riscv/insns/fcvt_s_d.h b/riscv/insns/fcvt_s_d.h new file mode 100644 index 0000000..e5289c4 --- /dev/null +++ b/riscv/insns/fcvt_s_d.h @@ -0,0 +1,4 @@ +require_fp; +softfloat_roundingMode = RM; +FRD = f64_to_f32(FRS1); +set_fp_exceptions; diff --git a/riscv/insns/fcvt_s_l.h b/riscv/insns/fcvt_s_l.h new file mode 100644 index 0000000..f149229 --- /dev/null +++ b/riscv/insns/fcvt_s_l.h @@ -0,0 +1,5 @@ +require_xpr64; +require_fp; +softfloat_roundingMode = RM; +FRD = i64_to_f32(RS1); +set_fp_exceptions; diff --git a/riscv/insns/fcvt_s_lu.h b/riscv/insns/fcvt_s_lu.h new file mode 100644 index 0000000..d9d0946 --- /dev/null +++ b/riscv/insns/fcvt_s_lu.h @@ -0,0 +1,5 @@ +require_xpr64; +require_fp; +softfloat_roundingMode = RM; +FRD = ui64_to_f32(RS1); +set_fp_exceptions; diff --git a/riscv/insns/fcvt_s_w.h b/riscv/insns/fcvt_s_w.h new file mode 100644 index 0000000..dedebb5 --- /dev/null +++ b/riscv/insns/fcvt_s_w.h @@ -0,0 +1,4 @@ +require_fp; +softfloat_roundingMode = RM; +FRD = i32_to_f32((int32_t)RS1); +set_fp_exceptions; diff --git a/riscv/insns/fcvt_s_wu.h b/riscv/insns/fcvt_s_wu.h new file mode 100644 index 0000000..abb782c --- /dev/null +++ b/riscv/insns/fcvt_s_wu.h @@ -0,0 +1,4 @@ +require_fp; +softfloat_roundingMode = RM; +FRD = ui32_to_f32((uint32_t)RS1); +set_fp_exceptions; diff --git a/riscv/insns/fcvt_w_d.h b/riscv/insns/fcvt_w_d.h new file mode 100644 index 0000000..88dc3d3 --- /dev/null +++ b/riscv/insns/fcvt_w_d.h @@ -0,0 +1,4 @@ +require_fp; +softfloat_roundingMode = RM; +RD = sext32(f64_to_i32(FRS1, RM, true)); +set_fp_exceptions; diff --git a/riscv/insns/fcvt_w_s.h b/riscv/insns/fcvt_w_s.h new file mode 100644 index 0000000..f14cc19 --- /dev/null +++ b/riscv/insns/fcvt_w_s.h @@ -0,0 +1,4 @@ +require_fp; +softfloat_roundingMode = RM; +RD = sext32(f32_to_i32(FRS1, RM, true)); +set_fp_exceptions; diff --git a/riscv/insns/fcvt_wu_d.h b/riscv/insns/fcvt_wu_d.h new file mode 100644 index 0000000..43ad6f6 --- /dev/null +++ b/riscv/insns/fcvt_wu_d.h @@ -0,0 +1,4 @@ +require_fp; +softfloat_roundingMode = RM; +RD = sext32(f64_to_ui32(FRS1, RM, true)); +set_fp_exceptions; diff --git a/riscv/insns/fcvt_wu_s.h b/riscv/insns/fcvt_wu_s.h new file mode 100644 index 0000000..ff7a11c --- /dev/null +++ b/riscv/insns/fcvt_wu_s.h @@ -0,0 +1,4 @@ +require_fp; +softfloat_roundingMode = RM; +RD = sext32(f32_to_ui32(FRS1, RM, true)); +set_fp_exceptions; diff --git a/riscv/insns/fdiv_d.h b/riscv/insns/fdiv_d.h new file mode 100644 index 0000000..aa00c98 --- /dev/null +++ b/riscv/insns/fdiv_d.h @@ -0,0 +1,4 @@ +require_fp; +softfloat_roundingMode = RM; +FRD = f64_div(FRS1, FRS2); +set_fp_exceptions; diff --git a/riscv/insns/fdiv_s.h b/riscv/insns/fdiv_s.h new file mode 100644 index 0000000..8c76587 --- /dev/null +++ b/riscv/insns/fdiv_s.h @@ -0,0 +1,4 @@ +require_fp; +softfloat_roundingMode = RM; +FRD = f32_div(FRS1, FRS2); +set_fp_exceptions; diff --git a/riscv/insns/fence.h b/riscv/insns/fence.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/fence_g_cv.h b/riscv/insns/fence_g_cv.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/fence_g_v.h b/riscv/insns/fence_g_v.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/fence_i.h b/riscv/insns/fence_i.h new file mode 100644 index 0000000..a2dbffe --- /dev/null +++ b/riscv/insns/fence_i.h @@ -0,0 +1 @@ +mmu.flush_icache(); diff --git a/riscv/insns/fence_l_cv.h b/riscv/insns/fence_l_cv.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/fence_l_v.h b/riscv/insns/fence_l_v.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/feq_d.h b/riscv/insns/feq_d.h new file mode 100644 index 0000000..9db8760 --- /dev/null +++ b/riscv/insns/feq_d.h @@ -0,0 +1,3 @@ +require_fp; +RD = f64_eq(FRS1, FRS2); +set_fp_exceptions; diff --git a/riscv/insns/feq_s.h b/riscv/insns/feq_s.h new file mode 100644 index 0000000..658e8f6 --- /dev/null +++ b/riscv/insns/feq_s.h @@ -0,0 +1,3 @@ +require_fp; +RD = f32_eq(FRS1, FRS2); +set_fp_exceptions; diff --git a/riscv/insns/fld.h b/riscv/insns/fld.h new file mode 100644 index 0000000..123dea4 --- /dev/null +++ b/riscv/insns/fld.h @@ -0,0 +1,2 @@ +require_fp; +FRD = mmu.load_int64(RS1+SIMM); diff --git a/riscv/insns/fle_d.h b/riscv/insns/fle_d.h new file mode 100644 index 0000000..da76187 --- /dev/null +++ b/riscv/insns/fle_d.h @@ -0,0 +1,3 @@ +require_fp; +RD = f64_le(FRS1, FRS2); +set_fp_exceptions; diff --git a/riscv/insns/fle_s.h b/riscv/insns/fle_s.h new file mode 100644 index 0000000..9c83a17 --- /dev/null +++ b/riscv/insns/fle_s.h @@ -0,0 +1,3 @@ +require_fp; +RD = f32_le(FRS1, FRS2); +set_fp_exceptions; diff --git a/riscv/insns/flt_d.h b/riscv/insns/flt_d.h new file mode 100644 index 0000000..01d135a --- /dev/null +++ b/riscv/insns/flt_d.h @@ -0,0 +1,3 @@ +require_fp; +RD = f64_lt(FRS1, FRS2); +set_fp_exceptions; diff --git a/riscv/insns/flt_s.h b/riscv/insns/flt_s.h new file mode 100644 index 0000000..52eee5d --- /dev/null +++ b/riscv/insns/flt_s.h @@ -0,0 +1,3 @@ +require_fp; +RD = f32_lt(FRS1, FRS2); +set_fp_exceptions; diff --git a/riscv/insns/flw.h b/riscv/insns/flw.h new file mode 100644 index 0000000..335fd7d --- /dev/null +++ b/riscv/insns/flw.h @@ -0,0 +1,2 @@ +require_fp; +FRD = mmu.load_int32(RS1+SIMM); diff --git a/riscv/insns/fmadd_d.h b/riscv/insns/fmadd_d.h new file mode 100644 index 0000000..f67853e --- /dev/null +++ b/riscv/insns/fmadd_d.h @@ -0,0 +1,4 @@ +require_fp; +softfloat_roundingMode = RM; +FRD = f64_mulAdd(FRS1, FRS2, FRS3); +set_fp_exceptions; diff --git a/riscv/insns/fmadd_s.h b/riscv/insns/fmadd_s.h new file mode 100644 index 0000000..19db642 --- /dev/null +++ b/riscv/insns/fmadd_s.h @@ -0,0 +1,4 @@ +require_fp; +softfloat_roundingMode = RM; +FRD = f32_mulAdd(FRS1, FRS2, FRS3); +set_fp_exceptions; diff --git a/riscv/insns/fmax_d.h b/riscv/insns/fmax_d.h new file mode 100644 index 0000000..cbbb343 --- /dev/null +++ b/riscv/insns/fmax_d.h @@ -0,0 +1,4 @@ +require_fp; +FRD = isNaNF64UI(FRS2) || f64_le_quiet(FRS2,FRS1) /* && FRS1 not NaN */ + ? FRS1 : FRS2; +set_fp_exceptions; diff --git a/riscv/insns/fmax_s.h b/riscv/insns/fmax_s.h new file mode 100644 index 0000000..8df665f --- /dev/null +++ b/riscv/insns/fmax_s.h @@ -0,0 +1,4 @@ +require_fp; +FRD = isNaNF32UI(FRS2) || f32_le_quiet(FRS2,FRS1) /* && FRS1 not NaN */ + ? FRS1 : FRS2; +set_fp_exceptions; diff --git a/riscv/insns/fmin_d.h b/riscv/insns/fmin_d.h new file mode 100644 index 0000000..3d3d454 --- /dev/null +++ b/riscv/insns/fmin_d.h @@ -0,0 +1,4 @@ +require_fp; +FRD = isNaNF64UI(FRS2) || f64_lt_quiet(FRS1,FRS2) /* && FRS1 not NaN */ + ? FRS1 : FRS2; +set_fp_exceptions; diff --git a/riscv/insns/fmin_s.h b/riscv/insns/fmin_s.h new file mode 100644 index 0000000..994c860 --- /dev/null +++ b/riscv/insns/fmin_s.h @@ -0,0 +1,4 @@ +require_fp; +FRD = isNaNF32UI(FRS2) || f32_lt_quiet(FRS1,FRS2) /* && FRS1 not NaN */ + ? FRS1 : FRS2; +set_fp_exceptions; diff --git a/riscv/insns/fmovn.h b/riscv/insns/fmovn.h new file mode 100644 index 0000000..394b56c --- /dev/null +++ b/riscv/insns/fmovn.h @@ -0,0 +1,2 @@ +require_vector; +if (RS1 & 0x1) FRD = FRS2; diff --git a/riscv/insns/fmovz.h b/riscv/insns/fmovz.h new file mode 100644 index 0000000..7862216 --- /dev/null +++ b/riscv/insns/fmovz.h @@ -0,0 +1,2 @@ +require_vector; +if (~RS1 & 0x1) FRD = FRS2; diff --git a/riscv/insns/fmsub_d.h b/riscv/insns/fmsub_d.h new file mode 100644 index 0000000..b1e9340 --- /dev/null +++ b/riscv/insns/fmsub_d.h @@ -0,0 +1,4 @@ +require_fp; +softfloat_roundingMode = RM; +FRD = f64_mulAdd(FRS1, FRS2, FRS3 ^ (uint64_t)INT64_MIN); +set_fp_exceptions; diff --git a/riscv/insns/fmsub_s.h b/riscv/insns/fmsub_s.h new file mode 100644 index 0000000..d3349f5 --- /dev/null +++ b/riscv/insns/fmsub_s.h @@ -0,0 +1,4 @@ +require_fp; +softfloat_roundingMode = RM; +FRD = f32_mulAdd(FRS1, FRS2, FRS3 ^ (uint32_t)INT32_MIN); +set_fp_exceptions; diff --git a/riscv/insns/fmul_d.h b/riscv/insns/fmul_d.h new file mode 100644 index 0000000..a8adedd --- /dev/null +++ b/riscv/insns/fmul_d.h @@ -0,0 +1,4 @@ +require_fp; +softfloat_roundingMode = RM; +FRD = f64_mul(FRS1, FRS2); +set_fp_exceptions; diff --git a/riscv/insns/fmul_s.h b/riscv/insns/fmul_s.h new file mode 100644 index 0000000..6475578 --- /dev/null +++ b/riscv/insns/fmul_s.h @@ -0,0 +1,4 @@ +require_fp; +softfloat_roundingMode = RM; +FRD = f32_mul(FRS1, FRS2); +set_fp_exceptions; diff --git a/riscv/insns/fnmadd_d.h b/riscv/insns/fnmadd_d.h new file mode 100644 index 0000000..1e2ee27 --- /dev/null +++ b/riscv/insns/fnmadd_d.h @@ -0,0 +1,4 @@ +require_fp; +softfloat_roundingMode = RM; +FRD = f64_mulAdd(FRS1, FRS2, FRS3) ^ (uint64_t)INT64_MIN; +set_fp_exceptions; diff --git a/riscv/insns/fnmadd_s.h b/riscv/insns/fnmadd_s.h new file mode 100644 index 0000000..78abb78 --- /dev/null +++ b/riscv/insns/fnmadd_s.h @@ -0,0 +1,4 @@ +require_fp; +softfloat_roundingMode = RM; +FRD = f32_mulAdd(FRS1, FRS2, FRS3) ^ (uint32_t)INT32_MIN; +set_fp_exceptions; diff --git a/riscv/insns/fnmsub_d.h b/riscv/insns/fnmsub_d.h new file mode 100644 index 0000000..ae643a5 --- /dev/null +++ b/riscv/insns/fnmsub_d.h @@ -0,0 +1,4 @@ +require_fp; +softfloat_roundingMode = RM; +FRD = f64_mulAdd(FRS1, FRS2, FRS3 ^ (uint64_t)INT64_MIN) ^ (uint64_t)INT64_MIN; +set_fp_exceptions; diff --git a/riscv/insns/fnmsub_s.h b/riscv/insns/fnmsub_s.h new file mode 100644 index 0000000..cbb70ba --- /dev/null +++ b/riscv/insns/fnmsub_s.h @@ -0,0 +1,4 @@ +require_fp; +softfloat_roundingMode = RM; +FRD = f32_mulAdd(FRS1, FRS2, FRS3 ^ (uint32_t)INT32_MIN) ^ (uint32_t)INT32_MIN; +set_fp_exceptions; diff --git a/riscv/insns/fsd.h b/riscv/insns/fsd.h new file mode 100644 index 0000000..113398e --- /dev/null +++ b/riscv/insns/fsd.h @@ -0,0 +1,2 @@ +require_fp; +mmu.store_uint64(RS1+BIMM, FRS2); diff --git a/riscv/insns/fsgnj_d.h b/riscv/insns/fsgnj_d.h new file mode 100644 index 0000000..f66e804 --- /dev/null +++ b/riscv/insns/fsgnj_d.h @@ -0,0 +1,2 @@ +require_fp; +FRD = (FRS1 &~ INT64_MIN) | (FRS2 & INT64_MIN); diff --git a/riscv/insns/fsgnj_s.h b/riscv/insns/fsgnj_s.h new file mode 100644 index 0000000..35609ac --- /dev/null +++ b/riscv/insns/fsgnj_s.h @@ -0,0 +1,2 @@ +require_fp; +FRD = (FRS1 &~ (uint32_t)INT32_MIN) | (FRS2 & (uint32_t)INT32_MIN); diff --git a/riscv/insns/fsgnjn_d.h b/riscv/insns/fsgnjn_d.h new file mode 100644 index 0000000..22de215 --- /dev/null +++ b/riscv/insns/fsgnjn_d.h @@ -0,0 +1,2 @@ +require_fp; +FRD = (FRS1 &~ INT64_MIN) | ((~FRS2) & INT64_MIN); diff --git a/riscv/insns/fsgnjn_s.h b/riscv/insns/fsgnjn_s.h new file mode 100644 index 0000000..dd66d71 --- /dev/null +++ b/riscv/insns/fsgnjn_s.h @@ -0,0 +1,2 @@ +require_fp; +FRD = (FRS1 &~ (uint32_t)INT32_MIN) | ((~FRS2) & (uint32_t)INT32_MIN); diff --git a/riscv/insns/fsgnjx_d.h b/riscv/insns/fsgnjx_d.h new file mode 100644 index 0000000..331b6e4 --- /dev/null +++ b/riscv/insns/fsgnjx_d.h @@ -0,0 +1,2 @@ +require_fp; +FRD = FRS1 ^ (FRS2 & INT64_MIN); diff --git a/riscv/insns/fsgnjx_s.h b/riscv/insns/fsgnjx_s.h new file mode 100644 index 0000000..b455406 --- /dev/null +++ b/riscv/insns/fsgnjx_s.h @@ -0,0 +1,2 @@ +require_fp; +FRD = FRS1 ^ (FRS2 & (uint32_t)INT32_MIN); diff --git a/riscv/insns/fsqrt_d.h b/riscv/insns/fsqrt_d.h new file mode 100644 index 0000000..7647c9c --- /dev/null +++ b/riscv/insns/fsqrt_d.h @@ -0,0 +1,4 @@ +require_fp; +softfloat_roundingMode = RM; +FRD = f64_sqrt(FRS1); +set_fp_exceptions; diff --git a/riscv/insns/fsqrt_s.h b/riscv/insns/fsqrt_s.h new file mode 100644 index 0000000..426f241 --- /dev/null +++ b/riscv/insns/fsqrt_s.h @@ -0,0 +1,4 @@ +require_fp; +softfloat_roundingMode = RM; +FRD = f32_sqrt(FRS1); +set_fp_exceptions; diff --git a/riscv/insns/fsub_d.h b/riscv/insns/fsub_d.h new file mode 100644 index 0000000..e25eebb --- /dev/null +++ b/riscv/insns/fsub_d.h @@ -0,0 +1,4 @@ +require_fp; +softfloat_roundingMode = RM; +FRD = f64_sub(FRS1, FRS2); +set_fp_exceptions; diff --git a/riscv/insns/fsub_s.h b/riscv/insns/fsub_s.h new file mode 100644 index 0000000..6c64d04 --- /dev/null +++ b/riscv/insns/fsub_s.h @@ -0,0 +1,4 @@ +require_fp; +softfloat_roundingMode = RM; +FRD = f32_sub(FRS1, FRS2); +set_fp_exceptions; diff --git a/riscv/insns/fsw.h b/riscv/insns/fsw.h new file mode 100644 index 0000000..23d3333 --- /dev/null +++ b/riscv/insns/fsw.h @@ -0,0 +1,2 @@ +require_fp; +mmu.store_uint32(RS1+BIMM, FRS2); diff --git a/riscv/insns/j.h b/riscv/insns/j.h new file mode 100644 index 0000000..3a4da2a --- /dev/null +++ b/riscv/insns/j.h @@ -0,0 +1 @@ +set_pc(JUMP_TARGET); diff --git a/riscv/insns/jal.h b/riscv/insns/jal.h new file mode 100644 index 0000000..41dc403 --- /dev/null +++ b/riscv/insns/jal.h @@ -0,0 +1,2 @@ +RA = npc; +set_pc(JUMP_TARGET); diff --git a/riscv/insns/jalr_c.h b/riscv/insns/jalr_c.h new file mode 100644 index 0000000..91be911 --- /dev/null +++ b/riscv/insns/jalr_c.h @@ -0,0 +1,3 @@ +reg_t temp = RS1; +RD = npc; +set_pc(temp + SIMM); diff --git a/riscv/insns/jalr_j.h b/riscv/insns/jalr_j.h new file mode 100644 index 0000000..0d2ef12 --- /dev/null +++ b/riscv/insns/jalr_j.h @@ -0,0 +1 @@ +#include "insns/jalr_c.h" diff --git a/riscv/insns/jalr_r.h b/riscv/insns/jalr_r.h new file mode 100644 index 0000000..0d2ef12 --- /dev/null +++ b/riscv/insns/jalr_r.h @@ -0,0 +1 @@ +#include "insns/jalr_c.h" diff --git a/riscv/insns/lb.h b/riscv/insns/lb.h new file mode 100644 index 0000000..81ba7de --- /dev/null +++ b/riscv/insns/lb.h @@ -0,0 +1 @@ +RD = mmu.load_int8(RS1+SIMM); diff --git a/riscv/insns/lbu.h b/riscv/insns/lbu.h new file mode 100644 index 0000000..12c688a --- /dev/null +++ b/riscv/insns/lbu.h @@ -0,0 +1 @@ +RD = mmu.load_uint8(RS1+SIMM); diff --git a/riscv/insns/ld.h b/riscv/insns/ld.h new file mode 100644 index 0000000..940d348 --- /dev/null +++ b/riscv/insns/ld.h @@ -0,0 +1,2 @@ +require_xpr64; +RD = mmu.load_int64(RS1+SIMM); diff --git a/riscv/insns/lh.h b/riscv/insns/lh.h new file mode 100644 index 0000000..ec25bc4 --- /dev/null +++ b/riscv/insns/lh.h @@ -0,0 +1 @@ +RD = mmu.load_int16(RS1+SIMM); diff --git a/riscv/insns/lhu.h b/riscv/insns/lhu.h new file mode 100644 index 0000000..0999c00 --- /dev/null +++ b/riscv/insns/lhu.h @@ -0,0 +1 @@ +RD = mmu.load_uint16(RS1+SIMM); diff --git a/riscv/insns/lui.h b/riscv/insns/lui.h new file mode 100644 index 0000000..6af2a2a --- /dev/null +++ b/riscv/insns/lui.h @@ -0,0 +1 @@ +RD = sext32(BIGIMM << IMM_BITS); diff --git a/riscv/insns/lw.h b/riscv/insns/lw.h new file mode 100644 index 0000000..769c9fd --- /dev/null +++ b/riscv/insns/lw.h @@ -0,0 +1 @@ +RD = mmu.load_int32(RS1+SIMM); diff --git a/riscv/insns/lwu.h b/riscv/insns/lwu.h new file mode 100644 index 0000000..f8f9841 --- /dev/null +++ b/riscv/insns/lwu.h @@ -0,0 +1,2 @@ +require_xpr64; +RD = mmu.load_uint32(RS1+SIMM); diff --git a/riscv/insns/mffsr.h b/riscv/insns/mffsr.h new file mode 100644 index 0000000..29debc4 --- /dev/null +++ b/riscv/insns/mffsr.h @@ -0,0 +1,2 @@ +require_fp; +RD = fsr; diff --git a/riscv/insns/mfpcr.h b/riscv/insns/mfpcr.h new file mode 100644 index 0000000..7de089e --- /dev/null +++ b/riscv/insns/mfpcr.h @@ -0,0 +1,68 @@ +require_supervisor; + +reg_t val; + +switch(insn.rtype.rs2) +{ + case 0: + val = sr; + break; + case 1: + val = epc; + break; + case 2: + val = badvaddr; + break; + case 3: + val = evec; + break; + case 4: + val = count; + break; + case 5: + val = compare; + break; + case 6: + val = cause; + break; + case 7: + val = 0; + cause &= ~(1 << (IPI_IRQ+CAUSE_IP_SHIFT)); + break; + + case 8: + val = mmu.memsz >> PGSHIFT; + break; + + case 9: + val = mmu.get_ptbr(); + break; + + case 10: + val = id; + break; + + case 11: + val = vecbanks; + break; + + case 12: + val = sim.num_cores(); + break; + + case 17: + val = sim.get_fromhost(); + break; + + case 24: + val = pcr_k0; + break; + case 25: + val = pcr_k1; + break; + + default: + val = -1; +} + +RD = sext_xprlen(val); diff --git a/riscv/insns/mftx_d.h b/riscv/insns/mftx_d.h new file mode 100644 index 0000000..31be4cb --- /dev/null +++ b/riscv/insns/mftx_d.h @@ -0,0 +1,3 @@ +require_xpr64; +require_fp; +RD = FRS2; diff --git a/riscv/insns/mftx_s.h b/riscv/insns/mftx_s.h new file mode 100644 index 0000000..589b33b --- /dev/null +++ b/riscv/insns/mftx_s.h @@ -0,0 +1,2 @@ +require_fp; +RD = sext32(FRS2); diff --git a/riscv/insns/movn.h b/riscv/insns/movn.h new file mode 100644 index 0000000..402d6d3 --- /dev/null +++ b/riscv/insns/movn.h @@ -0,0 +1,2 @@ +require_vector; +if (RS1 & 0x1) RD = RS2; diff --git a/riscv/insns/movz.h b/riscv/insns/movz.h new file mode 100644 index 0000000..74cf8a9 --- /dev/null +++ b/riscv/insns/movz.h @@ -0,0 +1,2 @@ +require_vector; +if (~RS1 & 0x1) RD = RS2; diff --git a/riscv/insns/mtfsr.h b/riscv/insns/mtfsr.h new file mode 100644 index 0000000..cc6f9ea --- /dev/null +++ b/riscv/insns/mtfsr.h @@ -0,0 +1,4 @@ +require_fp; +uint32_t tmp = fsr; +set_fsr(RS1); +RD = tmp; diff --git a/riscv/insns/mtpcr.h b/riscv/insns/mtpcr.h new file mode 100644 index 0000000..59f864f --- /dev/null +++ b/riscv/insns/mtpcr.h @@ -0,0 +1,45 @@ +require_supervisor; + +switch(insn.rtype.rs2) +{ + case 0: + set_sr(RS1); + break; + case 1: + epc = RS1; + break; + case 3: + evec = RS1; + break; + case 4: + count = RS1; + break; + case 5: + cause &= ~(1 << (TIMER_IRQ+CAUSE_IP_SHIFT)); + compare = RS1; + break; + + case 7: + sim.send_ipi(RS1); + break; + + case 9: + mmu.set_ptbr(RS1); + break; + + case 11: + vecbanks = RS1 & 0xff; + vecbanks_count = __builtin_popcountll(vecbanks); + break; + + case 16: + sim.set_tohost(RS1); + break; + + case 24: + pcr_k0 = RS1; + break; + case 25: + pcr_k1 = RS1; + break; +} diff --git a/riscv/insns/mul.h b/riscv/insns/mul.h new file mode 100644 index 0000000..770d733 --- /dev/null +++ b/riscv/insns/mul.h @@ -0,0 +1 @@ +RD = sext_xprlen(RS1 * RS2); diff --git a/riscv/insns/mulh.h b/riscv/insns/mulh.h new file mode 100644 index 0000000..f771a62 --- /dev/null +++ b/riscv/insns/mulh.h @@ -0,0 +1,8 @@ +if(xpr64) +{ + int64_t a = RS1; + int64_t b = RS2; + RD = (int128_t(a) * int128_t(b)) >> 64; +} +else + RD = sext32((sext32(RS1) * sext32(RS2)) >> 32); diff --git a/riscv/insns/mulhsu.h b/riscv/insns/mulhsu.h new file mode 100644 index 0000000..c832657 --- /dev/null +++ b/riscv/insns/mulhsu.h @@ -0,0 +1,8 @@ +if(xpr64) +{ + int64_t a = RS1; + uint64_t b = RS2; + RD = (int128_t(a) * uint128_t(b)) >> 64; +} +else + RD = sext32((sext32(RS1) * reg_t((uint32_t)RS2)) >> 32); diff --git a/riscv/insns/mulhu.h b/riscv/insns/mulhu.h new file mode 100644 index 0000000..6334426 --- /dev/null +++ b/riscv/insns/mulhu.h @@ -0,0 +1,4 @@ +if(xpr64) + RD = (uint128_t(RS1) * uint128_t(RS2)) >> 64; +else + RD = sext32(((uint64_t)(uint32_t)RS1 * (uint64_t)(uint32_t)RS2) >> 32); diff --git a/riscv/insns/mulw.h b/riscv/insns/mulw.h new file mode 100644 index 0000000..7b0a934 --- /dev/null +++ b/riscv/insns/mulw.h @@ -0,0 +1,2 @@ +require_xpr64; +RD = sext32(RS1 * RS2); diff --git a/riscv/insns/mxtf_d.h b/riscv/insns/mxtf_d.h new file mode 100644 index 0000000..29792ec --- /dev/null +++ b/riscv/insns/mxtf_d.h @@ -0,0 +1,3 @@ +require_xpr64; +require_fp; +FRD = RS1; diff --git a/riscv/insns/mxtf_s.h b/riscv/insns/mxtf_s.h new file mode 100644 index 0000000..54546ea --- /dev/null +++ b/riscv/insns/mxtf_s.h @@ -0,0 +1,2 @@ +require_fp; +FRD = RS1; diff --git a/riscv/insns/or.h b/riscv/insns/or.h new file mode 100644 index 0000000..07bcac3 --- /dev/null +++ b/riscv/insns/or.h @@ -0,0 +1 @@ +RD = RS1 | RS2; diff --git a/riscv/insns/ori.h b/riscv/insns/ori.h new file mode 100644 index 0000000..9561b97 --- /dev/null +++ b/riscv/insns/ori.h @@ -0,0 +1 @@ +RD = SIMM | RS1; diff --git a/riscv/insns/rdcycle.h b/riscv/insns/rdcycle.h new file mode 100644 index 0000000..9b966a6 --- /dev/null +++ b/riscv/insns/rdcycle.h @@ -0,0 +1 @@ +RD = cycle; diff --git a/riscv/insns/rdinstret.h b/riscv/insns/rdinstret.h new file mode 100644 index 0000000..9b966a6 --- /dev/null +++ b/riscv/insns/rdinstret.h @@ -0,0 +1 @@ +RD = cycle; diff --git a/riscv/insns/rdnpc.h b/riscv/insns/rdnpc.h new file mode 100644 index 0000000..5525421 --- /dev/null +++ b/riscv/insns/rdnpc.h @@ -0,0 +1 @@ +RD = npc; diff --git a/riscv/insns/rdtime.h b/riscv/insns/rdtime.h new file mode 100644 index 0000000..9b966a6 --- /dev/null +++ b/riscv/insns/rdtime.h @@ -0,0 +1 @@ +RD = cycle; diff --git a/riscv/insns/rem.h b/riscv/insns/rem.h new file mode 100644 index 0000000..ac82a56 --- /dev/null +++ b/riscv/insns/rem.h @@ -0,0 +1,6 @@ +if(RS2 == 0) + RD = RS1; +else if(sreg_t(RS1) == INT64_MIN && sreg_t(RS2) == -1) + RD = 0; +else + RD = sext_xprlen(sext_xprlen(RS1) % sext_xprlen(RS2)); diff --git a/riscv/insns/remu.h b/riscv/insns/remu.h new file mode 100644 index 0000000..c698aca --- /dev/null +++ b/riscv/insns/remu.h @@ -0,0 +1,4 @@ +if(RS2 == 0) + RD = RS1; +else + RD = sext_xprlen(zext_xprlen(RS1) % zext_xprlen(RS2)); diff --git a/riscv/insns/remuw.h b/riscv/insns/remuw.h new file mode 100644 index 0000000..8234af3 --- /dev/null +++ b/riscv/insns/remuw.h @@ -0,0 +1,5 @@ +require_xpr64; +if(RS2 == 0) + RD = RS1; +else + RD = sext32(zext_xprlen(RS1) % zext_xprlen(RS2)); diff --git a/riscv/insns/remw.h b/riscv/insns/remw.h new file mode 100644 index 0000000..93c3858 --- /dev/null +++ b/riscv/insns/remw.h @@ -0,0 +1,7 @@ +require_xpr64; +if(RS2 == 0) + RD = RS1; +else if(int32_t(RS1) == INT32_MIN && int32_t(RS2) == -1) + RD = 0; +else + RD = sext32(int32_t(RS1) % int32_t(RS2)); diff --git a/riscv/insns/sb.h b/riscv/insns/sb.h new file mode 100644 index 0000000..af5bd10 --- /dev/null +++ b/riscv/insns/sb.h @@ -0,0 +1 @@ +mmu.store_uint8(RS1+BIMM, RS2); diff --git a/riscv/insns/sd.h b/riscv/insns/sd.h new file mode 100644 index 0000000..2009149 --- /dev/null +++ b/riscv/insns/sd.h @@ -0,0 +1,2 @@ +require_xpr64; +mmu.store_uint64(RS1+BIMM, RS2); diff --git a/riscv/insns/sh.h b/riscv/insns/sh.h new file mode 100644 index 0000000..a484e1e --- /dev/null +++ b/riscv/insns/sh.h @@ -0,0 +1 @@ +mmu.store_uint16(RS1+BIMM, RS2); diff --git a/riscv/insns/sll.h b/riscv/insns/sll.h new file mode 100644 index 0000000..86eb966 --- /dev/null +++ b/riscv/insns/sll.h @@ -0,0 +1 @@ +RD = sext_xprlen(RS1 << (RS2 & (xprlen-1))); diff --git a/riscv/insns/slli.h b/riscv/insns/slli.h new file mode 100644 index 0000000..bfaf430 --- /dev/null +++ b/riscv/insns/slli.h @@ -0,0 +1,8 @@ +if(xpr64) + RD = RS1 << SHAMT; +else +{ + if(SHAMT & 0x20) + throw trap_illegal_instruction; + RD = sext32(RS1 << SHAMT); +} diff --git a/riscv/insns/slliw.h b/riscv/insns/slliw.h new file mode 100644 index 0000000..1f6e50d --- /dev/null +++ b/riscv/insns/slliw.h @@ -0,0 +1,2 @@ +require_xpr64; +RD = sext32(RS1 << SHAMTW); diff --git a/riscv/insns/sllw.h b/riscv/insns/sllw.h new file mode 100644 index 0000000..f3356d8 --- /dev/null +++ b/riscv/insns/sllw.h @@ -0,0 +1,2 @@ +require_xpr64; +RD = sext32(RS1 << (RS2 & 0x1F)); diff --git a/riscv/insns/slt.h b/riscv/insns/slt.h new file mode 100644 index 0000000..5c50534 --- /dev/null +++ b/riscv/insns/slt.h @@ -0,0 +1 @@ +RD = sreg_t(cmp_trunc(RS1)) < sreg_t(cmp_trunc(RS2)); diff --git a/riscv/insns/slti.h b/riscv/insns/slti.h new file mode 100644 index 0000000..1dcd892 --- /dev/null +++ b/riscv/insns/slti.h @@ -0,0 +1 @@ +RD = sreg_t(cmp_trunc(RS1)) < sreg_t(cmp_trunc(SIMM)); diff --git a/riscv/insns/sltiu.h b/riscv/insns/sltiu.h new file mode 100644 index 0000000..45e579b --- /dev/null +++ b/riscv/insns/sltiu.h @@ -0,0 +1 @@ +RD = cmp_trunc(RS1) < cmp_trunc(SIMM); diff --git a/riscv/insns/sltu.h b/riscv/insns/sltu.h new file mode 100644 index 0000000..2c5bdc3 --- /dev/null +++ b/riscv/insns/sltu.h @@ -0,0 +1 @@ +RD = cmp_trunc(RS1) < cmp_trunc(RS2); diff --git a/riscv/insns/sra.h b/riscv/insns/sra.h new file mode 100644 index 0000000..7102da0 --- /dev/null +++ b/riscv/insns/sra.h @@ -0,0 +1 @@ +RD = sext_xprlen(sext_xprlen(RS1) >> (RS2 & (xprlen-1))); diff --git a/riscv/insns/srai.h b/riscv/insns/srai.h new file mode 100644 index 0000000..bb17d27 --- /dev/null +++ b/riscv/insns/srai.h @@ -0,0 +1,8 @@ +if(xpr64) + RD = sreg_t(RS1) >> SHAMT; +else +{ + if(SHAMT & 0x20) + throw trap_illegal_instruction; + RD = sext32(int32_t(RS1) >> SHAMT); +} diff --git a/riscv/insns/sraiw.h b/riscv/insns/sraiw.h new file mode 100644 index 0000000..4c56730 --- /dev/null +++ b/riscv/insns/sraiw.h @@ -0,0 +1,2 @@ +require_xpr64; +RD = sext32(int32_t(RS1) >> SHAMTW); diff --git a/riscv/insns/sraw.h b/riscv/insns/sraw.h new file mode 100644 index 0000000..d178374 --- /dev/null +++ b/riscv/insns/sraw.h @@ -0,0 +1,2 @@ +require_xpr64; +RD = sext32(int32_t(RS1) >> (RS2 & 0x1F)); diff --git a/riscv/insns/srl.h b/riscv/insns/srl.h new file mode 100644 index 0000000..8230d27 --- /dev/null +++ b/riscv/insns/srl.h @@ -0,0 +1,4 @@ +if(xpr64) + RD = RS1 >> (RS2 & 0x3F); +else + RD = sext32((uint32_t)RS1 >> (RS2 & 0x1F)); diff --git a/riscv/insns/srli.h b/riscv/insns/srli.h new file mode 100644 index 0000000..5378fd1 --- /dev/null +++ b/riscv/insns/srli.h @@ -0,0 +1,8 @@ +if(xpr64) + RD = RS1 >> SHAMT; +else +{ + if(SHAMT & 0x20) + throw trap_illegal_instruction; + RD = sext32((uint32_t)RS1 >> SHAMT); +} diff --git a/riscv/insns/srliw.h b/riscv/insns/srliw.h new file mode 100644 index 0000000..c400507 --- /dev/null +++ b/riscv/insns/srliw.h @@ -0,0 +1,2 @@ +require_xpr64; +RD = sext32((uint32_t)RS1 >> SHAMTW); diff --git a/riscv/insns/srlw.h b/riscv/insns/srlw.h new file mode 100644 index 0000000..b206f7c --- /dev/null +++ b/riscv/insns/srlw.h @@ -0,0 +1,2 @@ +require_xpr64; +RD = sext32((uint32_t)RS1 >> (RS2 & 0x1F)); diff --git a/riscv/insns/stop.h b/riscv/insns/stop.h new file mode 100644 index 0000000..791a82c --- /dev/null +++ b/riscv/insns/stop.h @@ -0,0 +1,3 @@ +require_vector; +utmode = false; +throw vt_command_stop; diff --git a/riscv/insns/sub.h b/riscv/insns/sub.h new file mode 100644 index 0000000..2b1e057 --- /dev/null +++ b/riscv/insns/sub.h @@ -0,0 +1 @@ +RD = sext_xprlen(RS1 - RS2); diff --git a/riscv/insns/subw.h b/riscv/insns/subw.h new file mode 100644 index 0000000..28db334 --- /dev/null +++ b/riscv/insns/subw.h @@ -0,0 +1,3 @@ +require_xpr64; +RD = sext32(RS1 - RS2); + diff --git a/riscv/insns/sw.h b/riscv/insns/sw.h new file mode 100644 index 0000000..dbe260f --- /dev/null +++ b/riscv/insns/sw.h @@ -0,0 +1 @@ +mmu.store_uint32(RS1+BIMM, RS2); diff --git a/riscv/insns/syscall.h b/riscv/insns/syscall.h new file mode 100644 index 0000000..2c7199d --- /dev/null +++ b/riscv/insns/syscall.h @@ -0,0 +1 @@ +throw trap_syscall; diff --git a/riscv/insns/utidx.h b/riscv/insns/utidx.h new file mode 100644 index 0000000..b3c944c --- /dev/null +++ b/riscv/insns/utidx.h @@ -0,0 +1,2 @@ +require_vector; +RD = utidx; diff --git a/riscv/insns/vf.h b/riscv/insns/vf.h new file mode 100644 index 0000000..7779645 --- /dev/null +++ b/riscv/insns/vf.h @@ -0,0 +1,8 @@ +require_vector; +for (int i=0; ipc = RS1+SIMM; + uts[i]->utmode = true; + while (uts[i]->utmode) + uts[i]->step(1, false); // XXX +} diff --git a/riscv/insns/vfld.h b/riscv/insns/vfld.h new file mode 100644 index 0000000..9b40470 --- /dev/null +++ b/riscv/insns/vfld.h @@ -0,0 +1,3 @@ +require_vector; +require_fp; +VEC_LOAD(FRD, load_int64, 8); diff --git a/riscv/insns/vflsegd.h b/riscv/insns/vflsegd.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/vflsegstd.h b/riscv/insns/vflsegstd.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/vflsegstw.h b/riscv/insns/vflsegstw.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/vflsegw.h b/riscv/insns/vflsegw.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/vflstd.h b/riscv/insns/vflstd.h new file mode 100644 index 0000000..fa9b32d --- /dev/null +++ b/riscv/insns/vflstd.h @@ -0,0 +1,3 @@ +require_vector; +require_fp; +VEC_LOAD(FRD, load_int64, RS2); diff --git a/riscv/insns/vflstw.h b/riscv/insns/vflstw.h new file mode 100644 index 0000000..716c818 --- /dev/null +++ b/riscv/insns/vflstw.h @@ -0,0 +1,3 @@ +require_vector; +require_fp; +VEC_LOAD(FRD, load_int32, RS2); diff --git a/riscv/insns/vflw.h b/riscv/insns/vflw.h new file mode 100644 index 0000000..75fdd04 --- /dev/null +++ b/riscv/insns/vflw.h @@ -0,0 +1,3 @@ +require_vector; +require_fp; +VEC_LOAD(FRD, load_int32, 4); diff --git a/riscv/insns/vfmst.h b/riscv/insns/vfmst.h new file mode 100644 index 0000000..686d7c5 --- /dev/null +++ b/riscv/insns/vfmst.h @@ -0,0 +1,4 @@ +require_vector; +require_fp; +assert(0 <= RS2 && RS2 < MAX_UTS); +UT_FRD(RS2) = FRS1; diff --git a/riscv/insns/vfmsv.h b/riscv/insns/vfmsv.h new file mode 100644 index 0000000..a9aa876 --- /dev/null +++ b/riscv/insns/vfmsv.h @@ -0,0 +1,5 @@ +require_vector; +require_fp; +UT_LOOP_START + UT_LOOP_FRD = FRS1; +UT_LOOP_END diff --git a/riscv/insns/vfmts.h b/riscv/insns/vfmts.h new file mode 100644 index 0000000..a6da126 --- /dev/null +++ b/riscv/insns/vfmts.h @@ -0,0 +1,4 @@ +require_vector; +require_fp; +assert(0 <= RS2 && RS2 < MAX_UTS); +FRD = UT_FRS1(RS2); diff --git a/riscv/insns/vfmvv.h b/riscv/insns/vfmvv.h new file mode 100644 index 0000000..279da21 --- /dev/null +++ b/riscv/insns/vfmvv.h @@ -0,0 +1,5 @@ +require_vector; +require_fp; +UT_LOOP_START + UT_LOOP_FRD = UT_LOOP_FRS1; +UT_LOOP_END diff --git a/riscv/insns/vfsd.h b/riscv/insns/vfsd.h new file mode 100644 index 0000000..f619fc8 --- /dev/null +++ b/riscv/insns/vfsd.h @@ -0,0 +1,3 @@ +require_vector; +require_fp; +VEC_STORE(FRD, store_uint64, 8); diff --git a/riscv/insns/vfssegd.h b/riscv/insns/vfssegd.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/vfssegstd.h b/riscv/insns/vfssegstd.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/vfssegstw.h b/riscv/insns/vfssegstw.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/vfssegw.h b/riscv/insns/vfssegw.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/vfsstd.h b/riscv/insns/vfsstd.h new file mode 100644 index 0000000..b3bb260 --- /dev/null +++ b/riscv/insns/vfsstd.h @@ -0,0 +1,3 @@ +require_vector; +require_fp; +VEC_STORE(FRD, store_uint64, RS2); diff --git a/riscv/insns/vfsstw.h b/riscv/insns/vfsstw.h new file mode 100644 index 0000000..9cef9b0 --- /dev/null +++ b/riscv/insns/vfsstw.h @@ -0,0 +1,3 @@ +require_vector; +require_fp; +VEC_STORE(FRD, store_uint32, RS2); diff --git a/riscv/insns/vfsw.h b/riscv/insns/vfsw.h new file mode 100644 index 0000000..3fe3d3f --- /dev/null +++ b/riscv/insns/vfsw.h @@ -0,0 +1,3 @@ +require_vector; +require_fp; +VEC_STORE(FRD, store_uint32, 4); diff --git a/riscv/insns/vlb.h b/riscv/insns/vlb.h new file mode 100644 index 0000000..618380a --- /dev/null +++ b/riscv/insns/vlb.h @@ -0,0 +1,2 @@ +require_vector; +VEC_LOAD(RD, load_int8, 1); diff --git a/riscv/insns/vlbu.h b/riscv/insns/vlbu.h new file mode 100644 index 0000000..f92c8b5 --- /dev/null +++ b/riscv/insns/vlbu.h @@ -0,0 +1,2 @@ +require_vector; +VEC_LOAD(RD, load_uint8, 1); diff --git a/riscv/insns/vld.h b/riscv/insns/vld.h new file mode 100644 index 0000000..fb7a3c5 --- /dev/null +++ b/riscv/insns/vld.h @@ -0,0 +1,3 @@ +require_vector; +require_xpr64; +VEC_LOAD(RD, load_int64, 8); diff --git a/riscv/insns/vlh.h b/riscv/insns/vlh.h new file mode 100644 index 0000000..269c2a8 --- /dev/null +++ b/riscv/insns/vlh.h @@ -0,0 +1,2 @@ +require_vector; +VEC_LOAD(RD, load_int16, 2); diff --git a/riscv/insns/vlhu.h b/riscv/insns/vlhu.h new file mode 100644 index 0000000..7a2019d --- /dev/null +++ b/riscv/insns/vlhu.h @@ -0,0 +1,2 @@ +require_vector; +VEC_LOAD(RD, load_uint16, 2); diff --git a/riscv/insns/vlsegb.h b/riscv/insns/vlsegb.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/vlsegbu.h b/riscv/insns/vlsegbu.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/vlsegd.h b/riscv/insns/vlsegd.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/vlsegh.h b/riscv/insns/vlsegh.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/vlseghu.h b/riscv/insns/vlseghu.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/vlsegstb.h b/riscv/insns/vlsegstb.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/vlsegstbu.h b/riscv/insns/vlsegstbu.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/vlsegstd.h b/riscv/insns/vlsegstd.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/vlsegsth.h b/riscv/insns/vlsegsth.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/vlsegsthu.h b/riscv/insns/vlsegsthu.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/vlsegstw.h b/riscv/insns/vlsegstw.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/vlsegstwu.h b/riscv/insns/vlsegstwu.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/vlsegw.h b/riscv/insns/vlsegw.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/vlsegwu.h b/riscv/insns/vlsegwu.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/vlstb.h b/riscv/insns/vlstb.h new file mode 100644 index 0000000..219d90e --- /dev/null +++ b/riscv/insns/vlstb.h @@ -0,0 +1,2 @@ +require_vector; +VEC_LOAD(RD, load_int8, RS2); diff --git a/riscv/insns/vlstbu.h b/riscv/insns/vlstbu.h new file mode 100644 index 0000000..09faa29 --- /dev/null +++ b/riscv/insns/vlstbu.h @@ -0,0 +1,2 @@ +require_vector; +VEC_LOAD(RD, load_uint8, RS2); diff --git a/riscv/insns/vlstd.h b/riscv/insns/vlstd.h new file mode 100644 index 0000000..5e5de9c --- /dev/null +++ b/riscv/insns/vlstd.h @@ -0,0 +1,3 @@ +require_vector; +require_xpr64; +VEC_LOAD(RD, load_int64, RS2); diff --git a/riscv/insns/vlsth.h b/riscv/insns/vlsth.h new file mode 100644 index 0000000..af6b5b5 --- /dev/null +++ b/riscv/insns/vlsth.h @@ -0,0 +1,2 @@ +require_vector; +VEC_LOAD(RD, load_int16, RS2); diff --git a/riscv/insns/vlsthu.h b/riscv/insns/vlsthu.h new file mode 100644 index 0000000..0fe8452 --- /dev/null +++ b/riscv/insns/vlsthu.h @@ -0,0 +1,2 @@ +require_vector; +VEC_LOAD(RD, load_uint16, RS2); diff --git a/riscv/insns/vlstw.h b/riscv/insns/vlstw.h new file mode 100644 index 0000000..5375dc0 --- /dev/null +++ b/riscv/insns/vlstw.h @@ -0,0 +1,2 @@ +require_vector; +VEC_LOAD(RD, load_int32, RS2); diff --git a/riscv/insns/vlstwu.h b/riscv/insns/vlstwu.h new file mode 100644 index 0000000..328e23f --- /dev/null +++ b/riscv/insns/vlstwu.h @@ -0,0 +1,2 @@ +require_vector; +VEC_LOAD(RD, load_uint32, RS2); diff --git a/riscv/insns/vlw.h b/riscv/insns/vlw.h new file mode 100644 index 0000000..6e35911 --- /dev/null +++ b/riscv/insns/vlw.h @@ -0,0 +1,2 @@ +require_vector; +VEC_LOAD(RD, load_int32, 4); diff --git a/riscv/insns/vlwu.h b/riscv/insns/vlwu.h new file mode 100644 index 0000000..4fa1489 --- /dev/null +++ b/riscv/insns/vlwu.h @@ -0,0 +1,2 @@ +require_vector; +VEC_LOAD(RD, load_uint32, 4); diff --git a/riscv/insns/vmst.h b/riscv/insns/vmst.h new file mode 100644 index 0000000..f4d03d9 --- /dev/null +++ b/riscv/insns/vmst.h @@ -0,0 +1,3 @@ +require_vector; +assert(0 <= RS2 && RS2 < MAX_UTS); +UT_RD(RS2) = RS1; diff --git a/riscv/insns/vmsv.h b/riscv/insns/vmsv.h new file mode 100644 index 0000000..c6f4c2c --- /dev/null +++ b/riscv/insns/vmsv.h @@ -0,0 +1,4 @@ +require_vector; +UT_LOOP_START + UT_LOOP_RD = RS1; +UT_LOOP_END diff --git a/riscv/insns/vmts.h b/riscv/insns/vmts.h new file mode 100644 index 0000000..2d463bc --- /dev/null +++ b/riscv/insns/vmts.h @@ -0,0 +1,3 @@ +require_vector; +assert(0 <= RS2 && RS2 < MAX_UTS); +RD = UT_RS1(RS2); diff --git a/riscv/insns/vmvv.h b/riscv/insns/vmvv.h new file mode 100644 index 0000000..91d63d4 --- /dev/null +++ b/riscv/insns/vmvv.h @@ -0,0 +1,4 @@ +require_vector; +UT_LOOP_START + UT_LOOP_RD = UT_LOOP_RS1; +UT_LOOP_END diff --git a/riscv/insns/vsb.h b/riscv/insns/vsb.h new file mode 100644 index 0000000..c3d5b9d --- /dev/null +++ b/riscv/insns/vsb.h @@ -0,0 +1,2 @@ +require_vector; +VEC_STORE(RD, store_uint8, 1); diff --git a/riscv/insns/vsd.h b/riscv/insns/vsd.h new file mode 100644 index 0000000..9c02069 --- /dev/null +++ b/riscv/insns/vsd.h @@ -0,0 +1,3 @@ +require_vector; +require_xpr64; +VEC_STORE(RD, store_uint64, 8); diff --git a/riscv/insns/vsetvl.h b/riscv/insns/vsetvl.h new file mode 100644 index 0000000..c2212ff --- /dev/null +++ b/riscv/insns/vsetvl.h @@ -0,0 +1,3 @@ +require_vector; +setvl(RS1); +RD = VL; diff --git a/riscv/insns/vsh.h b/riscv/insns/vsh.h new file mode 100644 index 0000000..623eda8 --- /dev/null +++ b/riscv/insns/vsh.h @@ -0,0 +1,2 @@ +require_vector; +VEC_STORE(RD, store_uint16, 2); diff --git a/riscv/insns/vssegb.h b/riscv/insns/vssegb.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/vssegd.h b/riscv/insns/vssegd.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/vssegh.h b/riscv/insns/vssegh.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/vssegstb.h b/riscv/insns/vssegstb.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/vssegstd.h b/riscv/insns/vssegstd.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/vssegsth.h b/riscv/insns/vssegsth.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/vssegstw.h b/riscv/insns/vssegstw.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/vssegw.h b/riscv/insns/vssegw.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/vsstb.h b/riscv/insns/vsstb.h new file mode 100644 index 0000000..b83cc50 --- /dev/null +++ b/riscv/insns/vsstb.h @@ -0,0 +1,2 @@ +require_vector; +VEC_STORE(RD, store_uint8, RS2); diff --git a/riscv/insns/vsstd.h b/riscv/insns/vsstd.h new file mode 100644 index 0000000..26868d2 --- /dev/null +++ b/riscv/insns/vsstd.h @@ -0,0 +1,3 @@ +require_vector; +require_xpr64; +VEC_STORE(RD, store_uint64, RS2); diff --git a/riscv/insns/vssth.h b/riscv/insns/vssth.h new file mode 100644 index 0000000..3904331 --- /dev/null +++ b/riscv/insns/vssth.h @@ -0,0 +1,2 @@ +require_vector; +VEC_STORE(RD, store_uint16, RS2); diff --git a/riscv/insns/vsstw.h b/riscv/insns/vsstw.h new file mode 100644 index 0000000..8f05953 --- /dev/null +++ b/riscv/insns/vsstw.h @@ -0,0 +1,2 @@ +require_vector; +VEC_STORE(RD, store_uint32, RS2); diff --git a/riscv/insns/vsw.h b/riscv/insns/vsw.h new file mode 100644 index 0000000..662d4e3 --- /dev/null +++ b/riscv/insns/vsw.h @@ -0,0 +1,2 @@ +require_vector; +VEC_STORE(RD, store_uint32, 4); diff --git a/riscv/insns/vtcfgivl.h b/riscv/insns/vtcfgivl.h new file mode 100644 index 0000000..e69de29 diff --git a/riscv/insns/vvcfgivl.h b/riscv/insns/vvcfgivl.h new file mode 100644 index 0000000..0ded9f8 --- /dev/null +++ b/riscv/insns/vvcfgivl.h @@ -0,0 +1,6 @@ +require_vector; +nxpr_use = SIMM & 0x3f; +nfpr_use = (SIMM >> 6) & 0x3f; +vcfg(); +setvl(RS1); +RD = VL; diff --git a/riscv/insns/xor.h b/riscv/insns/xor.h new file mode 100644 index 0000000..49b1783 --- /dev/null +++ b/riscv/insns/xor.h @@ -0,0 +1 @@ +RD = RS1 ^ RS2; diff --git a/riscv/insns/xori.h b/riscv/insns/xori.h new file mode 100644 index 0000000..5852aac --- /dev/null +++ b/riscv/insns/xori.h @@ -0,0 +1 @@ +RD = SIMM ^ RS1; diff --git a/riscv/interactive.cc b/riscv/interactive.cc new file mode 100644 index 0000000..4f7891f --- /dev/null +++ b/riscv/interactive.cc @@ -0,0 +1,256 @@ +#include "sim.h" +#include "htif.h" +#include +#include +#include +#include +#include + +void sim_t::interactive() +{ + putchar(':'); + char s[128]; + std::cin.getline(s,sizeof(s)-1); + + char* p = strtok(s," "); + if(!p) + { + interactive_run_noisy(std::string("r"), std::vector(1,"1")); + return; + } + std::string cmd = p; + + std::vector args; + while((p = strtok(NULL," "))) + args.push_back(p); + + + typedef void (sim_t::*interactive_func)(const std::string&, const std::vector&); + std::map funcs; + + funcs["r"] = &sim_t::interactive_run_noisy; + funcs["rs"] = &sim_t::interactive_run_silent; + funcs["rp"] = &sim_t::interactive_run_proc_noisy; + funcs["rps"] = &sim_t::interactive_run_proc_silent; + funcs["reg"] = &sim_t::interactive_reg; + funcs["fregs"] = &sim_t::interactive_fregs; + funcs["fregd"] = &sim_t::interactive_fregd; + funcs["mem"] = &sim_t::interactive_mem; + funcs["str"] = &sim_t::interactive_str; + funcs["until"] = &sim_t::interactive_until; + funcs["while"] = &sim_t::interactive_until; + funcs["q"] = &sim_t::interactive_quit; + + try + { + if(funcs.count(cmd)) + (this->*funcs[cmd])(cmd, args); + } + catch(trap_t t) {} +} + +void sim_t::interactive_run_noisy(const std::string& cmd, const std::vector& args) +{ + interactive_run(cmd,args,true); +} + +void sim_t::interactive_run_silent(const std::string& cmd, const std::vector& args) +{ + interactive_run(cmd,args,false); +} + +void sim_t::interactive_run(const std::string& cmd, const std::vector& args, bool noisy) +{ + if(args.size()) + step_all(atoll(args[0].c_str()),1,noisy); + else + while(1) step_all(1,1,noisy); +} + +void sim_t::interactive_run_proc_noisy(const std::string& cmd, const std::vector& args) +{ + interactive_run_proc(cmd,args,true); +} + +void sim_t::interactive_run_proc_silent(const std::string& cmd, const std::vector& args) +{ + interactive_run_proc(cmd,args,false); +} + +void sim_t::interactive_run_proc(const std::string& cmd, const std::vector& a, bool noisy) +{ + if(a.size() == 0) + return; + + int p = atoi(a[0].c_str()); + if(p >= (int)num_cores()) + return; + + if(a.size() == 2) + procs[p]->step(atoi(a[1].c_str()),noisy); + else + while(1) procs[p]->step(1,noisy); +} + +void sim_t::interactive_quit(const std::string& cmd, const std::vector& args) +{ + stop(); +} + +reg_t sim_t::get_pc(const std::vector& args) +{ + if(args.size() != 1) + throw trap_illegal_instruction; + + int p = atoi(args[0].c_str()); + if(p >= (int)num_cores()) + throw trap_illegal_instruction; + + return procs[p]->pc; +} + +reg_t sim_t::get_reg(const std::vector& args) +{ + if(args.size() != 2) + throw trap_illegal_instruction; + + int p = atoi(args[0].c_str()); + int r = atoi(args[1].c_str()); + if(p >= (int)num_cores() || r >= NXPR) + throw trap_illegal_instruction; + + return procs[p]->XPR[r]; +} + +reg_t sim_t::get_freg(const std::vector& args) +{ + if(args.size() != 2) + throw trap_illegal_instruction; + + int p = atoi(args[0].c_str()); + int r = atoi(args[1].c_str()); + if(p >= (int)num_cores() || r >= NFPR) + throw trap_illegal_instruction; + + return procs[p]->FPR[r]; +} + +void sim_t::interactive_reg(const std::string& cmd, const std::vector& args) +{ + printf("0x%016llx\n",(unsigned long long)get_reg(args)); +} + +union fpr +{ + reg_t r; + float s; + double d; +}; + +void sim_t::interactive_fregs(const std::string& cmd, const std::vector& args) +{ + fpr f; + f.r = get_freg(args); + printf("%g\n",f.s); +} + +void sim_t::interactive_fregd(const std::string& cmd, const std::vector& args) +{ + fpr f; + f.r = get_freg(args); + printf("%g\n",f.d); +} + +reg_t sim_t::get_mem(const std::vector& args) +{ + if(args.size() != 1 && args.size() != 2) + throw trap_illegal_instruction; + + std::string addr_str = args[0]; + if(args.size() == 2) + { + int p = atoi(args[0].c_str()); + if(p >= (int)num_cores()) + throw trap_illegal_instruction; + mmu->set_vm_enabled(!!(procs[p]->sr & SR_VM)); + mmu->set_ptbr(procs[p]->mmu.get_ptbr()); + addr_str = args[1]; + } + + reg_t addr = strtol(addr_str.c_str(),NULL,16), val; + if(addr == LONG_MAX) + addr = strtoul(addr_str.c_str(),NULL,16); + + switch(addr % 8) + { + case 0: + val = mmu->load_uint64(addr); + break; + case 4: + val = mmu->load_uint32(addr); + break; + case 2: + case 6: + val = mmu->load_uint16(addr); + break; + default: + val = mmu->load_uint8(addr); + break; + } + return val; +} + +void sim_t::interactive_mem(const std::string& cmd, const std::vector& args) +{ + printf("0x%016llx\n",(unsigned long long)get_mem(args)); +} + +void sim_t::interactive_str(const std::string& cmd, const std::vector& args) +{ + if(args.size() != 1) + throw trap_illegal_instruction; + + reg_t addr = strtol(args[0].c_str(),NULL,16); + + char ch; + while((ch = mmu->load_uint8(addr++))) + putchar(ch); + + putchar('\n'); +} + +void sim_t::interactive_until(const std::string& cmd, const std::vector& args) +{ + if(args.size() < 3) + return; + + std::string scmd = args[0]; + reg_t val = strtol(args[args.size()-1].c_str(),NULL,16); + if(val == LONG_MAX) + val = strtoul(args[args.size()-1].c_str(),NULL,16); + + std::vector args2; + args2 = std::vector(args.begin()+1,args.end()-1); + + while(1) + { + reg_t current; + if(scmd == "reg") + current = get_reg(args2); + else if(scmd == "pc") + current = get_pc(args2); + else if(scmd == "mem") + current = get_mem(args2); + else if(scmd == "tohost") + current = tohost; + else + return; + + if(cmd == "until" && current == val) + break; + if(cmd == "while" && current != val) + break; + + step_all(1,1,false); + } +} diff --git a/riscv/mmu.cc b/riscv/mmu.cc new file mode 100644 index 0000000..b2c8c98 --- /dev/null +++ b/riscv/mmu.cc @@ -0,0 +1,104 @@ +#include "mmu.h" +#include "sim.h" +#include "processor.h" + +mmu_t::mmu_t(char* _mem, size_t _memsz) + : mem(_mem), memsz(_memsz), badvaddr(0), + ptbr(0), supervisor(true), vm_enabled(false) +{ + flush_tlb(); +} + +mmu_t::~mmu_t() +{ +} + +void mmu_t::flush_tlb() +{ + memset(tlb_insn_tag, -1, sizeof(tlb_insn_tag)); + memset(tlb_load_tag, -1, sizeof(tlb_load_tag)); + memset(tlb_store_tag, -1, sizeof(tlb_store_tag)); + + flush_icache(); +} + +void mmu_t::flush_icache() +{ + memset(icache_tag, -1, sizeof(icache_tag)); +} + +void* mmu_t::refill(reg_t addr, bool store, bool fetch) +{ + reg_t idx = (addr >> PGSHIFT) % TLB_ENTRIES; + reg_t expected_tag = addr & ~(PGSIZE-1); + + reg_t pte = walk(addr); + + reg_t pte_perm = pte & PTE_PERM; + if(supervisor) // shift supervisor permission bits into user perm bits + pte_perm = (pte_perm/(PTE_SX/PTE_UX)) & PTE_PERM; + pte_perm |= pte & PTE_E; + + reg_t perm = (fetch ? PTE_UX : store ? PTE_UW : PTE_UR) | PTE_E; + if(unlikely((pte_perm & perm) != perm)) + { + badvaddr = addr; + throw store ? trap_store_access_fault + : fetch ? trap_instruction_access_fault + : trap_load_access_fault; + } + + tlb_load_tag[idx] = (pte_perm & PTE_UR) ? expected_tag : -1; + tlb_store_tag[idx] = (pte_perm & PTE_UW) ? expected_tag : -1; + tlb_insn_tag[idx] = (pte_perm & PTE_UX) ? expected_tag : -1; + tlb_data[idx] = (long)(pte >> PTE_PPN_SHIFT << PGSHIFT) + (long)mem; + + return (void*)(((long)addr & (PGSIZE-1)) | tlb_data[idx]); +} + +pte_t mmu_t::walk(reg_t addr) +{ + pte_t pte = 0; + + if(!vm_enabled) + { + if(addr < memsz) + pte = PTE_E | PTE_PERM | ((addr >> PGSHIFT) << PTE_PPN_SHIFT); + } + else + { + reg_t base = ptbr; + reg_t ptd; + + int ptshift = (LEVELS-1)*PTIDXBITS; + for(reg_t i = 0; i < LEVELS; i++, ptshift -= PTIDXBITS) + { + reg_t idx = (addr >> (PGSHIFT+ptshift)) & ((1<= memsz) + break; + + ptd = *(pte_t*)(mem+pte_addr); + if(ptd & PTE_E) + { + // if this PTE is from a larger PT, fake a leaf + // PTE so the TLB will work right + reg_t vpn = addr >> PGSHIFT; + ptd |= (vpn & ((1<<(ptshift))-1)) << PTE_PPN_SHIFT; + + // fault if physical addr is invalid + reg_t ppn = ptd >> PTE_PPN_SHIFT; + if((ppn << PGSHIFT) + (addr & (PGSIZE-1)) < memsz) + pte = ptd; + break; + } + else if(!(ptd & PTE_T)) + break; + + base = (ptd >> PTE_PPN_SHIFT) << PGSHIFT; + } + } + + return pte; +} diff --git a/riscv/mmu.h b/riscv/mmu.h new file mode 100644 index 0000000..fb186ee --- /dev/null +++ b/riscv/mmu.h @@ -0,0 +1,191 @@ +#ifndef _RISCV_MMU_H +#define _RISCV_MMU_H + +#include "decode.h" +#include "trap.h" +#include "common.h" +#include "processor.h" + +class processor_t; + +// virtual memory configuration +typedef reg_t pte_t; +const reg_t LEVELS = 4; +const reg_t PGSHIFT = 12; +const reg_t PGSIZE = 1 << PGSHIFT; +const reg_t PTIDXBITS = PGSHIFT - (sizeof(pte_t) == 8 ? 3 : 2); +const reg_t PPN_BITS = 8*sizeof(reg_t) - PGSHIFT; + +// page table entry (PTE) fields +#define PTE_T 0x001 // Entry is a page Table descriptor +#define PTE_E 0x002 // Entry is a page table Entry +#define PTE_R 0x004 // Referenced +#define PTE_D 0x008 // Dirty +#define PTE_UX 0x010 // User eXecute permission +#define PTE_UW 0x020 // User Read permission +#define PTE_UR 0x040 // User Write permission +#define PTE_SX 0x080 // Supervisor eXecute permission +#define PTE_SW 0x100 // Supervisor Read permission +#define PTE_SR 0x200 // Supervisor Write permission +#define PTE_PERM (PTE_SR | PTE_SW | PTE_SX | PTE_UR | PTE_UW | PTE_UX) +#define PTE_PERM_SHIFT 4 +#define PTE_PPN_SHIFT 12 // LSB of physical page number in the PTE + +// this class implements a processor's port into the virtual memory system. +// an MMU and instruction cache are maintained for simulator performance. +class mmu_t +{ +public: + mmu_t(char* _mem, size_t _memsz); + ~mmu_t(); + + // template for functions that load an aligned value from memory + #define load_func(type) \ + type##_t load_##type(reg_t addr) { \ + if(unlikely(addr % sizeof(type##_t))) \ + { \ + badvaddr = addr; \ + throw trap_load_address_misaligned; \ + } \ + void* paddr = translate(addr, false, false); \ + return *(type##_t*)paddr; \ + } + + // load value from memory at aligned address; zero extend to register width + load_func(uint8) + load_func(uint16) + load_func(uint32) + load_func(uint64) + + // load value from memory at aligned address; sign extend to register width + load_func(int8) + load_func(int16) + load_func(int32) + load_func(int64) + + // template for functions that store an aligned value to memory + #define store_func(type) \ + void store_##type(reg_t addr, type##_t val) { \ + if(unlikely(addr % sizeof(type##_t))) \ + { \ + badvaddr = addr; \ + throw trap_store_address_misaligned; \ + } \ + void* paddr = translate(addr, true, false); \ + *(type##_t*)paddr = val; \ + } + + // store value to memory at aligned address + store_func(uint8) + store_func(uint16) + store_func(uint32) + store_func(uint64) + + // load instruction from memory at aligned address. + // (needed because instruction alignment requirement is variable + // if RVC is supported) + // returns the instruction at the specified address, given the current + // RVC mode. func is set to a pointer to a function that knows how to + // execute the returned instruction. + insn_t __attribute__((always_inline)) load_insn(reg_t addr, bool rvc, + insn_func_t* func) + { + insn_t insn; + + #ifdef RISCV_ENABLE_RVC + if(addr % 4 == 2 && rvc) // fetch across word boundary + { + void* addr_lo = translate(addr, false, true); + insn.bits = *(uint16_t*)addr_lo; + + *func = processor_t::dispatch_table + [insn.bits % processor_t::DISPATCH_TABLE_SIZE]; + + if(!INSN_IS_RVC(insn.bits)) + { + void* addr_hi = translate(addr+2, false, true); + insn.bits |= (uint32_t)*(uint16_t*)addr_hi << 16; + } + } + else + #endif + { + reg_t idx = (addr/sizeof(insn_t)) % ICACHE_ENTRIES; + insn_t data = icache_data[idx]; + *func = icache_func[idx]; + if(likely(icache_tag[idx] == addr)) + return data; + + // the processor guarantees alignment based upon rvc mode + void* paddr = translate(addr, false, true); + insn = *(insn_t*)paddr; + + icache_tag[idx] = addr; + icache_data[idx] = insn; + icache_func[idx] = *func = processor_t::dispatch_table + [insn.bits % processor_t::DISPATCH_TABLE_SIZE]; + } + + return insn; + } + + // get the virtual address that caused a fault + reg_t get_badvaddr() { return badvaddr; } + + // get/set the page table base register + reg_t get_ptbr() { return ptbr; } + void set_ptbr(reg_t addr) { ptbr = addr & ~(PGSIZE-1); flush_tlb(); } + + // keep the MMU in sync with processor mode + void set_supervisor(bool sup) { supervisor = sup; } + void set_vm_enabled(bool en) { vm_enabled = en; } + + // flush the TLB and instruction cache + void flush_tlb(); + void flush_icache(); + +private: + char* mem; + size_t memsz; + reg_t badvaddr; + + reg_t ptbr; + bool supervisor; + bool vm_enabled; + + // implement a TLB for simulator performance + static const reg_t TLB_ENTRIES = 256; + long tlb_data[TLB_ENTRIES]; + reg_t tlb_insn_tag[TLB_ENTRIES]; + reg_t tlb_load_tag[TLB_ENTRIES]; + reg_t tlb_store_tag[TLB_ENTRIES]; + + // implement an instruction cache for simulator performance + static const reg_t ICACHE_ENTRIES = 256; + insn_t icache_data[ICACHE_ENTRIES]; + insn_func_t icache_func[ICACHE_ENTRIES]; + reg_t icache_tag[ICACHE_ENTRIES]; + + // finish translation on a TLB miss and upate the TLB + void* refill(reg_t addr, bool store, bool fetch); + + // perform a page table walk for a given virtual address + pte_t walk(reg_t addr); + + // translate a virtual address to a physical address + void* translate(reg_t addr, bool store, bool fetch) + { + reg_t idx = (addr >> PGSHIFT) % TLB_ENTRIES; + + reg_t* tlb_tag = fetch ? tlb_insn_tag : store ? tlb_store_tag :tlb_load_tag; + reg_t expected_tag = addr & ~(PGSIZE-1); + if(likely(tlb_tag[idx] == expected_tag)) + return (void*)(((long)addr & (PGSIZE-1)) | tlb_data[idx]); + + return refill(addr, store, fetch); + } + + friend class processor_t; +}; + +#endif diff --git a/riscv/opcodes.h b/riscv/opcodes.h new file mode 100644 index 0000000..b37b833 --- /dev/null +++ b/riscv/opcodes.h @@ -0,0 +1,272 @@ +DECLARE_INSN(movn, 0x6f7, 0x1ffff) +DECLARE_INSN(vfsstw, 0x150f, 0x1ffff) +DECLARE_INSN(remuw, 0x7bb, 0x1ffff) +DECLARE_INSN(fmin_d, 0x180d3, 0x1ffff) +DECLARE_INSN(vlsthu, 0x128b, 0x1ffff) +DECLARE_INSN(c_swsp, 0x8, 0x1f) +DECLARE_INSN(bltu, 0x363, 0x3ff) +DECLARE_INSN(vlsegstwu, 0xb0b, 0xfff) +DECLARE_INSN(movz, 0x2f7, 0x1ffff) +DECLARE_INSN(fcvt_lu_s, 0x9053, 0x3ff1ff) +DECLARE_INSN(fence_l_cv, 0x32f, 0x3ff) +DECLARE_INSN(fmin_s, 0x18053, 0x1ffff) +DECLARE_INSN(c_lw0, 0x12, 0x801f) +DECLARE_INSN(slliw, 0x9b, 0x3f83ff) +DECLARE_INSN(lb, 0x3, 0x3ff) +DECLARE_INSN(vlwu, 0x30b, 0x3fffff) +DECLARE_INSN(fcvt_d_l, 0xc0d3, 0x3ff1ff) +DECLARE_INSN(lh, 0x83, 0x3ff) +DECLARE_INSN(fcvt_d_w, 0xe0d3, 0x3ff1ff) +DECLARE_INSN(lw, 0x103, 0x3ff) +DECLARE_INSN(add, 0x33, 0x1ffff) +DECLARE_INSN(fcvt_d_s, 0x100d3, 0x3ff1ff) +DECLARE_INSN(fence_g_v, 0x2af, 0x3ff) +DECLARE_INSN(mfpcr, 0x17b, 0x7c1ffff) +DECLARE_INSN(c_fsd, 0x18, 0x1f) +DECLARE_INSN(fmax_d, 0x190d3, 0x1ffff) +DECLARE_INSN(bne, 0xe3, 0x3ff) +DECLARE_INSN(rdcycle, 0x277, 0x7ffffff) +DECLARE_INSN(fcvt_s_d, 0x11053, 0x3ff1ff) +DECLARE_INSN(vlh, 0x8b, 0x3fffff) +DECLARE_INSN(bgeu, 0x3e3, 0x3ff) +DECLARE_INSN(vflstd, 0x158b, 0x1ffff) +DECLARE_INSN(c_li, 0x0, 0x1f) +DECLARE_INSN(di, 0xfb, 0x7ffffff) +DECLARE_INSN(sltiu, 0x193, 0x3ff) +DECLARE_INSN(mtpcr, 0x1fb, 0xf801ffff) +DECLARE_INSN(vlb, 0xb, 0x3fffff) +DECLARE_INSN(stop, 0x177, 0xffffffff) +DECLARE_INSN(vld, 0x18b, 0x3fffff) +DECLARE_INSN(c_slli, 0x19, 0x1c1f) +DECLARE_INSN(break, 0xf7, 0xffffffff) +DECLARE_INSN(cflush, 0x2fb, 0xffffffff) +DECLARE_INSN(fcvt_s_w, 0xe053, 0x3ff1ff) +DECLARE_INSN(vflstw, 0x150b, 0x1ffff) +DECLARE_INSN(mul, 0x433, 0x1ffff) +DECLARE_INSN(c_lw, 0xa, 0x1f) +DECLARE_INSN(vlw, 0x10b, 0x3fffff) +DECLARE_INSN(vssegstw, 0x90f, 0xfff) +DECLARE_INSN(amominu_d, 0x19ab, 0x1ffff) +DECLARE_INSN(c_sdsp, 0x6, 0x1f) +DECLARE_INSN(utidx, 0x1f7, 0x7ffffff) +DECLARE_INSN(srli, 0x293, 0x3f03ff) +DECLARE_INSN(c_srli, 0x819, 0x1c1f) +DECLARE_INSN(c_ldsp, 0x4, 0x1f) +DECLARE_INSN(c_flw, 0x14, 0x1f) +DECLARE_INSN(c_srai32, 0x1419, 0x1c1f) +DECLARE_INSN(amominu_w, 0x192b, 0x1ffff) +DECLARE_INSN(divuw, 0x6bb, 0x1ffff) +DECLARE_INSN(mulw, 0x43b, 0x1ffff) +DECLARE_INSN(vssegstd, 0x98f, 0xfff) +DECLARE_INSN(srlw, 0x2bb, 0x1ffff) +DECLARE_INSN(vssegstb, 0x80f, 0xfff) +DECLARE_INSN(mftx_d, 0x1c0d3, 0x7c1ffff) +DECLARE_INSN(div, 0x633, 0x1ffff) +DECLARE_INSN(c_ld, 0x9, 0x1f) +DECLARE_INSN(mftx_s, 0x1c053, 0x7c1ffff) +DECLARE_INSN(vssegsth, 0x88f, 0xfff) +DECLARE_INSN(vvcfgivl, 0xf3, 0x3ff) +DECLARE_INSN(j, 0x67, 0x7f) +DECLARE_INSN(ei, 0x7b, 0x7ffffff) +DECLARE_INSN(fence, 0x12f, 0x3ff) +DECLARE_INSN(vsw, 0x10f, 0x3fffff) +DECLARE_INSN(fnmsub_s, 0x4b, 0x1ff) +DECLARE_INSN(vfssegstd, 0xd8f, 0xfff) +DECLARE_INSN(fcvt_l_s, 0x8053, 0x3ff1ff) +DECLARE_INSN(fle_s, 0x17053, 0x1ffff) +DECLARE_INSN(vsb, 0xf, 0x3fffff) +DECLARE_INSN(mffsr, 0x1d053, 0x7ffffff) +DECLARE_INSN(fdiv_s, 0x3053, 0x1f1ff) +DECLARE_INSN(vlstbu, 0x120b, 0x1ffff) +DECLARE_INSN(vsetvl, 0x2f3, 0x3fffff) +DECLARE_INSN(fle_d, 0x170d3, 0x1ffff) +DECLARE_INSN(fence_i, 0xaf, 0x3ff) +DECLARE_INSN(vlsegbu, 0x220b, 0x1ffff) +DECLARE_INSN(fnmsub_d, 0xcb, 0x1ff) +DECLARE_INSN(addw, 0x3b, 0x1ffff) +DECLARE_INSN(sll, 0xb3, 0x1ffff) +DECLARE_INSN(xor, 0x233, 0x1ffff) +DECLARE_INSN(sub, 0x10033, 0x1ffff) +DECLARE_INSN(eret, 0x27b, 0xffffffff) +DECLARE_INSN(blt, 0x263, 0x3ff) +DECLARE_INSN(vsstw, 0x110f, 0x1ffff) +DECLARE_INSN(mtfsr, 0x1f053, 0x3fffff) +DECLARE_INSN(vssth, 0x108f, 0x1ffff) +DECLARE_INSN(rem, 0x733, 0x1ffff) +DECLARE_INSN(srliw, 0x29b, 0x3f83ff) +DECLARE_INSN(lui, 0x37, 0x7f) +DECLARE_INSN(vsstb, 0x100f, 0x1ffff) +DECLARE_INSN(fcvt_s_lu, 0xd053, 0x3ff1ff) +DECLARE_INSN(vsstd, 0x118f, 0x1ffff) +DECLARE_INSN(addi, 0x13, 0x3ff) +DECLARE_INSN(vfmst, 0x1173, 0x1ffff) +DECLARE_INSN(mulh, 0x4b3, 0x1ffff) +DECLARE_INSN(fmul_s, 0x2053, 0x1f1ff) +DECLARE_INSN(vlsegsthu, 0xa8b, 0xfff) +DECLARE_INSN(srai, 0x10293, 0x3f03ff) +DECLARE_INSN(amoand_d, 0x9ab, 0x1ffff) +DECLARE_INSN(flt_d, 0x160d3, 0x1ffff) +DECLARE_INSN(sraw, 0x102bb, 0x1ffff) +DECLARE_INSN(fmul_d, 0x20d3, 0x1f1ff) +DECLARE_INSN(ld, 0x183, 0x3ff) +DECLARE_INSN(ori, 0x313, 0x3ff) +DECLARE_INSN(flt_s, 0x16053, 0x1ffff) +DECLARE_INSN(addiw, 0x1b, 0x3ff) +DECLARE_INSN(amoand_w, 0x92b, 0x1ffff) +DECLARE_INSN(feq_s, 0x15053, 0x1ffff) +DECLARE_INSN(fsgnjx_d, 0x70d3, 0x1ffff) +DECLARE_INSN(sra, 0x102b3, 0x1ffff) +DECLARE_INSN(c_lwsp, 0x5, 0x1f) +DECLARE_INSN(bge, 0x2e3, 0x3ff) +DECLARE_INSN(c_add3, 0x1c, 0x31f) +DECLARE_INSN(sraiw, 0x1029b, 0x3f83ff) +DECLARE_INSN(vssegd, 0x218f, 0x1ffff) +DECLARE_INSN(srl, 0x2b3, 0x1ffff) +DECLARE_INSN(vfmts, 0x1973, 0x1ffff) +DECLARE_INSN(fsgnjx_s, 0x7053, 0x1ffff) +DECLARE_INSN(vfmsv, 0x973, 0x3fffff) +DECLARE_INSN(feq_d, 0x150d3, 0x1ffff) +DECLARE_INSN(fcvt_d_wu, 0xf0d3, 0x3ff1ff) +DECLARE_INSN(vmts, 0x1873, 0x1ffff) +DECLARE_INSN(or, 0x333, 0x1ffff) +DECLARE_INSN(rdinstret, 0xa77, 0x7ffffff) +DECLARE_INSN(fcvt_wu_d, 0xb0d3, 0x3ff1ff) +DECLARE_INSN(subw, 0x1003b, 0x1ffff) +DECLARE_INSN(jalr_c, 0x6b, 0x3ff) +DECLARE_INSN(fmax_s, 0x19053, 0x1ffff) +DECLARE_INSN(amomaxu_d, 0x1dab, 0x1ffff) +DECLARE_INSN(c_slliw, 0x1819, 0x1c1f) +DECLARE_INSN(jalr_j, 0x16b, 0x3ff) +DECLARE_INSN(c_fld, 0x15, 0x1f) +DECLARE_INSN(vlstw, 0x110b, 0x1ffff) +DECLARE_INSN(vlsth, 0x108b, 0x1ffff) +DECLARE_INSN(xori, 0x213, 0x3ff) +DECLARE_INSN(jalr_r, 0xeb, 0x3ff) +DECLARE_INSN(amomaxu_w, 0x1d2b, 0x1ffff) +DECLARE_INSN(fcvt_wu_s, 0xb053, 0x3ff1ff) +DECLARE_INSN(vlstb, 0x100b, 0x1ffff) +DECLARE_INSN(vlstd, 0x118b, 0x1ffff) +DECLARE_INSN(c_ld0, 0x8012, 0x801f) +DECLARE_INSN(rdtime, 0x677, 0x7ffffff) +DECLARE_INSN(andi, 0x393, 0x3ff) +DECLARE_INSN(c_srli32, 0xc19, 0x1c1f) +DECLARE_INSN(fsgnjn_d, 0x60d3, 0x1ffff) +DECLARE_INSN(fnmadd_s, 0x4f, 0x1ff) +DECLARE_INSN(jal, 0x6f, 0x7f) +DECLARE_INSN(lwu, 0x303, 0x3ff) +DECLARE_INSN(vlsegstbu, 0xa0b, 0xfff) +DECLARE_INSN(c_beq, 0x10, 0x1f) +DECLARE_INSN(vlhu, 0x28b, 0x3fffff) +DECLARE_INSN(vfsstd, 0x158f, 0x1ffff) +DECLARE_INSN(c_bne, 0x11, 0x1f) +DECLARE_INSN(fnmadd_d, 0xcf, 0x1ff) +DECLARE_INSN(fence_g_cv, 0x3af, 0x3ff) +DECLARE_INSN(amoadd_d, 0x1ab, 0x1ffff) +DECLARE_INSN(c_sw, 0xd, 0x1f) +DECLARE_INSN(amomax_w, 0x152b, 0x1ffff) +DECLARE_INSN(c_move, 0x2, 0x801f) +DECLARE_INSN(fmovn, 0xef7, 0x1ffff) +DECLARE_INSN(c_fsw, 0x16, 0x1f) +DECLARE_INSN(c_j, 0x8002, 0x801f) +DECLARE_INSN(mulhsu, 0x533, 0x1ffff) +DECLARE_INSN(c_sd, 0xc, 0x1f) +DECLARE_INSN(amoadd_w, 0x12b, 0x1ffff) +DECLARE_INSN(fcvt_d_lu, 0xd0d3, 0x3ff1ff) +DECLARE_INSN(amomax_d, 0x15ab, 0x1ffff) +DECLARE_INSN(fcvt_w_d, 0xa0d3, 0x3ff1ff) +DECLARE_INSN(fmovz, 0xaf7, 0x1ffff) +DECLARE_INSN(c_or3, 0x21c, 0x31f) +DECLARE_INSN(vmvv, 0x73, 0x3fffff) +DECLARE_INSN(vfssegstw, 0xd0f, 0xfff) +DECLARE_INSN(slt, 0x133, 0x1ffff) +DECLARE_INSN(mxtf_d, 0x1e0d3, 0x3fffff) +DECLARE_INSN(sllw, 0xbb, 0x1ffff) +DECLARE_INSN(amoor_d, 0xdab, 0x1ffff) +DECLARE_INSN(slti, 0x113, 0x3ff) +DECLARE_INSN(remu, 0x7b3, 0x1ffff) +DECLARE_INSN(flw, 0x107, 0x3ff) +DECLARE_INSN(remw, 0x73b, 0x1ffff) +DECLARE_INSN(sltu, 0x1b3, 0x1ffff) +DECLARE_INSN(slli, 0x93, 0x3f03ff) +DECLARE_INSN(c_and3, 0x31c, 0x31f) +DECLARE_INSN(vssegw, 0x210f, 0x1ffff) +DECLARE_INSN(amoor_w, 0xd2b, 0x1ffff) +DECLARE_INSN(vsd, 0x18f, 0x3fffff) +DECLARE_INSN(beq, 0x63, 0x3ff) +DECLARE_INSN(fld, 0x187, 0x3ff) +DECLARE_INSN(mxtf_s, 0x1e053, 0x3fffff) +DECLARE_INSN(fsub_s, 0x1053, 0x1f1ff) +DECLARE_INSN(and, 0x3b3, 0x1ffff) +DECLARE_INSN(vtcfgivl, 0x1f3, 0x3ff) +DECLARE_INSN(lbu, 0x203, 0x3ff) +DECLARE_INSN(vf, 0x3f3, 0xf80003ff) +DECLARE_INSN(vlsegstw, 0x90b, 0xfff) +DECLARE_INSN(syscall, 0x77, 0xffffffff) +DECLARE_INSN(fsgnj_s, 0x5053, 0x1ffff) +DECLARE_INSN(c_addi, 0x1, 0x1f) +DECLARE_INSN(vfmvv, 0x173, 0x3fffff) +DECLARE_INSN(vlstwu, 0x130b, 0x1ffff) +DECLARE_INSN(c_sub3, 0x11c, 0x31f) +DECLARE_INSN(vsh, 0x8f, 0x3fffff) +DECLARE_INSN(vlsegstb, 0x80b, 0xfff) +DECLARE_INSN(vlsegstd, 0x98b, 0xfff) +DECLARE_INSN(vflsegd, 0x258b, 0x1ffff) +DECLARE_INSN(vflsegw, 0x250b, 0x1ffff) +DECLARE_INSN(vlsegsth, 0x88b, 0xfff) +DECLARE_INSN(fsgnj_d, 0x50d3, 0x1ffff) +DECLARE_INSN(vflsegstw, 0xd0b, 0xfff) +DECLARE_INSN(c_sub, 0x801a, 0x801f) +DECLARE_INSN(mulhu, 0x5b3, 0x1ffff) +DECLARE_INSN(fcvt_l_d, 0x80d3, 0x3ff1ff) +DECLARE_INSN(vmsv, 0x873, 0x3fffff) +DECLARE_INSN(vmst, 0x1073, 0x1ffff) +DECLARE_INSN(fadd_d, 0xd3, 0x1f1ff) +DECLARE_INSN(fcvt_s_wu, 0xf053, 0x3ff1ff) +DECLARE_INSN(rdnpc, 0x26b, 0x7ffffff) +DECLARE_INSN(fcvt_s_l, 0xc053, 0x3ff1ff) +DECLARE_INSN(vflsegstd, 0xd8b, 0xfff) +DECLARE_INSN(c_add, 0x1a, 0x801f) +DECLARE_INSN(fcvt_lu_d, 0x90d3, 0x3ff1ff) +DECLARE_INSN(vfld, 0x58b, 0x3fffff) +DECLARE_INSN(fsub_d, 0x10d3, 0x1f1ff) +DECLARE_INSN(fmadd_s, 0x43, 0x1ff) +DECLARE_INSN(fcvt_w_s, 0xa053, 0x3ff1ff) +DECLARE_INSN(vssegh, 0x208f, 0x1ffff) +DECLARE_INSN(fsqrt_s, 0x4053, 0x3ff1ff) +DECLARE_INSN(c_srai, 0x1019, 0x1c1f) +DECLARE_INSN(amomin_w, 0x112b, 0x1ffff) +DECLARE_INSN(fsgnjn_s, 0x6053, 0x1ffff) +DECLARE_INSN(c_slli32, 0x419, 0x1c1f) +DECLARE_INSN(vlsegwu, 0x230b, 0x1ffff) +DECLARE_INSN(vfsw, 0x50f, 0x3fffff) +DECLARE_INSN(amoswap_d, 0x5ab, 0x1ffff) +DECLARE_INSN(fence_l_v, 0x22f, 0x3ff) +DECLARE_INSN(fsqrt_d, 0x40d3, 0x3ff1ff) +DECLARE_INSN(vflw, 0x50b, 0x3fffff) +DECLARE_INSN(fdiv_d, 0x30d3, 0x1f1ff) +DECLARE_INSN(fmadd_d, 0xc3, 0x1ff) +DECLARE_INSN(divw, 0x63b, 0x1ffff) +DECLARE_INSN(amomin_d, 0x11ab, 0x1ffff) +DECLARE_INSN(divu, 0x6b3, 0x1ffff) +DECLARE_INSN(amoswap_w, 0x52b, 0x1ffff) +DECLARE_INSN(vfsd, 0x58f, 0x3fffff) +DECLARE_INSN(fadd_s, 0x53, 0x1f1ff) +DECLARE_INSN(vlsegb, 0x200b, 0x1ffff) +DECLARE_INSN(fsd, 0x1a7, 0x3ff) +DECLARE_INSN(vlsegd, 0x218b, 0x1ffff) +DECLARE_INSN(vlsegh, 0x208b, 0x1ffff) +DECLARE_INSN(sw, 0x123, 0x3ff) +DECLARE_INSN(fmsub_s, 0x47, 0x1ff) +DECLARE_INSN(vfssegw, 0x250f, 0x1ffff) +DECLARE_INSN(c_addiw, 0x1d, 0x1f) +DECLARE_INSN(lhu, 0x283, 0x3ff) +DECLARE_INSN(sh, 0xa3, 0x3ff) +DECLARE_INSN(vlsegw, 0x210b, 0x1ffff) +DECLARE_INSN(fsw, 0x127, 0x3ff) +DECLARE_INSN(vlbu, 0x20b, 0x3fffff) +DECLARE_INSN(sb, 0x23, 0x3ff) +DECLARE_INSN(fmsub_d, 0xc7, 0x1ff) +DECLARE_INSN(vlseghu, 0x228b, 0x1ffff) +DECLARE_INSN(vssegb, 0x200f, 0x1ffff) +DECLARE_INSN(vfssegd, 0x258f, 0x1ffff) +DECLARE_INSN(sd, 0x1a3, 0x3ff) diff --git a/riscv/processor.cc b/riscv/processor.cc new file mode 100644 index 0000000..2a53cca --- /dev/null +++ b/riscv/processor.cc @@ -0,0 +1,240 @@ +#include "processor.h" +#include "common.h" +#include "config.h" +#include "sim.h" +#include +#include +#include +#include +#include +#include + +processor_t::processor_t(sim_t* _sim, mmu_t* _mmu, uint32_t _id) + : sim(*_sim), mmu(*_mmu), id(_id), utidx(0) +{ + reset(); + + // create microthreads + for (int i=0; i> CAUSE_IP_SHIFT; + interrupts &= (sr & SR_IM) >> SR_IM_SHIFT; + + if(interrupts && (sr & SR_ET)) + throw trap_interrupt; +} + +void processor_t::step(size_t n, bool noisy) +{ + if(!run) + return; + + size_t i = 0; + while(1) try + { + take_interrupt(); + + mmu_t& _mmu = mmu; + insn_t insn; + insn_func_t func; + reg_t npc = pc; + + // execute_insn fetches and executes one instruction + #define execute_insn(noisy) \ + do { \ + insn = _mmu.load_insn(npc, sr & SR_EC, &func); \ + if(noisy) disasm(insn,pc); \ + npc = func(this, insn, npc); \ + pc = npc; \ + } while(0) + + if(noisy) for( ; i < n; i++) // print out instructions as we go + execute_insn(true); + else + { + // unrolled for speed + for( ; n > 3 && i < n-3; i+=4) + { + execute_insn(false); + execute_insn(false); + execute_insn(false); + execute_insn(false); + } + for( ; i < n; i++) + execute_insn(false); + } + + break; + } + catch(trap_t t) + { + // an exception occurred in the target processor + i++; + take_trap(t,noisy); + } + catch(vt_command_t cmd) + { + // this microthread has finished + i++; + assert(cmd == vt_command_stop); + break; + } + catch(halt_t t) + { + // sleep until IPI + reset(); + return; + } + + cycle += i; + + // update timer and possibly register a timer interrupt + uint32_t old_count = count; + count += i; + if(old_count < compare && uint64_t(old_count) + i >= compare) + cause |= 1 << (TIMER_IRQ+CAUSE_IP_SHIFT); +} + +void processor_t::take_trap(trap_t t, bool noisy) +{ + if(noisy) + printf("core %3d: trap %s, pc 0x%016llx\n", + id, trap_name(t), (unsigned long long)pc); + + // switch to supervisor, set previous supervisor bit, disable traps + set_sr((((sr & ~SR_ET) | SR_S) & ~SR_PS) | ((sr & SR_S) ? SR_PS : 0)); + cause = (cause & ~CAUSE_EXCCODE) | (t << CAUSE_EXCCODE_SHIFT); + epc = pc; + pc = evec; + badvaddr = mmu.get_badvaddr(); +} + +void processor_t::deliver_ipi() +{ + cause |= 1 << (IPI_IRQ+CAUSE_IP_SHIFT); + run = true; +} + +void processor_t::disasm(insn_t insn, reg_t pc) +{ + printf("core %3d: 0x%016llx (0x%08x) ",id,(unsigned long long)pc,insn.bits); + + #ifdef RISCV_HAVE_LIBOPCODES + disassemble_info info; + INIT_DISASSEMBLE_INFO(info, stdout, fprintf); + info.flavour = bfd_target_unknown_flavour; + info.arch = bfd_arch_mips; + info.mach = 101; // XXX bfd_mach_mips_riscv requires modified bfd.h + info.endian = BFD_ENDIAN_LITTLE; + info.buffer = (bfd_byte*)&insn; + info.buffer_length = sizeof(insn); + info.buffer_vma = pc; + + int ret = print_insn_little_mips(pc, &info); + assert(ret == insn_length(insn.bits)); + #else + printf("unknown"); + #endif + printf("\n"); +} diff --git a/riscv/processor.h b/riscv/processor.h new file mode 100644 index 0000000..3bc1177 --- /dev/null +++ b/riscv/processor.h @@ -0,0 +1,89 @@ +#ifndef _RISCV_PROCESSOR_H +#define _RISCV_PROCESSOR_H + +#include "decode.h" +#include +#include "trap.h" + +#define MAX_UTS 2048 + +class processor_t; +class mmu_t; +typedef reg_t (*insn_func_t)(processor_t*, insn_t, reg_t); +class sim_t; + +// this class represents one processor in a RISC-V machine. +class processor_t +{ +public: + processor_t(sim_t* _sim, mmu_t* _mmu, uint32_t _id); + ~processor_t(); + + void step(size_t n, bool noisy); // run for n cycles + void deliver_ipi(); // register an interprocessor interrupt + +private: + sim_t& sim; + mmu_t& mmu; // main memory is always accessed via the mmu + + // user-visible architected state + reg_t XPR[NXPR]; + freg_t FPR[NFPR]; + reg_t pc; + uint32_t fsr; + + // counters + reg_t cycle; + + // privileged control registers + reg_t epc; + reg_t badvaddr; + reg_t cause; + reg_t evec; + reg_t pcr_k0; + reg_t pcr_k1; + uint32_t id; + uint32_t sr; // only modify the status register using set_sr() + uint32_t count; + uint32_t compare; + + // # of bits in an XPR (32 or 64). (redundant with sr) + int xprlen; + + // is this processor running? (deliver_ipi() sets this) + bool run; + + // functions + void reset(); // resets architected state; halts processor if it was running + void take_interrupt(); // take a trap if any interrupts are pending + void set_sr(uint32_t val); // set the status register + void set_fsr(uint32_t val); // set the floating-point status register + void take_trap(trap_t t, bool noisy); // take an exception + void disasm(insn_t insn, reg_t pc); // disassemble and print an instruction + + // vector stuff + void vcfg(); + void setvl(int vlapp); + + reg_t vecbanks; + uint32_t vecbanks_count; + + bool utmode; + uint32_t utidx; + int vlmax; + int vl; + int nxfpr_bank; + int nxpr_use; + int nfpr_use; + processor_t* uts[MAX_UTS]; + + // this constructor is used for each of the uts + processor_t(sim_t* _sim, mmu_t* _mmu, uint32_t _id, uint32_t _utidx); + + friend class sim_t; + friend class mmu_t; + + #include "dispatch.h" +}; + +#endif diff --git a/riscv/riscv-isa-run.cc b/riscv/riscv-isa-run.cc new file mode 100644 index 0000000..a0af8de --- /dev/null +++ b/riscv/riscv-isa-run.cc @@ -0,0 +1,56 @@ +#include +#include "sim.h" +#include "htif.h" + +static void help() +{ + fprintf(stderr, "usage: riscv-isa-run -f -t [additional options]\n"); + fprintf(stderr, "Options:\n"); + fprintf(stderr, " -f From-host pipe file descriptor\n"); + fprintf(stderr, " -t To-host pipe file descriptor\n"); + fprintf(stderr, " -p Simulate processors\n"); + fprintf(stderr, " -d Interactive debug mode\n"); + exit(1); +} + +int main(int argc, char** argv) +{ + bool debug = false; + int nprocs = 1; + int fromhost_fd = -1, tohost_fd = -1; + + // parse command-line arguments + for(int c; (c = getopt(argc,argv,"hdp:f:t:")) != -1; ) + { + switch(c) + { + case 'd': + debug = true; + break; + case 'p': + nprocs = atoi(optarg); + break; + case 'f': + fromhost_fd = atoi(optarg); + break; + case 't': + tohost_fd = atoi(optarg); + break; + default: + fprintf(stderr, "unknown option: -%c", optopt); + case 'h': + help(); + } + } + + // we require -f and -t to be specified so we can communicate with the host + if(fromhost_fd == -1 || tohost_fd == -1) + help(); + + // initialize host-target interface + htif_t htif(tohost_fd, fromhost_fd); + + // initalize simulator and run to completion + sim_t s(nprocs, &htif); + s.run(debug); +} diff --git a/riscv/riscv.ac b/riscv/riscv.ac new file mode 100644 index 0000000..5766d6d --- /dev/null +++ b/riscv/riscv.ac @@ -0,0 +1,32 @@ +AC_ARG_ENABLE([fpu], AS_HELP_STRING([--disable-fpu], [Disable floating-point])) +AS_IF([test "x$enable_fpu" != "xno"], [ + AC_DEFINE([RISCV_ENABLE_FPU],,[Define if floating-point instructions are supported]) +]) + +AC_ARG_ENABLE([64bit], AS_HELP_STRING([--disable-64bit], [Disable 64-bit mode])) +AS_IF([test "x$enable_64bit" != "xno"], [ + AC_DEFINE([RISCV_ENABLE_64BIT],,[Define if 64-bit mode is supported]) +]) + +AC_ARG_ENABLE([rvc], AS_HELP_STRING([--enable-rvc], [Enable instruction compression])) +AS_IF([test "x$enable_rvc" = "xyes"], [ + AC_DEFINE([RISCV_ENABLE_RVC],,[Define if instruction compression is supported]) +]) + +AC_ARG_ENABLE([vec], AS_HELP_STRING([--disable-vec], [Disable vector processor])) +AS_IF([test "x$enable_vec" != "xno"], [ + AC_DEFINE([RISCV_ENABLE_VEC],,[Define if vector processor is supported]) +]) + +libopc=`dirname \`which riscv-gcc\``/../`$ac_config_guess`/riscv/lib/libopcodes.a +AC_CHECK_FILES([$libopc],[have_libopcodes="yes"],[have_libopcodes="no"]) + +AC_SEARCH_LIBS([bfd_init],[bfd],[],[have_libopcodes="no"]) + +AS_IF([test "$have_libopcodes" = "no"],[ + AC_MSG_WARN([Could not find opcodes library]) + AC_MSG_WARN([Build will not include disassembly support]) +],[ + LIBS="$libopc $LIBS" + AC_DEFINE([RISCV_HAVE_LIBOPCODES],,[Define if libopcodes exists]) +]) diff --git a/riscv/riscv.mk.in b/riscv/riscv.mk.in new file mode 100644 index 0000000..50dc76a --- /dev/null +++ b/riscv/riscv.mk.in @@ -0,0 +1,50 @@ +riscv_subproject_deps = \ + softfloat_riscv \ + softfloat \ + +riscv_hdrs = \ + htif.h \ + common.h \ + decode.h \ + mmu.h \ + processor.h \ + sim.h \ + trap.h \ + opcodes.h \ + insn_header.h \ + dispatch.h \ + +NDISPATCH := 10 +DISPATCH_SRCS := \ + dispatch0.cc \ + dispatch1.cc \ + dispatch2.cc \ + dispatch3.cc \ + dispatch4.cc \ + dispatch5.cc \ + dispatch6.cc \ + dispatch7.cc \ + dispatch8.cc \ + dispatch9.cc \ + dispatch10.cc \ + +$(DISPATCH_SRCS): %.cc: dispatch $(wildcard insns/*.h) $(riscv_hdrs) + $< $(subst dispatch,,$(subst .cc,,$@)) $(NDISPATCH) 1024 < $(src_dir)/riscv/opcodes.h > $@ + +$(src_dir)/riscv/dispatch.h: %.h: dispatch + $< $(NDISPATCH) 1024 < $(src_dir)/riscv/opcodes.h > $@ + +riscv_srcs = \ + htif.cc \ + processor.cc \ + sim.cc \ + interactive.cc \ + trap.cc \ + icsim.cc \ + mmu.cc \ + $(DISPATCH_SRCS) \ + +riscv_test_srcs = + +riscv_install_prog_srcs = \ + riscv-isa-run.cc \ diff --git a/riscv/sim.cc b/riscv/sim.cc new file mode 100644 index 0000000..85d0995 --- /dev/null +++ b/riscv/sim.cc @@ -0,0 +1,92 @@ +#include "sim.h" +#include "htif.h" +#include +#include +#include +#include +#include + +sim_t::sim_t(int _nprocs, htif_t* _htif) + : htif(_htif), + procs(_nprocs), + running(false) +{ + // allocate target machine's memory, shrinking it as necessary + // until the allocation succeeds + + size_t memsz0 = sizeof(size_t) == 8 ? 0x100000000ULL : 0x70000000UL; + size_t quantum = std::max(PGSIZE, (reg_t)sysconf(_SC_PAGESIZE)); + memsz0 = memsz0/quantum*quantum; + + memsz = memsz0; + mem = (char*)mmap64(NULL, memsz, PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0); + + if(mem == MAP_FAILED) + { + while(mem == MAP_FAILED && (memsz = memsz*10/11/quantum*quantum)) + mem = (char*)mmap64(NULL, memsz, PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0); + assert(mem != MAP_FAILED); + fprintf(stderr, "warning: only got %lu bytes of target mem (wanted %lu)\n", + (unsigned long)memsz, (unsigned long)memsz0); + } + + mmu = new mmu_t(mem, memsz); + + for(size_t i = 0; i < num_cores(); i++) + procs[i] = new processor_t(this, new mmu_t(mem, memsz), i); + + htif->init(this); +} + +sim_t::~sim_t() +{ + for(size_t i = 0; i < num_cores(); i++) + { + mmu_t* pmmu = &procs[i]->mmu; + delete procs[i]; + delete pmmu; + } + delete mmu; + munmap(mem, memsz); +} + +void sim_t::set_tohost(reg_t val) +{ + fromhost = 0; + tohost = val; +} + +reg_t sim_t::get_fromhost() +{ + htif->wait_for_fromhost_write(); + return fromhost; +} + +void sim_t::send_ipi(reg_t who) +{ + if(who < num_cores()) + procs[who]->deliver_ipi(); +} + +void sim_t::run(bool debug) +{ + htif->wait_for_start(); + + // start core 0 + send_ipi(0); + + for(running = true; running; ) + { + if(!debug) + step_all(100,100,false); + else + interactive(); + } +} + +void sim_t::step_all(size_t n, size_t interleave, bool noisy) +{ + for(size_t j = 0; j < n; j+=interleave) + for(int i = 0; i < (int)num_cores(); i++) + procs[i]->step(interleave,noisy); +} diff --git a/riscv/sim.h b/riscv/sim.h new file mode 100644 index 0000000..c4058d3 --- /dev/null +++ b/riscv/sim.h @@ -0,0 +1,82 @@ +#ifndef _RISCV_SIM_H +#define _RISCV_SIM_H + +#include +#include +#include "processor.h" +#include "mmu.h" + +class htif_t; + +// this class encapsulates the processors and memory in a RISC-V machine. +class sim_t +{ +public: + sim_t(int _nprocs, htif_t* _htif); + ~sim_t(); + + // run the simulation to completion + void run(bool debug); + + // communicate with the host machine + void set_tohost(reg_t val); + reg_t get_fromhost(); + + // deliver an IPI to a specific processor + void send_ipi(reg_t who); + + // returns the number of processors in this simulator + size_t num_cores() { return procs.size(); } + +private: + htif_t* htif; + + // global registers for communication with host machine + reg_t tohost; + reg_t fromhost; + + // main memory, shared between processors + char* mem; + size_t memsz; // memory size in bytes + mmu_t* mmu; // debug port into main memory + + // processors + std::vector procs; + + // terminate the simulation loop after the current iteration + void stop() { running = false; } + bool running; + + // run each processor for n instructions; interleave instructions are + // run on a processor before moving on to the next processor. + // interleave must divide n. + // if noisy, print out the instructions as they execute. + void step_all(size_t n, size_t interleave, bool noisy); + + // presents a prompt for introspection into the simulation + void interactive(); + + // functions that help implement interactive() + void interactive_quit(const std::string& cmd, const std::vector& args); + void interactive_run(const std::string& cmd, const std::vector& args, bool noisy); + void interactive_run_noisy(const std::string& cmd, const std::vector& args); + void interactive_run_silent(const std::string& cmd, const std::vector& args); + void interactive_run_proc(const std::string& cmd, const std::vector& args, bool noisy); + void interactive_run_proc_noisy(const std::string& cmd, const std::vector& args); + void interactive_run_proc_silent(const std::string& cmd, const std::vector& args); + void interactive_reg(const std::string& cmd, const std::vector& args); + void interactive_fregs(const std::string& cmd, const std::vector& args); + void interactive_fregd(const std::string& cmd, const std::vector& args); + void interactive_mem(const std::string& cmd, const std::vector& args); + void interactive_str(const std::string& cmd, const std::vector& args); + void interactive_until(const std::string& cmd, const std::vector& args); + reg_t get_reg(const std::vector& args); + reg_t get_freg(const std::vector& args); + reg_t get_mem(const std::vector& args); + reg_t get_pc(const std::vector& args); + reg_t get_tohost(const std::vector& args); + + friend class htif_t; +}; + +#endif diff --git a/riscv/trap.cc b/riscv/trap.cc new file mode 100644 index 0000000..d873a19 --- /dev/null +++ b/riscv/trap.cc @@ -0,0 +1,10 @@ +#include "trap.h" + +const char* trap_name(trap_t t) +{ + #define DECLARE_TRAP(x) "trap_"#x + static const char* names[] = { TRAP_LIST }; + #undef DECLARE_TRAP + + return (unsigned)t >= sizeof(names)/sizeof(names[0]) ? "unknown" : names[t]; +} diff --git a/riscv/trap.h b/riscv/trap.h new file mode 100644 index 0000000..ad5491a --- /dev/null +++ b/riscv/trap.h @@ -0,0 +1,44 @@ +#ifndef _RISCV_TRAP_H +#define _RISCV_TRAP_H + +#define TRAP_LIST \ + DECLARE_TRAP(instruction_address_misaligned), \ + DECLARE_TRAP(instruction_access_fault), \ + DECLARE_TRAP(illegal_instruction), \ + DECLARE_TRAP(privileged_instruction), \ + DECLARE_TRAP(fp_disabled), \ + DECLARE_TRAP(interrupt), \ + DECLARE_TRAP(syscall), \ + DECLARE_TRAP(breakpoint), \ + DECLARE_TRAP(load_address_misaligned), \ + DECLARE_TRAP(store_address_misaligned), \ + DECLARE_TRAP(load_access_fault), \ + DECLARE_TRAP(store_access_fault), \ + DECLARE_TRAP(vector_disabled), \ + DECLARE_TRAP(vector_bank), \ + DECLARE_TRAP(vector_illegal_instruction), \ + DECLARE_TRAP(reserved1), \ + DECLARE_TRAP(reserved2), \ + DECLARE_TRAP(reserved3), \ + DECLARE_TRAP(int0), \ + DECLARE_TRAP(int1), \ + DECLARE_TRAP(int2), \ + DECLARE_TRAP(int3), \ + DECLARE_TRAP(int4), \ + DECLARE_TRAP(int5), \ + DECLARE_TRAP(int6), \ + DECLARE_TRAP(int7), \ + +#define DECLARE_TRAP(x) trap_##x +enum trap_t +{ + TRAP_LIST + NUM_TRAPS +}; +#undef DECLARE_TRAP + +struct halt_t {}; // thrown to stop the processor from running + +extern "C" const char* trap_name(trap_t t); + +#endif diff --git a/scripts/config.guess b/scripts/config.guess new file mode 100755 index 0000000..f32079a --- /dev/null +++ b/scripts/config.guess @@ -0,0 +1,1526 @@ +#! /bin/sh +# Attempt to guess a canonical system name. +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, +# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 +# Free Software Foundation, Inc. + +timestamp='2008-01-23' + +# 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 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA +# 02110-1301, USA. +# +# 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. + + +# Originally written by Per Bothner . +# Please send patches to . Submit a context +# diff and a properly formatted ChangeLog entry. +# +# This script attempts to guess a canonical system name similar to +# config.sub. If it succeeds, it prints the system name on stdout, and +# exits with 0. Otherwise, it exits with 1. +# +# The plan is that this can be called by configure scripts if you +# don't specify an explicit build system type. + +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] + +Output the configuration name of the system \`$me' is run on. + +Operation modes: + -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 (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, +2002, 2003, 2004, 2005, 2006, 2007, 2008 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 + +trap 'exit 1' 1 2 15 + +# 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. + +set_cc_for_build=' +trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ; +trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ; +: ${TMPDIR=/tmp} ; + { 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) ; } || + { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } || + { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ; +dummy=$tmp/dummy ; +tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ; +case $CC_FOR_BUILD,$HOST_CC,$CC in + ,,) echo "int x;" > $dummy.c ; + for c in cc gcc c89 c99 ; do + if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then + CC_FOR_BUILD="$c"; 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 ; set_cc_for_build= ;' + +# 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) >/dev/null 2>&1 ; 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 + +# 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 tupples: *-*-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". + sysctl="sysctl -n hw.machine_arch" + UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \ + /usr/sbin/$sysctl 2>/dev/null || echo unknown)` + case "${UNAME_MACHINE_ARCH}" in + armeb) machine=armeb-unknown ;; + arm*) machine=arm-unknown ;; + sh3el) machine=shl-unknown ;; + sh3eb) machine=sh-unknown ;; + sh5el) machine=sh5le-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. + case "${UNAME_MACHINE_ARCH}" in + arm*|i386|m68k|ns32k|sh3*|sparc|vax) + eval $set_cc_for_build + if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep __ELF__ >/dev/null + 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 + # 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/[-_].*/\./'` + ;; + esac + # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: + # contains redundant information, the shorter form: + # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. + echo "${machine}-${os}${release}" + exit ;; + *:OpenBSD:*:*) + UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` + echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} + exit ;; + *:ekkoBSD:*:*) + echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE} + exit ;; + *:SolidBSD:*:*) + echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE} + exit ;; + macppc:MirBSD:*:*) + echo powerpc-unknown-mirbsd${UNAME_RELEASE} + exit ;; + *:MirBSD:*:*) + echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE} + exit ;; + alpha:OSF1:*:*) + 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. + echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + exit ;; + Alpha\ *:Windows_NT*:*) + # How do we know it's Interix rather than the generic POSIX subsystem? + # Should we change UNAME_MACHINE based on the output of uname instead + # of the specific Alpha model? + echo alpha-pc-interix + exit ;; + 21064:Windows_NT:50:3) + echo alpha-dec-winnt3.5 + exit ;; + Amiga*:UNIX_System_V:4.0:*) + echo m68k-unknown-sysv4 + exit ;; + *:[Aa]miga[Oo][Ss]:*:*) + echo ${UNAME_MACHINE}-unknown-amigaos + exit ;; + *:[Mm]orph[Oo][Ss]:*:*) + echo ${UNAME_MACHINE}-unknown-morphos + exit ;; + *:OS/390:*:*) + echo i370-ibm-openedition + exit ;; + *:z/VM:*:*) + echo s390-ibm-zvmoe + exit ;; + *:OS400:*:*) + echo powerpc-ibm-os400 + exit ;; + arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) + echo arm-acorn-riscix${UNAME_RELEASE} + exit ;; + arm:riscos:*:*|arm:RISCOS:*:*) + echo arm-unknown-riscos + exit ;; + SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) + echo hppa1.1-hitachi-hiuxmpp + exit ;; + Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) + # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. + if test "`(/bin/universe) 2>/dev/null`" = att ; then + echo pyramid-pyramid-sysv3 + else + echo pyramid-pyramid-bsd + fi + exit ;; + NILE*:*:*:dcosx) + echo pyramid-pyramid-svr4 + exit ;; + DRS?6000:unix:4.0:6*) + echo sparc-icl-nx6 + exit ;; + DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) + case `/usr/bin/uname -p` in + sparc) echo sparc-icl-nx7; exit ;; + esac ;; + sun4H:SunOS:5.*:*) + echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) + echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) + echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + 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. + echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + 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'. + echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` + exit ;; + sun3*:SunOS:*:*) + echo m68k-sun-sunos${UNAME_RELEASE} + exit ;; + 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) + echo m68k-sun-sunos${UNAME_RELEASE} + ;; + sun4) + echo sparc-sun-sunos${UNAME_RELEASE} + ;; + esac + exit ;; + aushp:SunOS:*:*) + echo sparc-auspex-sunos${UNAME_RELEASE} + exit ;; + # 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:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit ;; + atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit ;; + *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit ;; + milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) + echo m68k-milan-mint${UNAME_RELEASE} + exit ;; + hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) + echo m68k-hades-mint${UNAME_RELEASE} + exit ;; + *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) + echo m68k-unknown-mint${UNAME_RELEASE} + exit ;; + m68k:machten:*:*) + echo m68k-apple-machten${UNAME_RELEASE} + exit ;; + powerpc:machten:*:*) + echo powerpc-apple-machten${UNAME_RELEASE} + exit ;; + RISC*:Mach:*:*) + echo mips-dec-mach_bsd4.3 + exit ;; + RISC*:ULTRIX:*:*) + echo mips-dec-ultrix${UNAME_RELEASE} + exit ;; + VAX*:ULTRIX*:*:*) + echo vax-dec-ultrix${UNAME_RELEASE} + exit ;; + 2020:CLIX:*:* | 2430:CLIX:*:*) + echo clipper-intergraph-clix${UNAME_RELEASE} + exit ;; + mips:*:*:UMIPS | mips:*:*:RISCos) + eval $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; } + echo mips-mips-riscos${UNAME_RELEASE} + exit ;; + Motorola:PowerMAX_OS:*:*) + echo powerpc-motorola-powermax + exit ;; + Motorola:*:4.3:PL8-*) + echo powerpc-harris-powermax + exit ;; + Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) + echo powerpc-harris-powermax + exit ;; + Night_Hawk:Power_UNIX:*:*) + echo powerpc-harris-powerunix + exit ;; + m88k:CX/UX:7*:*) + echo m88k-harris-cxux7 + exit ;; + m88k:*:4*:R4*) + echo m88k-motorola-sysv4 + exit ;; + m88k:*:3*:R3*) + echo m88k-motorola-sysv3 + exit ;; + AViiON:dgux:*:*) + # DG/UX returns AViiON for all architectures + UNAME_PROCESSOR=`/usr/bin/uname -p` + if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] + then + if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ + [ ${TARGET_BINARY_INTERFACE}x = x ] + then + echo m88k-dg-dgux${UNAME_RELEASE} + else + echo m88k-dg-dguxbcs${UNAME_RELEASE} + fi + else + echo i586-dg-dgux${UNAME_RELEASE} + fi + exit ;; + M88*:DolphinOS:*:*) # DolphinOS (SVR3) + echo m88k-dolphin-sysv3 + exit ;; + M88*:*:R3*:*) + # Delta 88k system running SVR3 + echo m88k-motorola-sysv3 + exit ;; + XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) + echo m88k-tektronix-sysv3 + exit ;; + Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) + echo m68k-tektronix-bsd + exit ;; + *:IRIX*:*:*) + echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` + exit ;; + ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. + echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id + exit ;; # Note that: echo "'`uname -s`'" gives 'AIX ' + i*86:AIX:*:*) + echo i386-ibm-aix + exit ;; + ia64:AIX:*:*) + if [ -x /usr/bin/oslevel ] ; then + IBM_REV=`/usr/bin/oslevel` + else + IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + fi + echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} + exit ;; + *:AIX:2:3) + if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then + eval $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 + echo "$SYSTEM_NAME" + else + echo rs6000-ibm-aix3.2.5 + fi + elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then + echo rs6000-ibm-aix3.2.4 + else + echo rs6000-ibm-aix3.2 + fi + exit ;; + *:AIX:*:[456]) + 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 [ -x /usr/bin/oslevel ] ; then + IBM_REV=`/usr/bin/oslevel` + else + IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + fi + echo ${IBM_ARCH}-ibm-aix${IBM_REV} + exit ;; + *:AIX:*:*) + echo rs6000-ibm-aix + exit ;; + ibmrt:4.4BSD:*|romp-ibm:BSD:*) + echo romp-ibm-bsd4.4 + exit ;; + ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and + echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to + exit ;; # report: romp-ibm BSD 4.3 + *:BOSX:*:*) + echo rs6000-bull-bosx + exit ;; + DPX/2?00:B.O.S.:*:*) + echo m68k-bull-sysv3 + exit ;; + 9000/[34]??:4.3bsd:1.*:*) + echo m68k-hp-bsd + exit ;; + hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) + echo m68k-hp-bsd4.4 + exit ;; + 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 [ -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 [ "${HP_ARCH}" = "" ]; then + eval $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 [ ${HP_ARCH} = "hppa2.0w" ] + then + eval $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 __LP64__ >/dev/null + then + HP_ARCH="hppa2.0w" + else + HP_ARCH="hppa64" + fi + fi + echo ${HP_ARCH}-hp-hpux${HPUX_REV} + exit ;; + ia64:HP-UX:*:*) + HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` + echo ia64-hp-hpux${HPUX_REV} + exit ;; + 3050*:HI-UX:*:*) + eval $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; } + echo unknown-hitachi-hiuxwe2 + exit ;; + 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) + echo hppa1.1-hp-bsd + exit ;; + 9000/8??:4.3bsd:*:*) + echo hppa1.0-hp-bsd + exit ;; + *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) + echo hppa1.0-hp-mpeix + exit ;; + hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) + echo hppa1.1-hp-osf + exit ;; + hp8??:OSF1:*:*) + echo hppa1.0-hp-osf + exit ;; + i*86:OSF1:*:*) + if [ -x /usr/sbin/sysversion ] ; then + echo ${UNAME_MACHINE}-unknown-osf1mk + else + echo ${UNAME_MACHINE}-unknown-osf1 + fi + exit ;; + parisc*:Lites*:*:*) + echo hppa1.1-hp-lites + exit ;; + C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) + echo c1-convex-bsd + exit ;; + 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*:*) + echo c34-convex-bsd + exit ;; + C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) + echo c38-convex-bsd + exit ;; + C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) + echo c4-convex-bsd + exit ;; + CRAY*Y-MP:*:*:*) + echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + 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:*:*:*) + echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*T3E:*:*:*) + echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*SV1:*:*:*) + echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + *:UNICOS/mp:*:*) + echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + 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/ /_/'` + echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" + exit ;; + 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/ /_/'` + echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" + exit ;; + i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) + echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} + exit ;; + sparc*:BSD/OS:*:*) + echo sparc-unknown-bsdi${UNAME_RELEASE} + exit ;; + *:BSD/OS:*:*) + echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} + exit ;; + *:FreeBSD:*:*) + case ${UNAME_MACHINE} in + pc98) + echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + amd64) + echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + *) + echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + esac + exit ;; + i*:CYGWIN*:*) + echo ${UNAME_MACHINE}-pc-cygwin + exit ;; + *:MINGW*:*) + echo ${UNAME_MACHINE}-pc-mingw32 + exit ;; + i*:windows32*:*) + # uname -m includes "-pc" on this system. + echo ${UNAME_MACHINE}-mingw32 + exit ;; + i*:PW*:*) + echo ${UNAME_MACHINE}-pc-pw32 + exit ;; + *:Interix*:[3456]*) + case ${UNAME_MACHINE} in + x86) + echo i586-pc-interix${UNAME_RELEASE} + exit ;; + EM64T | authenticamd) + echo x86_64-unknown-interix${UNAME_RELEASE} + exit ;; + IA64) + echo ia64-unknown-interix${UNAME_RELEASE} + exit ;; + esac ;; + [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*) + echo i${UNAME_MACHINE}-pc-mks + exit ;; + i*:Windows_NT*:* | Pentium*:Windows_NT*:*) + # How do we know it's Interix rather than the generic POSIX subsystem? + # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we + # UNAME_MACHINE based on the output of uname instead of i386? + echo i586-pc-interix + exit ;; + i*:UWIN*:*) + echo ${UNAME_MACHINE}-pc-uwin + exit ;; + amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) + echo x86_64-unknown-cygwin + exit ;; + p*:CYGWIN*:*) + echo powerpcle-unknown-cygwin + exit ;; + prep*:SunOS:5.*:*) + echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + *:GNU:*:*) + # the GNU system + echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` + exit ;; + *:GNU/*:*:*) + # other systems with GNU libc and userland + echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu + exit ;; + i*86:Minix:*:*) + echo ${UNAME_MACHINE}-pc-minix + exit ;; + arm*:Linux:*:*) + eval $set_cc_for_build + if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep -q __ARM_EABI__ + then + echo ${UNAME_MACHINE}-unknown-linux-gnu + else + echo ${UNAME_MACHINE}-unknown-linux-gnueabi + fi + exit ;; + avr32*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + cris:Linux:*:*) + echo cris-axis-linux-gnu + exit ;; + crisv32:Linux:*:*) + echo crisv32-axis-linux-gnu + exit ;; + frv:Linux:*:*) + echo frv-unknown-linux-gnu + exit ;; + ia64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + m32r*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + m68*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + mips:Linux:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #undef CPU + #undef mips + #undef mipsel + #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) + CPU=mipsel + #else + #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) + CPU=mips + #else + CPU= + #endif + #endif +EOF + eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' + /^CPU/{ + s: ::g + p + }'`" + test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } + ;; + mips64:Linux:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #undef CPU + #undef mips64 + #undef mips64el + #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) + CPU=mips64el + #else + #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) + CPU=mips64 + #else + CPU= + #endif + #endif +EOF + eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' + /^CPU/{ + s: ::g + p + }'`" + test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } + ;; + or32:Linux:*:*) + echo or32-unknown-linux-gnu + exit ;; + ppc:Linux:*:*) + echo powerpc-unknown-linux-gnu + exit ;; + ppc64:Linux:*:*) + echo powerpc64-unknown-linux-gnu + exit ;; + alpha:Linux:*:*) + case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` 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 ld.so.1 >/dev/null + if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi + echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} + exit ;; + parisc:Linux:*:* | hppa:Linux:*:*) + # Look for CPU level + case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in + PA7*) echo hppa1.1-unknown-linux-gnu ;; + PA8*) echo hppa2.0-unknown-linux-gnu ;; + *) echo hppa-unknown-linux-gnu ;; + esac + exit ;; + parisc64:Linux:*:* | hppa64:Linux:*:*) + echo hppa64-unknown-linux-gnu + exit ;; + s390:Linux:*:* | s390x:Linux:*:*) + echo ${UNAME_MACHINE}-ibm-linux + exit ;; + sh64*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + sh*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + sparc:Linux:*:* | sparc64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + vax:Linux:*:*) + echo ${UNAME_MACHINE}-dec-linux-gnu + exit ;; + x86_64:Linux:*:*) + echo x86_64-unknown-linux-gnu + exit ;; + xtensa*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit ;; + i*86:Linux:*:*) + # The BFD linker knows what the default object file format is, so + # first see if it will tell us. cd to the root directory to prevent + # problems with other programs or directories called `ld' in the path. + # Set LC_ALL=C to ensure ld outputs messages in English. + ld_supported_targets=`cd /; LC_ALL=C ld --help 2>&1 \ + | sed -ne '/supported targets:/!d + s/[ ][ ]*/ /g + s/.*supported targets: *// + s/ .*// + p'` + case "$ld_supported_targets" in + elf32-i386) + TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu" + ;; + a.out-i386-linux) + echo "${UNAME_MACHINE}-pc-linux-gnuaout" + exit ;; + coff-i386) + echo "${UNAME_MACHINE}-pc-linux-gnucoff" + exit ;; + "") + # Either a pre-BFD a.out linker (linux-gnuoldld) or + # one that does not give us useful --help. + echo "${UNAME_MACHINE}-pc-linux-gnuoldld" + exit ;; + esac + # Determine whether the default compiler is a.out or elf + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + #ifdef __ELF__ + # ifdef __GLIBC__ + # if __GLIBC__ >= 2 + LIBC=gnu + # else + LIBC=gnulibc1 + # endif + # else + LIBC=gnulibc1 + # endif + #else + #if defined(__INTEL_COMPILER) || defined(__PGI) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) + LIBC=gnu + #else + LIBC=gnuaout + #endif + #endif + #ifdef __dietlibc__ + LIBC=dietlibc + #endif +EOF + eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' + /^LIBC/{ + s: ::g + p + }'`" + test x"${LIBC}" != x && { + echo "${UNAME_MACHINE}-pc-linux-${LIBC}" + exit + } + test x"${TENTATIVE}" != x && { echo "${TENTATIVE}"; exit; } + ;; + 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. + echo i386-sequent-sysv4 + exit ;; + 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. + echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} + exit ;; + i*86:OS/2:*:*) + # If we were able to find `uname', then EMX Unix compatibility + # is probably installed. + echo ${UNAME_MACHINE}-pc-os2-emx + exit ;; + i*86:XTS-300:*:STOP) + echo ${UNAME_MACHINE}-unknown-stop + exit ;; + i*86:atheos:*:*) + echo ${UNAME_MACHINE}-unknown-atheos + exit ;; + i*86:syllable:*:*) + echo ${UNAME_MACHINE}-pc-syllable + exit ;; + i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*) + echo i386-unknown-lynxos${UNAME_RELEASE} + exit ;; + i*86:*DOS:*:*) + echo ${UNAME_MACHINE}-pc-msdosdjgpp + exit ;; + i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) + UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` + if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then + echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} + else + echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} + fi + exit ;; + 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 + echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} + exit ;; + 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 + echo ${UNAME_MACHINE}-pc-sco$UNAME_REL + else + echo ${UNAME_MACHINE}-pc-sysv32 + fi + exit ;; + 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 i386. + echo i386-pc-msdosdjgpp + exit ;; + Intel:Mach:3*:*) + echo i386-pc-mach3 + exit ;; + paragon:*:*:*) + echo i860-intel-osf1 + exit ;; + i860:*:4.*:*) # i860-SVR4 + if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then + echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 + else # Add other i860-SVR4 vendors below as they are discovered. + echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 + fi + exit ;; + mini*:CTIX:SYS*5:*) + # "miniframe" + echo m68010-convergent-sysv + exit ;; + mc68k:UNIX:SYSTEM5:3.51m) + echo m68k-convergent-sysv + exit ;; + M680?0:D-NIX:5.3:*) + echo m68k-diab-dnix + exit ;; + 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; } ;; + m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) + echo m68k-unknown-lynxos${UNAME_RELEASE} + exit ;; + mc68030:UNIX_System_V:4.*:*) + echo m68k-atari-sysv4 + exit ;; + TSUNAMI:LynxOS:2.*:*) + echo sparc-unknown-lynxos${UNAME_RELEASE} + exit ;; + rs6000:LynxOS:2.*:*) + echo rs6000-unknown-lynxos${UNAME_RELEASE} + exit ;; + PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*) + echo powerpc-unknown-lynxos${UNAME_RELEASE} + exit ;; + SM[BE]S:UNIX_SV:*:*) + echo mips-dde-sysv${UNAME_RELEASE} + exit ;; + RM*:ReliantUNIX-*:*:*) + echo mips-sni-sysv4 + exit ;; + RM*:SINIX-*:*:*) + echo mips-sni-sysv4 + exit ;; + *:SINIX-*:*:*) + if uname -p 2>/dev/null >/dev/null ; then + UNAME_MACHINE=`(uname -p) 2>/dev/null` + echo ${UNAME_MACHINE}-sni-sysv4 + else + echo ns32k-sni-sysv + fi + exit ;; + PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort + # says + echo i586-unisys-sysv4 + exit ;; + *:UNIX_System_V:4*:FTX*) + # From Gerald Hewes . + # How about differentiating between stratus architectures? -djm + echo hppa1.1-stratus-sysv4 + exit ;; + *:*:*:FTX*) + # From seanf@swdc.stratus.com. + echo i860-stratus-sysv4 + exit ;; + i*86:VOS:*:*) + # From Paul.Green@stratus.com. + echo ${UNAME_MACHINE}-stratus-vos + exit ;; + *:VOS:*:*) + # From Paul.Green@stratus.com. + echo hppa1.1-stratus-vos + exit ;; + mc68*:A/UX:*:*) + echo m68k-apple-aux${UNAME_RELEASE} + exit ;; + news*:NEWS-OS:6*:*) + echo mips-sony-newsos6 + exit ;; + R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) + if [ -d /usr/nec ]; then + echo mips-nec-sysv${UNAME_RELEASE} + else + echo mips-unknown-sysv${UNAME_RELEASE} + fi + exit ;; + BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. + echo powerpc-be-beos + exit ;; + BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. + echo powerpc-apple-beos + exit ;; + BePC:BeOS:*:*) # BeOS running on Intel PC compatible. + echo i586-pc-beos + exit ;; + SX-4:SUPER-UX:*:*) + echo sx4-nec-superux${UNAME_RELEASE} + exit ;; + SX-5:SUPER-UX:*:*) + echo sx5-nec-superux${UNAME_RELEASE} + exit ;; + SX-6:SUPER-UX:*:*) + echo sx6-nec-superux${UNAME_RELEASE} + exit ;; + SX-7:SUPER-UX:*:*) + echo sx7-nec-superux${UNAME_RELEASE} + exit ;; + SX-8:SUPER-UX:*:*) + echo sx8-nec-superux${UNAME_RELEASE} + exit ;; + SX-8R:SUPER-UX:*:*) + echo sx8r-nec-superux${UNAME_RELEASE} + exit ;; + Power*:Rhapsody:*:*) + echo powerpc-apple-rhapsody${UNAME_RELEASE} + exit ;; + *:Rhapsody:*:*) + echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} + exit ;; + *:Darwin:*:*) + UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown + case $UNAME_PROCESSOR in + unknown) UNAME_PROCESSOR=powerpc ;; + esac + echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} + exit ;; + *:procnto*:*:* | *:QNX:[0123456789]*:*) + UNAME_PROCESSOR=`uname -p` + if test "$UNAME_PROCESSOR" = "x86"; then + UNAME_PROCESSOR=i386 + UNAME_MACHINE=pc + fi + echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE} + exit ;; + *:QNX:*:4*) + echo i386-pc-qnx + exit ;; + NSE-?:NONSTOP_KERNEL:*:*) + echo nse-tandem-nsk${UNAME_RELEASE} + exit ;; + NSR-?:NONSTOP_KERNEL:*:*) + echo nsr-tandem-nsk${UNAME_RELEASE} + exit ;; + *:NonStop-UX:*:*) + echo mips-compaq-nonstopux + exit ;; + BS2000:POSIX*:*:*) + echo bs2000-siemens-sysv + exit ;; + DS/*:UNIX_System_V:*:*) + echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} + exit ;; + *: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 + else + UNAME_MACHINE="$cputype" + fi + echo ${UNAME_MACHINE}-unknown-plan9 + exit ;; + *:TOPS-10:*:*) + echo pdp10-unknown-tops10 + exit ;; + *:TENEX:*:*) + echo pdp10-unknown-tenex + exit ;; + KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) + echo pdp10-dec-tops20 + exit ;; + XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) + echo pdp10-xkl-tops20 + exit ;; + *:TOPS-20:*:*) + echo pdp10-unknown-tops20 + exit ;; + *:ITS:*:*) + echo pdp10-unknown-its + exit ;; + SEI:*:*:SEIUX) + echo mips-sei-seiux${UNAME_RELEASE} + exit ;; + *:DragonFly:*:*) + echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` + exit ;; + *:*VMS:*:*) + UNAME_MACHINE=`(uname -p) 2>/dev/null` + case "${UNAME_MACHINE}" in + A*) echo alpha-dec-vms ; exit ;; + I*) echo ia64-dec-vms ; exit ;; + V*) echo vax-dec-vms ; exit ;; + esac ;; + *:XENIX:*:SysV) + echo i386-pc-xenix + exit ;; + i*86:skyos:*:*) + echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//' + exit ;; + i*86:rdos:*:*) + echo ${UNAME_MACHINE}-pc-rdos + exit ;; +esac + +#echo '(No uname command or uname output not recognized.)' 1>&2 +#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2 + +eval $set_cc_for_build +cat >$dummy.c < +# include +#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 (__arm) && defined (__acorn) && defined (__unix) + printf ("arm-acorn-riscix\n"); exit (0); +#endif + +#if defined (hp300) && !defined (hpux) + printf ("m68k-hp-bsd\n"); exit (0); +#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 + printf ("vax-dec-ultrix\n"); exit (0); +# 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; } + +# Convex versions that predate uname can use getsysinfo(1) + +if [ -x /usr/convex/getsysinfo ] +then + case `getsysinfo -f cpu_type` in + c1*) + echo c1-convex-bsd + exit ;; + c2*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit ;; + c34*) + echo c34-convex-bsd + exit ;; + c38*) + echo c38-convex-bsd + exit ;; + c4*) + echo c4-convex-bsd + exit ;; + esac +fi + +cat >&2 < in order to provide the needed +information to handle your system. + +config.guess timestamp = $timestamp + +uname -m = `(uname -m) 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 + +exit 1 + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/scripts/config.sub b/scripts/config.sub new file mode 100755 index 0000000..9613107 --- /dev/null +++ b/scripts/config.sub @@ -0,0 +1,1663 @@ +#! /bin/sh +# Configuration validation subroutine script. +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, +# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 +# Free Software Foundation, Inc. + +timestamp='2009-09-02' + +# This file is (in principle) common to ALL GNU software. +# The presence of a machine in this file suggests that SOME GNU software +# can handle that machine. It does not imply ALL GNU software can. +# +# 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 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA +# 02110-1301, USA. +# +# 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. + + +# Please send patches to . Submit a context +# diff and a properly formatted ChangeLog entry. +# +# 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. + +# 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. + +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] CPU-MFR-OPSYS + $0 [OPTION] ALIAS + +Canonicalize a configuration name. + +Operation modes: + -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 (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, +2002, 2003, 2004, 2005, 2006, 2007, 2008 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" + 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 + +# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any). +# Here we must recognize all the valid KERNEL-OS combinations. +maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` +case $maybe_os in + nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \ + uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \ + storm-chaos* | os2-emx* | rtmk-nova*) + os=-$maybe_os + basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` + ;; + *) + basic_machine=`echo $1 | sed 's/-[^-]*$//'` + if [ $basic_machine != $1 ] + then os=`echo $1 | sed 's/.*-/-/'` + else os=; fi + ;; +esac + +### Let's recognize common machines as not being operating systems so +### that things like config.sub decstation-3100 work. We also +### recognize some manufacturers as not being operating systems, so we +### can provide default operating systems below. +case $os in + -sun*os*) + # Prevent following clause from handling this invalid input. + ;; + -dec* | -mips* | -sequent* | -encore* | -pc532* | -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) + os= + basic_machine=$1 + ;; + -sim | -cisco | -oki | -wec | -winbond) + os= + basic_machine=$1 + ;; + -scout) + ;; + -wrs) + os=-vxworks + basic_machine=$1 + ;; + -chorusos*) + os=-chorusos + basic_machine=$1 + ;; + -chorusrdb) + os=-chorusrdb + basic_machine=$1 + ;; + -hiux*) + os=-hiuxwe2 + ;; + -sco6) + os=-sco5v6 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco5) + os=-sco3.2v5 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco4) + os=-sco3.2v4 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco3.2.[4-9]*) + os=`echo $os | sed -e 's/sco3.2./sco3.2v/'` + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco3.2v[4-9]*) + # Don't forget version if it is 3.2v4 or newer. + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco5v6*) + # Don't forget version if it is 3.2v4 or newer. + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco*) + os=-sco3.2v2 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -udk*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -isc) + os=-isc2.2 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -clix*) + basic_machine=clipper-intergraph + ;; + -isc*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -lynx*) + os=-lynxos + ;; + -ptx*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'` + ;; + -windowsnt*) + os=`echo $os | sed -e 's/windowsnt/winnt/'` + ;; + -psos*) + os=-psos + ;; + -mint | -mint[0-9]*) + basic_machine=m68k-atari + os=-mint + ;; +esac + +# Decode aliases for certain CPU-COMPANY combinations. +case $basic_machine in + # Recognize the basic CPU types without company name. + # Some are omitted here because they have special meanings below. + 1750a | 580 \ + | a29k \ + | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ + | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ + | am33_2.0 \ + | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \ + | bfin \ + | c4x | clipper \ + | d10v | d30v | dlx | dsp16xx \ + | fido | fr30 | frv \ + | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ + | i370 | i860 | i960 | ia64 \ + | ip2k | iq2000 \ + | m32c | m32r | m32rle | m68000 | m68k | m88k \ + | maxq | mb | microblaze | mcore | mep \ + | mips | mipsbe | mipseb | mipsel | mipsle \ + | mips16 \ + | mips64 | mips64el \ + | mips64vr | mips64vrel \ + | mips64orion | mips64orionel \ + | mips64vr4100 | mips64vr4100el \ + | mips64vr4300 | mips64vr4300el \ + | mips64vr5000 | mips64vr5000el \ + | mips64vr5900 | mips64vr5900el \ + | mipsisa32 | mipsisa32el \ + | mipsisa32r2 | mipsisa32r2el \ + | mipsisa64 | mipsisa64el \ + | mipsisa64r2 | mipsisa64r2el \ + | mipsisa64sb1 | mipsisa64sb1el \ + | mipsisa64sr71k | mipsisa64sr71kel \ + | mipstx39 | mipstx39el \ + | mn10200 | mn10300 \ + | mt \ + | msp430 \ + | nios | nios2 \ + | ns16k | ns32k \ + | or32 \ + | pdp10 | pdp11 | pj | pjl \ + | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \ + | pyramid \ + | score \ + | sh | sh[1234] | sh[24]a | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \ + | sh64 | sh64le \ + | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \ + | sparcv8 | sparcv9 | sparcv9b | sparcv9v \ + | spu | strongarm \ + | tahoe | thumb | tic4x | tic80 | tron \ + | v850 | v850e \ + | we32k \ + | x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \ + | z8k) + basic_machine=$basic_machine-unknown + ;; + m6811 | m68hc11 | m6812 | m68hc12) + # Motorola 68HC11/12. + basic_machine=$basic_machine-unknown + os=-none + ;; + m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) + ;; + ms1) + basic_machine=mt-unknown + ;; + + # cbatten - Add maven target + maven) + basic_machine=mipsmavenel-ucb + ;; + + # We use `pc' rather than `unknown' + # because (1) that's what they normally are, and + # (2) the word "unknown" tends to confuse beginning users. + i*86 | x86_64) + basic_machine=$basic_machine-pc + ;; + # Object if more than one company name word. + *-*-*) + echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 + exit 1 + ;; + # Recognize the basic CPU types with company name. + 580-* \ + | a29k-* \ + | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ + | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ + | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \ + | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ + | avr-* | avr32-* \ + | bfin-* | bs2000-* \ + | c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \ + | clipper-* | craynv-* | cydra-* \ + | d10v-* | d30v-* | dlx-* \ + | elxsi-* \ + | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \ + | h8300-* | h8500-* \ + | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ + | i*86-* | i860-* | i960-* | ia64-* \ + | ip2k-* | iq2000-* \ + | m32c-* | m32r-* | m32rle-* \ + | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ + | m88110-* | m88k-* | maxq-* | mcore-* \ + | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ + | mips16-* \ + | mips64-* | mips64el-* \ + | mips64vr-* | mips64vrel-* \ + | mips64orion-* | mips64orionel-* \ + | mips64vr4100-* | mips64vr4100el-* \ + | mips64vr4300-* | mips64vr4300el-* \ + | mips64vr5000-* | mips64vr5000el-* \ + | mips64vr5900-* | mips64vr5900el-* \ + | mipsisa32-* | mipsisa32el-* \ + | mipsisa32r2-* | mipsisa32r2el-* \ + | mipsisa64-* | mipsisa64el-* \ + | mipsisa64r2-* | mipsisa64r2el-* \ + | mipsisa64sb1-* | mipsisa64sb1el-* \ + | mipsisa64sr71k-* | mipsisa64sr71kel-* \ + | mipstx39-* | mipstx39el-* \ + | mmix-* \ + | mt-* \ + | msp430-* \ + | nios-* | nios2-* \ + | none-* | np1-* | ns16k-* | ns32k-* \ + | orion-* \ + | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ + | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \ + | pyramid-* \ + | romp-* | rs6000-* \ + | sh-* | sh[1234]-* | sh[24]a-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \ + | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ + | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \ + | sparclite-* \ + | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \ + | tahoe-* | thumb-* \ + | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \ + | tron-* \ + | v850-* | v850e-* | vax-* \ + | we32k-* \ + | x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \ + | xstormy16-* | xtensa*-* \ + | ymp-* \ + | z8k-*) + ;; + # Recognize the basic CPU types without company name, with glob match. + xtensa*) + basic_machine=$basic_machine-unknown + ;; + # Recognize the various machine names and aliases which stand + # for a CPU type and a company and sometimes even an OS. + 386bsd) + basic_machine=i386-unknown + os=-bsd + ;; + 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) + basic_machine=m68000-att + ;; + 3b*) + basic_machine=we32k-att + ;; + a29khif) + basic_machine=a29k-amd + os=-udi + ;; + abacus) + basic_machine=abacus-unknown + ;; + adobe68k) + basic_machine=m68010-adobe + os=-scout + ;; + alliant | fx80) + basic_machine=fx80-alliant + ;; + altos | altos3068) + basic_machine=m68k-altos + ;; + am29k) + basic_machine=a29k-none + os=-bsd + ;; + amd64) + basic_machine=x86_64-pc + ;; + amd64-*) + basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + amdahl) + basic_machine=580-amdahl + os=-sysv + ;; + amiga | amiga-*) + basic_machine=m68k-unknown + ;; + amigaos | amigados) + basic_machine=m68k-unknown + os=-amigaos + ;; + amigaunix | amix) + basic_machine=m68k-unknown + os=-sysv4 + ;; + apollo68) + basic_machine=m68k-apollo + os=-sysv + ;; + apollo68bsd) + basic_machine=m68k-apollo + os=-bsd + ;; + aux) + basic_machine=m68k-apple + os=-aux + ;; + balance) + basic_machine=ns32k-sequent + os=-dynix + ;; + blackfin) + basic_machine=bfin-unknown + os=-linux + ;; + blackfin-*) + basic_machine=bfin-`echo $basic_machine | sed 's/^[^-]*-//'` + os=-linux + ;; + c90) + basic_machine=c90-cray + os=-unicos + ;; + convex-c1) + basic_machine=c1-convex + os=-bsd + ;; + convex-c2) + basic_machine=c2-convex + os=-bsd + ;; + convex-c32) + basic_machine=c32-convex + os=-bsd + ;; + convex-c34) + basic_machine=c34-convex + os=-bsd + ;; + convex-c38) + basic_machine=c38-convex + os=-bsd + ;; + cray | j90) + basic_machine=j90-cray + os=-unicos + ;; + craynv) + basic_machine=craynv-cray + os=-unicosmp + ;; + cr16) + basic_machine=cr16-unknown + os=-elf + ;; + crds | unos) + basic_machine=m68k-crds + ;; + crisv32 | crisv32-* | etraxfs*) + basic_machine=crisv32-axis + ;; + cris | cris-* | etrax*) + basic_machine=cris-axis + ;; + crx) + basic_machine=crx-unknown + os=-elf + ;; + da30 | da30-*) + basic_machine=m68k-da30 + ;; + decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn) + basic_machine=mips-dec + ;; + decsystem10* | dec10*) + basic_machine=pdp10-dec + os=-tops10 + ;; + decsystem20* | dec20*) + basic_machine=pdp10-dec + os=-tops20 + ;; + delta | 3300 | motorola-3300 | motorola-delta \ + | 3300-motorola | delta-motorola) + basic_machine=m68k-motorola + ;; + delta88) + basic_machine=m88k-motorola + os=-sysv3 + ;; + djgpp) + basic_machine=i586-pc + os=-msdosdjgpp + ;; + dpx20 | dpx20-*) + basic_machine=rs6000-bull + os=-bosx + ;; + dpx2* | dpx2*-bull) + basic_machine=m68k-bull + os=-sysv3 + ;; + ebmon29k) + basic_machine=a29k-amd + os=-ebmon + ;; + elxsi) + basic_machine=elxsi-elxsi + os=-bsd + ;; + encore | umax | mmax) + basic_machine=ns32k-encore + ;; + es1800 | OSE68k | ose68k | ose | OSE) + basic_machine=m68k-ericsson + os=-ose + ;; + fx2800) + basic_machine=i860-alliant + ;; + genix) + basic_machine=ns32k-ns + ;; + gmicro) + basic_machine=tron-gmicro + os=-sysv + ;; + go32) + basic_machine=i386-pc + os=-go32 + ;; + h3050r* | hiux*) + basic_machine=hppa1.1-hitachi + os=-hiuxwe2 + ;; + h8300hms) + basic_machine=h8300-hitachi + os=-hms + ;; + h8300xray) + basic_machine=h8300-hitachi + os=-xray + ;; + h8500hms) + basic_machine=h8500-hitachi + os=-hms + ;; + harris) + basic_machine=m88k-harris + os=-sysv3 + ;; + hp300-*) + basic_machine=m68k-hp + ;; + hp300bsd) + basic_machine=m68k-hp + os=-bsd + ;; + hp300hpux) + basic_machine=m68k-hp + os=-hpux + ;; + hp3k9[0-9][0-9] | hp9[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hp9k2[0-9][0-9] | hp9k31[0-9]) + basic_machine=m68000-hp + ;; + hp9k3[2-9][0-9]) + basic_machine=m68k-hp + ;; + hp9k6[0-9][0-9] | hp6[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hp9k7[0-79][0-9] | hp7[0-79][0-9]) + basic_machine=hppa1.1-hp + ;; + hp9k78[0-9] | hp78[0-9]) + # FIXME: really hppa2.0-hp + basic_machine=hppa1.1-hp + ;; + hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) + # FIXME: really hppa2.0-hp + basic_machine=hppa1.1-hp + ;; + hp9k8[0-9][13679] | hp8[0-9][13679]) + basic_machine=hppa1.1-hp + ;; + hp9k8[0-9][0-9] | hp8[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hppa-next) + os=-nextstep3 + ;; + hppaosf) + basic_machine=hppa1.1-hp + os=-osf + ;; + hppro) + basic_machine=hppa1.1-hp + os=-proelf + ;; + i370-ibm* | ibm*) + basic_machine=i370-ibm + ;; +# I'm not sure what "Sysv32" means. Should this be sysv3.2? + i*86v32) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv32 + ;; + i*86v4*) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv4 + ;; + i*86v) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv + ;; + i*86sol2) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-solaris2 + ;; + i386mach) + basic_machine=i386-mach + os=-mach + ;; + i386-vsta | vsta) + basic_machine=i386-unknown + os=-vsta + ;; + iris | iris4d) + basic_machine=mips-sgi + case $os in + -irix*) + ;; + *) + os=-irix4 + ;; + esac + ;; + isi68 | isi) + basic_machine=m68k-isi + os=-sysv + ;; + m68knommu) + basic_machine=m68k-unknown + os=-linux + ;; + m68knommu-*) + basic_machine=m68k-`echo $basic_machine | sed 's/^[^-]*-//'` + os=-linux + ;; + m88k-omron*) + basic_machine=m88k-omron + ;; + magnum | m3230) + basic_machine=mips-mips + os=-sysv + ;; + merlin) + basic_machine=ns32k-utek + os=-sysv + ;; + mingw32) + basic_machine=i386-pc + os=-mingw32 + ;; + mingw32ce) + basic_machine=arm-unknown + os=-mingw32ce + ;; + miniframe) + basic_machine=m68000-convergent + ;; + *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*) + basic_machine=m68k-atari + os=-mint + ;; + mips3*-*) + basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'` + ;; + mips3*) + basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown + ;; + monitor) + basic_machine=m68k-rom68k + os=-coff + ;; + morphos) + basic_machine=powerpc-unknown + os=-morphos + ;; + msdos) + basic_machine=i386-pc + os=-msdos + ;; + ms1-*) + basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'` + ;; + mvs) + basic_machine=i370-ibm + os=-mvs + ;; + ncr3000) + basic_machine=i486-ncr + os=-sysv4 + ;; + netbsd386) + basic_machine=i386-unknown + os=-netbsd + ;; + netwinder) + basic_machine=armv4l-rebel + os=-linux + ;; + news | news700 | news800 | news900) + basic_machine=m68k-sony + os=-newsos + ;; + news1000) + basic_machine=m68030-sony + os=-newsos + ;; + news-3600 | risc-news) + basic_machine=mips-sony + os=-newsos + ;; + necv70) + basic_machine=v70-nec + os=-sysv + ;; + next | m*-next ) + basic_machine=m68k-next + case $os in + -nextstep* ) + ;; + -ns2*) + os=-nextstep2 + ;; + *) + os=-nextstep3 + ;; + esac + ;; + nh3000) + basic_machine=m68k-harris + os=-cxux + ;; + nh[45]000) + basic_machine=m88k-harris + os=-cxux + ;; + nindy960) + basic_machine=i960-intel + os=-nindy + ;; + mon960) + basic_machine=i960-intel + os=-mon960 + ;; + nonstopux) + basic_machine=mips-compaq + os=-nonstopux + ;; + np1) + basic_machine=np1-gould + ;; + nsr-tandem) + basic_machine=nsr-tandem + ;; + op50n-* | op60c-*) + basic_machine=hppa1.1-oki + os=-proelf + ;; + openrisc | openrisc-*) + basic_machine=or32-unknown + ;; + os400) + basic_machine=powerpc-ibm + os=-os400 + ;; + OSE68000 | ose68000) + basic_machine=m68000-ericsson + os=-ose + ;; + os68k) + basic_machine=m68k-none + os=-os68k + ;; + pa-hitachi) + basic_machine=hppa1.1-hitachi + os=-hiuxwe2 + ;; + paragon) + basic_machine=i860-intel + os=-osf + ;; + parisc) + basic_machine=hppa-unknown + os=-linux + ;; + parisc-*) + basic_machine=hppa-`echo $basic_machine | sed 's/^[^-]*-//'` + os=-linux + ;; + pbd) + basic_machine=sparc-tti + ;; + pbb) + basic_machine=m68k-tti + ;; + pc532 | pc532-*) + basic_machine=ns32k-pc532 + ;; + pc98) + basic_machine=i386-pc + ;; + pc98-*) + basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentium | p5 | k5 | k6 | nexgen | viac3) + basic_machine=i586-pc + ;; + pentiumpro | p6 | 6x86 | athlon | athlon_*) + basic_machine=i686-pc + ;; + pentiumii | pentium2 | pentiumiii | pentium3) + basic_machine=i686-pc + ;; + pentium4) + basic_machine=i786-pc + ;; + pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*) + basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentiumpro-* | p6-* | 6x86-* | athlon-*) + basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*) + basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentium4-*) + basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pn) + basic_machine=pn-gould + ;; + power) basic_machine=power-ibm + ;; + ppc) basic_machine=powerpc-unknown + ;; + ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppcle | powerpclittle | ppc-le | powerpc-little) + basic_machine=powerpcle-unknown + ;; + ppcle-* | powerpclittle-*) + basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppc64) basic_machine=powerpc64-unknown + ;; + ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppc64le | powerpc64little | ppc64-le | powerpc64-little) + basic_machine=powerpc64le-unknown + ;; + ppc64le-* | powerpc64little-*) + basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ps2) + basic_machine=i386-ibm + ;; + pw32) + basic_machine=i586-unknown + os=-pw32 + ;; + rdos) + basic_machine=i386-pc + os=-rdos + ;; + rom68k) + basic_machine=m68k-rom68k + os=-coff + ;; + rm[46]00) + basic_machine=mips-siemens + ;; + rtpc | rtpc-*) + basic_machine=romp-ibm + ;; + s390 | s390-*) + basic_machine=s390-ibm + ;; + s390x | s390x-*) + basic_machine=s390x-ibm + ;; + sa29200) + basic_machine=a29k-amd + os=-udi + ;; + sb1) + basic_machine=mipsisa64sb1-unknown + ;; + sb1el) + basic_machine=mipsisa64sb1el-unknown + ;; + sde) + basic_machine=mipsisa32-sde + os=-elf + ;; + sei) + basic_machine=mips-sei + os=-seiux + ;; + sequent) + basic_machine=i386-sequent + ;; + sh) + basic_machine=sh-hitachi + os=-hms + ;; + sh5el) + basic_machine=sh5le-unknown + ;; + sh64) + basic_machine=sh64-unknown + ;; + sparclite-wrs | simso-wrs) + basic_machine=sparclite-wrs + os=-vxworks + ;; + sps7) + basic_machine=m68k-bull + os=-sysv2 + ;; + spur) + basic_machine=spur-unknown + ;; + st2000) + basic_machine=m68k-tandem + ;; + stratus) + basic_machine=i860-stratus + os=-sysv4 + ;; + sun2) + basic_machine=m68000-sun + ;; + sun2os3) + basic_machine=m68000-sun + os=-sunos3 + ;; + sun2os4) + basic_machine=m68000-sun + os=-sunos4 + ;; + sun3os3) + basic_machine=m68k-sun + os=-sunos3 + ;; + sun3os4) + basic_machine=m68k-sun + os=-sunos4 + ;; + sun4os3) + basic_machine=sparc-sun + os=-sunos3 + ;; + sun4os4) + basic_machine=sparc-sun + os=-sunos4 + ;; + sun4sol2) + basic_machine=sparc-sun + os=-solaris2 + ;; + sun3 | sun3-*) + basic_machine=m68k-sun + ;; + sun4) + basic_machine=sparc-sun + ;; + sun386 | sun386i | roadrunner) + basic_machine=i386-sun + ;; + sv1) + basic_machine=sv1-cray + os=-unicos + ;; + symmetry) + basic_machine=i386-sequent + os=-dynix + ;; + t3e) + basic_machine=alphaev5-cray + os=-unicos + ;; + t90) + basic_machine=t90-cray + os=-unicos + ;; + tic54x | c54x*) + basic_machine=tic54x-unknown + os=-coff + ;; + tic55x | c55x*) + basic_machine=tic55x-unknown + os=-coff + ;; + tic6x | c6x*) + basic_machine=tic6x-unknown + os=-coff + ;; + tile*) + basic_machine=tile-unknown + os=-linux-gnu + ;; + tx39) + basic_machine=mipstx39-unknown + ;; + tx39el) + basic_machine=mipstx39el-unknown + ;; + toad1) + basic_machine=pdp10-xkl + os=-tops20 + ;; + tower | tower-32) + basic_machine=m68k-ncr + ;; + tpf) + basic_machine=s390x-ibm + os=-tpf + ;; + udi29k) + basic_machine=a29k-amd + os=-udi + ;; + ultra3) + basic_machine=a29k-nyu + os=-sym1 + ;; + v810 | necv810) + basic_machine=v810-nec + os=-none + ;; + vaxv) + basic_machine=vax-dec + os=-sysv + ;; + vms) + basic_machine=vax-dec + os=-vms + ;; + vpp*|vx|vx-*) + basic_machine=f301-fujitsu + ;; + vxworks960) + basic_machine=i960-wrs + os=-vxworks + ;; + vxworks68) + basic_machine=m68k-wrs + os=-vxworks + ;; + vxworks29k) + basic_machine=a29k-wrs + os=-vxworks + ;; + w65*) + basic_machine=w65-wdc + os=-none + ;; + w89k-*) + basic_machine=hppa1.1-winbond + os=-proelf + ;; + xbox) + basic_machine=i686-pc + os=-mingw32 + ;; + xps | xps100) + basic_machine=xps100-honeywell + ;; + ymp) + basic_machine=ymp-cray + os=-unicos + ;; + z8k-*-coff) + basic_machine=z8k-unknown + os=-sim + ;; + none) + basic_machine=none-none + os=-none + ;; + +# 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) + basic_machine=hppa1.1-winbond + ;; + op50n) + basic_machine=hppa1.1-oki + ;; + op60c) + basic_machine=hppa1.1-oki + ;; + romp) + basic_machine=romp-ibm + ;; + mmix) + basic_machine=mmix-knuth + ;; + rs6000) + basic_machine=rs6000-ibm + ;; + vax) + basic_machine=vax-dec + ;; + pdp10) + # there are many clones, so DEC is not a safe bet + basic_machine=pdp10-unknown + ;; + pdp11) + basic_machine=pdp11-dec + ;; + we32k) + basic_machine=we32k-att + ;; + sh[1234] | sh[24]a | sh[34]eb | sh[1234]le | sh[23]ele) + basic_machine=sh-unknown + ;; + sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v) + basic_machine=sparc-sun + ;; + cydra) + basic_machine=cydra-cydrome + ;; + orion) + basic_machine=orion-highlevel + ;; + orion105) + basic_machine=clipper-highlevel + ;; + mac | mpw | mac-mpw) + basic_machine=m68k-apple + ;; + pmac | pmac-mpw) + basic_machine=powerpc-apple + ;; + *-unknown) + # Make sure to match an already-canonicalized machine name. + ;; + *) + echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 + exit 1 + ;; +esac + +# Here we canonicalize certain aliases for manufacturers. +case $basic_machine in + *-digital*) + basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'` + ;; + *-commodore*) + basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'` + ;; + *) + ;; +esac + +# Decode manufacturer-specific aliases for certain operating systems. + +if [ x"$os" != x"" ] +then +case $os in + # First match some system type aliases + # that might get confused with valid system types. + # -solaris* is a basic system type, with this one exception. + -solaris1 | -solaris1.*) + os=`echo $os | sed -e 's|solaris1|sunos4|'` + ;; + -solaris) + os=-solaris2 + ;; + -svr4*) + os=-sysv4 + ;; + -unixware*) + os=-sysv4.2uw + ;; + -gnu/linux*) + os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'` + ;; + # First accept the basic system types. + # The portable systems comes first. + # Each alternative MUST END IN A *, to match a version number. + # -sysv* is not here because it comes later, after sysvr4. + -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ + | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\ + | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \ + | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ + | -aos* \ + | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ + | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ + | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \ + | -openbsd* | -solidbsd* \ + | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \ + | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ + | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ + | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ + | -chorusos* | -chorusrdb* \ + | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ + | -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \ + | -uxpv* | -beos* | -mpeix* | -udk* \ + | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ + | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ + | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ + | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ + | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ + | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \ + | -skyos* | -haiku* | -rdos* | -toppers* | -drops*) + # Remember, each alternative MUST END IN *, to match a version number. + ;; + -qnx*) + case $basic_machine in + x86-* | i*86-*) + ;; + *) + os=-nto$os + ;; + esac + ;; + -nto-qnx*) + ;; + -nto*) + os=`echo $os | sed -e 's|nto|nto-qnx|'` + ;; + -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \ + | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \ + | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*) + ;; + -mac*) + os=`echo $os | sed -e 's|mac|macos|'` + ;; + -linux-dietlibc) + os=-linux-dietlibc + ;; + -linux*) + os=`echo $os | sed -e 's|linux|linux-gnu|'` + ;; + -sunos5*) + os=`echo $os | sed -e 's|sunos5|solaris2|'` + ;; + -sunos6*) + os=`echo $os | sed -e 's|sunos6|solaris3|'` + ;; + -opened*) + os=-openedition + ;; + -os400*) + os=-os400 + ;; + -wince*) + os=-wince + ;; + -osfrose*) + os=-osfrose + ;; + -osf*) + os=-osf + ;; + -utek*) + os=-bsd + ;; + -dynix*) + os=-bsd + ;; + -acis*) + os=-aos + ;; + -atheos*) + os=-atheos + ;; + -syllable*) + os=-syllable + ;; + -386bsd) + os=-bsd + ;; + -ctix* | -uts*) + os=-sysv + ;; + -nova*) + os=-rtmk-nova + ;; + -ns2 ) + os=-nextstep2 + ;; + -nsk*) + os=-nsk + ;; + # Preserve the version number of sinix5. + -sinix5.*) + os=`echo $os | sed -e 's|sinix|sysv|'` + ;; + -sinix*) + os=-sysv4 + ;; + -tpf*) + os=-tpf + ;; + -triton*) + os=-sysv3 + ;; + -oss*) + os=-sysv3 + ;; + -svr4) + os=-sysv4 + ;; + -svr3) + os=-sysv3 + ;; + -sysvr4) + os=-sysv4 + ;; + # This must come after -sysvr4. + -sysv*) + ;; + -ose*) + os=-ose + ;; + -es1800*) + os=-ose + ;; + -xenix) + os=-xenix + ;; + -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) + os=-mint + ;; + -aros*) + os=-aros + ;; + -kaos*) + os=-kaos + ;; + -zvmoe) + os=-zvmoe + ;; + -none) + ;; + *) + # Get rid of the `-' at the beginning of $os. + os=`echo $os | sed 's/[^-]*-//'` + echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2 + exit 1 + ;; +esac +else + +# Here we handle the default operating systems that come with various machines. +# The value should be what the vendor currently ships out the door with their +# machine or put another way, the most popular os provided with the machine. + +# Note that if you're going to try to match "-MANUFACTURER" here (say, +# "-sun"), then you have to tell the case statement up towards the top +# that MANUFACTURER isn't an operating system. Otherwise, code above +# will signal an error saying that MANUFACTURER isn't an operating +# system, and we'll never get to this point. + +case $basic_machine in + score-*) + os=-elf + ;; + spu-*) + os=-elf + ;; + *-acorn) + os=-riscix1.2 + ;; + arm*-rebel) + os=-linux + ;; + arm*-semi) + os=-aout + ;; + c4x-* | tic4x-*) + os=-coff + ;; + # This must come before the *-dec entry. + pdp10-*) + os=-tops20 + ;; + pdp11-*) + os=-none + ;; + *-dec | vax-*) + os=-ultrix4.2 + ;; + m68*-apollo) + os=-domain + ;; + i386-sun) + os=-sunos4.0.2 + ;; + m68000-sun) + os=-sunos3 + # This also exists in the configure program, but was not the + # default. + # os=-sunos4 + ;; + m68*-cisco) + os=-aout + ;; + mep-*) + os=-elf + ;; + mips*-cisco) + os=-elf + ;; + mips*-*) + os=-elf + ;; + or32-*) + os=-coff + ;; + *-tti) # must be before sparc entry or we get the wrong os. + os=-sysv3 + ;; + sparc-* | *-sun) + os=-sunos4.1.1 + ;; + *-be) + os=-beos + ;; + *-haiku) + os=-haiku + ;; + *-ibm) + os=-aix + ;; + *-knuth) + os=-mmixware + ;; + *-wec) + os=-proelf + ;; + *-winbond) + os=-proelf + ;; + *-oki) + os=-proelf + ;; + *-hp) + os=-hpux + ;; + *-hitachi) + os=-hiux + ;; + i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent) + os=-sysv + ;; + *-cbm) + os=-amigaos + ;; + *-dg) + os=-dgux + ;; + *-dolphin) + os=-sysv3 + ;; + m68k-ccur) + os=-rtu + ;; + m88k-omron*) + os=-luna + ;; + *-next ) + os=-nextstep + ;; + *-sequent) + os=-ptx + ;; + *-crds) + os=-unos + ;; + *-ns) + os=-genix + ;; + i370-*) + os=-mvs + ;; + *-next) + os=-nextstep3 + ;; + *-gould) + os=-sysv + ;; + *-highlevel) + os=-bsd + ;; + *-encore) + os=-bsd + ;; + *-sgi) + os=-irix + ;; + *-siemens) + os=-sysv4 + ;; + *-masscomp) + os=-rtu + ;; + f30[01]-fujitsu | f700-fujitsu) + os=-uxpv + ;; + *-rom68k) + os=-coff + ;; + *-*bug) + os=-coff + ;; + *-apple) + os=-macos + ;; + *-atari*) + os=-mint + ;; + *) + os=-none + ;; +esac +fi + +# Here we handle the case where we know the os, and the CPU type, but not the +# manufacturer. We pick the logical manufacturer. +vendor=unknown +case $basic_machine in + *-unknown) + case $os in + -riscix*) + vendor=acorn + ;; + -sunos*) + vendor=sun + ;; + -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 + ;; + -mvs* | -opened*) + vendor=ibm + ;; + -os400*) + 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 + basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` + ;; +esac + +echo $basic_machine$os +exit + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100755 index 0000000..89fc9b0 --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,238 @@ +#! /bin/sh +# +# install - install a program, script, or datafile +# This comes from X11R5. +# +# 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. +# + + +# 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}" + +tranformbasename="" +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=: + 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/scripts/mk-install-dirs.sh b/scripts/mk-install-dirs.sh new file mode 100755 index 0000000..644b5f7 --- /dev/null +++ b/scripts/mk-install-dirs.sh @@ -0,0 +1,40 @@ +#! /bin/sh +# mkinstalldirs --- make directory hierarchy +# Author: Noah Friedman +# Created: 1993-05-16 +# Public domain + +# $Id: mkinstalldirs,v 1.1 2003/09/09 22:24:03 mhampton Exp $ + +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" 1>&2 + + mkdir "$pathcomp" || lasterr=$? + + if test ! -d "$pathcomp"; then + errstatus=$lasterr + fi + fi + + pathcomp="$pathcomp/" + done +done + +exit $errstatus + +# mkinstalldirs ends here diff --git a/scripts/vcs-version.sh b/scripts/vcs-version.sh new file mode 100755 index 0000000..31fae86 --- /dev/null +++ b/scripts/vcs-version.sh @@ -0,0 +1,117 @@ +#!/bin/bash +#========================================================================= +# vcs-version.sh [options] [src-dir] +#========================================================================= +# +# -h Display this message +# -v Verbose mode +# +# This script will create a version string by querying a version control +# system. The string is appropriate for use in installations and +# distributions. Currently this script assumes we are using git as our +# version control system but it would be possible to check and see if we +# are using an alternative version control system and create a version +# string appropriately. +# +# The script uses git describe plus a few other git commands to create a +# version strings in the following format: +# +# X.Y[-Z-gN][-dirty] +# +# where X is the major release, Y is the minor release, Z is the number +# of commits since the X.Y release, N is an eight digit abbreviated SHA +# hash of the most recent commit and the dirty suffix is appended when +# the working directory used to create the installation or distribution +# is not a pristine checkout. Here are some example version strings: +# +# 0.0 : initial import +# 0.0-3-g99ef6933 : 3rd commit since initial import (N=99ef6933) +# 1.0 : release 1.0 +# 1.1-12-g3487ab12 : 12th commit since release 1.1 (N=3487ab12) +# 1.1-12-g3487ab12-dirty : 12th commit since release 1.1 (N=3487ab12) +# +# The last example is from a dirty working directory. To find the last +# release, the script looks for the last tag (does not need to be an +# annotated tag, but probably should be) which matches the format rel-*. +# If there is no such tag in the history, then the script uses 0.0 as +# the release number and counts the total number of commits since the +# original import for the commit count. +# +# If the current directory is not within the working directory, then the +# path to the source directory should be supplied on the command line. +# +# Author : Christopher Batten +# Date : August 5, 2009 + +set -e + +#------------------------------------------------------------------------- +# Command line parsing +#------------------------------------------------------------------------- + +if ( test "$1" = "-h" ); then + echo "" + sed -n '3p' $0 | sed -e 's/#//' + sed -n '5,/^$/p' $0 | sed -e 's/#//' + exit 1 +fi + +# Source directory command line option + +src_dir="." +if ( test -n "$1" ); then + src_dir="$1" +fi + +#------------------------------------------------------------------------- +# Verify source directory +#------------------------------------------------------------------------- +# If the source directory is not a git working directory output a +# question mark. A distribution will not be in a working directory, but +# the build system should be structured such that this script is not +# executed (and instead the version information should probably come +# from configure). If the user does not specify a source directory use +# the current directory. + +if !( git rev-parse --is-inside-work-tree &> /dev/null ); then + echo "?" + exit 1; +fi + +top_dir=`git rev-parse --show-cdup` +cd ./${top_dir} + +#------------------------------------------------------------------------- +# Create the version string +#------------------------------------------------------------------------- +# See if we can do a describe based on a tag and if not use a default +# release number of 0.0 so that we always get canonical version number + +if ( git describe --tags --match "rel-*" &> /dev/null ); then + ver_str=`git describe --tags --match "rel-*" | sed 's/rel-//'` +else + ver_num="0.0" + ver_commits=`git rev-list --all | wc -l | tr -d " "` + ver_sha=`git describe --tags --match "rel-*" --always` + ver_str="${ver_num}-${ver_commits}-g${ver_sha}" +fi + +# Add a dirty suffix if working directory is dirty + +if !( git diff --quiet ); then + ver_str="${ver_str}-dirty" +else + untracked=`git ls-files --directory --exclude-standard --others -t` + if ( test -n "${untracked}" ); then + ver_str="${ver_str}-dirty" + fi +fi + +# Output the final version string + +echo "${ver_str}" + +# Final exit status + +exit 0; + diff --git a/softfloat/8086/OLD-specialize.c b/softfloat/8086/OLD-specialize.c new file mode 100755 index 0000000..ffb306d --- /dev/null +++ b/softfloat/8086/OLD-specialize.c @@ -0,0 +1,40 @@ + +/*============================================================================ + +*** FIX. + +This C source fragment is part of the SoftFloat IEC/IEEE Floating-point +Arithmetic Package, Release 2b. + +Written by John R. Hauser. This work was made possible in part by the +International Computer Science Institute, located at Suite 600, 1947 Center +Street, Berkeley, California 94704. Funding was partially provided by the +National Science Foundation under grant MIP-9311980. The original version +of this code was written as part of a project to build a fixed-point vector +processor in collaboration with the University of California at Berkeley, +overseen by Profs. Nelson Morgan and John Wawrzynek. More information +is available through the Web page `http://www.cs.berkeley.edu/~jhauser/ +arithmetic/SoftFloat.html'. + +THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has +been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES +RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS +AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES, +COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE +EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE +INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR +OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE. + +Derivative works are acceptable, even for commercial purposes, so long as +(1) the source code for the derivative work includes prominent notice that +the work is derivative, and (2) the source code includes prominent notice with +these four paragraphs for those parts of this code that are retained. + +=============================================================================*/ + +/*---------------------------------------------------------------------------- +| Underflow tininess-detection mode, statically initialized to default value. +| (The declaration in `softfloat.h' must match the `int8' type here.) +*----------------------------------------------------------------------------*/ +bool float_detectTininess = float_tininess_afterRounding; + diff --git a/softfloat/8086/OLD-specialize.h b/softfloat/8086/OLD-specialize.h new file mode 100755 index 0000000..9e4461c --- /dev/null +++ b/softfloat/8086/OLD-specialize.h @@ -0,0 +1,379 @@ + +/*============================================================================ + +*** FIX. + +This C source fragment is part of the SoftFloat IEC/IEEE Floating-point +Arithmetic Package, Release 2b. + +Written by John R. Hauser. This work was made possible in part by the +International Computer Science Institute, located at Suite 600, 1947 Center +Street, Berkeley, California 94704. Funding was partially provided by the +National Science Foundation under grant MIP-9311980. The original version +of this code was written as part of a project to build a fixed-point vector +processor in collaboration with the University of California at Berkeley, +overseen by Profs. Nelson Morgan and John Wawrzynek. More information +is available through the Web page `http://www.cs.berkeley.edu/~jhauser/ +arithmetic/SoftFloat.html'. + +THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has +been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES +RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS +AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES, +COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE +EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE +INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR +OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE. + +Derivative works are acceptable, even for commercial purposes, so long as +(1) the source code for the derivative work includes prominent notice that +the work is derivative, and (2) the source code includes prominent notice with +these four paragraphs for those parts of this code that are retained. + +=============================================================================*/ + +/*---------------------------------------------------------------------------- +| Internal canonical NaN format. +*----------------------------------------------------------------------------*/ +*** COMMON +typedef struct { + flag sign; + uint128_t bits; +} commonNaNT; + +/*---------------------------------------------------------------------------- +| The pattern for a default generated single-precision NaN. +*----------------------------------------------------------------------------*/ +#define float32Bits_defaultNaN 0xFFC00000 + +/*---------------------------------------------------------------------------- +| Returns 1 if the single-precision floating-point value `a' is a NaN; +| otherwise, returns 0. +*----------------------------------------------------------------------------*/ +*** COMMON +#define softfloat_isNaNFloat32Bits( a ) ( 0xFF000000 < (uint32_t) ( a )<<1 ) + +/*---------------------------------------------------------------------------- +| Returns 1 if the single-precision floating-point value `a' is a signaling +| NaN; otherwise, returns 0. +*----------------------------------------------------------------------------*/ +inline bool softfloat_isSigNaNFloat32Bits( uint32_t a ) + { return ( ( a>>22 & 0x1FF ) == 0x1FE ) && ( a & 0x003FFFFF ); } + +/*---------------------------------------------------------------------------- +*----------------------------------------------------------------------------*/ +commonNaNT softfloat_NaNFromFloat32Bits( uint32_t ); +uint32_t softfloat_float32BitsFromNaN( commonNaNT ); +uint32_t softfloat_propNaNFloat32Bits( uint32_t, uint32_t ); + +/*---------------------------------------------------------------------------- +| The pattern for a default generated double-precision NaN. +*----------------------------------------------------------------------------*/ +#define float64Bits_defaultNaN 0xFFF8000000000000 + +/*---------------------------------------------------------------------------- +| Returns 1 if the double-precision floating-point value `a' is a NaN; +| otherwise, returns 0. +*----------------------------------------------------------------------------*/ +*** COMMON +#define softfloat_isNaNFloat64Bits( a ) ( 0xFFE0000000000000 < (uint64_t) ( a )<<1 ) + + + + + + +/*---------------------------------------------------------------------------- +| Returns 1 if the double-precision floating-point value `a' is a signaling +| NaN; otherwise, returns 0. +*----------------------------------------------------------------------------*/ + +flag float64_is_signaling_nan( float64 a ) +{ + + return + ( ( ( a>>51 ) & 0xFFF ) == 0xFFE ) + && ( a & LIT64( 0x0007FFFFFFFFFFFF ) ); + +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the double-precision floating-point NaN +| `a' to the canonical NaN format. If `a' is a signaling NaN, the invalid +| exception is raised. +*----------------------------------------------------------------------------*/ + +static commonNaNT float64ToCommonNaN( float64 a ) +{ + commonNaNT z; + + if ( float64_is_signaling_nan( a ) ) float_raise( float_flag_invalid ); + z.sign = a>>63; + z.low = 0; + z.high = a<<12; + return z; + +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the canonical NaN `a' to the double- +| precision floating-point format. +*----------------------------------------------------------------------------*/ + +static float64 commonNaNToFloat64( commonNaNT a ) +{ + + return + ( ( (bits64) a.sign )<<63 ) + | LIT64( 0x7FF8000000000000 ) + | ( a.high>>12 ); + +} + +/*---------------------------------------------------------------------------- +| Takes two double-precision floating-point values `a' and `b', one of which +| is a NaN, and returns the appropriate NaN result. If either `a' or `b' is a +| signaling NaN, the invalid exception is raised. +*----------------------------------------------------------------------------*/ + +static float64 propagateFloat64NaN( float64 a, float64 b ) +{ + flag aIsNaN, aIsSignalingNaN, bIsNaN, bIsSignalingNaN; + + aIsNaN = float64_is_nan( a ); + aIsSignalingNaN = float64_is_signaling_nan( a ); + bIsNaN = float64_is_nan( b ); + bIsSignalingNaN = float64_is_signaling_nan( b ); + a |= LIT64( 0x0008000000000000 ); + b |= LIT64( 0x0008000000000000 ); + if ( aIsSignalingNaN | bIsSignalingNaN ) float_raise( float_flag_invalid ); + if ( aIsSignalingNaN ) { + if ( bIsSignalingNaN ) goto returnLargerSignificand; + return bIsNaN ? b : a; + } + else if ( aIsNaN ) { + if ( bIsSignalingNaN | ! bIsNaN ) return a; + returnLargerSignificand: + if ( (bits64) ( a<<1 ) < (bits64) ( b<<1 ) ) return b; + if ( (bits64) ( b<<1 ) < (bits64) ( a<<1 ) ) return a; + return ( a < b ) ? a : b; + } + else { + return b; + } + +} + +#ifdef FLOATX80 + +/*---------------------------------------------------------------------------- +| The pattern for a default generated extended double-precision NaN. The +| `high' and `low' values hold the most- and least-significant bits, +| respectively. +*----------------------------------------------------------------------------*/ +#define floatx80_default_nan_high 0xFFFF +#define floatx80_default_nan_low LIT64( 0xC000000000000000 ) + +/*---------------------------------------------------------------------------- +| Returns 1 if the extended double-precision floating-point value `a' is a +| NaN; otherwise, returns 0. +*----------------------------------------------------------------------------*/ + +flag floatx80_is_nan( floatx80 a ) +{ + + return ( ( a.high & 0x7FFF ) == 0x7FFF ) && (bits64) ( a.low<<1 ); + +} + +/*---------------------------------------------------------------------------- +| Returns 1 if the extended double-precision floating-point value `a' is a +| signaling NaN; otherwise, returns 0. +*----------------------------------------------------------------------------*/ + +flag floatx80_is_signaling_nan( floatx80 a ) +{ + bits64 aLow; + + aLow = a.low & ~ LIT64( 0x4000000000000000 ); + return + ( ( a.high & 0x7FFF ) == 0x7FFF ) + && (bits64) ( aLow<<1 ) + && ( a.low == aLow ); + +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the extended double-precision floating- +| point NaN `a' to the canonical NaN format. If `a' is a signaling NaN, the +| invalid exception is raised. +*----------------------------------------------------------------------------*/ + +static commonNaNT floatx80ToCommonNaN( floatx80 a ) +{ + commonNaNT z; + + if ( floatx80_is_signaling_nan( a ) ) float_raise( float_flag_invalid ); + z.sign = a.high>>15; + z.low = 0; + z.high = a.low<<1; + return z; + +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the canonical NaN `a' to the extended +| double-precision floating-point format. +*----------------------------------------------------------------------------*/ + +static floatx80 commonNaNToFloatx80( commonNaNT a ) +{ + floatx80 z; + + z.low = LIT64( 0xC000000000000000 ) | ( a.high>>1 ); + z.high = ( ( (bits16) a.sign )<<15 ) | 0x7FFF; + return z; + +} + +/*---------------------------------------------------------------------------- +| Takes two extended double-precision floating-point values `a' and `b', one +| of which is a NaN, and returns the appropriate NaN result. If either `a' or +| `b' is a signaling NaN, the invalid exception is raised. +*----------------------------------------------------------------------------*/ + +static floatx80 propagateFloatx80NaN( floatx80 a, floatx80 b ) +{ + flag aIsNaN, aIsSignalingNaN, bIsNaN, bIsSignalingNaN; + + aIsNaN = floatx80_is_nan( a ); + aIsSignalingNaN = floatx80_is_signaling_nan( a ); + bIsNaN = floatx80_is_nan( b ); + bIsSignalingNaN = floatx80_is_signaling_nan( b ); + a.low |= LIT64( 0xC000000000000000 ); + b.low |= LIT64( 0xC000000000000000 ); + if ( aIsSignalingNaN | bIsSignalingNaN ) float_raise( float_flag_invalid ); + if ( aIsSignalingNaN ) { + if ( bIsSignalingNaN ) goto returnLargerSignificand; + return bIsNaN ? b : a; + } + else if ( aIsNaN ) { + if ( bIsSignalingNaN | ! bIsNaN ) return a; + returnLargerSignificand: + if ( a.low < b.low ) return b; + if ( b.low < a.low ) return a; + return ( a.high < b.high ) ? a : b; + } + else { + return b; + } + +} + +#endif + +#ifdef FLOAT128 + +/*---------------------------------------------------------------------------- +| The pattern for a default generated quadruple-precision NaN. The `high' and +| `low' values hold the most- and least-significant bits, respectively. +*----------------------------------------------------------------------------*/ +#define float128_default_nan_high LIT64( 0xFFFF800000000000 ) +#define float128_default_nan_low LIT64( 0x0000000000000000 ) + +/*---------------------------------------------------------------------------- +| Returns 1 if the quadruple-precision floating-point value `a' is a NaN; +| otherwise, returns 0. +*----------------------------------------------------------------------------*/ + +flag float128_is_nan( float128 a ) +{ + + return + ( LIT64( 0xFFFE000000000000 ) <= (bits64) ( a.high<<1 ) ) + && ( a.low || ( a.high & LIT64( 0x0000FFFFFFFFFFFF ) ) ); + +} + +/*---------------------------------------------------------------------------- +| Returns 1 if the quadruple-precision floating-point value `a' is a +| signaling NaN; otherwise, returns 0. +*----------------------------------------------------------------------------*/ + +flag float128_is_signaling_nan( float128 a ) +{ + + return + ( ( ( a.high>>47 ) & 0xFFFF ) == 0xFFFE ) + && ( a.low || ( a.high & LIT64( 0x00007FFFFFFFFFFF ) ) ); + +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the quadruple-precision floating-point NaN +| `a' to the canonical NaN format. If `a' is a signaling NaN, the invalid +| exception is raised. +*----------------------------------------------------------------------------*/ + +static commonNaNT float128ToCommonNaN( float128 a ) +{ + commonNaNT z; + + if ( float128_is_signaling_nan( a ) ) float_raise( float_flag_invalid ); + z.sign = a.high>>63; + shortShift128Left( a.high, a.low, 16, &z.high, &z.low ); + return z; + +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the canonical NaN `a' to the quadruple- +| precision floating-point format. +*----------------------------------------------------------------------------*/ + +static float128 commonNaNToFloat128( commonNaNT a ) +{ + float128 z; + + shift128Right( a.high, a.low, 16, &z.high, &z.low ); + z.high |= ( ( (bits64) a.sign )<<63 ) | LIT64( 0x7FFF800000000000 ); + return z; + +} + +/*---------------------------------------------------------------------------- +| Takes two quadruple-precision floating-point values `a' and `b', one of +| which is a NaN, and returns the appropriate NaN result. If either `a' or +| `b' is a signaling NaN, the invalid exception is raised. +*----------------------------------------------------------------------------*/ + +static float128 propagateFloat128NaN( float128 a, float128 b ) +{ + flag aIsNaN, aIsSignalingNaN, bIsNaN, bIsSignalingNaN; + + aIsNaN = float128_is_nan( a ); + aIsSignalingNaN = float128_is_signaling_nan( a ); + bIsNaN = float128_is_nan( b ); + bIsSignalingNaN = float128_is_signaling_nan( b ); + a.high |= LIT64( 0x0000800000000000 ); + b.high |= LIT64( 0x0000800000000000 ); + if ( aIsSignalingNaN | bIsSignalingNaN ) float_raise( float_flag_invalid ); + if ( aIsSignalingNaN ) { + if ( bIsSignalingNaN ) goto returnLargerSignificand; + return bIsNaN ? b : a; + } + else if ( aIsNaN ) { + if ( bIsSignalingNaN | ! bIsNaN ) return a; + returnLargerSignificand: + if ( lt128( a.high<<1, a.low, b.high<<1, b.low ) ) return b; + if ( lt128( b.high<<1, b.low, a.high<<1, a.low ) ) return a; + return ( a.high < b.high ) ? a : b; + } + else { + return b; + } + +} + +#endif + diff --git a/softfloat/8086/platform.h b/softfloat/8086/platform.h new file mode 100755 index 0000000..9355edf --- /dev/null +++ b/softfloat/8086/platform.h @@ -0,0 +1,38 @@ + +/*============================================================================ + +*** FIX. + +This C source fragment is part of the SoftFloat IEC/IEEE Floating-point +Arithmetic Package, Release 2b. + +Written by John R. Hauser. This work was made possible in part by the +International Computer Science Institute, located at Suite 600, 1947 Center +Street, Berkeley, California 94704. Funding was partially provided by the +National Science Foundation under grant MIP-9311980. The original version +of this code was written as part of a project to build a fixed-point vector +processor in collaboration with the University of California at Berkeley, +overseen by Profs. Nelson Morgan and John Wawrzynek. More information +is available through the Web page `http://www.cs.berkeley.edu/~jhauser/ +arithmetic/SoftFloat.html'. + +THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has +been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES +RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS +AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES, +COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE +EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE +INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR +OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE. + +Derivative works are acceptable, even for commercial purposes, so long as +(1) the source code for the derivative work includes prominent notice that +the work is derivative, and (2) the source code includes prominent notice with +these four paragraphs for those parts of this code that are retained. + +=============================================================================*/ + +/*---------------------------------------------------------------------------- +*----------------------------------------------------------------------------*/ +#define LITTLEENDIAN + diff --git a/softfloat/8086/s_commonNaNToF32UI.c b/softfloat/8086/s_commonNaNToF32UI.c new file mode 100755 index 0000000..3b96c41 --- /dev/null +++ b/softfloat/8086/s_commonNaNToF32UI.c @@ -0,0 +1,17 @@ + +#include +#include "platform.h" +#include "specialize.h" + +/*---------------------------------------------------------------------------- +| Returns the result of converting the canonical NaN `a' to the single- +| precision floating-point format. +*----------------------------------------------------------------------------*/ + +uint_fast32_t softfloat_commonNaNToF32UI( struct commonNaN a ) +{ + + return (uint_fast32_t) a.sign<<31 | 0x7FC00000 | a.v64>>41; + +} + diff --git a/softfloat/8086/s_commonNaNToF64UI.c b/softfloat/8086/s_commonNaNToF64UI.c new file mode 100755 index 0000000..474ceee --- /dev/null +++ b/softfloat/8086/s_commonNaNToF64UI.c @@ -0,0 +1,19 @@ + +#include +#include "platform.h" +#include "specialize.h" + +/*---------------------------------------------------------------------------- +| Returns the result of converting the canonical NaN `a' to the double- +| precision floating-point format. +*----------------------------------------------------------------------------*/ + +uint_fast64_t softfloat_commonNaNToF64UI( struct commonNaN a ) +{ + + return + (uint_fast64_t) a.sign<<63 | UINT64_C( 0x7FF8000000000000 ) + | a.v64>>12; + +} + diff --git a/softfloat/8086/s_f32UIToCommonNaN.c b/softfloat/8086/s_f32UIToCommonNaN.c new file mode 100755 index 0000000..067e8da --- /dev/null +++ b/softfloat/8086/s_f32UIToCommonNaN.c @@ -0,0 +1,25 @@ + +#include +#include "platform.h" +#include "specialize.h" +#include "softfloat.h" + +/*---------------------------------------------------------------------------- +| Returns the result of converting the single-precision floating-point NaN +| `a' to the canonical NaN format. If `a' is a signaling NaN, the invalid +| exception is raised. +*----------------------------------------------------------------------------*/ +struct commonNaN softfloat_f32UIToCommonNaN( uint_fast32_t uiA ) +{ + struct commonNaN z; + + if ( softfloat_isSigNaNF32UI( uiA ) ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + } + z.sign = uiA>>31; + z.v64 = (uint_fast64_t) uiA<<41; + z.v0 = 0; + return z; + +} + diff --git a/softfloat/8086/s_f64UIToCommonNaN.c b/softfloat/8086/s_f64UIToCommonNaN.c new file mode 100755 index 0000000..f933ded --- /dev/null +++ b/softfloat/8086/s_f64UIToCommonNaN.c @@ -0,0 +1,25 @@ + +#include +#include "platform.h" +#include "specialize.h" +#include "softfloat.h" + +/*---------------------------------------------------------------------------- +| Returns the result of converting the double-precision floating-point NaN +| `a' to the canonical NaN format. If `a' is a signaling NaN, the invalid +| exception is raised. +*----------------------------------------------------------------------------*/ +struct commonNaN softfloat_f64UIToCommonNaN( uint_fast64_t uiA ) +{ + struct commonNaN z; + + if ( softfloat_isSigNaNF64UI( uiA ) ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + } + z.sign = uiA>>63; + z.v64 = uiA<<12; + z.v0 = 0; + return z; + +} + diff --git a/softfloat/8086/s_isSigNaNF32UI.c b/softfloat/8086/s_isSigNaNF32UI.c new file mode 100755 index 0000000..0a9c33f --- /dev/null +++ b/softfloat/8086/s_isSigNaNF32UI.c @@ -0,0 +1,13 @@ + +#include +#include +#include "platform.h" +#include "specialize.h" + +bool softfloat_isSigNaNF32UI( uint_fast32_t ui ) +{ + + return ( ( ui>>22 & 0x1FF ) == 0x1FE ) && ( ui & 0x003FFFFF ); + +} + diff --git a/softfloat/8086/s_isSigNaNF64UI.c b/softfloat/8086/s_isSigNaNF64UI.c new file mode 100755 index 0000000..d255213 --- /dev/null +++ b/softfloat/8086/s_isSigNaNF64UI.c @@ -0,0 +1,15 @@ + +#include +#include +#include "platform.h" +#include "specialize.h" + +bool softfloat_isSigNaNF64UI( uint_fast64_t ui ) +{ + + return + ( ( ui>>51 & 0xFFF ) == 0xFFE ) + && ( ui & UINT64_C( 0x0007FFFFFFFFFFFF ) ); + +} + diff --git a/softfloat/8086/s_propagateNaNF32UI.c b/softfloat/8086/s_propagateNaNF32UI.c new file mode 100755 index 0000000..07774e8 --- /dev/null +++ b/softfloat/8086/s_propagateNaNF32UI.c @@ -0,0 +1,55 @@ + +/*** UPDATE COMMENTS. ***/ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +/*---------------------------------------------------------------------------- +| Takes two single-precision floating-point values `a' and `b', one of which +| is a NaN, and returns the appropriate NaN result. If either `a' or `b' is a +| signaling NaN, the invalid exception is raised. +*----------------------------------------------------------------------------*/ + +uint_fast32_t + softfloat_propagateNaNF32UI( uint_fast32_t uiA, uint_fast32_t uiB ) +{ + bool isNaNA, isSigNaNA, isNaNB, isSigNaNB; + uint_fast32_t uiMagA, uiMagB; + + /*------------------------------------------------------------------------ + *------------------------------------------------------------------------*/ + isNaNA = isNaNF32UI( uiA ); + isSigNaNA = softfloat_isSigNaNF32UI( uiA ); + isNaNB = isNaNF32UI( uiB ); + isSigNaNB = softfloat_isSigNaNF32UI( uiB ); + /*------------------------------------------------------------------------ + | Make NaNs non-signaling. + *------------------------------------------------------------------------*/ + uiA |= 0x00400000; + uiB |= 0x00400000; + /*------------------------------------------------------------------------ + *------------------------------------------------------------------------*/ + if ( isSigNaNA | isSigNaNB ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + } + if ( isSigNaNA ) { + if ( isSigNaNB ) goto returnLargerSignificand; + return isNaNB ? uiB : uiA; + } else if ( isNaNA ) { + if ( isSigNaNB || ! isNaNB ) return uiA; + returnLargerSignificand: + uiMagA = uiA<<1; + uiMagB = uiB<<1; + if ( uiMagA < uiMagB ) return uiB; + if ( uiMagB < uiMagA ) return uiA; + return ( uiA < uiB ) ? uiA : uiB; + } else { + return uiB; + } + +} + diff --git a/softfloat/8086/s_propagateNaNF64UI.c b/softfloat/8086/s_propagateNaNF64UI.c new file mode 100755 index 0000000..0ff6446 --- /dev/null +++ b/softfloat/8086/s_propagateNaNF64UI.c @@ -0,0 +1,55 @@ + +/*** UPDATE COMMENTS. ***/ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +/*---------------------------------------------------------------------------- +| Takes two double-precision floating-point values `a' and `b', one of which +| is a NaN, and returns the appropriate NaN result. If either `a' or `b' is a +| signaling NaN, the invalid exception is raised. +*----------------------------------------------------------------------------*/ + +uint_fast64_t + softfloat_propagateNaNF64UI( uint_fast64_t uiA, uint_fast64_t uiB ) +{ + bool isNaNA, isSigNaNA, isNaNB, isSigNaNB; + uint_fast64_t uiMagA, uiMagB; + + /*------------------------------------------------------------------------ + *------------------------------------------------------------------------*/ + isNaNA = isNaNF64UI( uiA ); + isSigNaNA = softfloat_isSigNaNF64UI( uiA ); + isNaNB = isNaNF64UI( uiB ); + isSigNaNB = softfloat_isSigNaNF64UI( uiB ); + /*------------------------------------------------------------------------ + | Make NaNs non-signaling. + *------------------------------------------------------------------------*/ + uiA |= UINT64_C( 0x0008000000000000 ); + uiB |= UINT64_C( 0x0008000000000000 ); + /*------------------------------------------------------------------------ + *------------------------------------------------------------------------*/ + if ( isSigNaNA | isSigNaNB ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + } + if ( isSigNaNA ) { + if ( isSigNaNB ) goto returnLargerSignificand; + return isNaNB ? uiB : uiA; + } else if ( isNaNA ) { + if ( isSigNaNB || ! isNaNB ) return uiA; + returnLargerSignificand: + uiMagA = uiA & UINT64_C( 0x7FFFFFFFFFFFFFFF ); + uiMagB = uiB & UINT64_C( 0x7FFFFFFFFFFFFFFF ); + if ( uiMagA < uiMagB ) return uiB; + if ( uiMagB < uiMagA ) return uiA; + return ( uiA < uiB ) ? uiA : uiB; + } else { + return uiB; + } + +} + diff --git a/softfloat/8086/softfloat_raiseFlags.c b/softfloat/8086/softfloat_raiseFlags.c new file mode 100755 index 0000000..c0c0dc8 --- /dev/null +++ b/softfloat/8086/softfloat_raiseFlags.c @@ -0,0 +1,51 @@ + +/*============================================================================ + +*** FIX. + +This C source fragment is part of the SoftFloat IEC/IEEE Floating-point +Arithmetic Package, Release 2b. + +Written by John R. Hauser. This work was made possible in part by the +International Computer Science Institute, located at Suite 600, 1947 Center +Street, Berkeley, California 94704. Funding was partially provided by the +National Science Foundation under grant MIP-9311980. The original version +of this code was written as part of a project to build a fixed-point vector +processor in collaboration with the University of California at Berkeley, +overseen by Profs. Nelson Morgan and John Wawrzynek. More information +is available through the Web page `http://www.cs.berkeley.edu/~jhauser/ +arithmetic/SoftFloat.html'. + +THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has +been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES +RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS +AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES, +COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE +EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE +INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR +OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE. + +Derivative works are acceptable, even for commercial purposes, so long as +(1) the source code for the derivative work includes prominent notice that +the work is derivative, and (2) the source code includes prominent notice with +these four paragraphs for those parts of this code that are retained. + +=============================================================================*/ + +#include "platform.h" +#include "softfloat.h" + +/*---------------------------------------------------------------------------- +| Raises the exceptions specified by `flags'. Floating-point traps can be +| defined here if desired. It is currently not possible for such a trap +| to substitute a result value. If traps are not implemented, this routine +| should be simply `float_exception_flags |= flags;'. +*----------------------------------------------------------------------------*/ + +void softfloat_raiseFlags( int_fast8_t flags ) +{ + + softfloat_exceptionFlags |= flags; + +} + diff --git a/softfloat/8086/softfloat_types.h b/softfloat/8086/softfloat_types.h new file mode 100755 index 0000000..b5c1828 --- /dev/null +++ b/softfloat/8086/softfloat_types.h @@ -0,0 +1,16 @@ + +#ifndef softfloat_types_h +#define softfloat_types_h + +/*** COMMENTS. ***/ + +#include +#include + +typedef struct { uint32_t v; } float32_t; +typedef struct { uint64_t v; } float64_t; +typedef struct { uint64_t v; uint16_t x; } floatx80_t; +typedef struct { uint64_t v[ 2 ]; } float128_t; + +#endif + diff --git a/softfloat/8086/specialize.h b/softfloat/8086/specialize.h new file mode 100755 index 0000000..ca0bb1d --- /dev/null +++ b/softfloat/8086/specialize.h @@ -0,0 +1,113 @@ + +/*============================================================================ + +*** FIX. + +This C source fragment is part of the SoftFloat IEC/IEEE Floating-point +Arithmetic Package, Release 2b. + +Written by John R. Hauser. This work was made possible in part by the +International Computer Science Institute, located at Suite 600, 1947 Center +Street, Berkeley, California 94704. Funding was partially provided by the +National Science Foundation under grant MIP-9311980. The original version +of this code was written as part of a project to build a fixed-point vector +processor in collaboration with the University of California at Berkeley, +overseen by Profs. Nelson Morgan and John Wawrzynek. More information +is available through the Web page `http://www.cs.berkeley.edu/~jhauser/ +arithmetic/SoftFloat.html'. + +THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has +been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES +RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS +AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES, +COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE +EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE +INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR +OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE. + +Derivative works are acceptable, even for commercial purposes, so long as +(1) the source code for the derivative work includes prominent notice that +the work is derivative, and (2) the source code includes prominent notice with +these four paragraphs for those parts of this code that are retained. + +=============================================================================*/ + +#include +#include + +/*---------------------------------------------------------------------------- +*----------------------------------------------------------------------------*/ +#define init_detectTininess softfloat_tininess_afterRounding; + +/*---------------------------------------------------------------------------- +| Structure used to transfer NaN representations from one format to another. +*----------------------------------------------------------------------------*/ +struct commonNaN { + bool sign; + uint64_t v64, v0; +}; + +/*---------------------------------------------------------------------------- +| The pattern for a default generated single-precision NaN. +*----------------------------------------------------------------------------*/ +#define defaultNaNF32UI 0xFFC00000 + +/*---------------------------------------------------------------------------- +| Returns 1 if the single-precision floating-point value `a' is a signaling +| NaN; otherwise, returns 0. +*----------------------------------------------------------------------------*/ +#if defined INLINE_LEVEL && ( 1 <= INLINE_LEVEL ) +INLINE bool softfloat_isSigNaNF32UI( uint_fast32_t ui ) + { return ( ( ui>>22 & 0x1FF ) == 0x1FE ) && ( ui & 0x003FFFFF ); } +#else +bool softfloat_isSigNaNF32UI( uint_fast32_t ); +#endif + +/*---------------------------------------------------------------------------- +*----------------------------------------------------------------------------*/ +struct commonNaN softfloat_f32UIToCommonNaN( uint_fast32_t ); +#if defined INLINE_LEVEL && ( 1 <= INLINE_LEVEL ) +INLINE uint_fast32_t softfloat_commonNaNToF32UI( struct commonNaN a ) + { return (uint_fast32_t) a.sign<<31 | 0x7FC00000 | a.v64>>41; } +#else +uint_fast32_t softfloat_commonNaNToF32UI( struct commonNaN ); +#endif + +/*---------------------------------------------------------------------------- +| Takes two single-precision floating-point values `a' and `b', one of which +| is a NaN, and returns the appropriate NaN result. If either `a' or `b' is a +| signaling NaN, the invalid exception is raised. +*----------------------------------------------------------------------------*/ +uint_fast32_t softfloat_propagateNaNF32UI( uint_fast32_t, uint_fast32_t ); + +/*---------------------------------------------------------------------------- +| The pattern for a default generated double-precision NaN. +*----------------------------------------------------------------------------*/ +#define defaultNaNF64UI UINT64_C(0xFFF8000000000000) + +/*---------------------------------------------------------------------------- +*----------------------------------------------------------------------------*/ +#if defined INLINE_LEVEL && ( 1 <= INLINE_LEVEL ) +INLINE bool softfloat_isSigNaNF64UI( uint_fast64_t ui ) +{ + return + ( ( ui>>51 & 0xFFF ) == 0xFFE ) + && ( ui & UINT64_C( 0x0007FFFFFFFFFFFF ) ); +} +#else +bool softfloat_isSigNaNF64UI( uint_fast64_t ); +#endif + +/*---------------------------------------------------------------------------- +*----------------------------------------------------------------------------*/ +/*** MIGHT BE INLINE'D. ***/ +struct commonNaN softfloat_f64UIToCommonNaN( uint_fast64_t ); +uint_fast64_t softfloat_commonNaNToF64UI( struct commonNaN ); + +/*---------------------------------------------------------------------------- +| Takes two double-precision floating-point values `a' and `b', one of which +| is a NaN, and returns the appropriate NaN result. If either `a' or `b' is a +| signaling NaN, the invalid exception is raised. +*----------------------------------------------------------------------------*/ +uint_fast64_t softfloat_propagateNaNF64UI( uint_fast64_t, uint_fast64_t ); + diff --git a/softfloat/f32_add.c b/softfloat/f32_add.c new file mode 100755 index 0000000..dc53d68 --- /dev/null +++ b/softfloat/f32_add.c @@ -0,0 +1,29 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" + +float32_t f32_add( float32_t a, float32_t b ) +{ + union ui32_f32 uA; + uint_fast32_t uiA; + bool signA; + union ui32_f32 uB; + uint_fast32_t uiB; + bool signB; + float32_t ( *magsRoutine )( uint_fast32_t, uint_fast32_t, bool ); + + uA.f = a; + uiA = uA.ui; + signA = signF32UI( uiA ); + uB.f = b; + uiB = uB.ui; + signB = signF32UI( uiB ); + magsRoutine = + ( signA == signB ) ? softfloat_addMagsF32 : softfloat_subMagsF32; + return magsRoutine( uiA, uiB, signA ); + +} + diff --git a/softfloat/f32_div.c b/softfloat/f32_div.c new file mode 100755 index 0000000..958b140 --- /dev/null +++ b/softfloat/f32_div.c @@ -0,0 +1,96 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +float32_t f32_div( float32_t a, float32_t b ) +{ + union ui32_f32 uA; + uint_fast32_t uiA; + bool signA; + int_fast16_t expA; + uint_fast32_t sigA; + union ui32_f32 uB; + uint_fast32_t uiB; + bool signB; + int_fast16_t expB; + uint_fast32_t sigB; + bool signZ; + struct exp16_sig32 normExpSig; + int_fast16_t expZ; + uint_fast32_t sigZ; + uint_fast32_t uiZ; + union ui32_f32 uZ; + + uA.f = a; + uiA = uA.ui; + signA = signF32UI( uiA ); + expA = expF32UI( uiA ); + sigA = fracF32UI( uiA ); + uB.f = b; + uiB = uB.ui; + signB = signF32UI( uiB ); + expB = expF32UI( uiB ); + sigB = fracF32UI( uiB ); + signZ = signA ^ signB; + if ( expA == 0xFF ) { + if ( sigA ) goto propagateNaN; + if ( expB == 0xFF ) { + if ( sigB ) goto propagateNaN; + goto invalid; + } + goto infinity; + } + if ( expB == 0xFF ) { + if ( sigB ) goto propagateNaN; + goto zero; + } + if ( ! expB ) { + if ( ! sigB ) { + if ( ! ( expA | sigA ) ) goto invalid; + softfloat_raiseFlags( softfloat_flag_infinity ); + goto infinity; + } + normExpSig = softfloat_normSubnormalF32Sig( sigB ); + expB = normExpSig.exp; + sigB = normExpSig.sig; + } + if ( ! expA ) { + if ( ! sigA ) goto zero; + normExpSig = softfloat_normSubnormalF32Sig( sigA ); + expA = normExpSig.exp; + sigA = normExpSig.sig; + } + expZ = expA - expB + 0x7D; + sigA = ( sigA | 0x00800000 )<<7; + sigB = ( sigB | 0x00800000 )<<8; + if ( sigB <= ( sigA + sigA ) ) { + ++expZ; + sigA >>= 1; + } + sigZ = ( (uint_fast64_t) sigA<<32 ) / sigB; + if ( ! ( sigZ & 0x3F ) ) { + sigZ |= ( (uint_fast64_t) sigB * sigZ != (uint_fast64_t) sigA<<32 ); + } + return softfloat_roundPackToF32( signZ, expZ, sigZ ); + propagateNaN: + uiZ = softfloat_propagateNaNF32UI( uiA, uiB ); + goto uiZ; + invalid: + softfloat_raiseFlags( softfloat_flag_invalid ); + uiZ = defaultNaNF32UI; + goto uiZ; + infinity: + uiZ = packToF32UI( signZ, 0xFF, 0 ); + goto uiZ; + zero: + uiZ = packToF32UI( signZ, 0, 0 ); + uiZ: + uZ.ui = uiZ; + return uZ.f; + +} + diff --git a/softfloat/f32_eq.c b/softfloat/f32_eq.c new file mode 100755 index 0000000..8f2306b --- /dev/null +++ b/softfloat/f32_eq.c @@ -0,0 +1,34 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +bool f32_eq( float32_t a, float32_t b ) +{ + union ui32_f32 uA; + uint_fast32_t uiA; + union ui32_f32 uB; + uint_fast32_t uiB; + + uA.f = a; + uiA = uA.ui; + uB.f = b; + uiB = uB.ui; + if ( + ( ( expF32UI( uiA ) == 0xFF ) && fracF32UI( uiA ) ) + || ( ( expF32UI( uiB ) == 0xFF ) && fracF32UI( uiB ) ) + ) { + if ( + softfloat_isSigNaNF32UI( uiA ) || softfloat_isSigNaNF32UI( uiB ) + ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + } + return false; + } + return ( uiA == uiB ) || ! (uint32_t) ( ( uiA | uiB )<<1 ); + +} + diff --git a/softfloat/f32_eq_signaling.c b/softfloat/f32_eq_signaling.c new file mode 100755 index 0000000..bfba48a --- /dev/null +++ b/softfloat/f32_eq_signaling.c @@ -0,0 +1,29 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" + +bool f32_eq_signaling( float32_t a, float32_t b ) +{ + union ui32_f32 uA; + uint_fast32_t uiA; + union ui32_f32 uB; + uint_fast32_t uiB; + + uA.f = a; + uiA = uA.ui; + uB.f = b; + uiB = uB.ui; + if ( + ( ( expF32UI( uiA ) == 0xFF ) && fracF32UI( uiA ) ) + || ( ( expF32UI( uiB ) == 0xFF ) && fracF32UI( uiB ) ) + ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + return false; + } + return ( uiA == uiB ) || ! (uint32_t) ( ( uiA | uiB )<<1 ); + +} + diff --git a/softfloat/f32_isSignalingNaN.c b/softfloat/f32_isSignalingNaN.c new file mode 100755 index 0000000..09aaa82 --- /dev/null +++ b/softfloat/f32_isSignalingNaN.c @@ -0,0 +1,16 @@ + +#include +#include "platform.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +bool f32_isSignalingNaN( float32_t a ) +{ + union ui32_f32 uA; + + uA.f = a; + return softfloat_isSigNaNF32UI( uA.ui ); + +} + diff --git a/softfloat/f32_le.c b/softfloat/f32_le.c new file mode 100755 index 0000000..5f47be5 --- /dev/null +++ b/softfloat/f32_le.c @@ -0,0 +1,34 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" + +bool f32_le( float32_t a, float32_t b ) +{ + union ui32_f32 uA; + uint_fast32_t uiA; + union ui32_f32 uB; + uint_fast32_t uiB; + bool signA, signB; + + uA.f = a; + uiA = uA.ui; + uB.f = b; + uiB = uB.ui; + if ( + ( ( expF32UI( uiA ) == 0xFF ) && fracF32UI( uiA ) ) + || ( ( expF32UI( uiB ) == 0xFF ) && fracF32UI( uiB ) ) + ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + return false; + } + signA = signF32UI( uiA ); + signB = signF32UI( uiB ); + return + ( signA != signB ) ? signA || ! (uint32_t) ( ( uiA | uiB )<<1 ) + : ( uiA == uiB ) || ( signA ^ ( uiA < uiB ) ); + +} + diff --git a/softfloat/f32_le_quiet.c b/softfloat/f32_le_quiet.c new file mode 100755 index 0000000..2b541da --- /dev/null +++ b/softfloat/f32_le_quiet.c @@ -0,0 +1,39 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +bool f32_le_quiet( float32_t a, float32_t b ) +{ + union ui32_f32 uA; + uint_fast32_t uiA; + union ui32_f32 uB; + uint_fast32_t uiB; + bool signA, signB; + + uA.f = a; + uiA = uA.ui; + uB.f = b; + uiB = uB.ui; + if ( + ( ( expF32UI( uiA ) == 0xFF ) && fracF32UI( uiA ) ) + || ( ( expF32UI( uiB ) == 0xFF ) && fracF32UI( uiB ) ) + ) { + if ( + softfloat_isSigNaNF32UI( uiA ) || softfloat_isSigNaNF32UI( uiB ) + ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + } + return false; + } + signA = signF32UI( uiA ); + signB = signF32UI( uiB ); + return + ( signA != signB ) ? signA || ! (uint32_t) ( ( uiA | uiB )<<1 ) + : ( uiA == uiB ) || ( signA ^ ( uiA < uiB ) ); + +} + diff --git a/softfloat/f32_lt.c b/softfloat/f32_lt.c new file mode 100755 index 0000000..753b28a --- /dev/null +++ b/softfloat/f32_lt.c @@ -0,0 +1,34 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" + +bool f32_lt( float32_t a, float32_t b ) +{ + union ui32_f32 uA; + uint_fast32_t uiA; + union ui32_f32 uB; + uint_fast32_t uiB; + bool signA, signB; + + uA.f = a; + uiA = uA.ui; + uB.f = b; + uiB = uB.ui; + if ( + ( ( expF32UI( uiA ) == 0xFF ) && fracF32UI( uiA ) ) + || ( ( expF32UI( uiB ) == 0xFF ) && fracF32UI( uiB ) ) + ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + return false; + } + signA = signF32UI( uiA ); + signB = signF32UI( uiB ); + return + ( signA != signB ) ? signA && ( (uint32_t) ( ( uiA | uiB )<<1 ) != 0 ) + : ( uiA != uiB ) && ( signA ^ ( uiA < uiB ) ); + +} + diff --git a/softfloat/f32_lt_quiet.c b/softfloat/f32_lt_quiet.c new file mode 100755 index 0000000..ecd90bf --- /dev/null +++ b/softfloat/f32_lt_quiet.c @@ -0,0 +1,39 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +bool f32_lt_quiet( float32_t a, float32_t b ) +{ + union ui32_f32 uA; + uint_fast32_t uiA; + union ui32_f32 uB; + uint_fast32_t uiB; + bool signA, signB; + + uA.f = a; + uiA = uA.ui; + uB.f = b; + uiB = uB.ui; + if ( + ( ( expF32UI( uiA ) == 0xFF ) && fracF32UI( uiA ) ) + || ( ( expF32UI( uiB ) == 0xFF ) && fracF32UI( uiB ) ) + ) { + if ( + softfloat_isSigNaNF32UI( uiA ) || softfloat_isSigNaNF32UI( uiB ) + ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + } + return false; + } + signA = signF32UI( uiA ); + signB = signF32UI( uiB ); + return + ( signA != signB ) ? signA && ( (uint32_t) ( ( uiA | uiB )<<1 ) != 0 ) + : ( uiA != uiB ) && ( signA ^ ( uiA < uiB ) ); + +} + diff --git a/softfloat/f32_mul.c b/softfloat/f32_mul.c new file mode 100755 index 0000000..d49c1dd --- /dev/null +++ b/softfloat/f32_mul.c @@ -0,0 +1,89 @@ + +#include +#include +#include "platform.h" +#include "primitives.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +float32_t f32_mul( float32_t a, float32_t b ) +{ + union ui32_f32 uA; + uint_fast32_t uiA; + bool signA; + int_fast16_t expA; + uint_fast32_t sigA; + union ui32_f32 uB; + uint_fast32_t uiB; + bool signB; + int_fast16_t expB; + uint_fast32_t sigB; + bool signZ; + uint_fast32_t magBits; + struct exp16_sig32 normExpSig; + int_fast16_t expZ; + uint_fast32_t sigZ, uiZ; + union ui32_f32 uZ; + + uA.f = a; + uiA = uA.ui; + signA = signF32UI( uiA ); + expA = expF32UI( uiA ); + sigA = fracF32UI( uiA ); + uB.f = b; + uiB = uB.ui; + signB = signF32UI( uiB ); + expB = expF32UI( uiB ); + sigB = fracF32UI( uiB ); + signZ = signA ^ signB; + if ( expA == 0xFF ) { + if ( sigA || ( ( expB == 0xFF ) && sigB ) ) goto propagateNaN; + magBits = expB | sigB; + goto infArg; + } + if ( expB == 0xFF ) { + if ( sigB ) goto propagateNaN; + magBits = expA | sigA; + goto infArg; + } + if ( ! expA ) { + if ( ! sigA ) goto zero; + normExpSig = softfloat_normSubnormalF32Sig( sigA ); + expA = normExpSig.exp; + sigA = normExpSig.sig; + } + if ( ! expB ) { + if ( ! sigB ) goto zero; + normExpSig = softfloat_normSubnormalF32Sig( sigB ); + expB = normExpSig.exp; + sigB = normExpSig.sig; + } + expZ = expA + expB - 0x7F; + sigA = ( sigA | 0x00800000 )<<7; + sigB = ( sigB | 0x00800000 )<<8; + sigZ = softfloat_shortShift64RightJam( (uint_fast64_t) sigA * sigB, 32 ); + if ( sigZ < 0x40000000 ) { + --expZ; + sigZ <<= 1; + } + return softfloat_roundPackToF32( signZ, expZ, sigZ ); + propagateNaN: + uiZ = softfloat_propagateNaNF32UI( uiA, uiB ); + goto uiZ; + infArg: + if ( ! magBits ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + uiZ = defaultNaNF32UI; + } else { + uiZ = packToF32UI( signZ, 0xFF, 0 ); + } + goto uiZ; + zero: + uiZ = packToF32UI( signZ, 0, 0 ); + uiZ: + uZ.ui = uiZ; + return uZ.f; + +} + diff --git a/softfloat/f32_mulAdd.c b/softfloat/f32_mulAdd.c new file mode 100755 index 0000000..3d4cee9 --- /dev/null +++ b/softfloat/f32_mulAdd.c @@ -0,0 +1,25 @@ + +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" + +float32_t f32_mulAdd( float32_t a, float32_t b, float32_t c ) +{ + union ui32_f32 uA; + uint_fast32_t uiA; + union ui32_f32 uB; + uint_fast32_t uiB; + union ui32_f32 uC; + uint_fast32_t uiC; + + uA.f = a; + uiA = uA.ui; + uB.f = b; + uiB = uB.ui; + uC.f = c; + uiC = uC.ui; + return softfloat_mulAddF32( 0, uiA, uiB, uiC ); + +} + diff --git a/softfloat/f32_rem.c b/softfloat/f32_rem.c new file mode 100755 index 0000000..d29b840 --- /dev/null +++ b/softfloat/f32_rem.c @@ -0,0 +1,124 @@ + +#include +#include +#include "platform.h" +#include "primitives.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +float32_t f32_rem( float32_t a, float32_t b ) +{ + union ui32_f32 uA; + uint_fast32_t uiA; + bool signA; + int_fast16_t expA; + uint_fast32_t sigA; + union ui32_f32 uB; + uint_fast32_t uiB; + bool signB; + int_fast16_t expB; + uint_fast32_t sigB; + struct exp16_sig32 normExpSig; + int_fast16_t expDiff; + uint_fast32_t q; + uint_fast64_t sigA64, sigB64, q64; + uint_fast32_t alternateSigA; + uint32_t sigMean; + bool signZ; + uint_fast32_t uiZ; + union ui32_f32 uZ; + + uA.f = a; + uiA = uA.ui; + signA = signF32UI( uiA ); + expA = expF32UI( uiA ); + sigA = fracF32UI( uiA ); + uB.f = b; + uiB = uB.ui; + signB = signF32UI( uiB ); + expB = expF32UI( uiB ); + sigB = fracF32UI( uiB ); + if ( expA == 0xFF ) { + if ( sigA || ( ( expB == 0xFF ) && sigB ) ) goto propagateNaN; + goto invalid; + } + if ( expB == 0xFF ) { + if ( sigB ) goto propagateNaN; + return a; + } + if ( ! expB ) { + if ( ! sigB ) goto invalid; + normExpSig = softfloat_normSubnormalF32Sig( sigB ); + expB = normExpSig.exp; + sigB = normExpSig.sig; + } + if ( ! expA ) { + if ( ! sigA ) return a; + normExpSig = softfloat_normSubnormalF32Sig( sigA ); + expA = normExpSig.exp; + sigA = normExpSig.sig; + } + expDiff = expA - expB; + sigA |= 0x00800000; + sigB |= 0x00800000; + if ( expDiff < 32 ) { + sigA <<= 8; + sigB <<= 8; + if ( expDiff < 0 ) { + if ( expDiff < -1 ) return a; + sigA >>= 1; + } + q = ( sigB <= sigA ); + if ( q ) sigA -= sigB; + if ( 0 < expDiff ) { + q = ( (uint_fast64_t) sigA<<32 ) / sigB; + q >>= 32 - expDiff; + sigB >>= 2; + sigA = ( ( sigA>>1 )<<( expDiff - 1 ) ) - sigB * q; + } else { + sigA >>= 2; + sigB >>= 2; + } + } else { + if ( sigB <= sigA ) sigA -= sigB; + sigA64 = (uint_fast64_t) sigA<<40; + sigB64 = (uint_fast64_t) sigB<<40; + expDiff -= 64; + while ( 0 < expDiff ) { + q64 = softfloat_estimateDiv128To64( sigA64, 0, sigB64 ); + q64 = ( 2 < q64 ) ? q64 - 2 : 0; + sigA64 = - ( ( sigB * q64 )<<38 ); + expDiff -= 62; + } + expDiff += 64; + q64 = softfloat_estimateDiv128To64( sigA64, 0, sigB64 ); + q64 = ( 2 < q64 ) ? q64 - 2 : 0; + q = q64>>( 64 - expDiff ); + sigB <<= 6; + sigA = ( ( sigA64>>33 )<<( expDiff - 1 ) ) - sigB * q; + } + do { + alternateSigA = sigA; + ++q; + sigA -= sigB; + } while ( sigA < 0x80000000 ); + sigMean = sigA + alternateSigA; + if ( ( 0x80000000 <= sigMean ) || ( ! sigMean && ( q & 1 ) ) ) { + sigA = alternateSigA; + } + signZ = ( 0x80000000 <= sigA ); + if ( signZ ) sigA = - sigA; + return softfloat_normRoundPackToF32( signA ^ signZ, expB, sigA ); + propagateNaN: + uiZ = softfloat_propagateNaNF32UI( uiA, uiB ); + goto uiZ; + invalid: + softfloat_raiseFlags( softfloat_flag_invalid ); + uiZ = defaultNaNF32UI; + uiZ: + uZ.ui = uiZ; + return uZ.f; + +} + diff --git a/softfloat/f32_roundToInt.c b/softfloat/f32_roundToInt.c new file mode 100755 index 0000000..f8f9114 --- /dev/null +++ b/softfloat/f32_roundToInt.c @@ -0,0 +1,78 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +float32_t f32_roundToInt( float32_t a, int_fast8_t roundingMode, bool exact ) +{ + union ui32_f32 uA; + uint_fast32_t uiA; + int_fast16_t expA; + uint_fast32_t uiZ; + bool signA; + uint_fast32_t lastBitMask, roundBitsMask; + union ui32_f32 uZ; + + uA.f = a; + uiA = uA.ui; + expA = expF32UI( uiA ); + if ( 0x96 <= expA ) { + if ( ( expA == 0xFF ) && fracF32UI( uiA ) ) { + uiZ = softfloat_propagateNaNF32UI( uiA, 0 ); + goto uiZ; + } + return a; + } + if ( expA <= 0x7E ) { + if ( ! (uint32_t) ( uiA<<1 ) ) return a; + if ( exact ) softfloat_exceptionFlags |= softfloat_flag_inexact; + signA = signF32UI( uiA ); + switch ( roundingMode ) { + case softfloat_round_nearest_even: + if ( ( expA == 0x7E ) && fracF32UI( uiA ) ) { + uiZ = packToF32UI( signA, 0x7F, 0 ); + goto uiZ; + } + break; + case softfloat_round_min: + uiZ = signA ? 0xBF800000 : 0; + goto uiZ; + case softfloat_round_max: + uiZ = signA ? 0x80000000 : 0x3F800000; + goto uiZ; + case softfloat_round_nearest_maxMag: + if ( expA == 0x7E ) { + uiZ = packToF32UI( signA, 0x7F, 0 ); + goto uiZ; + } + break; + } + uiZ = packToF32UI( signA, 0, 0 ); + goto uiZ; + } + lastBitMask = (uint_fast32_t) 1<<( 0x96 - expA ); + roundBitsMask = lastBitMask - 1; + uiZ = uiA; + if ( roundingMode == softfloat_round_nearest_maxMag ) { + uiZ += lastBitMask>>1; + } else if ( roundingMode == softfloat_round_nearest_even ) { + uiZ += lastBitMask>>1; + if ( ! ( uiZ & roundBitsMask ) ) uiZ &= ~ lastBitMask; + } else if ( roundingMode != softfloat_round_minMag ) { + if ( signF32UI( uiZ ) ^ ( roundingMode == softfloat_round_max ) ) { + uiZ += roundBitsMask; + } + } + uiZ &= ~ roundBitsMask; + if ( exact && ( uiZ != uiA ) ) { + softfloat_exceptionFlags |= softfloat_flag_inexact; + } + uiZ: + uZ.ui = uiZ; + return uZ.f; + +} + diff --git a/softfloat/f32_sqrt.c b/softfloat/f32_sqrt.c new file mode 100755 index 0000000..c9eb907 --- /dev/null +++ b/softfloat/f32_sqrt.c @@ -0,0 +1,74 @@ + +#include +#include +#include "platform.h" +#include "primitives.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +float32_t f32_sqrt( float32_t a ) +{ + union ui32_f32 uA; + uint_fast32_t uiA; + bool signA; + int_fast16_t expA; + uint_fast32_t sigA, uiZ; + struct exp16_sig32 normExpSig; + int_fast16_t expZ; + uint_fast32_t sigZ; + uint_fast64_t term, rem; + union ui32_f32 uZ; + + uA.f = a; + uiA = uA.ui; + signA = signF32UI( uiA ); + expA = expF32UI( uiA ); + sigA = fracF32UI( uiA ); + if ( expA == 0xFF ) { + if ( sigA ) { + uiZ = softfloat_propagateNaNF32UI( uiA, 0 ); + goto uiZ; + } + if ( ! signA ) return a; + goto invalid; + } + if ( signA ) { + if ( ! ( expA | sigA ) ) return a; + goto invalid; + } + if ( ! expA ) { + if ( ! sigA ) return a; + normExpSig = softfloat_normSubnormalF32Sig( sigA ); + expA = normExpSig.exp; + sigA = normExpSig.sig; + } + expZ = ( ( expA - 0x7F )>>1 ) + 0x7E; + sigA = ( sigA | 0x00800000 )<<8; + sigZ = softfloat_estimateSqrt32( expA, sigA ) + 2; + if ( ( sigZ & 0x7F ) <= 5 ) { + if ( sigZ < 2 ) { + sigZ = 0x7FFFFFFF; + goto roundPack; + } + sigA >>= expA & 1; + term = (uint_fast64_t) sigZ * sigZ; + rem = ( (uint_fast64_t) sigA<<32 ) - term; + while ( UINT64_C( 0x8000000000000000 ) <= rem ) { + --sigZ; + rem += ( (uint_fast64_t) sigZ<<1 ) | 1; + } + sigZ |= ( rem != 0 ); + } + sigZ = softfloat_shortShift32Right1Jam( sigZ ); + roundPack: + return softfloat_roundPackToF32( 0, expZ, sigZ ); + invalid: + softfloat_raiseFlags( softfloat_flag_invalid ); + uiZ = defaultNaNF32UI; + uiZ: + uZ.ui = uiZ; + return uZ.f; + +} + diff --git a/softfloat/f32_sub.c b/softfloat/f32_sub.c new file mode 100755 index 0000000..c64df8e --- /dev/null +++ b/softfloat/f32_sub.c @@ -0,0 +1,29 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" + +float32_t f32_sub( float32_t a, float32_t b ) +{ + union ui32_f32 uA; + uint_fast32_t uiA; + bool signA; + union ui32_f32 uB; + uint_fast32_t uiB; + bool signB; + float32_t ( *magsRoutine )( uint_fast32_t, uint_fast32_t, bool ); + + uA.f = a; + uiA = uA.ui; + signA = signF32UI( uiA ); + uB.f = b; + uiB = uB.ui; + signB = signF32UI( uiB ); + magsRoutine = + ( signA == signB ) ? softfloat_subMagsF32 : softfloat_addMagsF32; + return magsRoutine( uiA, uiB ^ 0x80000000, signA ); + +} + diff --git a/softfloat/f32_to_f64.c b/softfloat/f32_to_f64.c new file mode 100755 index 0000000..9f0ae5c --- /dev/null +++ b/softfloat/f32_to_f64.c @@ -0,0 +1,47 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +float64_t f32_to_f64( float32_t a ) +{ + union ui32_f32 uA; + uint_fast32_t uiA; + bool sign; + int_fast16_t exp; + uint_fast32_t sig; + uint_fast64_t uiZ; + struct exp16_sig32 normExpSig; + union ui64_f64 uZ; + + uA.f = a; + uiA = uA.ui; + sign = signF32UI( uiA ); + exp = expF32UI( uiA ); + sig = fracF32UI( uiA ); + if ( exp == 0xFF ) { + uiZ = + sig ? softfloat_commonNaNToF64UI( + softfloat_f32UIToCommonNaN( uiA ) ) + : packToF64UI( sign, 0x7FF, 0 ); + goto uiZ; + } + if ( ! exp ) { + if ( ! sig ) { + uiZ = packToF64UI( sign, 0, 0 ); + goto uiZ; + } + normExpSig = softfloat_normSubnormalF32Sig( sig ); + exp = normExpSig.exp - 1; + sig = normExpSig.sig; + } + uiZ = packToF64UI( sign, exp + 0x380, (uint_fast64_t) sig<<29 ); + uiZ: + uZ.ui = uiZ; + return uZ.f; + +} + diff --git a/softfloat/f32_to_i32.c b/softfloat/f32_to_i32.c new file mode 100755 index 0000000..bbbaee0 --- /dev/null +++ b/softfloat/f32_to_i32.c @@ -0,0 +1,34 @@ + +#include +#include +#include "platform.h" +#include "primitives.h" +#include "internals.h" +#include "softfloat.h" + +int_fast32_t f32_to_i32( float32_t a, int_fast8_t roundingMode, bool exact ) +{ + union ui32_f32 uA; + uint_fast32_t uiA; + bool sign; + int_fast16_t exp; + uint_fast32_t sig; + uint_fast64_t sig64; + int_fast16_t shiftCount; + + uA.f = a; + uiA = uA.ui; + sign = signF32UI( uiA ); + exp = expF32UI( uiA ); + sig = fracF32UI( uiA ); + if ( ( exp == 0xFF ) && sig ) sign = 0; + if ( exp ) sig |= 0x00800000; + sig64 = (uint_fast64_t) sig<<32; + shiftCount = 0xAF - exp; + if ( 0 < shiftCount ) { + sig64 = softfloat_shift64RightJam( sig64, shiftCount ); + } + return softfloat_roundPackToI32( sign, sig64, roundingMode, exact ); + +} + diff --git a/softfloat/f32_to_i32_r_minMag.c b/softfloat/f32_to_i32_r_minMag.c new file mode 100755 index 0000000..63ff1e2 --- /dev/null +++ b/softfloat/f32_to_i32_r_minMag.c @@ -0,0 +1,45 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" + +int_fast32_t f32_to_i32_r_minMag( float32_t a, bool exact ) +{ + union ui32_f32 uA; + uint_fast32_t uiA; + int_fast16_t exp; + uint_fast32_t sig; + bool sign; + int_fast16_t shiftCount; + int_fast32_t absZ; + + uA.f = a; + uiA = uA.ui; + exp = expF32UI( uiA ); + sig = fracF32UI( uiA ); + if ( exp < 0x7F ) { + if ( exact && ( exp | sig ) ) { + softfloat_exceptionFlags |= softfloat_flag_inexact; + } + return 0; + } + sign = signF32UI( uiA ); + shiftCount = 0x9E - exp; + if ( shiftCount <= 0 ) { + if ( uiA != packToF32UI( 1, 0x9E, 0 ) ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + if ( ! sign || ( ( exp == 0xFF ) && sig ) ) return 0x7FFFFFFF; + } + return -0x7FFFFFFF - 1; + } + sig = ( sig | 0x00800000 )<<8; + absZ = sig>>shiftCount; + if ( exact && (uint32_t) ( sig<<( ( - shiftCount ) & 31 ) ) ) { + softfloat_exceptionFlags |= softfloat_flag_inexact; + } + return sign ? - absZ : absZ; + +} + diff --git a/softfloat/f32_to_i64.c b/softfloat/f32_to_i64.c new file mode 100755 index 0000000..c0b8981 --- /dev/null +++ b/softfloat/f32_to_i64.c @@ -0,0 +1,44 @@ + +#include +#include +#include "platform.h" +#include "primitives.h" +#include "internals.h" +#include "softfloat.h" + +int_fast64_t f32_to_i64( float32_t a, int_fast8_t roundingMode, bool exact ) +{ + union ui32_f32 uA; + uint_fast32_t uiA; + bool sign; + int_fast16_t exp; + uint_fast32_t sig; + int_fast16_t shiftCount; + uint_fast64_t sig64, extra; + struct uint64_extra sig64Extra; + + uA.f = a; + uiA = uA.ui; + sign = signF32UI( uiA ); + exp = expF32UI( uiA ); + sig = fracF32UI( uiA ); + shiftCount = 0xBE - exp; + if ( shiftCount < 0 ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + if ( ! sign || ( ( exp == 0xFF ) && sig ) ) { + return INT64_C( 0x7FFFFFFFFFFFFFFF ); + } + return - INT64_C( 0x7FFFFFFFFFFFFFFF ) - 1; + } + if ( exp ) sig |= 0x00800000; + sig64 = (uint_fast64_t) sig<<40; + extra = 0; + if ( shiftCount ) { + sig64Extra = softfloat_shift64ExtraRightJam( sig64, 0, shiftCount ); + sig64 = sig64Extra.v; + extra = sig64Extra.extra; + } + return softfloat_roundPackToI64( sign, sig64, extra, roundingMode, exact ); + +} + diff --git a/softfloat/f32_to_i64_r_minMag.c b/softfloat/f32_to_i64_r_minMag.c new file mode 100755 index 0000000..33bff93 --- /dev/null +++ b/softfloat/f32_to_i64_r_minMag.c @@ -0,0 +1,52 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" + +int_fast64_t f32_to_i64_r_minMag( float32_t a, bool exact ) +{ + union ui32_f32 uA; + uint_fast32_t uiA; + int_fast16_t exp; + uint_fast32_t sig; + bool sign; + int_fast16_t shiftCount; + uint_fast64_t sig64; + int_fast64_t absZ; + + uA.f = a; + uiA = uA.ui; + exp = expF32UI( uiA ); + sig = fracF32UI( uiA ); + if ( exp < 0x7F ) { + if ( exact && ( exp | sig ) ) { + softfloat_exceptionFlags |= softfloat_flag_inexact; + } + return 0; + } + sign = signF32UI( uiA ); + shiftCount = 0xBE - exp; + if ( shiftCount <= 0 ) { + if ( uiA != packToF32UI( 1, 0xBE, 0 ) ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + if ( ! sign || ( ( exp == 0xFF ) && sig ) ) { + return INT64_C( 0x7FFFFFFFFFFFFFFF ); + } + } + return - INT64_C( 0x7FFFFFFFFFFFFFFF ) - 1; + } + sig |= 0x00800000; + sig64 = (uint_fast64_t) sig<<40; + absZ = sig64>>shiftCount; + shiftCount = 40 - shiftCount; + if ( + exact && ( shiftCount < 0 ) && (uint32_t) ( sig<<( shiftCount & 31 ) ) + ) { + softfloat_exceptionFlags |= softfloat_flag_inexact; + } + return sign ? - absZ : absZ; + +} + diff --git a/softfloat/f32_to_ui32.c b/softfloat/f32_to_ui32.c new file mode 100755 index 0000000..3501db8 --- /dev/null +++ b/softfloat/f32_to_ui32.c @@ -0,0 +1,33 @@ + +#include +#include +#include "platform.h" +#include "primitives.h" +#include "internals.h" +#include "softfloat.h" + +uint_fast32_t f32_to_ui32( float32_t a, int_fast8_t roundingMode, bool exact ) +{ + union ui32_f32 uA; + uint_fast32_t uiA; + bool sign; + int_fast16_t exp; + uint_fast32_t sig; + uint_fast64_t sig64; + int_fast16_t shiftCount; + + uA.f = a; + uiA = uA.ui; + sign = signF32UI( uiA ); + exp = expF32UI( uiA ); + sig = fracF32UI( uiA ); + if ( exp ) sig |= 0x00800000; + sig64 = (uint_fast64_t) sig<<32; + shiftCount = 0xAF - exp; + if ( 0 < shiftCount ) { + sig64 = softfloat_shift64RightJam( sig64, shiftCount ); + } + return softfloat_roundPackToUI32( sign, sig64, roundingMode, exact ); + +} + diff --git a/softfloat/f32_to_ui32_r_minMag.c b/softfloat/f32_to_ui32_r_minMag.c new file mode 100755 index 0000000..edd858d --- /dev/null +++ b/softfloat/f32_to_ui32_r_minMag.c @@ -0,0 +1,41 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" + +uint_fast32_t f32_to_ui32_r_minMag( float32_t a, bool exact ) +{ + union ui32_f32 uA; + uint_fast32_t uiA; + int_fast16_t exp; + uint_fast32_t sig; + int_fast16_t shiftCount; + uint_fast32_t z; + + uA.f = a; + uiA = uA.ui; + exp = expF32UI( uiA ); + sig = fracF32UI( uiA ); + if ( exp < 0x7F ) { + if ( exact && ( exp | sig ) ) { + softfloat_exceptionFlags |= softfloat_flag_inexact; + } + return 0; + } + if ( signF32UI( uiA ) ) goto invalid; + shiftCount = 0x9E - exp; + if ( shiftCount < 0 ) goto invalid; + sig = ( sig | 0x00800000 )<<8; + z = sig>>shiftCount; + if ( exact && ( sig & ( ( (uint_fast32_t) 1< +#include +#include "platform.h" +#include "primitives.h" +#include "internals.h" +#include "softfloat.h" + +uint_fast64_t f32_to_ui64( float32_t a, int_fast8_t roundingMode, bool exact ) +{ + union ui32_f32 uA; + uint_fast32_t uiA; + bool sign; + int_fast16_t exp; + uint_fast32_t sig; + int_fast16_t shiftCount; + uint_fast64_t sig64, extra; + struct uint64_extra sig64Extra; + + uA.f = a; + uiA = uA.ui; + sign = signF32UI( uiA ); + exp = expF32UI( uiA ); + sig = fracF32UI( uiA ); + shiftCount = 0xBE - exp; + if ( shiftCount < 0 ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + return UINT64_C( 0xFFFFFFFFFFFFFFFF ); + } + if ( exp ) sig |= 0x00800000; + sig64 = (uint_fast64_t) sig<<40; + extra = 0; + if ( shiftCount ) { + sig64Extra = softfloat_shift64ExtraRightJam( sig64, 0, shiftCount ); + sig64 = sig64Extra.v; + extra = sig64Extra.extra; + } + return + softfloat_roundPackToUI64( sign, sig64, extra, roundingMode, exact ); + +} + diff --git a/softfloat/f32_to_ui64_r_minMag.c b/softfloat/f32_to_ui64_r_minMag.c new file mode 100755 index 0000000..738d6b1 --- /dev/null +++ b/softfloat/f32_to_ui64_r_minMag.c @@ -0,0 +1,45 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" + +uint_fast64_t f32_to_ui64_r_minMag( float32_t a, bool exact ) +{ + union ui32_f32 uA; + uint_fast32_t uiA; + int_fast16_t exp; + uint_fast32_t sig; + int_fast16_t shiftCount; + uint_fast64_t sig64, z; + + uA.f = a; + uiA = uA.ui; + exp = expF32UI( uiA ); + sig = fracF32UI( uiA ); + if ( exp < 0x7F ) { + if ( exact && ( exp | sig ) ) { + softfloat_exceptionFlags |= softfloat_flag_inexact; + } + return 0; + } + if ( signF32UI( uiA ) ) goto invalid; + shiftCount = 0xBE - exp; + if ( shiftCount < 0 ) goto invalid; + sig |= 0x00800000; + sig64 = (uint_fast64_t) sig<<40; + z = sig64>>shiftCount; + shiftCount = 40 - shiftCount; + if ( + exact && ( shiftCount < 0 ) && (uint32_t) ( sig<<( shiftCount & 31 ) ) + ) { + softfloat_exceptionFlags |= softfloat_flag_inexact; + } + return z; + invalid: + softfloat_raiseFlags( softfloat_flag_invalid ); + return UINT64_C( 0xFFFFFFFFFFFFFFFF ); + +} + diff --git a/softfloat/f64_add.c b/softfloat/f64_add.c new file mode 100755 index 0000000..9ec4b5f --- /dev/null +++ b/softfloat/f64_add.c @@ -0,0 +1,29 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" + +float64_t f64_add( float64_t a, float64_t b ) +{ + union ui64_f64 uA; + uint_fast64_t uiA; + bool signA; + union ui64_f64 uB; + uint_fast64_t uiB; + bool signB; + float64_t ( *magsRoutine )( uint_fast64_t, uint_fast64_t, bool ); + + uA.f = a; + uiA = uA.ui; + signA = signF64UI( uiA ); + uB.f = b; + uiB = uB.ui; + signB = signF64UI( uiB ); + magsRoutine = + ( signA == signB ) ? softfloat_addMagsF64 : softfloat_subMagsF64; + return magsRoutine( uiA, uiB, signA ); + +} + diff --git a/softfloat/f64_div.c b/softfloat/f64_div.c new file mode 100755 index 0000000..9bc72b3 --- /dev/null +++ b/softfloat/f64_div.c @@ -0,0 +1,104 @@ + +#include +#include +#include "platform.h" +#include "primitives.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +float64_t f64_div( float64_t a, float64_t b ) +{ + union ui64_f64 uA; + uint_fast64_t uiA; + bool signA; + int_fast16_t expA; + uint_fast64_t sigA; + union ui64_f64 uB; + uint_fast64_t uiB; + bool signB; + int_fast16_t expB; + uint_fast64_t sigB; + bool signZ; + struct exp16_sig64 normExpSig; + int_fast16_t expZ; + uint_fast64_t sigZ; + struct uint128 term, rem; + uint_fast64_t uiZ; + union ui64_f64 uZ; + + uA.f = a; + uiA = uA.ui; + signA = signF64UI( uiA ); + expA = expF64UI( uiA ); + sigA = fracF64UI( uiA ); + uB.f = b; + uiB = uB.ui; + signB = signF64UI( uiB ); + expB = expF64UI( uiB ); + sigB = fracF64UI( uiB ); + signZ = signA ^ signB; + if ( expA == 0x7FF ) { + if ( sigA ) goto propagateNaN; + if ( expB == 0x7FF ) { + if ( sigB ) goto propagateNaN; + goto invalid; + } + goto infinity; + } + if ( expB == 0x7FF ) { + if ( sigB ) goto propagateNaN; + goto zero; + } + if ( ! expB ) { + if ( ! sigB ) { + if ( ! ( expA | sigA ) ) goto invalid; + softfloat_raiseFlags( softfloat_flag_infinity ); + goto infinity; + } + normExpSig = softfloat_normSubnormalF64Sig( sigB ); + expB = normExpSig.exp; + sigB = normExpSig.sig; + } + if ( ! expA ) { + if ( ! sigA ) goto zero; + normExpSig = softfloat_normSubnormalF64Sig( sigA ); + expA = normExpSig.exp; + sigA = normExpSig.sig; + } + expZ = expA - expB + 0x3FD; + sigA = ( sigA | UINT64_C( 0x0010000000000000 ) )<<10; + sigB = ( sigB | UINT64_C( 0x0010000000000000 ) )<<11; + if ( sigB <= ( sigA + sigA ) ) { + ++expZ; + sigA >>= 1; + } + sigZ = softfloat_estimateDiv128To64( sigA, 0, sigB ); + if ( ( sigZ & 0x1FF ) <= 2 ) { + term = softfloat_mul64To128( sigB, sigZ ); + rem = softfloat_sub128( sigA, 0, term.v64, term.v0 ); + while ( UINT64_C( 0x8000000000000000 ) <= rem.v64 ) { + --sigZ; + rem = softfloat_add128( rem.v64, rem.v0, 0, sigB ); + } + sigZ |= ( rem.v0 != 0 ); + } + return softfloat_roundPackToF64( signZ, expZ, sigZ ); + propagateNaN: + uiZ = softfloat_propagateNaNF64UI( uiA, uiB ); + goto uiZ; + invalid: + softfloat_raiseFlags( softfloat_flag_invalid ); + uiZ = defaultNaNF64UI; + goto uiZ; + infinity: + uiZ = packToF64UI( signZ, 0x7FF, 0 ); + goto uiZ; + zero: + uiZ = packToF64UI( signZ, 0, 0 ); + uiZ: + uZ.ui = uiZ; + return uZ.f; + +} + diff --git a/softfloat/f64_eq.c b/softfloat/f64_eq.c new file mode 100755 index 0000000..925aabc --- /dev/null +++ b/softfloat/f64_eq.c @@ -0,0 +1,35 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +bool f64_eq( float64_t a, float64_t b ) +{ + union ui64_f64 uA; + uint_fast64_t uiA; + union ui64_f64 uB; + uint_fast64_t uiB; + + uA.f = a; + uiA = uA.ui; + uB.f = b; + uiB = uB.ui; + if ( + ( ( expF64UI( uiA ) == 0x7FF ) && fracF64UI( uiA ) ) + || ( ( expF64UI( uiB ) == 0x7FF ) && fracF64UI( uiB ) ) + ) { + if ( + softfloat_isSigNaNF64UI( uiA ) || softfloat_isSigNaNF64UI( uiB ) + ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + } + return false; + } + return + ( uiA == uiB ) || ! ( ( uiA | uiB ) & UINT64_C( 0x7FFFFFFFFFFFFFFF ) ); + +} + diff --git a/softfloat/f64_eq_signaling.c b/softfloat/f64_eq_signaling.c new file mode 100755 index 0000000..7a54dc1 --- /dev/null +++ b/softfloat/f64_eq_signaling.c @@ -0,0 +1,30 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" + +bool f64_eq_signaling( float64_t a, float64_t b ) +{ + union ui64_f64 uA; + uint_fast64_t uiA; + union ui64_f64 uB; + uint_fast64_t uiB; + + uA.f = a; + uiA = uA.ui; + uB.f = b; + uiB = uB.ui; + if ( + ( ( expF64UI( uiA ) == 0x7FF ) && fracF64UI( uiA ) ) + || ( ( expF64UI( uiB ) == 0x7FF ) && fracF64UI( uiB ) ) + ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + return false; + } + return + ( uiA == uiB ) || ! ( ( uiA | uiB ) & UINT64_C( 0x7FFFFFFFFFFFFFFF ) ); + +} + diff --git a/softfloat/f64_isSignalingNaN.c b/softfloat/f64_isSignalingNaN.c new file mode 100755 index 0000000..d720ac1 --- /dev/null +++ b/softfloat/f64_isSignalingNaN.c @@ -0,0 +1,16 @@ + +#include +#include "platform.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +bool f64_isSignalingNaN( float64_t a ) +{ + union ui64_f64 uA; + + uA.f = a; + return softfloat_isSigNaNF64UI( uA.ui ); + +} + diff --git a/softfloat/f64_le.c b/softfloat/f64_le.c new file mode 100755 index 0000000..e6c5caf --- /dev/null +++ b/softfloat/f64_le.c @@ -0,0 +1,35 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" + +bool f64_le( float64_t a, float64_t b ) +{ + union ui64_f64 uA; + uint_fast64_t uiA; + union ui64_f64 uB; + uint_fast64_t uiB; + bool signA, signB; + + uA.f = a; + uiA = uA.ui; + uB.f = b; + uiB = uB.ui; + if ( + ( ( expF64UI( uiA ) == 0x7FF ) && fracF64UI( uiA ) ) + || ( ( expF64UI( uiB ) == 0x7FF ) && fracF64UI( uiB ) ) + ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + return false; + } + signA = signF64UI( uiA ); + signB = signF64UI( uiB ); + return + ( signA != signB ) + ? signA || ! ( ( uiA | uiB ) & UINT64_C( 0x7FFFFFFFFFFFFFFF ) ) + : ( uiA == uiB ) || ( signA ^ ( uiA < uiB ) ); + +} + diff --git a/softfloat/f64_le_quiet.c b/softfloat/f64_le_quiet.c new file mode 100755 index 0000000..e9b7ede --- /dev/null +++ b/softfloat/f64_le_quiet.c @@ -0,0 +1,40 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +bool f64_le_quiet( float64_t a, float64_t b ) +{ + union ui64_f64 uA; + uint_fast64_t uiA; + union ui64_f64 uB; + uint_fast64_t uiB; + bool signA, signB; + + uA.f = a; + uiA = uA.ui; + uB.f = b; + uiB = uB.ui; + if ( + ( ( expF64UI( uiA ) == 0x7FF ) && fracF64UI( uiA ) ) + || ( ( expF64UI( uiB ) == 0x7FF ) && fracF64UI( uiB ) ) + ) { + if ( + softfloat_isSigNaNF64UI( uiA ) || softfloat_isSigNaNF64UI( uiB ) + ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + } + return false; + } + signA = signF64UI( uiA ); + signB = signF64UI( uiB ); + return + ( signA != signB ) + ? signA || ! ( ( uiA | uiB ) & UINT64_C( 0x7FFFFFFFFFFFFFFF ) ) + : ( uiA == uiB ) || ( signA ^ ( uiA < uiB ) ); + +} + diff --git a/softfloat/f64_lt.c b/softfloat/f64_lt.c new file mode 100755 index 0000000..1b2f696 --- /dev/null +++ b/softfloat/f64_lt.c @@ -0,0 +1,35 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" + +bool f64_lt( float64_t a, float64_t b ) +{ + union ui64_f64 uA; + uint_fast64_t uiA; + union ui64_f64 uB; + uint_fast64_t uiB; + bool signA, signB; + + uA.f = a; + uiA = uA.ui; + uB.f = b; + uiB = uB.ui; + if ( + ( ( expF64UI( uiA ) == 0x7FF ) && fracF64UI( uiA ) ) + || ( ( expF64UI( uiB ) == 0x7FF ) && fracF64UI( uiB ) ) + ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + return false; + } + signA = signF64UI( uiA ); + signB = signF64UI( uiB ); + return + ( signA != signB ) + ? signA && ( ( uiA | uiB ) & UINT64_C( 0x7FFFFFFFFFFFFFFF ) ) + : ( uiA != uiB ) && ( signA ^ ( uiA < uiB ) ); + +} + diff --git a/softfloat/f64_lt_quiet.c b/softfloat/f64_lt_quiet.c new file mode 100755 index 0000000..f27e6da --- /dev/null +++ b/softfloat/f64_lt_quiet.c @@ -0,0 +1,40 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +bool f64_lt_quiet( float64_t a, float64_t b ) +{ + union ui64_f64 uA; + uint_fast64_t uiA; + union ui64_f64 uB; + uint_fast64_t uiB; + bool signA, signB; + + uA.f = a; + uiA = uA.ui; + uB.f = b; + uiB = uB.ui; + if ( + ( ( expF64UI( uiA ) == 0x7FF ) && fracF64UI( uiA ) ) + || ( ( expF64UI( uiB ) == 0x7FF ) && fracF64UI( uiB ) ) + ) { + if ( + softfloat_isSigNaNF64UI( uiA ) || softfloat_isSigNaNF64UI( uiB ) + ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + } + return false; + } + signA = signF64UI( uiA ); + signB = signF64UI( uiB ); + return + ( signA != signB ) + ? signA && ( ( uiA | uiB ) & UINT64_C( 0x7FFFFFFFFFFFFFFF ) ) + : ( uiA != uiB ) && ( signA ^ ( uiA < uiB ) ); + +} + diff --git a/softfloat/f64_mul.c b/softfloat/f64_mul.c new file mode 100755 index 0000000..4b5dc4e --- /dev/null +++ b/softfloat/f64_mul.c @@ -0,0 +1,91 @@ + +#include +#include +#include "platform.h" +#include "primitives.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +float64_t f64_mul( float64_t a, float64_t b ) +{ + union ui64_f64 uA; + uint_fast64_t uiA; + bool signA; + int_fast16_t expA; + uint_fast64_t sigA; + union ui64_f64 uB; + uint_fast64_t uiB; + bool signB; + int_fast16_t expB; + uint_fast64_t sigB; + bool signZ; + uint_fast64_t magBits; + struct exp16_sig64 normExpSig; + int_fast16_t expZ; + struct uint128 sigZ128; + uint_fast64_t sigZ, uiZ; + union ui64_f64 uZ; + + uA.f = a; + uiA = uA.ui; + signA = signF64UI( uiA ); + expA = expF64UI( uiA ); + sigA = fracF64UI( uiA ); + uB.f = b; + uiB = uB.ui; + signB = signF64UI( uiB ); + expB = expF64UI( uiB ); + sigB = fracF64UI( uiB ); + signZ = signA ^ signB; + if ( expA == 0x7FF ) { + if ( sigA || ( ( expB == 0x7FF ) && sigB ) ) goto propagateNaN; + magBits = expB | sigB; + goto infArg; + } + if ( expB == 0x7FF ) { + if ( sigB ) goto propagateNaN; + magBits = expA | sigA; + goto infArg; + } + if ( ! expA ) { + if ( ! sigA ) goto zero; + normExpSig = softfloat_normSubnormalF64Sig( sigA ); + expA = normExpSig.exp; + sigA = normExpSig.sig; + } + if ( ! expB ) { + if ( ! sigB ) goto zero; + normExpSig = softfloat_normSubnormalF64Sig( sigB ); + expB = normExpSig.exp; + sigB = normExpSig.sig; + } + expZ = expA + expB - 0x3FF; + sigA = ( sigA | UINT64_C( 0x0010000000000000 ) )<<10; + sigB = ( sigB | UINT64_C( 0x0010000000000000 ) )<<11; + sigZ128 = softfloat_mul64To128( sigA, sigB ); + sigZ = sigZ128.v64 | ( sigZ128.v0 != 0 ); + if ( sigZ < UINT64_C( 0x4000000000000000 ) ) { + --expZ; + sigZ <<= 1; + } + return softfloat_roundPackToF64( signZ, expZ, sigZ ); + propagateNaN: + uiZ = softfloat_propagateNaNF64UI( uiA, uiB ); + goto uiZ; + infArg: + if ( ! magBits ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + uiZ = defaultNaNF64UI; + } else { + uiZ = packToF64UI( signZ, 0x7FF, 0 ); + } + goto uiZ; + zero: + uiZ = packToF64UI( signZ, 0, 0 ); + uiZ: + uZ.ui = uiZ; + return uZ.f; + +} + diff --git a/softfloat/f64_mulAdd.c b/softfloat/f64_mulAdd.c new file mode 100755 index 0000000..fa1669a --- /dev/null +++ b/softfloat/f64_mulAdd.c @@ -0,0 +1,25 @@ + +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" + +float64_t f64_mulAdd( float64_t a, float64_t b, float64_t c ) +{ + union ui64_f64 uA; + uint_fast64_t uiA; + union ui64_f64 uB; + uint_fast64_t uiB; + union ui64_f64 uC; + uint_fast64_t uiC; + + uA.f = a; + uiA = uA.ui; + uB.f = b; + uiB = uB.ui; + uC.f = c; + uiC = uC.ui; + return softfloat_mulAddF64( 0, uiA, uiB, uiC ); + +} + diff --git a/softfloat/f64_rem.c b/softfloat/f64_rem.c new file mode 100755 index 0000000..08fcd78 --- /dev/null +++ b/softfloat/f64_rem.c @@ -0,0 +1,113 @@ + +#include +#include +#include "platform.h" +#include "primitives.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +float64_t f64_rem( float64_t a, float64_t b ) +{ + union ui64_f64 uA; + uint_fast64_t uiA; + bool signA; + int_fast16_t expA; + uint_fast64_t sigA; + union ui64_f64 uB; + uint_fast64_t uiB; + bool signB; + int_fast16_t expB; + uint_fast64_t sigB; + struct exp16_sig64 normExpSig; + int_fast16_t expDiff; + uint_fast64_t q, alternateSigA; + uint64_t sigMean; + bool signZ; + uint_fast64_t uiZ; + union ui64_f64 uZ; + + uA.f = a; + uiA = uA.ui; + signA = signF64UI( uiA ); + expA = expF64UI( uiA ); + sigA = fracF64UI( uiA ); + uB.f = b; + uiB = uB.ui; + signB = signF64UI( uiB ); + expB = expF64UI( uiB ); + sigB = fracF64UI( uiB ); + if ( expA == 0x7FF ) { + if ( sigA || ( ( expB == 0x7FF ) && sigB ) ) goto propagateNaN; + goto invalid; + } + if ( expB == 0x7FF ) { + if ( sigB ) goto propagateNaN; + return a; + } + if ( ! expB ) { + if ( ! sigB ) goto invalid; + normExpSig = softfloat_normSubnormalF64Sig( sigB ); + expB = normExpSig.exp; + sigB = normExpSig.sig; + } + if ( ! expA ) { + if ( ! sigA ) return a; + normExpSig = softfloat_normSubnormalF64Sig( sigA ); + expA = normExpSig.exp; + sigA = normExpSig.sig; + } + expDiff = expA - expB; + sigA = ( sigA | UINT64_C( 0x0010000000000000 ) )<<11; + sigB = ( sigB | UINT64_C( 0x0010000000000000 ) )<<11; + if ( expDiff < 0 ) { + if ( expDiff < -1 ) return a; + sigA >>= 1; + } + q = ( sigB <= sigA ); + if ( q ) sigA -= sigB; + expDiff -= 64; + while ( 0 < expDiff ) { + q = softfloat_estimateDiv128To64( sigA, 0, sigB ); + q = ( 2 < q ) ? q - 2 : 0; + sigA = - ( ( sigB>>2 ) * q ); + expDiff -= 62; + } + expDiff += 64; + if ( 0 < expDiff ) { + q = softfloat_estimateDiv128To64( sigA, 0, sigB ); + q = ( 2 < q ) ? q - 2 : 0; + q >>= 64 - expDiff; + sigB >>= 2; + sigA = ( ( sigA>>1 )<<( expDiff - 1 ) ) - sigB * q; + } else { + sigA >>= 2; + sigB >>= 2; + } + do { + alternateSigA = sigA; + ++q; + sigA -= sigB; + } while ( sigA < UINT64_C( 0x8000000000000000 ) ); + sigMean = sigA + alternateSigA; + if ( + ( UINT64_C( 0x8000000000000000 ) <= sigMean ) + || ( ! sigMean && ( q & 1 ) ) + ) { + sigA = alternateSigA; + } + signZ = ( UINT64_C( 0x8000000000000000 ) <= sigA ); + if ( signZ ) sigA = - sigA; + return softfloat_normRoundPackToF64( signA ^ signZ, expB, sigA ); + propagateNaN: + uiZ = softfloat_propagateNaNF64UI( uiA, uiB ); + goto uiZ; + invalid: + softfloat_raiseFlags( softfloat_flag_invalid ); + uiZ = defaultNaNF64UI; + uiZ: + uZ.ui = uiZ; + return uZ.f; + +} + diff --git a/softfloat/f64_roundToInt.c b/softfloat/f64_roundToInt.c new file mode 100755 index 0000000..ef16dfa --- /dev/null +++ b/softfloat/f64_roundToInt.c @@ -0,0 +1,80 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +float64_t f64_roundToInt( float64_t a, int_fast8_t roundingMode, bool exact ) +{ + union ui64_f64 uA; + uint_fast64_t uiA; + int_fast16_t expA; + uint_fast64_t uiZ; + bool signA; + uint_fast64_t lastBitMask, roundBitsMask; + union ui64_f64 uZ; + + uA.f = a; + uiA = uA.ui; + expA = expF64UI( uiA ); + if ( 0x433 <= expA ) { + if ( ( expA == 0x7FF ) && fracF64UI( uiA ) ) { + uiZ = softfloat_propagateNaNF64UI( uiA, 0 ); + goto uiZ; + } + return a; + } + if ( expA <= 0x3FE ) { + if ( ! ( uiA & UINT64_C( 0x7FFFFFFFFFFFFFFF ) ) ) return a; + if ( exact ) softfloat_exceptionFlags |= softfloat_flag_inexact; + signA = signF64UI( uiA ); + switch ( roundingMode ) { + case softfloat_round_nearest_even: + if ( ( expA == 0x3FE ) && fracF64UI( uiA ) ) { + uiZ = packToF64UI( signA, 0x3FF, 0 ); + goto uiZ; + } + break; + case softfloat_round_min: + uiZ = signA ? UINT64_C( 0xBFF0000000000000 ) : 0; + goto uiZ; + case softfloat_round_max: + uiZ = + signA ? UINT64_C( 0x8000000000000000 ) + : UINT64_C( 0x3FF0000000000000 ); + goto uiZ; + case softfloat_round_nearest_maxMag: + if ( expA == 0x3FE ) { + uiZ = packToF64UI( signA, 0x3FF, 0 ); + goto uiZ; + } + break; + } + uiZ = packToF64UI( signA, 0, 0 ); + goto uiZ; + } + lastBitMask = (uint_fast64_t) 1<<( 0x433 - expA ); + roundBitsMask = lastBitMask - 1; + uiZ = uiA; + if ( roundingMode == softfloat_round_nearest_maxMag ) { + uiZ += lastBitMask>>1; + } else if ( roundingMode == softfloat_round_nearest_even ) { + uiZ += lastBitMask>>1; + if ( ! ( uiZ & roundBitsMask ) ) uiZ &= ~ lastBitMask; + } else if ( roundingMode != softfloat_round_minMag ) { + if ( signF64UI( uiZ ) ^ ( roundingMode == softfloat_round_max ) ) { + uiZ += roundBitsMask; + } + } + uiZ &= ~ roundBitsMask; + if ( exact && ( uiZ != uiA ) ) { + softfloat_exceptionFlags |= softfloat_flag_inexact; + } + uiZ: + uZ.ui = uiZ; + return uZ.f; + +} + diff --git a/softfloat/f64_sqrt.c b/softfloat/f64_sqrt.c new file mode 100755 index 0000000..cd91010 --- /dev/null +++ b/softfloat/f64_sqrt.c @@ -0,0 +1,74 @@ + +#include +#include +#include "platform.h" +#include "primitives.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +float64_t f64_sqrt( float64_t a ) +{ + union ui64_f64 uA; + uint_fast64_t uiA; + bool signA; + int_fast16_t expA; + uint_fast64_t sigA, uiZ; + struct exp16_sig64 normExpSig; + int_fast16_t expZ; + uint_fast32_t sigZ32; + uint_fast64_t sigZ; + struct uint128 term, rem; + union ui64_f64 uZ; + + uA.f = a; + uiA = uA.ui; + signA = signF64UI( uiA ); + expA = expF64UI( uiA ); + sigA = fracF64UI( uiA ); + if ( expA == 0x7FF ) { + if ( sigA ) { + uiZ = softfloat_propagateNaNF64UI( uiA, 0 ); + goto uiZ; + } + if ( ! signA ) return a; + goto invalid; + } + if ( signA ) { + if ( ! ( expA | sigA ) ) return a; + goto invalid; + } + if ( ! expA ) { + if ( ! sigA ) return a; + normExpSig = softfloat_normSubnormalF64Sig( sigA ); + expA = normExpSig.exp; + sigA = normExpSig.sig; + } + expZ = ( ( expA - 0x3FF )>>1 ) + 0x3FE; + sigA |= UINT64_C( 0x0010000000000000 ); + sigZ32 = softfloat_estimateSqrt32( expA, sigA>>21 ); + sigA <<= 9 - ( expA & 1 ); + sigZ = + softfloat_estimateDiv128To64( sigA, 0, (uint_fast64_t) sigZ32<<32 ) + + ( (uint_fast64_t) sigZ32<<30 ); + if ( ( sigZ & 0x1FF ) <= 5 ) { + term = softfloat_mul64To128( sigZ, sigZ ); + rem = softfloat_sub128( sigA, 0, term.v64, term.v0 ); + while ( UINT64_C( 0x8000000000000000 ) <= rem.v64 ) { + --sigZ; + rem = + softfloat_add128( + rem.v64, rem.v0, sigZ>>63, (uint64_t) ( sigZ<<1 ) ); + } + sigZ |= ( ( rem.v64 | rem.v0 ) != 0 ); + } + return softfloat_roundPackToF64( 0, expZ, sigZ ); + invalid: + softfloat_raiseFlags( softfloat_flag_invalid ); + uiZ = defaultNaNF64UI; + uiZ: + uZ.ui = uiZ; + return uZ.f; + +} + diff --git a/softfloat/f64_sub.c b/softfloat/f64_sub.c new file mode 100755 index 0000000..38bd574 --- /dev/null +++ b/softfloat/f64_sub.c @@ -0,0 +1,29 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" + +float64_t f64_sub( float64_t a, float64_t b ) +{ + union ui64_f64 uA; + uint_fast64_t uiA; + bool signA; + union ui64_f64 uB; + uint_fast64_t uiB; + bool signB; + float64_t ( *magsRoutine )( uint_fast64_t, uint_fast64_t, bool ); + + uA.f = a; + uiA = uA.ui; + signA = signF64UI( uiA ); + uB.f = b; + uiB = uB.ui; + signB = signF64UI( uiB ); + magsRoutine = + ( signA == signB ) ? softfloat_subMagsF64 : softfloat_addMagsF64; + return magsRoutine( uiA, uiB, signA ); + +} + diff --git a/softfloat/f64_to_f32.c b/softfloat/f64_to_f32.c new file mode 100755 index 0000000..395d6c6 --- /dev/null +++ b/softfloat/f64_to_f32.c @@ -0,0 +1,43 @@ + +#include +#include +#include "platform.h" +#include "primitives.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +float32_t f64_to_f32( float64_t a ) +{ + union ui64_f64 uA; + uint_fast64_t uiA; + bool sign; + int_fast16_t exp; + uint_fast64_t sig; + uint_fast32_t uiZ, sig32; + union ui32_f32 uZ; + + uA.f = a; + uiA = uA.ui; + sign = signF64UI( uiA ); + exp = expF64UI( uiA ); + sig = fracF64UI( uiA ); + if ( exp == 0x7FF ) { + uiZ = + sig ? softfloat_commonNaNToF32UI( + softfloat_f64UIToCommonNaN( uiA ) ) + : packToF32UI( sign, 0xFF, 0 ); + goto uiZ; + } + sig32 = softfloat_shortShift64RightJam( sig, 22 ); + if ( ! ( exp | sig32 ) ) { + uiZ = packToF32UI( sign, 0, 0 ); + goto uiZ; + } + return softfloat_roundPackToF32( sign, exp - 0x381, sig32 | 0x40000000 ); + uiZ: + uZ.ui = uiZ; + return uZ.f; + +} + diff --git a/softfloat/f64_to_i32.c b/softfloat/f64_to_i32.c new file mode 100755 index 0000000..0778a86 --- /dev/null +++ b/softfloat/f64_to_i32.c @@ -0,0 +1,30 @@ + +#include +#include +#include "platform.h" +#include "primitives.h" +#include "internals.h" +#include "softfloat.h" + +int_fast32_t f64_to_i32( float64_t a, int_fast8_t roundingMode, bool exact ) +{ + union ui64_f64 uA; + uint_fast64_t uiA; + bool sign; + int_fast16_t exp; + uint_fast64_t sig; + int_fast16_t shiftCount; + + uA.f = a; + uiA = uA.ui; + sign = signF64UI( uiA ); + exp = expF64UI( uiA ); + sig = fracF64UI( uiA ); + if ( ( exp == 0x7FF ) && sig ) sign = 0; + if ( exp ) sig |= UINT64_C( 0x0010000000000000 ); + shiftCount = 0x42C - exp; + if ( 0 < shiftCount ) sig = softfloat_shift64RightJam( sig, shiftCount ); + return softfloat_roundPackToI32( sign, sig, roundingMode, exact ); + +} + diff --git a/softfloat/f64_to_i32_r_minMag.c b/softfloat/f64_to_i32_r_minMag.c new file mode 100755 index 0000000..39246c2 --- /dev/null +++ b/softfloat/f64_to_i32_r_minMag.c @@ -0,0 +1,50 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" + +int_fast32_t f64_to_i32_r_minMag( float64_t a, bool exact ) +{ + union ui64_f64 uA; + uint_fast64_t uiA; + int_fast16_t exp; + uint_fast64_t sig; + bool sign; + int_fast16_t shiftCount; + uint_fast32_t absZ; + union { uint32_t ui; int32_t i; } uZ; + int_fast32_t z; + + uA.f = a; + uiA = uA.ui; + exp = expF64UI( uiA ); + sig = fracF64UI( uiA ); + if ( exp < 0x3FF ) { + if ( exact && ( exp | sig ) ) { + softfloat_exceptionFlags |= softfloat_flag_inexact; + } + return 0; + } + sign = signF64UI( uiA ); + if ( 0x41E < exp ) { + if ( ( exp == 0x7FF ) && sig ) sign = 0; + goto invalid; + } + sig |= UINT64_C( 0x0010000000000000 ); + shiftCount = 0x433 - exp; + absZ = sig>>shiftCount; + uZ.ui = sign ? - absZ : absZ; + z = uZ.i; + if ( ( z < 0 ) != sign ) goto invalid; + if ( exact && ( (uint_fast64_t) absZ< +#include +#include "platform.h" +#include "primitives.h" +#include "internals.h" +#include "softfloat.h" + +int_fast64_t f64_to_i64( float64_t a, int_fast8_t roundingMode, bool exact ) +{ + union ui64_f64 uA; + uint_fast64_t uiA; + bool sign; + int_fast16_t exp; + uint_fast64_t sig; + int_fast16_t shiftCount; + struct uint64_extra sigExtra; + + uA.f = a; + uiA = uA.ui; + sign = signF64UI( uiA ); + exp = expF64UI( uiA ); + sig = fracF64UI( uiA ); + if ( exp ) sig |= UINT64_C( 0x0010000000000000 ); + shiftCount = 0x433 - exp; + if ( shiftCount <= 0 ) { + if ( 0x43E < exp ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + return + ! sign + || ( ( exp == 0x7FF ) + && ( sig != UINT64_C( 0x0010000000000000 ) ) ) + ? INT64_C( 0x7FFFFFFFFFFFFFFF ) + : - INT64_C( 0x7FFFFFFFFFFFFFFF ) - 1; + } + sigExtra.v = sig<<( - shiftCount ); + sigExtra.extra = 0; + } else { + sigExtra = softfloat_shift64ExtraRightJam( sig, 0, shiftCount ); + } + return + softfloat_roundPackToI64( + sign, sigExtra.v, sigExtra.extra, roundingMode, exact ); + +} + diff --git a/softfloat/f64_to_i64_r_minMag.c b/softfloat/f64_to_i64_r_minMag.c new file mode 100755 index 0000000..525705b --- /dev/null +++ b/softfloat/f64_to_i64_r_minMag.c @@ -0,0 +1,52 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" + +int_fast64_t f64_to_i64_r_minMag( float64_t a, bool exact ) +{ + union ui64_f64 uA; + uint_fast64_t uiA; + bool sign; + int_fast16_t exp; + uint_fast64_t sig; + int_fast16_t shiftCount; + int_fast64_t absZ; + + uA.f = a; + uiA = uA.ui; + sign = signF64UI( uiA ); + exp = expF64UI( uiA ); + sig = fracF64UI( uiA ); + shiftCount = exp - 0x433; + if ( 0 <= shiftCount ) { + if ( 0x43E <= exp ) { + if ( uiA != packToF64UI( 1, 0x43E, 0 ) ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + if ( ! sign || ( ( exp == 0x7FF ) && sig ) ) { + return INT64_C( 0x7FFFFFFFFFFFFFFF ); + } + } + return - INT64_C( 0x7FFFFFFFFFFFFFFF ) - 1; + } + sig |= UINT64_C( 0x0010000000000000 ); + absZ = sig<>( - shiftCount ); + if ( exact && (uint64_t) ( sig<<( shiftCount & 63 ) ) ) { + softfloat_exceptionFlags |= softfloat_flag_inexact; + } + } + return sign ? - absZ : absZ; + +} + diff --git a/softfloat/f64_to_ui32.c b/softfloat/f64_to_ui32.c new file mode 100755 index 0000000..b186605 --- /dev/null +++ b/softfloat/f64_to_ui32.c @@ -0,0 +1,29 @@ + +#include +#include +#include "platform.h" +#include "primitives.h" +#include "internals.h" +#include "softfloat.h" + +uint_fast32_t f64_to_ui32( float64_t a, int_fast8_t roundingMode, bool exact ) +{ + union ui64_f64 uA; + uint_fast64_t uiA; + bool sign; + int_fast16_t exp; + uint_fast64_t sig; + int_fast16_t shiftCount; + + uA.f = a; + uiA = uA.ui; + sign = signF64UI( uiA ); + exp = expF64UI( uiA ); + sig = fracF64UI( uiA ); + if ( exp ) sig |= UINT64_C( 0x0010000000000000 ); + shiftCount = 0x42C - exp; + if ( 0 < shiftCount ) sig = softfloat_shift64RightJam( sig, shiftCount ); + return softfloat_roundPackToUI32( sign, sig, roundingMode, exact ); + +} + diff --git a/softfloat/f64_to_ui32_r_minMag.c b/softfloat/f64_to_ui32_r_minMag.c new file mode 100755 index 0000000..9f1dd4d --- /dev/null +++ b/softfloat/f64_to_ui32_r_minMag.c @@ -0,0 +1,40 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" + +uint_fast32_t f64_to_ui32_r_minMag( float64_t a, bool exact ) +{ + union ui64_f64 uA; + uint_fast64_t uiA; + int_fast16_t exp; + uint_fast64_t sig; + int_fast16_t shiftCount; + uint_fast32_t z; + + uA.f = a; + uiA = uA.ui; + exp = expF64UI( uiA ); + sig = fracF64UI( uiA ); + if ( exp < 0x3FF ) { + if ( exact && ( exp | sig ) ) { + softfloat_exceptionFlags |= softfloat_flag_inexact; + } + return 0; + } + if ( signF64UI( uiA ) || ( 0x41E < exp ) ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + return 0xFFFFFFFF; + } + sig |= UINT64_C( 0x0010000000000000 ); + shiftCount = 0x433 - exp; + z = sig>>shiftCount; + if ( exact && ( (uint_fast64_t) z< +#include +#include "platform.h" +#include "primitives.h" +#include "internals.h" +#include "softfloat.h" + +uint_fast64_t f64_to_ui64( float64_t a, int_fast8_t roundingMode, bool exact ) +{ + union ui64_f64 uA; + uint_fast64_t uiA; + bool sign; + int_fast16_t exp; + uint_fast64_t sig; + int_fast16_t shiftCount; + struct uint64_extra sigExtra; + + uA.f = a; + uiA = uA.ui; + sign = signF64UI( uiA ); + exp = expF64UI( uiA ); + sig = fracF64UI( uiA ); + if ( exp ) sig |= UINT64_C( 0x0010000000000000 ); + shiftCount = 0x433 - exp; + if ( shiftCount <= 0 ) { + if ( 0x43E < exp ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + return UINT64_C( 0xFFFFFFFFFFFFFFFF ); + } + sigExtra.v = sig<<( - shiftCount ); + sigExtra.extra = 0; + } else { + sigExtra = softfloat_shift64ExtraRightJam( sig, 0, shiftCount ); + } + return + softfloat_roundPackToUI64( + sign, sigExtra.v, sigExtra.extra, roundingMode, exact ); + +} + diff --git a/softfloat/f64_to_ui64_r_minMag.c b/softfloat/f64_to_ui64_r_minMag.c new file mode 100755 index 0000000..a66d3ff --- /dev/null +++ b/softfloat/f64_to_ui64_r_minMag.c @@ -0,0 +1,45 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" + +uint_fast64_t f64_to_ui64_r_minMag( float64_t a, bool exact ) +{ + union ui64_f64 uA; + uint_fast64_t uiA; + int_fast16_t exp; + uint_fast64_t sig; + int_fast16_t shiftCount; + uint_fast64_t z; + + uA.f = a; + uiA = uA.ui; + exp = expF64UI( uiA ); + sig = fracF64UI( uiA ); + if ( exp < 0x3FF ) { + if ( exact && ( exp | sig ) ) { + softfloat_exceptionFlags |= softfloat_flag_inexact; + } + return 0; + } + if ( signF64UI( uiA ) ) goto invalid; + shiftCount = exp - 0x433; + if ( 0 <= shiftCount ) { + if ( 0x43E < exp ) goto invalid; + z = ( sig | UINT64_C( 0x0010000000000000 ) )<>( - shiftCount ); + if ( exact && (uint64_t) ( sig<<( shiftCount & 63 ) ) ) { + softfloat_exceptionFlags |= softfloat_flag_inexact; + } + } + return z; + invalid: + softfloat_raiseFlags( softfloat_flag_invalid ); + return UINT64_C( 0xFFFFFFFFFFFFFFFF ); + +} + diff --git a/softfloat/i32_to_f32.c b/softfloat/i32_to_f32.c new file mode 100755 index 0000000..f51facd --- /dev/null +++ b/softfloat/i32_to_f32.c @@ -0,0 +1,21 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" + +float32_t i32_to_f32( int_fast32_t a ) +{ + bool sign; + union ui32_f32 uZ; + + sign = ( a < 0 ); + if ( ! ( a & 0x7FFFFFFF ) ) { + uZ.ui = sign ? packToF32UI( 1, 0x9E, 0 ) : 0; + return uZ.f; + } + return softfloat_normRoundPackToF32( sign, 0x9C, sign ? - a : a ); + +} + diff --git a/softfloat/i32_to_f64.c b/softfloat/i32_to_f64.c new file mode 100755 index 0000000..d42cbe8 --- /dev/null +++ b/softfloat/i32_to_f64.c @@ -0,0 +1,31 @@ + +#include +#include +#include "platform.h" +#include "primitives.h" +#include "internals.h" +#include "softfloat.h" + +float64_t i32_to_f64( int_fast32_t a ) +{ + uint_fast64_t uiZ; + bool sign; + uint_fast32_t absA; + int shiftCount; + union ui64_f64 uZ; + + if ( ! a ) { + uiZ = 0; + } else { + sign = ( a < 0 ); + absA = sign ? - a : a; + shiftCount = softfloat_countLeadingZeros32( absA ) + 21; + uiZ = + packToF64UI( + sign, 0x432 - shiftCount, (uint_fast64_t) absA< +#include +#include "platform.h" +#include "primitives.h" +#include "internals.h" +#include "softfloat.h" + +float32_t i64_to_f32( int_fast64_t a ) +{ + bool sign; + uint_fast64_t absA; + int shiftCount; + union ui32_f32 u; + uint_fast32_t sig; + + sign = ( a < 0 ); + absA = sign ? - (uint_fast64_t) a : a; + shiftCount = softfloat_countLeadingZeros64( absA ) - 40; + if ( 0 <= shiftCount ) { + u.ui = + a ? packToF32UI( + sign, 0x95 - shiftCount, (uint_fast32_t) absA< +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" + +float64_t i64_to_f64( int_fast64_t a ) +{ + bool sign; + union ui64_f64 uZ; + + sign = ( a < 0 ); + if ( ! ( a & UINT64_C( 0x7FFFFFFFFFFFFFFF ) ) ) { + uZ.ui = sign ? packToF64UI( 1, 0x43E, 0 ) : 0; + return uZ.f; + } + return softfloat_normRoundPackToF64( sign, 0x43C, sign ? - a : a ); + +} + diff --git a/softfloat/internals.h b/softfloat/internals.h new file mode 100755 index 0000000..5e6fd76 --- /dev/null +++ b/softfloat/internals.h @@ -0,0 +1,232 @@ + +/*** UPDATE COMMENTS. ***/ + +#include "softfloat_types.h" + +union ui32_f32 { uint32_t ui; float32_t f; }; +union ui64_f64 { uint64_t ui; float64_t f; }; +#ifdef LITTLEENDIAN +union ui128_f128 { uint64_t ui0, ui64; float128_t f; }; +#else +union ui128_f128 { uint64_t ui64, ui0; float128_t f; }; +#endif + +enum { + softfloat_mulAdd_subC = 1, + softfloat_mulAdd_subProd = 2 +}; + +uint_fast32_t + softfloat_roundPackToUI32( bool, uint_fast64_t, int_fast8_t, bool ); +uint_fast64_t + softfloat_roundPackToUI64( + bool, uint_fast64_t, uint_fast64_t, int_fast8_t, bool ); +/*---------------------------------------------------------------------------- +| Takes a 64-bit fixed-point value `absZ' with binary point between bits 6 +| and 7, and returns the properly rounded 32-bit integer corresponding to the +| input. If `zSign' is 1, the input is negated before being converted to an +| integer. Bit 63 of `absZ' must be zero. Ordinarily, the fixed-point input +| is simply rounded to an integer, with the inexact exception raised if the +| input cannot be represented exactly as an integer. However, if the fixed- +| point input is too large, the invalid exception is raised and the largest +| positive or negative integer is returned. +*----------------------------------------------------------------------------*/ +int_fast32_t + softfloat_roundPackToI32( bool, uint_fast64_t, int_fast8_t, bool ); +/*---------------------------------------------------------------------------- +| Takes the 128-bit fixed-point value formed by concatenating `absZ0' and +| `absZ1', with binary point between bits 63 and 64 (between the input words), +| and returns the properly rounded 64-bit integer corresponding to the input. +| If `zSign' is 1, the input is negated before being converted to an integer. +| Ordinarily, the fixed-point input is simply rounded to an integer, with +| the inexact exception raised if the input cannot be represented exactly as +| an integer. However, if the fixed-point input is too large, the invalid +| exception is raised and the largest positive or negative integer is +| returned. +*----------------------------------------------------------------------------*/ +int_fast64_t + softfloat_roundPackToI64( + bool, uint_fast64_t, uint_fast64_t, int_fast8_t, bool ); + +/*---------------------------------------------------------------------------- +| Returns 1 if the single-precision floating-point value `a' is a NaN; +| otherwise, returns 0. +*----------------------------------------------------------------------------*/ +#define isNaNF32UI( ui ) (0xFF000000<(uint32_t)((uint_fast32_t)(ui)<<1)) +/*---------------------------------------------------------------------------- +| Returns the sign bit of the single-precision floating-point value `a'. +*----------------------------------------------------------------------------*/ +#define signF32UI( a ) ((bool)((uint32_t)(a)>>31)) +/*---------------------------------------------------------------------------- +| Returns the exponent bits of the single-precision floating-point value `a'. +*----------------------------------------------------------------------------*/ +#define expF32UI( a ) ((int_fast16_t)((a)>>23)&0xFF) +/*---------------------------------------------------------------------------- +| Returns the fraction bits of the single-precision floating-point value `a'. +*----------------------------------------------------------------------------*/ +#define fracF32UI( a ) ((a)&0x007FFFFF) +/*---------------------------------------------------------------------------- +| Packs the sign `zSign', exponent `zExp', and significand `zSig' into a +| single-precision floating-point value, returning the result. After being +| shifted into the proper positions, the three fields are simply added +| together to form the result. This means that any integer portion of `zSig' +| will be added into the exponent. Since a properly normalized significand +| will have an integer portion equal to 1, the `zExp' input should be 1 less +| than the desired result exponent whenever `zSig' is a complete, normalized +| significand. +*----------------------------------------------------------------------------*/ +#define packToF32UI( sign, exp, sig ) (((uint32_t)(sign)<<31)+((uint32_t)(exp)<<23)+(sig)) + +/*---------------------------------------------------------------------------- +| Normalizes the subnormal single-precision floating-point value represented +| by the denormalized significand `aSig'. The normalized exponent and +| significand are stored at the locations pointed to by `zExpPtr' and +| `zSigPtr', respectively. +*----------------------------------------------------------------------------*/ +struct exp16_sig32 { int_fast16_t exp; uint_fast32_t sig; }; +struct exp16_sig32 softfloat_normSubnormalF32Sig( uint_fast32_t ); + +/*---------------------------------------------------------------------------- +| Takes an abstract floating-point value having sign `zSign', exponent `zExp', +| and significand `zSig', and returns the proper single-precision floating- +| point value corresponding to the abstract input. Ordinarily, the abstract +| value is simply rounded and packed into the single-precision format, with +| the inexact exception raised if the abstract input cannot be represented +| exactly. However, if the abstract value is too large, the overflow and +| inexact exceptions are raised and an infinity or maximal finite value is +| returned. If the abstract value is too small, the input value is rounded to +| a subnormal number, and the underflow and inexact exceptions are raised if +| the abstract input cannot be represented exactly as a subnormal single- +| precision floating-point number. +| The input significand `zSig' has its binary point between bits 30 +| and 29, which is 7 bits to the left of the usual location. This shifted +| significand must be normalized or smaller. If `zSig' is not normalized, +| `zExp' must be 0; in that case, the result returned is a subnormal number, +| and it must not require rounding. In the usual case that `zSig' is +| normalized, `zExp' must be 1 less than the ``true'' floating-point exponent. +| The handling of underflow and overflow follows the IEC/IEEE Standard for +| Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ +float32_t softfloat_roundPackToF32( bool, int_fast16_t, uint_fast32_t ); +/*---------------------------------------------------------------------------- +| Takes an abstract floating-point value having sign `zSign', exponent `zExp', +| and significand `zSig', and returns the proper single-precision floating- +| point value corresponding to the abstract input. This routine is just like +| `roundAndPackFloat32' except that `zSig' does not have to be normalized. +| Bit 31 of `zSig' must be zero, and `zExp' must be 1 less than the ``true'' +| floating-point exponent. +*----------------------------------------------------------------------------*/ +float32_t softfloat_normRoundPackToF32( bool, int_fast16_t, uint_fast32_t ); + +/*---------------------------------------------------------------------------- +| Returns the result of adding the absolute values of the single-precision +| floating-point values `a' and `b'. If `zSign' is 1, the sum is negated +| before being returned. `zSign' is ignored if the result is a NaN. +| The addition is performed according to the IEC/IEEE Standard for Binary +| Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ +float32_t softfloat_addMagsF32( uint_fast32_t, uint_fast32_t, bool ); +/*---------------------------------------------------------------------------- +| Returns the result of subtracting the absolute values of the single- +| precision floating-point values `a' and `b'. If `zSign' is 1, the +| difference is negated before being returned. `zSign' is ignored if the +| result is a NaN. The subtraction is performed according to the IEC/IEEE +| Standard for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ +float32_t softfloat_subMagsF32( uint_fast32_t, uint_fast32_t, bool ); +/*---------------------------------------------------------------------------- +*----------------------------------------------------------------------------*/ +float32_t + softfloat_mulAddF32( int, uint_fast32_t, uint_fast32_t, uint_fast32_t ); + +/*---------------------------------------------------------------------------- +| Returns 1 if the double-precision floating-point value `a' is a NaN; +| otherwise, returns 0. +*----------------------------------------------------------------------------*/ +#define isNaNF64UI( ui ) (UINT64_C(0xFFE0000000000000)<(uint64_t)((uint_fast64_t)(ui)<<1)) +/*---------------------------------------------------------------------------- +| Returns the sign bit of the double-precision floating-point value `a'. +*----------------------------------------------------------------------------*/ +#define signF64UI( a ) ((bool)((uint64_t)(a)>>63)) +/*---------------------------------------------------------------------------- +| Returns the exponent bits of the double-precision floating-point value `a'. +*----------------------------------------------------------------------------*/ +#define expF64UI( a ) ((int_fast16_t)((a)>>52)&0x7FF) +/*---------------------------------------------------------------------------- +| Returns the fraction bits of the double-precision floating-point value `a'. +*----------------------------------------------------------------------------*/ +#define fracF64UI( a ) ((a)&UINT64_C(0x000FFFFFFFFFFFFF)) +/*---------------------------------------------------------------------------- +| Packs the sign `zSign', exponent `zExp', and significand `zSig' into a +| double-precision floating-point value, returning the result. After being +| shifted into the proper positions, the three fields are simply added +| together to form the result. This means that any integer portion of `zSig' +| will be added into the exponent. Since a properly normalized significand +| will have an integer portion equal to 1, the `zExp' input should be 1 less +| than the desired result exponent whenever `zSig' is a complete, normalized +| significand. +*----------------------------------------------------------------------------*/ +#define packToF64UI( sign, exp, sig ) (((uint64_t)(sign)<<63)+((uint64_t)(exp)<<52)+(sig)) + +/*---------------------------------------------------------------------------- +| Normalizes the subnormal double-precision floating-point value represented +| by the denormalized significand `aSig'. The normalized exponent and +| significand are stored at the locations pointed to by `zExpPtr' and +| `zSigPtr', respectively. +*----------------------------------------------------------------------------*/ +struct exp16_sig64 { int_fast16_t exp; uint_fast64_t sig; }; +struct exp16_sig64 softfloat_normSubnormalF64Sig( uint_fast64_t ); + +/*---------------------------------------------------------------------------- +| Takes an abstract floating-point value having sign `zSign', exponent `zExp', +| and significand `zSig', and returns the proper double-precision floating- +| point value corresponding to the abstract input. Ordinarily, the abstract +| value is simply rounded and packed into the double-precision format, with +| the inexact exception raised if the abstract input cannot be represented +| exactly. However, if the abstract value is too large, the overflow and +| inexact exceptions are raised and an infinity or maximal finite value is +| returned. If the abstract value is too small, the input value is rounded +| to a subnormal number, and the underflow and inexact exceptions are raised +| if the abstract input cannot be represented exactly as a subnormal double- +| precision floating-point number. +| The input significand `zSig' has its binary point between bits 62 +| and 61, which is 10 bits to the left of the usual location. This shifted +| significand must be normalized or smaller. If `zSig' is not normalized, +| `zExp' must be 0; in that case, the result returned is a subnormal number, +| and it must not require rounding. In the usual case that `zSig' is +| normalized, `zExp' must be 1 less than the ``true'' floating-point exponent. +| The handling of underflow and overflow follows the IEC/IEEE Standard for +| Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ +float64_t softfloat_roundPackToF64( bool, int_fast16_t, uint_fast64_t ); +/*---------------------------------------------------------------------------- +| Takes an abstract floating-point value having sign `zSign', exponent `zExp', +| and significand `zSig', and returns the proper double-precision floating- +| point value corresponding to the abstract input. This routine is just like +| `roundAndPackFloat64' except that `zSig' does not have to be normalized. +| Bit 63 of `zSig' must be zero, and `zExp' must be 1 less than the ``true'' +| floating-point exponent. +*----------------------------------------------------------------------------*/ +float64_t softfloat_normRoundPackToF64( bool, int_fast16_t, uint_fast64_t ); + +/*---------------------------------------------------------------------------- +| Returns the result of adding the absolute values of the double-precision +| floating-point values `a' and `b'. If `zSign' is 1, the sum is negated +| before being returned. `zSign' is ignored if the result is a NaN. +| The addition is performed according to the IEC/IEEE Standard for Binary +| Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ +float64_t softfloat_addMagsF64( uint_fast64_t, uint_fast64_t, bool ); +/*---------------------------------------------------------------------------- +| Returns the result of subtracting the absolute values of the double- +| precision floating-point values `a' and `b'. If `zSign' is 1, the +| difference is negated before being returned. `zSign' is ignored if the +| result is a NaN. The subtraction is performed according to the IEC/IEEE +| Standard for Binary Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ +float64_t softfloat_subMagsF64( uint_fast64_t, uint_fast64_t, bool ); +/*---------------------------------------------------------------------------- +*----------------------------------------------------------------------------*/ +float64_t + softfloat_mulAddF64( int, uint_fast64_t, uint_fast64_t, uint_fast64_t ); + diff --git a/softfloat/primitives.h b/softfloat/primitives.h new file mode 100755 index 0000000..71038ea --- /dev/null +++ b/softfloat/primitives.h @@ -0,0 +1,628 @@ + +/*============================================================================ + +This C source fragment is part of the SoftFloat IEC/IEEE Floating-point +Arithmetic Package, Release 3. + +*** UPDATE + +Written by John R. Hauser. This work was made possible in part by the +International Computer Science Institute, located at Suite 600, 1947 Center +Street, Berkeley, California 94704. Funding was partially provided by the +National Science Foundation under grant MIP-9311980. The original version +of this code was written as part of a project to build a fixed-point vector +processor in collaboration with the University of California at Berkeley, +overseen by Profs. Nelson Morgan and John Wawrzynek. More information +is available through the Web page `http://www.cs.berkeley.edu/~jhauser/ +arithmetic/SoftFloat.html'. + +THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has +been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES +RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS +AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES, +COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE +EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE +INSTITUTE (possibly via similar legal notice) AGAINST ALL LOSSES, COSTS, OR +OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE. + +Derivative works are acceptable, even for commercial purposes, so long as +(1) the source code for the derivative work includes prominent notice that +the work is derivative, and (2) the source code includes prominent notice with +these four paragraphs for those parts of this code that are retained. + +=============================================================================*/ + +#include +#include + +/*** CHANGE TO USE `fast' INTEGER TYPES? ***/ +/*** ADD 80-BIT FUNCTIONS? ***/ + +#ifdef LITTLEENDIAN +struct uintx80 { uint64_t v0; uint16_t v64; }; +struct uint128 { uint64_t v0, v64; }; +struct uint192 { uint64_t v0, v64, v128; }; +struct uint256 { uint64_t v0, v64, v128, v192; }; +#else +struct uintx80 { uint16_t v64; uint64_t v0; }; +struct uint128 { uint64_t v64, v0; }; +struct uint192 { uint64_t v128, v64, v0; }; +struct uint256 { uint64_t v256, v128, v64, v0; }; +#endif + +struct uint64_extra { uint64_t v, extra; }; +struct uint128_extra { uint64_t v64; uint64_t v0; uint64_t extra; }; + + +/*** SHIFT COUNTS CANNOT BE ZERO. MUST CHECK BEFORE CALLING! ***/ + + +/*---------------------------------------------------------------------------- +| Returns 1 if the 128-bit value formed by concatenating `a0' and `a1' +| is equal to the 128-bit value formed by concatenating `b0' and `b1'. +| Otherwise, returns 0. +*----------------------------------------------------------------------------*/ +#if defined INLINE_LEVEL && ( 1 <= INLINE_LEVEL ) +INLINE bool + softfloat_eq128( uint64_t a64, uint64_t a0, uint64_t b64, uint64_t b0 ) + { return ( a64 == b64 ) && ( a0 == b0 ); } +#else +bool softfloat_eq128( uint64_t, uint64_t, uint64_t, uint64_t ); +#endif + +/*---------------------------------------------------------------------------- +| Returns 1 if the 128-bit value formed by concatenating `a0' and `a1' is less +| than or equal to the 128-bit value formed by concatenating `b0' and `b1'. +| Otherwise, returns 0. +*----------------------------------------------------------------------------*/ +#if defined INLINE_LEVEL && ( 1 <= INLINE_LEVEL ) +INLINE bool + softfloat_le128( uint64_t a64, uint64_t a0, uint64_t b64, uint64_t b0 ) + { return ( a64 < b64 ) || ( ( a64 == b64 ) && ( a0 <= b0 ) ); } +#else +bool softfloat_le128( uint64_t, uint64_t, uint64_t, uint64_t ); +#endif + +/*---------------------------------------------------------------------------- +| Returns 1 if the 128-bit value formed by concatenating `a0' and `a1' is less +| than the 128-bit value formed by concatenating `b0' and `b1'. Otherwise, +| returns 0. +*----------------------------------------------------------------------------*/ +#if defined INLINE_LEVEL && ( 1 <= INLINE_LEVEL ) +INLINE bool + softfloat_lt128( uint64_t a64, uint64_t a0, uint64_t b64, uint64_t b0 ) + { return ( a64 < b64 ) || ( ( a64 == b64 ) && ( a0 < b0 ) ); } +#else +bool softfloat_lt128( uint64_t, uint64_t, uint64_t, uint64_t ); +#endif + +/*---------------------------------------------------------------------------- +| Shifts the 128-bit value formed by concatenating `a0' and `a1' left by the +| number of bits given in `count'. Any bits shifted off are lost. The value +| of `count' must be less than 64. The result is broken into two 64-bit +| pieces which are stored at the locations pointed to by `z0Ptr' and `z1Ptr'. +*----------------------------------------------------------------------------*/ +#if defined INLINE_LEVEL && ( 2 <= INLINE_LEVEL ) +INLINE struct uint128 + softfloat_shortShift128Left( uint64_t a64, uint64_t a0, unsigned int count ) +{ + struct uint128 z; + z.v64 = a64<>( ( - count ) & 63 ); + z.v0 = a0<>( negCount & 63 ); + z.v64 = a64<>( negCount & 63 ); + z.v0 = a0<>count | ( (uint32_t) ( a<<( ( - count ) & 31 ) ) != 0 ) + : ( a != 0 ); +} +#else +uint32_t softfloat_shift32RightJam( uint32_t, unsigned int ); +#endif + +/*---------------------------------------------------------------------------- +| Shift count is less than 32. +*----------------------------------------------------------------------------*/ +#if defined INLINE +INLINE uint32_t softfloat_shortShift32Right1Jam( uint32_t a ) + { return a>>1 | ( a & 1 ); } +#else +uint32_t softfloat_shortShift32Right1Jam( uint32_t ); +#endif + +/*---------------------------------------------------------------------------- +| Shifts `a' right by the number of bits given in `count'. If any nonzero +| bits are shifted off, they are ``jammed'' into the least significant bit of +| the result by setting the least significant bit to 1. The value of `count' +| can be arbitrarily large; in particular, if `count' is greater than 64, the +| result will be either 0 or 1, depending on whether `a' is zero or nonzero. +| The result is stored in the location pointed to by `zPtr'. +*----------------------------------------------------------------------------*/ +#if defined INLINE_LEVEL && ( 3 <= INLINE_LEVEL ) +INLINE uint64_t softfloat_shift64RightJam( uint64_t a, unsigned int count ) +{ + return + ( count < 64 ) + ? a>>count | ( (uint64_t) ( a<<( ( - count ) & 63 ) ) != 0 ) + : ( a != 0 ); +} +#else +uint64_t softfloat_shift64RightJam( uint64_t, unsigned int ); +#endif + +/*---------------------------------------------------------------------------- +| Shift count is less than 64. +*----------------------------------------------------------------------------*/ +#if defined INLINE_LEVEL && ( 2 <= INLINE_LEVEL ) +INLINE uint64_t + softfloat_shortShift64RightJam( uint64_t a, unsigned int count ) + { return a>>count | ( ( a & ( ( (uint64_t) 1<>count; + z.extra = a<<( ( - count ) & 63 ); + } else { + z.v = 0; + z.extra = ( count == 64 ) ? a : ( a != 0 ); + } + z.extra |= ( extra != 0 ); + return z; +} +#else +struct uint64_extra + softfloat_shift64ExtraRightJam( uint64_t, uint64_t, unsigned int ); +#endif + +/*---------------------------------------------------------------------------- +| Shift count is less than 64. +*----------------------------------------------------------------------------*/ +#if defined INLINE_LEVEL && ( 2 <= INLINE_LEVEL ) +INLINE struct uint64_extra + softfloat_shortShift64ExtraRightJam( + uint64_t a, uint64_t extra, unsigned int count ) +{ + struct uint64_extra z; + z.v = a>>count; + z.extra = a<<( ( - count ) & 63 ) | ( extra != 0 ); + return z; +} +#else +struct uint64_extra + softfloat_shortShift64ExtraRightJam( uint64_t, uint64_t, unsigned int ); +#endif + +/*---------------------------------------------------------------------------- +| Shifts the 128-bit value formed by concatenating `a0' and `a1' right by the +| number of bits given in `count'. Any bits shifted off are lost. The value +| of `count' can be arbitrarily large; in particular, if `count' is greater +| than 128, the result will be 0. The result is broken into two 64-bit pieces +| which are stored at the locations pointed to by `z0Ptr' and `z1Ptr'. +*----------------------------------------------------------------------------*/ +/*---------------------------------------------------------------------------- +| Shift count is less than 64. +*----------------------------------------------------------------------------*/ +#if defined INLINE_LEVEL && ( 2 <= INLINE_LEVEL ) +INLINE struct uint128 + softfloat_shortShift128Right( uint64_t a64, uint64_t a0, unsigned int count ) +{ + struct uint128 z; + z.v64 = a64>>count; + z.v0 = a64<<( ( - count ) & 63 ) | a0>>count; + return z; +} +#else +struct uint128 + softfloat_shortShift128Right( uint64_t, uint64_t, unsigned int ); +#endif + +/*---------------------------------------------------------------------------- +| Shifts the 128-bit value formed by concatenating `a0' and `a1' right by the +| number of bits given in `count'. If any nonzero bits are shifted off, they +| are ``jammed'' into the least significant bit of the result by setting the +| least significant bit to 1. The value of `count' can be arbitrarily large; +| in particular, if `count' is greater than 128, the result will be either +| 0 or 1, depending on whether the concatenation of `a0' and `a1' is zero or +| nonzero. The result is broken into two 64-bit pieces which are stored at +| the locations pointed to by `z0Ptr' and `z1Ptr'. +*----------------------------------------------------------------------------*/ +#if defined INLINE_LEVEL && ( 4 <= INLINE_LEVEL ) +INLINE struct uint128 + softfloat_shift128RightJam( uint64_t a64, uint64_t a0, unsigned int count ) +{ + unsigned int negCount; + struct uint128 z; + if ( count < 64 ) { + negCount = - count; + z.v64 = a64>>( count & 63 ); + z.v0 = + a64<<( negCount & 63 ) | a0>>count + | ( (uint64_t) ( a0<<( negCount & 63 ) ) != 0 ); + } else { + z.v64 = 0; + z.v0 = + ( count < 128 ) + ? a64>>( count & 63 ) + | ( ( ( a64 & ( ( (uint64_t) 1<<( count & 63 ) ) - 1 ) ) + | a0 ) + != 0 ) + : ( ( a64 | a0 ) != 0 ); + } + return z; +} +#else +struct uint128 + softfloat_shift128RightJam( uint64_t, uint64_t, unsigned int ); +#endif + +/*---------------------------------------------------------------------------- +| Shifts the 192-bit value formed by concatenating `a0', `a1', and `a2' right +| by 64 _plus_ the number of bits given in `count'. The shifted result is +| at most 128 nonzero bits; these are broken into two 64-bit pieces which are +| stored at the locations pointed to by `z0Ptr' and `z1Ptr'. The bits shifted +| off form a third 64-bit result as follows: The _last_ bit shifted off is +| the most-significant bit of the extra result, and the other 63 bits of the +| extra result are all zero if and only if _all_but_the_last_ bits shifted off +| were all zero. This extra result is stored in the location pointed to by +| `z2Ptr'. The value of `count' can be arbitrarily large. +| (This routine makes more sense if `a0', `a1', and `a2' are considered +| to form a fixed-point value with binary point between `a1' and `a2'. This +| fixed-point value is shifted right by the number of bits given in `count', +| and the integer part of the result is returned at the locations pointed to +| by `z0Ptr' and `z1Ptr'. The fractional part of the result may be slightly +| corrupted as described above, and is returned at the location pointed to by +| `z2Ptr'.) +*----------------------------------------------------------------------------*/ +#if defined INLINE_LEVEL && ( 5 <= INLINE_LEVEL ) +INLINE struct uint128_extra + softfloat_shift128ExtraRightJam( + uint64_t a64, uint64_t a0, uint64_t extra, unsigned int count ) +{ + unsigned int negCount = - count; + struct uint128_extra z; + if ( count < 64 ) { + z.v64 = a64>>count; + z.v0 = a64<<( negCount & 63 ) | a0>>count; + z.extra = a0<<( negCount & 63 ); + } else { + z.v64 = 0; + if ( count == 64 ) { + z.v0 = a64; + z.extra = a0; + } else { + extra |= a0; + if ( count < 128 ) { + z.v0 = a64>>( count & 63 ); + z.extra = a64<<( negCount & 63 ); + } else { + z.v0 = 0; + z.extra = ( count == 128 ) ? a64 : ( a64 != 0 ); + } + } + } + z.extra |= ( extra != 0 ); + return z; +} +#else +struct uint128_extra + softfloat_shift128ExtraRightJam( uint64_t, uint64_t, uint64_t, unsigned int ); +#endif + +/*---------------------------------------------------------------------------- +| Shift count is less than 64. +*----------------------------------------------------------------------------*/ +#if defined INLINE_LEVEL && ( 3 <= INLINE_LEVEL ) +INLINE struct uint128_extra + softfloat_shortShift128ExtraRightJam( + uint64_t a64, uint64_t a0, uint64_t extra, unsigned int count ) +{ + unsigned int negCount = - count; + struct uint128_extra z; + z.v64 = a64>>count; + z.v0 = a64<<( negCount & 63 ) | a0>>count; + z.extra = a0<<( negCount & 63 ) | ( extra != 0 ); + return z; +} +#else +struct uint128_extra + softfloat_shortShift128ExtraRightJam( + uint64_t, uint64_t, uint64_t, unsigned int ); +#endif + +extern const uint8_t softfloat_countLeadingZeros8[ 256 ]; + +/*---------------------------------------------------------------------------- +| Returns the number of leading 0 bits before the most-significant 1 bit of +| `a'. If `a' is zero, 32 is returned. +*----------------------------------------------------------------------------*/ +#if defined INLINE_LEVEL && ( 2 <= INLINE_LEVEL ) +INLINE int softfloat_countLeadingZeros32( uint32_t a ) +{ + int count = 0; + if ( a < 0x10000 ) { + count = 16; + a <<= 16; + } + if ( a < 0x1000000 ) { + count += 8; + a <<= 8; + } + count += softfloat_countLeadingZeros8[ a>>24 ]; + return count; +} +#else +int softfloat_countLeadingZeros32( uint32_t ); +#endif + +/*---------------------------------------------------------------------------- +| Returns the number of leading 0 bits before the most-significant 1 bit of +| `a'. If `a' is zero, 64 is returned. +*----------------------------------------------------------------------------*/ +#if defined INLINE_LEVEL && ( 4 <= INLINE_LEVEL ) +INLINE int softfloat_countLeadingZeros64( uint64_t a ) +{ + int count = 32; + uint32_t a32 = a; + if ( UINT64_C( 0x100000000 ) <= a ) { + count = 0; + a32 = a>>32; + } + /*------------------------------------------------------------------------ + | From here, result is current count + count leading zeros of `a32'. + *------------------------------------------------------------------------*/ + if ( a32 < 0x10000 ) { + count += 16; + a32 <<= 16; + } + if ( a32 < 0x1000000 ) { + count += 8; + a32 <<= 8; + } + count += softfloat_countLeadingZeros8[ a32>>24 ]; + return count; +} +#else +int softfloat_countLeadingZeros64( uint64_t ); +#endif + +/*---------------------------------------------------------------------------- +| Adds the 128-bit value formed by concatenating `a0' and `a1' to the 128-bit +| value formed by concatenating `b0' and `b1'. Addition is modulo 2^128, so +| any carry out is lost. The result is broken into two 64-bit pieces which +| are stored at the locations pointed to by `z0Ptr' and `z1Ptr'. +*----------------------------------------------------------------------------*/ +#if defined INLINE_LEVEL && ( 2 <= INLINE_LEVEL ) +INLINE struct uint128 + softfloat_add128( uint64_t a64, uint64_t a0, uint64_t b64, uint64_t b0 ) +{ + struct uint128 z; + z.v0 = a0 + b0; + z.v64 = a64 + b64; + z.v64 += ( z.v0 < a0 ); + return z; +} +#else +struct uint128 softfloat_add128( uint64_t, uint64_t, uint64_t, uint64_t ); +#endif + +/*---------------------------------------------------------------------------- +| Adds the 192-bit value formed by concatenating `a0', `a1', and `a2' to the +| 192-bit value formed by concatenating `b0', `b1', and `b2'. Addition is +| modulo 2^192, so any carry out is lost. The result is broken into three +| 64-bit pieces which are stored at the locations pointed to by `z0Ptr', +| `z1Ptr', and `z2Ptr'. +*----------------------------------------------------------------------------*/ +#if defined INLINE_LEVEL && ( 3 <= INLINE_LEVEL ) +INLINE struct uint192 + softfloat_add192( + uint64_t a128, + uint64_t a64, + uint64_t a0, + uint64_t b128, + uint64_t b64, + uint64_t b0 + ) +{ + struct uint192 z; + unsigned int carry64, carry128; + z.v0 = a0 + b0; + carry64 = ( z.v0 < a0 ); + z.v64 = a64 + b64; + carry128 = ( z.v64 < a64 ); + z.v128 = a128 + b128; + z.v64 += carry64; + carry128 += ( z.v64 < carry64 ); + z.v128 += carry128; + return z; +} +#else +struct uint192 + softfloat_add192( + uint64_t, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t ); +#endif + +/*---------------------------------------------------------------------------- +| Subtracts the 128-bit value formed by concatenating `b0' and `b1' from the +| 128-bit value formed by concatenating `a0' and `a1'. Subtraction is modulo +| 2^128, so any borrow out (carry out) is lost. The result is broken into two +| 64-bit pieces which are stored at the locations pointed to by `z0Ptr' and +| `z1Ptr'. +*----------------------------------------------------------------------------*/ +#if defined INLINE_LEVEL && ( 2 <= INLINE_LEVEL ) +INLINE struct uint128 + softfloat_sub128( uint64_t a64, uint64_t a0, uint64_t b64, uint64_t b0 ) +{ + struct uint128 z; + z.v0 = a0 - b0; + z.v64 = a64 - b64; + z.v64 -= ( a0 < b0 ); + return z; +} +#else +struct uint128 softfloat_sub128( uint64_t, uint64_t, uint64_t, uint64_t ); +#endif + +/*---------------------------------------------------------------------------- +| Subtracts the 192-bit value formed by concatenating `b0', `b1', and `b2' +| from the 192-bit value formed by concatenating `a0', `a1', and `a2'. +| Subtraction is modulo 2^192, so any borrow out (carry out) is lost. The +| result is broken into three 64-bit pieces which are stored at the locations +| pointed to by `z0Ptr', `z1Ptr', and `z2Ptr'. +*----------------------------------------------------------------------------*/ +#if defined INLINE_LEVEL && ( 3 <= INLINE_LEVEL ) +INLINE struct uint192 + softfloat_sub192( + uint64_t a128, + uint64_t a64, + uint64_t a0, + uint64_t b128, + uint64_t b64, + uint64_t b0 + ) +{ + struct uint192 z; + unsigned int borrow64, borrow128; + z.v0 = a0 - b0; + borrow64 = ( a0 < b0 ); + z.v64 = a64 - b64; + borrow128 = ( a64 < b64 ); + z.v128 = a128 - b128; + borrow128 += ( z.v64 < borrow64 ); + z.v64 -= borrow64; + z.v128 -= borrow128; + return z; +} +#else +struct uint192 + softfloat_sub192( + uint64_t, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t ); +#endif + +/*---------------------------------------------------------------------------- +| Multiplies `a' by `b' to obtain a 128-bit product. The product is broken +| into two 64-bit pieces which are stored at the locations pointed to by +| `z0Ptr' and `z1Ptr'. +*----------------------------------------------------------------------------*/ +#if defined INLINE_LEVEL && ( 4 <= INLINE_LEVEL ) +INLINE struct uint128 softfloat_mul64To128( uint64_t a, uint64_t b ) +{ + uint32_t a32 = a>>32; + uint32_t a0 = a; + uint32_t b32 = b>>32; + uint32_t b0 = b; + struct uint128 z; + uint64_t mid1, mid2, mid; + z.v0 = (uint64_t) a0 * b0; + mid1 = (uint64_t) a32 * b0; + mid2 = (uint64_t) a0 * b32; + z.v64 = (uint64_t) a32 * b32; + mid = mid1 + mid2; + z.v64 += ( (uint64_t) ( mid < mid1 ) )<<32 | mid>>32; + mid <<= 32; + z.v0 += mid; + z.v64 += ( z.v0 < mid ); + return z; +} +#else +struct uint128 softfloat_mul64To128( uint64_t, uint64_t ); +#endif + +/*---------------------------------------------------------------------------- +| Multiplies the 128-bit value formed by concatenating `a0' and `a1' by +| `b' to obtain a 192-bit product. The product is broken into three 64-bit +| pieces which are stored at the locations pointed to by `z0Ptr', `z1Ptr', and +| `z2Ptr'. +*----------------------------------------------------------------------------*/ +struct uint192 softfloat_mul128By64To192( uint64_t, uint64_t, uint64_t ); +/*---------------------------------------------------------------------------- +| Multiplies the 128-bit value formed by concatenating `a0' and `a1' to the +| 128-bit value formed by concatenating `b0' and `b1' to obtain a 256-bit +| product. The product is broken into four 64-bit pieces which are stored at +| the locations pointed to by `z0Ptr', `z1Ptr', `z2Ptr', and `z3Ptr'. +*----------------------------------------------------------------------------*/ +struct uint256 softfloat_mul128To256( uint64_t, uint64_t, uint64_t, uint64_t ); + +/*---------------------------------------------------------------------------- +| Returns an approximation to the 64-bit integer quotient obtained by dividing +| `b' into the 128-bit value formed by concatenating `a0' and `a1'. The +| divisor `b' must be at least 2^63. If q is the exact quotient truncated +| toward zero, the approximation returned lies between q and q + 2 inclusive. +| If the exact quotient q is larger than 64 bits, the maximum positive 64-bit +| unsigned integer is returned. +*----------------------------------------------------------------------------*/ +uint64_t softfloat_estimateDiv128To64( uint64_t, uint64_t, uint64_t ); + +/*---------------------------------------------------------------------------- +| Returns an approximation to the square root of the 32-bit significand given +| by `a'. Considered as an integer, `a' must be at least 2^31. If bit 0 of +| `aExp' (the least significant bit) is 1, the integer returned approximates +| 2^31*sqrt(`a'/2^31), where `a' is considered an integer. If bit 0 of `aExp' +| is 0, the integer returned approximates 2^31*sqrt(`a'/2^30). In either +| case, the approximation returned lies strictly within +/-2 of the exact +| value. +*----------------------------------------------------------------------------*/ +uint32_t softfloat_estimateSqrt32( unsigned int, uint32_t ); + diff --git a/softfloat/s_add128.c b/softfloat/s_add128.c new file mode 100755 index 0000000..59c0348 --- /dev/null +++ b/softfloat/s_add128.c @@ -0,0 +1,17 @@ + +#include +#include "platform.h" +#include "primitives.h" + +struct uint128 + softfloat_add128( uint64_t a64, uint64_t a0, uint64_t b64, uint64_t b0 ) +{ + struct uint128 z; + + z.v0 = a0 + b0; + z.v64 = a64 + b64; + z.v64 += ( z.v0 < a0 ); + return z; + +} + diff --git a/softfloat/s_add192.c b/softfloat/s_add192.c new file mode 100755 index 0000000..543eb5d --- /dev/null +++ b/softfloat/s_add192.c @@ -0,0 +1,30 @@ + +#include +#include "platform.h" +#include "primitives.h" + +struct uint192 + softfloat_add192( + uint64_t a128, + uint64_t a64, + uint64_t a0, + uint64_t b128, + uint64_t b64, + uint64_t b0 + ) +{ + struct uint192 z; + unsigned int carry64, carry128; + + z.v0 = a0 + b0; + carry64 = ( z.v0 < a0 ); + z.v64 = a64 + b64; + carry128 = ( z.v64 < a64 ); + z.v128 = a128 + b128; + z.v64 += carry64; + carry128 += ( z.v64 < carry64 ); + z.v128 += carry128; + return z; + +} + diff --git a/softfloat/s_addMagsF32.c b/softfloat/s_addMagsF32.c new file mode 100755 index 0000000..f361e2b --- /dev/null +++ b/softfloat/s_addMagsF32.c @@ -0,0 +1,75 @@ + +#include +#include +#include "platform.h" +#include "primitives.h" +#include "internals.h" +#include "specialize.h" + +float32_t + softfloat_addMagsF32( uint_fast32_t uiA, uint_fast32_t uiB, bool signZ ) +{ + int_fast16_t expA; + uint_fast32_t sigA; + int_fast16_t expB; + uint_fast32_t sigB; + int_fast16_t expDiff; + uint_fast32_t uiZ; + int_fast16_t expZ; + uint_fast32_t sigZ; + union ui32_f32 uZ; + + expA = expF32UI( uiA ); + sigA = fracF32UI( uiA ); + expB = expF32UI( uiB ); + sigB = fracF32UI( uiB ); + expDiff = expA - expB; + sigA <<= 6; + sigB <<= 6; + if ( ! expDiff ) { + if ( expA == 0xFF ) { + if ( sigA | sigB ) goto propagateNaN; + uiZ = uiA; + goto uiZ; + } + if ( ! expA ) { + uiZ = packToF32UI( signZ, 0, ( uiA + uiB ) & 0x7FFFFFFF ); + goto uiZ; + } + expZ = expA; + sigZ = 0x40000000 + sigA + sigB; + } else { + if ( expDiff < 0 ) { + if ( expB == 0xFF ) { + if ( sigB ) goto propagateNaN; + uiZ = packToF32UI( signZ, 0xFF, 0 ); + goto uiZ; + } + expZ = expB; + sigA += expA ? 0x20000000 : sigA; + sigA = softfloat_shift32RightJam( sigA, - expDiff ); + } else { + if ( expA == 0xFF ) { + if ( sigA ) goto propagateNaN; + uiZ = uiA; + goto uiZ; + } + expZ = expA; + sigB += expB ? 0x20000000 : sigB; + sigB = softfloat_shift32RightJam( sigB, expDiff ); + } + sigZ = 0x20000000 + sigA + sigB; + if ( sigZ < 0x40000000 ) { + --expZ; + sigZ <<= 1; + } + } + return softfloat_roundPackToF32( signZ, expZ, sigZ ); + propagateNaN: + uiZ = softfloat_propagateNaNF32UI( uiA, uiB ); + uiZ: + uZ.ui = uiZ; + return uZ.f; + +} + diff --git a/softfloat/s_addMagsF64.c b/softfloat/s_addMagsF64.c new file mode 100755 index 0000000..a81c3e4 --- /dev/null +++ b/softfloat/s_addMagsF64.c @@ -0,0 +1,77 @@ + +#include +#include +#include "platform.h" +#include "primitives.h" +#include "internals.h" +#include "specialize.h" + +float64_t + softfloat_addMagsF64( uint_fast64_t uiA, uint_fast64_t uiB, bool signZ ) +{ + int_fast16_t expA; + uint_fast64_t sigA; + int_fast16_t expB; + uint_fast64_t sigB; + int_fast16_t expDiff; + uint_fast64_t uiZ; + int_fast16_t expZ; + uint_fast64_t sigZ; + union ui64_f64 uZ; + + expA = expF64UI( uiA ); + sigA = fracF64UI( uiA ); + expB = expF64UI( uiB ); + sigB = fracF64UI( uiB ); + expDiff = expA - expB; + sigA <<= 9; + sigB <<= 9; + if ( ! expDiff ) { + if ( expA == 0x7FF ) { + if ( sigA | sigB ) goto propagateNaN; + uiZ = uiA; + goto uiZ; + } + if ( ! expA ) { + uiZ = + packToF64UI( + signZ, 0, ( uiA + uiB ) & UINT64_C( 0x7FFFFFFFFFFFFFFF ) ); + goto uiZ; + } + expZ = expA; + sigZ = UINT64_C( 0x4000000000000000 ) + sigA + sigB; + } else { + if ( expDiff < 0 ) { + if ( expB == 0x7FF ) { + if ( sigB ) goto propagateNaN; + uiZ = packToF64UI( signZ, 0x7FF, 0 ); + goto uiZ; + } + expZ = expB; + sigA += expA ? UINT64_C( 0x2000000000000000 ) : sigA; + sigA = softfloat_shift64RightJam( sigA, - expDiff ); + } else { + if ( expA == 0x7FF ) { + if ( sigA ) goto propagateNaN; + uiZ = uiA; + goto uiZ; + } + expZ = expA; + sigB += expB ? UINT64_C( 0x2000000000000000 ) : sigB; + sigB = softfloat_shift64RightJam( sigB, expDiff ); + } + sigZ = UINT64_C( 0x2000000000000000 ) + sigA + sigB; + if ( sigZ < UINT64_C( 0x4000000000000000 ) ) { + --expZ; + sigZ <<= 1; + } + } + return softfloat_roundPackToF64( signZ, expZ, sigZ ); + propagateNaN: + uiZ = softfloat_propagateNaNF64UI( uiA, uiB ); + uiZ: + uZ.ui = uiZ; + return uZ.f; + +} + diff --git a/softfloat/s_countLeadingZeros32.c b/softfloat/s_countLeadingZeros32.c new file mode 100755 index 0000000..0bd17e1 --- /dev/null +++ b/softfloat/s_countLeadingZeros32.c @@ -0,0 +1,22 @@ + +#include +#include "primitives.h" + +int softfloat_countLeadingZeros32( uint32_t a ) +{ + int count; + + count = 0; + if ( a < 0x10000 ) { + count = 16; + a <<= 16; + } + if ( a < 0x1000000 ) { + count += 8; + a <<= 8; + } + count += softfloat_countLeadingZeros8[ a>>24 ]; + return count; + +} + diff --git a/softfloat/s_countLeadingZeros64.c b/softfloat/s_countLeadingZeros64.c new file mode 100755 index 0000000..79f4280 --- /dev/null +++ b/softfloat/s_countLeadingZeros64.c @@ -0,0 +1,32 @@ + +#include +#include "primitives.h" +#include "platform.h" + +int softfloat_countLeadingZeros64( uint64_t a ) +{ + int count; + uint32_t a32; + + count = 32; + a32 = a; + if ( UINT64_C( 0x100000000 ) <= a ) { + count = 0; + a32 = a>>32; + } + /*------------------------------------------------------------------------ + | From here, result is current count + count leading zeros of `a32'. + *------------------------------------------------------------------------*/ + if ( a32 < 0x10000 ) { + count += 16; + a32 <<= 16; + } + if ( a32 < 0x1000000 ) { + count += 8; + a32 <<= 8; + } + count += softfloat_countLeadingZeros8[ a32>>24 ]; + return count; + +} + diff --git a/softfloat/s_countLeadingZeros8.c b/softfloat/s_countLeadingZeros8.c new file mode 100755 index 0000000..4eca7e9 --- /dev/null +++ b/softfloat/s_countLeadingZeros8.c @@ -0,0 +1,24 @@ + +#include +#include "platform.h" +#include "primitives.h" + +const uint8_t softfloat_countLeadingZeros8[ 256 ] = { + 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + diff --git a/softfloat/s_eq128.c b/softfloat/s_eq128.c new file mode 100755 index 0000000..7261dc4 --- /dev/null +++ b/softfloat/s_eq128.c @@ -0,0 +1,13 @@ + +#include +#include +#include "platform.h" +#include "primitives.h" + +bool softfloat_eq128( uint64_t a64, uint64_t a0, uint64_t b64, uint64_t b0 ) +{ + + return ( a64 == b64 ) && ( a0 == b0 ); + +} + diff --git a/softfloat/s_estimateDiv128To64.c b/softfloat/s_estimateDiv128To64.c new file mode 100755 index 0000000..f8610a2 --- /dev/null +++ b/softfloat/s_estimateDiv128To64.c @@ -0,0 +1,28 @@ + +#include +#include "platform.h" +#include "primitives.h" + +uint64_t softfloat_estimateDiv128To64( uint64_t a64, uint64_t a0, uint64_t b ) +{ + uint32_t b32; + uint64_t z; + struct uint128 term, rem; + uint64_t rem32; + + if ( b <= a64 ) return UINT64_C( 0xFFFFFFFFFFFFFFFF ); + b32 = b>>32; + z = ( (uint64_t) b32<<32 <= a64 ) ? UINT64_C( 0xFFFFFFFF00000000 ) + : ( a64 / b32 )<<32; + term = softfloat_mul64To128( b, z ); + rem = softfloat_sub128( a64, a0, term.v64, term.v0 ); + while ( UINT64_C( 0x8000000000000000 ) <= rem.v64 ) { + z -= UINT64_C( 0x100000000 ); + rem = softfloat_add128( rem.v64, rem.v0, b32, (uint64_t) ( b<<32 ) ); + } + rem32 = ( rem.v64<<32 ) | ( rem.v0>>32 ); + z |= ( (uint64_t) b32<<32 <= rem32 ) ? 0xFFFFFFFF : rem32 / b32; + return z; + +} + diff --git a/softfloat/s_estimateSqrt32.c b/softfloat/s_estimateSqrt32.c new file mode 100755 index 0000000..e22a9dc --- /dev/null +++ b/softfloat/s_estimateSqrt32.c @@ -0,0 +1,37 @@ + +#include +#include "platform.h" +#include "primitives.h" + +uint32_t softfloat_estimateSqrt32( unsigned int expA, uint32_t a ) +{ + static const uint16_t sqrtOddAdjustments[] = { + 0x0004, 0x0022, 0x005D, 0x00B1, 0x011D, 0x019F, 0x0236, 0x02E0, + 0x039C, 0x0468, 0x0545, 0x0631, 0x072B, 0x0832, 0x0946, 0x0A67 + }; + static const uint16_t sqrtEvenAdjustments[] = { + 0x0A2D, 0x08AF, 0x075A, 0x0629, 0x051A, 0x0429, 0x0356, 0x029E, + 0x0200, 0x0179, 0x0109, 0x00AF, 0x0068, 0x0034, 0x0012, 0x0002 + }; + int index; + uint32_t z; + union { uint32_t ui; int32_t i; } u32; + + index = ( a>>27 ) & 15; + if ( expA & 1 ) { + z = 0x4000 + ( a>>17 ) - sqrtOddAdjustments[ index ]; + z = ( ( a / z )<<14 ) + ( z<<15 ); + a >>= 1; + } else { + z = 0x8000 + ( a>>17 ) - sqrtEvenAdjustments[ index ]; + z = a / z + z; + z = ( 0x20000 <= z ) ? 0xFFFF8000 : z<<15; + if ( z <= a ) { + u32.ui = a; + return u32.i>>1; + } + } + return (uint32_t) ( ( (uint64_t) a<<31 ) / z ) + ( z>>1 ); + +} + diff --git a/softfloat/s_le128.c b/softfloat/s_le128.c new file mode 100755 index 0000000..83b1d7f --- /dev/null +++ b/softfloat/s_le128.c @@ -0,0 +1,13 @@ + +#include +#include +#include "platform.h" +#include "primitives.h" + +bool softfloat_le128( uint64_t a64, uint64_t a0, uint64_t b64, uint64_t b0 ) +{ + + return ( a64 < b64 ) || ( ( a64 == b64 ) && ( a0 <= b0 ) ); + +} + diff --git a/softfloat/s_lt128.c b/softfloat/s_lt128.c new file mode 100755 index 0000000..33a3df4 --- /dev/null +++ b/softfloat/s_lt128.c @@ -0,0 +1,13 @@ + +#include +#include +#include "platform.h" +#include "primitives.h" + +bool softfloat_lt128( uint64_t a64, uint64_t a0, uint64_t b64, uint64_t b0 ) +{ + + return ( a64 < b64 ) || ( ( a64 == b64 ) && ( a0 < b0 ) ); + +} + diff --git a/softfloat/s_mul128By64To192.c b/softfloat/s_mul128By64To192.c new file mode 100755 index 0000000..dfa8825 --- /dev/null +++ b/softfloat/s_mul128By64To192.c @@ -0,0 +1,20 @@ + +#include +#include "platform.h" +#include "primitives.h" + +struct uint192 + softfloat_mul128By64To192( uint64_t a64, uint64_t a0, uint64_t b ) +{ + struct uint128 p0, p64; + struct uint192 z; + + p0 = softfloat_mul64To128( a0, b ); + z.v0 = p0.v0; + p64 = softfloat_mul64To128( a64, b ); + z.v64 = p64.v0 + p0.v64; + z.v128 = p64.v64 + ( z.v64 < p64.v0 ); + return z; + +} + diff --git a/softfloat/s_mul128To256.c b/softfloat/s_mul128To256.c new file mode 100755 index 0000000..a96cd94 --- /dev/null +++ b/softfloat/s_mul128To256.c @@ -0,0 +1,28 @@ + +#include +#include "platform.h" +#include "primitives.h" + +struct uint256 + softfloat_mul128To256( uint64_t a64, uint64_t a0, uint64_t b64, uint64_t b0 ) +{ + struct uint128 p0, p64, p128; + struct uint256 z; + + p0 = softfloat_mul64To128( a0, b0 ); + z.v0 = p0.v0; + p64 = softfloat_mul64To128( a64, b0 ); + z.v64 = p64.v0 + p0.v64; + z.v128 = p64.v64 + ( z.v64 < p64.v0 ); + p128 = softfloat_mul64To128( a64, b64 ); + z.v128 += p128.v0; + z.v192 = p128.v64 + ( z.v128 < p128.v0 ); + p64 = softfloat_mul64To128( a0, b64 ); + z.v64 += p64.v0; + p64.v64 += ( z.v64 < p64.v0 ); + z.v128 += p64.v64; + z.v192 += ( z.v128 < p64.v64 ); + return z; + +} + diff --git a/softfloat/s_mul64To128.c b/softfloat/s_mul64To128.c new file mode 100755 index 0000000..c17780b --- /dev/null +++ b/softfloat/s_mul64To128.c @@ -0,0 +1,28 @@ + +#include +#include "platform.h" +#include "primitives.h" + +struct uint128 softfloat_mul64To128( uint64_t a, uint64_t b ) +{ + uint32_t a32, a0, b32, b0; + struct uint128 z; + uint64_t mid1, mid2, mid; + + a32 = a>>32; + a0 = a; + b32 = b>>32; + b0 = b; + z.v0 = (uint64_t) a0 * b0; + mid1 = (uint64_t) a32 * b0; + mid2 = (uint64_t) a0 * b32; + z.v64 = (uint64_t) a32 * b32; + mid = mid1 + mid2; + z.v64 += ( (uint64_t) ( mid < mid1 ) )<<32 | mid>>32; + mid <<= 32; + z.v0 += mid; + z.v64 += ( z.v0 < mid ); + return z; + +} + diff --git a/softfloat/s_mulAddF32.c b/softfloat/s_mulAddF32.c new file mode 100755 index 0000000..e55a0ba --- /dev/null +++ b/softfloat/s_mulAddF32.c @@ -0,0 +1,171 @@ + +#include +#include +#include "platform.h" +#include "primitives.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +float32_t + softfloat_mulAddF32( + int op, uint_fast32_t uiA, uint_fast32_t uiB, uint_fast32_t uiC ) +{ + bool signA; + int_fast16_t expA; + uint_fast32_t sigA; + bool signB; + int_fast16_t expB; + uint_fast32_t sigB; + bool signC; + int_fast16_t expC; + uint_fast32_t sigC; + bool signProd; + uint_fast32_t magBits, uiZ; + struct exp16_sig32 normExpSig; + int_fast16_t expProd; + uint_fast64_t sigProd; + bool signZ; + int_fast16_t expZ; + uint_fast32_t sigZ; + int_fast16_t expDiff; + uint_fast64_t sigZ64, sigC64; + int shiftCount; + union ui32_f32 uZ; + + signA = signF32UI( uiA ); + expA = expF32UI( uiA ); + sigA = fracF32UI( uiA ); + signB = signF32UI( uiB ); + expB = expF32UI( uiB ); + sigB = fracF32UI( uiB ); + signC = signF32UI( uiC ) ^ ( op == softfloat_mulAdd_subC ); + expC = expF32UI( uiC ); + sigC = fracF32UI( uiC ); + signProd = signA ^ signB ^ ( op == softfloat_mulAdd_subProd ); + if ( expA == 0xFF ) { + if ( sigA || ( ( expB == 0xFF ) && sigB ) ) goto propagateNaN_ABC; + magBits = expB | sigB; + goto infProdArg; + } + if ( expB == 0xFF ) { + if ( sigB ) goto propagateNaN_ABC; + magBits = expA | sigA; + goto infProdArg; + } + if ( expC == 0xFF ) { + if ( sigC ) { + uiZ = 0; + goto propagateNaN_ZC; + } + uiZ = uiC; + goto uiZ; + } + if ( ! expA ) { + if ( ! sigA ) goto zeroProd; + normExpSig = softfloat_normSubnormalF32Sig( sigA ); + expA = normExpSig.exp; + sigA = normExpSig.sig; + } + if ( ! expB ) { + if ( ! sigB ) goto zeroProd; + normExpSig = softfloat_normSubnormalF32Sig( sigB ); + expB = normExpSig.exp; + sigB = normExpSig.sig; + } + expProd = expA + expB - 0x7E; + sigA = ( sigA | 0x00800000 )<<7; + sigB = ( sigB | 0x00800000 )<<7; + sigProd = (uint_fast64_t) sigA * sigB; + if ( sigProd < UINT64_C( 0x2000000000000000 ) ) { + --expProd; + sigProd <<= 1; + } + signZ = signProd; + if ( ! expC ) { + if ( ! sigC ) { + expZ = expProd - 1; + sigZ = softfloat_shortShift64RightJam( sigProd, 31 ); + goto roundPack; + } + normExpSig = softfloat_normSubnormalF32Sig( sigC ); + expC = normExpSig.exp; + sigC = normExpSig.sig; + } + sigC = ( sigC | 0x00800000 )<<6; + expDiff = expProd - expC; + if ( signProd == signC ) { + if ( expDiff <= 0 ) { + expZ = expC; + sigZ = sigC + softfloat_shift64RightJam( sigProd, 32 - expDiff ); + } else { + expZ = expProd; + sigZ64 = + sigProd + + softfloat_shift64RightJam( + (uint_fast64_t) sigC<<32, expDiff ); + sigZ = softfloat_shortShift64RightJam( sigZ64, 32 ); + } + if ( sigZ < 0x40000000 ) { + --expZ; + sigZ <<= 1; + } + } else { +/*** OPTIMIZE BETTER? ***/ + sigC64 = (uint_fast64_t) sigC<<32; + if ( expDiff < 0 ) { + signZ = signC; + expZ = expC; + sigZ64 = sigC64 - softfloat_shift64RightJam( sigProd, - expDiff ); + } else if ( ! expDiff ) { + expZ = expProd; + sigZ64 = sigProd - sigC64; + if ( ! sigZ64 ) goto completeCancellation; + if ( sigZ64 & UINT64_C( 0x8000000000000000 ) ) { + signZ ^= 1; + sigZ64 = - sigZ64; + } + } else { + expZ = expProd; + sigZ64 = sigProd - softfloat_shift64RightJam( sigC64, expDiff ); + } + shiftCount = softfloat_countLeadingZeros64( sigZ64 ) - 1; + expZ -= shiftCount; + shiftCount -= 32; + if ( shiftCount < 0 ) { + sigZ = softfloat_shortShift64RightJam( sigZ64, - shiftCount ); + } else { + sigZ = (uint_fast32_t) sigZ64< +#include +#include "platform.h" +#include "primitives.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +float64_t + softfloat_mulAddF64( + int op, uint_fast64_t uiA, uint_fast64_t uiB, uint_fast64_t uiC ) +{ + bool signA; + int_fast16_t expA; + uint_fast64_t sigA; + bool signB; + int_fast16_t expB; + uint_fast64_t sigB; + bool signC; + int_fast16_t expC; + uint_fast64_t sigC; + bool signProd; + uint_fast64_t magBits, uiZ; + struct exp16_sig64 normExpSig; + int_fast16_t expProd; + struct uint128 sigProd; + bool signZ; + int_fast16_t expZ; + uint_fast64_t sigZ; + int_fast16_t expDiff; + struct uint128 sigC128, sigZ128; + int shiftCount; + union ui64_f64 uZ; + + signA = signF64UI( uiA ); + expA = expF64UI( uiA ); + sigA = fracF64UI( uiA ); + signB = signF64UI( uiB ); + expB = expF64UI( uiB ); + sigB = fracF64UI( uiB ); + signC = signF64UI( uiC ) ^ ( op == softfloat_mulAdd_subC ); + expC = expF64UI( uiC ); + sigC = fracF64UI( uiC ); + signProd = signA ^ signB ^ ( op == softfloat_mulAdd_subProd ); + if ( expA == 0x7FF ) { + if ( sigA || ( ( expB == 0x7FF ) && sigB ) ) goto propagateNaN_ABC; + magBits = expB | sigB; + goto infProdArg; + } + if ( expB == 0x7FF ) { + if ( sigB ) goto propagateNaN_ABC; + magBits = expA | sigA; + goto infProdArg; + } + if ( expC == 0x7FF ) { + if ( sigC ) { + uiZ = 0; + goto propagateNaN_ZC; + } + uiZ = uiC; + goto uiZ; + } + if ( ! expA ) { + if ( ! sigA ) goto zeroProd; + normExpSig = softfloat_normSubnormalF64Sig( sigA ); + expA = normExpSig.exp; + sigA = normExpSig.sig; + } + if ( ! expB ) { + if ( ! sigB ) goto zeroProd; + normExpSig = softfloat_normSubnormalF64Sig( sigB ); + expB = normExpSig.exp; + sigB = normExpSig.sig; + } + expProd = expA + expB - 0x3FE; + sigA = ( sigA | UINT64_C( 0x0010000000000000 ) )<<10; + sigB = ( sigB | UINT64_C( 0x0010000000000000 ) )<<10; + sigProd = softfloat_mul64To128( sigA, sigB ); + if ( sigProd.v64 < UINT64_C( 0x2000000000000000 ) ) { + --expProd; + sigProd = softfloat_shortShift128Left( sigProd.v64, sigProd.v0, 1 ); + } + signZ = signProd; + if ( ! expC ) { + if ( ! sigC ) { + expZ = expProd - 1; + sigZ = sigProd.v64<<1 | ( sigProd.v0 != 0 ); + goto roundPack; + } + normExpSig = softfloat_normSubnormalF64Sig( sigC ); + expC = normExpSig.exp; + sigC = normExpSig.sig; + } + sigC = ( sigC | UINT64_C( 0x0010000000000000 ) )<<9; + expDiff = expProd - expC; + if ( signProd == signC ) { + if ( expDiff <= 0 ) { + expZ = expC; + if ( expDiff ) { + sigProd.v64 = + softfloat_shift64RightJam( sigProd.v64, - expDiff ); + } + sigZ = ( sigC + sigProd.v64 ) | ( sigProd.v0 != 0 ); + } else { + expZ = expProd; + sigC128 = softfloat_shift128RightJam( sigC, 0, expDiff ); + sigZ128 = + softfloat_add128( + sigProd.v64, sigProd.v0, sigC128.v64, sigC128.v0 ); + sigZ = sigZ128.v64 | ( sigZ128.v0 != 0 ); + } + if ( sigZ < UINT64_C( 0x4000000000000000 ) ) { + --expZ; + sigZ <<= 1; + } + } else { +/*** OPTIMIZE BETTER? ***/ + if ( expDiff < 0 ) { + signZ = signC; + expZ = expC; + sigProd = + softfloat_shift128RightJam( + sigProd.v64, sigProd.v0, - expDiff ); + sigZ128 = softfloat_sub128( sigC, 0, sigProd.v64, sigProd.v0 ); + } else if ( ! expDiff ) { + expZ = expProd; + sigZ128 = softfloat_sub128( sigProd.v64, sigProd.v0, sigC, 0 ); + if ( ! ( sigZ128.v64 | sigZ128.v0 ) ) goto completeCancellation; + if ( sigZ128.v64 & UINT64_C( 0x8000000000000000 ) ) { + signZ ^= 1; + sigZ128 = softfloat_sub128( 0, 0, sigZ128.v64, sigZ128.v0 ); + } + } else { + expZ = expProd; + sigC128 = softfloat_shift128RightJam( sigC, 0, expDiff ); + sigZ128 = + softfloat_sub128( + sigProd.v64, sigProd.v0, sigC128.v64, sigC128.v0 ); + } + if ( ! sigZ128.v64 ) { + expZ -= 64; + sigZ128.v64 = sigZ128.v0; + sigZ128.v0 = 0; + } + shiftCount = softfloat_countLeadingZeros64( sigZ128.v64 ) - 1; + expZ -= shiftCount; + if ( shiftCount < 0 ) { + sigZ = softfloat_shortShift64RightJam( sigZ128.v64, - shiftCount ); + } else { + sigZ128 = + softfloat_shortShift128Left( + sigZ128.v64, sigZ128.v0, shiftCount ); + sigZ = sigZ128.v64; + } + sigZ |= ( sigZ128.v0 != 0 ); + } + roundPack: + return softfloat_roundPackToF64( signZ, expZ, sigZ ); + propagateNaN_ABC: + uiZ = softfloat_propagateNaNF64UI( uiA, uiB ); + goto propagateNaN_ZC; + infProdArg: + if ( magBits ) { + uiZ = packToF64UI( signProd, 0x7FF, 0 ); + if ( expC != 0x7FF ) goto uiZ; + if ( sigC ) goto propagateNaN_ZC; + if ( signProd == signC ) goto uiZ; + } + invalid: + softfloat_raiseFlags( softfloat_flag_invalid ); + uiZ = defaultNaNF64UI; + propagateNaN_ZC: + uiZ = softfloat_propagateNaNF64UI( uiZ, uiC ); + goto uiZ; + zeroProd: + uiZ = uiC; + if ( ! ( expC | sigC ) && ( signProd != signC ) ) { + completeCancellation: + uiZ = + packToF64UI( softfloat_roundingMode == softfloat_round_min, 0, 0 ); + } + uiZ: + uZ.ui = uiZ; + return uZ.f; + +} + diff --git a/softfloat/s_normRoundPackToF32.c b/softfloat/s_normRoundPackToF32.c new file mode 100755 index 0000000..2e6f4b0 --- /dev/null +++ b/softfloat/s_normRoundPackToF32.c @@ -0,0 +1,24 @@ + +#include +#include +#include "platform.h" +#include "primitives.h" +#include "internals.h" + +float32_t + softfloat_normRoundPackToF32( bool sign, int_fast16_t exp, uint_fast32_t sig ) +{ + int shiftCount; + union ui32_f32 uZ; + + shiftCount = softfloat_countLeadingZeros32( sig ) - 1; + exp -= shiftCount; + if ( ( 7 <= shiftCount ) && ( (uint16_t) exp < 0xFD ) ) { + uZ.ui = packToF32UI( sign, sig ? exp : 0, sig<<( shiftCount - 7 ) ); + return uZ.f; + } else { + return softfloat_roundPackToF32( sign, exp, sig< +#include +#include "platform.h" +#include "primitives.h" +#include "internals.h" + +float64_t + softfloat_normRoundPackToF64( bool sign, int_fast16_t exp, uint_fast64_t sig ) +{ + int shiftCount; + union ui64_f64 uZ; + + shiftCount = softfloat_countLeadingZeros64( sig ) - 1; + exp -= shiftCount; + if ( ( 10 <= shiftCount ) && ( (uint16_t) exp < 0x7FD ) ) { + uZ.ui = packToF64UI( sign, sig ? exp : 0, sig<<( shiftCount - 10 ) ); + return uZ.f; + } else { + return softfloat_roundPackToF64( sign, exp, sig< +#include "platform.h" +#include "primitives.h" +#include "internals.h" + +struct exp16_sig32 softfloat_normSubnormalF32Sig( uint_fast32_t sig ) +{ + int shiftCount; + struct exp16_sig32 z; + + shiftCount = softfloat_countLeadingZeros32( sig ) - 8; + z.exp = 1 - shiftCount; + z.sig = sig< +#include "platform.h" +#include "primitives.h" +#include "internals.h" + +struct exp16_sig64 softfloat_normSubnormalF64Sig( uint_fast64_t sig ) +{ + int shiftCount; + struct exp16_sig64 z; + + shiftCount = softfloat_countLeadingZeros64( sig ) - 11; + z.exp = 1 - shiftCount; + z.sig = sig< +#include +#include "platform.h" +#include "primitives.h" +#include "internals.h" +#include "softfloat.h" + +float32_t + softfloat_roundPackToF32( bool sign, int_fast16_t exp, uint_fast32_t sig ) +{ + int roundingMode; + bool roundNearestEven; + int roundIncrement, roundBits; + bool isTiny; + uint_fast32_t uiZ; + union ui32_f32 uZ; + + roundingMode = softfloat_roundingMode; + roundNearestEven = ( roundingMode == softfloat_round_nearest_even ); + roundIncrement = 0x40; + if ( + ! roundNearestEven + && ( roundingMode != softfloat_round_nearest_maxMag ) + ) { + roundIncrement = + ( roundingMode == softfloat_round_minMag ) + || ( roundingMode + == ( sign ? softfloat_round_max : softfloat_round_min ) ) + ? 0 + : 0x7F; + } + roundBits = sig & 0x7F; + if ( 0xFD <= (uint16_t) exp ) { + if ( exp < 0 ) { + isTiny = + ( softfloat_detectTininess + == softfloat_tininess_beforeRounding ) + || ( exp < -1 ) + || ( sig + roundIncrement < 0x80000000 ); + sig = softfloat_shift32RightJam( sig, - exp ); + exp = 0; + roundBits = sig & 0x7F; + if ( isTiny && roundBits ) { + softfloat_raiseFlags( softfloat_flag_underflow ); + } + } else if ( + ( 0xFD < exp ) || ( 0x80000000 <= sig + roundIncrement ) + ) { + softfloat_raiseFlags( + softfloat_flag_overflow | softfloat_flag_inexact ); + uiZ = packToF32UI( sign, 0xFF, 0 ) - ! roundIncrement; + goto uiZ; + } + } + if ( roundBits ) softfloat_exceptionFlags |= softfloat_flag_inexact; + sig = ( sig + roundIncrement )>>7; + sig &= ~ ( ! ( roundBits ^ 0x40 ) & roundNearestEven ); + uiZ = packToF32UI( sign, sig ? exp : 0, sig ); + uiZ: + uZ.ui = uiZ; + return uZ.f; + +} + diff --git a/softfloat/s_roundPackToF64.c b/softfloat/s_roundPackToF64.c new file mode 100755 index 0000000..fb0ef1d --- /dev/null +++ b/softfloat/s_roundPackToF64.c @@ -0,0 +1,66 @@ + +#include +#include +#include "platform.h" +#include "primitives.h" +#include "internals.h" +#include "softfloat.h" + +float64_t + softfloat_roundPackToF64( bool sign, int_fast16_t exp, uint_fast64_t sig ) +{ + int roundingMode; + bool roundNearestEven; + int roundIncrement, roundBits; + bool isTiny; + uint_fast64_t uiZ; + union ui64_f64 uZ; + + roundingMode = softfloat_roundingMode; + roundNearestEven = ( roundingMode == softfloat_round_nearest_even ); + roundIncrement = 0x200; + if ( + ! roundNearestEven + && ( roundingMode != softfloat_round_nearest_maxMag ) + ) { + roundIncrement = + ( roundingMode == softfloat_round_minMag ) + || ( roundingMode + == ( sign ? softfloat_round_max : softfloat_round_min ) ) + ? 0 + : 0x3FF; + } + roundBits = sig & 0x3FF; + if ( 0x7FD <= (uint16_t) exp ) { + if ( exp < 0 ) { + isTiny = + ( softfloat_detectTininess + == softfloat_tininess_beforeRounding ) + || ( exp < -1 ) + || ( sig + roundIncrement < UINT64_C( 0x8000000000000000 ) ); + sig = softfloat_shift64RightJam( sig, - exp ); + exp = 0; + roundBits = sig & 0x3FF; + if ( isTiny && roundBits ) { + softfloat_raiseFlags( softfloat_flag_underflow ); + } + } else if ( + ( 0x7FD < exp ) + || ( UINT64_C( 0x8000000000000000 ) <= sig + roundIncrement ) + ) { + softfloat_raiseFlags( + softfloat_flag_overflow | softfloat_flag_inexact ); + uiZ = packToF64UI( sign, 0x7FF, 0 ) - ! roundIncrement; + goto uiZ; + } + } + if ( roundBits ) softfloat_exceptionFlags |= softfloat_flag_inexact; + sig = ( sig + roundIncrement )>>10; + sig &= ~ ( ! ( roundBits ^ 0x200 ) & roundNearestEven ); + uiZ = packToF64UI( sign, sig ? exp : 0, sig ); + uiZ: + uZ.ui = uiZ; + return uZ.f; + +} + diff --git a/softfloat/s_roundPackToI32.c b/softfloat/s_roundPackToI32.c new file mode 100755 index 0000000..1c91497 --- /dev/null +++ b/softfloat/s_roundPackToI32.c @@ -0,0 +1,48 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" + +int_fast32_t + softfloat_roundPackToI32( + bool sign, uint_fast64_t sig, int_fast8_t roundingMode, bool exact ) +{ + bool roundNearestEven; + int roundIncrement, roundBits; + uint_fast32_t sig32; + union { uint32_t ui; int32_t i; } uZ; + int_fast32_t z; + + roundNearestEven = ( roundingMode == softfloat_round_nearest_even ); + roundIncrement = 0x40; + if ( + ! roundNearestEven + && ( roundingMode != softfloat_round_nearest_maxMag ) + ) { + roundIncrement = + ( roundingMode == softfloat_round_minMag ) + || ( roundingMode + == ( sign ? softfloat_round_max : softfloat_round_min ) ) + ? 0 + : 0x7F; + } + roundBits = sig & 0x7F; + sig += roundIncrement; + if ( sig & UINT64_C( 0xFFFFFF8000000000 ) ) goto invalid; + sig32 = sig>>7; + sig32 &= ~ ( ! ( roundBits ^ 0x40 ) & roundNearestEven ); + uZ.ui = sign ? - sig32 : sig32; + z = uZ.i; + if ( z && ( ( z < 0 ) ^ sign ) ) goto invalid; + if ( exact && roundBits ) { + softfloat_exceptionFlags |= softfloat_flag_inexact; + } + return z; + invalid: + softfloat_raiseFlags( softfloat_flag_invalid ); + return sign ? -0x7FFFFFFF - 1 : 0x7FFFFFFF; + +} + diff --git a/softfloat/s_roundPackToI64.c b/softfloat/s_roundPackToI64.c new file mode 100755 index 0000000..b2f5d63 --- /dev/null +++ b/softfloat/s_roundPackToI64.c @@ -0,0 +1,52 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" + +int_fast64_t + softfloat_roundPackToI64( + bool sign, + uint_fast64_t sig64, + uint_fast64_t sig0, + int_fast8_t roundingMode, + bool exact + ) +{ + bool roundNearestEven, increment; + union { uint64_t ui; int64_t i; } uZ; + int_fast64_t z; + + roundNearestEven = ( roundingMode == softfloat_round_nearest_even ); + increment = ( UINT64_C( 0x8000000000000000 ) <= sig0 ); + if ( + ! roundNearestEven + && ( roundingMode != softfloat_round_nearest_maxMag ) + ) { + increment = + ( roundingMode != softfloat_round_minMag ) + && ( roundingMode + == ( sign ? softfloat_round_min : softfloat_round_max ) ) + && sig0; + } + if ( increment ) { + ++sig64; + if ( ! sig64 ) goto invalid; + sig64 &= + ~ ( ! ( sig0 & UINT64_C( 0x7FFFFFFFFFFFFFFF ) ) + & roundNearestEven ); + } + uZ.ui = sign ? - sig64 : sig64; + z = uZ.i; + if ( z && ( ( z < 0 ) ^ sign ) ) goto invalid; + if ( exact && sig0 ) softfloat_exceptionFlags |= softfloat_flag_inexact; + return z; + invalid: + softfloat_raiseFlags( softfloat_flag_invalid ); + return + sign ? - INT64_C( 0x7FFFFFFFFFFFFFFF ) - 1 + : INT64_C( 0x7FFFFFFFFFFFFFFF ); + +} + diff --git a/softfloat/s_roundPackToUI32.c b/softfloat/s_roundPackToUI32.c new file mode 100755 index 0000000..ab44ec7 --- /dev/null +++ b/softfloat/s_roundPackToUI32.c @@ -0,0 +1,44 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" + +uint_fast32_t + softfloat_roundPackToUI32( + bool sign, uint_fast64_t sig, int_fast8_t roundingMode, bool exact ) +{ + bool roundNearestEven; + int roundIncrement, roundBits; + uint_fast32_t z; + + roundNearestEven = ( roundingMode == softfloat_round_nearest_even ); + roundIncrement = 0x40; + if ( + ! roundNearestEven + && ( roundingMode != softfloat_round_nearest_maxMag ) + ) { + roundIncrement = + ( roundingMode == softfloat_round_minMag ) + || ( roundingMode + == ( sign ? softfloat_round_max : softfloat_round_min ) ) + ? 0 + : 0x7F; + } + roundBits = sig & 0x7F; + sig += roundIncrement; + if ( sig & UINT64_C( 0xFFFFFF8000000000 ) ) goto invalid; + z = sig>>7; + z &= ~ ( ! ( roundBits ^ 0x40 ) & roundNearestEven ); + if ( sign && z ) goto invalid; + if ( exact && roundBits ) { + softfloat_exceptionFlags |= softfloat_flag_inexact; + } + return z; + invalid: + softfloat_raiseFlags( softfloat_flag_invalid ); + return 0xFFFFFFFF; + +} + diff --git a/softfloat/s_roundPackToUI64.c b/softfloat/s_roundPackToUI64.c new file mode 100755 index 0000000..d42266f --- /dev/null +++ b/softfloat/s_roundPackToUI64.c @@ -0,0 +1,46 @@ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" + +uint_fast64_t + softfloat_roundPackToUI64( + bool sign, + uint_fast64_t sig64, + uint_fast64_t sig0, + int_fast8_t roundingMode, + bool exact + ) +{ + bool roundNearestEven, increment; + + roundNearestEven = ( roundingMode == softfloat_round_nearest_even ); + increment = ( UINT64_C( 0x8000000000000000 ) <= sig0 ); + if ( + ! roundNearestEven + && ( roundingMode != softfloat_round_nearest_maxMag ) + ) { + increment = + ( roundingMode != softfloat_round_minMag ) + && ( roundingMode + == ( sign ? softfloat_round_min : softfloat_round_max ) ) + && sig0; + } + if ( increment ) { + ++sig64; + if ( ! sig64 ) goto invalid; + sig64 &= + ~ ( ! ( sig0 & UINT64_C( 0x7FFFFFFFFFFFFFFF ) ) + & roundNearestEven ); + } + if ( sign && sig64 ) goto invalid; + if ( exact && sig0 ) softfloat_exceptionFlags |= softfloat_flag_inexact; + return sig64; + invalid: + softfloat_raiseFlags( softfloat_flag_invalid ); + return UINT64_C( 0xFFFFFFFFFFFFFFFF ); + +} + diff --git a/softfloat/s_shift128ExtraRightJam.c b/softfloat/s_shift128ExtraRightJam.c new file mode 100755 index 0000000..6c57974 --- /dev/null +++ b/softfloat/s_shift128ExtraRightJam.c @@ -0,0 +1,38 @@ + +#include +#include "platform.h" +#include "primitives.h" + +struct uint128_extra + softfloat_shift128ExtraRightJam( + uint64_t a64, uint64_t a0, uint64_t extra, unsigned int count ) +{ + unsigned int negCount; + struct uint128_extra z; + + negCount = - count; + if ( count < 64 ) { + z.v64 = a64>>count; + z.v0 = a64<<( negCount & 63 ) | a0>>count; + z.extra = a0<<( negCount & 63 ); + } else { + z.v64 = 0; + if ( count == 64 ) { + z.v0 = a64; + z.extra = a0; + } else { + extra |= a0; + if ( count < 128 ) { + z.v0 = a64>>( count & 63 ); + z.extra = a64<<( negCount & 63 ); + } else { + z.v0 = 0; + z.extra = ( count == 128 ) ? a64 : ( a64 != 0 ); + } + } + } + z.extra |= ( extra != 0 ); + return z; + +} + diff --git a/softfloat/s_shift128RightJam.c b/softfloat/s_shift128RightJam.c new file mode 100755 index 0000000..5a4e188 --- /dev/null +++ b/softfloat/s_shift128RightJam.c @@ -0,0 +1,31 @@ + +#include +#include "platform.h" +#include "primitives.h" + +struct uint128 + softfloat_shift128RightJam( uint64_t a64, uint64_t a0, unsigned int count ) +{ + unsigned int negCount; + struct uint128 z; + + if ( count < 64 ) { + negCount = - count; + z.v64 = a64>>( count & 63 ); + z.v0 = + a64<<( negCount & 63 ) | a0>>count + | ( (uint64_t) ( a0<<( negCount & 63 ) ) != 0 ); + } else { + z.v64 = 0; + z.v0 = + ( count < 128 ) + ? a64>>( count & 63 ) + | ( ( ( a64 & ( ( (uint64_t) 1<<( count & 63 ) ) - 1 ) ) + | a0 ) + != 0 ) + : ( ( a64 | a0 ) != 0 ); + } + return z; + +} + diff --git a/softfloat/s_shift32RightJam.c b/softfloat/s_shift32RightJam.c new file mode 100755 index 0000000..b697a34 --- /dev/null +++ b/softfloat/s_shift32RightJam.c @@ -0,0 +1,15 @@ + +#include +#include "platform.h" +#include "primitives.h" + +uint32_t softfloat_shift32RightJam( uint32_t a, unsigned int count ) +{ + + return + ( count < 32 ) + ? a>>count | ( (uint32_t) ( a<<( ( - count ) & 31 ) ) != 0 ) + : ( a != 0 ); + +} + diff --git a/softfloat/s_shift64ExtraRightJam.c b/softfloat/s_shift64ExtraRightJam.c new file mode 100755 index 0000000..167ea54 --- /dev/null +++ b/softfloat/s_shift64ExtraRightJam.c @@ -0,0 +1,23 @@ + +#include +#include "platform.h" +#include "primitives.h" + +struct uint64_extra + softfloat_shift64ExtraRightJam( + uint64_t a, uint64_t extra, unsigned int count ) +{ + struct uint64_extra z; + + if ( count < 64 ) { + z.v = a>>count; + z.extra = a<<( ( - count ) & 63 ); + } else { + z.v = 0; + z.extra = ( count == 64 ) ? a : ( a != 0 ); + } + z.extra |= ( extra != 0 ); + return z; + +} + diff --git a/softfloat/s_shift64RightJam.c b/softfloat/s_shift64RightJam.c new file mode 100755 index 0000000..ebebb61 --- /dev/null +++ b/softfloat/s_shift64RightJam.c @@ -0,0 +1,15 @@ + +#include +#include "platform.h" +#include "primitives.h" + +uint64_t softfloat_shift64RightJam( uint64_t a, unsigned int count ) +{ + + return + ( count < 64 ) + ? a>>count | ( (uint64_t) ( a<<( ( - count ) & 63 ) ) != 0 ) + : ( a != 0 ); + +} + diff --git a/softfloat/s_shortShift128ExtraRightJam.c b/softfloat/s_shortShift128ExtraRightJam.c new file mode 100755 index 0000000..c772740 --- /dev/null +++ b/softfloat/s_shortShift128ExtraRightJam.c @@ -0,0 +1,20 @@ + +#include +#include "platform.h" +#include "primitives.h" + +struct uint128_extra + softfloat_shortShift128ExtraRightJam( + uint64_t a64, uint64_t a0, uint64_t extra, unsigned int count ) +{ + unsigned int negCount; + struct uint128_extra z; + + negCount = - count; + z.v64 = a64>>count; + z.v0 = a64<<( negCount & 63 ) | a0>>count; + z.extra = a0<<( negCount & 63 ) | ( extra != 0 ); + return z; + +} + diff --git a/softfloat/s_shortShift128Left.c b/softfloat/s_shortShift128Left.c new file mode 100755 index 0000000..9c29988 --- /dev/null +++ b/softfloat/s_shortShift128Left.c @@ -0,0 +1,16 @@ + +#include +#include "platform.h" +#include "primitives.h" + +struct uint128 + softfloat_shortShift128Left( uint64_t a64, uint64_t a0, unsigned int count ) +{ + struct uint128 z; + + z.v64 = a64<>( ( - count ) & 63 ); + z.v0 = a0< +#include "platform.h" +#include "primitives.h" + +struct uint128 + softfloat_shortShift128Right( uint64_t a64, uint64_t a0, unsigned int count ) +{ + struct uint128 z; + + z.v64 = a64>>count; + z.v0 = a64<<( ( - count ) & 63 ) | a0>>count; + return z; + +} + diff --git a/softfloat/s_shortShift192Left.c b/softfloat/s_shortShift192Left.c new file mode 100755 index 0000000..cf1e55d --- /dev/null +++ b/softfloat/s_shortShift192Left.c @@ -0,0 +1,20 @@ + +#include +#include "platform.h" +#include "primitives.h" + +struct uint192 + softfloat_shortShift192Left( + uint64_t a128, uint64_t a64, uint64_t a0, unsigned int count ) +{ + unsigned int negCount; + struct uint192 z; + + negCount = - count; + z.v128 = a128<>( negCount & 63 ); + z.v64 = a64<>( negCount & 63 ); + z.v0 = a0< +#include "platform.h" +#include "primitives.h" + +uint32_t softfloat_shortShift32Right1Jam( uint32_t a ) +{ + + return a>>1 | ( a & 1 ); + +} + diff --git a/softfloat/s_shortShift64ExtraRightJam.c b/softfloat/s_shortShift64ExtraRightJam.c new file mode 100755 index 0000000..b861c67 --- /dev/null +++ b/softfloat/s_shortShift64ExtraRightJam.c @@ -0,0 +1,17 @@ + +#include +#include "platform.h" +#include "primitives.h" + +struct uint64_extra + softfloat_shortShift64ExtraRightJam( + uint64_t a, uint64_t extra, unsigned int count ) +{ + struct uint64_extra z; + + z.v = a>>count; + z.extra = a<<( ( - count ) & 63 ) | ( extra != 0 ); + return z; + +} + diff --git a/softfloat/s_shortShift64RightJam.c b/softfloat/s_shortShift64RightJam.c new file mode 100755 index 0000000..0da6c93 --- /dev/null +++ b/softfloat/s_shortShift64RightJam.c @@ -0,0 +1,12 @@ + +#include +#include "platform.h" +#include "primitives.h" + +uint64_t softfloat_shortShift64RightJam( uint64_t a, unsigned int count ) +{ + + return a>>count | ( ( a & ( ( (uint64_t) 1< +#include "platform.h" +#include "primitives.h" + +struct uint128 + softfloat_sub128( uint64_t a64, uint64_t a0, uint64_t b64, uint64_t b0 ) +{ + struct uint128 z; + + z.v0 = a0 - b0; + z.v64 = a64 - b64; + z.v64 -= ( a0 < b0 ); + return z; + +} + diff --git a/softfloat/s_sub192.c b/softfloat/s_sub192.c new file mode 100755 index 0000000..96f21c9 --- /dev/null +++ b/softfloat/s_sub192.c @@ -0,0 +1,30 @@ + +#include +#include "platform.h" +#include "primitives.h" + +struct uint192 + softfloat_sub192( + uint64_t a128, + uint64_t a64, + uint64_t a0, + uint64_t b128, + uint64_t b64, + uint64_t b0 + ) +{ + struct uint192 z; + unsigned int borrow64, borrow128; + + z.v0 = a0 - b0; + borrow64 = ( a0 < b0 ); + z.v64 = a64 - b64; + borrow128 = ( a64 < b64 ); + z.v128 = a128 - b128; + borrow128 += ( z.v64 < borrow64 ); + z.v64 -= borrow64; + z.v128 -= borrow128; + return z; + +} + diff --git a/softfloat/s_subMagsF32.c b/softfloat/s_subMagsF32.c new file mode 100755 index 0000000..0c83b02 --- /dev/null +++ b/softfloat/s_subMagsF32.c @@ -0,0 +1,81 @@ + +#include +#include +#include "platform.h" +#include "primitives.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +float32_t + softfloat_subMagsF32( uint_fast32_t uiA, uint_fast32_t uiB, bool signZ ) +{ + int_fast16_t expA; + uint_fast32_t sigA; + int_fast16_t expB; + uint_fast32_t sigB; + int_fast16_t expDiff; + uint_fast32_t uiZ; + int_fast16_t expZ; + uint_fast32_t sigZ; + union ui32_f32 uZ; + + expA = expF32UI( uiA ); + sigA = fracF32UI( uiA ); + expB = expF32UI( uiB ); + sigB = fracF32UI( uiB ); + expDiff = expA - expB; + sigA <<= 7; + sigB <<= 7; + if ( 0 < expDiff ) goto expABigger; + if ( expDiff < 0 ) goto expBBigger; + if ( expA == 0xFF ) { + if ( sigA | sigB ) goto propagateNaN; + softfloat_raiseFlags( softfloat_flag_invalid ); + uiZ = defaultNaNF32UI; + goto uiZ; + } + if ( ! expA ) { + expA = 1; + expB = 1; + } + if ( sigB < sigA ) goto aBigger; + if ( sigA < sigB ) goto bBigger; + uiZ = packToF32UI( softfloat_roundingMode == softfloat_round_min, 0, 0 ); + goto uiZ; + expBBigger: + if ( expB == 0xFF ) { + if ( sigB ) goto propagateNaN; + uiZ = packToF32UI( signZ ^ 1, 0xFF, 0 ); + goto uiZ; + } + sigA += expA ? 0x40000000 : sigA; + sigA = softfloat_shift32RightJam( sigA, - expDiff ); + sigB |= 0x40000000; + bBigger: + signZ ^= 1; + expZ = expB; + sigZ = sigB - sigA; + goto normRoundPack; + expABigger: + if ( expA == 0xFF ) { + if ( sigA ) goto propagateNaN; + uiZ = uiA; + goto uiZ; + } + sigB += expB ? 0x40000000 : sigB; + sigB = softfloat_shift32RightJam( sigB, expDiff ); + sigA |= 0x40000000; + aBigger: + expZ = expA; + sigZ = sigA - sigB; + normRoundPack: + return softfloat_normRoundPackToF32( signZ, expZ - 1, sigZ ); + propagateNaN: + uiZ = softfloat_propagateNaNF32UI( uiA, uiB ); + uiZ: + uZ.ui = uiZ; + return uZ.f; + +} + diff --git a/softfloat/s_subMagsF64.c b/softfloat/s_subMagsF64.c new file mode 100755 index 0000000..45b81ba --- /dev/null +++ b/softfloat/s_subMagsF64.c @@ -0,0 +1,81 @@ + +#include +#include +#include "platform.h" +#include "primitives.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +float64_t + softfloat_subMagsF64( uint_fast64_t uiA, uint_fast64_t uiB, bool signZ ) +{ + int_fast16_t expA; + uint_fast64_t sigA; + int_fast16_t expB; + uint_fast64_t sigB; + int_fast16_t expDiff; + uint_fast64_t uiZ; + int_fast16_t expZ; + uint_fast64_t sigZ; + union ui64_f64 uZ; + + expA = expF64UI( uiA ); + sigA = fracF64UI( uiA ); + expB = expF64UI( uiB ); + sigB = fracF64UI( uiB ); + expDiff = expA - expB; + sigA <<= 10; + sigB <<= 10; + if ( 0 < expDiff ) goto expABigger; + if ( expDiff < 0 ) goto expBBigger; + if ( expA == 0x7FF ) { + if ( sigA | sigB ) goto propagateNaN; + softfloat_raiseFlags( softfloat_flag_invalid ); + uiZ = defaultNaNF64UI; + goto uiZ; + } + if ( ! expA ) { + expA = 1; + expB = 1; + } + if ( sigB < sigA ) goto aBigger; + if ( sigA < sigB ) goto bBigger; + uiZ = packToF64UI( softfloat_roundingMode == softfloat_round_min, 0, 0 ); + goto uiZ; + expBBigger: + if ( expB == 0x7FF ) { + if ( sigB ) goto propagateNaN; + uiZ = packToF64UI( signZ ^ 1, 0x7FF, 0 ); + goto uiZ; + } + sigA += expA ? UINT64_C( 0x4000000000000000 ) : sigA; + sigA = softfloat_shift64RightJam( sigA, - expDiff ); + sigB |= UINT64_C( 0x4000000000000000 ); + bBigger: + signZ ^= 1; + expZ = expB; + sigZ = sigB - sigA; + goto normRoundPack; + expABigger: + if ( expA == 0x7FF ) { + if ( sigA ) goto propagateNaN; + uiZ = uiA; + goto uiZ; + } + sigB += expB ? UINT64_C( 0x4000000000000000 ) : sigB; + sigB = softfloat_shift64RightJam( sigB, expDiff ); + sigA |= UINT64_C( 0x4000000000000000 ); + aBigger: + expZ = expA; + sigZ = sigA - sigB; + normRoundPack: + return softfloat_normRoundPackToF64( signZ, expZ - 1, sigZ ); + propagateNaN: + uiZ = softfloat_propagateNaNF64UI( uiA, uiB ); + uiZ: + uZ.ui = uiZ; + return uZ.f; + +} + diff --git a/softfloat/softfloat.ac b/softfloat/softfloat.ac new file mode 100644 index 0000000..e69de29 diff --git a/softfloat/softfloat.h b/softfloat/softfloat.h new file mode 100755 index 0000000..3eddeed --- /dev/null +++ b/softfloat/softfloat.h @@ -0,0 +1,233 @@ + +#ifndef softfloat_h +#define softfloat_h + +#ifdef __cplusplus +extern "C" { +#endif + +/*** UPDATE COMMENTS. ***/ + +/*============================================================================ + +This C header file is part of the SoftFloat IEEE Floating-point Arithmetic +Package, Release 2b. + +Written by John R. Hauser. This work was made possible in part by the +International Computer Science Institute, located at Suite 600, 1947 Center +Street, Berkeley, California 94704. Funding was partially provided by the +National Science Foundation under grant MIP-9311980. The original version +of this code was written as part of a project to build a fixed-point vector +processor in collaboration with the University of California at Berkeley, +overseen by Profs. Nelson Morgan and John Wawrzynek. More information +is available through the Web page `http://www.cs.berkeley.edu/~jhauser/ +arithmetic/SoftFloat.html'. + +THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has +been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES +RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS +AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES, +COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE +EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE +INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR +OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE. + +Derivative works are acceptable, even for commercial purposes, so long as +(1) the source code for the derivative work includes prominent notice that +the work is derivative, and (2) the source code includes prominent notice with +these four paragraphs for those parts of this code that are retained. + +=============================================================================*/ + +#include "softfloat_types.h" + +/*---------------------------------------------------------------------------- +| Software floating-point underflow tininess-detection mode. +*----------------------------------------------------------------------------*/ +extern int_fast8_t softfloat_detectTininess; +enum { + softfloat_tininess_beforeRounding = 0, + softfloat_tininess_afterRounding = 1 +}; + +/*---------------------------------------------------------------------------- +| Software floating-point rounding mode. +*----------------------------------------------------------------------------*/ +extern int_fast8_t softfloat_roundingMode; +enum { + softfloat_round_nearest_even = 0, + softfloat_round_minMag = 1, + softfloat_round_min = 2, + softfloat_round_max = 3, + softfloat_round_nearest_maxMag = 4 +}; + +/*---------------------------------------------------------------------------- +| Software floating-point exception flags. +*----------------------------------------------------------------------------*/ +extern int_fast8_t softfloat_exceptionFlags; +enum { + softfloat_flag_inexact = 1, + softfloat_flag_underflow = 2, + softfloat_flag_overflow = 4, + softfloat_flag_infinity = 8, + softfloat_flag_invalid = 16 +}; + +/*---------------------------------------------------------------------------- +| Routine to raise any or all of the software floating-point exception flags. +*----------------------------------------------------------------------------*/ +void softfloat_raiseFlags( int_fast8_t ); + +/*---------------------------------------------------------------------------- +| Integer-to-floating-point conversion routines. +*----------------------------------------------------------------------------*/ +float32_t ui32_to_f32( uint_fast32_t ); +float64_t ui32_to_f64( uint_fast32_t ); +floatx80_t ui32_to_fx80( uint_fast32_t ); +float128_t ui32_to_f128( uint_fast32_t ); +float32_t ui64_to_f32( uint_fast64_t ); +float64_t ui64_to_f64( uint_fast64_t ); +floatx80_t ui64_to_fx80( uint_fast64_t ); +float128_t ui64_to_f128( uint_fast64_t ); +float32_t i32_to_f32( int_fast32_t ); +float64_t i32_to_f64( int_fast32_t ); +floatx80_t i32_to_fx80( int_fast32_t ); +float128_t i32_to_f128( int_fast32_t ); +float32_t i64_to_f32( int_fast64_t ); +float64_t i64_to_f64( int_fast64_t ); +floatx80_t i64_to_fx80( int_fast64_t ); +float128_t i64_to_f128( int_fast64_t ); + +/*---------------------------------------------------------------------------- +| 32-bit (single-precision) floating-point operations. +*----------------------------------------------------------------------------*/ +uint_fast32_t f32_to_ui32( float32_t, int_fast8_t, bool ); +uint_fast64_t f32_to_ui64( float32_t, int_fast8_t, bool ); +int_fast32_t f32_to_i32( float32_t, int_fast8_t, bool ); +int_fast64_t f32_to_i64( float32_t, int_fast8_t, bool ); +uint_fast32_t f32_to_ui32_r_minMag( float32_t, bool ); +uint_fast64_t f32_to_ui64_r_minMag( float32_t, bool ); +int_fast32_t f32_to_i32_r_minMag( float32_t, bool ); +int_fast64_t f32_to_i64_r_minMag( float32_t, bool ); +float64_t f32_to_f64( float32_t ); +floatx80_t f32_to_fx80( float32_t ); +float128_t f32_to_f128( float32_t ); +float32_t f32_roundToInt( float32_t, int_fast8_t, bool ); +float32_t f32_add( float32_t, float32_t ); +float32_t f32_sub( float32_t, float32_t ); +float32_t f32_mul( float32_t, float32_t ); +float32_t f32_mulAdd( float32_t, float32_t, float32_t ); +float32_t f32_div( float32_t, float32_t ); +float32_t f32_rem( float32_t, float32_t ); +float32_t f32_sqrt( float32_t ); +bool f32_eq( float32_t, float32_t ); +bool f32_le( float32_t, float32_t ); +bool f32_lt( float32_t, float32_t ); +bool f32_eq_signaling( float32_t, float32_t ); +bool f32_le_quiet( float32_t, float32_t ); +bool f32_lt_quiet( float32_t, float32_t ); +bool f32_isSignalingNaN( float32_t ); + +/*---------------------------------------------------------------------------- +| 64-bit (double-precision) floating-point operations. +*----------------------------------------------------------------------------*/ +uint_fast32_t f64_to_ui32( float64_t, int_fast8_t, bool ); +uint_fast64_t f64_to_ui64( float64_t, int_fast8_t, bool ); +int_fast32_t f64_to_i32( float64_t, int_fast8_t, bool ); +int_fast64_t f64_to_i64( float64_t, int_fast8_t, bool ); +uint_fast32_t f64_to_ui32_r_minMag( float64_t, bool ); +uint_fast64_t f64_to_ui64_r_minMag( float64_t, bool ); +int_fast32_t f64_to_i32_r_minMag( float64_t, bool ); +int_fast64_t f64_to_i64_r_minMag( float64_t, bool ); +float32_t f64_to_f32( float64_t ); +floatx80_t f64_to_fx80( float64_t ); +float128_t f64_to_f128( float64_t ); +float64_t f64_roundToInt( float64_t, int_fast8_t, bool ); +float64_t f64_add( float64_t, float64_t ); +float64_t f64_sub( float64_t, float64_t ); +float64_t f64_mul( float64_t, float64_t ); +float64_t f64_mulAdd( float64_t, float64_t, float64_t ); +float64_t f64_div( float64_t, float64_t ); +float64_t f64_rem( float64_t, float64_t ); +float64_t f64_sqrt( float64_t ); +bool f64_eq( float64_t, float64_t ); +bool f64_le( float64_t, float64_t ); +bool f64_lt( float64_t, float64_t ); +bool f64_eq_signaling( float64_t, float64_t ); +bool f64_le_quiet( float64_t, float64_t ); +bool f64_lt_quiet( float64_t, float64_t ); +bool f64_isSignalingNaN( float64_t ); + +/*---------------------------------------------------------------------------- +| Extended double-precision rounding precision. Valid values are 32, 64, and +| 80. +*----------------------------------------------------------------------------*/ +extern int_fast8_t floatx80_roundingPrecision; + +/*---------------------------------------------------------------------------- +| Extended double-precision floating-point operations. +*----------------------------------------------------------------------------*/ +uint_fast32_t fx80_to_ui32( floatx80_t, int_fast8_t, bool ); +uint_fast64_t fx80_to_ui64( floatx80_t, int_fast8_t, bool ); +int_fast32_t fx80_to_i32( floatx80_t, int_fast8_t, bool ); +int_fast64_t fx80_to_i64( floatx80_t, int_fast8_t, bool ); +uint_fast32_t fx80_to_ui32_r_minMag( floatx80_t, bool ); +uint_fast64_t fx80_to_ui64_r_minMag( floatx80_t, bool ); +int_fast32_t fx80_to_i32_r_minMag( floatx80_t, bool ); +int_fast64_t fx80_to_i64_r_minMag( floatx80_t, bool ); +float32_t fx80_to_f32( floatx80_t ); +float64_t fx80_to_f64( floatx80_t ); +float128_t fx80_to_f128( floatx80_t ); +floatx80_t fx80_roundToInt( floatx80_t, int_fast8_t, bool ); +floatx80_t fx80_add( floatx80_t, floatx80_t ); +floatx80_t fx80_sub( floatx80_t, floatx80_t ); +floatx80_t fx80_mul( floatx80_t, floatx80_t ); +floatx80_t fx80_mulAdd( floatx80_t, floatx80_t, floatx80_t ); +floatx80_t fx80_div( floatx80_t, floatx80_t ); +floatx80_t fx80_rem( floatx80_t, floatx80_t ); +floatx80_t fx80_sqrt( floatx80_t ); +bool fx80_eq( floatx80_t, floatx80_t ); +bool fx80_le( floatx80_t, floatx80_t ); +bool fx80_lt( floatx80_t, floatx80_t ); +bool fx80_eq_signaling( floatx80_t, floatx80_t ); +bool fx80_le_quiet( floatx80_t, floatx80_t ); +bool fx80_lt_quiet( floatx80_t, floatx80_t ); +bool fx80_isSignalingNaN( floatx80_t ); + +/*---------------------------------------------------------------------------- +| 128-bit (quadruple-precision) floating-point operations. +*----------------------------------------------------------------------------*/ +uint_fast32_t f128_to_ui32( float128_t, int_fast8_t, bool ); +uint_fast64_t f128_to_ui64( float128_t, int_fast8_t, bool ); +int_fast32_t f128_to_i32( float128_t, int_fast8_t, bool ); +int_fast64_t f128_to_i64( float128_t, int_fast8_t, bool ); +uint_fast32_t f128_to_ui32_r_minMag( float128_t, bool ); +uint_fast64_t f128_to_ui64_r_minMag( float128_t, bool ); +int_fast32_t f128_to_i32_r_minMag( float128_t, bool ); +int_fast64_t f128_to_i64_r_minMag( float128_t, bool ); +float32_t f128_to_f32( float128_t ); +float64_t f128_to_f64( float128_t ); +floatx80_t f128_to_fx80( float128_t ); +float128_t f128_roundToInt( float128_t, int_fast8_t, bool ); +float128_t f128_add( float128_t, float128_t ); +float128_t f128_sub( float128_t, float128_t ); +float128_t f128_mul( float128_t, float128_t ); +float128_t f128_mulAdd( float128_t, float128_t, float128_t ); +float128_t f128_div( float128_t, float128_t ); +float128_t f128_rem( float128_t, float128_t ); +float128_t f128_sqrt( float128_t ); +bool f128_eq( float128_t, float128_t ); +bool f128_le( float128_t, float128_t ); +bool f128_lt( float128_t, float128_t ); +bool f128_eq_signaling( float128_t, float128_t ); +bool f128_le_quiet( float128_t, float128_t ); +bool f128_lt_quiet( float128_t, float128_t ); +bool f128_isSignalingNaN( float128_t ); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/softfloat/softfloat.mk.in b/softfloat/softfloat.mk.in new file mode 100644 index 0000000..59993cb --- /dev/null +++ b/softfloat/softfloat.mk.in @@ -0,0 +1,113 @@ +softfloat_subproject_deps = \ + sotfloat_riscv \ + +softfloat_hdrs = \ + internals.h \ + primitives.h \ + softfloat.h \ + +softfloat_c_srcs = \ + f32_add.c \ + f32_div.c \ + f32_eq.c \ + f32_eq_signaling.c \ + f32_isSignalingNaN.c \ + f32_le.c \ + f32_le_quiet.c \ + f32_lt.c \ + f32_lt_quiet.c \ + f32_mulAdd.c \ + f32_mul.c \ + f32_rem.c \ + f32_roundToInt.c \ + f32_sqrt.c \ + f32_sub.c \ + f32_to_f64.c \ + f32_to_i32.c \ + f32_to_i32_r_minMag.c \ + f32_to_i64.c \ + f32_to_i64_r_minMag.c \ + f32_to_ui32.c \ + f32_to_ui32_r_minMag.c \ + f32_to_ui64.c \ + f32_to_ui64_r_minMag.c \ + f64_add.c \ + f64_div.c \ + f64_eq.c \ + f64_eq_signaling.c \ + f64_isSignalingNaN.c \ + f64_le.c \ + f64_le_quiet.c \ + f64_lt.c \ + f64_lt_quiet.c \ + f64_mulAdd.c \ + f64_mul.c \ + f64_rem.c \ + f64_roundToInt.c \ + f64_sqrt.c \ + f64_sub.c \ + f64_to_f32.c \ + f64_to_i32.c \ + f64_to_i32_r_minMag.c \ + f64_to_i64.c \ + f64_to_i64_r_minMag.c \ + f64_to_ui32.c \ + f64_to_ui32_r_minMag.c \ + f64_to_ui64.c \ + f64_to_ui64_r_minMag.c \ + i32_to_f32.c \ + i32_to_f64.c \ + i64_to_f32.c \ + i64_to_f64.c \ + s_add128.c \ + s_add192.c \ + s_addMagsF32.c \ + s_addMagsF64.c \ + s_countLeadingZeros32.c \ + s_countLeadingZeros64.c \ + s_countLeadingZeros8.c \ + s_eq128.c \ + s_estimateDiv128To64.c \ + s_estimateSqrt32.c \ + s_le128.c \ + s_lt128.c \ + s_mul128By64To192.c \ + s_mul128To256.c \ + s_mul64To128.c \ + s_mulAddF32.c \ + s_mulAddF64.c \ + s_normRoundPackToF32.c \ + s_normRoundPackToF64.c \ + s_normSubnormalF32Sig.c \ + s_normSubnormalF64Sig.c \ + softfloat_state.c \ + s_roundPackToF32.c \ + s_roundPackToF64.c \ + s_roundPackToI32.c \ + s_roundPackToI64.c \ + s_roundPackToUI32.c \ + s_roundPackToUI64.c \ + s_shift128ExtraRightJam.c \ + s_shift128RightJam.c \ + s_shift32RightJam.c \ + s_shift64ExtraRightJam.c \ + s_shift64RightJam.c \ + s_shortShift128ExtraRightJam.c \ + s_shortShift128Left.c \ + s_shortShift128Right.c \ + s_shortShift192Left.c \ + s_shortShift32Right1Jam.c \ + s_shortShift64ExtraRightJam.c \ + s_shortShift64RightJam.c \ + s_sub128.c \ + s_sub192.c \ + s_subMagsF32.c \ + s_subMagsF64.c \ + ui32_to_f32.c \ + ui32_to_f64.c \ + ui64_to_f32.c \ + ui64_to_f64.c \ + +softfloat_test_srcs = + +softfloat_install_prog_srcs = diff --git a/softfloat/softfloat_state.c b/softfloat/softfloat_state.c new file mode 100755 index 0000000..8859089 --- /dev/null +++ b/softfloat/softfloat_state.c @@ -0,0 +1,19 @@ + +/*** COMMENTS. ***/ + +#include +#include "platform.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +/*---------------------------------------------------------------------------- +| Floating-point rounding mode, extended double-precision rounding precision, +| and exception flags. +*----------------------------------------------------------------------------*/ +int_fast8_t softfloat_roundingMode = softfloat_round_nearest_even; +int_fast8_t softfloat_detectTininess = init_detectTininess; +int_fast8_t softfloat_exceptionFlags = 0; + +int_fast8_t floatx80_roundingPrecision = 80; + diff --git a/softfloat/ui32_to_f32.c b/softfloat/ui32_to_f32.c new file mode 100755 index 0000000..ba0fc1a --- /dev/null +++ b/softfloat/ui32_to_f32.c @@ -0,0 +1,25 @@ + +#include +#include "platform.h" +#include "primitives.h" +#include "internals.h" +#include "softfloat.h" + +float32_t ui32_to_f32( uint_fast32_t a ) +{ + union ui32_f32 uZ; + + if ( ! a ) { + uZ.ui = 0; + return uZ.f; + } + if ( a & 0x80000000 ) { + return + softfloat_roundPackToF32( + 0, 0x9D, softfloat_shortShift32Right1Jam( a ) ); + } else { + return softfloat_normRoundPackToF32( 0, 0x9C, a ); + } + +} + diff --git a/softfloat/ui32_to_f64.c b/softfloat/ui32_to_f64.c new file mode 100755 index 0000000..d0bd177 --- /dev/null +++ b/softfloat/ui32_to_f64.c @@ -0,0 +1,26 @@ + +#include +#include "platform.h" +#include "primitives.h" +#include "internals.h" +#include "softfloat.h" + +float64_t ui32_to_f64( uint_fast32_t a ) +{ + uint_fast64_t uiZ; + int shiftCount; + union ui64_f64 uZ; + + if ( ! a ) { + uiZ = 0; + } else { + shiftCount = softfloat_countLeadingZeros32( a ) + 21; + uiZ = + packToF64UI( + 0, 0x432 - shiftCount, (uint_fast64_t) a< +#include "platform.h" +#include "primitives.h" +#include "internals.h" +#include "softfloat.h" + +float32_t ui64_to_f32( uint_fast64_t a ) +{ + int shiftCount; + union ui32_f32 u; + uint_fast32_t sig; + + shiftCount = softfloat_countLeadingZeros64( a ) - 40; + if ( 0 <= shiftCount ) { + u.ui = + a ? packToF32UI( + 0, 0x95 - shiftCount, (uint_fast32_t) a< +#include "platform.h" +#include "primitives.h" +#include "internals.h" +#include "softfloat.h" + +float64_t ui64_to_f64( uint_fast64_t a ) +{ + union ui64_f64 uZ; + + if ( ! a ) { + uZ.ui = 0; + return uZ.f; + } + if ( a & UINT64_C( 0x8000000000000000 ) ) { + return + softfloat_roundPackToF64( + 0, 0x43D, softfloat_shortShift64RightJam( a, 1 ) ); + } else { + return softfloat_normRoundPackToF64( 0, 0x43C, a ); + } + +} + diff --git a/softfloat_riscv/platform.h b/softfloat_riscv/platform.h new file mode 100755 index 0000000..6c54313 --- /dev/null +++ b/softfloat_riscv/platform.h @@ -0,0 +1,42 @@ + +/*============================================================================ + +*** FIX. + +This C source fragment is part of the SoftFloat IEC/IEEE Floating-point +Arithmetic Package, Release 2b. + +Written by John R. Hauser. This work was made possible in part by the +International Computer Science Institute, located at Suite 600, 1947 Center +Street, Berkeley, California 94704. Funding was partially provided by the +National Science Foundation under grant MIP-9311980. The original version +of this code was written as part of a project to build a fixed-point vector +processor in collaboration with the University of California at Berkeley, +overseen by Profs. Nelson Morgan and John Wawrzynek. More information +is available through the Web page `http://www.cs.berkeley.edu/~jhauser/ +arithmetic/SoftFloat.html'. + +THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has +been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES +RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS +AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES, +COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE +EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE +INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR +OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE. + +Derivative works are acceptable, even for commercial purposes, so long as +(1) the source code for the derivative work includes prominent notice that +the work is derivative, and (2) the source code includes prominent notice with +these four paragraphs for those parts of this code that are retained. + +=============================================================================*/ + +/*---------------------------------------------------------------------------- +*----------------------------------------------------------------------------*/ +#define LITTLEENDIAN + +#ifndef UINT64_C +# define UINT64_C(x) (x ## ULL) +# define INT64_C(x) (x ## LL) +#endif diff --git a/softfloat_riscv/s_commonNaNToF32UI.c b/softfloat_riscv/s_commonNaNToF32UI.c new file mode 100755 index 0000000..61f2735 --- /dev/null +++ b/softfloat_riscv/s_commonNaNToF32UI.c @@ -0,0 +1,17 @@ + +#include +#include "platform.h" +#include "specialize.h" + +/*---------------------------------------------------------------------------- +| Returns the result of converting the canonical NaN `a' to the single- +| precision floating-point format. +*----------------------------------------------------------------------------*/ + +uint_fast32_t softfloat_commonNaNToF32UI( struct commonNaN a ) +{ + + return (uint_fast32_t) a.sign<<31 | 0x7FFFFFFF; + +} + diff --git a/softfloat_riscv/s_commonNaNToF64UI.c b/softfloat_riscv/s_commonNaNToF64UI.c new file mode 100755 index 0000000..da36c04 --- /dev/null +++ b/softfloat_riscv/s_commonNaNToF64UI.c @@ -0,0 +1,18 @@ + +#include +#include "platform.h" +#include "specialize.h" + +/*---------------------------------------------------------------------------- +| Returns the result of converting the canonical NaN `a' to the double- +| precision floating-point format. +*----------------------------------------------------------------------------*/ + +uint_fast64_t softfloat_commonNaNToF64UI( struct commonNaN a ) +{ + + return + (uint_fast64_t) a.sign<<63 | UINT64_C( 0x7FFFFFFFFFFFFFFF ); + +} + diff --git a/softfloat_riscv/s_f32UIToCommonNaN.c b/softfloat_riscv/s_f32UIToCommonNaN.c new file mode 100755 index 0000000..9ee0db9 --- /dev/null +++ b/softfloat_riscv/s_f32UIToCommonNaN.c @@ -0,0 +1,25 @@ + +#include +#include "platform.h" +#include "specialize.h" +#include "softfloat.h" + +/*---------------------------------------------------------------------------- +| Returns the result of converting the single-precision floating-point NaN +| `a' to the canonical NaN format. If `a' is a signaling NaN, the invalid +| exception is raised. +*----------------------------------------------------------------------------*/ +struct commonNaN softfloat_f32UIToCommonNaN( uint_fast32_t uiA ) +{ + struct commonNaN z; + + if ( softfloat_isSigNaNF32UI( uiA ) ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + } + z.sign = uiA>>31; + z.v64 = (uint_fast64_t) 0x7FFFF <<41; + z.v0 = 0; + return z; + +} + diff --git a/softfloat_riscv/s_f64UIToCommonNaN.c b/softfloat_riscv/s_f64UIToCommonNaN.c new file mode 100755 index 0000000..84d8ca0 --- /dev/null +++ b/softfloat_riscv/s_f64UIToCommonNaN.c @@ -0,0 +1,25 @@ + +#include +#include "platform.h" +#include "specialize.h" +#include "softfloat.h" + +/*---------------------------------------------------------------------------- +| Returns the result of converting the double-precision floating-point NaN +| `a' to the canonical NaN format. If `a' is a signaling NaN, the invalid +| exception is raised. +*----------------------------------------------------------------------------*/ +struct commonNaN softfloat_f64UIToCommonNaN( uint_fast64_t uiA ) +{ + struct commonNaN z; + + if ( softfloat_isSigNaNF64UI( uiA ) ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + } + z.sign = uiA>>63; + z.v64 = (uint_fast64_t) 0xFFFFFFFFFFFFF <<12; + z.v0 = 0; + return z; + +} + diff --git a/softfloat_riscv/s_isSigNaNF32UI.c b/softfloat_riscv/s_isSigNaNF32UI.c new file mode 100755 index 0000000..0a9c33f --- /dev/null +++ b/softfloat_riscv/s_isSigNaNF32UI.c @@ -0,0 +1,13 @@ + +#include +#include +#include "platform.h" +#include "specialize.h" + +bool softfloat_isSigNaNF32UI( uint_fast32_t ui ) +{ + + return ( ( ui>>22 & 0x1FF ) == 0x1FE ) && ( ui & 0x003FFFFF ); + +} + diff --git a/softfloat_riscv/s_isSigNaNF64UI.c b/softfloat_riscv/s_isSigNaNF64UI.c new file mode 100755 index 0000000..d255213 --- /dev/null +++ b/softfloat_riscv/s_isSigNaNF64UI.c @@ -0,0 +1,15 @@ + +#include +#include +#include "platform.h" +#include "specialize.h" + +bool softfloat_isSigNaNF64UI( uint_fast64_t ui ) +{ + + return + ( ( ui>>51 & 0xFFF ) == 0xFFE ) + && ( ui & UINT64_C( 0x0007FFFFFFFFFFFF ) ); + +} + diff --git a/softfloat_riscv/s_propagateNaNF32UI.c b/softfloat_riscv/s_propagateNaNF32UI.c new file mode 100755 index 0000000..07774e8 --- /dev/null +++ b/softfloat_riscv/s_propagateNaNF32UI.c @@ -0,0 +1,55 @@ + +/*** UPDATE COMMENTS. ***/ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +/*---------------------------------------------------------------------------- +| Takes two single-precision floating-point values `a' and `b', one of which +| is a NaN, and returns the appropriate NaN result. If either `a' or `b' is a +| signaling NaN, the invalid exception is raised. +*----------------------------------------------------------------------------*/ + +uint_fast32_t + softfloat_propagateNaNF32UI( uint_fast32_t uiA, uint_fast32_t uiB ) +{ + bool isNaNA, isSigNaNA, isNaNB, isSigNaNB; + uint_fast32_t uiMagA, uiMagB; + + /*------------------------------------------------------------------------ + *------------------------------------------------------------------------*/ + isNaNA = isNaNF32UI( uiA ); + isSigNaNA = softfloat_isSigNaNF32UI( uiA ); + isNaNB = isNaNF32UI( uiB ); + isSigNaNB = softfloat_isSigNaNF32UI( uiB ); + /*------------------------------------------------------------------------ + | Make NaNs non-signaling. + *------------------------------------------------------------------------*/ + uiA |= 0x00400000; + uiB |= 0x00400000; + /*------------------------------------------------------------------------ + *------------------------------------------------------------------------*/ + if ( isSigNaNA | isSigNaNB ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + } + if ( isSigNaNA ) { + if ( isSigNaNB ) goto returnLargerSignificand; + return isNaNB ? uiB : uiA; + } else if ( isNaNA ) { + if ( isSigNaNB || ! isNaNB ) return uiA; + returnLargerSignificand: + uiMagA = uiA<<1; + uiMagB = uiB<<1; + if ( uiMagA < uiMagB ) return uiB; + if ( uiMagB < uiMagA ) return uiA; + return ( uiA < uiB ) ? uiA : uiB; + } else { + return uiB; + } + +} + diff --git a/softfloat_riscv/s_propagateNaNF64UI.c b/softfloat_riscv/s_propagateNaNF64UI.c new file mode 100755 index 0000000..0ff6446 --- /dev/null +++ b/softfloat_riscv/s_propagateNaNF64UI.c @@ -0,0 +1,55 @@ + +/*** UPDATE COMMENTS. ***/ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +/*---------------------------------------------------------------------------- +| Takes two double-precision floating-point values `a' and `b', one of which +| is a NaN, and returns the appropriate NaN result. If either `a' or `b' is a +| signaling NaN, the invalid exception is raised. +*----------------------------------------------------------------------------*/ + +uint_fast64_t + softfloat_propagateNaNF64UI( uint_fast64_t uiA, uint_fast64_t uiB ) +{ + bool isNaNA, isSigNaNA, isNaNB, isSigNaNB; + uint_fast64_t uiMagA, uiMagB; + + /*------------------------------------------------------------------------ + *------------------------------------------------------------------------*/ + isNaNA = isNaNF64UI( uiA ); + isSigNaNA = softfloat_isSigNaNF64UI( uiA ); + isNaNB = isNaNF64UI( uiB ); + isSigNaNB = softfloat_isSigNaNF64UI( uiB ); + /*------------------------------------------------------------------------ + | Make NaNs non-signaling. + *------------------------------------------------------------------------*/ + uiA |= UINT64_C( 0x0008000000000000 ); + uiB |= UINT64_C( 0x0008000000000000 ); + /*------------------------------------------------------------------------ + *------------------------------------------------------------------------*/ + if ( isSigNaNA | isSigNaNB ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + } + if ( isSigNaNA ) { + if ( isSigNaNB ) goto returnLargerSignificand; + return isNaNB ? uiB : uiA; + } else if ( isNaNA ) { + if ( isSigNaNB || ! isNaNB ) return uiA; + returnLargerSignificand: + uiMagA = uiA & UINT64_C( 0x7FFFFFFFFFFFFFFF ); + uiMagB = uiB & UINT64_C( 0x7FFFFFFFFFFFFFFF ); + if ( uiMagA < uiMagB ) return uiB; + if ( uiMagB < uiMagA ) return uiA; + return ( uiA < uiB ) ? uiA : uiB; + } else { + return uiB; + } + +} + diff --git a/softfloat_riscv/softfloat_raiseFlags.c b/softfloat_riscv/softfloat_raiseFlags.c new file mode 100755 index 0000000..c0c0dc8 --- /dev/null +++ b/softfloat_riscv/softfloat_raiseFlags.c @@ -0,0 +1,51 @@ + +/*============================================================================ + +*** FIX. + +This C source fragment is part of the SoftFloat IEC/IEEE Floating-point +Arithmetic Package, Release 2b. + +Written by John R. Hauser. This work was made possible in part by the +International Computer Science Institute, located at Suite 600, 1947 Center +Street, Berkeley, California 94704. Funding was partially provided by the +National Science Foundation under grant MIP-9311980. The original version +of this code was written as part of a project to build a fixed-point vector +processor in collaboration with the University of California at Berkeley, +overseen by Profs. Nelson Morgan and John Wawrzynek. More information +is available through the Web page `http://www.cs.berkeley.edu/~jhauser/ +arithmetic/SoftFloat.html'. + +THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has +been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES +RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS +AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES, +COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE +EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE +INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR +OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE. + +Derivative works are acceptable, even for commercial purposes, so long as +(1) the source code for the derivative work includes prominent notice that +the work is derivative, and (2) the source code includes prominent notice with +these four paragraphs for those parts of this code that are retained. + +=============================================================================*/ + +#include "platform.h" +#include "softfloat.h" + +/*---------------------------------------------------------------------------- +| Raises the exceptions specified by `flags'. Floating-point traps can be +| defined here if desired. It is currently not possible for such a trap +| to substitute a result value. If traps are not implemented, this routine +| should be simply `float_exception_flags |= flags;'. +*----------------------------------------------------------------------------*/ + +void softfloat_raiseFlags( int_fast8_t flags ) +{ + + softfloat_exceptionFlags |= flags; + +} + diff --git a/softfloat_riscv/softfloat_riscv.ac b/softfloat_riscv/softfloat_riscv.ac new file mode 100644 index 0000000..e69de29 diff --git a/softfloat_riscv/softfloat_riscv.mk.in b/softfloat_riscv/softfloat_riscv.mk.in new file mode 100644 index 0000000..0b898ed --- /dev/null +++ b/softfloat_riscv/softfloat_riscv.mk.in @@ -0,0 +1,21 @@ +softfloat_riscv_subproject_deps = \ + +softfloat_riscv_hdrs = \ + softfloat_types.h \ + platform.h \ + specialize.h \ + +softfloat_riscv_c_srcs = \ + softfloat_raiseFlags.c \ + s_commonNaNToF32UI.c \ + s_commonNaNToF64UI.c \ + s_f32UIToCommonNaN.c \ + s_f64UIToCommonNaN.c \ + s_isSigNaNF32UI.c \ + s_isSigNaNF64UI.c \ + s_propagateNaNF32UI.c \ + s_propagateNaNF64UI.c \ + +softfloat_riscv_test_srcs = + +softfloat_riscv_install_prog_srcs = diff --git a/softfloat_riscv/softfloat_types.h b/softfloat_riscv/softfloat_types.h new file mode 100755 index 0000000..9fada89 --- /dev/null +++ b/softfloat_riscv/softfloat_types.h @@ -0,0 +1,16 @@ + +#ifndef softfloat_types_h +#define softfloat_types_h + +/*** COMMENTS. ***/ + +#include +#include + +typedef uint32_t float32_t; +typedef uint64_t float64_t; +typedef struct { uint64_t v; uint16_t x; } floatx80_t; +typedef struct { uint64_t v[ 2 ]; } float128_t; + +#endif + diff --git a/softfloat_riscv/specialize.h b/softfloat_riscv/specialize.h new file mode 100755 index 0000000..bf57bc9 --- /dev/null +++ b/softfloat_riscv/specialize.h @@ -0,0 +1,113 @@ + +/*============================================================================ + +*** FIX. + +This C source fragment is part of the SoftFloat IEC/IEEE Floating-point +Arithmetic Package, Release 2b. + +Written by John R. Hauser. This work was made possible in part by the +International Computer Science Institute, located at Suite 600, 1947 Center +Street, Berkeley, California 94704. Funding was partially provided by the +National Science Foundation under grant MIP-9311980. The original version +of this code was written as part of a project to build a fixed-point vector +processor in collaboration with the University of California at Berkeley, +overseen by Profs. Nelson Morgan and John Wawrzynek. More information +is available through the Web page `http://www.cs.berkeley.edu/~jhauser/ +arithmetic/SoftFloat.html'. + +THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has +been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES +RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS +AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES, +COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE +EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE +INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR +OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE. + +Derivative works are acceptable, even for commercial purposes, so long as +(1) the source code for the derivative work includes prominent notice that +the work is derivative, and (2) the source code includes prominent notice with +these four paragraphs for those parts of this code that are retained. + +=============================================================================*/ + +#include +#include + +/*---------------------------------------------------------------------------- +*----------------------------------------------------------------------------*/ +#define init_detectTininess softfloat_tininess_beforeRounding; + +/*---------------------------------------------------------------------------- +| Structure used to transfer NaN representations from one format to another. +*----------------------------------------------------------------------------*/ +struct commonNaN { + bool sign; + uint64_t v64, v0; +}; + +/*---------------------------------------------------------------------------- +| The pattern for a default generated single-precision NaN. +*----------------------------------------------------------------------------*/ +#define defaultNaNF32UI 0xFFFFFFFF + +/*---------------------------------------------------------------------------- +| Returns 1 if the single-precision floating-point value `a' is a signaling +| NaN; otherwise, returns 0. +*----------------------------------------------------------------------------*/ +#if defined INLINE_LEVEL && ( 1 <= INLINE_LEVEL ) +INLINE bool softfloat_isSigNaNF32UI( uint_fast32_t ui ) + { return ( ( ui>>22 & 0x1FF ) == 0x1FE ) && ( ui & 0x003FFFFF ); } +#else +bool softfloat_isSigNaNF32UI( uint_fast32_t ); +#endif + +/*---------------------------------------------------------------------------- +*----------------------------------------------------------------------------*/ +struct commonNaN softfloat_f32UIToCommonNaN( uint_fast32_t ); +#if defined INLINE_LEVEL && ( 1 <= INLINE_LEVEL ) +INLINE uint_fast32_t softfloat_commonNaNToF32UI( struct commonNaN a ) + { return (uint_fast32_t) a.sign<<31 | 0x7FFFFFFF; } +#else +uint_fast32_t softfloat_commonNaNToF32UI( struct commonNaN ); +#endif + +/*---------------------------------------------------------------------------- +| Takes two single-precision floating-point values `a' and `b', one of which +| is a NaN, and returns the appropriate NaN result. If either `a' or `b' is a +| signaling NaN, the invalid exception is raised. +*----------------------------------------------------------------------------*/ +uint_fast32_t softfloat_propagateNaNF32UI( uint_fast32_t, uint_fast32_t ); + +/*---------------------------------------------------------------------------- +| The pattern for a default generated double-precision NaN. +*----------------------------------------------------------------------------*/ +#define defaultNaNF64UI UINT64_C(0xFFF8000000000000) + +/*---------------------------------------------------------------------------- +*----------------------------------------------------------------------------*/ +#if defined INLINE_LEVEL && ( 1 <= INLINE_LEVEL ) +INLINE bool softfloat_isSigNaNF64UI( uint_fast64_t ui ) +{ + return + ( ( ui>>51 & 0xFFF ) == 0xFFE ) + && ( ui & UINT64_C( 0x0007FFFFFFFFFFFF ) ); +} +#else +bool softfloat_isSigNaNF64UI( uint_fast64_t ); +#endif + +/*---------------------------------------------------------------------------- +*----------------------------------------------------------------------------*/ +/*** MIGHT BE INLINE'D. ***/ +struct commonNaN softfloat_f64UIToCommonNaN( uint_fast64_t ); +uint_fast64_t softfloat_commonNaNToF64UI( struct commonNaN ); + +/*---------------------------------------------------------------------------- +| Takes two double-precision floating-point values `a' and `b', one of which +| is a NaN, and returns the appropriate NaN result. If either `a' or `b' is a +| signaling NaN, the invalid exception is raised. +*----------------------------------------------------------------------------*/ +uint_fast64_t softfloat_propagateNaNF64UI( uint_fast64_t, uint_fast64_t ); +