| 1 |
/*=========================================================================== |
| 2 |
* |
| 3 |
* PUBLIC DOMAIN NOTICE |
| 4 |
* National Center for Biotechnology Information |
| 5 |
* |
| 6 |
* This software/database is a "United States Government Work" under the |
| 7 |
* terms of the United States Copyright Act. It was written as part of |
| 8 |
* the author's official duties as a United States Government employee and |
| 9 |
* thus cannot be copyrighted. This software/database is freely available |
| 10 |
* to the public for use. The National Library of Medicine and the U.S. |
| 11 |
* Government have not placed any restriction on its use or reproduction. |
| 12 |
* |
| 13 |
* Although all reasonable efforts have been taken to ensure the accuracy |
| 14 |
* and reliability of the software and data, the NLM and the U.S. |
| 15 |
* Government do not and cannot warrant the performance or results that |
| 16 |
* may be obtained by using this software or data. The NLM and the U.S. |
| 17 |
* Government disclaim all warranties, express or implied, including |
| 18 |
* warranties of performance, merchantability or fitness for any particular |
| 19 |
* purpose. |
| 20 |
* |
| 21 |
* Please cite the author in any work or product based on this material. |
| 22 |
* |
| 23 |
* =========================================================================== |
| 24 |
* |
| 25 |
*/ |
| 26 |
|
| 27 |
#ifndef _h_arch_impl_ |
| 28 |
#define _h_arch_impl_ |
| 29 |
|
| 30 |
#include <stdint.h> |
| 31 |
|
| 32 |
#ifdef __cplusplus |
| 33 |
extern "C" { |
| 34 |
#endif |
| 35 |
|
| 36 |
static __inline__ |
| 37 |
int uint8_lsbit ( uint8_t self ) |
| 38 |
{ |
| 39 |
int i; |
| 40 |
for ( i = 0; ; ++ i ) |
| 41 |
{ |
| 42 |
if ( ( self & ( 1 << i ) ) != 0 ) |
| 43 |
return i; |
| 44 |
} |
| 45 |
return -1; |
| 46 |
} |
| 47 |
|
| 48 |
static __inline__ |
| 49 |
int16_t uint16_lsbit ( uint16_t self ) |
| 50 |
{ |
| 51 |
if ( self == 0 ) |
| 52 |
return -1; |
| 53 |
if ( ( uint8_t ) self != 0 ) |
| 54 |
return uint8_lsbit ( ( uint8_t ) self ); |
| 55 |
return uint8_lsbit ( ( uint8_t ) ( self >> 8 ) ) + 8; |
| 56 |
} |
| 57 |
|
| 58 |
static __inline__ |
| 59 |
int32_t uint32_lsbit ( uint32_t self ) |
| 60 |
{ |
| 61 |
if ( self == 0 ) |
| 62 |
return -1; |
| 63 |
if ( ( uint16_t ) self != 0 ) |
| 64 |
return uint16_lsbit ( ( uint16_t ) self ); |
| 65 |
return uint16_lsbit ( ( uint16_t ) ( self >> 16 ) ) + 16; |
| 66 |
} |
| 67 |
|
| 68 |
typedef struct int128_t int128_t; |
| 69 |
struct int128_t |
| 70 |
{ |
| 71 |
uint64_t lo; |
| 72 |
int64_t hi; |
| 73 |
}; |
| 74 |
|
| 75 |
static __inline__ |
| 76 |
int64_t int128_hi ( const int128_t *self ) |
| 77 |
{ |
| 78 |
return self -> hi; |
| 79 |
} |
| 80 |
|
| 81 |
static __inline__ |
| 82 |
uint64_t int128_lo ( const int128_t *self ) |
| 83 |
{ |
| 84 |
return self -> lo; |
| 85 |
} |
| 86 |
|
| 87 |
static __inline__ |
| 88 |
void int128_sethi ( int128_t *self, int64_t i ) |
| 89 |
{ |
| 90 |
self -> hi = i; |
| 91 |
} |
| 92 |
|
| 93 |
static __inline__ |
| 94 |
void int128_setlo ( int128_t *self, uint64_t i ) |
| 95 |
{ |
| 96 |
self -> lo = i; |
| 97 |
} |
| 98 |
|
| 99 |
typedef struct uint128_t uint128_t; |
| 100 |
struct uint128_t |
| 101 |
{ |
| 102 |
uint64_t lo; |
| 103 |
uint64_t hi; |
| 104 |
}; |
| 105 |
|
| 106 |
static __inline__ |
| 107 |
uint64_t uint128_hi ( const uint128_t *self ) |
| 108 |
{ |
| 109 |
return self -> hi; |
| 110 |
} |
| 111 |
|
| 112 |
static __inline__ |
| 113 |
uint64_t uint128_lo ( const uint128_t *self ) |
| 114 |
{ |
| 115 |
return self -> lo; |
| 116 |
} |
| 117 |
|
| 118 |
static __inline__ |
| 119 |
void uint128_sethi ( uint128_t *self, uint64_t i ) |
| 120 |
{ |
| 121 |
self -> hi = i; |
| 122 |
} |
| 123 |
|
| 124 |
static __inline__ |
| 125 |
void uint128_setlo ( uint128_t *self, uint64_t i ) |
| 126 |
{ |
| 127 |
self -> lo = i; |
| 128 |
} |
| 129 |
|
| 130 |
static __inline__ |
| 131 |
void int128_add ( int128_t *self, const int128_t *i ) |
| 132 |
{ |
| 133 |
uint64_t lo = ( uint32_t ) self -> lo + ( uint32_t ) i -> lo; |
| 134 |
uint64_t hi = ( self -> lo >> 32 ) + ( i -> lo >> 32 ) + lo >> 32; |
| 135 |
self -> hi += i -> hi + ( uint32_t ) ( hi >> 32 ); |
| 136 |
self -> lo = ( hi << 32 ) | ( uint32_t ) lo; |
| 137 |
} |
| 138 |
|
| 139 |
static __inline__ |
| 140 |
void int128_sub ( int128_t *self, const int128_t *i ) |
| 141 |
{ |
| 142 |
int64_t lo = ( uint32_t ) self -> lo - ( uint32_t ) i -> lo; |
| 143 |
int64_t hi = ( uint32_t ) ( self -> lo >> 32 ) - ( uint32_t ) ( i -> lo >> 32 ) + lo >> 32; |
| 144 |
self -> hi -= i -> hi + ( hi >> 32 ); |
| 145 |
self -> lo = ( hi << 32 ) | ( uint32_t ) lo; |
| 146 |
} |
| 147 |
|
| 148 |
static __inline__ |
| 149 |
void int128_sar ( int128_t *self, uint32_t i ) |
| 150 |
{ |
| 151 |
} |
| 152 |
|
| 153 |
static __inline__ |
| 154 |
void int128_shl ( int128_t *self, uint32_t i ) |
| 155 |
{ |
| 156 |
} |
| 157 |
|
| 158 |
static __inline__ |
| 159 |
void uint128_and ( uint128_t *self, const uint128_t *i ) |
| 160 |
{ |
| 161 |
} |
| 162 |
|
| 163 |
static __inline__ |
| 164 |
void uint128_or ( uint128_t *self, const uint128_t *i ) |
| 165 |
{ |
| 166 |
} |
| 167 |
|
| 168 |
static __inline__ |
| 169 |
void uint128_orlo ( uint128_t *self, uint64_t i ) |
| 170 |
{ |
| 171 |
self -> lo |= i; |
| 172 |
} |
| 173 |
|
| 174 |
static __inline__ |
| 175 |
void uint128_xor ( uint128_t *self, const uint128_t *i ) |
| 176 |
{ |
| 177 |
} |
| 178 |
|
| 179 |
static __inline__ |
| 180 |
void uint128_not ( uint128_t *self ) |
| 181 |
{ |
| 182 |
} |
| 183 |
|
| 184 |
static __inline__ |
| 185 |
void uint128_shr ( uint128_t *self, uint32_t i ) |
| 186 |
{ |
| 187 |
} |
| 188 |
|
| 189 |
static __inline__ |
| 190 |
void uint128_shl ( uint128_t *self, uint32_t i ) |
| 191 |
{ |
| 192 |
} |
| 193 |
|
| 194 |
static __inline__ |
| 195 |
void uint128_bswap ( uint128_t *self ) |
| 196 |
{ |
| 197 |
} |
| 198 |
|
| 199 |
static __inline__ |
| 200 |
void uint128_bswap_copy ( uint128_t *to, const uint128_t *from ) |
| 201 |
{ |
| 202 |
} |
| 203 |
|
| 204 |
|
| 205 |
#ifdef __cplusplus |
| 206 |
} |
| 207 |
#endif |
| 208 |
|
| 209 |
#endif /* _h_arch_impl_ */ |