06. Mathematical coprocessor

Base lecture in Russian

Real numbers

Representation

  1. Fixed point: 1231234.21341234

    • Trailing/leading zeros: 1230000000.0/0.0000000123

  2. Floating point: 1.213123·10²³ = 1.213123E23 = 1.213123e+23

    • Normalization $$1<=mantissa<10$$

    • Accidental zeros: 712E+8 + 3e-5 = 71200000000.00003

Real numbers modelling

⇒ float point.

IEEE_754

But no, they thought they're all smartasses.

IEEE_754

Number

31 bit

30-22 bit

22-0 bit

Hexadecimal

Sign

Biased exponent

Mantissa

155.625 (normalized)

0

10000110

00110111010000000000000

431BA000

-5.23E-39 (denormalized)

1

00000000

01110001111001100011101

8038f31d

FPU / C1

Instruction set

More complex instructionx

Examples

Calculate a square root from integer

Caution: lt vs. 1t sucks :(

Caclulate $$e$$ as infinite sum of $$sum_(n=1)^infty 1/(n!)$$

   1 .data
   2 one:    .double 1
   3 ten:    .double 10
   4 .text
   5         l.d     $f2 one         # 1
   6         sub.d   $f4 $f4 $f4     # n
   7         mov.d   $f6 $f2         # n!
   8         mov.d   $f8 $f2         # here will be e
   9         l.d     $f10 ten        # here will be ε
  10         mov.d   $f0 $f2         # decimal length K
  11         li      $v0 5
  12         syscall
  13 
  14 enext:  blez    $v0 edone       # 10**(K+1)
  15         mul.d   $f0 $f0 $f10
  16         subi    $v0 $v0 1
  17         b       enext
  18 edone:  div.d   $f10 $f2 $f0    # ε
  19 
  20 loop:   add.d   $f4 $f4 $f2     # n=n+1
  21         mul.d   $f6 $f6 $f4     # n!=(n-1)!*n
  22         div.d   $f0 $f2 $f6     # next summand
  23         add.d   $f8 $f8 $f0
  24         c.lt.d  $f0 $f10        # next summand < ε
  25         bc1f    loop
  26 
  27         li      $v0 3           # output a double
  28         mov.d   $f12 $f8        # $f12 by syscall standard
  29         syscall

H/W

  1. EJudge: CubicRoot 'Cubical root'

    Input double (positive or negative) float $$1<=|A|<=1000000$$ and $$0.00001<=varepsilon<=0.01$$. Calculate a cubical root of A with closeness $$<=varepsilon$$ (you do not need to round the result). HINT: you always can calculate a cubic power of something!

    Input:

    1000
    0.0001
    Output:

    9.99995
  2. EJudge: FractionTruncate 'Inexact fraction'

    Input three cardinals — A, B and n. Output double float F that has exact n decimal places of A/B. You need to write a subroutine than accepts double f=A/B in $f12 and integer n in $a0 and returns rounded double F in $f0. Hint: $$10^n*A/B < 2^31$$

    Input:

    123
    456
    7
    Output:

    0.2697368
  3. EJudge: LeibPi 'Caclulating Pi'

    Calculate π value using Leibniz_formula_for_π accurate to N decimal places. Input N, output the result. Use function defied in ../Homework_FractionTruncate to truncate out other digits. Keep in mind that the exact formula is calculating π/4, you probably should start with 4 instead 1 to gain exact accuracy. Warning: the algorithm is slow, do not panic, but keep code as simple as possible.

    Input:

    4
    Output:

    3.1416

HSE/ArchitectureASM/06_MathCoprocessor (последним исправлял пользователь FrBrGeorge 2019-11-30 23:34:06)