Simple Scalar

# Simple Scalar - 10 10 10 100 d e h l o r w The reason for...

This preview shows pages 1–2. Sign up to view the full content.

/* * Anagram program by Raymond Chen, * inspired by a similar program by Brian Scearce * * This program is Copyright 1991 by Raymond Chen. * * * This program may be freely distributed provided all alterations * to the original are clearly indicated as such. */ /* There are two tricks. First is the Basic Idea: * * When the user types in a phrase, the phrase is first preprocessed to * determine how many of each letter appears. A bit field is then constructed * dynamically, such that each field is large enough to hold the next power * of two larger than the number of times the character appears. For example, * if the phrase is hello, world, the bit field would be * * 00 00 00 000 000 00 00 * d e h l o r w * * The phrase hello, world, itself would be encoded as * * 01 01 01 011 010 01 01 * d e h l o r w * * and the word hollow would be encoded as * * 00 00 01 010 010 00 01 * d e h l o r w * * The top bit of each field is set in a special value called the sign. * Here, the sign would be

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: * * 10 10 10 100 100 10 10 * d e h l o r w * * The reason for packing the values into a bit field is that the operation * of subtracting out the letters of a word from the current phrase can be * carried out in parallel. for example, subtracting the word hello from * the phrase hello, world, is merely * * d e h l o r w * 01 01 01 011 010 01 01 (dehllloorw) * - 00 00 01 010 010 00 01 (hlloow) * ======================== * 01 01 00 001 000 01 00 (delr) * * Since none of the sign bits is set, the word fits, and we can continue. * Suppose the next word we tried was hood. * * d e h l o r w * 01 01 00 001 000 01 00 (delr) * - 01 00 01 000 010 00 00 (hood) * ======================== * 00 00 11 000 110 01 00 * ^ ^ * A sign bit is set. (Two, actually.) This means that hood does not * fit in delr, so we skip it and try another word. (Observe that * when a sign bit becomes set, it screws up the values for the letters to...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

Simple Scalar - 10 10 10 100 d e h l o r w The reason for...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online