68 typedef unsigned int word;
119 static word* alloc( std::size_t );
120 static void free(
word*, std::size_t );
122 static word* alloc_word( std::size_t size );
123 static void free_word(
word* array, std::size_t size );
140 scfx_mant::alloc( std::size_t size )
142 #if defined( SC_BIG_ENDIAN )
143 return alloc_word( size ) + ( size - 1 );
144 #elif defined( SC_LITTLE_ENDIAN )
145 return alloc_word( size );
151 scfx_mant::free(
word* mant, std::size_t size )
153 #if defined( SC_BIG_ENDIAN )
154 free_word( mant - ( size - 1 ), size );
155 #elif defined( SC_LITTLE_ENDIAN )
156 free_word( mant, size );
164 SC_ASSERT_( i >= 0 && i < m_size,
"mantissa index out of range" );
165 #if defined( SC_BIG_ENDIAN )
167 #elif defined( SC_LITTLE_ENDIAN )
176 SC_ASSERT_( i >= 0 && i < m_size,
"mantissa index out of range" );
177 #if defined( SC_BIG_ENDIAN )
179 #elif defined( SC_LITTLE_ENDIAN )
186 : m_array(0), m_size(size)
188 m_array = alloc( size );
193 : m_array(0), m_size(rhs.m_size)
195 m_array = alloc( m_size );
196 for(
int i = 0; i < m_size; i ++ )
208 if( m_size != rhs.m_size )
210 free( m_array, m_size );
211 m_array = alloc( m_size = rhs.m_size );
214 for(
int i = 0; i < m_size; i ++ )
227 free( m_array, m_size );
235 for(
int i = 0; i < m_size; i ++ )
252 m_array = alloc( m_size = size );
256 word* p = alloc( size );
260 int end =
sc_min( size, m_size );
263 for(
int i = 0; i <
size; i ++ )
267 #if defined( SC_BIG_ENDIAN )
269 #elif defined( SC_LITTLE_ENDIAN )
275 #if defined( SC_BIG_ENDIAN )
277 #elif defined( SC_LITTLE_ENDIAN )
285 for(
int i = 0; i <
size; i ++ )
289 #if defined( SC_BIG_ENDIAN )
290 p[-size+1+i] = m_array[-m_size+1+i];
291 #elif defined( SC_LITTLE_ENDIAN )
292 p[size-1-i] = m_array[m_size-1-i];
297 #if defined( SC_BIG_ENDIAN )
299 #elif defined( SC_LITTLE_ENDIAN )
307 free( m_array, m_size );
317 SC_ASSERT_( ( i >> 1 ) >= 0 && ( i >> 1 ) < m_size,
318 "mantissa index out of range" );
319 #if defined( SC_BIG_ENDIAN )
320 return reinterpret_cast<half_word*
>( m_array )[-i];
321 #elif defined( SC_LITTLE_ENDIAN )
322 return reinterpret_cast<half_word*
>( m_array )[i];
330 SC_ASSERT_( ( i >> 1 ) >= 0 && ( i >> 1 ) < m_size,
331 "mantissa index out of range" );
332 #if defined( SC_BIG_ENDIAN )
333 return reinterpret_cast<half_word*
>( m_array )[-i];
334 #elif defined( SC_LITTLE_ENDIAN )
335 return reinterpret_cast<half_word*
>( m_array )[i];
343 SC_ASSERT_( i >= 0 && i < m_size,
"mantissa index out of range" );
344 #if defined( SC_BIG_ENDIAN )
345 return reinterpret_cast<half_word*
>( m_array - i ) + 1;
346 #elif defined( SC_LITTLE_ENDIAN )
347 return reinterpret_cast<half_word*
>( m_array + i );
360 for(
int i = 0; i < size; i ++ )
362 target[i] = ~source[i];
375 for(
int i = 0; i < mant.
size(); i ++ )
419 void*
operator new( std::size_t sz ) { return ::operator
new( sz ); }
428 scfx_mant_ref::remove_it()
438 : m_mant( 0 ), m_not_const( false )
443 : m_mant( const_cast<
scfx_mant*>( &mant ) ), m_not_const( false )
448 : m_mant( mant ), m_not_const( true )
457 m_mant =
const_cast<scfx_mant*
>( &mant );
void inc(scfx_mant &mant)
#define SC_ASSERT_(cnd, msg)
scfx_mant & operator=(const scfx_mant &)
scfx_mant_ref & operator=(const scfx_mant &)
scfx_mant_free_words_lock()
word operator[](int) const
static pthread_mutex_t m_mutex
A scoped mutex for static word_list* free_words.
~scfx_mant_free_words_lock()
const T sc_min(const T &a, const T &b)
half_word * half_addr(int=0) const
void resize_to(int, int=0)
void complement(scfx_mant &target, const scfx_mant &source, int size)
half_word half_at(int) const