Subversion Repositories HelenOS-historic

Rev

Rev 698 | Rev 734 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (C) 2005 Josef Cejka
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * - Redistributions of source code must retain the above copyright
  10.  *   notice, this list of conditions and the following disclaimer.
  11.  * - Redistributions in binary form must reproduce the above copyright
  12.  *   notice, this list of conditions and the following disclaimer in the
  13.  *   documentation and/or other materials provided with the distribution.
  14.  * - The name of the author may not be used to endorse or promote products
  15.  *   derived from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  */
  28.  
  29. #include<softfloat.h>
  30. #include<sftypes.h>
  31.  
  32. #include<add.h>
  33. #include<sub.h>
  34. #include<mul.h>
  35. #include<div.h>
  36.  
  37. #include<conversion.h>
  38. #include<comparison.h>
  39. #include<other.h>
  40.  
  41. /* Arithmetic functions */
  42.  
  43. float __addsf3(float a, float b)
  44. {
  45.     float32 fa, fb;
  46.     fa.f=a;
  47.     fb.f=b;
  48.     if (fa.parts.sign!=fb.parts.sign) {
  49.         if (fa.parts.sign) {
  50.             fa.parts.sign=0;
  51.             return subFloat32(fb,fa).f;
  52.         };
  53.         fb.parts.sign=0;
  54.         return subFloat32(fa,fb).f;
  55.     }
  56.     return addFloat32(fa,fb).f;
  57. }
  58.  
  59. float __subsf3(float a, float b)
  60. {
  61.     float32 fa, fb;
  62.     fa.f=a;
  63.     fb.f=b;
  64.     if (fa.parts.sign!=fb.parts.sign) {
  65.         fb.parts.sign=!fb.parts.sign;
  66.         return addFloat32(fa,fb).f;
  67.     }
  68.     return subFloat32(fa,fb).f;
  69. }
  70.  
  71. float __mulsf3(float a, float b)
  72. {
  73.     float32 fa, fb;
  74.     fa.f=a;
  75.     fb.f=b;
  76.     return  mulFloat32(fa, fb).f;
  77. }
  78.  
  79. float __divsf3(float a, float b)
  80. {
  81.     float32 fa, fb;
  82.     fa.f=a;
  83.     fb.f=b;
  84.     //return    divFloat32(fa, fb).f;
  85. }
  86.  
  87. float __negsf2(float a)
  88. {
  89.     float32 fa;
  90.     fa.f=a;
  91.     fa.parts.sign=!fa.parts.sign;
  92.     return fa.f;
  93. }
  94.  
  95. double __negdf2(double a)
  96. {
  97.     float64 fa;
  98.     fa.d=a;
  99.     fa.parts.sign=!fa.parts.sign;
  100.     return fa.d;
  101. }
  102.  
  103. /* Conversion functions */
  104.  
  105. double __extendsfdf2(float a)
  106. {
  107.     float32 fa;
  108.     fa.f = a;
  109.     return convertFloat32ToFloat64(fa).d;
  110. }
  111.  
  112. float __truncdfsf2(double a)
  113. {
  114.     float64 da;
  115.     da.d = a;
  116.     return convertFloat64ToFloat32(da).f;
  117. }
  118.  
  119. /* Comparison functions */
  120.  
  121. /* a<b .. -1
  122.  * a=b ..  0
  123.  * a>b ..  1
  124.  * */
  125.  
  126. int __cmpsf2(float a, float b)
  127. {
  128.     float32 fa,fb;
  129.     fa.f=a;
  130.     fb.f=b;
  131.     if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) {
  132.         return 1; /* no special constant for unordered - maybe signaled? */
  133.     };
  134.  
  135.    
  136.     if (isFloat32eq(fa,fb)) {
  137.         return 0;
  138.     };
  139.    
  140.     if (isFloat32lt(fa,fb)) {
  141.         return -1;
  142.         };
  143.     return 1;
  144. }
  145.  
  146. int __unordsf2(float a, float b)
  147. {
  148.     float32 fa,fb;
  149.     fa.f=a;
  150.     fb.f=b;
  151.     return ((isFloat32NaN(fa))||(isFloat32NaN(fb)));
  152. }
  153.  
  154. /**
  155.  * @return zero, if neither argument is a NaN and are equal
  156.  * */
  157. int __eqsf2(float a, float b)
  158. {
  159.     float32 fa,fb;
  160.     fa.f=a;
  161.     fb.f=b;
  162.     if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) {
  163.         /* TODO: sigNaNs*/
  164.         return 1;
  165.         };
  166.     return isFloat32eq(fa,fb)-1;
  167. }
  168.  
  169. /* strange behavior, but it was in gcc documentation */
  170. int __nesf2(float a, float b)
  171. {
  172.     return __eqsf2(a,b);
  173. }
  174.  
  175. /* return value >= 0 if a>=b and neither is NaN */
  176. int __gesf2(float a, float b)
  177. {
  178.     float32 fa,fb;
  179.     fa.f=a;
  180.     fb.f=b;
  181.     if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) {
  182.         /* TODO: sigNaNs*/
  183.         return -1;
  184.         };
  185.    
  186.     if (isFloat32eq(fa,fb)) {
  187.         return 0;
  188.     };
  189.    
  190.     if (isFloat32gt(fa,fb)) {
  191.         return 1;
  192.         };
  193.    
  194.     return -1;
  195. }
  196.  
  197. /** Return negative value, if a<b and neither is NaN*/
  198. int __ltsf2(float a, float b)
  199. {
  200.     float32 fa,fb;
  201.     fa.f=a;
  202.     fb.f=b;
  203.     if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) {
  204.         /* TODO: sigNaNs*/
  205.         return 1;
  206.         };
  207.     if (isFloat32lt(fa, fb)) {
  208.         return -1;
  209.         };
  210.     return 0;
  211. }
  212.  
  213. /* return value <= 0 if a<=b and neither is NaN */
  214. int __lesf2(float a, float b)
  215. {
  216.     float32 fa,fb;
  217.     fa.f=a;
  218.     fb.f=b;
  219.     if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) {
  220.         /* TODO: sigNaNs*/
  221.         return 1;
  222.         };
  223.    
  224.     if (isFloat32eq(fa,fb)) {
  225.         return 0;
  226.     };
  227.    
  228.     if (isFloat32lt(fa,fb)) {
  229.         return -1;
  230.         };
  231.    
  232.     return 1;
  233. }
  234.  
  235. /** Return positive value, if a>b and neither is NaN*/
  236. int __gtsf2(float a, float b)
  237. {
  238.     float32 fa,fb;
  239.     fa.f=a;
  240.     fb.f=b;
  241.     if ((isFloat32NaN(fa))||(isFloat32NaN(fb))) {
  242.         /* TODO: sigNaNs*/
  243.         return -1;
  244.         };
  245.     if (isFloat32gt(fa, fb)) {
  246.         return 1;
  247.         };
  248.     return 0;
  249. }
  250.  
  251. /* Other functions */
  252.  
  253. float __powisf2(float a, int b)
  254. {
  255. //TODO:
  256. }
  257.  
  258. float __mulsc3(float a, float b, float c, float d)
  259. {
  260. //TODO:
  261. }
  262.  
  263. float __divsc3(float a, float b, float c, float d)
  264. {
  265. //TODO:
  266. }
  267.  
  268.