Commit dd9a64f9 by Martin

llvm w/ daiFPU and SWAR data types. All changes consolidated in a single patch. Release 3

0 parents
Showing with 1817 additions and 0 deletions
/build/
/install/
/source/
/tests/_build/
/debug/
\ No newline at end of file
LLVM framework for IP Core Extensions
=====================================
This project contains
- script for downloading and building patched LLVM framework
- patches for IP extensions in Sparc/LEON architecture
LLVM version
------------
This package uses LLVM version 10.0.0 (git 3186b18b998124a6b577f8274a10b7ee8b634c18).
Building
--------
Simply run script './run.sh all' from any folder.
LLVM framework will be prepared in subdirectory 'install'.
Using
-----
- add directory 'install/bin' to PATH or copy directory 'install'
TBD
XXX - all tools from binutils starts with prefix 'sparc-daiteq-elf-'
XXX - new assembler instructions can be used with options '--has-swar','--has-fhalf','--has-fcplx','--has-fpack'
RB2003
This diff could not be displayed because it is too large.
#!/bin/bash
LLVM_NAME=llvm
LLVM_VERSION=10.0.0
LLVM_SERVER="https://github.com/llvm/llvm-project.git"
LLVM_GIT_BRANCH="release/10.x"
LLVM_GIT_COMMIT="3186b18b998124a6b577f8274a10b7ee8b634c18"
DAITEQ_BRANCH="daiteq"
TGT_TRIPLE=sparc-daiteq-none-elf
HOST_TRIPLE=x86_64-linux-gnu
CURDIR="$(pwd)"
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# number of cores used for make
MAKE_CORES=$(nproc --all)
DIR_SRCS=${CURDIR}/source
DIR_BLD=${CURDIR}/build
DIR_INST=${CURDIR}/install
DIR_PTCH=${SCRIPTDIR}/patches
DIR_DEBUG=${CURDIR}/debug
GENDIRS="${DIR_SRCS} ${DIR_BLD} ${DIR_INST}"
#DN_BUUNP=${DIR_UPCK}/${BU_NAME}-${BU_VERSION}
CCMAKE_ARGS="-D CMAKE_BUILD_TYPE=Release \
-D BUILD_SHARED_LIBS=ON \
-D LLVM_ENABLE_Z3_SOLVER=OFF \
-D CMAKE_INSTALL_PREFIX=${DIR_INST} \
-D LLVM_DEFAULT_TARGET_TRIPLE=${TGT_TRIPLE} \
-D LLVM_EXTERNAL_CLANG_SOURCE_DIR=${DIR_SRCS}/clang \
-D LLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR=${DIR_SRCS}/clang-tools-extra \
-D LLVM_EXTERNAL_COMPILER_RT_SOURCE_DIR=${DIR_SRCS}/compiler-rt \
-D LLVM_INCLUDE_DOCS=OFF \
-D LLVM_ENABLE_OCAMLDOC=OFF \
-D LLVM_INSTALL_BINUTILS_SYMLINKS=ON \
-D LLVM_TARGETS_TO_BUILD=Sparc \
-D LLVM_TARGET_ARCH=sparc \
-D LLVM_TOOL_CLANG_BUILD=ON \
-D LLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD=ON \
-D CLANG_INCLUDE_TESTS=ON \
-D CLANG_VENDOR=daiteq-esa \
-D LLVM_TOOL_COMPILER_RT_BUILD=OFF"
# -D COMPILER_RT_USE_BUILTINS_LIBRARY=ON
CCMAKE_DEBUG_ARGS="-D CMAKE_BUILD_TYPE:STRING=Debug \
-D LLVM_ENABLE_ASSERTIONS:BOOL=ON \
-D BUILD_SHARED_LIBS=ON \
-D LLVM_ENABLE_Z3_SOLVER=OFF \
-D CMAKE_INSTALL_PREFIX=${DIR_INST} \
-D LLVM_DEFAULT_TARGET_TRIPLE=${TGT_TRIPLE} \
-D LLVM_EXTERNAL_CLANG_SOURCE_DIR=${DIR_SRCS}/clang \
-D LLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR=${DIR_SRCS}/clang-tools-extra \
-D LLVM_EXTERNAL_COMPILER_RT_SOURCE_DIR=${DIR_SRCS}/compiler-rt \
-D LLVM_INCLUDE_DOCS=OFF \
-D LLVM_ENABLE_OCAMLDOC=OFF \
-D LLVM_INSTALL_BINUTILS_SYMLINKS=ON \
-D LLVM_TARGETS_TO_BUILD=Sparc \
-D LLVM_TARGET_ARCH=sparc \
-D LLVM_TOOL_CLANG_BUILD=ON \
-D LLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD=ON \
-D CLANG_INCLUDE_TESTS=ON \
-D CLANG_VENDOR=daiteq-esa \
-D LLVM_TOOL_COMPILER_RT_BUILD=OFF"
prepare_dirs() {
for d in ${GENDIRS}
do
echo "Create directory ${d}"
mkdir -p ${d}
done
}
download_source() {
mkdir -p ${DIR_SRCS}
if [ "$(ls -A ${DIR_SRCS})" ]
then
echo "Repository is already cloned ... check consistency"
else
git clone --progress -n --branch ${LLVM_GIT_BRANCH} ${LLVM_SERVER} ${DIR_SRCS}
fi
cd ${DIR_SRCS}
# is there already working branch
if [ $(git branch --list ${DAITEQ_BRANCH}) ]
then
# already exists
git checkout ${DAITEQ_BRANCH}
else
# no work branch
git reset --hard ${LLVM_GIT_COMMIT}
git branch ${DAITEQ_BRANCH}
git checkout ${DAITEQ_BRANCH}
fi
cd ${CURDIR}
}
apply_patches() {
if [ ! -e ${DIR_PTCH} ]
then
echo "There is not a directory with patches"
exit 1
fi
cd ${DIR_SRCS}
# change branch to ours
git checkout ${DAITEQ_BRANCH}
# reset to the source LLVM commit
git reset --hard ${LLVM_GIT_COMMIT}
# check applying patches
for p in `ls ${DIR_PTCH}/*.txt | sort -V`
do
echo "Use patch ${p}"
git apply --check --whitespace=fix ${p}
echo vysledek = $?
if [[ $? != 0 ]]; then
echo " Patch cannot be applied."
cd ${CURDIR}
break
fi
git am --whitespace=fix ${p}
done
cd ${CURDIR}
}
do_configure() {
if [ ! -e ${DIR_SRCS} ]
then
echo "There is no unpacked files with source codes"
exit 1
fi
mkdir -p ${DIR_BLD}
cd ${DIR_BLD}
CONF=1
if [ -f CMakeCache.txt ]
then
echo "Compilation is already configured - try it again."
#CONF=0
fi
if [ ${CONF} -eq 1 ]
then
cmake ${CCMAKE_ARGS} ${DIR_SRCS}/llvm
if [ $? -ne 0 ]
then
echo "E: configure failed"
exit 1
fi
fi
}
build_source() {
mkdir -p ${DIR_BLD}
cd ${DIR_BLD}
if [ ! -f Makefile ]
then
echo "Compilation is not configured - run configuration."
do_configure
fi
make -j ${MAKE_CORES}
if [ $? -ne 0 ]
then
echo "E: make failed"
exit 1
fi
cd ${CURDIR}
}
build_debug() {
if [ ! -e ${DIR_SRCS} ]
then
echo "There is no unpacked files with source codes"
exit 1
fi
mkdir -p ${DIR_DEBUG}
cd ${DIR_DEBUG}
if [ -f CMakeCache.txt ]
then
echo "Compilation is already configured - try it again."
#CONF=0
else
cmake ${CCMAKE_DEBUG_ARGS} ${DIR_SRCS}/llvm
if [ $? -ne 0 ]
then
echo "E: configure failed"
exit 1
fi
fi
make -j ${MAKE_CORES}
if [ $? -ne 0 ]
then
echo "E: make debug failed"
exit 1
fi
cd ${CURDIR}
}
install_pkg() {
mkdir -p ${DIR_INST}
cd ${DIR_BLD}
make install
cd ${CURDIR}
}
clean_build() {
echo "Removing build and install directories."
rm -rf ${DIR_BLD} ${DIR_INST}
}
clean_unpacked() {
echo "Removing patches from the repository."
cd ${DIR_SRCS}
# change branch to ours
git checkout ${DAITEQ_BRANCH}
# reset to the source LLVM commit
git reset --hard ${LLVM_GIT_COMMIT}
# check applying patches
cd ${CURDIR}
}
distclean_all() {
echo "Removing all download and generated files and directories."
rm -rf ${GENDIRS}
}
# ##############################################################################
print_help() {
echo "The script needs one argument - required operation:"
echo " all - do all steps (get,patch,config,build,install)"
echo " get - download source package if it doesn't exist"
echo " patch - patch original package"
echo " config - perform configuration in build directory (cmake)"
echo " build - build LLVM package (make)"
echo " install - install LLVM to the output directory"
echo " clean - remove generated files (build and install dirs.)"
echo " packclean - remove unpacked files (unpack dir.)"
echo " distclean - remove all generated files and directories"
echo " debug - build debug version of LLVM package"
}
# ##############################################################################
# main ...
echo "Script for preparing patched LLVM for LEON IP core extensions."
if [ "$#" -ne 1 ]
then
print_help
exit 0
fi
case $1 in
"all" )
#echo "do all"
download_source
apply_patches
do_configure
build_source
install_pkg
;;
"get" )
#echo "do clone LLVM"
download_source
;;
"patch" )
#echo "do patch"
apply_patches
;;
"config" )
#echo "do configure"
do_configure
;;
"build" )
#echo "do build"
build_source
;;
"install" )
#echo "do install"
install_pkg
;;
"clean" )
#echo "do clean"
clean_build
;;
"packclean" )
#echo "do packclean"
clean_unpacked
;;
"distclean" )
#echo "do distclean"
distclean_all
;;
"debug" )
#echo "do debug"
build_debug
;;
* )
echo "E: Unsupported operation"
print_help
exit 1
;;
esac
# Makefile for building all tests of isolated FPU/SWAR operations
SRCDIR=src
DSTDIR=_build
CC=clang
LC=llc
LDIS=llvm-dis
TOOLCHAIN=sparc-daiteq-elf
AS=$(TOOLCHAIN)-as
LD=$(TOOLCHAIN)-ld
OBJDUMP=$(TOOLCHAIN)-objdump
#LCFLAGS=-debug-pass=Structure -debug --asm-verbose
#LCFLAGS=-debug --print-machineinstrs -view-dag-combine1-dags
TESTBASE = $(basename $(notdir $(SOURCE)))
OUTDIR = $(DSTDIR)/$(SUBDIR)/$(basename $(SOURCE))
OUTFILES = $(OUTDIR)/$(TESTBASE)
PATHSOURCE = $(SRCDIR)/$(SUBDIR)/$(SOURCE)
DEFS = $(shell ./scripts/get_defines $(PATHSOURCE) D)
ASMALLFLAGS = $(shell ./scripts/get_defines $(PATHSOURCE) A)
ASFLAGS = $(ASMALLFLAGS:%=-Xassembler %)
ALLSRCDIRS:=$(sort $(notdir $(wildcard $(SRCDIR)/*)))
ALLSOURCES=$(sort $(notdir $(wildcard $(SRCDIR)/$(SRCSUBDIR)/*.c)))
.PHONY: all clean build_one build_dir $(OUTDIR)
# process all test directory
all: $(DSTDIR)
@for i in $(ALLSRCDIRS); do \
echo "Build for $$i \n"; \
mkdir -p $(DSTDIR)/$$i; \
make -C $(PWD) -f Makefile build_dir SRCSUBDIR=$$i PHASE=zero; \
done
@echo "All tests done\n"
test:
@echo "Srcs : $(ALLSOURCES)"
clean:
rm -fr $(ALLSOURCES:%=$(DSTDIR)/%/*)
# rm -fr $(DSTDIR)/*
build_dir:
@for i in $(ALLSOURCES); do \
echo " Build $(SRCDIR)/$(SRCSUBDIR)/$$i \n"; \
make -C $(PWD) -f Makefile build_one SUBDIR=$(SRCSUBDIR) SOURCE=$$i PHASE=one; \
done
@echo "Done in subdirectory $(SRCSUBDIR)"
build_one: $(OUTDIR)/done
@echo " ... done in '$(OUTDIR)'"
$(DSTDIR):
@echo "Create build directory"
@mkdir -p $(DSTDIR)
$(OUTDIR):
@mkdir -p $(OUTDIR)
$(OUTFILES).ast: $(PATHSOURCE)
@echo "Parse $(PATHSOURCE) to $(OUTFILES).ast"
@$(CC) -Xclang -ast-dump -fno-color-diagnostics -S $(TEST_CFLAGS) $(DEFS) $(CFLGS) $(PATHSOURCE) >$(OUTFILES).ast 2>$(OUTFILES).ast_err
$(OUTFILES).ll: $(PATHSOURCE)
@echo "Create IR $(OUTFILES).ll from $(PATHSOURCE)"
@$(CC) -emit-llvm $(TEST_CFLAGS) $(DEFS) $(CFLGS) $(PATHSOURCE) -S -o $(OUTFILES).ll 2>$(OUTFILES).ll_err
$(OUTFILES).bc: $(PATHSOURCE)
@echo "Create binary IR $(OUTFILES).bc from $(PATHSOURCE)"
@$(CC) -emit-llvm $(TEST_CFLAGS) $(DEFS) $(CFLGS) $(PATHSOURCE) -c -o $(OUTFILES).bc 2>$(OUTFILES).bc_err
$(OUTFILES)-dis.ll: $(OUTFILES).bc
@echo "Disassembly IR $(OUTFILES).bc to $(OUTFILES)-dis.ll"
@$(LDIS) < $(OUTFILES).bc 1>$(OUTFILES)-dis.ll 2>$(OUTFILES)-dis.ll_err
$(OUTFILES).S: $(OUTFILES).bc
@echo "Compile IR $(OUTFILES).bc to target ASM $(OUTFILES).S"
@$(LC) $(OUTFILES).bc $(LCFLAGS) -o $(OUTFILES).S 2>$(OUTFILES).S_err
$(OUTFILES).o: $(OUTFILES).S
@echo "Compile IR $(OUTFILES).bc to target ASM $(OUTFILES).S"
@$(CC) -target $(TOOLCHAIN) $(TEST_CFLAGS) $(DEFS) $(CFLGS) $(ASFLAGS) -c $(PATHSOURCE) -o $(OUTFILES).o 2>$(OUTFILES).obj_err
$(OUTFILES).dis: $(OUTFILES).o
@echo "Disassembly object $(OUTFILES).o to $(OUTFILES).dis"
@$(OBJDUMP) -Sdt $(OUTFILES).o >$(OUTFILES).dis 2>$(OUTFILES).dis_err
$(OUTDIR)/done: $(OUTDIR) $(OUTFILES).ast $(OUTFILES).ll $(OUTFILES)-dis.ll $(OUTFILES).dis
@touch $(OUTDIR)/done
#!/usr/bin/python
# Script for parsing source code file and extracting compile flags and options
# 2020 Roman Bartosinski, daiteq s.r.o.
#
# Line begins with:
# //A: assembler flags
# //T: C compiler flags
# //D: selection of data types for specific testing framework
import sys
meta={}
#print(sys.argv)
if len(sys.argv)>2:
onlytype = sys.argv[2]
else:
onlytype = None
try:
if len(sys.argv)<2:
raise Exception('no arg')
with open(sys.argv[1]) as f:
content = f.readlines()
# print(content)
for ln in content:
# skip unsupported lines
if not ln.startswith('//'):
continue
if (len(ln)<5) or (ln[3]!=':'):
continue
ctp = ln[2]
if (onlytype is not None) and (ctp!=onlytype[0]):
continue
# get data types
if ctp=='D':
if 'D' not in meta:
meta['D'] = ""
f = ln.find("'")
i = ln.find("=")
if f<0:
f = 3
l = len(ln)
else:
l = ln.rfind("'")
if i<0:
i = l
args = ln[f+1:i]
if i<l:
res = ln[i+1:l]
else:
res = ''
#print(args)
i = args.find(',')
if i<0:
a1 = args.strip()
a2 = "none"
else:
a1 = args[0:i].strip()
a2 = args[i+1:].strip()
if a1=='half':
meta['D'] += " -DPAR_A_HALF=1"
elif a1=='float':
meta['D'] += " -DPAR_A_SINGLE=1"
elif a1=='double':
meta['D'] += " -DPAR_A_DOUBLE=1"
elif a1=='int32':
meta['D'] += " -DPAR_A_INT32=1"
elif a1=='packhalf':
meta['D'] += " -DPAR_A_PACKHALF=1"
else:
meta['D'] += " -DPAR_A_NONE=1"
if a2=='none':
meta['D'] += " -DPAR_B_NONE=1"
elif a2=='half':
meta['D'] += " -DPAR_B_HALF=1"
elif a2=='float':
meta['D'] += " -DPAR_B_SINGLE=1"
elif a2=='double':
meta['D'] += " -DPAR_B_DOUBLE=1"
elif a2=='int32':
meta['D'] += " -DPAR_B_INT32=1"
elif a2=='packhalf':
meta['D'] += " -DPAR_B_PACKHALF=1"
res = res.strip()
if res=='half':
meta['D'] += " -DRES_HALF=1"
elif res=='float':
meta['D'] += " -DRES_SINGLE=1"
elif res=='double':
meta['D'] += " -DRES_DOUBLE=1"
elif res=='int32':
meta['D'] += " -DRES_INT32=1"
elif res=='packhalf':
meta['D'] += " -DRES_PACKHALF=1"
else:
meta['D'] += " -DRES_NONE=1"
# get list of compilator flags
if ctp=='T':
if 'T' not in meta:
meta['T'] = []
f = ln.find("'")
if f<0:
f = 4
l = len(ln)
else:
l = ln.rfind("'")
meta['T'].append(ln[f+1:l].strip())
# get assembler flags
if ctp=='A':
if 'A' not in meta:
meta['A'] = ""
f = ln.find("'")
if f<0:
f = 4
l = len(ln)
else:
l = ln.rfind("'")
meta['A'] += " " + ln[f+1:l].strip()
except:
if 'D' not in meta:
meta['D'] = ""
meta['D'] += " -DNOTREADY"
sys.exit
if onlytype is not None:
if onlytype in meta:
if isinstance(meta[onlytype], str):
print(meta[onlytype])
else:
print("\n".join(meta[onlytype]))
else:
print(meta)
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-double'
////A: '--has-fhalf'
#include <math.h>
//double fabs(double x);
int main(void)
{
volatile double a, z;
z = fabs(a);
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-double'
////A: '--has-fhalf'
int main(void)
{
volatile double a, b, z;
z = a + b;
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-double'
////A: '--has-fhalf'
int main(void)
{
volatile double a, b, z;
z = a / b;
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-double'
////A: '--has-fhalf'
int main(void)
{
volatile double a;
volatile int z;
z = (double)a;
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-double'
////A: '--has-fhalf'
int main(void)
{
volatile float z;
volatile double a;
z = (float)a;
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-double'
////A: '--has-fhalf'
int main(void)
{
volatile double z;
volatile int a;
z = (int)a;
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-double'
////A: '--has-fhalf'
int main(void)
{
volatile double a, b, z;
z = a * b;
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-double'
////A: '--has-fhalf'
int main(void)
{
volatile float a, b;
volatile double z;
z = (double)a * b;
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-double'
////A: '--has-fhalf'
int main(void)
{
volatile double a, z;
z = -a;
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-double'
//A: '--has-fhalf'
#include <math.h>
//double sqrt(double x);
int main(void)
{
volatile double a, z;
z = sqrt(a);
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-double'
////A: '--has-fhalf'
int main(void)
{
volatile float a;
volatile double z;
z = (double)a;
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-double'
////A: '--has-fhalf'
int main(void)
{
volatile double a, b, z;
z = a - b;
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-float'
////A: '--has-fhalf'
#include <math.h>
//float fabsf(float x);
int main(void)
{
volatile float a, z;
z = fabsf(a);
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-float'
////A: '--has-fhalf'
int main(void)
{
volatile float a, b, z;
z = a + b;
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-float'
////A: '--has-fhalf'
int main(void)
{
volatile float a, b, z;
z = a / b;
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-float'
////A: '--has-fhalf'
int main(void)
{
volatile float z;
volatile double a;
z = (float)a;
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-float'
////A: '--has-fhalf'
int main(void)
{
volatile float z;
volatile int a;
z = (int)a;
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-float'
////A: '--has-fhalf'
int main(void)
{
volatile float a, b, z;
z = a * b;
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-float'
////A: '--has-fhalf'
int main(void)
{
volatile float a, b;
volatile double z;
z = (double)a * b;
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-float'
////A: '--has-fhalf'
int main(void)
{
volatile float a, z;
z = -a;
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-float'
//A: '--has-fhalf'
#include <math.h>
//float sqrtf(float x);
int main(void)
{
volatile float a, z;
z = sqrtf(a);
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-float'
////A: '--has-fhalf'
int main(void)
{
volatile float a;
volatile double z;
z = (double)a;
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-float'
////A: '--has-fhalf'
int main(void)
{
volatile float a;
volatile int z;
z = (float)a;
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-float'
////A: '--has-fhalf'
int main(void)
{
volatile float a, b, z;
z = a - b;
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-half'
//A: '--has-fhalf'
// #include <mathhalf.h>
half fabsh(half x);
int main(void)
{
volatile half a, z;
z = fabsh(a);
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-half'
//A: '--has-fhalf'
int main(void)
{
volatile half a, b, z;
z = a + b;
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-half'
//A: '--has-fhalf'
int main(void)
{
volatile half a, b, z;
z = a / b;
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-half'
//A: '--has-fhalf'
int main(void)
{
volatile half a;
volatile int z;
z = (half)a;
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-half'
//A: '--has-fhalf'
int main(void)
{
volatile half a;
volatile float z;
z = (float)a;
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-half'
//A: '--has-fhalf'
int main(void)
{
volatile half z;
volatile int a;
z = (int)a;
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-half'
//A: '--has-fhalf'
int main(void)
{
volatile half a, b, z;
z = a * b;
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-half'
//A: '--has-fhalf'
int main(void)
{
volatile half a, b;
volatile float z;
z = (float)a * b;
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-half'
//A: '--has-fhalf'
int main(void)
{
volatile half a, z;
z = -a;
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-half'
//A: '--has-fhalf'
//#include <mathhalf.h>
half sqrth(half x);
int main(void)
{
volatile half a, z;
z = sqrth(a);
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-half'
//A: '--has-fhalf'
int main(void)
{
volatile half z;
volatile float a;
z = (half)a;
return 0;
}
/* assembler flags '//A:' , defines '//D:' , compiler options '//T:' */
////T: '-msoft-fp-half'
//A: '--has-fhalf'
int main(void)
{
volatile half a, b, z;
z = a - b;
return 0;
}
/* Assembler needs option --has-swar */
//A: '--has-swar'
#include <stdint.h>
typedef unsigned int s2x16b __attribute__((subword(16)));
#define ALEN 20
uint16_t input_a[ALEN] = {17554, 30725, 25860, 2562, 8722, 23094, 16793, 12791,
4507, 14944, 8703, 28534, 22887, 32420, 15943, 10643,
26325, 18166, 20856, 15838};
uint16_t input_b[ALEN] = {12996, 32492, 15993, 30426, 13600, 14398, 15600, 11328,
8375, 14670, 14411, 85, 985, 12091, 11686, 6561,
19045, 9275, 5777, 17885};
uint16_t output_zU16[ALEN];
uint16_t output_zS2x16b[ALEN];
void do_as_uint16(void)
{
uint16_t *pa = input_a;
uint16_t *pb = input_b;
uint16_t *pz = output_zU16;
for(int i=0;i<ALEN;++i) {
pz[i] = pa[i] + pb[i];
}
}
void do_as_s2x16b(void)
{
s2x16b *pa = (s2x16b *)input_a;
s2x16b *pb = (s2x16b *)input_b;
s2x16b *pz = (s2x16b *)output_zS2x16b;
for(int i=0;i<ALEN/2;++i) {
pz[i] = pa[i] + pb[i];
}
}
void do_as_s2x16b_sat(void)
{
{
#pragma swar saturate
s2x16b *pa = (s2x16b *)input_a;
s2x16b *pb = (s2x16b *)input_b;
s2x16b *pz = (s2x16b *)output_zS2x16b;
for(int i=0;i<ALEN/2;++i) {
pz[i] = pa[i] + pb[i];
}
}
}
void do_as_s2x16b_red(void)
{
{
#pragma swar reduce
s2x16b *pa = (s2x16b *)input_a;
s2x16b *pb = (s2x16b *)input_b;
s2x16b *pz = (s2x16b *)output_zS2x16b;
for(int i=0;i<ALEN/2;++i) {
pz[i] = pa[i] + pb[i];
}
}
}
void do_as_s2x16b_norm(void)
{
{ /* the second inside block is a hack for pragma swar - without them pragma is shared with other functions */
#pragma swar normalize
s2x16b *pa = (s2x16b *)input_a;
s2x16b *pb = (s2x16b *)input_b;
s2x16b *pz = (s2x16b *)output_zS2x16b;
for(int i=0;i<ALEN/2;++i) {
pz[i] = pa[i] + pb[i];
}
}
}
void do_as_s2x16b_dis(void)
{
#pragma swar manual
s2x16b *pa = (s2x16b *)input_a;
s2x16b *pb = (s2x16b *)input_b;
s2x16b *pz = (s2x16b *)output_zS2x16b;
for(int i=0;i<ALEN/2;++i) {
pz[i] = pa[i] + pb[i];
}
}
int main(void)
{
int fail = 0;
/* clear results */
for(int i=0;i<ALEN;++i) {
output_zU16[i] = 0;
output_zS2x16b[i] = 0;
}
/* compute as separated U16 */
do_as_uint16();
/* compute as swar s2x16b */
do_as_s2x16b();
/* display variables */
// printf("Data before (a,b, z1, z2):\n");
// for(int i=0;i<ALEN;++i) {
// printf(" #%d: %u , %u , %u , %u\n", i, input_a[i], input_b[i], output_zU16[i], output_zS2x16b[i]);
// }
for(int i=0;i<ALEN;++i) {
if (output_zU16[i]!=output_zS2x16b[i]) {
fail++;
}
}
/* test swar operations controlled with pragmas */
do_as_s2x16b_sat();
do_as_s2x16b_red();
do_as_s2x16b_norm();
do_as_s2x16b_dis();
return fail;
}
/* Assembler needs option --has-swar */
//A: '--has-swar'
#include <stdint.h>
typedef unsigned int s2x16b __attribute__((subword(16)));
#define ALEN 20
uint16_t input_a[ALEN] = {17554, 30725, 25860, 2562, 8722, 23094, 16793, 12791,
4507, 14944, 8703, 28534, 22887, 32420, 15943, 10643,
26325, 18166, 20856, 15838};
uint16_t input_b[ALEN] = {12996, 32492, 15993, 30426, 13600, 14398, 15600, 11328,
8375, 14670, 14411, 85, 985, 12091, 11686, 6561,
19045, 9275, 5777, 17885};
uint16_t output_zU16[ALEN];
uint16_t output_zS2x16b[ALEN];
void do_as_uint16(void)
{
uint16_t *pa = input_a;
uint16_t *pb = input_b;
uint16_t *pz = output_zU16;
for(int i=0;i<ALEN;++i) {
pz[i] = pa[i] + pb[i];
}
}
void do_as_s2x16b(void)
{
s2x16b *pa = (s2x16b *)input_a;
s2x16b *pb = (s2x16b *)input_b;
s2x16b *pz = (s2x16b *)output_zS2x16b;
for(int i=0;i<ALEN/2;++i) {
pz[i] = pa[i] + pb[i];
}
}
int main(void)
{
int fail = 0;
/* clear results */
for(int i=0;i<ALEN;++i) {
output_zU16[i] = 0;
output_zS2x16b[i] = 0;
}
/* compute as separated U16 */
do_as_uint16();
/* compute as swar s2x16b */
do_as_s2x16b();
/* display variables */
// printf("Data before (a,b, z1, z2):\n");
// for(int i=0;i<ALEN;++i) {
// printf(" #%d: %u , %u , %u , %u\n", i, input_a[i], input_b[i], output_zU16[i], output_zS2x16b[i]);
// }
for(int i=0;i<ALEN;++i) {
if (output_zU16[i]!=output_zS2x16b[i]) {
fail++;
}
}
return fail;
}
/* Assembler needs option --has-swar */
//A: '--has-swar'
#include <stdint.h>
typedef unsigned int s4x8b __attribute__((subword(8)));
#define ALEN 40
uint8_t input_a[ALEN] = { 111, 91, 82, 178, 12, 161, 183, 93,
214, 179, 173, 247, 121, 253, 143, 139,
45, 28, 246, 117, 103, 205, 231, 240,
68, 221, 150, 5, 81, 47, 78, 74,
167, 203, 230, 184, 190, 65, 113, 199};
uint8_t input_b[ALEN] = { 191, 122, 238, 38, 8, 130, 249, 86,
62, 179, 56, 250, 193, 51, 174, 221,
228, 84, 25, 18, 180, 252, 125, 67,
119, 154, 169, 109, 148, 73, 46, 103,
29, 44, 247, 200, 95, 23, 192, 236};
uint8_t output_zU8[ALEN];
uint8_t output_zS4x8b[ALEN];
void do_as_uint8(void)
{
uint8_t *pa = input_a;
uint8_t *pb = input_b;
uint8_t *pz = output_zU8;
for(int i=0;i<ALEN;++i) {
pz[i] = pa[i] + pb[i];
}
}
void do_as_s4x8b(void)
{
s4x8b *pa = (s4x8b *)input_a;
s4x8b *pb = (s4x8b *)input_b;
s4x8b *pz = (s4x8b *)output_zS4x8b;
for(int i=0;i<ALEN/4;++i) {
pz[i] = pa[i] + pb[i];
}
}
int main(void)
{
int fail = 0;
/* clear results */
for(int i=0;i<ALEN;++i) {
output_zU8[i] = 0;
output_zS4x8b[i] = 0;
}
/* compute as separated U8 */
do_as_uint8();
/* compute as swar s4x8b */
do_as_s4x8b();
/* display variables */
// printf("Data before (a,b, z1, z2):\n");
// for(int i=0;i<ALEN;++i) {
// printf(" #%d: %u , %u , %u , %u\n", i, input_a[i], input_b[i], output_zU8[i], output_zS4x8b[i]);
// }
for(int i=0;i<ALEN;++i) {
if (output_zU8[i]!=output_zS4x8b[i]) {
fail++;
}
}
return fail;
}
/* Assembler needs option --has-swar */
//A: '--has-swar'
#include <stdint.h>
#include "swar.h"
typedef unsigned int s10x3b __attribute__((subword(3)));
#define ALEN 5
uint32_t signal[ALEN] = {0x12345678,0xFFFFFFFF,0x11223344,0x77777777,0x13570246};
uint32_t code = {0x00000007};
uint32_t output[ALEN] = {0,0,0,0,0};
void do_s10x3b(void)
{
swarctrl(C_COR3b);
for(int i=0;i<ALEN;++i) {
output[i] = swar(code,signal[i]);
}
}
int main(void)
{
do_s10x3b();
return 0;
}
/* Assembler needs option --has-swar */
//A: '--has-swar'
#include <stdint.h>
#include "swar.h"
typedef unsigned int s32x1b __attribute__((subword(1)));
#define ALEN 5
uint32_t signal[ALEN] = {0x12345678,0xFFFFFFFF,0x11223344,0x77777777,0x13570246};
uint32_t code = {0x00000001};
uint32_t output[ALEN] = {0,0,0,0,0};
void do_s32x1b(void)
{
swarctrl(C_COR1b);
for(int i=0;i<ALEN;++i) {
output[i] = swar(code,signal[i]);
}
}
int main(void)
{
do_s32x1b();
return 0;
}
/* Assembler needs option --has-swar */
//A: '--has-swar'
#include <stdint.h>
#include "swar.h"
typedef unsigned int s16x2b __attribute__((subword(2)));
#define ALEN 5
uint32_t signal[ALEN] = {0x12345678,0xFFFFFFFF,0x11223344,0x77777777,0x13570246};
uint32_t code = {0x00000003};
uint32_t output[ALEN] = {0,0,0,0,0};
void do_s16x2b(void)
{
swarctrl(C_COR2b);
for(int i=0;i<ALEN;++i) {
output[i] = swar(code,signal[i]);
}
}
int main(void)
{
do_s16x2b();
return 0;
}
/* Assembler needs option --has-swar */
//A: '--has-swar'
#include <stdint.h>
#include "swar.h"
typedef unsigned int s8x4b __attribute__((subword(4)));
#define ALEN 5
uint32_t signal[ALEN] = {0x12345678,0xFFFFFFFF,0x11223344,0x77777777,0x13570246};
uint32_t code = {0x00000003};
uint32_t output[ALEN] = {0,0,0,0,0};
void do_s8x4b(void)
{
swarctrl(C_COR4b);
for(int i=0;i<ALEN;++i) {
output[i] = swar(code,signal[i]);
}
}
int main(void)
{
do_s8x4b();
return 0;
}
/* Assembler needs option --has-swar */
//A: '--has-swar'
#include <stdint.h>
#include "swar.h"
typedef unsigned int s10x3b __attribute__((subword(3)));
#define LEN 5
uint32_t data_a[LEN] = {01234567123,01122334455,07777777777,04444444444,07654765476};
uint32_t data_b[LEN] = {07654321765,02342342342,01234567123,02323232323,00000000000};
uint32_t data_z[LEN] = {0,0,0,0,0};
int main(void)
{
swarctrl(C_COR3b);
for(int i=0;i<LEN;++i) {
data_z[i] = swar(data_a[i], data_b[i]);
}
uint32_t a = swarstat(0);
return 0;
}
/* Assembler needs option --has-swar */
//A: '--has-swar'
#include <stdint.h>
typedef unsigned int s2x16b __attribute__((subword(16)));
#define ALEN 20
uint16_t input_a[ALEN] = {17554, 30725, 25860, 2562, 8722, 23094, 16793, 12791,
4507, 14944, 8703, 28534, 22887, 32420, 15943, 10643,
26325, 18166, 20856, 15838};
uint16_t input_b[ALEN] = {12996, 32492, 15993, 30426, 13600, 14398, 15600, 11328,
8375, 14670, 14411, 85, 985, 12091, 11686, 6561,
19045, 9275, 5777, 17885};
uint16_t output_zU16[ALEN];
uint16_t output_zS2x16b[ALEN];
void do_as_uint16(void)
{
uint16_t *pa = input_a;
uint16_t *pb = input_b;
uint16_t *pz = output_zU16;
for(int i=0;i<ALEN;++i) {
pz[i] = pa[i] * pb[i];
}
}
void do_as_s2x16b(void)
{
s2x16b *pa = (s2x16b *)input_a;
s2x16b *pb = (s2x16b *)input_b;
s2x16b *pz = (s2x16b *)output_zS2x16b;
for(int i=0;i<ALEN/2;++i) {
pz[i] = pa[i] * pb[i];
}
}
int main(void)
{
int fail = 0;
/* clear results */
for(int i=0;i<ALEN;++i) {
output_zU16[i] = 0;
output_zS2x16b[i] = 0;
}
/* compute as separated U16 */
do_as_uint16();
/* compute as swar s2x16b */
do_as_s2x16b();
/* display variables */
// printf("Data before (a,b, z1, z2):\n");
// for(int i=0;i<ALEN;++i) {
// printf(" #%d: %u , %u , %u , %u\n", i, input_a[i], input_b[i], output_zU16[i], output_zS2x16b[i]);
// }
for(int i=0;i<ALEN;++i) {
if (output_zU16[i]!=output_zS2x16b[i]) {
fail++;
}
}
return fail;
}
/* Assembler needs option --has-swar */
//A: '--has-swar'
#include <stdint.h>
typedef unsigned int s4x8b __attribute__((subword(8)));
#define ALEN 40
uint8_t input_a[ALEN] = { 111, 91, 82, 178, 12, 161, 183, 93,
214, 179, 173, 247, 121, 253, 143, 139,
45, 28, 246, 117, 103, 205, 231, 240,
68, 221, 150, 5, 81, 47, 78, 74,
167, 203, 230, 184, 190, 65, 113, 199};
uint8_t input_b[ALEN] = { 191, 122, 238, 38, 8, 130, 249, 86,
62, 179, 56, 250, 193, 51, 174, 221,
228, 84, 25, 18, 180, 252, 125, 67,
119, 154, 169, 109, 148, 73, 46, 103,
29, 44, 247, 200, 95, 23, 192, 236};
uint8_t output_zU8[ALEN];
uint8_t output_zS4x8b[ALEN];
void do_as_uint8(void)
{
uint8_t *pa = input_a;
uint8_t *pb = input_b;
uint8_t *pz = output_zU8;
for(int i=0;i<ALEN;++i) {
pz[i] = pa[i] * pb[i];
}
}
void do_as_s4x8b(void)
{
s4x8b *pa = (s4x8b *)input_a;
s4x8b *pb = (s4x8b *)input_b;
s4x8b *pz = (s4x8b *)output_zS4x8b;
for(int i=0;i<ALEN/4;++i) {
pz[i] = pa[i] * pb[i];
}
}
int main(void)
{
int fail = 0;
/* clear results */
for(int i=0;i<ALEN;++i) {
output_zU8[i] = 0;
output_zS4x8b[i] = 0;
}
/* compute as separated U8 */
do_as_uint8();
/* compute as swar s4x8b */
do_as_s4x8b();
/* display variables */
// printf("Data before (a,b, z1, z2):\n");
// for(int i=0;i<ALEN;++i) {
// printf(" #%d: %u , %u , %u , %u\n", i, input_a[i], input_b[i], output_zU8[i], output_zS4x8b[i]);
// }
for(int i=0;i<ALEN;++i) {
if (output_zU8[i]!=output_zS4x8b[i]) {
fail++;
}
}
return fail;
}
/* Assembler needs option --has-swar */
//A: '--has-swar'
#include <stdint.h>
typedef unsigned int s2x16b __attribute__((subword(16)));
#define ALEN 20
uint16_t input_a[ALEN] = {17554, 30725, 25860, 2562, 8722, 23094, 16793, 12791,
4507, 14944, 8703, 28534, 22887, 32420, 15943, 10643,
26325, 18166, 20856, 15838};
uint16_t input_b[ALEN] = {12996, 32492, 15993, 30426, 13600, 14398, 15600, 11328,
8375, 14670, 14411, 85, 985, 12091, 11686, 6561,
19045, 9275, 5777, 17885};
uint16_t output_zU16[ALEN];
uint16_t output_zS2x16b[ALEN];
void do_as_uint16(void)
{
uint16_t *pa = input_a;
uint16_t *pb = input_b;
uint16_t *pz = output_zU16;
for(int i=0;i<ALEN;++i) {
pz[i] = pa[i] - pb[i];
}
}
void do_as_s2x16b(void)
{
s2x16b *pa = (s2x16b *)input_a;
s2x16b *pb = (s2x16b *)input_b;
s2x16b *pz = (s2x16b *)output_zS2x16b;
for(int i=0;i<ALEN/2;++i) {
pz[i] = pa[i] - pb[i];
}
}
int main(void)
{
int fail = 0;
/* clear results */
for(int i=0;i<ALEN;++i) {
output_zU16[i] = 0;
output_zS2x16b[i] = 0;
}
/* compute as separated U16 */
do_as_uint16();
/* compute as swar s2x16b */
do_as_s2x16b();
/* display variables */
// printf("Data before (a,b, z1, z2):\n");
// for(int i=0;i<ALEN;++i) {
// printf(" #%d: %u , %u , %u , %u\n", i, input_a[i], input_b[i], output_zU16[i], output_zS2x16b[i]);
// }
for(int i=0;i<ALEN;++i) {
if (output_zU16[i]!=output_zS2x16b[i]) {
fail++;
}
}
return fail;
}
/* Assembler needs option --has-swar */
//A: '--has-swar'
#include <stdint.h>
typedef unsigned int s4x8b __attribute__((subword(8)));
#define ALEN 40
uint8_t input_a[ALEN] = { 111, 91, 82, 178, 12, 161, 183, 93,
214, 179, 173, 247, 121, 253, 143, 139,
45, 28, 246, 117, 103, 205, 231, 240,
68, 221, 150, 5, 81, 47, 78, 74,
167, 203, 230, 184, 190, 65, 113, 199};
uint8_t input_b[ALEN] = { 191, 122, 238, 38, 8, 130, 249, 86,
62, 179, 56, 250, 193, 51, 174, 221,
228, 84, 25, 18, 180, 252, 125, 67,
119, 154, 169, 109, 148, 73, 46, 103,
29, 44, 247, 200, 95, 23, 192, 236};
uint8_t output_zU8[ALEN];
uint8_t output_zS4x8b[ALEN];
void do_as_uint8(void)
{
uint8_t *pa = input_a;
uint8_t *pb = input_b;
uint8_t *pz = output_zU8;
for(int i=0;i<ALEN;++i) {
pz[i] = pa[i] - pb[i];
}
}
void do_as_s4x8b(void)
{
s4x8b *pa = (s4x8b *)input_a;
s4x8b *pb = (s4x8b *)input_b;
s4x8b *pz = (s4x8b *)output_zS4x8b;
for(int i=0;i<ALEN/4;++i) {
pz[i] = pa[i] - pb[i];
}
}
int main(void)
{
int fail = 0;
/* clear results */
for(int i=0;i<ALEN;++i) {
output_zU8[i] = 0;
output_zS4x8b[i] = 0;
}
/* compute as separated U8 */
do_as_uint8();
/* compute as swar s4x8b */
do_as_s4x8b();
/* display variables */
// printf("Data before (a,b, z1, z2):\n");
// for(int i=0;i<ALEN;++i) {
// printf(" #%d: %u , %u , %u , %u\n", i, input_a[i], input_b[i], output_zU8[i], output_zS4x8b[i]);
// }
for(int i=0;i<ALEN;++i) {
if (output_zU8[i]!=output_zS4x8b[i]) {
fail++;
}
}
return fail;
}
#ifndef SWAR_EXTENSION_HEADER_FILE
#define SWAR_EXTENSION_HEADER_FILE
/* swar known functions */
#define C_COR1b 0x4
#define C_COR2b 0x5
#define C_COR3b 0x6
#define C_COR4b 0x7
#define C_DEMR2b 0x9
#define C_DEMR3b 0xa
#define C_DEMR4b 0xb
#define C_DEMC2b 0xd
#define C_DEMC3b 0xe
#define C_DEMC4b 0xf
#define C_DEMC2bG 0x1
#define C_DEMC3bG 0x2
#define C_DEMC4bG 0x3
#endif /* SWAR_EXTENSION_HEADER_FILE */
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!