[sim] added SoftFloat-3 source
[riscv-isa-sim.git] / softfloat / SoftFloat-3 / source / s_countLeadingZeros64.c
1
2 #include <stdint.h>
3 #include "primitives.h"
4
5 int softfloat_countLeadingZeros64( uint64_t a )
6 {
7 int count;
8 uint32_t a32;
9
10 count = 32;
11 a32 = a;
12 if ( UINT64_C( 0x100000000 ) <= a ) {
13 count = 0;
14 a32 = a>>32;
15 }
16 /*------------------------------------------------------------------------
17 | From here, result is current count + count leading zeros of `a32'.
18 *------------------------------------------------------------------------*/
19 if ( a32 < 0x10000 ) {
20 count += 16;
21 a32 <<= 16;
22 }
23 if ( a32 < 0x1000000 ) {
24 count += 8;
25 a32 <<= 8;
26 }
27 count += softfloat_countLeadingZeros8[ a32>>24 ];
28 return count;
29
30 }
31