From c72c930bc0f781c2b41fb4cbd7a173364c0531fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Mon, 13 Jan 2014 09:08:21 +0100 Subject: [PATCH] . --- .gitignore | 83 +++++++++++++ Makefile | 12 +- SQRT.v | 38 ------ bericht/Makefile | 11 ++ bericht/bericht.tex | 135 +++++++++++----------- bericht/bibliography.bib | 28 +++-- bericht/code/sqrt.c | 30 +++++ bericht/ifathesis.cls | 243 +++++++++++++++++++++------------------ bericht/packages.tex | 4 +- c/sqrt.c | 5 +- verilog/heron_ctrl.v | 12 +- verilog/heron_top_tb.v | 35 ++++++ 12 files changed, 397 insertions(+), 239 deletions(-) create mode 100644 .gitignore delete mode 100644 SQRT.v create mode 100644 bericht/Makefile create mode 100644 bericht/code/sqrt.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5bdb0c3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,83 @@ +## Core latex/pdflatex auxiliary files: +*.aux +*.lof +*.log +*.lot +*.fls +*.out +*.toc + +## Intermediate documents: +*.dvi +# these rules might exclude image files for figures etc. +*.ps +*.eps +*.pdf + +## Bibliography auxiliary files (bibtex/biblatex/biber): +*.bbl +*.bcf +*.blg +*-blx.aux +*-blx.bib +*.run.xml + +## Build tool auxiliary files: +*.fdb_latexmk +*.synctex.gz +*.pdfsync + +## Auxiliary and intermediate files from other packages: + +# algorithms +*.alg +*.loa + +# amsthm +*.thm + +# beamer +*.nav +*.snm +*.vrb + +# glossaries +*.acn +*.acr +*.glg +*.glo +*.gls + +# hyperref +*.brf + +# listings +*.lol + +# makeidx +*.idx +*.ilg +*.ind +*.ist + +# minitoc +*.maf +*.mtc +*.mtc0 + +# minted +*.pyg + +# nomencl +*.nlo + +# todonotes +*.tdo + +# xindy +*.xdy + +# verilog +*.vcd + +/examples diff --git a/Makefile b/Makefile index 6e03e1a..29f6f5a 100644 --- a/Makefile +++ b/Makefile @@ -2,18 +2,15 @@ C99?=c99 all: bericht check fsm_tb +bericht: + cd bericht && make + check: sqrt ./sqrt sqrt: c/sqrt.c $(C99) -lm -o sqrt c/sqrt.c -bericht/graph.pdf: bericht/graph.dot - cd bericht; dot -Tpdf graph.dot > graph.pdf - -bericht: bericht/graph.pdf - latexmk -pdf bericht/bericht.tex; - fsm: verilog/heron_fsm.vcd gtkwave verilog/heron_fsm.vcd @@ -28,3 +25,6 @@ ctrl_tb: verilog/heron_ctrl.vcd %.vvp: %_tb.v %.v iverilog -o $@ -Iverilog verilog/heron_{fsm,ctrl}.v + +sync: + rsync -av --inplace --rsync-path=~/rsync-3.1.0/rsync -avHz -e ssh verilog/ eeets2:verilog diff --git a/SQRT.v b/SQRT.v deleted file mode 100644 index 5449521..0000000 --- a/SQRT.v +++ /dev/null @@ -1,38 +0,0 @@ -module SQRT(A, Y, clk, reset); - -parameter width = 31; -`define width 31 - -input [width:0] A; -reg [width:0] x; -reg [width:0] old_x; -output [width:0] Y; - -always @(A) -begin - case(state) - WAIT: Y = 0; - CALC1: - x = CALC1 - state = OUTPUT - CALC2: - if (old_x <= x) begin - state = OUTPUT - end - OUTPUT: Y = Y_t; - default: Y = 0; - endcase -end - -initial begin : parameter_check - if (width < 1) begin - $display("ERROR: %m :\n Invalid value (%d) for parameter width (lower bound: 1)", width); - $finish; - end - if (width > 32) begin - $display("ERROR: %m :\n Invalid value (%d) for parameter width (upper bound: 32)", width); - $finish; - end -end - -endmodule diff --git a/bericht/Makefile b/bericht/Makefile new file mode 100644 index 0000000..6d608d8 --- /dev/null +++ b/bericht/Makefile @@ -0,0 +1,11 @@ +all: bericht + +%.pdf: %.tex + latexmk -pdf $< + +%.pdf: %.dot + dot -Tpdf $< > $@ + +bericht.pdf: graph.pdf + +bericht: bericht.pdf diff --git a/bericht/bericht.tex b/bericht/bericht.tex index b0a8733..ff94027 100644 --- a/bericht/bericht.tex +++ b/bericht/bericht.tex @@ -24,7 +24,7 @@ listoftables, % includes list of tables listoflistings, % includes list of listings abbrevations, % includes index of symbols and abbrevations - bibIfa, % citation style (IfA standard), alternatives: bibNumeric, bibHarvard + bibNumeric, % citation style (IfA standard), alternatives: bibNumeric, bibHarvard langDE % define the language (default: langDE) ]{ifathesis} \ifaThesis{Belegarbeit} @@ -36,6 +36,7 @@ \ifaKeywords{Praktikum, Schaltungsentwurf, Verilog} % Keywords included in pdf-file. Could be found e.g. by Windows file search. \ifaTitleDE{Schaltkreis- und Systementwurf} \ifaTitleEN{} +\bibliography{bibliography} \ifaSupervisorA{Jens-Uwe Schlüßler} \ifaProfessor{Prof. Dr.-Ing. habil. René Schüffny} @@ -46,99 +47,103 @@ \ifaAbstractEN{example_files/00_abstract_en__invalid} \usepackage{tabularx} \usepackage{graphicx} -\usepackage{color} -\definecolor{mygreen}{rgb}{0,0.6,0} -\definecolor{mygray}{rgb}{0.5,0.5,0.5} -\definecolor{mymauve}{rgb}{0.58,0,0.82} - -\lstset{ % - backgroundcolor=\color{white}, % choose the background color; you must add \usepackage{color} or \usepackage{xcolor} - basicstyle=\footnotesize, % the size of the fonts that are used for the code - breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace - breaklines=true, % sets automatic line breaking - captionpos=b, % sets the caption-position to bottom - commentstyle=\color{mygreen}, % comment style - deletekeywords={...}, % if you want to delete keywords from the given language - escapeinside={\%*}{*)}, % if you want to add LaTeX within your code - extendedchars=true, % lets you use non-ASCII characters; for 8-bits encodings only, does not work with UTF-8 - frame=single, % adds a frame around the code - keepspaces=true, % keeps spaces in text, useful for keeping indentation of code (possibly needs columns=flexible) - keywordstyle=\color{blue}, % keyword style - language=C, % the language of the code - morekeywords={*,...}, % if you want to add more keywords to the set - numbers=left, % where to put the line-numbers; possible values are (none, left, right) - numbersep=5pt, % how far the line-numbers are from the code - numberstyle=\tiny\color{mygray}, % the style that is used for the line-numbers - rulecolor=\color{black}, % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. comments (green here)) - showspaces=false, % show spaces everywhere adding particular underscores; it overrides 'showstringspaces' - showstringspaces=false, % underline spaces within strings only - showtabs=false, % show tabs within strings adding particular underscores - stepnumber=2, % the step between two line-numbers. If it's 1, each line will be numbered - stringstyle=\color{mymauve}, % string literal style - tabsize=2, % sets default tabsize to 2 spaces - title=\lstname % show the filename of files included with \lstinputlisting; also try caption instead of title +% Keine Kapitelnummerierung +\makeatletter +\renewcommand{\thesection}{ + \ifnum\c@chapter<1 \@arabic\c@section + \else \thechapter.\@arabic\c@section + \fi } +\makeatother \begin{document} -\chapter{Einleitung} -TODO Kapitel 5.1 -> Aufgabenstellung +\section{Einleitung} +Aufgabe des Praktikums \emph{Schaltkreis- und Systementwurf} ist es einen integrierten Schaltkreis (ASIC) für +einen numerischen Algorithmus zu entwickeln. Der Schaltkreis ist mit der +Enwicklungsumgebung \emph{Cadence} zu erstellen. Dabei ist den Arbeitsschritten der Aufgabenstellung +\cite{aufgabenstellung} zu folgen. Die Schaltung ist durch Simulation zu verifizieren. +Der folgende Bericht enthält die geforderte Dokumentation nach Kapitel 5.1 +\cite{dokumentation} der Aufgabenstellung. -\chapter{Beschreibung des Algorithmus} +\section{Beschreibung des Algorithmus} +Der hier selbst gewählte Algorithmus ist Ziehen der Quadratwurzel mithilfe des +Heron’sche Näherungsverfahren (auch Babylonverfahren genannt). Es ist benannt +nach dem Altgriechen Heron von Alexandria, der es zum 1. Mal beschrieb. Es ist +vermutlich das älteste Nährungsverfahren für die Quadratwurzel. Wegen seines +einfachen Aufbaus, war es ein beliebter Algorithmus für die Implementierung in +Software bevor Hardwareimplementierung sich verbreitet haben. + +Die Iterationsvorschrift des Verfahren lautet: \begin{align} - x_{n+1}=\frac{x_n + \frac{a}{x_n}}{2} + x_{n+1} & =\frac{x_n + \frac{a}{x_n}}{2} \\ + lim_{n \rightarrow \infty} x_n & = \sqrt{a} \end{align} -\section{Implementierung in C} -\begin{lstlisting} -typedef uint32_t u32; -void heron_sqrt(u32 *mem) { - int i = mem[0]; - while (i > 0) { - u32 s = mem[i]; - if (s > 1) { - // x_0 = (s + 1) / 2 - // without increment to avoid overflow for 0xffffffff - u32 x = s >> 1; - u32 old_x = x; +wobei $a$ der Ausgangswert ist, aus welchem die Wurzel berechnet werden soll und +$x_n$ der sich von Iterations zu Iterations an die Quadratwurzel annähernde +Wert. - while(1) { - // x_{n + 1} = (x_n + (s / x_n)) / 2 - x = (x >> 1) + ((s/x) >> 1); - if (old_x <= x) { - break; - } - old_x = x; - } - mem[i] = x; - } - i--; - } -} -\end{lstlisting} -\subsection{Speicherbelegung} +Herleiten lässt sich die Folge aus dem Newton-Verfahren zur Bestimmung der +Nullstellen ($x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)}$): + +\begin{align} + x^2 &= a \\ + f(x) &= x^2 - a \\ + f'(x) &= 2x \\ + x_{n + 1} &= x_n - \frac{f(x_n)}{f'(x_n)} \\ + &= x_n - \frac{x_n^2 - a}{2x_n} \\ + &= x_n - \frac{x_n - a/x_n}{2} \\ + &= \frac{x_n + a/x_n}{2} +\end{align} + +Wobei in diesem Praktikum die Quadratwurzel von mehreren hintereinander im +Speicher abgelegten Zahlen berechnet wird. + +\section{Implementierung in C} +Der Prototyp des Algorithmus erfolgte in der Programmiersprache C nach dem +C99-Standard. + +\ifalisting{Implementierung in C}{lst:implementierung}{c}{code/sqrt.c}{true} + +Wie auch in der zu realisierenden Schaltung erwartet die Funktion im +Speicherfeld die Operanden für die Quadratwurzel-Berechnung. Wobei das 1. Feld +die Anzahl der Operanden angibt (siehe Speicherbelegung \ref{tbl:speicherbelegung}). + +\subsection{Speicherbelegung und Zahlenformat} Es wird angenommen, das jeder Speicherplatz 32 Bit breit ist. Jedes Datenfeld wird als vorzeichenlose Festkommazahl interpretiert. +Die Anzahl der Nachkommastellen lässt sich sowohl in der Schaltung +(heron\_comma\_fix) als auch in +der C-Implementierung (siehe Zeile \ref{comma}) leicht anpassen, wobei +vorrausgesetzt wird, dass die Anzahl durch 2 teilbar sein muss. Für die +Verifikation wurden 8. Kommastellen festgesetzt. +\begin{table} \begin{tabularx}{\textwidth}{X|X} Speicherplatz & Beschreibung \\\hline - MEM[0] & Anzahl der Operanden (n) \\ + MEM[0] & Anzahl der Operanden (N) \\ MEM[1] & 1. Operand \\ MEM[2] & 2. Operand \\ $\ldots$ & $\dots$ \\ MEM[N] & N. Operand \end{tabularx} +\caption{Speicherbelegung} +\label{tbl:speicherbelegung} +\end{table} \subsection{Datenflussgraph} \begin{figure}[ht] \centering - \includegraphics[width=0.3\textwidth]{graph.pdf} + \includegraphics[width=0.6\textwidth]{graph.pdf} \label{fig1} \end{figure} \subsection{Datenpfad} \end{document} + +% vim:spelllang=de diff --git a/bericht/bibliography.bib b/bericht/bibliography.bib index d25f916..28fad5d 100644 --- a/bericht/bibliography.bib +++ b/bericht/bibliography.bib @@ -1,11 +1,21 @@ -%% This BibTeX bibliography file was created using BibDesk. -%% http://bibdesk.sourceforge.net/ - - %% Saved with string encoding Unicode (UTF-8) -#@misc{mda, -# Date-Added = {2010-01-09 12:34:49 +0100}, -# Date-Modified = {2010-01-09 12:35:30 +0100}, -# Title = {{Model Driven Architecture}}, -# Url = {http://omg.org/mda}} +@inbook {aufgabenstellung, + Date-Added = {2013-01-11 13:00:00 +0100}, + crossref = {einführung}, + pages = "8" +} + +@inbook {dokumentation, + Date-Added = {2013-01-11 13:00:00 +0100}, + crossref = {einführung}, + pages = "9" +} + +@book{einführung, + Date-Added = {2013-01-11 13:00:00 +0100}, + author = "Jens-Uwe Schlüßler", + title = "Einführung in die Anwendung des Entwurfssystems CADENCE für die + Lehrveranstaltung Schaltkreis- und Systementwurf", + year = "2013", +} diff --git a/bericht/code/sqrt.c b/bericht/code/sqrt.c new file mode 100644 index 0000000..981d3e9 --- /dev/null +++ b/bericht/code/sqrt.c @@ -0,0 +1,30 @@ +typedef uint32_t u32; + +// have to a multiply of 2 +#define COMMA 8 @\label{comma}@ +#define COMMA_FIX (COMMA >> 1) + +void heron_sqrt(u32 *mem) { + int i = mem[0]; + while (i > 0) { + u32 s = mem[i]; + u32 x = s; + if (s > 1) { + // x_0 = (s + 1) / 2 + // without increment to avoid overflow for 0xffffffff + x = x >> 1; + u32 old_x = x; + + while(1) { + // x_{n + 1} = (x_n + (s / x_n)) / 2 + x = (x >> 1) + ((s/x) >> 1); + if (old_x <= x) { + break; + } + old_x = x; + } + } + mem[i] = x << COMMA_FIX; + i--; + } +} diff --git a/bericht/ifathesis.cls b/bericht/ifathesis.cls index d3fd006..4690143 100644 --- a/bericht/ifathesis.cls +++ b/bericht/ifathesis.cls @@ -1,15 +1,15 @@ %!TEX root = example.tex %******************************************************************************* -% * Copyright (c) 2006-2013 +% * Copyright (c) 2006-2013 % * Institute of Automation, Dresden University of Technology -% * +% * % * All rights reserved. This program and the accompanying materials -% * are made available under the terms of the Eclipse Public License v1.0 +% * are made available under the terms of the Eclipse Public License v1.0 % * which accompanies this distribution, and is available at % * http://www.eclipse.org/legal/epl-v10.html -% * +% * % * Contributors: -% * Institute of Automation - TU Dresden, Germany +% * Institute of Automation - TU Dresden, Germany % * - initial API and implementation % ******************************************************************************/ @@ -61,7 +61,7 @@ \PassOptionsToPackage{style=\@ifaBibliographyStyle, backend=bibtex8, maxbibnames=99}{biblatex} \PassOptionsToPackage{svgnames}{xcolor} % Namensraum für xcolor Paket - + \PassOptionsToPackage{fleqn}{amsmath} \LoadClass[ @@ -144,7 +144,7 @@ % Absatznummerierung fuer 4 Ebenen (z.B. 2.3.2.1) gemaess IfA Richtlinie einschalten. \setcounter{secnumdepth}{3} -\setcounter{tocdepth}{3} +\setcounter{tocdepth}{3} % Lade benötigte Pakete \RequirePackage{scrhack} %Zur Herstellung der Kompabilitaet mit Paketen, die nicht kompatibel zum KOMA-Script sind. @@ -153,10 +153,10 @@ % definiere Farben \definecolor{TUDBLAU}{rgb}{0.0,0.348,0.637} -\definecolor{OSGREEN}{rgb}{0,0.75,0.25} +\definecolor{OSGREEN}{rgb}{0,0.75,0.25} % Kläre zunächst einige Dinge, die von der Sprache abhängen -\ifthenelse{\equal{\@ifaThesisLanguage}{de}}{ +\ifthenelse{\equal{\@ifaThesisLanguage}{de}}{ % Deutsche Pakete \RequirePackage[ngerman]{babel} % Silbentrennung nach neuer deutscher Rechtschreibung. \RequirePackage[german]{nomencl} @@ -166,7 +166,7 @@ \newcommand{\@appTitle}{Anhang} \renewcommand{\@pdftitle}{\@ifaTitleDE} \renewcommand{\nomname}{Abkürzungs- und Symbolverzeichnis} - \renewcommand{\lstlistlistingname}{Quelltextverzeichnis} + \renewcommand{\lstlistlistingname}{Quelltextverzeichnis} }{ % Englische Pakete \RequirePackage[english]{babel} % Silbentrennung nach englischer Rechtschreibung. @@ -177,7 +177,7 @@ \newcommand{\@appTitle}{Appendix} \renewcommand{\@pdftitle}{\@ifaTitleEN} \renewcommand{\nomname}{Nomenclature} - \renewcommand{\lstlistlistingname}{List of Listings} + \renewcommand{\lstlistlistingname}{List of Listings} } %------------------------------------------------------------------------- @@ -190,7 +190,7 @@ \appendixname~\thechapter\autodot:\enskip} } %------------------------------------------------------------------------- - + % Veränderung der Bildunterschriften und Tabellenüberschriften: \addtokomafont{caption}{\small} % Kleinere Schriftgröße für Captions \setkomafont{captionlabel}{\sffamily\bfseries} % Caption-Label fett und serifenlos @@ -199,8 +199,8 @@ % Anpassung des Literaturverzeichnisses \setlength{\bibitemsep}{10pt} \defbibheading{bibliography}{ - \chapter*{\@bibTitle} - \addcontentsline{toc}{chapter}{\@bibTitle} + \chapter*{\@bibTitle} + \addcontentsline{toc}{chapter}{\@bibTitle} } % Notwendig für Autovervollständigung der Zitate im Texnic Center \renewcommand*{\bibliography}[1]{\addbibresource{#1.bib}} @@ -211,84 +211,107 @@ % Löst Probleme mit deutschen Umlauten in Listings %------------------------------------------------------------------------- \lstset{literate=% - {Ö}{{\"O}}1 - {Ä}{{\"A}}1 - {Ü}{{\"U}}1 - {ß}{{\ss}}2 - {ü}{{\"u}}1 - {ä}{{\"a}}1 - {ö}{{\"o}}1 + {Ö}{{\"O}}1 + {Ä}{{\"A}}1 + {Ü}{{\"U}}1 + {ß}{{\ss}}2 + {ü}{{\"u}}1 + {ä}{{\"a}}1 + {ö}{{\"o}}1 } %------------------------------------------------------------------------- % Integriert Listings und baut diese als Gleitobjekt aus, wenn gewünscht %------------------------------------------------------------------------- -% Usage: \listing{}{