scfx_other_defs.h revision 12027
112839Sgabeblack@google.com/*****************************************************************************
212839Sgabeblack@google.com
312839Sgabeblack@google.com  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
412839Sgabeblack@google.com  more contributor license agreements.  See the NOTICE file distributed
512839Sgabeblack@google.com  with this work for additional information regarding copyright ownership.
612839Sgabeblack@google.com  Accellera licenses this file to you under the Apache License, Version 2.0
712839Sgabeblack@google.com  (the "License"); you may not use this file except in compliance with the
812839Sgabeblack@google.com  License.  You may obtain a copy of the License at
912839Sgabeblack@google.com
1012839Sgabeblack@google.com    http://www.apache.org/licenses/LICENSE-2.0
1112839Sgabeblack@google.com
1212839Sgabeblack@google.com  Unless required by applicable law or agreed to in writing, software
1312839Sgabeblack@google.com  distributed under the License is distributed on an "AS IS" BASIS,
1412839Sgabeblack@google.com  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1512839Sgabeblack@google.com  implied.  See the License for the specific language governing
1612839Sgabeblack@google.com  permissions and limitations under the License.
1712839Sgabeblack@google.com
1812839Sgabeblack@google.com *****************************************************************************/
1912839Sgabeblack@google.com
2012839Sgabeblack@google.com/*****************************************************************************
2112839Sgabeblack@google.com
2212839Sgabeblack@google.com  scfx_other_defs.h -
2312839Sgabeblack@google.com
2412839Sgabeblack@google.com  Original Author: Martin Janssen, Synopsys, Inc.
2512839Sgabeblack@google.com
2612839Sgabeblack@google.com *****************************************************************************/
2712839Sgabeblack@google.com
2812839Sgabeblack@google.com/*****************************************************************************
2912839Sgabeblack@google.com
3012839Sgabeblack@google.com  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
3112993Sgabeblack@google.com  changes you are making here.
3212993Sgabeblack@google.com
3312993Sgabeblack@google.com      Name, Affiliation, Date:
3413129Sgabeblack@google.com  Description of Modification:
3512993Sgabeblack@google.com
3612839Sgabeblack@google.com *****************************************************************************/
3712839Sgabeblack@google.com
3812993Sgabeblack@google.com// $Log: scfx_other_defs.h,v $
3912993Sgabeblack@google.com// Revision 1.1.1.1  2006/12/15 20:20:04  acg
4012993Sgabeblack@google.com// SystemC 2.3
4112993Sgabeblack@google.com//
4212993Sgabeblack@google.com// Revision 1.3  2006/01/13 18:53:58  acg
4312993Sgabeblack@google.com// Andy Goodrich: added $Log command so that CVS comments are reproduced in
4412993Sgabeblack@google.com// the source.
4512993Sgabeblack@google.com//
4612993Sgabeblack@google.com
4712993Sgabeblack@google.com#ifndef SCFX_OTHER_DEFS_H
4812993Sgabeblack@google.com#define SCFX_OTHER_DEFS_H
4912993Sgabeblack@google.com
5012993Sgabeblack@google.com
5112993Sgabeblack@google.com#include "sysc/datatypes/fx/sc_fx_ids.h"
5212993Sgabeblack@google.com#include "sysc/datatypes/int/sc_signed.h"
5312993Sgabeblack@google.com#include "sysc/datatypes/int/sc_unsigned.h"
5412993Sgabeblack@google.com#include "sysc/datatypes/int/sc_int_base.h"
5512993Sgabeblack@google.com#include "sysc/datatypes/int/sc_uint_base.h"
5612993Sgabeblack@google.com#include "sysc/tracing/sc_trace.h"
5712993Sgabeblack@google.com
5812993Sgabeblack@google.com
5912993Sgabeblack@google.comnamespace sc_dt
6012993Sgabeblack@google.com{
6112993Sgabeblack@google.com
6212993Sgabeblack@google.com#ifdef SC_INCLUDE_FX
6313129Sgabeblack@google.com
6413129Sgabeblack@google.com// ----------------------------------------------------------------------------
6513129Sgabeblack@google.com//  CLASS : sc_signed
6613129Sgabeblack@google.com// ----------------------------------------------------------------------------
6712993Sgabeblack@google.com
6812993Sgabeblack@google.com// assignment operators
6913129Sgabeblack@google.com
7012993Sgabeblack@google.cominline
7113129Sgabeblack@google.comconst sc_signed&
7212993Sgabeblack@google.comsc_signed::operator = ( const sc_fxval& v )
7312993Sgabeblack@google.com{
7412993Sgabeblack@google.com    if( ! v.is_normal() ) /* also triggers OBSERVER_READ call */
7512993Sgabeblack@google.com    {
7612993Sgabeblack@google.com	SC_REPORT_ERROR( sc_core::SC_ID_INVALID_FX_VALUE_,
7712993Sgabeblack@google.com			 "sc_signed::operator = ( const sc_fxval& )" );
7812993Sgabeblack@google.com    }
7912993Sgabeblack@google.com
8012993Sgabeblack@google.com    for( int i = 0; i < length(); ++ i )
8112993Sgabeblack@google.com	(*this)[i] = v.get_bit( i );
8212993Sgabeblack@google.com
8312993Sgabeblack@google.com    return *this;
8412993Sgabeblack@google.com}
8512993Sgabeblack@google.com
8612993Sgabeblack@google.cominline
8712993Sgabeblack@google.comconst sc_signed&
8812993Sgabeblack@google.comsc_signed::operator = ( const sc_fxval_fast& v )
8912993Sgabeblack@google.com{
9012993Sgabeblack@google.com    if( ! v.is_normal() ) /* also triggers OBSERVER_READ call */
9112993Sgabeblack@google.com    {
9212993Sgabeblack@google.com	SC_REPORT_ERROR( sc_core::SC_ID_INVALID_FX_VALUE_,
9312993Sgabeblack@google.com			 "sc_signed::operator = ( const sc_fxval_fast& )" );
9412993Sgabeblack@google.com    }
9512993Sgabeblack@google.com
9612993Sgabeblack@google.com    for( int i = 0; i < length(); ++ i )
9712993Sgabeblack@google.com	(*this)[i] = v.get_bit( i );
9812993Sgabeblack@google.com
9912993Sgabeblack@google.com    return *this;
10012839Sgabeblack@google.com}
10112839Sgabeblack@google.com
10212839Sgabeblack@google.cominline
10312993Sgabeblack@google.comconst sc_signed&
10412993Sgabeblack@google.comsc_signed::operator = ( const sc_fxnum& v )
10512993Sgabeblack@google.com{
10612839Sgabeblack@google.com    if( ! v.is_normal() ) /* also triggers OBSERVER_READ call */
10712839Sgabeblack@google.com    {
10812839Sgabeblack@google.com	SC_REPORT_ERROR( sc_core::SC_ID_INVALID_FX_VALUE_,
10912839Sgabeblack@google.com			 "sc_signed::operator = ( const sc_fxnum& )" );
11012839Sgabeblack@google.com    }
11112993Sgabeblack@google.com
11212839Sgabeblack@google.com    for( int i = 0; i < length(); ++ i )
11312839Sgabeblack@google.com	(*this)[i] = v.get_bit( i );
11412839Sgabeblack@google.com
11512839Sgabeblack@google.com    return *this;
11612839Sgabeblack@google.com}
11712993Sgabeblack@google.com
11812839Sgabeblack@google.cominline
11912839Sgabeblack@google.comconst sc_signed&
12012839Sgabeblack@google.comsc_signed::operator = ( const sc_fxnum_fast& v )
12112993Sgabeblack@google.com{
12212839Sgabeblack@google.com    if( ! v.is_normal() ) /* also triggers OBSERVER_READ call */
12312993Sgabeblack@google.com    {
12412839Sgabeblack@google.com	SC_REPORT_ERROR( sc_core::SC_ID_INVALID_FX_VALUE_,
12512839Sgabeblack@google.com			 "sc_signed::operator = ( const sc_fxnum_fast& )" );
12612839Sgabeblack@google.com    }
12712839Sgabeblack@google.com
12812993Sgabeblack@google.com    for( int i = 0; i < length(); ++ i )
12912839Sgabeblack@google.com	(*this)[i] = v.get_bit( i );
13012993Sgabeblack@google.com
13112839Sgabeblack@google.com    return *this;
13212839Sgabeblack@google.com}
13312839Sgabeblack@google.com
13412993Sgabeblack@google.com
13512839Sgabeblack@google.com// ----------------------------------------------------------------------------
13612993Sgabeblack@google.com//  CLASS : sc_unsigned
13712839Sgabeblack@google.com// ----------------------------------------------------------------------------
13812839Sgabeblack@google.com
13912839Sgabeblack@google.com// assignment operators
14012993Sgabeblack@google.com
14112839Sgabeblack@google.cominline
14212993Sgabeblack@google.comconst sc_unsigned&
14312839Sgabeblack@google.comsc_unsigned::operator = ( const sc_fxval& v )
14412839Sgabeblack@google.com{
14512839Sgabeblack@google.com    if( ! v.is_normal() ) /* also triggers OBSERVER_READ call */
14612993Sgabeblack@google.com    {
14712839Sgabeblack@google.com	SC_REPORT_ERROR( sc_core::SC_ID_INVALID_FX_VALUE_,
14812993Sgabeblack@google.com			 "sc_unsigned::operator = ( const sc_fxval& )" );
14912839Sgabeblack@google.com    }
15012839Sgabeblack@google.com
15112839Sgabeblack@google.com    for( int i = 0; i < length(); ++ i )
15212993Sgabeblack@google.com	(*this)[i] = v.get_bit( i );
15312839Sgabeblack@google.com
15412993Sgabeblack@google.com    return *this;
15512839Sgabeblack@google.com}
15612839Sgabeblack@google.com
15712839Sgabeblack@google.cominline
15812839Sgabeblack@google.comconst sc_unsigned&
15912839Sgabeblack@google.comsc_unsigned::operator = ( const sc_fxval_fast& v )
16012839Sgabeblack@google.com{
16112839Sgabeblack@google.com    if( ! v.is_normal() ) /* also triggers OBSERVER_READ call */
16212839Sgabeblack@google.com    {
16312839Sgabeblack@google.com	SC_REPORT_ERROR( sc_core::SC_ID_INVALID_FX_VALUE_,
16412839Sgabeblack@google.com			 "sc_unsigned::operator = ( const sc_fxval_fast& )" );
16512839Sgabeblack@google.com    }
16612839Sgabeblack@google.com
16712839Sgabeblack@google.com    for( int i = 0; i < length(); ++ i )
16812839Sgabeblack@google.com	(*this)[i] = v.get_bit( i );
16912839Sgabeblack@google.com
17012839Sgabeblack@google.com    return *this;
17112839Sgabeblack@google.com}
17212839Sgabeblack@google.com
17312839Sgabeblack@google.cominline
17412839Sgabeblack@google.comconst sc_unsigned&
17512839Sgabeblack@google.comsc_unsigned::operator = ( const sc_fxnum& v )
17612839Sgabeblack@google.com{
17712839Sgabeblack@google.com    if( ! v.is_normal() ) /* also triggers OBSERVER_READ call */
17812839Sgabeblack@google.com    {
17912839Sgabeblack@google.com	SC_REPORT_ERROR( sc_core::SC_ID_INVALID_FX_VALUE_,
18012839Sgabeblack@google.com			 "sc_unsigned::operator = ( const sc_fxnum& )" );
18112839Sgabeblack@google.com    }
18212839Sgabeblack@google.com
18312839Sgabeblack@google.com    for( int i = 0; i < length(); ++ i )
18412839Sgabeblack@google.com	(*this)[i] = v.get_bit( i );
18512839Sgabeblack@google.com
18612839Sgabeblack@google.com    return *this;
18712839Sgabeblack@google.com}
18812839Sgabeblack@google.com
18912839Sgabeblack@google.cominline
19012839Sgabeblack@google.comconst sc_unsigned&
19112839Sgabeblack@google.comsc_unsigned::operator = ( const sc_fxnum_fast& v )
19212839Sgabeblack@google.com{
19312839Sgabeblack@google.com    if( ! v.is_normal() ) /* also triggers OBSERVER_READ call */
19412839Sgabeblack@google.com    {
19512839Sgabeblack@google.com	SC_REPORT_ERROR( sc_core::SC_ID_INVALID_FX_VALUE_,
19612839Sgabeblack@google.com			 "sc_unsigned::operator = ( const sc_fxnum_fast& )" );
19712839Sgabeblack@google.com    }
19812839Sgabeblack@google.com
19912839Sgabeblack@google.com    for( int i = 0; i < length(); ++ i )
20012839Sgabeblack@google.com	(*this)[i] = v.get_bit( i );
20112839Sgabeblack@google.com
20212839Sgabeblack@google.com    return *this;
20312839Sgabeblack@google.com}
20412839Sgabeblack@google.com
20512839Sgabeblack@google.com
20612839Sgabeblack@google.com// ----------------------------------------------------------------------------
20712839Sgabeblack@google.com//  CLASS : sc_int_base
20812839Sgabeblack@google.com// ----------------------------------------------------------------------------
20912839Sgabeblack@google.com
21012839Sgabeblack@google.com#ifndef _32BIT_
21112839Sgabeblack@google.com#define NUM_WIDTH LLWIDTH
21212839Sgabeblack@google.com#else
21312839Sgabeblack@google.com#define NUM_WIDTH INTWIDTH
21412839Sgabeblack@google.com#endif
21512839Sgabeblack@google.com
21612839Sgabeblack@google.com
21712839Sgabeblack@google.com// assignment operators
21812839Sgabeblack@google.com
21912839Sgabeblack@google.cominline
22012839Sgabeblack@google.comsc_int_base&
22112839Sgabeblack@google.comsc_int_base::operator = ( const sc_fxval& v )
22212839Sgabeblack@google.com{
22312839Sgabeblack@google.com    if( ! v.is_normal() ) { /* also triggers OBSERVER_READ call */
22412839Sgabeblack@google.com	SC_REPORT_ERROR( sc_core::SC_ID_INVALID_FX_VALUE_,
22512839Sgabeblack@google.com			 "sc_int_base::operator = ( const sc_fxval& )" );
22612839Sgabeblack@google.com    }
22712839Sgabeblack@google.com    for( int i = 0; i < m_len; ++ i ) {
22812839Sgabeblack@google.com	set( i, v.get_bit( i ) );
22912839Sgabeblack@google.com    }
230    extend_sign();
231    return *this;
232}
233
234inline
235sc_int_base&
236sc_int_base::operator = ( const sc_fxval_fast& v )
237{
238    if( ! v.is_normal() ) { /* also triggers OBSERVER_READ call */
239	SC_REPORT_ERROR( sc_core::SC_ID_INVALID_FX_VALUE_,
240			 "sc_int_base::operator = ( const sc_fxval_fast& )" );
241    }
242    for( int i = 0; i < m_len; ++ i ) {
243	set( i, v.get_bit( i ) );
244    }
245    extend_sign();
246    return *this;
247}
248
249inline
250sc_int_base&
251sc_int_base::operator = ( const sc_fxnum& v )
252{
253    if( ! v.is_normal() ) { /* also triggers OBSERVER_READ call */
254	SC_REPORT_ERROR( sc_core::SC_ID_INVALID_FX_VALUE_,
255			 "sc_int_base::operator = ( const sc_fxnum& )" );
256    }
257    for( int i = 0; i < m_len; ++ i ) {
258	set( i, v.get_bit( i ) );
259    }
260    extend_sign();
261    return *this;
262}
263
264inline
265sc_int_base&
266sc_int_base::operator = ( const sc_fxnum_fast& v )
267{
268    if( ! v.is_normal() ) { /* also triggers OBSERVER_READ call */
269	SC_REPORT_ERROR( sc_core::SC_ID_INVALID_FX_VALUE_,
270			 "sc_int_base::operator = ( const sc_fxnum_fast& )" );
271    }
272    for( int i = 0; i < m_len; ++ i ) {
273	set( i, v.get_bit( i ) );
274    }
275    extend_sign();
276    return *this;
277}
278
279#undef NUM_WIDTH
280
281
282// ----------------------------------------------------------------------------
283//  CLASS : sc_uint_base
284// ----------------------------------------------------------------------------
285
286// assignment operators
287
288inline
289sc_uint_base&
290sc_uint_base::operator = ( const sc_fxval& v )
291{
292    if( ! v.is_normal() ) { /* also triggers OBSERVER_READ call */
293	SC_REPORT_ERROR( sc_core::SC_ID_INVALID_FX_VALUE_,
294			 "sc_uint_base::operator = ( const sc_fxval& )" );
295    }
296    for( int i = 0; i < m_len; ++ i ) {
297	set( i, v.get_bit( i ) );
298    }
299    extend_sign();
300    return *this;
301}
302
303inline
304sc_uint_base&
305sc_uint_base::operator = ( const sc_fxval_fast& v )
306{
307    if( ! v.is_normal() ) { /* also triggers OBSERVER_READ call */
308	SC_REPORT_ERROR( sc_core::SC_ID_INVALID_FX_VALUE_,
309			 "sc_uint_base::operator = ( const sc_fxval_fast& )" );
310    }
311    for( int i = 0; i < m_len; ++ i ) {
312	set( i, v.get_bit( i ) );
313    }
314    extend_sign();
315    return *this;
316}
317
318inline
319sc_uint_base&
320sc_uint_base::operator = ( const sc_fxnum& v )
321{
322    if( ! v.is_normal() ) { /* also triggers OBSERVER_READ call */
323	SC_REPORT_ERROR( sc_core::SC_ID_INVALID_FX_VALUE_,
324			 "sc_uint_base::operator = ( const sc_fxnum& )" );
325    }
326    for( int i = 0; i < m_len; ++ i ) {
327	set( i, v.get_bit( i ) );
328    }
329    extend_sign();
330    return *this;
331}
332
333inline
334sc_uint_base&
335sc_uint_base::operator = ( const sc_fxnum_fast& v )
336{
337    if( ! v.is_normal() ) { /* also triggers OBSERVER_READ call */
338	SC_REPORT_ERROR( sc_core::SC_ID_INVALID_FX_VALUE_,
339			 "sc_uint_base::operator = ( const sc_fxnum_fast& )" );
340    }
341    for( int i = 0; i < m_len; ++ i ) {
342	set( i, v.get_bit( i ) );
343    }
344    extend_sign();
345    return *this;
346}
347
348
349#endif
350
351
352// ----------------------------------------------------------------------------
353//  FUNCTION : sc_trace
354// ----------------------------------------------------------------------------
355
356inline
357void
358sc_trace( sc_core::sc_trace_file* tf,
359	  const sc_fxval& object, const std::string& name )
360{
361    if( tf )
362	tf->trace( object, name );
363}
364
365inline
366void
367sc_trace( sc_core::sc_trace_file* tf,
368	  const sc_fxval* object, const std::string& name )
369{
370    if( tf )
371	tf->trace( *object, name );
372}
373
374inline
375void
376sc_trace( sc_core::sc_trace_file* tf,
377	  const sc_fxval_fast& object, const std::string& name )
378{
379    if( tf )
380	tf->trace( object, name );
381}
382
383inline
384void
385sc_trace( sc_core::sc_trace_file* tf,
386	  const sc_fxval_fast* object, const std::string& name )
387{
388    if( tf )
389	tf->trace( *object, name );
390}
391
392inline
393void
394sc_trace( sc_core::sc_trace_file* tf,
395	  const sc_fxnum& object, const std::string& name )
396{
397    if( tf )
398	tf->trace( object, name );
399}
400
401inline
402void
403sc_trace( sc_core::sc_trace_file* tf,
404	  const sc_fxnum* object, const std::string& name )
405{
406    if( tf )
407	tf->trace( *object, name );
408}
409
410inline
411void
412sc_trace( sc_core::sc_trace_file* tf,
413	  const sc_fxnum_fast& object, const std::string& name )
414{
415    if( tf )
416	tf->trace( object, name );
417}
418
419inline
420void
421sc_trace( sc_core::sc_trace_file* tf,
422	  const sc_fxnum_fast* object, const std::string& name )
423{
424    if( tf )
425	tf->trace( *object, name );
426}
427
428} // namespace sc_dt
429
430
431#endif
432
433// Taf!
434