Tuesday, October 25, 2011

High Performance Assembly Language

The Core i7 CPU offers the Advanced Vector Extensions (AVX) which expand on the capabilities of the Streaming SIMD Extensions (SSE) instructions.  SSE added additional floating point and integer capabilities to the CPU, in particular the registers used by SSE (xmm0, xmm1,...) are 128 bits each and these bits can be used to store multiple integers of various lengths and also multiple floating point values.  The instructions operating on these multiple values are referred to as SIMD (single-instruction multiple-data) instructions.  With the AVX instructions the registers are extended to 256 bits, though the integer instructions only operate on 128 bit quantities.

Here I will present some simple code which will be extended profitably to improve performance.  The keys to success here are loop unrolling, using independent registers for the unrolling and using specialized instructions.  In the process there will be several versions of the basic function which perform better than the basic C code optimized with loop unrolling by the gcc compiler.

Sunday, October 23, 2011

Nook Book now on Sale

From all I had seen I expected the Nook version (EPUB format) of my Assembly Language book to be a snap.  It was relatively easy, but not quite trivial.

Problem number 1 for the Nook was that the Nook didn't allow view in landscape mode.  My assembly code has a moderate number of end-of-line comments.  Many of these wrapped onto the next line.  With the Kindle I had been able to view my book in landscape mode which handled at least 3/4 of the lines properly.  I had quite a few lines to repair.  Some I fixed with creative substitutions, but some I had to extend onto the next line.

The next problem worth reporting is having a 2 appear at the top of one set of exercises.  This 2 came from the second list item.  It made no sense that the 2 would appear at the top of the page.  The same HTML rendered properly on the Kindle.  Eventually I removed all <p> and </p> tags from that set of exercises.  I also converted a <blockquote> section to preformatted.  Now the same HTML works for Nook and Kindle.

It was perhaps 4 hours work to repair things for the Nook.  It is now available for sale.

The Nook version is EPUB format which should be portable to iPad, Sony eReader and most other devices.  It is DRM-free so people shouldn't run into DRM roadblocks.

Friday, October 21, 2011

Finally Published a Kindle Version of the Assembly Language Book

I received a request from a person teaching 64 bit assembly language at another university for a Kindle version of my textbook.  I had been studying the issue of and on for a few months.  I knew that the Kindle format was based on HTML, but it was difficult to determine exactly what commands worked on the Kindle.  I had tried a few tools - Calibre and kindlegen on Linux and the mobibook creator for Windows.  It seemed like epub was going to work fairly well, while mobi was a bit of trouble.

I decided that I had to have a Kindle to test my work, so I ordered one for $79 and set about converting my book from LaTeX markup to HTML markup.  As I did this I previewed the results in Firefox and got things in fairly good order by Tuesday when the Kindle arrived.  Immediately I discovered that some of the problems I observed in previewers did not exist on the Kindle.  It looked possible.

One issue was displaying diagrams I had created using xfig.  I tried gif, png and jpeg and all were ugly in the previewers.  For the printed book I had used PDF files created by xfig for all the diagrams.  Eventually I tried using gimp to convert the images to jpeg.  This worked very well.  gimp asked for the number of dots per inch at the start of importing each PDF file and I used this to generate images with widths which are small enough for the Kindle.  The Kindle likes to scale images to fit the width of its screen which is not what the HTML standard dictates, but at least I have nice looking diagrams though frequently a bit large.

Most of my use of math mode in LaTeX was fairly simple and I converted these to HTML using <sup> and <sub> tags along with using tables for alignment.  This was fairly successful, but I had a few fairly complex formulas to render.

I copied the LaTeX commands for the complex formulas to separate files and ran pdflatex to convert to PDF.  Then I used gimp to crop the images for inclusion as jpeg images in my HTML book.  These images looked great on the Kindle though they are generally too large.

I used <blockquote> to indent quite a few tables in the book.  I decided that indenting looked better than centering.

Kindlegen has a sample document which includes a manifest file (OPF) and a table of contents file (NDX) which I adapted for my purposes to create a complete Kindle document matching the Amazon requirements.  I submitted the ebook on Thursday afternoon and by Friday morning it was up, complete with "Look Inside", and I had 1 sale.  Curiously the "Look Inside" preview displayed my indented table flush left, so I downloaded a sample of the book to my Kindle.  The tables were indented.  Still the preview looked fine otherwise and is good enough for my purposes.

I spent 7 days working on the conversion, averaging perhaps 4 hours each day.  That's a lot markup changes.  Now I think I know enough to invent my own markup which could be used to generate LaTeX and HTML from a common source.

It's on sale here.

Now it's time for an epub version for Barnes and Noble...