Hex Artifact Content
Not logged in

Artifact b556c772c113d69e4dc8669b33f2516a5672a342:


0000: 2f 2f 3d 3d 3d 2d 2d 20 6c 69 62 2f 66 6c 6f 61  //===-- lib/floa
0010: 74 73 69 74 66 2e 63 20 2d 20 69 6e 74 65 67 65  tsitf.c - intege
0020: 72 20 2d 3e 20 71 75 61 64 2d 70 72 65 63 69 73  r -> quad-precis
0030: 69 6f 6e 20 63 6f 6e 76 65 72 73 69 6f 6e 20 2d  ion conversion -
0040: 2d 2d 2d 2a 2d 20 43 20 2d 2a 2d 3d 3d 3d 2f 2f  ---*- C -*-===//
0050: 0a 2f 2f 0a 2f 2f 20 20 20 20 20 20 20 20 20 20  .//.//          
0060: 20 20 20 20 20 20 20 20 20 20 20 54 68 65 20 4c             The L
0070: 4c 56 4d 20 43 6f 6d 70 69 6c 65 72 20 49 6e 66  LVM Compiler Inf
0080: 72 61 73 74 72 75 63 74 75 72 65 0a 2f 2f 0a 2f  rastructure.//./
0090: 2f 20 54 68 69 73 20 66 69 6c 65 20 69 73 20 64  / This file is d
00a0: 75 61 6c 20 6c 69 63 65 6e 73 65 64 20 75 6e 64  ual licensed und
00b0: 65 72 20 74 68 65 20 4d 49 54 20 61 6e 64 20 74  er the MIT and t
00c0: 68 65 20 55 6e 69 76 65 72 73 69 74 79 20 6f 66  he University of
00d0: 20 49 6c 6c 69 6e 6f 69 73 20 4f 70 65 6e 0a 2f   Illinois Open./
00e0: 2f 20 53 6f 75 72 63 65 20 4c 69 63 65 6e 73 65  / Source License
00f0: 73 2e 20 53 65 65 20 4c 49 43 45 4e 53 45 2e 54  s. See LICENSE.T
0100: 58 54 20 66 6f 72 20 64 65 74 61 69 6c 73 2e 0a  XT for details..
0110: 2f 2f 0a 2f 2f 3d 3d 3d 2d 2d 2d 2d 2d 2d 2d 2d  //.//===--------
0120: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0130: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0140: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0150: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 3d 3d  --------------==
0160: 3d 2f 2f 0a 2f 2f 0a 2f 2f 20 54 68 69 73 20 66  =//.//.// This f
0170: 69 6c 65 20 69 6d 70 6c 65 6d 65 6e 74 73 20 69  ile implements i
0180: 6e 74 65 67 65 72 20 74 6f 20 71 75 61 64 2d 70  nteger to quad-p
0190: 72 65 63 69 73 69 6f 6e 20 63 6f 6e 76 65 72 73  recision convers
01a0: 69 6f 6e 20 66 6f 72 20 74 68 65 0a 2f 2f 20 63  ion for the.// c
01b0: 6f 6d 70 69 6c 65 72 2d 72 74 20 6c 69 62 72 61  ompiler-rt libra
01c0: 72 79 20 69 6e 20 74 68 65 20 49 45 45 45 2d 37  ry in the IEEE-7
01d0: 35 34 20 64 65 66 61 75 6c 74 20 72 6f 75 6e 64  54 default round
01e0: 2d 74 6f 2d 6e 65 61 72 65 73 74 2c 20 74 69 65  -to-nearest, tie
01f0: 73 2d 74 6f 2d 65 76 65 6e 0a 2f 2f 20 6d 6f 64  s-to-even.// mod
0200: 65 2e 0a 2f 2f 0a 2f 2f 3d 3d 3d 2d 2d 2d 2d 2d  e..//.//===-----
0210: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0220: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0230: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0240: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0250: 2d 3d 3d 3d 2f 2f 0a 0a 23 64 65 66 69 6e 65 20  -===//..#define 
0260: 51 55 41 44 5f 50 52 45 43 49 53 49 4f 4e 0a 23  QUAD_PRECISION.#
0270: 69 6e 63 6c 75 64 65 20 22 66 70 5f 6c 69 62 2e  include "fp_lib.
0280: 68 22 0a 0a 23 69 66 20 64 65 66 69 6e 65 64 28  h"..#if defined(
0290: 43 52 54 5f 48 41 53 5f 31 32 38 42 49 54 29 20  CRT_HAS_128BIT) 
02a0: 26 26 20 64 65 66 69 6e 65 64 28 43 52 54 5f 4c  && defined(CRT_L
02b0: 44 42 4c 5f 31 32 38 42 49 54 29 0a 43 4f 4d 50  DBL_128BIT).COMP
02c0: 49 4c 45 52 5f 52 54 5f 41 42 49 20 66 70 5f 74  ILER_RT_ABI fp_t
02d0: 20 5f 5f 66 6c 6f 61 74 73 69 74 66 28 69 6e 74   __floatsitf(int
02e0: 20 61 29 20 7b 0a 0a 20 20 20 20 63 6f 6e 73 74   a) {..    const
02f0: 20 69 6e 74 20 61 57 69 64 74 68 20 3d 20 73 69   int aWidth = si
0300: 7a 65 6f 66 20 61 20 2a 20 43 48 41 52 5f 42 49  zeof a * CHAR_BI
0310: 54 3b 0a 0a 20 20 20 20 2f 2f 20 48 61 6e 64 6c  T;..    // Handl
0320: 65 20 7a 65 72 6f 20 61 73 20 61 20 73 70 65 63  e zero as a spec
0330: 69 61 6c 20 63 61 73 65 20 74 6f 20 70 72 6f 74  ial case to prot
0340: 65 63 74 20 63 6c 7a 0a 20 20 20 20 69 66 20 28  ect clz.    if (
0350: 61 20 3d 3d 20 30 29 0a 20 20 20 20 20 20 20 20  a == 0).        
0360: 72 65 74 75 72 6e 20 66 72 6f 6d 52 65 70 28 30  return fromRep(0
0370: 29 3b 0a 0a 20 20 20 20 2f 2f 20 41 6c 6c 20 6f  );..    // All o
0380: 74 68 65 72 20 63 61 73 65 73 20 62 65 67 69 6e  ther cases begin
0390: 20 62 79 20 65 78 74 72 61 63 74 69 6e 67 20 74   by extracting t
03a0: 68 65 20 73 69 67 6e 20 61 6e 64 20 61 62 73 6f  he sign and abso
03b0: 6c 75 74 65 20 76 61 6c 75 65 20 6f 66 20 61 0a  lute value of a.
03c0: 20 20 20 20 72 65 70 5f 74 20 73 69 67 6e 20 3d      rep_t sign =
03d0: 20 30 3b 0a 20 20 20 20 75 6e 73 69 67 6e 65 64   0;.    unsigned
03e0: 20 61 41 62 73 20 3d 20 28 75 6e 73 69 67 6e 65   aAbs = (unsigne
03f0: 64 29 61 3b 0a 20 20 20 20 69 66 20 28 61 20 3c  d)a;.    if (a <
0400: 20 30 29 20 7b 0a 20 20 20 20 20 20 20 20 73 69   0) {.        si
0410: 67 6e 20 3d 20 73 69 67 6e 42 69 74 3b 0a 20 20  gn = signBit;.  
0420: 20 20 20 20 20 20 61 41 62 73 20 3d 20 7e 28 75        aAbs = ~(u
0430: 6e 73 69 67 6e 65 64 29 61 20 2b 20 31 55 3b 0a  nsigned)a + 1U;.
0440: 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2f 20 45 78      }..    // Ex
0450: 70 6f 6e 65 6e 74 20 6f 66 20 28 66 70 5f 74 29  ponent of (fp_t)
0460: 61 20 69 73 20 74 68 65 20 77 69 64 74 68 20 6f  a is the width o
0470: 66 20 61 62 73 28 61 29 2e 0a 20 20 20 20 63 6f  f abs(a)..    co
0480: 6e 73 74 20 69 6e 74 20 65 78 70 6f 6e 65 6e 74  nst int exponent
0490: 20 3d 20 28 61 57 69 64 74 68 20 2d 20 31 29 20   = (aWidth - 1) 
04a0: 2d 20 5f 5f 62 75 69 6c 74 69 6e 5f 63 6c 7a 28  - __builtin_clz(
04b0: 61 41 62 73 29 3b 0a 20 20 20 20 72 65 70 5f 74  aAbs);.    rep_t
04c0: 20 72 65 73 75 6c 74 3b 0a 0a 20 20 20 20 2f 2f   result;..    //
04d0: 20 53 68 69 66 74 20 61 20 69 6e 74 6f 20 74 68   Shift a into th
04e0: 65 20 73 69 67 6e 69 66 69 63 61 6e 64 20 66 69  e significand fi
04f0: 65 6c 64 20 61 6e 64 20 63 6c 65 61 72 20 74 68  eld and clear th
0500: 65 20 69 6d 70 6c 69 63 69 74 20 62 69 74 2e 0a  e implicit bit..
0510: 20 20 20 20 63 6f 6e 73 74 20 69 6e 74 20 73 68      const int sh
0520: 69 66 74 20 3d 20 73 69 67 6e 69 66 69 63 61 6e  ift = significan
0530: 64 42 69 74 73 20 2d 20 65 78 70 6f 6e 65 6e 74  dBits - exponent
0540: 3b 0a 20 20 20 20 72 65 73 75 6c 74 20 3d 20 28  ;.    result = (
0550: 72 65 70 5f 74 29 61 41 62 73 20 3c 3c 20 73 68  rep_t)aAbs << sh
0560: 69 66 74 20 5e 20 69 6d 70 6c 69 63 69 74 42 69  ift ^ implicitBi
0570: 74 3b 0a 0a 20 20 20 20 2f 2f 20 49 6e 73 65 72  t;..    // Inser
0580: 74 20 74 68 65 20 65 78 70 6f 6e 65 6e 74 0a 20  t the exponent. 
0590: 20 20 20 72 65 73 75 6c 74 20 2b 3d 20 28 72 65     result += (re
05a0: 70 5f 74 29 28 65 78 70 6f 6e 65 6e 74 20 2b 20  p_t)(exponent + 
05b0: 65 78 70 6f 6e 65 6e 74 42 69 61 73 29 20 3c 3c  exponentBias) <<
05c0: 20 73 69 67 6e 69 66 69 63 61 6e 64 42 69 74 73   significandBits
05d0: 3b 0a 20 20 20 20 2f 2f 20 49 6e 73 65 72 74 20  ;.    // Insert 
05e0: 74 68 65 20 73 69 67 6e 20 62 69 74 20 61 6e 64  the sign bit and
05f0: 20 72 65 74 75 72 6e 0a 20 20 20 20 72 65 74 75   return.    retu
0600: 72 6e 20 66 72 6f 6d 52 65 70 28 72 65 73 75 6c  rn fromRep(resul
0610: 74 20 7c 20 73 69 67 6e 29 3b 0a 7d 0a 0a 23 65  t | sign);.}..#e
0620: 6e 64 69 66 0a                                   ndif.