Some characteristics of SHARC Number Representation

Document Sample
Some characteristics of SHARC Number Representation Powered By Docstoc
					   SHARC Processor Characteristics

   Number Representations
   When 1 + 1 = 2
            BUT 2 *2 != 4
              M. R. Smith,
Electrical and Computer Engineering
University of Calgary, Alberta, Canada
       smithmr @ ucalgary.ca
  To tackled
Number Representations are varied
Make sure you understand them
Can solve many coding errors by recognizing
 improper use of number representations
SHARC default number representation for
 integers is not what is expected.
Understanding Number Representations allows
 for extra speed in that 1 in 1000 situation




            Number Representations -- SHARC ADSP21061
3/16/2013     Copyright M. Smith -- smithmr@ucalgary,ca   2 / 28
  Number Representations
Number representations are important.
This is a talk about the number representations
 on the Analog Devices ADSP-21061 SHARC
     Processor has “C-like” syntax for assembly code
     Both single cycle integer and float operations
     32-bit registers (integer and float)
For more information see the article
 Smith, M. R., "Quirks and SHARCs -- Issues in
    programming the Analog Devices SHARC processor.
    When 1 + 1 = 2 but 2 + 2 != 4", Circuit Cellar, March
    2001.
                Number Representations -- SHARC ADSP21061
3/16/2013         Copyright M. Smith -- smithmr@ucalgary,ca   3 / 28
Recap -- Bit patterns in memory

  Bit values stored in memory
      Can represent what you like
      hash table, ascii characters, signed and
       unsigned integer numbers (various
       precisions), floating point numbers etc.
  Certain number representations more
   easily supported by the processor for
   various operations than others.
  On SHARC -- 32 bit integers and FP, also
   40-bit FP (extended FP).
               Number Representations -- SHARC ADSP21061
 3/16/2013       Copyright M. Smith -- smithmr@ucalgary,ca   4 / 28
    Example -- Eight Bit Values
Unsigned 8-bit integers
  Range 0 -- 255, resolution 1
  e.g. 0x00 = 0, 0x10 = 16, 0x7F = 127
  0x80 = 128, 0x81 = 129, 0x90 = ????, 0xC0 = ????
  0xF0 = ????, 0xFE = 254, 0xFF = 255

Signed 8-bit integers -- 2’s complement
  Range -128 to + 127, resolution 1
  e.g. 0x00 = 0, 0x10 = +16, 0x7F = +127
  0x80 = -128, 0x81 = -128 + 1 = -127, 0x90 = ???
  0xF0 = ????, 0xFE = -2, 0xFF = -1


               Number Representations -- SHARC ADSP21061
  3/16/2013      Copyright M. Smith -- smithmr@ucalgary,ca   5 / 28
Floating Point in Binary Representation
      20 (decimal) = 0x14 hex = %0001 0100 (binary)
                              = %0001 0100. 0000 0000 0000

      Normalize binary -- express as %1.frac * 2N

      %0001 0100. 0000 0000 0000 = %1.0100 0000 0000 * 24


      6 = %0110. 0000 0000 = %1.1000 0000 0000 * 22

      Sign = 0 Fraction part = 0.1000 0000 0000
                   Biased Exponent 2 + 127 = 129 = %1000 0001
    Stored as FP Number      0 1000 0001 1000 0000 0000 etc
               0x40C0 0000 = 0100 0000 1100 0000 0000 000
                  Number Representations -- SHARC ADSP21061
 3/16/2013          Copyright M. Smith -- smithmr@ucalgary,ca   6 / 28
  Display Program Code -- Float




            32-bit registers




                 Number Representations -- SHARC ADSP21061
3/16/2013          Copyright M. Smith -- smithmr@ucalgary,ca   7 / 28
                     No such Mode
  Code displayed in Mixedinstruction as F4 =
                                                          Only R4 =
                                                    WARNING --- F4 = 2
                                                    is the same as R4 = 2
                                                 and is DIFFERENT F4 = 2.0
                                                   Note how FP looks like
                                                   VERY LARGE integer




               32 bit registers
                40 bit display
            Ultra High precision
                      FP


                 Number Representations -- SHARC ADSP21061
3/16/2013          Copyright M. Smith -- smithmr@ucalgary,ca       8 / 28
   Need to learn to recognize
What do “integers” look like when they are
 displayed as “floats”
What do “floats” look like when displayed as
 “integers”
   Happens when you pass a pointer to the start of an
       array and then treat the array incorrectly
 I consider the following a BUG IN ASSEMBLER                   NOT
                                                                INTENDED
   F4 = 6 is actually the same as F4 = 3 * 10-45               AS A
   FN = value does not exist -- only RN = value                VERY
                                                                SMALL
   Make sure that you add the decimal point!!!!                VALUE
   .byte4 array_of_FLOATS[] = { 2.8, 3, 3.2, 3.4};

                  Number Representations -- SHARC ADSP21061
 3/16/2013          Copyright M. Smith -- smithmr@ucalgary,ca    9 / 28
  Display Program Code -- Integer




            32 BIT registers


                                         Top 32 bits means something




                           Note how integers look like
                           VERY SMALL floats -- note integer
                           has wrong values – 2 * 3 = 0
                Number Representations -- SHARC ADSP21061
3/16/2013         Copyright M. Smith -- smithmr@ucalgary,ca    10 / 28
Unexpected default integer representation

  68k processor
       Default operations
       Signed and unsigned integer representation
  21k processor / Blackfin / TigerSHARC
       Default operations
       Signed and unsigned integer representation
        of “fractional” values
       Signed and unsigned integer “need to be
        switched on”
  See difference in multiplication
                Number Representations -- SHARC ADSP21061
  3/16/2013       Copyright M. Smith -- smithmr@ucalgary,ca   11 / 28
 Code displayed in Mixed Mode
 Q9 – What happens with Blackfin




            Number Representations -- SHARC ADSP21061
3/16/2013     Copyright M. Smith -- smithmr@ucalgary,ca   12 / 28
  Proper Integer Coding sequence




            Number Representations -- SHARC ADSP21061
3/16/2013     Copyright M. Smith -- smithmr@ucalgary,ca   13 / 28
  Bit meaning in 8-bit signed fractional number




                ^ ACTS AS IF “BINARY POINT”                       HERE
        Binary Pattern             %1001 0011 =

        -1 * 2-0 + 0*2-1 + 0*2-2 + 1* 2-3 + 0* 2-4 + 0* 2-5 + 1* 2-6 + 1* 2-7

        Decimal Calculation = ( 0x93 / 128) = ( 0x80 + 0x13 ) / 128
                             = ( -128 + 19 ) / 128
                             = -1 + 19 / 128

                    Number Representations -- SHARC ADSP21061
3/16/2013             Copyright M. Smith -- smithmr@ucalgary,ca          14 / 28
  Signed fractional
Integer interpreted with a binary point
 just after the sign bit

Using 32-bit values
Smallest value -1.0
Largest almost = + 1.0 = 1.0 - 2^-31
Steps (accuracy) 2^-31


            Number Representations -- SHARC ADSP21061
3/16/2013     Copyright M. Smith -- smithmr@ucalgary,ca   15 / 28
   68k equivalence -- 8-bit example
Standard number format
   Range -128 to + 127, resolution 1
   0x0A+ 0x01 = 0x0B
   %00001010 + %00000001 = %00001011
In any given DSP algorithm it could be useful to scale
 input values so that we have an alternative number
 format where binary point is effectively placed
 between bit #3 and #4
   Range -8 to 7 7/8, resolution 1/8
   0xA0 + 0x10 = 0xB0 (Means 0xA.0, 0x1.0, 0xB.0)
   %1010.0000 + %0001.0000 = %1011.0000
Addition supported in both number formats
               Number Representations -- SHARC ADSP21061
 3/16/2013       Copyright M. Smith -- smithmr@ucalgary,ca   16 / 28
  68k equivalence -- 8-bit example
Standard number format
     Range -128 to + 127, resolution 1
     0x0A * 0x01 = 0x0A
     %00001010 * %00000001 = %00001010
Alternative number format where binary point is
 placed between bit #3 and #4
     Range -8 to 7 7/8, resolution 1/8
     0xA.0 * 0x1.0 = 0x??
     %10100000 * %00010000 = %101000000000
Must now adjust by >> 8 to get correct answer.
 When SHARC in SSF format, the scaling occurs
 automatically
              Number Representations -- SHARC ADSP21061
3/16/2013       Copyright M. Smith -- smithmr@ucalgary,ca   17 / 28
   Equivalent decimal calculation

As done in grade 6
   -0.75 * 0.125
   Perform 75 * 125 then adjust for 5 decimal
    places.
   -9375 then adjust to give -0.09375


68k multiplication was
   0xA.0 * 0x1.0
   Perform 0xA0 * 0x10 then adjust for hex places
   0xA00 then adjust to give 0xA.00
              Number Representations -- SHARC ADSP21061
 3/16/2013      Copyright M. Smith -- smithmr@ucalgary,ca   18 / 28
  Displayed as “signed fractional”




            Number Representations -- SHARC ADSP21061
3/16/2013     Copyright M. Smith -- smithmr@ucalgary,ca   19 / 28
SHARC DIVISION APPEARS WEIRD TOO




             Number Representations -- SHARC ADSP21061
 3/16/2013     Copyright M. Smith -- smithmr@ucalgary,ca   20 / 28
 Actual SHARC division operations
 Note the parallel instructions




            Number Representations -- SHARC ADSP21061
3/16/2013     Copyright M. Smith -- smithmr@ucalgary,ca   21 / 28
  Division is slow
Integer division on 68K -- 70 cycles
     60000 / 3 takes 70 cycles
     60000 / 2 takes 70 cycles
Integer shift takes much less
     60000 / 2 = 60000 >> 1
     ASR #1, D0 (with D0 = 60000) takes 4
      cycles
     21061 -- ASHIFT D0 BY -1 takes 1 cycle
Can we find an equivalent operation for
 floating point scaling (by 2, 4, 8, 16 etc.)?
              Number Representations -- SHARC ADSP21061
3/16/2013       Copyright M. Smith -- smithmr@ucalgary,ca   22 / 28
Signed Fractional -- ASHIFT of integer

                      Works here
                      but that’s cheating since SF format is an
                      floating point interpretation
                      of an integer format




             Number Representations -- SHARC ADSP21061
 3/16/2013     Copyright M. Smith -- smithmr@ucalgary,ca    23 / 28
  Binary Pattern of TRUE floats



              SIGN           EXPONENT                        FRACTIONAL
               BIT             BITS                             BITS


            Floating point division is often SLOW

            DIVIDE BY 2, 4, 8, 16 fast with integers
            CAN ALSO MAKE FAST WITH FLOATS
                 If you understand number representations


               Number Representations -- SHARC ADSP21061
3/16/2013        Copyright M. Smith -- smithmr@ucalgary,ca          24 / 28
  Fast scaling -- Floats as Integers


                                                          Differ
                                                          in
                                                          value
                                                          by 4.0




                                                            Differ
                                                            in
                                                            BEXP
                                                            by 2

            Number Representations -- SHARC ADSP21061
3/16/2013     Copyright M. Smith -- smithmr@ucalgary,ca    25 / 28
  Complete Fast Scaling




            Number Representations -- SHARC ADSP21061
3/16/2013     Copyright M. Smith -- smithmr@ucalgary,ca   26 / 28
  Nothing but a party trick!
            F8 = 0.0625;                          R8 = -4;

                                                   F0 = 4.0;
            F0 = 4.0;                               F1 = SCALEB F0 BY R8;
            F1 = F0 * F8;
                                                    F2   =   2.0;
                                                    F3   =   SCALEB F2 BY R8;
        F2 = 2.0;                                   F4   =   0.0;
        F3 = F3 * F8;                               F5   =   SCALEB F4 BY R8;
        F4 = 0.0;
                                          Works just like our code
        F5 = F4 * F8;
        Since this processor              Advantage – this is a COMPUTE
    has single cycle multiply                operation and NOT a MAC
                                             operation
    operation

                   Number Representations -- SHARC ADSP21061
3/16/2013            Copyright M. Smith -- smithmr@ucalgary,ca              27 / 28
  Learnt today
Number Representations are varied
Make sure you understand them
Can solve many coding errors by recognizing
 improper use of number representations --
 Limitation in SHARC assembler for F4 =
Signed Fractional is default SHARC integer
 representation
Understanding Number Representations allows
 for that 1 in 1000 situation when somebody at a
 party likes to play with DSP processors.

            Number Representations -- SHARC ADSP21061
3/16/2013     Copyright M. Smith -- smithmr@ucalgary,ca   28 / 28

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:0
posted:3/17/2013
language:English
pages:28
ihuang pingba ihuang pingba http://
About