19.11.2014 Views

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

40.5 <strong>The</strong> Trait <strong>Fortress</strong>.Core.BinaryWord<br />

A value of type BinaryWordb is a binary word of 2 b bits; b may be any natural number, so BinaryWord0 is a<br />

bit, BinaryWord3 is a byte, BinaryWord6 is a 64-bit word, and BinaryWord10 is a 1024-bit word. In fact,<br />

for convenience, the type abbreviations Bit and Byte are defined:<br />

type Bit = BinaryWord0<br />

type Byte = BinaryWord3<br />

<strong>The</strong> type BinaryWordb has 2 (2b) distinct values. When the binary word is regarded as an unsigned integer, these<br />

values are identified with the nonnegative integers that are less than 2 (2b) . A binary word may also be regarded as a<br />

signed integer: a value that, when regarded as an unsigned integer, is identified with an integer less than 2 (2b −1) , is<br />

identified with that same integer when regarded as a signed integer; but a value that, when regarded as an unsigned<br />

integer, is identified with an integer not less than 2 (2b −1) , is identified with that same integer less 2 (2b) . (This is the<br />

standard “two’s complement” representation for signed integers.)<br />

A binary word of one bit can have one of two values, 0 or 1. A binary word of more than one bit has two halves, a<br />

high half and a low half, which are binary words of half the size. If v is the unsigned integer value of a binary word<br />

of 2 b bits, b ≥ 1 , h is the unsigned integer value of its high half, and l is the unsigned integer value of its low half,<br />

then v = h · 2 2b−1 + l .<br />

Operations on binary words include bitwise boolean operations, arithmetic operations, shifts and rotates, population<br />

count, and counting of leading and trailing zeros. <strong>The</strong> type BinaryWordb is not “endian” and has no operations<br />

that depend on endianness. However, if w is binary word, then w.littleEndian is a little-endian version of w and<br />

w.bigEndian is a big-endian version of w ; for example, if w is of type BinaryWord6 , then w.littleEndian 63 is<br />

the most significant bit (the sign bit if the word is regarded as a two’s-complement integer), and w.bigEndian 0 is that<br />

same bit.<br />

trait BinaryWordnat b extends { BasicBinaryWordOperationsBinaryWordb }<br />

comprises {}<br />

where { b ≤ maxBinaryWordBitLog }<br />

coercion int r(x:IntegerStaticr) where { −2 b−1 ≤ r < 2 b }<br />

coercion bool bigEndianBytes,bool bigEndianBits<br />

(x:BinaryEndianWordb,bigEndianBytes,bigEndianBits)<br />

coercion nat b ′ ,nat n,bool bigEndianSequence<br />

(x:BinaryLinearEndianSequenceb ′ , n,bigEndianSequence)<br />

where { 2 b = n · 2 b′ }<br />

coercion nat b ′ ,bool bigEndianBytes,bool bigEndianBits,nat n,bool bigEndianSequence<br />

(x:BinaryEndianLinearEndianSequenceb ′ ,bigEndianBytes,bigEndianBits,<br />

n,bigEndianSequence)<br />

where { 2 b = n · 2 b′ }<br />

bit(m:IndexInt):Bit<br />

getter lowHalf ():BinaryWordb − 1 where { b > 0 }<br />

getter highHalf ():BinaryWordb − 1 where { b > 0 }<br />

opr ‖ nat m(self,other: BinaryWordb): BinaryWordb + 1<br />

where { b < maxBinaryWordBitLog }<br />

bitShuffle(other: BinaryWordb):BinaryWordb + 1<br />

where { b < maxBinaryWordBitLog }<br />

bitUnshuffle():(BinaryWordb − 1, BinaryWordb − 1) where { b > 0 }<br />

end<br />

279

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!