Vous êtes sur la page 1sur 319

IEEE Standard for Standard

SystemC

Language Reference
Manual
Sponsored by the
Design Automation Standards Committee
IEEE
3 Park Avenue
New York, NY 10016-5997
USA
9 January 2012
IEEE Computer Society
IEEE Std 1666"-2011
(Revision of
IEEE Std 1666-2005)
IEEE Std 1666

-2011
(Revision of
IEEE Std 1666-2005)
IEEE Standard for Standard
SystemC

Language Reference
Manual
Sponsor
Design Automation Standards Committee
of the
IEEE Computer Society
Approved 10 September 2011
IEEE-SA Standards Board
The Institute of Electrical and Electronics Engineers, Inc.
3 Park Avenue, New York, NY 10016-5997, USA
Copyright 2012 by the Institute of Electrical and Electronics Engineers, Inc.
All rights reserved. Published 9 January 2012. Printed in the United States of America.
IEEE is a registered trademark in the U.S. Patent & Trademark Office, owned by the Institute of Electrical and Electronics
Engineers, Incorporated.
SystemC is a registered trademark in the U.S. Patent & Trademark Office, owned by the Accellera Systems Initiative.
Print: ISBN978-0-7381-6801-2 STD97162
PDF: ISBN978-0-7381-6802-9 STDPD97162
IEEE prohibits discrimination, harassment, and bullying. For more information, visit http://www.ieee.org/web/aboutus/
whatis/policies/p9-26.html.
No part of this publication may be reproduced in any form, in an electronic retrieval system or otherwise, without the prior
written permission of the publisher.
Grateful acknowledgment is made to the Open SystemC Initiative (OSCI) for the permission to use
the following source material:
OSCI TLM Language Reference Manual Version 2.0.1
Note that a merger of OSCI and Accellera, announced on 5 December 2011, created a new
organization, Accellera Systems Initiative.
Abstract: SystemC

is defined in this standard. SystemC is an ANSI standard C++ class library


for system and hardware design for use by designers and architects who need to address complex
systems that are a hybrid between hardware and software. This standard provides a precise and
complete definition of the SystemC class library so that a SystemC implementation can be
developed with reference to this standard alone. The primary audiences for this standard are the
implementors of the SystemC class library, the implementors of tools supporting the class library,
and the users of the class library.
Keywords: C++, computer languages, digital systems, discrete event simulation, electronic
design automation, electronic system level, electronic systems, embedded software, fixed-point,
hardware description language, hardware design, hardware verification, IEEE 1666, SystemC,
system modeling, system-on-chip, transaction level
I EEE Standards documents are devel oped wi thi n the I EEE Societi es and the Standards Coordi nati ng
Commi ttees of the IEEE Standards Associati on (I EEE-SA) Standards Board. The I EEE devel ops i ts standards
through a consensus devel opment process, approved by the Ameri can Nati onal Standards I nstitute, whi ch
bri ngs together vol unteers representing vari ed vi ewpoints and i nterests to achi eve the f i nal product. Vol unteers
are not necessari l y members of the I nsti tute and serve wi thout compensati on. Whi l e the I EEE admi ni sters the
process and establi shes rul es to promote fai rness i n the consensus devel opment process, the I EEE does not
i ndependentl y eval uate, test, or veri f y the accuracy of any of the i nf ormati on contai ned i n i ts standards.
Use of an I EEE Standard i s whol l y vol untary. The I EEE di sclai ms l i abi l i ty f or any personal i nj ury, property or
other damage, of any nature whatsoever, whether speci al , i ndi rect, consequenti al , or compensatory, di rectl y or
i ndirectl y resul ti ng f rom the publ i cati on, use of , or rel i ance upon thi s, or any other I EEE Standard document.
TheI EEE does not warrant or represent the accuracy or content of the materi al contai ned herei n, and expressl y
di scl ai ms any express or i mpl i ed warranty, incl udi ng any i mpl i ed warranty of merchantabi l i ty or f i tness f or a
speci f i c purpose, or that the use of the materi al contai ned herei n i s f ree f rom patent i nf ri ngement. I EEE
Standards documents are supplied ASI S.
The exi stence of an I EEE Standard does not i mpl y that there are no other ways to produce, test, measure,
purchase, market, or provi de other goods and services rel ated to the scope of the I EEE Standard. Furthermore,
the vi ewpoi nt expressed at the ti me a standard i s approved and i ssued i s subj ect to change brought about
through developments i n the state of the art and comments recei ved f rom users of the standard. Every I EEE
Standard i s subj ected to revi ew at l east every f i ve years f or revi si on or reaf f i rmati on. When a document i s
more than f i ve years old and has not been reaf f i rmed, i t i s reasonabl e to concl ude that i ts contents, al though
sti l l of some val ue, do not whol l y ref lect the present state of the art. Users are cauti oned to check to determi ne
that they have the l atest edi ti on of any I EEE Standard.
I n publ i shi ng and making thi s document avai l abl e, the I EEE i s not suggesti ng or renderi ng prof essi onal or
other servi ces f or, or on behal f of , any person or enti ty. Nor i s the I EEE undertaki ng to perf orm any duty owed
by any other person or enti ty to another. Any person uti l i zi ng thi s, and any other I EEE Standards document,
shoul d rely upon the advice of a competent professi onal i n determi ni ng the exerci se of reasonabl e care i n any
gi ven ci rcumstances.
I nterpretati ons: Occasi onal l y questi ons may ari se regardi ng the meaning of porti ons of standards as they rel ate
to speci f i c appl i cati ons. When the need f or i nterpretati ons i s brought to the attenti on of I EEE, the I nsti tute wi l l
i ni tiate acti on to prepare appropri ate responses. Si nce I EEE Standards represent a consensus of concerned
i nterests, i t i s important to ensure that any i nterpretation has al so recei ved the concurrence of a bal ance of
i nterests. For this reason, I EEE and the members of i ts soci eti es and Standards Coordi nati ng Commi ttees are
not abl e to provi de an i nstant response to i nterpretati on requests except i n those cases where the matter has
previ ously recei ved f ormal considerati on. At l ectures, symposi a, semi nars, or educati onal courses, an
i ndivi dual presenti ng i nf ormati on on I EEE standards shal l make i t cl ear that hi s or her vi ews shoul d be
consi dered the personal vi ews of that i ndi vi dual rather than the f ormal posi ti on, expl anati on, or interpretati on
of the I EEE. Comments for revi si on of I EEE Standards are wel come f rom any i nterested party, regardl ess of
membershi p af f i l i ation wi th IEEE. Suggesti ons f or changes i n documents shoul d be i n the f orm of a proposed
change of text, together wi th appropri ate supporti ng comments.
Comments on standards and requests f or i nterpretati ons shoul d be addressed to:
Secretary, I EEE-SA Standards Board
445 Hoes Lane
Pi scataway, NJ 08854-4141
USA
Authori zati on to photocopy porti ons of any i ndivi dual standard f or i nternal or personal use i s granted by the
I nsti tute of El ectri cal and El ectroni cs Engi neers, Inc., provi ded that the appropri ate f ee i s pai d to Copyri ght
Cl earance Center. To arrange f or payment of l i censing f ee, pl ease contact Copyri ght Clearance Center,
Customer Servi ce, 222 Rosewood Dri ve, Danvers, MA 01923 USA; +1 978 750 8400. Permi ssi on to
photocopy porti ons of any i ndi vi dual standard for educati onal cl assroom use can al so be obtai ned through the
Copyri ght Cl earance Center.
iv
Copyright 2012 IEEE. All rights reserved.
Introduction
This document def ines SystemC, which is a C++ cl ass l ibrary.
As the electroni cs i ndustry bui lds more complex systems i nvol vi ng large numbers of components including
sof tware, there i s an i ncreasing need for a model ing language that can manage the complexity and size of
these systems. SystemC provi des a mechanism for managing this compl exi ty with i ts facil ity f or model ing
hardware and sof tware together at multipl e level s of abstraction. This capabil ity is not avail abl e in
tradi ti onal hardware descripti on l anguages.
Stakeholders in SystemC i ncl ude Electroni c Design Automation (EDA) companies who impl ement
SystemC cl ass l ibraries and tool s, i ntegrated circui t (IC) suppl iers who extend those cl ass l ibraries and use
SystemC to model their i ntell ectual property, and end users who use SystemC to model their systems.
Before the publi cation of thi s standard, SystemC was defi ned by an open-source, proof -of-concept C++
li brary, al so known as the reference si mul ator, avail abl e from the Accel lera Systems I ni ti ati ve. I n the event
of discrepanci es between the behavior of the reference simul ator and statements made in this standard, thi s
standard shal l be taken to be defi nitive.
This standard is not intended to serve as a users guide or to provi de an introduction to SystemC. Readers
requiring a SystemC tutorial or inf ormati on on the i ntended use of SystemC shoul d consult the Accell era
Systems I ni ti ative Web site (www.accel lera.org) to l ocate the many books and trai ning classes avai lable.
Note that the Open Systems I nitiati ve (OSCI) announced i n December 2011 i ts merger with Accel lera to
form the Accellera Systems Initiative. The name of the new organizati on has been used throughout thi s
document instead of the name Open SystemC Imitative or the acronym OSCI. The exceptions are in
statements that refer to previous OSCI actions, and standards such as OSCI TLM-2.0.1, whose names
have not been changed.
Notice to users
Laws and regulations
Users of these documents should consult al l appl icabl e laws and regul ations. Compl iance wi th the
provisions of thi s standard does not i mply compliance to any appl icabl e regulatory requi rements.
I mplementers of the standard are responsible f or observing or ref erri ng to the appli cabl e regul atory
requirements. I EEE does not, by the publi cati on of its standards, intend to urge action that is not i n
compliance wi th appl icabl e laws, and these documents may not be construed as doing so.
Copyrights
This document is copyri ghted by the I EEE. I t i s made avai lable for a wi de variety of both publ ic and pri vate
uses. These i ncl ude both use, by reference, in laws and regulati ons, and use in private sel f-regulati on,
standardi zation, and the promoti on of engi neeri ng practices and methods. By maki ng this document
avai lable for use and adopti on by publi c authori ti es and private users, the IEEE does not wai ve any rights in
copyright to thi s document.
This i ntroducti on i s not part of I EEE Std 1666-2011, I EEE Standard f or Standard SystemC

Language Reference
Manual .
v
Copyright 2012 IEEE. All rights reserved.
Updating of IEEE documents
Users of IEEE standards shoul d be aware that these documents may be superseded at any time by
the i ssuance of new editions or may be amended from time to time through the issuance of
amendments, corrigenda, or errata. An offi ci al I EEE document at any point in time consi sts of the
current edi tion of the document together with any amendments, corrigenda, or errata then i n eff ect.
I n order to determi ne whether a gi ven document is the current edition and whether it has been
amended through the issuance of amendments, corrigenda, or errata, visit the I EEE Standards
Associati on websi te at http://ieeexplore.i eee.org/xpl/standards.j sp, or contact the I EEE at the address
li sted previ ously.
For more informati on about the I EEE Standards Associati on or the I EEE standards development process,
visit the IEEE-SA website at http://standards.ieee.org.
Errata
Errata, i f any, f or this and al l other standards can be accessed at the f ol lowi ng URL: http://
standards.ieee.org/fi ndstds/errata/i ndex.html. Users are encouraged to check thi s URL f or errata
periodicall y.
Interpretations
Current i nterpretations can be accessed at the foll owing URL: http://standards.ieee.org/fi ndstds/
interps/index.html.
Patents
Attenti on is call ed to the possibil ity that i mplementati on of thi s standard may requi re use of subject matter
covered by patent rights. By publ icati on of thi s standard, no posi ti on is taken with respect to the exi stence or
val idi ty of any patent ri ghts i n connection therewith. The IEEE shall not be responsibl e f or identif ying
patents or patent appl icati ons for whi ch a l icense may be requi red to i mplement an I EEE standard or for
conducti ng inquiries i nto the legal val idity or scope of those patents that are brought to its attenti on.
vi
Copyright 2012 IEEE. All rights reserved.
Participants
This entity-based standard was created under the leadershi p of the fol lowi ng i ndi vi dual s:
Stan Krolikoski, Chai r
JeromeCornet, Vi ce Chai r
John Aynsley, Techni cal Lead and Author
David Long, Co-Author (SystemC Data Types)
DennisBrophy, Secretar y
SofieVandeputte, Typogr aphi cal Edi tor
At the time this enti ty-based standard was completed, the LRM Worki ng Group had the f oll owing
membership:
The f ol lowi ng members of the enti ty-based bal loting commi ttee voted on this standard. Bal loti ng enti ti es
may have voted for approval, disapproval, or abstention.
The worki ng group gratef ul ly acknowledges the contributi ons of the f ol lowi ng participants:
Accel l era Organi zati on
Cadence Design Systems
Freescal e Semi conductors
I ntel Corporati on
JEITA
Mentor Graphi cs
NXP Semi conductors
OSCI
STARC
STMi croel ectroni cs
Synopsys
Texas I nstruments
Accel l era Organi zati on
Cadence Desi gn Systems
I ntel Corporati on
JEI TA
Mentor Graphi cs
NXP Semi conductors
OSCI
Qual comm Incorporated
SGCC
STARC
STMi croel ectroni cs
Synopsys
Texas I nstruments
John Aynsl ey
Bi shnupri ya Bhattacharya
Davi d C. Bl ack
Jerome Cornet
Al an Fitch
Mark Gl asser
Puneet Goel
Andy Goodrich
Phil i pp A. Hartmann
Hi roshi I mai
Marti n Janssen
Tor Jeremiassen
Davi d Long
Mi chael McNamara
Mi ke Meredi th
Eric E. Roesl er
Stuart Swan
Bart Vanthournout
Yossi Vel l er
Kaz Yoshi naga
vii
Copyright 2012 IEEE. All rights reserved.
When the I EEE-SA Standards Board approved this standard on 10 September 2011, it had the f oll owing
membership:
Richard H. Hulett, Chai r
John Kulick, Vi ce Chai r
Robert Grow, Past Chai r
Judith Gorman, Secr etary
* Member Emeri tus
Al so included are the fol lowing nonvoti ng I EEE-SA Standards Board l iaisons:
Satish K. Aggarwal, NRC Repr esentati ve
Ri chard DeBlasi o, DOE Repr esentati ve
Al an H. Cookson, NI ST Repr esentati ve
Mi chel l e D. Turner
I EEE Standar ds Pr ogram Manager , Document Devel opment
Joan Wool ery
I EEE Standar ds Pr ogr am Manager , Techni cal Pr ogr amDevel opment
Masayuki Ariyoshi
Wi ll i am Bartl ey
Ted Burse
Cl i nt Chapl i n
Wael Di ab
Jean-Phi l i ppe Faure
Al ex Gel man
Paul Houz
Ji m Hughes
Joseph L. Koepf i nger*
Davi d Law
Thomas Lee
Hung Li ng
Ol eg Logvi nov
Ted Ol sen
Gary Robi nson
Jon Rosdahl
Sam Sci acca
Mi ke Seavey
Curti s Si l l er
Phil Wi nston
Howard Wolf man
Don Wri ght
vii i
Copyright 2012 IEEE. All rights reserved.
Contents
1. Overview.............................................................................................................................................. 1
1.1 Scope............................................................................................................................................ 1
1.2 Purpose......................................................................................................................................... 1
1.3 Subsets......................................................................................................................................... 2
1.4 Relationshi p withC++................................................................................................................. 2
1.5 Gui dancefor readers.................................................................................................................... 2
2. Normativereferences........................................................................................................................... 4
3. Termi nol ogy and conventi ons used i n this standard............................................................................ 5
3.1 Terminology................................................................................................................................. 5
3.1.1 Shal l, shoul d, may, can.................................................................................................... 5
3.1.2 Implementati on, appl icati on............................................................................................ 5
3.1.3 Call , call ed from, deri ved from........................................................................................ 5
3.1.4 Specifi ctechnical terms................................................................................................... 5
3.2 Syntacti cal conventions............................................................................................................... 7
3.2.1 Implementati on-defined................................................................................................... 7
3.2.2 Di sabled........................................................................................................................... 7
3.2.3 Ell ipsis (...)....................................................................................................................... 7
3.2.4 Classnames...................................................................................................................... 7
3.2.5 Embolded text .................................................................................................................. 8
3.3 Semanti c conventi ons.................................................................................................................. 8
3.3.1 Classdefi ni ti ons and theinheri tancehierarchy ............................................................... 8
3.3.2 Functi ondefi niti onsand side-effects............................................................................... 8
3.3.3 Functionswhosereturn typeis areferenceor apointer .................................................. 8
3.3.4 Namespaces and internal nami ng.................................................................................. 10
3.3.5 Non-compliant applicati ons and errors.......................................................................... 11
3.4 Notes and exampl es................................................................................................................... 11
4. Elaborati onand si mulati on semanti cs............................................................................................... 12
4.1 El aboration................................................................................................................................. 12
4.1.1 Instanti ati on ................................................................................................................... 12
4.1.2 Process macros............................................................................................................... 14
4.1.3 Port bi nding and export binding.................................................................................... 14
4.1.4 Setti ng thetimeresolution............................................................................................. 15
4.2 Si mulati on.................................................................................................................................. 15
4.2.1 Thescheduli ngalgorithm.............................................................................................. 16
4.2.2 Ini ti al ization, cycles, and pauses in thescheduling algori thm....................................... 19
4.3 Running el aboration and si mulati on.......................................................................................... 20
4.3.1 Function declarations..................................................................................................... 20
4.3.2 Function sc_el ab_and_sim............................................................................................. 20
4.3.3 Functionssc_argc andsc_argv ...................................................................................... 21
4.3.4 Runni ng under appli cation control usi ngfunctions sc_main and sc_start..................... 21
4.3.5 Runni ngunder control of thekernel .............................................................................. 23
4.4 El aboration and si mulation call backs........................................................................................ 23
4.4.1 before_end_of_elaborati on............................................................................................ 24
4.4.2 end_of_elaboration........................................................................................................ 25
4.4.3 start_of_si mulation........................................................................................................ 26
ix
Copyright 2012 IEEE. All rights reserved.
4.4.4 end_of_simul ati on ......................................................................................................... 27
4.5 Other functi ons rel ated to the scheduler .................................................................................... 27
4.5.1 Function declarations..................................................................................................... 27
4.5.2 Function sc_pause.......................................................................................................... 28
4.5.3 Functi on sc_stop, sc_set_stop_mode, and sc_get_stop_mode ...................................... 29
4.5.4 Function sc_ti me_stamp ................................................................................................ 30
4.5.5 Function sc_del ta_count ................................................................................................ 31
4.5.6 Function sc_is_running.................................................................................................. 31
4.5.7 Functi ons to detect pending activity .............................................................................. 31
4.5.8 Function sc_get_status................................................................................................... 32
5. Core language class defi ni ti ons......................................................................................................... 35
5.1 Cl ass header fi les....................................................................................................................... 35
5.1.1 #include "systemc"......................................................................................................... 35
5.1.2 #include "systemc.h" ...................................................................................................... 35
5.2 sc_modul e.................................................................................................................................. 37
5.2.1 Descripti on..................................................................................................................... 37
5.2.2 Class defi nition .............................................................................................................. 37
5.2.3 Constraints on usage...................................................................................................... 39
5.2.4 kind ................................................................................................................................ 39
5.2.5 SC_MODULE ............................................................................................................... 40
5.2.6 Constructors................................................................................................................... 40
5.2.7 SC_CTOR...................................................................................................................... 40
5.2.8 SC_HAS_PROCESS..................................................................................................... 41
5.2.9 SC_METHOD, SC_THREAD, SC_CTHREAD........................................................... 42
5.2.10 Method process.............................................................................................................. 43
5.2.11 Thread and cl ocked thread processes............................................................................. 43
5.2.12 Clocked thread processes............................................................................................... 44
5.2.13 reset_si gnal _i s and async_reset_si gnal _is..................................................................... 46
5.2.14 sensitive ......................................................................................................................... 48
5.2.15 dont_initial ize ................................................................................................................ 48
5.2.16 set_stack_si ze................................................................................................................. 49
5.2.17 next_trigger .................................................................................................................... 50
5.2.18 wait................................................................................................................................. 52
5.2.19 Posi ti onal port binding................................................................................................... 53
5.2.20 bef ore_end_of _el aboration, end_of_elaborati on, start_of _si mulati on,
end_of _simulati on ......................................................................................................... 55
5.2.21 get_chil d_objects and get_chi ld_events ........................................................................ 55
5.2.22 sc_gen_unique_name..................................................................................................... 56
5.2.23 sc_behavior and sc_channel ........................................................................................... 56
5.3 sc_modul e_name ....................................................................................................................... 57
5.3.1 Descripti on..................................................................................................................... 57
5.3.2 Class defi nition .............................................................................................................. 57
5.3.3 Constraints on usage...................................................................................................... 58
5.3.4 Module hierarchy ........................................................................................................... 58
5.3.5 Member f unctions.......................................................................................................... 58
5.4 sc_sensitive.............................................................................................................................. 60
5.4.1 Descripti on..................................................................................................................... 60
5.4.2 Class defi nition .............................................................................................................. 60
5.4.3 Constraints on usage...................................................................................................... 60
5.4.4 operator<<...................................................................................................................... 60
5.5 sc_spawn_opti ons and sc_spawn............................................................................................... 61
5.5.1 Descripti on..................................................................................................................... 61
x
Copyright 2012 IEEE. All rights reserved.
5.5.2 Class defi nition .............................................................................................................. 61
5.5.3 Constraints on usage...................................................................................................... 62
5.5.4 Constructors................................................................................................................... 62
5.5.5 Member f unctions.......................................................................................................... 63
5.5.6 sc_spawn........................................................................................................................ 64
5.5.7 SC_FORK and SC_JOIN............................................................................................... 66
5.6 sc_process_handl e ..................................................................................................................... 67
5.6.1 Descripti on..................................................................................................................... 67
5.6.2 Class defi nition .............................................................................................................. 68
5.6.3 Constraints on usage...................................................................................................... 69
5.6.4 Constructors................................................................................................................... 69
5.6.5 Member f unctions.......................................................................................................... 69
5.6.6 Member f unctions f or process control ........................................................................... 73
5.6.7 sc_get_current_process_handle ..................................................................................... 88
5.6.8 sc_i s_unwinding ............................................................................................................ 89
5.7 sc_event_finder and sc_event_fi nder_t ..................................................................................... 90
5.7.1 Descripti on..................................................................................................................... 90
5.7.2 Class defi nition .............................................................................................................. 90
5.7.3 Constraints on usage...................................................................................................... 90
5.8 sc_event_and_li st and sc_event_or_li st ..................................................................................... 92
5.8.1 Descripti on..................................................................................................................... 92
5.8.2 Class defi nition .............................................................................................................. 92
5.8.3 Constraints and usage .................................................................................................... 93
5.8.4 Constructors, destructor, assi gnment ............................................................................. 93
5.8.5 Member f unctions and operators ................................................................................... 94
5.9 sc_event_and_exprand sc_event_or_expr............................................................................ 95
5.9.1 Descripti on..................................................................................................................... 95
5.9.2 Class defi nition .............................................................................................................. 95
5.9.3 Constraints on usage...................................................................................................... 96
5.9.4 Operators........................................................................................................................ 96
5.10 sc_event ..................................................................................................................................... 97
5.10.1 Descripti on..................................................................................................................... 97
5.10.2 Class defi nition .............................................................................................................. 97
5.10.3 Constraints on usage...................................................................................................... 98
5.10.4 Constructors, destructor, and event naming.................................................................. 98
5.10.5 Functi ons f or nami ng and hi erarchy traversal .............................................................. 99
5.10.6 notif y and cancel .......................................................................................................... 100
5.10.7 Event l ists..................................................................................................................... 101
5.10.8 Mul tipl e event notif icati ons......................................................................................... 101
5.11 sc_time..................................................................................................................................... 101
5.11.1 Descripti on................................................................................................................... 101
5.11.2 Class defi nition ............................................................................................................ 101
5.11.3 Time resolution............................................................................................................ 102
5.11.4 Function sc_max_time................................................................................................. 103
5.11.5 Functions and operators............................................................................................... 103
5.11.6 SC_ZERO_TIME ........................................................................................................ 103
5.12 sc_port...................................................................................................................................... 104
5.12.1 Descripti on................................................................................................................... 104
5.12.2 Class defi nition ............................................................................................................ 104
5.12.3 Template parameters.................................................................................................... 105
5.12.4 Constraints on usage.................................................................................................... 106
5.12.5 Constructors................................................................................................................. 107
5.12.6 kind .............................................................................................................................. 107
5.12.7 Named port binding ..................................................................................................... 108
xi
Copyright 2012 IEEE. All rights reserved.
5.12.8 Member functi ons for bound ports and port-to-port binding....................................... 109
5.12.9 bef ore_end_of _el aboration, end_of_elaborati on, start_of _si mulati on,
end_of _simulati on ....................................................................................................... 112
5.13 sc_export .................................................................................................................................. 113
5.13.1 Descripti on................................................................................................................... 113
5.13.2 Class defi nition ............................................................................................................ 113
5.13.3 Template parameters.................................................................................................... 114
5.13.4 Constraints on usage.................................................................................................... 114
5.13.5 Constructors................................................................................................................. 114
5.13.6 kind .............................................................................................................................. 114
5.13.7 Export bindi ng ............................................................................................................. 115
5.13.8 Member functi ons for bound exports and export-to-export binding ........................... 116
5.13.9 bef ore_end_of _el aboration, end_of_elaborati on, start_of _si mulati on,
end_of _simulati on ....................................................................................................... 117
5.14 sc_i nterface.............................................................................................................................. 117
5.14.1 Descripti on................................................................................................................... 117
5.14.2 Class defi nition ............................................................................................................ 117
5.14.3 Constraints on usage.................................................................................................... 118
5.14.4 register_port ................................................................................................................. 118
5.14.5 def aul t_event ................................................................................................................ 119
5.15 sc_prim_channel ...................................................................................................................... 119
5.15.1 Descripti on................................................................................................................... 119
5.15.2 Class defi nition ............................................................................................................ 119
5.15.3 Constraints on usage.................................................................................................... 121
5.15.4 Constructors, destructor, and hierarchi cal names........................................................ 121
5.15.5 kind .............................................................................................................................. 121
5.15.6 request_update and update........................................................................................... 121
5.15.7 next_trigger and wait ................................................................................................... 123
5.15.8 bef ore_end_of _el aboration, end_of_elaborati on, start_of _si mulati on,
end_of _simulati on ....................................................................................................... 123
5.16 sc_obj ect .................................................................................................................................. 124
5.16.1 Descripti on................................................................................................................... 124
5.16.2 Class defi nition ............................................................................................................ 124
5.16.3 Constraints on usage.................................................................................................... 125
5.16.4 Constructors and destructor ......................................................................................... 126
5.16.5 name, basename, and ki nd........................................................................................... 126
5.16.6 pri nt and dump............................................................................................................. 127
5.16.7 Functi ons f or obj ect hi erarchy traversal ...................................................................... 127
5.16.8 Member f uncti ons f or attri butes .................................................................................. 129
5.17 Hi erarachi cal nami ng of obj ects and events............................................................................ 130
5.18 sc_attr_base.............................................................................................................................. 131
5.18.1 Descripti on................................................................................................................... 131
5.18.2 Class defi nition ............................................................................................................ 131
5.18.3 Member f unctions........................................................................................................ 132
5.19 sc_attribute............................................................................................................................... 132
5.19.1 Descripti on................................................................................................................... 132
5.19.2 Class defi nition ............................................................................................................ 132
5.19.3 Template parameters.................................................................................................... 132
5.19.4 Member f uncti ons and data members.......................................................................... 132
5.20 sc_attr_cl tn............................................................................................................................... 133
5.20.1 Descripti on................................................................................................................... 133
5.20.2 Class defi nition ............................................................................................................ 133
5.20.3 Constraints on usage.................................................................................................... 133
5.20.4 Iterators........................................................................................................................ 133
xii
Copyright 2012 IEEE. All rights reserved.
6. Predefi ned channel class def ini ti ons................................................................................................ 135
6.1 sc_si gnal_i n_i f ......................................................................................................................... 135
6.1.1 Descripti on................................................................................................................... 135
6.1.2 Class defi nition ............................................................................................................ 135
6.1.3 Member f unctions........................................................................................................ 135
6.2 sc_signal_in_if <bool > and sc_signal _i n_if <sc_dt::sc_logic>................................................. 136
6.2.1 Descripti on................................................................................................................... 136
6.2.2 Class defi nition ............................................................................................................ 136
6.2.3 Member f unctions........................................................................................................ 137
6.3 sc_si gnal_i nout_i f .................................................................................................................... 137
6.3.1 Descripti on................................................................................................................... 137
6.3.2 Class defi nition ............................................................................................................ 137
6.3.3 Member f unctions........................................................................................................ 138
6.4 sc_si gnal ................................................................................................................................... 139
6.4.1 Descripti on................................................................................................................... 139
6.4.2 Class defi nition ............................................................................................................ 139
6.4.3 Template parameter T.................................................................................................. 140
6.4.4 Reading and writing si gnal s......................................................................................... 140
6.4.5 Constructors................................................................................................................. 141
6.4.6 register_port ................................................................................................................. 141
6.4.7 Member f unctions f or reading ..................................................................................... 141
6.4.8 Member functi ons for wri ti ng...................................................................................... 142
6.4.9 Member f unctions f or events....................................................................................... 142
6.4.10 Di agnostic member f uncti ons...................................................................................... 143
6.4.11 operator<<.................................................................................................................... 143
6.5 sc_signal<bool,WRI TER_POLICY> and sc_signal<sc_dt::sc_logic,WRI TER_POLI CY> .. 144
6.5.1 Descripti on................................................................................................................... 144
6.5.2 Class defi nition ............................................................................................................ 144
6.5.3 Member f unctions........................................................................................................ 146
6.6 sc_buf fer .................................................................................................................................. 147
6.6.1 Descripti on................................................................................................................... 147
6.6.2 Class defi nition ............................................................................................................ 147
6.6.3 Constructors................................................................................................................. 147
6.6.4 Member f unctions........................................................................................................ 148
6.7 sc_cl ock ................................................................................................................................... 149
6.7.1 Descripti on................................................................................................................... 149
6.7.2 Class defi nition ............................................................................................................ 149
6.7.3 Characteri stic properties.............................................................................................. 150
6.7.4 Constructors................................................................................................................. 150
6.7.5 write............................................................................................................................. 151
6.7.6 Diagnostic member functi ons...................................................................................... 151
6.7.7 bef ore_end_of_elaborati on .......................................................................................... 151
6.7.8 sc_i n_clk ...................................................................................................................... 151
6.8 sc_i n......................................................................................................................................... 152
6.8.1 Descripti on................................................................................................................... 152
6.8.2 Class defi nition ............................................................................................................ 152
6.8.3 Member f unctions........................................................................................................ 153
6.8.4 Function sc_trace......................................................................................................... 153
6.8.5 end_of_elaboration ...................................................................................................... 153
6.9 sc_i n<bool > and sc_i n<sc_dt::sc_logic>................................................................................. 153
6.9.1 Descripti on................................................................................................................... 153
6.9.2 Class defi nition ............................................................................................................ 154
6.9.3 Member f unctions........................................................................................................ 155
xii i
Copyright 2012 IEEE. All rights reserved.
6.10 sc_i nout .................................................................................................................................... 156
6.10.1 Descripti on................................................................................................................... 156
6.10.2 Class defi nition ............................................................................................................ 156
6.10.3 Member f unctions........................................................................................................ 157
6.10.4 ini ti al ize ....................................................................................................................... 157
6.10.5 Function sc_trace......................................................................................................... 157
6.10.6 end_of_elaborati on ...................................................................................................... 158
6.10.7 Bindi ng......................................................................................................................... 158
6.11 sc_i nout<bool> and sc_inout<sc_dt::sc_l ogi c> ...................................................................... 158
6.11.1 Descripti on................................................................................................................... 158
6.11.2 Class defi nition ............................................................................................................ 158
6.11.3 Member f unctions........................................................................................................ 160
6.12 sc_out ....................................................................................................................................... 160
6.12.1 Descripti on................................................................................................................... 160
6.12.2 Class defi nition ............................................................................................................ 160
6.12.3 Member f unctions........................................................................................................ 161
6.13 sc_si gnal_resolved................................................................................................................... 161
6.13.1 Descripti on................................................................................................................... 161
6.13.2 Class defi nition ............................................................................................................ 161
6.13.3 Constructors................................................................................................................. 162
6.13.4 Resol ution semantics................................................................................................... 162
6.13.5 Member f unctions........................................................................................................ 163
6.14 sc_i n_resol ved ......................................................................................................................... 164
6.14.1 Descripti on................................................................................................................... 164
6.14.2 Class defi nition ............................................................................................................ 164
6.14.3 Member f unctions........................................................................................................ 165
6.15 sc_i nout_resolved .................................................................................................................... 165
6.15.1 Descripti on................................................................................................................... 165
6.15.2 Class defi nition ............................................................................................................ 165
6.15.3 Member f unctions........................................................................................................ 166
6.16 sc_out_resol ved ....................................................................................................................... 166
6.16.1 Descripti on................................................................................................................... 166
6.16.2 Class defi nition ............................................................................................................ 166
6.16.3 Member f unctions........................................................................................................ 167
6.17 sc_si gnal_rv ............................................................................................................................. 167
6.17.1 Descripti on................................................................................................................... 167
6.17.2 Class defi nition ............................................................................................................ 167
6.17.3 Semantics and member functi ons ................................................................................ 167
6.18 sc_i n_rv.................................................................................................................................... 168
6.18.1 Descripti on................................................................................................................... 168
6.18.2 Class defi nition ............................................................................................................ 168
6.18.3 Member f unctions........................................................................................................ 169
6.19 sc_i nout_rv............................................................................................................................... 169
6.19.1 Descripti on................................................................................................................... 169
6.19.2 Class defi nition ............................................................................................................ 169
6.19.3 Member f unctions........................................................................................................ 170
6.20 sc_out_rv.................................................................................................................................. 170
6.20.1 Descripti on................................................................................................................... 170
6.20.2 Class defi nition ............................................................................................................ 170
6.20.3 Member f unctions........................................................................................................ 171
6.21 sc_f if o_in_if ............................................................................................................................. 171
6.21.1 Descripti on................................................................................................................... 171
6.21.2 Class defi nition ............................................................................................................ 171
6.21.3 Member f unctions........................................................................................................ 172
xiv
Copyright 2012 IEEE. All rights reserved.
6.22 sc_f if o_out_if ........................................................................................................................... 172
6.22.1 Descripti on................................................................................................................... 172
6.22.2 Class defi nition ............................................................................................................ 172
6.22.3 Member f unctions........................................................................................................ 173
6.23 sc_f if o ...................................................................................................................................... 173
6.23.1 Descripti on................................................................................................................... 173
6.23.2 Class defi nition ............................................................................................................ 173
6.23.3 Template parameter T.................................................................................................. 174
6.23.4 Constructors................................................................................................................. 175
6.23.5 register_port ................................................................................................................. 175
6.23.6 Member f uncti ons f or reading ..................................................................................... 175
6.23.7 Member functi ons for wri ting...................................................................................... 176
6.23.8 The update phase ......................................................................................................... 176
6.23.9 Member f uncti ons f or events....................................................................................... 177
6.23.10Member f uncti ons for avail abl e values and f ree sl ots ................................................. 177
6.23.11Diagnostic member functi ons...................................................................................... 177
6.23.12operator<<.................................................................................................................... 177
6.24 sc_f if o_in ................................................................................................................................. 178
6.24.1 Descripti on................................................................................................................... 178
6.24.2 Class defi nition ............................................................................................................ 178
6.24.3 Member f unctions........................................................................................................ 179
6.25 sc_f if o_out ............................................................................................................................... 179
6.25.1 Descripti on................................................................................................................... 179
6.25.2 Class defi nition ............................................................................................................ 179
6.25.3 Member f unctions........................................................................................................ 180
6.26 sc_mutex_i f .............................................................................................................................. 182
6.26.1 Descripti on................................................................................................................... 182
6.26.2 Class defi nition ............................................................................................................ 182
6.26.3 Member f unctions........................................................................................................ 182
6.27 sc_mutex .................................................................................................................................. 182
6.27.1 Descripti on................................................................................................................... 182
6.27.2 Class defi nition ............................................................................................................ 182
6.27.3 Constructors................................................................................................................. 183
6.27.4 Member f unctions........................................................................................................ 183
6.28 sc_semaphore_if ...................................................................................................................... 184
6.28.1 Descripti on................................................................................................................... 184
6.28.2 Class defi nition ............................................................................................................ 184
6.28.3 Member f unctions........................................................................................................ 184
6.29 sc_semaphore........................................................................................................................... 185
6.29.1 Descripti on................................................................................................................... 185
6.29.2 Class defi nition ............................................................................................................ 185
6.29.3 Constructors................................................................................................................. 185
6.29.4 Member f unctions........................................................................................................ 185
6.30 sc_event_queue........................................................................................................................ 186
6.30.1 Descripti on................................................................................................................... 186
6.30.2 Class defi nition ............................................................................................................ 186
6.30.3 Constraints on usage.................................................................................................... 187
6.30.4 Constructors................................................................................................................. 187
6.30.5 kind .............................................................................................................................. 187
6.30.6 Member f unctions........................................................................................................ 187
7. SystemC data types.......................................................................................................................... 189
7.1 I ntroducti on.............................................................................................................................. 189
xv
Copyright 2012 IEEE. All rights reserved.
7.2 Common characteri stics........................................................................................................... 191
7.2.1 Ini ti al izati on and assi gnment operators....................................................................... 192
7.2.2 Precision of ari thmetic expressi ons............................................................................. 193
7.2.3 Base class default word length..................................................................................... 193
7.2.4 Word l ength ................................................................................................................. 194
7.2.5 Bit-select ...................................................................................................................... 194
7.2.6 Part-select..................................................................................................................... 195
7.2.7 Concatenati on .............................................................................................................. 196
7.2.8 Reduction operators..................................................................................................... 197
7.2.9 Integer conversi on........................................................................................................ 198
7.2.10 String input and output ................................................................................................ 198
7.2.11 Conversi on of appl icati on-def ined types in integer expressi ons ................................. 199
7.3 Stri ng l iterals............................................................................................................................ 199
7.4 sc_value_base........................................................................................................................ 201
7.4.1 Descripti on................................................................................................................... 201
7.4.2 Class defi nition ............................................................................................................ 201
7.4.3 Constraints on usage.................................................................................................... 201
7.4.4 Member f unctions........................................................................................................ 202
7.5 Li mited-preci si on i nteger types............................................................................................... 202
7.5.1 Type defi ni ti ons........................................................................................................... 202
7.5.2 sc_i nt_base................................................................................................................... 203
7.5.3 sc_uint_base................................................................................................................. 208
7.5.4 sc_i nt ............................................................................................................................ 213
7.5.5 sc_uint .......................................................................................................................... 215
7.5.6 Bit-selects..................................................................................................................... 217
7.5.7 Part-selects................................................................................................................... 222
7.6 Fi ni te-preci si on i nteger types................................................................................................... 227
7.6.1 Type defi ni ti ons........................................................................................................... 227
7.6.2 Constraints on usage.................................................................................................... 227
7.6.3 sc_signed...................................................................................................................... 227
7.6.4 sc_unsi gned.................................................................................................................. 234
7.6.5 sc_bigi nt ....................................................................................................................... 240
7.6.6 sc_biguint ..................................................................................................................... 242
7.6.7 Bit-selects..................................................................................................................... 244
7.6.8 Part-selects................................................................................................................... 248
7.7 I nteger concatenations ............................................................................................................. 253
7.7.1 Descripti on................................................................................................................... 253
7.7.2 Class defi nition ............................................................................................................ 253
7.7.3 Constraints on usage.................................................................................................... 255
7.7.4 Assi gnment operators .................................................................................................. 255
7.7.5 Implici t type conversion .............................................................................................. 255
7.7.6 Explici t type conversion .............................................................................................. 255
7.7.7 Other member functions .............................................................................................. 256
7.8 Generi c base proxy class.......................................................................................................... 256
7.8.1 Descripti on................................................................................................................... 256
7.8.2 Class defi nition ............................................................................................................ 256
7.8.3 Constraints on usage.................................................................................................... 256
7.9 Logic and vector types............................................................................................................. 257
7.9.1 Type defi ni ti ons........................................................................................................... 257
7.9.2 sc_l ogi c ........................................................................................................................ 257
7.9.3 sc_bv_base................................................................................................................... 262
7.9.4 sc_l v_base.................................................................................................................... 267
7.9.5 sc_bv ............................................................................................................................ 273
7.9.6 sc_l v ............................................................................................................................. 275
xvi
Copyright 2012 IEEE. All rights reserved.
7.9.7 Bit-selects..................................................................................................................... 277
7.9.8 Part-selects................................................................................................................... 280
7.9.9 Concatenati ons............................................................................................................. 286
7.10 Fi xed-poi nt types..................................................................................................................... 293
7.10.1 Fixed-point representati on ........................................................................................... 293
7.10.2 Fixed-point type conversi on ........................................................................................ 294
7.10.3 Fixed-point data types.................................................................................................. 295
7.10.4 Fixed-point expressions and operations....................................................................... 296
7.10.5 Bit and part selecti on ................................................................................................... 299
7.10.6 Variable-preci si on f ixed-point value li mits................................................................. 300
7.10.7 Fixed-poi nt word l ength and mode.............................................................................. 300
7.10.8 Conversi ons to character stri ng.................................................................................... 302
7.10.9 Finite word-l ength ef fects............................................................................................ 304
7.10.10sc_f xnum...................................................................................................................... 327
7.10.11sc_f xnum_f ast .............................................................................................................. 332
7.10.12sc_f xval ........................................................................................................................ 337
7.10.13sc_f xval_f ast ................................................................................................................ 341
7.10.14sc_f ix............................................................................................................................ 346
7.10.15sc_ufi x.......................................................................................................................... 349
7.10.16sc_f ix_fast .................................................................................................................... 352
7.10.17sc_ufi x_fast .................................................................................................................. 355
7.10.18sc_f ixed........................................................................................................................ 358
7.10.19sc_ufi xed...................................................................................................................... 360
7.10.20sc_f ixed_f ast ................................................................................................................ 362
7.10.21sc_ufi xed_f ast .............................................................................................................. 365
7.10.22Bit-selects..................................................................................................................... 367
7.10.23Part-sel ects................................................................................................................... 369
7.11 Contexts ................................................................................................................................... 375
7.11.1 sc_l ength_param.......................................................................................................... 375
7.11.2 sc_l ength_context ........................................................................................................ 377
7.11.3 sc_f xtype_params ........................................................................................................ 378
7.11.4 sc_f xtype_context ........................................................................................................ 380
7.11.5 sc_f xcast_switch .......................................................................................................... 381
7.11.6 sc_f xcast_context ......................................................................................................... 382
7.12 Control of stri ng representati on ............................................................................................... 383
7.12.1 Descripti on................................................................................................................... 383
7.12.2 Class defi nition ............................................................................................................ 383
7.12.3 Functions...................................................................................................................... 384
8. SystemC util ities.............................................................................................................................. 385
8.1 Trace fi les ................................................................................................................................ 385
8.1.1 Class defi ni ti on and f unction declarations................................................................... 385
8.1.2 sc_trace_fi le................................................................................................................. 385
8.1.3 sc_create_vcd_trace_f il e.............................................................................................. 386
8.1.4 sc_close_vcd_trace_f ile............................................................................................... 386
8.1.5 sc_write_comment ....................................................................................................... 386
8.1.6 sc_trace ........................................................................................................................ 386
8.2 sc_report................................................................................................................................... 388
8.2.1 Descripti on................................................................................................................... 388
8.2.2 Class defi nition ............................................................................................................ 388
8.2.3 Constraints on usage.................................................................................................... 389
8.2.4 sc_verbosi ty ................................................................................................................. 389
8.2.5 sc_severity ................................................................................................................... 389
xvii
Copyright 2012 IEEE. All rights reserved.
8.2.6 Copy constructor and assignment ................................................................................ 390
8.2.7 Member f unctions........................................................................................................ 390
8.3 sc_report_handl er..................................................................................................................... 391
8.3.1 Descripti on................................................................................................................... 391
8.3.2 Class defi nition ............................................................................................................ 391
8.3.3 Constraints on usage.................................................................................................... 393
8.3.4 sc_actions..................................................................................................................... 393
8.3.5 report ............................................................................................................................ 393
8.3.6 set_acti ons.................................................................................................................... 394
8.3.7 stop_af ter ..................................................................................................................... 395
8.3.8 get_count...................................................................................................................... 396
8.3.9 Verbosity l evel ............................................................................................................. 396
8.3.10 suppress and force........................................................................................................ 396
8.3.11 set_handler ................................................................................................................... 397
8.3.12 get_new_acti on_i d....................................................................................................... 398
8.3.13 sc_i nterrupt_here and sc_stop_here............................................................................. 398
8.3.14 get_cached_report and cl ear_cached_report................................................................ 398
8.3.15 set_l og_f il e_name and get_log_fi le_name.................................................................. 399
8.4 sc_exception............................................................................................................................. 399
8.4.1 Descripti on................................................................................................................... 399
8.4.2 Class defi nition ............................................................................................................ 399
8.5 sc_vector .................................................................................................................................. 400
8.5.1 Descripti on................................................................................................................... 400
8.5.2 Class defi nition ............................................................................................................ 400
8.5.3 Constraints on usage.................................................................................................... 403
8.5.4 Constructors and destructors........................................................................................ 403
8.5.5 ini t and create_element ................................................................................................ 404
8.5.6 kind, si ze, get_el ements............................................................................................... 405
8.5.7 operator[ ] and at ........................................................................................................... 406
8.5.8 Iterators........................................................................................................................ 406
8.5.9 bind .............................................................................................................................. 406
8.5.10 sc_assemble_vector ..................................................................................................... 408
8.6 Util ity f unctions....................................................................................................................... 410
8.6.1 Function declarations................................................................................................... 410
8.6.2 sc_abs........................................................................................................................... 411
8.6.3 sc_max ......................................................................................................................... 411
8.6.4 sc_mi n.......................................................................................................................... 411
8.6.5 Version and copyright.................................................................................................. 411
9. Overview of TLM-2.0...................................................................................................................... 413
9.1 Compl iance with the TLM-2.0 standard.................................................................................. 414
10. Introduction to TLM-2.0.................................................................................................................. 415
10.1 Background.............................................................................................................................. 415
10.2 Transaction-l evel modeli ng, use cases, and abstraction .......................................................... 415
10.3 Coding styles............................................................................................................................ 416
10.3.1 Unti med coding style................................................................................................... 416
10.3.2 Loosely-timed codi ng styl e and temporal decoupli ng................................................. 417
10.3.3 Synchronizati on i n l oosely-timed model s.................................................................... 418
10.3.4 Approximatel y-timed codi ng style .............................................................................. 418
10.3.5 Characterization of loosely-ti med and approximatel y-ti med coding styles ................ 419
10.3.6 Switchi ng between l oosely-timed and approximatel y-timed model ing ...................... 419
xviii
Copyright 2012 IEEE. All rights reserved.
10.3.7 Cycl e-accurate modeli ng ............................................................................................. 419
10.3.8 Blocking versus non-bl ocking transport i nterf aces ..................................................... 419
10.3.9 Use cases and codi ng styles......................................................................................... 420
10.4 I niti ators, targets, sockets, and transacti on bridges ................................................................. 420
10.5 DMI and debug transport interfaces ........................................................................................ 423
10.6 Combi ned interfaces and sockets............................................................................................. 423
10.7 Namespaces ............................................................................................................................. 423
10.8 Header fi les and versi on numbers............................................................................................ 424
10.8.1 Sof tware versi on i nf ormation ...................................................................................... 424
10.8.2 Defi niti ons ................................................................................................................... 424
10.8.3 Rules ............................................................................................................................ 425
11. TLM-2.0 core interf aces.................................................................................................................. 426
11.1 Transport i nterf aces ................................................................................................................. 426
11.1.1 Blocking transport i nterface......................................................................................... 426
11.1.2 Non-blocking transport i nterf ace................................................................................. 430
11.1.3 Timi ng annotati on wi th the transport i nterfaces.......................................................... 438
11.1.4 Mi grati on path from TLM-1........................................................................................ 442
11.2 Di rect memory interface.......................................................................................................... 442
11.2.1 Introduction.................................................................................................................. 442
11.2.2 Class defi nition ............................................................................................................ 443
11.2.3 get_di rect_mem_ptr method........................................................................................ 444
11.2.4 templ ate argument and tlm_generic_payload class..................................................... 445
11.2.5 tl m_dmi cl ass............................................................................................................... 445
11.2.6 invali date_direct_mem_ptr method ............................................................................. 448
11.2.7 DMI versus transport ................................................................................................... 449
11.2.8 DMI and temporal decoupl ing..................................................................................... 449
11.2.9 Opti mizati on using a DMI hi nt .................................................................................... 450
11.3 Debug transport i nterf ace......................................................................................................... 450
11.3.1 Introduction.................................................................................................................. 450
11.3.2 Class defi nition ............................................................................................................ 450
11.3.3 TRANS templ ate argument and tlm_generic_payl oad class....................................... 451
11.3.4 Rules ............................................................................................................................ 451
12. TLM-2.0 gl obal quantum................................................................................................................. 453
12.1 I ntroducti on.............................................................................................................................. 453
12.2 Header fi le................................................................................................................................ 453
12.3 Cl ass def ini tion ........................................................................................................................ 453
12.4 Cl ass tl m_gl obal _quantum ...................................................................................................... 454
13. Combined TLM-2.0 interf aces and sockets..................................................................................... 455
13.1 Combined interfaces ................................................................................................................ 455
13.1.1 Introduction.................................................................................................................. 455
13.1.2 Class defi nition ............................................................................................................ 455
13.2 I nitiator and target sockets....................................................................................................... 456
13.2.1 Introduction.................................................................................................................. 456
13.2.2 Class defi nition ............................................................................................................ 456
13.2.3 Classes tlm_base_ini ti ator_socket_b and tlm_base_target_socket_b.......................... 460
13.2.4 Classes tlm_base_ini tiator_socket and tl m_base_target_socket.................................. 460
13.2.5 Cl asses tlm_initiator_socket and tlm_target_socket .................................................... 461
xix
Copyright 2012 IEEE. All rights reserved.
14. TLM-2.0 generic payl oad ................................................................................................................ 465
14.1 I ntroducti on.............................................................................................................................. 465
14.2 Extensions and interoperabil ity ............................................................................................... 465
14.2.1 Use the generic payload di rectl y, wi th ignorable extensions....................................... 466
14.2.2 Defi ne a new protocol traits class containing a typedef f or tl m_generi c_payload...... 467
14.2.3 Defi ne a new protocol trai ts cl ass and a new transacti on type .................................... 467
14.3 Generic payl oad attri butes and methods.................................................................................. 467
14.4 Cl ass def ini tion ........................................................................................................................ 468
14.5 Generi c payload memory management ................................................................................... 470
14.6 Constructors, assi gnment, and destructor ................................................................................ 474
14.7 Default val ues and modif iabil ity of attributes ......................................................................... 474
14.8 Option attribute........................................................................................................................ 476
14.9 Command attri bute .................................................................................................................. 477
14.10Address attribute..................................................................................................................... 478
14.11Data pointer attribute.............................................................................................................. 479
14.12Data l ength attri bute................................................................................................................ 480
14.13Byte enabl e pointer attribute................................................................................................... 480
14.14Byte enabl e l ength attri bute.................................................................................................... 481
14.15Streaming width attri bute........................................................................................................ 482
14.16DMI all owed attri bute............................................................................................................. 482
14.17Response status attribute......................................................................................................... 483
14.17.1The standard error response......................................................................................... 484
14.18Endianness.............................................................................................................................. 487
14.18.1Introduction.................................................................................................................. 487
14.18.2Rules ............................................................................................................................ 488
14.19Helper f unctions to determine host endi anness ...................................................................... 490
14.19.1Introduction.................................................................................................................. 490
14.19.2Defi ni ti on..................................................................................................................... 490
14.19.3Rules ............................................................................................................................ 491
14.20Helper f unctions f or endi anness conversion........................................................................... 491
14.20.1Introduction.................................................................................................................. 491
14.20.2Defi ni ti on..................................................................................................................... 492
14.20.3Rules ............................................................................................................................ 492
14.21Generi c payload extensions.................................................................................................... 494
14.21.1Introduction.................................................................................................................. 494
14.21.2Rati onal e...................................................................................................................... 494
14.21.3Extensi on pointers, objects and transacti on bri dges.................................................... 495
14.21.4Rules ............................................................................................................................ 495
15. TLM-2.0 base protocol and phases.................................................................................................. 500
15.1 Phases....................................................................................................................................... 500
15.1.1 Introduction.................................................................................................................. 500
15.1.2 Class defi nition ............................................................................................................ 500
15.1.3 Rules ............................................................................................................................ 501
15.2 Base protocol ........................................................................................................................... 502
15.2.1 Introduction.................................................................................................................. 502
15.2.2 Class defi nition ............................................................................................................ 503
15.2.3 Base protocol phase sequences.................................................................................... 503
15.2.4 Permi tted phase transitions.......................................................................................... 505
15.2.5 Ignorable phases .......................................................................................................... 508
15.2.6 Base protocol timi ng parameters and fl ow control ...................................................... 510
15.2.7 Base protocol rul es concerning ti ming annotati on ...................................................... 514
xx
Copyright 2012 IEEE. All rights reserved.
15.2.8 Base protocol rules concerni ng b_transport................................................................. 514
15.2.9 Base protocol rul es concerning request and response ordering................................... 515
15.2.10Base protocol rul es for switching between b_transport and nb_transport ................... 516
15.2.11Other base protocol rules............................................................................................. 517
15.2.12Summary of base protocol transaction ordering rules................................................. 517
15.2.13Guideli nes for creati ng base-protocol-compli ant components.................................... 517
16. TLM-2.0 util iti es.............................................................................................................................. 521
16.1 Conveni ence sockets................................................................................................................ 521
16.1.1 Introduction.................................................................................................................. 521
16.1.2 Simpl e sockets............................................................................................................. 523
16.1.3 Tagged si mple sockets................................................................................................. 529
16.1.4 Multi-sockets ............................................................................................................... 532
16.2 Quantum keeper ....................................................................................................................... 537
16.2.1 Introduction.................................................................................................................. 537
16.2.2 Header f il e.................................................................................................................... 537
16.2.3 Class defi nition ............................................................................................................ 537
16.2.4 General gui del ines f or processes usi ng temporal decoupli ng...................................... 538
16.2.5 Class tlm_quantumkeeper ............................................................................................ 539
16.3 Payload event queue ................................................................................................................ 541
16.3.1 Introduction.................................................................................................................. 541
16.3.2 Header f il e.................................................................................................................... 542
16.3.3 Class defi nition ............................................................................................................ 542
16.3.4 Rules ............................................................................................................................ 543
16.4 I nstance-speci fi c extensi ons .................................................................................................... 544
16.4.1 Introduction.................................................................................................................. 544
16.4.2 Header f il e.................................................................................................................... 544
16.4.3 Class defi nition ............................................................................................................ 544
17. TLM-1 Message passi ng i nterf ace and anal ysis ports..................................................................... 546
17.1 Put, get, peek, and transport interfaces.................................................................................... 546
17.1.1 Descripti on................................................................................................................... 546
17.1.2 Class Def inition ........................................................................................................... 546
17.1.3 Blocking versus non-bl ocking interf aces..................................................................... 548
17.1.4 Blocking put, get, peek, and transport ......................................................................... 549
17.1.5 Non-blocking i nterf ace methods.................................................................................. 549
17.1.6 Argument passing and transaction li fetime ................................................................. 550
17.1.7 Constraints on the transacti on data type...................................................................... 551
17.2 TLM-1 fi fo interfaces .............................................................................................................. 551
17.2.1 Descripti on................................................................................................................... 551
17.2.2 Cl ass Defi ni ti on ........................................................................................................... 551
17.2.3 Member f uncti ons........................................................................................................ 552
17.3 tlm_f if o .................................................................................................................................... 552
17.3.1 Descripti on................................................................................................................... 552
17.3.2 Class Def inition ........................................................................................................... 553
17.3.3 Template parameter T .................................................................................................. 554
17.3.4 Constructors and destructor ......................................................................................... 554
17.3.5 Member f uncti ons........................................................................................................ 554
17.3.6 Delta cycle semanti cs................................................................................................... 556
17.4 Analysis interface and analysi s ports....................................................................................... 558
17.4.1 Class defi nition ............................................................................................................ 558
17.4.2 Rules ............................................................................................................................ 559
xxi
Copyright 2012 IEEE. All rights reserved.
Annex A (informati ve) I ntroducti on to SystemC ........................................................................................ 562
Annex B (inf ormati ve) Glossary.................................................................................................................. 566
Annex C (informati ve) Deprecated f eatures................................................................................................ 583
Annex D (informati ve) Changes between IEEE Std 1666-2005 and I EEE Std 1666-2011........................ 585
I ndex ............................................................................................................................................................ 589
1
Copyright 2012 IEEE. All rights reserved.
IEEE Standard for Standard
SystemC

Language Reference
Manual
I MPORTANT NOTI CE: This standard is not intended to ensure safety, security, health, or
environmental protection. I mplementers of the standard are responsible for determining appropriate
safety, security, environmental, andhealthpracticesor regulatoryrequirements.
ThisI EEE document ismadeavailablefor use subject to important noticesandlegal disclaimers. These
noticesanddisclaimersappear in all publicationscontainingthisdocument andmaybefoundunder the
heading"I mportant Notice" or "Important NoticesandDisclaimersConcerningIEEE Documents." They
can alsobeobtainedonrequest fromI EEE or viewedat http://standards.ieee.org/I PR/disclaimers.html.
1. Overview
1.1 Scope
This standard defi nes SystemC
1
with Transacti on Level Modeli ng (TLM) asan ANSI standard C++ class
li brary for systemandhardwaredesi gn.
1.2 Purpose
The general purpose of thi s standard i s to provi dea C++-based standard for designers and archi tects who
need to address complex systemsthat areahybrid between hardwareand software.
The speci fi c purpose of this standard i sto provide aprecise and complete defi ni ti on of the SystemC class
li brary including aTLM l ibrary so that a SystemC implementation can be developed wi th referenceto thi s
standard alone. This standard is not intended to serve as a users guide or to provide an introduction to
SystemC, but i t doescontai n useful i nformation for end users.
1
SystemC

isaregistered trademark of theAccel leraSystemsInitiati ve.


IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


2
Copyright 2012 IEEE. All rights reserved.
1.3 Subsets
It is anti cipated that tool vendors wi ll create impl ementations that support onl y a subset of this standard or
that i mpose further constrai nts on the use of thi s standard. Such i mplementations are not fully compli ant
wi th this standard but may nevertheless clai mpartial compli ance with this standard and may usethe name
SystemC. Seeal so 9.1 for adescri ption of TLM-2.0-compl iance.
1.4 Relationship with C++
This standard i s cl osely rel ated to the C++ programming language and adheres to the termi nology used i n
ISO/IEC 14882:2003.
2
This standard doesnot seek to restri ct theusageof theC++ programming l anguage;
a SystemC appli cati on may use any of the faci li ti es provided by C++, which in turn may use any of the
facil itiesprovi ded by C. However, wherethefacil itiesprovided by thi sstandard areused, they shal l beused
in accordancewi th therul es and constraints set out i n thisstandard.
This standard defines the publ ic interface to the SystemC class l ibrary and the constrai nts on how those
classes may beused. The SystemC cl ass library may bei mplemented i n any manner whatsoever, provided
only that theobl igati onsimposed by this standard arehonored.
A C++ class li brary may be extended usi ng the mechanisms provi ded by theC++ l anguage. Impl ementors
and usersarefreeto extend SystemCin thi sway, providedthat they do not vi olatethi sstandard.
NOTEIt is possible to create a well-formed C++ programthat is legal according to theC++ programming language
standard but that violatesthisstandard. Animplementationisnot obliged to detect every violation of thisstandard.
3
1.5 Guidance for readers
Readers who arenot entirely famili ar wi th SystemCshould start wi th Annex A, Introduction to SystemC,
which provi des a brief i nformal summary of the subject i ntended to aid in the understandi ng of the
normati vedefini ti ons. Suchreadersmay also find i t helpful to scan theexampl esembedded in thenormati ve
definitions and to see Annex B, Glossary.
Readers should pay close attention to Clause 3, Terminology and conventions used in this standard. An
understanding of the terminology defined i n Clause 3 i s necessary for a precise interpretati on of thi s stan-
dard.
Clause 4, Elaboration and simulation semantics, definesthebehavi or of theSystemCkernel and is central
to an understanding of SystemC. The semantic defi nitions given i n the subsequent cl auses detai li ng the
indi vi dual cl asses arebuil t on thefoundati onsl ai di n Clause4.
The cl auses from Clause 5 onward define the publ ic interface to the SystemC class l ibrary. The fol lowi ng
informati on i sl isted for eachclass:
a) A C++ sourcecodeli sting of theclass defini tion
b) A statement of any constrai ntson theuseof theclassand i ts members
c) A statement of thesemanticsof thecl assand itsmembers
d) For certai nclasses, adescri pti on of functions, typedefs, andmacros associated withtheclass
e) Informativeexamples il lustrating both typical and atypical uses of thecl ass
2
Information onreferencescanbefound in Clause2.
3
Notesi ntext, tables, and figuresaregi ven for information onl y and do not contain requirementsneeded to i mplement thestandard.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


3
Copyright 2012 IEEE. All rights reserved.
Readers shoul d bear in mind that the primary obli gation of a tool vendor i s to impl ement the abstract
semanti csdefined i nClause4, usi ng theframework and constraintsprovi ded by theclassdefini tionsstarting
in Cl ause5.
The clauses from Clause 9 onward defi ne the public interface to the TLM-2.0 class li brary, i ncl udi ng the
classesof thei nteroperabi li ty layer and theuti lities.
Cl ause17 definestheTLM-1 Messagepassi ng interface, including tlm_fifoand anal ysi sports.
Annex A is i ntended to aid thereader in theunderstanding of thestructureand i ntent of the SystemC class
li brary.
Annex B i sagl ossary giving informal descri pti onsof thetermsused in thi sstandard.
Annex C l ists the deprecated features, that i s, features that were present in versi on 2.0.1 of the Open
SystemC Initi ati ve (OSCI) open source proof-of-concept SystemC implementation but are not part of thi s
standard.
Annex D l ists thechangesbetween IEEE Std1666-2005 and IEEE 1666-2011.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


4
Copyright 2012 IEEE. All rights reserved.
2. Normative references
Thefol lowi ng referenced documents are indispensabl efor the appli cation of thisdocument (i.e., they must
beunderstood and used, so each referenced document is cited in text and itsrelati onship to thi sdocument is
expl ai ned). For dated references, only theedi ti on cited appl ies. For undated references, thel atest edi ti on of
thereferenced document (i ncluding any amendmentsor corri genda) appli es.
This standard shal l beused in conj unction with thefol lowi ngpubli cati ons:
ISO/IEC 14882:2003, Programming LanguagesC++.
4
4
ISO/IEC publications are avai lable from the I SO Central Secretariat, Case Postal e 56, 1 rue de Varemb, CH-1211, Genve 20,
Switzerland/Suisse (http://www.iso.ch/). ISO/IEC publ icati ons are also avail abl e in the United States from Global Engi neering
Documents, 15 InvernessWay East, Engl ewood, Colorado 80112, USA (http://gl obal .ihs.com/). El ectronic copi esare avai lable in the
United States from the Ameri can National Standards Institute, 25 West 43rd Street, 4th Floor, New York, NY 10036, USA (http://
www.ansi.org/).
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


5
Copyright 2012 IEEE. All rights reserved.
3. Terminology and conventions used in this standard
3.1 Terminology
3.1.1 Shall, should, may, can
Theword shal l is used to indicateamandatory requirement.
Theword shoul d isused to recommend aparti cular courseof action, but it doesnot i mposeany obli gati on.
Theword may is used to mean shal l bepermitted(in thesenseof bei ngl egal ly al lowed).
Theword can is used to mean shal l beableto (i n thesenseof being technicall y possi bl e).
In somecases, word usageisqual ified to indi cateon whomtheobl igation fal ls, such as an appl i cati on may
or an i mpl ementati on shal l .
3.1.2 Implementation, application
The word i mpl ementati on is used to mean any speci fi c i mplementation of the ful l SystemC, TLM-1, and
TLM-2.0class librariesasdefi ned in thisstandard, only thepubl ic interfaceof whichneed beexposed to the
appl ication.
Theword appl i cati on i sused to mean aC++ program, wri ttenby an enduser, that usestheSystemC, TLM-
1, and TLM-2.0 class li brari es, that is, usesclasses, functions, or macrosdefi ned in thi sstandard.
3.1.3 Call, called from, derived from
Thetermcal l is taken to mean call di rectl y or indirectly. Call indirectl y meanscal l an intermedi atefunction
that i n turn cal ls thefunction in questi on, wherethechai nof function call smay beextended indefi ni tely.
Simil arly, cal l ed fr om means cal led from di rectl y or i ndi rectl y.
Except whereexpli ci tl y qual ified, thetermder i ved from istaken to mean deri ved di rectl y or i ndi rectl y from.
Deri ved indirectly frommeans derived from oneor moreintermediatebasecl asses.
3.1.4 Specific technical terms
Thefol lowi ng terms are sometimes used to refer to classesand someti mes used to refer to objectsof those
classes. When the di stincti on is important, the usage of the term may be qual ified. For exampl e, a port
i nstance is an object of aclass deri ved from thecl ass sc_port, whereasaport cl ass isa cl assderi ved from
class sc_port.
A modul e is acl ass derived fromtheclass sc_module.
A port is either aclassderived fromthecl ass sc_port or an obj ect of theclasssc_port.
An expor t is an object of theclasssc_export.
An i nter face is acl ass derived fromtheclasssc_interface.
An i nter face pr oper is an abstract cl ass derived fromtheclass sc_interface but not derived fromthe cl ass
sc_object.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


6
Copyright 2012 IEEE. All rights reserved.
A pr i mi ti ve channel i s a non-abstract cl ass derived from one or morei nterfaces and also derived fromthe
classsc_prim_channel.
A hi er ar chi cal channel isanon-abstract classderived fromoneor moreinterfacesand also deri ved fromthe
classsc_module.
A channel isanon-abstract classderivedfromoneor morei nterfaces. A channel may beapri mitivechannel
or a hierarchi cal channel . If not, it i s strongly recommended that a channel be deri ved from the cl ass
sc_object.
An event is anobject of theclasssc_event.
A si gnal is anobject of theclasssc_signal.
A process i nstance is an object of an i mplementati on-defined cl ass deri ved from the class sc_object and
created by one of the three macros SC_METHOD, SC_THREAD, or SC_CTHREAD or by cal li ng the
functi on sc_spawn.
The term process refers to either a process i nstance or to the member function that is associated wi th a
processinstancewhen i t iscreated. Themeani ng is madeclear by thecontext.
A stati c pr ocess is a process created during the construction of the modul e hierarchy or from the
before_end_of_elaborationcal lback.
A dynami c pr ocess is aprocess created from theend_of_elaboration cal lback or duri ngsimul ation.
An unspawned process is a process created by invoking one of the three macros SC_METHOD,
SC_THREAD, or SC_CTHREAD. An unspawned process is typicall y a stati c process, but i t would be a
dynami c process if invoked fromtheend_of_elaboration cal lback.
A spawned process i saprocess created by cal li ng thefuncti on sc_spawn. A spawned process i stypical ly a
dynami c process, but it woul d beastatic processi f sc_spawnis cal led beforetheend of el aboration.
A process handl e is an object of theclass sc_process_handle.
The modul e hi er archy is the total set of module i nstances constructed duri ng el aboration. The term is
sometimes used to include al l of the obj ects i nstantiated within those modules during elaborati on. The
modulehi erarchy is asubset of theobj ect hi erar chy.
The obj ect hi erar chy is the total set of objects of the cl ass sc_object. Part of the object hierarchy is
constructed during elaboration (the modul e hi erar chy) and i ncl udes modul e, port, primi ti ve channel, and
stati c process i nstances. Part i sconstructed dynami call y and destroyed dynami call y duri ng simul ation and
includes dynamic process instances (see5.16). Events do not belong to the obj ect hierarchy, al though l ike
objectsof thecl asssc_object, eventsmay haveahierarchi cal name.
A gi ven instancei swi thi n modul eM if theconstructor of thei nstanceiscall ed (expl ici tly or i mpli citl y) from
the constructor of module M and i f the instance is not within another module instance that is i tself within
moduleM.
A given modul ei ssai d to contai n agi ven instanceif theinstanceiswithi n that module.
A chi l d of agiven moduleis an i nstancethat i swithi n that module.
A parent of agi ven instancei samodul ehaving that instanceasachi ld.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


7
Copyright 2012 IEEE. All rights reserved.
A top-l evel modul e is amodulethat i snot i nstantiated withi n any other module.
The concepts of el aborati on and si mul ati on are defined i n Cl ause 4. The terms duri ng el aborati on and
duri ng si mul ati on indicate that an action may happen at that ti me. Thei mplementati on makesanumber of
cal lbacks to theapplication during el aboration and simul ation. Whether aparticular action isall owed wi thin
aparticular cal lback cannot bei nferredfromthetermsduri ng el abor ati on and duri ng si mul ati on al onebut is
defined i ndetai l in 4.4. For exampl e, anumber of acti ons that arepermittedduri ng el abor ati on areexpl icitly
forbidden duri ng theend_of_elaboration cal lback.
The term duri ng el aborati on includes the constructi on of the modul e hi erarchy and the
before_end_of_elaborationcal lbacks.
The term duri ng el aborati on or si mul ati on includes every phase from the construction of the modul e
hierarchy up to and including thefinal del ta cycle, but neither i ncludes nor excludes activity subsequent to
thefinal del tacycl e. In other words, useof thi sterminfersnothi ng about whether speci fi c acti onsareor are
not permi tted after thefi nal deltacycle.
Thetermduri ng si mul ati on includesthei ni ti ali zati on, eval uation, and updatephasesand any period when
simul ation is paused.
3.2 Syntactical conventions
3.2.1 Implementation-defined
The i tali cized term i mpl ementati on-defi ned i s used where part of a C++ defi ni ti on i s omi tted from this
standard. In such cases, an implementation shall providean appropri atedefini ti on that honorsthesemantics
defined in this standard.
3.2.2 Disabled
Thei tali cized termdi sabl ed is used within aC++ classdefi ni ti on to indi catea group of member functi ons
that shall be di sabled by the i mplementati on so that they cannot be cal led by an appli cati on. The di sabled
member functi ons aretypical ly thedefault constructor, thecopy constructor, or theassi gnment operator.
3.2.3 Ellipsis (...)
An el li psi s, which consi stsof threeconsecutivedots(...), isused to i ndi catethat i rrel evant or repeti ti veparts
of aC++ codeli sting or exampl ehavebeen omitted for cl arity.
3.2.4 Class names
Cl ass names italici zed and annotated wi th a superscript dagger (

) should not be used expli ci tl y within an


appl icati on. Moreover, an appli cation shal l not createan object of such aclass. It i sstrongly recommended
that thegiven classnamebeused. However, an i mplementati on may substituteanalternati vecl assnamein
placeof every occurrenceof aparticular daggeredclassname.
Only thecl ass name is considered here. Whether any part of thedefi nition of the classi si mplementati on-
defined is aseparatei ssue.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


8
Copyright 2012 IEEE. All rights reserved.
Theclassnamesarethefol lowing:
3.2.5 Embolded text
Emboldi ng is used to enhance readabi li ty i n thi s standard but has no si gni fi cance in SystemC itself.
Emboldi ng is used for names of types, cl asses, functions, and operators in runni ng text and i n code
fragments where these names are defi ned. Embol ding is never used for uppercase names of macros,
constants, and enuml iterals.
3.3 Semantic conventions
3.3.1 Class definitions and the inheritance hierarchy
An impl ementation may di ffer fromthi s standard i n that an i mplementati on may introduce addi tional base
classes, class members, and fri ends to theclasses defined in thi s standard. An i mplementati on may modify
theinheri tancehi erarchy by movi ng class membersdefi ned by thi sstandard i nto baseclassesnot defi ned by
thi s standard. Such additions and modificati ons may be made as necessary in order to i mplement the
semanti cs defi ned by this standard or i n order to introduce additi onal functi onali ty not defined by this
standard.
3.3.2 Function definitions and side-effects
This standard explici tl y defi nes the semantics of the C++ functi ons i n the SystemC class l ibrary. Such
functi ons shall not have any side-effects that woul d contradict the behavior explici tl y mandated by this
standard. In general, the reader should assume the common-sense rul e that i f it is expl icitly stated that a
functi onshal l performacti onA, that functi on shall not performany acti on other thanA, either directly or by
cal li ng another function defi ned in this standard. However, a functi on may, and indeed i n certain
circumstances shall , perform any tasksnecessary for resourcemanagement, performanceoptimization, or to
support any ancil lary featuresof an implementation. Asan exampl eof resourcemanagement, it isassumed
that a destructor wi ll perform any tasks necessary to release the resources al located by the corresponding
constructor. As an exampl eof an anci ll ary feature, an i mplementati on could have the constructor for cl ass
sc_moduleincrement acount of thenumber of moduleinstancesin themodulehi erarchy.
3.3.3 Functions whose return type is a reference or a pointer
Many functi ons in this standard return a reference to an obj ect or a pointer to an obj ect; that is, the return
typeof thefunction isareferenceor apoi nter. Thi s subclausegivessomegeneral rul esdefini ng theli feti me
and theval idi ty of such obj ects.
sc_bi nd_pr oxy

sc_fxnum_bi tr ef

sc_si gned_bi tref

sc_ui nt_subref

sc_bi tref

sc_fxnum_fast_bi tref

sc_si gned_bi tref_r

sc_ui nt_subref_r

sc_bi tref_r

sc_fxnum_fast_subr ef

sc_si gned_subr ef

sc_unsi gned_bi tr ef

sc_concatr ef

sc_fxnum_subr ef

sc_si gned_subr ef_r

sc_unsi gned_bi tr ef_r

sc_concr ef

sc_i nt_bi tr ef

sc_subr ef

sc_unsi gned_subref

sc_concr ef_r

sc_i nt_bi tr ef_r

sc_subr ef_r

sc_unsi gned_subref_r

sc_context_begi n

sc_i nt_subref

sc_swi tch

sc_val ue_base

sc_event_and_expr

sc_i nt_subref_r

sc_ui nt_bi tr ef

sc_vector _i ter


sc_event_or _expr

sc_sensi ti ve

sc_ui nt_bi tr ef_r

IEEE Std 1666-2011


IEEE Standard for Standard SystemC

Language Reference Manual


9
Copyright 2012 IEEE. All rights reserved.
An object returned from afuncti on by pointer or by referencei ssaid to bevali d during any peri od in whi ch
the obj ect i s not del eted and the val ueor behavior of theobject remai ns accessibl eto the appli cation. If an
appl ication refers to thereturned object after i t ceasesto bevali d, the behavior of the implementati on shal l
beundefined.
3.3.3.1 Functions that return *this or an actual argument
In certai n cases, the object returned is either an obj ect (*this) returned by reference fromits own member
functi on (for example, theassi gnment operators), or i t i san object that waspassed by referenceasan actual
argument to the functi on being call ed [for example, std::ostream& operator<< (std::ostream&, const
T&)]. In ei ther case, thefunction cal l i tsel f pl acesno addi tional obl igati onson thei mplementation concern-
ing theli feti meand val idity of theobj ect foll owing returnfromthefuncti on call .
3.3.3.2 Functions that return const char*
Certai n functions have the return type const char*; that i s, they return a pointer to a nul l-terminated
character string. Such strings shall remai n val id until the end of theprogramwi th theexcepti on of member
functi on sc_process_handle::nameand member functi onsof cl ass sc_report, wherethei mplementati on i s
only required to keep thestri ngvali d whi letheprocesshandleor report object itself isval id.
3.3.3.3 Functions that return a reference or pointer to an object in the module hierarchy
Certai n functi ons return a reference or poi nter to an object that forms part of the module hi erarchy or a
property of such an obj ect. Thereturntypesof thesefunctionsincludethefol lowi ng:
a) sc_i nterface* // Returnsachannel
b) sc_event& // Returnsanevent
c) sc_event_finder& // Returnsanevent fi nder
d) sc_time& // Returnsaproperty of pri mi ti vechannel sc_cl ock
Thei mplementati on i sobli ged to ensurethat thereturned obj ect is val id either until the channel , event, or
event fi nder i s del eted expli citly by the appli cation or unti l the destruction of the modul e hierarchy,
whichever i ssooner.
3.3.3.4 Functions that return a reference or pointer to a transient object
Certai n functions return a reference or pointer to an object that may be deleted by the appli cati on or the
implementation beforethedestruction of themodulehierarchy. The return typesof thesefuncti onsi ncl ude
thefol lowing:
a) sc_object *
b) sc_event *
c) sc_attr_base*
d) std::stri ng& // Property of an attributeobject
Thefunctionsconcerned arethefol lowi ng:
sc_object* sc_process_handl e::get_parent_object() const;
sc_object* sc_process_handl e::get_process_obj ect() const;
sc_object* sc_obj ect::get_parent_object() const;
sc_object* sc_event::get_parent_obj ect() const;
sc_object* sc_fi nd_object( const char* );
sc_event* sc_find_event( const char* );
sc_attr_base* sc_obj ect::get_attribute( const std::stri ng& );
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


10
Copyright 2012 IEEE. All rights reserved.
const sc_attr_base* sc_obj ect::get_attri bute( const std::string& ) const;
sc_attr_base* sc_obj ect::remove_attribute( const std::stri ng& );
const std::string& sc_attr_base::name() const;
The i mplementati on i s only obli ged to ensure that the returned reference i s vali d until the sc_object,
sc_event, sc_attr_base, or std::stringobj ect itself is del eted.
Certai n functionsreturn areferencetoan obj ect that representsatransient coll ection of other objects, where
the appl icati on may add or del ete obj ects before the destructi on of the module hierarchy such that the
contentsof thecoll ection woul d bemodified. Thereturn types of thesefuncti ons includethefollowi ng:
a) std::vector< sc_obj ect * > &
b) std::vector< sc_event * > &
c) sc_attr_cltn*
Thefunctionsconcerned arethefol lowi ng:
virtual const std::vector<sc_object*>& sc_module::get_chi ld_obj ects() const;
virtual const std::vector<sc_event*>& sc_modul e::get_child_events() const;
const std::vector<sc_object*>& sc_process_handl e::get_chil d_objects() const;
const std::vector<sc_event*>& sc_process_handl e::get_chil d_events() const;
virtual const std::vector<sc_object*>& sc_object::get_chi ld_obj ects() const;
virtual const std::vector<sc_event*>& sc_obj ect::get_chil d_events() const;
const std::vector<sc_object*>& sc_get_top_level _obj ects();
const std::vector<sc_event*>& sc_get_top_l evel_events();
sc_attr_cltn& sc_obj ect::attr_cltn();
const sc_attr_cltn& sc_obj ect::attr_cl tn() const;
Thei mplementati oni sonly obl iged to ensurethat thereturned obj ect (thevector or col lecti on) isitself val id
until an sc_object, an sc_event, or an attri butei s added or del eted that would affect thecoll ection returned
by thefunction i f i t wereto becall edagai n.
3.3.3.5 Functions sc_time_stamp and sc_signal::read
Thei mplementati on is obl igedto keeptheobj ect returned fromfuncti onsc_time_stamp val id until thestart
of thenext ti med noti fi cati on phase.
Thei mplementati oni sobl iged to keeptheobject returnedfrom function sc_signal::read val id unti l theend
of thecurrent evaluation phase.
For both functions, it is strongly recommended that the appl icati on be written in such a way that it would
havei denti cal behavior, whether thesefuncti ons return areferenceto an object or return thesameobject by
val ue.
3.3.4 Namespaces and internal naming
An impl ementation shal l place every decl arati on specified by this standard, with the one excepti on of
sc_main, wi thin one of the fi ve namespaces sc_core, sc_dt, sc_unnamed, tlm, and tlm_utils. The core
languageand predefi ned channel sshall bepl aced in thenamespacesc_core. TheSystemC datatypes proper
shal l be pl aced in the namespace sc_dt. The SystemC utili ti es are di vi ded between the two namespaces
sc_coreand sc_dt.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


11
Copyright 2012 IEEE. All rights reserved.
It is recommended that an i mplementation use nested namespaces wi thin sc_core and sc_dt in order to
reduceto aminimumthenumber of impl ementati on-defined namesin thesetwo namespaces. Thenamesof
any such nested namespacesshall bei mplementati on-defi ned.
In general, the choi ce of internal, i mplementati on-specific names withi n an i mplementati on can cause
naming confl ictswi thin an appli cation. It i sup to thei mplementor tochoosenamesthat areunli kel y to cause
naming confl icts wi thin anappli cati on.
3.3.5 Non-compliant applications and errors
In the case where an appli cati on fai ls to meet an obl igati on imposed by this standard, the behavi or of the
SystemC impl ementation shall be undefi ned in general . When thi sresultsi n the violation of adiagnosable
rul eof theC++ standard, theC++ impl ementation wi ll issue adi agnosti c messagein conformancewi th the
C++ standard.
When this standard expli ci tl y statesthat thefail ureof an appl icati on to meet aspeci fi c obli gation i san err or
or a war ni ng, the SystemC impl ementation shall generate a diagnosti c message by call ing the functi on
sc_report_handler::report. In the case of an err or , the implementation shall call function report with a
severi ty of SC_ERROR. In the case of a warni ng, the i mplementati on shall call functi on report with a
severi ty of SC_WARNING.
An i mplementati on or an appli cati on may choose to suppress run-ti me error checki ng and di agnostic
messages because of considerations of efficiency or practicality. For exampl e, an appl ication may cal l
member function set_actionsof cl ass sc_report_handler to take no action for certain categori es of report.
An appl ication that fai lsto meet theobl igati onsimposed by thisstandard remai nsin error.
There are cases where this standard states expli ci tl y that a certai n behavior or resul t i s undefi ned. This
standard places no obl igations on theimpl ementation in such aci rcumstance. In particular, such a ci rcum-
stancemay or may not result in anerr or or awarni ng.
3.4 Notes and examples
Notes appear at the end of certain subclauses, designated by the uppercase word NOTE. Notes often
descri betheconsequences of rul es defi ned el sewherein thisstandard. Certai n subclausesi ncl udeexamples
consisti ngof fragments of C++ sourcecode. Such notesandexampl esareinformati veto hel p thereader but
arenot an official part of thi sstandard.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


12
Copyright 2012 IEEE. All rights reserved.
4. Elaboration and simulation semantics
An i mplementati on of the SystemC class l ibrary i ncl udes a publ ic shel l consi sting of those predefined
classes, functi ons, macros, and so forth that can beuseddirectl y by an appl ication. Such featuresaredefined
in Clause 5, Cl ause 6, Clause 7, and Clause 8 of thi s standard. An i mplementati on al so i ncl udes a pri vate
ker nel that i mplements thecorefuncti onali ty of theclass li brary. Theunderlyi ng semanti csof thekernel are
defined in this clause.
Theexecution of aSystemCappl ication consi sts of el aborati on foll owed by si mul ati on. Elaborati on resul ts
in thecreation of themodul e hi erar chy. Elaborati on i nvol ves the execution of appl ication code, the publ ic
shel l of the i mplementation (as menti oned i n the preceding paragraph), and the pri vate kernel of the
impl ementation. Simul ation i nvolves the execution of theschedul er, part of the kernel, whi ch i n turn may
executeprocesses within theappli cation.
In addition to providi ng support for el aboration and i mplementing the schedul er, the kernel may also
provide i mplementati on-speci fic functi onali ty beyond the scope of this standard. As an example of such
functi onali ty, the kernel may save the state of the module hi erarchy after elaborati on and run or restart
simul ation from that point, or it may support the graphi cal displ ay of state variables on-the-fly during
simul ation.
Thephasesof el aboration and si mulati onshal l runi n thefollowi ngsequence:
a) ElaborationConstruction of themodul ehi erarchy
b) ElaborationCallbacks to function before_end_of_elaboration
c) ElaborationCallbacks to function end_of_elaboration
d) SimulationCallbacks to function start_of_simulation
e) SimulationInitialization phase
f) SimulationEvaluation, update, delta notification, and ti med noti fi cation phases(repeated)
g) SimulationCallbacks to function end_of_simulation
h) SimulationDestruction of the module hierarchy
4.1 Elaboration
The pri mary purpose of el aboration is to create i nternal data structures within the kernel as required to
support thesemanti cs of simul ati on. During el aboration, theparts of themodule hi erarchy (modul es, ports,
pri mitivechannel s, andprocesses) arecreated, andportsand exports arebound to channel s.
Theacti ons statedi nthefoll owi ng subcl ausescan occur duri ng el aborati onand onl y duri ng elaborati on.
NOTE 1Because these actions can only occur during elaboration, SystemCdoesnot support thedynamic creation or
modification of themodulehierarchy during simulation, althoughit doessupport dynamic processes.
NOTE 2Other actions besides thoselisted below may occur during elaboration, provided that they do not contradict
any statement madeinthisstandard. For example, theobjectsof classsc_dt::sc_logicmay becreatedduring elaboration
and spawned processes may be created during elaboration, but the function notify of class sc_event cannot becalled
during elaboration.
4.1.1 Instantiation
Instances of thefollowi ng cl asses(or cl assesderi ved fromtheseclasses) may becreated during el aboration
and only during el aboration. Such i nstances shall not be deleted before the destructi on of the modul e
hierarchy at theend of simul ation.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


13
Copyright 2012 IEEE. All rights reserved.
sc_module (see5.2)
sc_port (see5.12)
sc_export (see5.13)
sc_pri m_channel (see5.15)
An impl ementation shall permit an appl ication to have zero or one top-l evel module and may permit more
than onetop-l evel module(see4.3.4.1 and4.3.5).
Instances of cl ass sc_module and cl ass sc_prim_channel may only be created wi thin a module or from
functi on sc_main (or a function cal led fromsc_main), or in the absenceof an sc_main (see 4.3.5), i n the
formof oneor moretop-l evel modul es. Instancesof cl ass sc_port and class sc_export can only becreated
wi thin a modul e. It shall be an error to i nstanti ate a modul e or primitive channel other than as descri bed
above, or to instanti ateaport or export other thanwi thi namodule.
Thei nstantiati on of a module al so i mpli es the construction of objectsof cl ass sc_module_name and cl ass
sc_sensi ti ve

(see5.4).
Al though these rul es al low for considerable flexi bil ity in i nstantiati ng the module hi erarchy, it is strongl y
recommended that, wherever possibl e, module, port, export, and primitive channel i nstances be data
members of a module or thei r addresses be stored in data members of a module. Moreover, the names of
thosedatamembersshoul d matchthestring namesof theinstanceswherever possi bl e.
NOTE 1The four classes sc_module, sc_port, sc_export, and sc_prim_channel are derived from acommon base
classsc_object, and thus, they havesomemember functionsin common (see5.16).
NOTE 2Objects of classes derived from sc_object but not derived fromoneof thesefour classes may beinstantiated
during elaboration or simulation, asmay objectsof user-defined classes.
Exampl e:
#include"systemc.h"
struct Mod: sc_modul e
{
SC_CTOR(Mod) { }
} ;
struct S
{
Mod m; // Unusual codi ng styl e- modul ei nstancewi thi nstruct
S(char* name_) : m(name_) { }
} ;
struct Top: sc_modul e // Fivei nstancesof moduleMod exi st within modul eTop.
{
Mod m1; // Recommended codi ng styl e
Mod *m2; // Recommended codi ng styl e
Ss1;
SC_CTOR(Top)
: m1("m1"), // m1.name() returns"top.m1"
s1("s1") // s1.m.name() returns"top.s1"
{
m2 = new Mod("m2"); // m2->name() returns"top.m2"
f();
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


14
Copyright 2012 IEEE. All rights reserved.
S*s2 = new S("s2"); // s2->m.name() returns "top.s2"
}
void f() {
Mod *m3 = new Mod("m3"); // Unusual codi ngstyl e- not recommended
} // m3->name() returns"top.m3"
} ;
int sc_main(i nt argc, char* argv[])
{
Top top("top");
sc_start();
return 0;
}
4.1.2 Process macros
An unspawned pr ocess i nstance is aprocesscreatedby invoking oneof thefol lowing threeprocessmacros:
SC_METHOD
SC_THREAD
SC_CTHREAD
The name of a member function belongi ng to a cl ass derived fromclass sc_module shal l be passed as an
argument to the macro. Thi s member functi on shal l become the function associ ated wi th the process
instance.
Unspawnedprocessescan becreated during el aborati on or fromtheend_of_elaboration call back. Spawned
processes may becreatedby cal li ng thefuncti on sc_spawnduring elaboration or simul ation.
The purpose of the process macros i s to regi ster the associated functi on wi th the kernel such that the
schedul er can call back that member functi on duri ng simul ation. It is al so possibleto usespawned processes
for thi s samepurpose. Theprocess macros areprovided for backward compati bi li ty wi th earl ier versi onsof
SystemCand to providecl ockedthreads for hardwaresynthesi s.
4.1.3 Port binding and export binding
Port i nstances can be bound to channel instances, to other port i nstances, or to export i nstances. Export
instances can be bound to channel i nstances or to other export i nstances but not to port instances. Port
binding i s an asymmetri cal rel ationshi p, and export bi ndi ng i s an asymmetrical relationshi p. If a port is
bound to achannel , it is not trueto say that thechannel is bound to theport. Rather, it istrueto say that the
channel is thechannel to whi chtheport i sbound.
Portscan bebound by nameor by posi tion. Named port bi nding i sperformedby amember functi onof class
sc_port (see 5.12.7). Posi ti onal port binding i s performed by a member function of cl ass sc_module (see
5.2.19). Exports can onl y be bound by name. Export bi ndi ng is performed by a member functi on of class
sc_export (see5.13.7).
A given port instanceshall not bebound both by nameand by posi ti on.
A port shoul dtypi call y bebound wi thi ntheparent of themodul ei nstancecontaini ng that port. Hence, when
port A i s bound to port B, the modul e containing port A wi ll typical ly be i nstanti ated wi thi n the module
contai ning port B. An export shoul d typi cal ly be bound withi n the modul e containi ng the export. A port
should typi cal ly bebound to achannel or aport that li es wi thi nthesamemodul ein which theport i sbound
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


15
Copyright 2012 IEEE. All rights reserved.
or to an export withi n achi ld modul e. An export shoul d typi call y bebound to achannel that li eswithi n the
samemodulein which theexport i sboundor to an export wi thin achi ld module.
When port A is bound to port B, and port B isbound to channel C, theeffect shal l be thesameasi f port A
werebound directly to channel C. Wherever thi sstandardrefersto port A bei ng bound tochannel C, i t shal l
beassumed thismeansthat port A i sbound either directly to channel Cor to another port that isitself bound
to channel Caccordi ng tothis very samerule. Thi ssameruleshall apply whenbi ndi ng exports.
Port and export binding can occur during el aboration and onl y during el aboration. Whether a port need be
bound is dependent on theport pol icy argument of the port i nstance, whereas every export shal l be bound
exactl y once. A modul emay havezero or moreportsand zero or moreexports. If amodulehasno ports, no
(positional ) port bindings are necessary or permi tted for instancesof that module. Ports may be bound (by
name) i n any sequence. The bi ndi ng of ports belongi ng to di fferent modul e instances may be interleaved.
Sinceaport may bebound to another port that hasnot yet i tsel f been bound, thei mplementati on may defer
the completion of port binding unti l a later time duri ng el aboration, whereas exports shall be bound
immedi ately. Such deferred port binding shal l becompleted by the impl ementation beforethecall backs to
functi on end_of_elaboration.
Thechannel to which a port is bound shall not bedel eted before thedestruction of themodul ehierarchy at
theend of simul ation.
Where permi tted in thedefi niti on of theport object, asingleport can be bound to multi ple channel or port
instances. Such ports areknown asmul ti ports (see5.12.3). An export can onl y bebound once. It shall bean
error to bi nd agi ven port instanceto agiven channel instancemorethan once, even i f theport isamultiport.
When a port is bound to achannel, thekernel shall call the member function register_port of thechannel .
Thereisno corresponding functi on cal led when an export i sbound(see5.14).
Thepurposeof port and export binding isto enableaport or export to forward i nterfacemethod cal lsmade
during si mulation to thechannel instancesto whi ch that port wasbound during el aborati on. Thisforwarding
is performed duri ng simul ation by member functionsof the class sc_port and the cl ass sc_export, such as
operator->. A port r equi r es the servicesdefi ned by an interface (that is, the type of the port), whereas an
export provi des theservi ces definedby an i nterface(that is, thetypeof theexport).
NOTE 1A phrase such as bi nd a channel to a por t is not used in this standard. However, it is recognized that such a
phrasemay beusedinformally to meanbi nd a por t to a channel .
NOTE 2A port of a child module instance can be bound to an export of that samechild moduleinstance.
NOTE 3The member function register_port isdefined in theclasssc_interfacefromwhich every channel isderived.
4.1.4 Setting the time resolution
The si mulati on time resolution can be set duri ng elaboration and only duri ng el aboration. The time
resoluti oni sset by call ing thefunction sc_set_time_resolution (see5.11.3).
NOTETime resolution can only be set globally. Thereis no concept of alocal timeresolution.
4.2 Simulation
This subcl ause defines the behavi or of the schedul er and the semanti cs of simul ated ti me and process
executi on.
The primary purpose of the schedul er is to tri gger or resume the execution of the processes that the user
suppli es as part of the appli cation. The scheduler i s event-dri ven, meaning that processes are executed i n
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


16
Copyright 2012 IEEE. All rights reserved.
responseto theoccurrenceof events. Eventsoccur (arenoti fi ed) at preci sepoints in simul ation ti me. Events
arerepresented by obj ects of theclass sc_event, and by this cl ass al one(see5.10).
Simul ation time is an i nteger quantity. Simul ation time is initiali zed to zero at the start of simulati on and
increasesmonotonicall y during simul ati on. Thephysi cal significanceof theinteger val uerepresenti ng ti me
wi thin the kernel is determined by the si mulati on time resoluti on. Simul ation ti me and ti me i ntervals are
represented by class sc_time. Certain functions al low ti me to be expressed as a value pair having the
signaturedouble,sc_time_unit (see5.11.1).
The scheduler can execute a spawned or unspawned process i nstance as a consequence of one of the
fol lowi ng fivecauses, and theseal one:
In response to the process instance having been made runnabl e during the ini tial ization phase (see
4.2.1.1)
In response to a call to function sc_spawn during simulati on
In response to the occurrence of an event to whi ch theprocessi nstanceissensi ti ve
In response to a time-out having occurred
In response to a call to a process control member functi on of theclasssc_process_handle.
Thesensi ti vi ty of aprocess i nstanceisthe set of events and ti me-outs that can potentiall y causetheprocess
to be resumed or tri ggered. The stati c sensi ti vi ty of an unspawned process instance is fixed during
elaborati on. The stati c sensi ti vi ty of a spawned process i nstance is fixed when the function sc_spawn i s
cal led. The dynami c sensi ti vi ty of a process instance may vary over time under the control of the process
itsel f. A processi nstancei ssaid to besensi ti ve to an event i f theevent has beenadded to thestati c sensi ti vity
or dynami c sensi tivi ty of theprocessi nstance. A ti me-out occurswhenagiventimeinterval has elapsed.
Thescheduler shal l also manageevent notificati ons and pri mitivechannel updaterequests.
4.2.1 The scheduling algorithm
Thesemantics of thescheduli ng algori thm aredefi ned in the foll owing subcl auses. For the sakeof cl arity,
imperative l anguage i s used in this descri pti on. The descri pti on of the scheduli ng al gori thm uses the
fol lowi ng four sets:
The set of runnable processes
The set of update requests
The set of delta notifications and time-outs
The set of timed notifications and time-outs
An i mplementati on may substi tutean alternativescheme, provi ded thescheduli ng semanti cs given hereare
retai ned.
A processinstanceshal l not appear morethan oncei ntheset of runnableprocesses. An attempt to add to this
set aprocess instancethat i salready runnableshall bei gnored.
An update request results from, and only from, a cal l to member function request_update or
async_request_updateof classsc_prim_channel (see5.15.6).
An i mmedi ate noti fi cati on results from, and only from, acall to member functi on notify of class sc_event
wi th no arguments(see5.10.6).
A del ta noti fi cati on resul ts from, and only from, acal l to member functi on notify of cl ass sc_event with a
zero-valuedtimeargument.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


17
Copyright 2012 IEEE. All rights reserved.
A ti med noti fi cati on resul ts from, and onl y from, a call to member function notify of class sc_event with a
non-zero-valued time argument. Thetime argument determi nes the time of the notificati on, relati ve to the
ti mewhen functi onnotify is cal led.
A ti me-out resul ts from, and onl y from, certai n calls to functi ons wait or next_trigger, which aremember
functi ons of class sc_module, member functi ons of cl ass sc_prim_channel, and non-member functi ons. A
ti me-out resul ti ng fromacal l wi th azero-valued timeargument i sadded totheset of deltanotificationsand
ti me-outs. A time-out resulting fromacal l with anon-zero-valuedti meargument isadded to theset of ti med
noti fi cati ons and time-outs(see5.2.17and5.2.18).
Thescheduler starts by executing thei nitiali zati on phase.
4.2.1.1 Initialization phase
Performthefol lowi ng threestepsi ntheorder gi ven:
a) Run theupdatephaseasdefi ned in 4.2.1.3 but without conti nui ngto thedeltanoti fi cation phase.
b) Add every method and thread process i nstance in the obj ect hierarchy to the set of runnable
processes, but exclude those process i nstances for whi ch the functi on dont_initialize has been
cal led, and excludecl ocked thread processes.
c) Run thedeltanotificati on phase, asdefi ned i n 4.2.1.4. At theend of thedeltanotificati on phase, go
to theeval uation phase.
NOTEThe update and delta notification phases are necessary because update requests can be created during
elaboration in order to set initial valuesfor primitivechannels, for example, fromfunctioninitializeof classsc_inout.
4.2.1.2 Evaluation phase
Fromtheset of runnableprocesses, sel ect aprocessi nstance, removei t fromtheset, and onl y then trigger or
resumei tsexecuti on. Run theprocessi nstancei mmediately and without i nterruption up to thepoi nt whereit
either returnsor, i n thecaseof athreador cl ocked thread process, call sthefuncti on wait or call sthemember
functi on suspendof aprocesshandl eassociated wi th theprocessi nstancei tsel f.
Since process instances execute without i nterruption, onl y a si ngle process instance can berunni ng at any
one ti me, and no other process instance can execute until the currently executi ng process instance has
yielded control to thekernel . A processshal l not pre-empt or i nterrupt theexecution of another process. This
isknownasco-r outi ne semanticsor co-oper ati ve mul ti taski ng.
The order i n which process instances are sel ected from the set of runnabl e processes is impl ementation-
defined. However, if a specific versi on of a specific i mplementati on runs a specific appl ication usi ng a
specific input dataset, theorder of processexecution shall not vary from run to run.
A process may execute an immediate noti fi cati on, in which case all process i nstances that are currentl y
sensitiveto thenoti fi edevent shal l beaddedto theset of runnabl eprocesses. Such processinstancesshal l be
executed in thecurrent evaluation phase. Thecurrentl y executing processi nstanceshall not beadded to the
set of runnabl eprocessesas theresul t of an i mmediatenotification executed by theprocessinstanceitself.
A processmay cal l function sc_spawnto createaspawned processinstance, in whi ch casethenew process
instanceshall beaddedto theset of runnabl eprocesses(unlessfuncti on sc_spawn_options::dont_initialize
iscal led) andsubsequentl y executed in thi svery sameeval uation phase.
A processmay call themember functi on request_updateor async_request_updateof apri mitivechannel ,
which wi ll cause the member functi on update of that same pri mitive channel to be cal led back during the
very next updatephase.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


18
Copyright 2012 IEEE. All rights reserved.
A process may cal l aprocess control member function of the cl ass sc_process_handle, whi ch may causea
processinstanceto becomerunnabl ein thecurrent evaluati on phaseor may removeaprocessinstancefrom
theset of runnableprocesses.
Repeat thisstep unti l theset of runnableprocesses is empty; then goon to theupdatephase.
The scheduler is not pre-empti ve. An appl ication can assume that a method process wil l execute in its
entirety without interrupti on, and a thread or clocked thread process wi ll execute the code between two
consecutivecall stofunction wait wi thout interrupti on.
Because the order in which processes are run withi n the evaluati on phase is not under the control of the
appl ication, accessto shared storageshoul d beexpl icitly synchronizedtoavoid non-determi ni stic behavior.
An impl ementation runni ng on a machi ne that provi des hardware support for concurrent processes may
permi t two or more processes to run concurrently, provided that the behavior appears identical to the co-
routinesemantics defined i nthis subcl ause. In other words, thei mplementati onwould beobli ged toanal yze
any dependencies between processes and to constrain their execution to match theco-routinesemanti cs.
When an immediatenoti ficati onoccurs, onl y processesthat arecurrently sensiti vetothenotified event shal l
be made runnabl e. Thi s excludes processes that are only made dynami cal ly sensitive to the noti fied event
later i n thesameeval uation phase, unlessthoseprocesseshappen tobestati call y sensitiveto thegi ven event.
4.2.1.3 Update phase
Executeany and all pending cal ls to functi onupdateresulting fromcal ls to functi on request_updatemade
in theimmediatel y preceding evaluation phaseor madeduri ng elaborati onif theupdatephaseis executedas
part of the ini ti al ization phaseor resul ti ng fromcal ls to function async_request_update. Functi on update
shal l becall ed no morethanoncefor each primitivechannel i nstancei n eachupdatephase.
If no remaini ng pendi ng call s to functi on update exist, go on to the del ta noti fi cation phase(except when
executed from thei nitial ization phase).
4.2.1.4 Delta notification phase
If pendi ng delta noti fi cati ons or time-outs exist (whi ch can only result from cal ls to functi on notify or
functi on wait in theimmedi ately precedi ng evaluati on phaseor updatephase):
a) Determinewhichprocessinstancesaresensitiveto theseevents or ti me-outs.
b) Add al l such process instances totheset of runnabl eprocesses.
c) Removeall such noti fi cationsandtime-outsfromtheset of del tanotificationsand ti me-outs.
If, at the end of the del ta noti fi cati on phase, the set of runnabl e processes is non-empty, go back to the
eval uation phase.
4.2.1.5 Timed notification phase
If pending ti med notificationsor time-outsexist:
a) Advancesi mulati on timeto theti meof theearli est pendi ngtimed notificati on or time-out.
b) Determinewhi ch process i nstances aresensitiveto theevents notified and time-outs lapsi ng at thi s
precisetime.
c) Add al l such process instances totheset of runnabl eprocesses.
d) Removeall such noti fi cationsandtime-outsfromtheset of ti mednoti fi cati onsandtime-outs.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


19
Copyright 2012 IEEE. All rights reserved.
If no pendi ng timed notificati ons or time-outs exist, the end of simul ation has been reached. So, exi t the
schedul er.
If, at the end of the ti med noti fi cati on phase, the set of runnable processes is non-empty, go back to the
eval uation phase.
NOTEOn exiting the scheduler, the value of the simulation timewill depend on how thescheduler wasinvoked (see
4.3.4.2).
4.2.2 Initialization, cycles, and pauses in the scheduling algorithm
A del ta cycl e isasequenceof stepsin thescheduling al gori thmconsisti ngof thefoll owing stepsi ntheorder
given:
a) An evaluati onphase
b) An updatephase
c) A deltanoti fi cati on phase
Thei niti ali zati onphasedoesnot i ncl udeadel tacycle.
Update requests may be created duri ng el aborati on or before the i ni ti alizati on phase, and they shall be
schedul edto executei ntheupdatephaseduring theiniti ali zati onphase.
Delta notifi cati ons and timed notifications may be created during el aboration or before the ini ti al izati on
phase. Such delta noti fi cati ons shall be schedul ed to occur in the del ta notification phase during the
ini ti al izati on phase.
Thescheduler repeatedly executeswholedel tacycl esandmay ceaseexecution at theboundary between the
deltanotificati onandeval uation phases. Theonl y circumstancesin which thescheduler can ceaseexecution
other than at thi s boundary are after a call to functi on sc_stop, when an exception is thrown, or when
simul ation is stopped or aborted by thereport handler (see8.3).
When sc_pausei scal led, theschedul er shal l ceaseexecuti on at theend of adeltanoti fi cation phase, and if i t
isto resumeexecution, thescheduler shall resumeat thestart of thenext evaluati on phase.
An appl ication may create update requests and event notificati ons whil ethe schedul er is paused, and these
shal l be treated by the scheduler asi f they had been created in theevaluation phasei mmediately fol lowi ng
resumpti on, i n thefoll owing sense: updaterequestsshall bequeued to beexecuted i n thefirst updatephase
fol lowi ng resumpti on, immedi ate notifications shal l make any sensitive processes runnable in the fi rst
eval uation phase, and delta notificati ons shall make any sensitive processes runnabl e in the second
eval uation phasefol lowi ng resumpti on.
Update requests created before the i nitiali zati on phase or whi le the scheduler i s paused shal l not be
associ ated wi th any processi nstancewi th respect to therulesfor updating thestateof any primiti vechannel ,
for example, thewri ter poli cy of sc_signal.
NOTE 1The scheduling algorithmimplies theexistenceof three causal loops resulting fromimmediate notification,
deltanotification, and timed notification, asfollows:
The immediate notification loop isrestrictedto asingleevaluation phase.
The delta notification loop takes the path of an evaluation phase, followed by an updatephase, followed by a
deltanotification phase, and back to an evaluationphase. This loopadvancessimulationby onedeltacycle.
The timed notification loop takes thepath of an evaluation phase, followed by an updatephase, followed by a
delta notification phase, followed by a timed notification phase, and back to an evaluation phase. This loop
advancessimulationtime.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


20
Copyright 2012 IEEE. All rights reserved.
NOTE 2The immediate notification loop is non-deterministic in thesense that process execution can beinterleaved
withimmediatenotification, and theorder in which runnableprocessesareexecuted isundefined.
NOTE 3The delta notification and timed notification loops are deterministic in the sense that process execution
alternateswithprimitivechannel updates. If, within aparticular application, inter-processcommunication is confined to
using only deterministic primitivechannels, thebehavior of theapplication will beindependent of theorder in which the
processes areexecuted within theevaluation phase(assuming no other explicit dependencies on process order such as
external input or output exist).
4.3 Running elaboration and simulation
An impl ementation shal l provide ei ther or both of the foll owing two mechani sms for runni ng elaboration
and simul ation:
Under application control using functions sc_mainand sc_start
Under control of the kernel
Both mechanismsaredefined i n thefol lowi ng subclauses. An implementation is not obl igedtoprovideboth
mechanisms.
4.3.1 Function declarations
namespacesc_core{
int sc_elab_and_sim( i nt argc, char* argv[] );
int sc_argc();
const char* const* sc_argv();
enum sc_starvation_policy {
SC_RUN_TO_TIME,
SC_EXIT_ON_STARVATION
} ;
void sc_start();
void sc_start( const sc_ti me&, sc_starvation_pol icy p = SC_RUN_TO_TIME );
void sc_start( double, sc_time_unit, sc_starvation_pol icy p= SC_RUN_TO_TIME );
}
4.3.2 Function sc_elab_and_sim
Thefunction main that i s theentry point of theC++ programmay beprovi ded by theimpl ementation or by
the appli cati on. If function main is provided by the impl ementation, functi on main shall ini ti ate the
mechanisms for el aboration and si mulation as descri bed in thi s subcl ause. If functi on main is provided by
the appli cation, function main shall cal l the function sc_elab_and_sim, which i s the entry point i nto the
SystemCimpl ementation.
Thei mplementati onshall provi deafunction sc_elab_and_sim with thefoll owing declarati on:
int sc_elab_and_sim( i nt argc, char* argv[] );
Function sc_elab_and_sim shall i ni ti ate the mechanisms for runni ng el aboration and simulati on. The
appl icati on should pass the val ues of the parameters from functi on main as arguments to functi on
sc_elab_and_sim. Whether the appli cati on may cal l function sc_elab_and_sim more than once is
impl ementation-defined.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


21
Copyright 2012 IEEE. All rights reserved.
A return value of 0 from function sc_elab_and_sim shall i ndi cate successful completi on. An
implementation may useother returnvaluesto i ndi cateother termi nation conditions.
NOTEFunction sc_elab_and_simwasnamed sc_main_mainin an earlier version of SystemC.
4.3.3 Functions sc_argc and sc_argv
Thei mplementati onshall provi defuncti ons sc_argcand sc_argv with thefoll owi ng declarati ons:
int sc_argc();
const char* const* sc_argv();
These two functions shal l return the values of the arguments passed to functi on main or functi on
sc_elab_and_sim.
4.3.4 Running under application control using functions sc_main and sc_start
The appli cation provides a function sc_main and call s the functi on sc_start, as defined i n 4.3.4.1 and
4.3.4.2.
4.3.4.1 Function sc_main
An appli cation shall provi de a function sc_main in the gl obal namespace wi th the foll owing declaration.
Theorder and typesof theargumentsand thereturn typeshal l beasshown here:
int sc_main( i nt argc, char* argv[] );
This function shall be call ed once from the kernel and is the only entry poi nt into the appli cation. The
argumentsargc and argv[] arecommand-l inearguments. Thei mplementati on may pass thevaluesof C++
command-li ne arguments (as passed to functi on main) through to function sc_main. The choice of which
C++ command-li neargumentsto passisimpl ementation-defi ned.
Elaborati on consi sts of the execution of the sc_main functi on from the start of sc_main to the point
immedi ately beforethefi rst cal l tothefuncti on sc_start.
A return value of 0 from function sc_main shall indicate successful compl eti on. An appl ication may use
other return val ues to indicateother terminati on condi ti ons.
NOTE 1As a consequence of the rules definedin 4.1, beforecalling function sc_start for thefirst time, thefunction
sc_main may instantiate modules, instantiate primitive channels, bind the ports and exports of module instances to
channels, and set thetimeresolution. Morethan onetop-level modulemay exist.
NOTE 2Throughout this standard, the termcal l is taken to mean call directly or indirectly. Hence, function sc_start
may becalled indirectly fromfunctionsc_mainby another function or functions.
4.3.4.2 Function sc_start
Theimpl ementation shal l provideafunction sc_start i n thenamespacesc_core, overl oadedwith thefoll ow-
ing signatures:
void sc_start();
void sc_start( const sc_ti me&, sc_starvation_pol icy p = SC_RUN_TO_TIME );
void sc_start( double, sc_time_unit, sc_starvation_pol icy p= SC_RUN_TO_TIME );
Thebehavi or of thelatter functi onshal l beequivalent to thefol lowi ng defi ni ti on:
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


22
Copyright 2012 IEEE. All rights reserved.
void sc_start( doubled, sc_time_unit t, sc_starvation_policy p ) { sc_start( sc_time(d, t), p ); }
When called for the first ti me, functi on sc_start shall start the scheduler, which shall run up to the
simulation time passed as an argument (if an argument was passed), unless otherwise i nterrupted, and as
determi ned by the starvation pol icy argument. The scheduler shal l execute the initiali zation phase before
executi ng thefi rst eval uation phase, as described i n 4.2.1.1.
When call edon thesecond and subsequent occasions, function sc_start shal l resumethescheduler fromthe
ti meit had reached at theend of thepreviouscall to sc_start. Thescheduler shall run for thetimepassed as
an argument (i f an argument was passed), relati ve to the current simul ati on ti me, unless otherwise
interrupted, and as determi ned by the starvati on poli cy argument. The scheduler shal l execute from the
eval uation phaseof anew deltacycl e, as described in 4.2.2.
When a time is passed as an argument, the scheduler shal l execute up to and i ncl udi ng the l atest timed
notifi cati on phase with si mulati on time less than or equal to the end ti me (cal cul ated by adding the ti me
given as an argument to the si mulati on timewhen function sc_start is called). On return fromsc_start, if
theargument of typesc_starvation_policy hastheval ueSC_RUN_TO_TIME, theimpl ementation shall set
simul ation ti me equal to theend ti me, regardl ess of the ti me of the most recent event notificati on or ti me-
out. If the argument of type sc_starvation_policy has the val ue SC_EXIT_ON_STARVATION, the
impl ementation shal l set si mulati on timeequal to theti meof themost recent event noti fi cati on or time-out,
which may belessthan theend ti me.
When functi onsc_start i s cal led without any arguments, thescheduler shall run unti l therei s no remaining
activi ty, unl ess otherwi seinterrupted. In other words, except when sc_stop or sc_pausehavebeen called or
an excepti on has been thrown, control shall only be returned from sc_start when the set of runnable
processes, the set of update requests, the set of del ta noti fi cati ons and time-outs, and the set of timed
notifi cati ons and ti me-outs are al l empty. On return fromsc_start, thei mplementati on shal l set si mulati on
ti meequal tothetimeof themost recent event noti fi cation or ti me-out.
When function sc_start is call ed wi th a zero-valued time argument, the scheduler shal l run for one del ta
cycl e, that is, an evaluati on phase, an updatephase, and adel tanotification phase, in that order. Theval ueof
thestarvation poli cy argument shall beignored. Simul ation ti meshal l not beadvanced. If thisisthefi rst call
to sc_start, the scheduler shal l execute the initiali zation phase before executi ng the evaluation phase, as
descri bed i n 4.2.1.1. If, when sc_start i s cal led with a zero-valued ti me argument, the set of runnabl e
processes is empty, the set of update requests is empty, and the set of del ta noti fi cations and ti me-outs i s
empty; that i s, i f sc_pending_activity_at_current_time() == false, the i mplementati on shal l i ssue a
warni ng andthevaluereturned from sc_delta_count shal l not bei ncremented.
Oncestarted, thescheduler shall run unti l either i t reachestheend ti me, therei snoremai ning acti vi ty, or the
appl icati on call s thefuncti on sc_pauseor sc_stop, an exception occurs, or simulati on i sstopped or aborted
by the report handler (see 8.3). If the functi on sc_pause has been call ed, function sc_start may be call ed
agai n. Once the function sc_stop has been cal led, functi on sc_start shall not be cal led agai n. If nei ther
sc_pause nor sc_stop havebeen cal led, thei mplementati on shall i nsert an impl ici t cal l to sc_pause before
returning control fromfuncti on sc_start, and functi onsc_start may becal led again.
Updaterequests, timed notifications, and deltanotificati ons may becreated beforethefirst call to sc_start,
but immedi atenoti fi cations shal l not becreated before thefirst cal l to sc_start. Updaterequests and event
notifi cati ons, including immedi atenoti fi cations, may becreated between or after cal ls to sc_start.
Function sc_start may becal led from function sc_main, and only from function sc_main.
Appli cati ons arerecommended tocal l function sc_stop beforereturning control fromsc_mainto ensurethat
theend_of_simulation cal lbacks arecall ed (see4.4.4).
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


23
Copyright 2012 IEEE. All rights reserved.
Exampl e:
int sc_main( i nt argc, char* argv[] )
{
Top top("top"); // Instanti atemodul ehi erarchy
sc_start(100, SC_NS); // Run for exactl y 100 ns
sc_start(); // Run unti l nomoreacti vity
if (sc_get_status() == SC_PAUSED) {
SC_REPORT_INFO("", "sc_stopcall ed to terminateapaused simulation");
sc_stop();
}
return 0;
}
NOTEWhen the scheduler is paused between successivecallsto function sc_start, theset of runnableprocesses does
not need to beempty.
4.3.5 Running under control of the kernel
Elaborati on and si mulati on may be initiated under the di rect control of the kernel, i n whi ch case the
impl ementation shall not cal l the function sc_main, and the i mplementati on is not obli ged to provide a
functi on sc_start.
An impl ementation may permit morethan onetop-level module, but i t i snot obli ged to do so.
Inthi scase, themechanismsused to i nitiateel aborati on andsi mulation and toi denti fy top-l evel modulesare
impl ementation-defined.
Inthi scase, ani mplementati on shall honor al l obligati onsset out in thi sstandard with theexcepti on of those
in 4.3.4.
4.4 Elaboration and simulation callbacks
Four call back functions are cal led by the kernel at vari ous stages during elaboration and si mulati on. They
havethefoll owing declarations:
virtual void before_end_of_elaboration();
virtual void end_of_elaboration();
virtual void start_of_simulation();
virtual void end_of_simulation();
The impl ementation shal l define each of these four call back functions as member functi ons of the cl asses
sc_module, sc_port, sc_export, and sc_prim_channel, and each of these definitions shall have empty
functi on bodi es. The i mplementati on also overri des various of these functions as member functi ons of
various predefi ned channel and port cl asses and having specific behavi ors (see Clause 6). An appli cati on
may overri de any of these four functions in any class deri ved from any of the cl asses menti oned in this
paragraph. If an appl ication overrides any such cal lback function of apredefined classand thecall back has
impl ementation-defined behavior (for exampl e, sc_in::end_of_elaboration), the appli cati on-defined
member function in thederi ved class may or may not call the impl ementation-defi ned functi on of the base
class, and thebehavior wi ll di ffer, dependi ng on whether themember functi onof thebaseclassiscal led.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


24
Copyright 2012 IEEE. All rights reserved.
Wi thi n each of the four categori es of call back functions, the order in which the cal lbacks are made for
objectsof cl asssc_module, sc_port, sc_export, and sc_prim_channel shall bei mplementati on-defined.
Theimpl ementation shall makecall backsto al l such functionsfor every instancein themodulehi erarchy, as
defined in thefoll owing subcl auses.
Thei mplementati on shal l providethefoll owing two functi ons:
namespacesc_core{
bool sc_start_of_simulation_invoked();
bool sc_end_of_simulation_invoked();
}
Function sc_start_of_simulation_invokedshall return trueafter and only after al l thecall backstofuncti on
start_of_simulation have executed to compl eti on. Function sc_end_of_simulation_invoked shal l return
trueafter, and onl y after, all thecall backstofunction end_of_simulation haveexecuted tocompleti on.
4.4.1 before_end_of_elaboration
The impl ementation shall make cal lbacks to member functi on before_end_of_elaboration after the
construction of themodulehierarchy definedi n 4.3 i scomplete. Functi on before_end_of_elaboration may
extend theconstruction of the modul ehi erarchy by i nstanti ating further modul es (and other obj ects) wi thi n
themodul ehi erarchy.
Thepurpose of member functi on before_end_of_elaboration is to all ow an appl icati on to perform acti ons
duri ng elaboration that depend on theglobal properti es of themodulehi erarchy and that al so need to modi fy
the modul e hierarchy. Examples incl ude the i nstantiati on of top-level modul es to moni tor events buried
wi thin thehi erarchy.
The foll owing acti ons may be performed directl y or indirectly from the member function
before_end_of_elaboration.
a) Thei nstantiati onof objects of class sc_module, sc_port, sc_export, sc_prim_channel.
b) Thei nstantiati on of obj ects of other classesderived fromclasssc_object.
c) Port bi ndi ng.
d) Export bi ndi ng.
e) Themacros SC_METHOD, SC_THREAD, SC_CTHREAD, and SC_HAS_PROCESS.
f) Themember sensitiveand member functi ons dont_initialize, set_stack_size, reset_signal_is, and
async_reset_signal_is, of theclasssc_module.
g) Call sto event fi nder functions.
h) Call sto function sc_spawnto createstatic, spawnedprocesses.
i ) Call s to member function set_sensitivity of cl ass sc_spawn_options to set the sensitivity of a
spawned process usi ng an event, an i nterface, or an event finder functi on. A port cannot be used
becauseport bi ndi ngmay havebeen deferred.
j ) Call s to member functions reset_signal_is and async_reset_signal_is of the class
sc_spawn_options.
k) Call stomember functionsrequest_updateor async_request_updateof classsc_prim_channel to
createupdaterequests (for exampl e, by call ing member functi on initializeof class sc_inout).
l ) Call s to member functi ons notify(const sc_time&) and notify(double,sc_time_unit) of class
sc_event to createdel taand ti mednoti fi cations.
m) Call s to the process control member functions suspend, resume, disable, enable, sync_reset_on,
andsync_reset_off of classsc_process_handle.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


25
Copyright 2012 IEEE. All rights reserved.
Thefoll owi ngconstructsshall not beused directl y or indirectly wi thin cal lback before_end_of_elaboration:
a) Call sto member functi on notify of classsc_event with an empty argument li st to createimmedi ate
noti ficati ons
b) Call stotheprocess control member functionskill, reset, or throw_it of classsc_process_handle
Thefol lowing constructs cannot beused directly withi n member function before_end_of_elaboration, but
they may be used where permitted wi thi n modul e instances nested within call backs to
before_end_of_elaboration:
a) ThemacroSC_CTOR
operator-> and operator[] of class sc_port shoul d not be cal led from the function
before_end_of_elaborationbecause the impl ementation may not havecompleted port bi ndi ng at thetime
of thi scall back and, hence, theseoperatorsmay returnnull pointers. Themember function sizemay return a
val uel ess thani tsfi nal value.
Any sc_object instances created fromcall back before_end_of_elaboration shall beplaced at a location i n
themodulehierarchy as i f thoseinstanceshad been createdfromtheconstructor of themodul eto which the
cal lback belongs, or to the parent modul ei f the call back bel ongs to aport, export, or primiti vechannel. In
other words, it shal l beasif theinstanceswerecreated fromtheconstructor of theobject whosecal lback is
cal led.
Objectsi nstantiated fromthemember function before_end_of_elaboration may themsel vesoverrideany of
the four call back functi ons, including the member functi on before_end_of_elaboration itsel f. The
impl ementation shall make all such nested call backs. An appl icati on can assume that every such member
functi onwi ll becal led back by theimpl ementation, whatever thecontext i nwhi ch theobj ect isinstantiated.
4.4.2 end_of_elaboration
Theimpl ementation shal l call member function end_of_elaboration at thevery end of el aboration after al l
cal lbacks to before_end_of_elaboration have completed and after the completion of any i nstantiati on or
port bi ndi ngperformed by thosecallbacksand beforestarting simul ation.
The purpose of member function end_of_elaboration i s to all ow an appl icati on to perform housekeepi ng
actions at theend of el aboration that do not need to modi fy themodul ehi erarchy. Exampl esi ncl udedesi gn
rul echecki ng, actions that depend on thenumber of timesaport isbound, and pri nting diagnostic messages
concerning themodul ehi erarchy.
Thefollowi ngacti ons may beperformed directly or i ndi rectl y fromthecal lback end_of_elaboration:
a) The instantiation of objects of classes derived from cl ass sc_object but excluding cl asses
sc_module, sc_port, sc_export, and sc_prim_channel
b) Themacros SC_METHOD, SC_THREAD, and SC_HAS_PROCESS
c) The member sensitive and member functi ons dont_initialize and set_stack_size of the cl ass
sc_module
d) Call sto function sc_spawnto createdynamic spawned processes
e) Call stomember functi onsrequest_updateor async_request_updateof classsc_prim_channel to
createupdaterequests (for exampl e, by call ing member functi on writeof classsc_inout)
f) Call s to member functi ons notify(const sc_time&) and notify(double,sc_time_unit) of class
sc_event to createdel taand ti mednoti fi cations
g) Call s to the process control member functions suspend, resume, disable, enable, sync_reset_on,
andsync_reset_off of classsc_process_handle
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


26
Copyright 2012 IEEE. All rights reserved.
h) Interfacemethod cal ls usi ng operator-> and operator[] of class sc_port, provided that thosecall s
do not attempt toperformactions prohibited outsidesi mulati onsuch asevent notification
Thefollowi ngconstructsshall not beused directl y or indirectly wi thin cal lback end_of_elaboration:
a) Thei nstantiati onof objects of class sc_module, sc_port, sc_export, sc_prim_channel
b) Port bi ndi ng
c) Export bindi ng
d) Themacros SC_CTOR, SC_CTHREAD
e) Themember functions reset_signal_isand async_reset_signal_isof theclasssc_module
f) Call stoevent fi nder functions
g) Call sto member functi on notify of classsc_event with an empty argument li st to createimmedi ate
noti ficati ons
h) Call stotheprocesscontrol member functionskill, reset, or throw_it of classsc_process_handle
4.4.3 start_of_simulation
The impl ementation shal l call member functi on start_of_simulation i mmediatel y when the appl ication
cal ls functi onsc_start for thefirst timeor at thevery start of simul ation, if simul ation i si nitiated under the
direct control of thekernel . If an appl icati on makesmultipl ecall stosc_start, theimpl ementation shall onl y
makethe cal lbacks to start_of_simulation on the fi rst such call to sc_start. The impl ementation shall call
functi on start_of_simulation after the cal lbacks to end_of_elaboration and before i nvoking the
ini ti al izati on phaseof thescheduler.
The purpose of member functi on start_of_simulation i s to all ow an appl ication to performhousekeeping
actions at the start of simul ation. Examples include opening sti mulus and response fil es and pri nting
diagnosti c messages. Theintenti on is that an i mplementati on that i ni ti atesel aborati on and simul ati on under
direct control of the kernel (in the absenceof functions sc_main and sc_start) shall make the cal lbacks to
end_of_elaboration at the end of el aborati on and the cal lbacks to start_of_simulation at the start of
simul ation.
Thefollowi ngacti onsmay beperformed directly or i ndi rectl y fromthecal lback start_of_simulation:
a) The instantiation of objects of classes derived from cl ass sc_object but excluding cl asses
sc_module, sc_port, sc_export, and sc_prim_channel
b) Call sto function sc_spawnto createdynamic spawned processes
c) Call stomember functi onsrequest_updateor async_request_updateof classsc_prim_channel to
createupdaterequests (for exampleby call ing member function writeof classsc_inout)
d) Call s to member functi ons notify(const sc_time&) and notify(double,sc_time_unit) of class
sc_event to createdel taand ti mednoti fi cations
e) Call s to the process control member functi ons suspend, resume, disable, enable, sync_reset_on,
andsync_reset_off of classsc_process_handle
f) Interfacemethod cal ls usi ng operator-> and operator[] of class sc_port, provided that thosecall s
do not attempt toperformactions prohibited outsidesi mulati onsuch asevent notification
Thefollowi ngconstructsshall not beuseddirectl y or indirectly wi thin cal lback start_of_simulation:
a) Thei nstantiati onof objects of class sc_module, sc_port, sc_export, sc_prim_channel
b) Port bi ndi ng
c) Export bindi ng
d) Themacros SC_CTOR, SC_METHOD, SC_THREAD, SC_CTHREAD, and SC_HAS_PROCESS
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


27
Copyright 2012 IEEE. All rights reserved.
e) Themember sensitiveand member functi ons dont_initialize, set_stack_size, reset_signal_is, and
async_reset_signal_isof theclass sc_module
f) Call stoevent fi nder functions
g) Call sto member functi on notify of cl ass sc_event with an empty argument li st to createimmedi ate
noti ficati ons
h) Call stotheprocess control member functionskill, reset, or throw_it of classsc_process_handle
4.4.4 end_of_simulation
The i mplementation shall call member function end_of_simulation at the point when the schedul er hal ts
because of the function sc_stop havi ng been call ed duri ng simul ati on (see 4.5.3) or at the very end of
simul ation if simul ation is ini ti atedunder thedirect control of thekernel . Theend_of_simulationcal lbacks
shal l only becal led onceeven if function sc_stop iscal led multipleti mes.
The purpose of member functi on end_of_simulation is to all ow an appl ication to perform housekeeping
actions at the end of simul ation. Exampl es i ncl ude closi ng stimul us and response fil es and printing
diagnosti c messages. Theintenti on isthat an i mplementati on that i ni ti atesel aborati on and simul ati on under
direct control of the kernel (in the absenceof functions sc_main and sc_start) shall make the cal lbacks to
end_of_simulationat thevery end of si mulation whether or not function sc_stop hasbeen cal led.
As a consequence of the language mechanisms of C++, the destructors of any obj ects in the module
hierarchy wil l be call ed as these objects are deleted at the end of program executi on. Any call backs to
functi on end_of_simulation shal l be made before the destructi on of the modul e hi erarchy. The function
sc_end_of_simulation_invoked may becal led by theappl ication withi n adestructor to determinewhether
thecal lback hasbeen made.
Theimpl ementation i snot obli ged to support any of thefoll owing actionswhen madedi rectl y or indirectl y
from the member functi on end_of_simulation or from the destructors of any objects i n the module
hierarchy. Whether any of theseactionscausesan error isimplementation-defined.
a) Thei nstantiati onof objects of classesderived fromclasssc_object
b) Call sto function sc_spawnto createdynamic spawned processes
c) Call stomember functi onsrequest_updateor async_request_updateof classsc_prim_channel to
createupdaterequests (for exampleby call ing member function writeof classsc_inout)
d) Call sto member function notify of theclass sc_event
4.5 Other functions related to the scheduler
4.5.1 Function declarations
namespacesc_core{
void sc_pause();
enum sc_stop_mode
{
SC_STOP_FINISH_DELTA ,
SC_STOP_IMMEDIATE
} ;
extern voi d sc_set_stop_mode( sc_stop_modemode);
extern sc_stop_modesc_get_stop_mode();
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


28
Copyright 2012 IEEE. All rights reserved.
void sc_stop();
const sc_time& sc_time_stamp();
const sc_dt::ui nt64sc_delta_count();
bool sc_is_running();
bool sc_pending_activity_at_current_time();
bool sc_pending_activity_at_future_time();
bool sc_pending_activity();
sc_timesc_time_to_pending_activity();
enum sc_status
{
SC_ELABORATION = 0x01,
SC_BEFORE_END_OF_ELABORATION = 0x02,
SC_END_OF_ELABORATION = 0x04,
SC_START_OF_SIMULATION = 0x08,
SC_RUNNING = 0x10,
SC_PAUSED = 0x20,
SC_STOPPED = 0x40,
SC_END_OF_SIMULATION = 0x80
} ;
sc_statussc_get_status();
}
4.5.2 Function sc_pause
Thei mplementati onshall provi deafunction sc_pausewith thefoll owing declarati on:
void sc_pause();
Function sc_pauseshall causetheschedul er to ceaseexecution at theend of thecurrent del tacyclesuchthat
thescheduler canberesumed again later. If sc_start was call ed, sc_pauseshall causetheschedul er to return
control from sc_start at the end of the current del ta cycl e such that the schedul er can be resumed by a
subsequent cal l tosc_start.
Function sc_pauseshall benon-bl ocking; that i s, thecall ing function shal l continueto executeuntil i t yields
or returns.
If thefunction sc_pausei s cal led during theevaluati on phaseor theupdatephase, theschedul er shall com-
plete the current delta cycl e before ceasi ng execution; that is, the schedul er shall complete the eval uation
phase, theupdatephase, and thedel tanotificati on phase.
Function sc_pause may be call ed duri ng elaborati on, fromfuncti on sc_main, or fromone of the call backs
before_end_of_elaboration, end_of_elaboration, start_of_simulation, or end_of_simulation, i n whi ch
caseit shall haveno effect andshal l beignoredby theimpl ementation.
If sc_stop has al ready beencall ed, acall to sc_pauseshall haveno effect.
Thefol lowi ngoperati ons arepermitted whi lesimul ation is paused:
a) The i nstantiati on of objects of a type deri ved from sc_object provided that i nstanti ation of those
objectsi spermitted during simulati on
b) Call sto function sc_spawnto createdynami cprocesses
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


29
Copyright 2012 IEEE. All rights reserved.
c) Call sto member functi ons request_update and async_request_updateof cl ass sc_prim_channel
to createupdaterequests
d) Call sto member function notify of class sc_event to createimmedi ate, delta, or timed noti fi cations
e) Call s to the process control member functi ons suspend, resume, disable, enable, sync_reset_on,
andsync_reset_off of classsc_process_handle
f) Interfacemethod cal ls using operator-> and operator[] of cl ass sc_port, provi ded those functi ons
do not themsel vesperformany operationsthat areforbi dden whil esimul ation ispaused
g) Call sto function sc_stop
It shall bean error to perform any of thefol lowing operationswhilesimul ation ispaused:
a) Thei nstantiati onof objects of class sc_module, sc_port, sc_export, or sc_prim_channel
b) Port bi ndi ng
c) Export bindi ng
d) Invocation of themacrosSC_METHOD, SC_THREAD, or SC_CTHREAD
e) Useof themember sensitiveof classsc_moduleto createstatic sensiti vity
f) Call s to the member functi ons dont_initialize, set_stack_size, reset_signal_is, or
async_reset_signal_isof theclasssc_module
g) Call sto event fi nder functions
h) Call stotheprocess control member functions kill, reset, or throw_it of classsc_process_handle
i ) Call sto themember functi ons wait or next_trigger of cl asses sc_moduleandsc_prim_channel or
to thenon-member functi ons wait or next_trigger
4.5.3 Function sc_stop, sc_set_stop_mode, and sc_get_stop_mode
The impl ementation shall provide functions sc_set_stop_mode, sc_get_stop_mode, and sc_stop with the
fol lowi ng decl arations:
enum sc_stop_mode
{
SC_STOP_FINISH_DELTA ,
SC_STOP_IMMEDIATE
} ;
extern voi d sc_set_stop_mode( sc_stop_modemode);
extern sc_stop_modesc_get_stop_mode();
void sc_stop();
The functi on sc_set_stop_mode shall set the current stop mode to the val ue passed as an argument. The
functi on sc_get_stop_modeshall return thecurrent stop mode. Functi on sc_set_stop_mode may becall ed
during elaboration or from one of the cal lbacks before_end_of_elaboration, end_of_elaboration, or
start_of_simulation. If sc_set_stop_mode i s call ed more than once, the most recent call shal l take
precedence. It shal l bean error for theappl icati on to call functi on sc_set_stop_modefromthei nitiali zati on
phaseonward.
The function sc_stop may be cal led by the appl icati on from an elaborati on or si mulati on cal lback, froma
process, from the member functi on update of class sc_prim_channel, or from function sc_main. The
impl ementation may call thefunction sc_stop frommember functi onreport of class sc_report_handler.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


30
Copyright 2012 IEEE. All rights reserved.
A call to function sc_stop shall cause elaborati on or simulation to halt as descri bed bel ow and control to
return to function sc_main or to the kernel. The i mplementati on shal l pri nt out a message from function
sc_stop to standard output to indicate that si mulation has been halted by this means. The impl ementation
shal l maketheend_of_simulationcal lbacks asdescri bed in 4.4.4.
If the functi on sc_stop is cal led from one of the cal lbacks before_end_of_elaboration,
end_of_elaboration, start_of_simulation, or end_of_simulation, elaborati on or si mulati on shall hal t after
thecurrent call back phaseiscompl ete, that is, after al l cal lbacks of thegivenki nd havebeen made.
If thefuncti on sc_stop i s cal led duri ng theeval uation phaseor theupdatephase, theschedul er shall halt as
determi ned by thecurrent stop mode but i n any casebeforethe del tanoti fi cation phaseof thecurrent del ta
cycl e. If thecurrent stopmodeis SC_STOP_FINISH_DELTA, thescheduler shall completeboththecurrent
eval uation phase and the current update phase before halting simul ation. If the current stop mode is
SC_STOP_IMMEDIATE and functi on sc_stop i s call ed during the eval uation phase, the schedul er shal l
completetheexecution of thecurrent processand shall then halt wi thout executi ng any further processesand
wi thout executing theupdatephase. If functi onsc_stop iscall ed during theupdatephase, thescheduler shall
complete the update phase before hal ti ng. Whatever the stop mode, simul ation shal l not hal t until the
currentl y executi ng process has yi el ded control to the scheduler (such as by call ing function wait or by
executi ng areturnstatement).
Thedefault stopmodeshall beSC_STOP_FINISH_DELTA.
It shall bean error for theappl ication to cal l functi onsc_start after function sc_stop hasbeen cal led.
If functi on sc_stop is cal led a second time before or after el aboration or si mulati on has halted, the
implementation shal l issue a warning. If functi on stop_after of class sc_report_handler has been used to
cause sc_stop to be cal led on the occurrence of a warning, the i mplementati on shal l overri de this report-
handl ing mechani sm and shall not makefurther cal ls to sc_stop, preventing an infiniteregression.
A cal l tosc_stop shal l takeprecedenceover acal l to sc_pause.
NOTE 1A function sc_stop shall be provided by the implementation, whether or not the implementors choose to
provideafunctionsc_start.
NOTE 2Throughout this standard, the term cal l is taken to mean call directly or indirectly. Hence, function sc_stop
may becalled indirectly, for example, by an interfacemethod call.
4.5.4 Function sc_time_stamp
Thei mplementati onshall provi deafunction sc_time_stamp wi th thefoll owing declaration:
const sc_time& sc_time_stamp();
Thefuncti on sc_time_stamp shal l return thecurrent simul ati on ti me. Duri ng el aboration and ini ti al izati on,
thefuncti on shal l return avalueof zero.
NOTEThe simulation time can only bemodified by thescheduler.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


31
Copyright 2012 IEEE. All rights reserved.
4.5.5 Function sc_delta_count
The i mplementati on shall provi de a function sc_delta_count with the foll owing declaration:
const sc_dt::ui nt64 sc_delta_count();
The f unction sc_delta_count shal l return an i nteger val ue that is i ncremented exactl y once in each del ta
cycl e i n which at least one process is tri ggered or resumed and, thus, returns a count of the absolute number
of del ta cycles that have occurred duri ng si mulation, starting f rom zero, i gnoring any delta cycles i n whi ch
there were no runnabl e processes. The delta count shal l be 0 during elaboration, during the i ni ti al izati on
phase, and during the f irst evaluati on phase. The del ta count shal l f irst be incremented af ter the eval uation
phase of the fi rst whol e del ta cycl e. The delta count shal l be i ncremented between the evaluati on phase and
the update phase of each del ta cycle in which there were runnabl e processes.
A delta cycl e in which there are no runnabl e processes can occur when f uncti on sc_start is cal led wi th a
zero-valued time argument or when the schedul er is resumed foll owing a call to sc_pause.
When the schedul er i s resumed f ol lowi ng a call to f uncti on sc_pause, the delta count shal l conti nue to be
incremented as if sc_pausehad not been cal led.
When the delta count reaches the maxi mum val ue of type sc_dt::uint64, the count shal l start agai n f rom
zero. Hence, the delta count in successi ve delta cycl es mi ght be maxval ue-1, maxvalue, 0, 1, 2, and so on.
NOTEThis function is intended for use in primitive channel s to detect whether an event has occurred by comparing
the del ta count wi th the del ta count stored i n a vari abl e f rom an earl i er del ta cycle. The f ol lowi ng code f ragment wi ll test
whether a process has been executed i n two consecuti ve del ta cycl es:
if (sc_delta_count() == stored_delta_count + 1) { /* consecuti ve * / }
stored_del ta_count = sc_del ta_count();
4.5.6 Function sc_is_running
The i mplementati on shall provi de a function sc_is_runningwith the f oll owing decl aration:
bool sc_is_running();
The functi on sc_is_runningshall return the val ue true whi le the schedul er is runni ng or paused, incl udi ng
the initiali zation phase, and shall return the val ue false during el aboration, duri ng the call backs
start_of_simulation and end_of_simulation, and on return f rom sc_start after sc_stop has been cal led.
The f ol lowi ng rel ati on shal l hold:
sc_assert( sc_is_running() == (sc_get_status() & (SC_RUNNI NG | SC_PAUSED)) );
4.5.7 Functions to detect pending activity
The i mplementati on shal l provide four f unctions to detect pendi ng activi ty wi th the foll owing declarations:
bool sc_pending_activity_at_current_time();
bool sc_pending_activity_at_future_time();
bool sc_pending_activity();
sc_time sc_time_to_pending_activity();
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


32
Copyright 2012 IEEE. All rights reserved.
The functi on sc_pending_activity_at_current_time shall return the value true if and only i f the set of
runnabl e processes is not empty, the set of update requests i s not empty, or the set of del ta notif icati ons and
ti me-outs i s not empty. By impl icati on, i f sc_pending_activity_at_current_time were to return the val ue
false, the next acti on of the scheduler would be to execute the timed notif icati on phase.
The f uncti on sc_pending_activity_at_future_timeshall return the value trueif and onl y i f the set of timed
notif i cati ons and ti me-outs is not empty.
The functi on sc_pending_activity shall return the val ue true if and onl y i f
sc_pending_activity_at_current_timeor sc_pending_activity_at_future_timewould return true.
The functi on sc_time_to_pending_activity shall return the ti me unti l the earl iest pendi ng activity,
cal cul ated as f oll ows.
If sc_pending_activity_at_current_time() == true, the val ue returned i s SC_ZERO_TIME.
Otherwise, if sc_pending_activity_at_future_time() == true, the value returned i s T -
sc_time_stamp(), where T is the ti me of the earli est ti med noti fi cati on or ti me-out in the set of
ti med notif ications and ti me-outs.
Otherwise, the value returned is sc_max_time() - sc_time_stamp().
These f our functi ons may be cal led at any ti me during or f ollowi ng el aborati on or si mulati on.
The functi on sc_pending_activity may return false at the end of el aboration. Theref ore, care shoul d be
taken when call ing sc_start in a loop condi ti onal on any of the f uncti ons that detect pending activity.
Exampl e:
int sc_main( i nt argc, char* argv[] )
{
// Instantiate top-level modul e
...
sc_start( SC_ZERO_TIME ); // Run the i ni ti al izati on phase to create pending acti vity
whil e( sc_pendi ng_activi ty() ) {
sc_start( sc_time_to_pending_activity() ); // Run up to the next acti vi ty
}
return 0;
}
4.5.8 Function sc_get_status
The i mplementati on shall provi de a function sc_get_statuswith the f oll owing declarati on:
sc_status sc_get_status();
The function sc_get_status shal l return one of the ei ght val ues of type sc_status to indicate the current
phase of el aboration or si mul ation as def ined by Tabl e 1.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


33
Copyright 2012 IEEE. All rights reserved.
When cal led f rom before_end_of_elaboration, the f unction sc_get_status shall return
SC_BEFORE_END_OF_ELABORATION even when call ed f rom a constructor (of a module or other
object) that is call ed di rectl y or indirectly f rom before_end_of_elaboration. I n other words, sc_get_status
permi ts the appli cation to disti ngui sh between the construction of the module hierarchy defi ned in 4.3 and
the extended constructi on of the module hierarchy def ined i n 4.4.1.
When sc_start is bei ng used, sc_get_statusshal l return SC_ELABORATION when called bef ore the f i rst
cal l to sc_start and shal l return ei ther SC_PAUSED or SC_STOPPED when call ed between or af ter call s to
sc_start.
If sc_pause and sc_stop have both been call ed, sc_get_statusshal l return SC_STOPPED.
When cal led from end_of_simulation, the f uncti on sc_get_status shal l return
SC_END_OF_SIMULATION i rrespective of whether sc_pauseor sc_stop have been call ed.
Exampl e:
if (sc_get_status() & (SC_RUNNI NG | SC_PAUSED | SC_STOPPED) )
...
Figure 1 shows the possible transi tions between the val ues of type sc_status as returned from functi on
sc_get_statuswhen call ed during the various phases of si mulati on.
NOTEWhen sc_start i s not bei ng used, the mechani sms f or runni ng el aborati on and simul ation are impl ementati on-
defi ned, as are the cal l backs to end_of_simulationi n the absence of a cal l to sc_stop(see 4.3 and 4.4.4).
Table 1Value returned by sc_get_status
Value Whencalled
SC_ELABORATI ON Duri ng the constructi on of the modul e hi erarchy, or i f sc_start
i s bei ng used, before the f i rst cal l to sc_start
SC_BEFORE_END_OF_ELABORATI ON From the cal l back f uncti on before_end_of_elaboration
SC_END_OF_ELABORATI ON Fromthe cal l back functi on end_of_elaboration
SC_START_OF_SI MULATION From the cal l back f uncti on start_of_simulation
SC_RUNNI NG From the i ni ti al ization, eval uati on, or update phase
SC_PAUSED When the scheduler is not runni ng and sc_pausehas been
cal l ed
SC_STOPPED When the scheduler is not runni ng and sc_stophas been cal led
SC_END_OF_SIMULATI ON From the cal l back f uncti on end_of_simulation
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


34
Copyright 2012 IEEE. All rights reserved.
Figure 1Transitions between values returned by sc_get_status
SC_ELABORATION
SC_BEFORE_END_OF_ELABORATION
SC_END_OF_ELABORATION
SC_START_OF_SIMULATION
SC_RUNNI NG SC_PAUSED
SC_END_OF_SIMULATI ON
SC_STOPPED
sc_start
(Cal lbacks)
sc_stop
Starvati on
Implementation-def ined
sc_pause
(Cal lbacks)
(Cal lbacks)
sc_start
sc_stop
Starvati on
(Cal lbacks)
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


35
Copyright 2012 IEEE. All rights reserved.
5. Core language class definitions
5.1 Class header files
To use the SystemC cl ass library features, an appli cation shall i ncl ude ei ther of the C++ header fi les
specif ied i n this subclause at appropriate positions i n the source code as requi red by the scope and l inkage
rul es of C++. The TLM-1 and TLM-2.0 classes and TLM-2.0 util ities are i n separate header fi les (see 10.8).
5.1.1 #include "systemc"
The header f il e named systemc shal l add the names sc_core, sc_dt, and sc_unnamed to the declarative
region in whi ch it i s included, and these three names only. The header f il e systemcshall not introduce into
the decl arative region in which it i s included any other names from this standard or any names from the
standard C or C++ l ibraries.
I t is recommended that appl ications include the header f il e systemcrather than the header fi le systemc.h.
Exampl e:
#include "systemc"
usi ng sc_core::sc_module;
usi ng sc_core::sc_signal ;
usi ng sc_core::SC_NS;
usi ng sc_core::sc_start;
usi ng sc_dt::sc_logic;
#include <i ostream>
usi ng std::ofstream;
usi ng std::cout;
usi ng std::endl ;
5.1.2 #include "systemc.h"
The header fi le named systemc.h shall add all of the names f rom the namespaces sc_core and sc_dt to the
decl arative region in which i t i s i ncl uded, together with the name sc_unnamed and sel ected names f rom the
standard C or C++ l ibraries as defi ned in thi s subclause. I t is recommended that an i mplementati on keep to a
mi nimum the number of addi ti onal i mplementati on-specifi c names i ntroduced by this header f ile.
The header f il e systemc.h is provi ded f or backward compati bi li ty with earl ier versions of SystemC and may
be deprecated i n f uture versions of this standard.
The header f il e systemc.h shall include at least the f ol lowi ng:
#include "systemc"
// Using declarati ons for al l the names in the sc_core namespace speci fi ed i n this standard
usi ng sc_core::sc_module;
...
// Using declarati ons for al l the names in the sc_dt namespace specif ied in this standard
usi ng sc_dt::sc_int;
...
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


36
Copyright 2012 IEEE. All rights reserved.
// Using declarati ons for selected names in the standard li brari es
usi ng std::i os;
usi ng std::streambuf;
usi ng std::streampos;
usi ng std::streamsize;
usi ng std::i ostream;
usi ng std::i stream;
usi ng std::ostream;
usi ng std::cin;
usi ng std::cout;
usi ng std::cerr;
usi ng std::endl ;
usi ng std::fl ush;
usi ng std::dec;
usi ng std::hex;
usi ng std::oct;
usi ng std::f stream;
usi ng std::i fstream;
usi ng std::ofstream;
usi ng std::size_t;
usi ng std::memchr;
usi ng std::memcmp;
usi ng std::memcpy;
usi ng std::memmove;
usi ng std::memset;
usi ng std::strcat;
usi ng std::strncat;
usi ng std::strchr;
usi ng std::strrchr;
usi ng std::strcmp;
usi ng std::strncmp;
usi ng std::strcpy;
usi ng std::strncpy;
usi ng std::strcspn;
usi ng std::strspn;
usi ng std::strlen;
usi ng std::strpbrk;
usi ng std::strstr;
usi ng std::strtok;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


37
Copyright 2012 IEEE. All rights reserved.
5.2 sc_module
5.2.1 Description
Cl ass sc_module is the base cl ass for modules. Modul es are the pri nci pl e structural buil ding blocks of
SystemC.
5.2.2 Class definition
namespace sc_core {
class sc_bi nd_proxy

{ i mpl ementati on-defi ned } ;


const sc_bi nd_proxy

SC_BIND_PROXY_NIL;
class sc_module
: publi c sc_object
{
publ ic:
virtual ~sc_module();
virtual const char* kind() const;
void operator() ( const sc_bi nd_proxy

& p001,
const sc_bi nd_proxy

& p002 = SC_BIND_PROXY_NIL,


const sc_bi nd_proxy

& p003 = SC_BIND_PROXY_NIL,


...
const sc_bi nd_proxy

& p063 = SC_BIND_PROXY_NIL,


const sc_bi nd_proxy

& p064 = SC_BIND_PROXY_NIL );


virtual const std::vector<sc_object* >& get_child_objects() const;
virtual const std::vector<sc_event* >& get_child_events() const;
protected:
sc_module( const sc_modul e_name& );
sc_module();
void reset_signal_is( const sc_in<bool >& , bool );
void reset_signal_is( const sc_inout<bool >& , bool );
void reset_signal_is( const sc_out<bool >& , bool );
void reset_signal_is( const sc_si gnal _i n_i f<bool>& , bool );
void async_reset_signal_is( const sc_in<bool >& , bool );
void async_reset_signal_is( const sc_inout<bool >& , bool );
void async_reset_signal_is( const sc_out<bool >& , bool );
void async_reset_signal_is( const sc_si gnal _i n_i f<bool>& , bool );
sc_sensi ti ve

sensitive;
void dont_initialize();
void set_stack_size( si ze_t );
void next_trigger();
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


38
Copyright 2012 IEEE. All rights reserved.
void next_trigger( const sc_event& );
void next_trigger( const sc_event_or_li st & );
void next_trigger( const sc_event_and_li st & );
void next_trigger( const sc_ti me& );
void next_trigger( double , sc_ti me_unit );
void next_trigger( const sc_ti me& , const sc_event& );
void next_trigger( double , sc_ti me_unit , const sc_event& );
void next_trigger( const sc_ti me& , const sc_event_or_l ist &);
void next_trigger( double , sc_ti me_unit , const sc_event_or_li st & );
void next_trigger( const sc_ti me& , const sc_event_and_li st & );
void next_trigger( double , sc_ti me_unit , const sc_event_and_li st & );
void wait();
void wait( i nt );
void wait( const sc_event& );
void wait( const sc_event_or_l ist &);
void wait( const sc_event_and_l ist & );
void wait( const sc_ti me& );
void wait( double , sc_time_unit );
void wait( const sc_ti me& , const sc_event& );
void wait( double , sc_time_unit , const sc_event& );
void wait( const sc_ti me& , const sc_event_or_l ist & );
void wait( double , sc_time_unit , const sc_event_or_l ist & );
void wait( const sc_ti me& , const sc_event_and_l ist & );
void wait( double , sc_time_unit , const sc_event_and_l ist & );
virtual void before_end_of_elaboration();
virtual void end_of_elaboration();
virtual void start_of_simulation();
virtual void end_of_simulation();
pri vate:
// Di sabl ed
sc_module( const sc_modul e& );
sc_module& operator= ( const sc_modul e& );
} ;
void next_trigger();
void next_trigger( const sc_event& );
void next_trigger( const sc_event_or_li st & );
void next_trigger( const sc_event_and_li st & );
void next_trigger( const sc_ti me& );
void next_trigger( double , sc_ti me_unit );
void next_trigger( const sc_ti me& , const sc_event& );
void next_trigger( double , sc_ti me_unit , const sc_event& );
void next_trigger( const sc_ti me& , const sc_event_or_li st & );
void next_trigger( double , sc_ti me_unit , const sc_event_or_li st & );
void next_trigger( const sc_ti me& , const sc_event_and_li st & );
void next_trigger( double , sc_ti me_unit , const sc_event_and_li st & );
void wait();
void wait( i nt );
void wait( const sc_event& );
void wait( const sc_event_or_l ist & );
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


39
Copyright 2012 IEEE. All rights reserved.
void wait( const sc_event_and_li st & );
void wait( const sc_ti me& );
void wait( double , sc_time_unit );
void wait( const sc_ti me& , const sc_event& );
void wait( double , sc_time_unit , const sc_event& );
void wait( const sc_ti me& , const sc_event_or_l ist & );
void wait( double , sc_time_unit , const sc_event_or_l ist & );
void wait( const sc_ti me& , const sc_event_and_l ist & );
void wait( double , sc_time_unit , const sc_event_and_l ist & );
#def ine SC_MODULE(name) struct name : sc_module
#def ine SC_CTOR(name) i mpl ementati on-defi ned; name(sc_module_name)
#def ine SC_HAS_PROCESS(name) i mpl ementati on-defi ned
#def ine SC_METHOD(name) i mpl ementati on-defi ned
#def ine SC_THREAD(name) i mpl ementati on-defi ned
#def ine SC_CTHREAD(name,cl k) i mpl ementati on-defi ned
const char* sc_gen_unique_name( const char* );
typedef sc_modul e sc_behavior;
typedef sc_modul e sc_channel;
} // namespace sc_core
5.2.3 Constraints on usage
Objects of class sc_module can only be constructed during el aboration. It shall be an error to i nstantiate a
module during si mulati on.
Every class derived (di rectl y or indirectly) from cl ass sc_module shall have at l east one constructor. Every
such constructor shall have one and only one parameter of class sc_module_name but may have f urther
parameters of classes other than sc_module_name. That parameter is not required to be the fi rst parameter
of the constructor.
A stri ng-val ued argument shall be passed to the constructor of every module i nstance. It is good practi ce to
make this stri ng name the same as the C++ variabl e name through whi ch the module is ref erenced, i f such a
vari abl e exists.
I nter-modul e communication should typi call y be accompli shed usi ng i nterf ace method cal ls; that i s, a
module shoul d communicate with its envi ronment through i ts ports. Other communicati on mechanisms are
permi ssibl e, for example, for debuggi ng or di agnostic purposes.
NOTE 1Because the constructors are protected, cl ass sc_modulecannot be i nstantiated di rectl y but may be used as a
base class.
NOTE 2A module should be publ i cl y deri ved f rom cl ass sc_module.
NOTE 3It is permissibl e to use cl ass sc_module as an i ndi rect base cl ass. I n other words, a module can be deri ved
f rom another modul e. Thi s can be a usef ul codi ng i di om.
5.2.4 kind
Member f uncti on kind shall return the string "sc_module".
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


40
Copyright 2012 IEEE. All rights reserved.
5.2.5 SC_MODULE
The macro SC_MODULE may be used to prefi x the def ini tion of a modul e, but the use of this macro i s not
obligatory.
Exampl e:
// The f ollowi ng two cl ass defi nitions are equall y acceptabl e.
SC_MODULE(M)
{
M(sc_module_name) { }
...
} ;
class M: publ ic sc_modul e
{
publ ic:
M(sc_module_name) { }
...
} ;
5.2.6 Constructors
sc_module( const sc_modul e_name& );
sc_module();
Module names are managed by class sc_module_name, not by class sc_module. The stri ng name of the
module instance i s i nitiali zed usi ng the value of the string name passed as an argument to the constructor of
the class sc_module_name(see 5.3).
5.2.7 SC_CTOR
This macro i s provided f or convenience when declari ng or defi ning a constructor of a modul e. Macro
SC_CTOR shal l onl y be used at a place where the rul es of C++ permi t a constructor to be decl ared and can
be used as the decl arator of a constructor declaration or a constructor def ini tion. The name of the modul e
class bei ng constructed shall be passed as the argument to the macro.
Exampl e:
SC_MODULE(M1)
{
SC_CTOR(M1) // Constructor defini ti on
: i (0)
{ }
int i;
...
} ;
SC_MODULE(M2)
{
SC_CTOR(M2); // Constructor decl arati on
int i;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


41
Copyright 2012 IEEE. All rights reserved.
...
} ;
M2::M2(sc_modul e_name) : i(0) { }
The use of macro SC_CTOR i s not obl igatory. Using SC_CTOR, it i s not possible to add user-def ined
arguments to the constructor. I f an appl ication needs to pass addi ti onal arguments, the constructor shal l be
provided expli ci tl y. This is a useful coding i diom.
NOTE 1The macros SC_CTOR and SC_MODULE may be used i n conj uncti on or may be used separatel y.
NOTE 2Since macro SC_CTOR is equi val ent to decl aring a constructor f or a modul e, an i mpl ementati on wi l l ensure
that the constructor so decl ared has a parameter of type sc_module_name.
NOTE 3If process macros are invoked but macro SC_CTOR i s not used, macro SC_HAS_PROCESS shoul d be used
i nstead (see 5.2.8).
Exampl e:
SC_MODULE(M)
{
M(sc_module_name n, int a, int b) // Additional constructor parameters
: sc_modul e(n)
{ }
...
} ;
5.2.8 SC_HAS_PROCESS
Macro SC_CTOR includes defi nitions used by the macros SC_METHOD, SC_THREAD and
SC_CTHREAD. These same def ini ti ons are introduced by the macro SC_HAS_PROCESS. I f a process
macro i s invoked from the constructor body of a module but macro SC_CTOR i s not used within the modul e
class def ini tion, macro SC_HAS_PROCESS shall be invoked within the cl ass def inition or the constructor
body of the modul e. I f a process macro i s i nvoked from the before_end_of_elaboration or
end_of_elaboration cal lbacks of a module but macro SC_CTOR is not used wi thi n the module cl ass
def ini ti on, macro SC_HAS_PROCESS shall be invoked wi thin the class defi ni ti on of the modul e or f rom
that same call back.
Macro SC_HAS_PROCESS shal l onl y be used wi thin the class def ini tion, constructor body, or member
f uncti on body of a module. The name of the module class bei ng constructed shal l be passed as the argument
to the macro. The macro invocati on shal l be termi nated wi th a semicolon.
NOTEThe use of the macros SC_CTOR and SC_HAS_PROCESS is not requi red i n order to call the f uncti on
sc_spawn.
Exampl e:
SC_MODULE(M)
{
M(sc_module_name n) // SC_CTOR not used
: sc_modul e(n)
{
SC_THREAD(T); // Process macro
}
void T();
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


42
Copyright 2012 IEEE. All rights reserved.

SC_HAS_PROCESS(M); // Necessary
...
} ;
5.2.9 SC_METHOD, SC_THREAD, SC_CTHREAD
The argument passed to the macro SC_METHOD or SC_THREAD or the fi rst argument passed to
SC_CTHREAD shal l be the name of a member f uncti on. The macro shall associ ate that f unction with a
method pr ocess i nstance, a thr ead process i nstance, or a cl ocked thr ead process i nstance, respecti vel y. Thi s
shall be the only way i n whi ch an unspawned process i nstance can be created (see 4.1.2).
The second argument passed to the macro SC_CTHREAD shall be an expression of the type
sc_event_finder.
I n each case, the macro i nvocati on shall be termi nated with a semi col on.
These three macros shal l only be invoked i n the body of the constructor, in the before_end_of_elaboration
or end_of_elaboration call backs of a module, or i n a member f uncti on cal led from the constructor or
cal lback. Macro SC_CTHREAD shal l not be invoked from the end_of_elaboration call back. The f irst
argument shal l be the name of a member f unction of that same module.
A member f unction associated with an unspawned process instance shal l have a return type of void and shall
have no arguments. (Note that a f uncti on associated with a spawned process i nstance may have a return type
and may have arguments.)
A si ngl e member function can be associated wi th multiple process instances withi n the same module. Each
process i nstance is a di stinct obj ect of a class derived f rom cl ass sc_object, and each macro shall use the
member f unction name (i n quotati on marks) as the string name ultimately passed as an argument to the
constructor of the base class sub-obj ect of class sc_object. Each process instance can have i ts own stati c
sensitivity and shall be triggered or resumed independently of other process instances.
Associati ng a member f unction with a process instance does not impose any expli ci t restricti ons on how that
member function may be used by the applicati on. For exampl e, such a function may be cal led di rectly by the
appl ication, as well as by the kernel.
A process i nstance can be suspended, resumed, disabled, enabl ed, kil led, or reset using the member
f uncti ons of class sc_process_handle.
Exampl e:
SC_MODULE(M)
{
sc_i n<bool> clk;
SC_CTOR(M)
{
SC_METHOD(a_method);
SC_THREAD(a_thread);
SC_CTHREAD(a_cthread, cl k.pos());
}
void a_method();
void a_thread();
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


43
Copyright 2012 IEEE. All rights reserved.
void a_cthread();
...
} ;
5.2.10 Method process
This subclause shall apply to both spawned and unspawned process instances.
A method process is sai d to be tr i ggered when the kernel cal ls the f uncti on associ ated with the process
instance. When a method process is triggered, the associated f uncti on executes from begi nni ng to end, then
returns control to the kernel . A method process can only be ter mi nated by cal li ng the kill method of a
process handle associ ated wi th that process.
A method process i nstance may have stati c sensi ti vity. A method process, and only a method process, may
cal l the f unction next_trigger to create dynami c sensi ti vi ty. Function next_trigger i s a member f unction of
class sc_module, a member f unction of cl ass sc_prim_channel, and a non-member function.
A method process instance cannot be made runnabl e as a result of an immedi ate noti fi cati on executed by the
process i tself, regardl ess of the static sensi ti vi ty or dynamic sensi ti vity of the method process i nstance (see
4.2.1.2).
An implementati on i s not obli ged to run a method process i n a separate sof tware thread. A method process
may run in the same execution context as the si mulati on kernel.
Member function kind of the impl ementation-def ined class associated wi th a method process instance shal l
return the string sc_method_process.
NOTE 1Any local variables declared withi n the process wi ll be destroyed on return f rom the process. Data members
of the modul e shoul d be used to store persi stent state associ ated wi th the method process.
NOTE 2Function next_trigger can becal l ed f rom a member f uncti on of the modul e i tsel f , f rom a member f uncti on of
a channel , or f rom any f uncti on subj ect onl y to the rul es of C++, provi ded that the f uncti on i s ul timatel y cal l ed f rom a
method process.
5.2.11 Thread and clocked thread processes
This subclause shall apply to both spawned and unspawned process instances.
A f uncti on associated with a thread or cl ocked thread process i nstance is cal led once and onl y once by the
kernel, except when a process is reset; in which case, the associ ated f unction may be cal led again (see
5.2.12).
A thread or cl ocked thread process, and only such a process, may cal l the f uncti on wait. Such a call causes
the call ing process to suspend execution. Function wait is a member f unction of class sc_module, a member
f uncti on of cl ass sc_prim_channel, and a non-member function.
A thread or clocked thread process i nstance is said to be r esumed when the kernel causes the process to
continue execution, starti ng wi th the statement i mmediately f oll owing the most recent call to f unction wait.
When a thread or cl ocked thread process is resumed, the process executes unti l it reaches the next cal l to
functi on wait. Then, the process i s suspended once again.
A thread process i nstance may have static sensiti vity. A thread process instance may call functi on wait to
create dynami c sensitivity. A cl ocked thread process i nstance i s stati cal ly sensitive onl y to a si ngle cl ock.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


44
Copyright 2012 IEEE. All rights reserved.
A thread or clocked thread process i nstance cannot be made runnabl e as a result of an immedi ate noti fi cation
executed by the process i tsel f, regardl ess of the stati c sensi ti vity or dynami c sensi tivi ty of the thread process
instance (see 4.2.1.2).
Each thread or clocked thread process requi res i ts own executi on stack. As a result, context switchi ng
between thread processes may i mpose a simul ati on overhead when compared with method processes.
I f the thread or clocked thread process executes the enti re f uncti on body or executes a return statement and
thus returns control to the kernel , the associ ated functi on shall not be called again f or that process i nstance.
The process instance i s then said to be ter mi nated.
Member f uncti on kind of the i mplementati on-def ined cl ass associ ated with a thread process instance shall
return the string sc_thread_process.
Member f uncti on kind of the impl ementation-defined cl ass associated with a clocked thread process
instance shal l return the stri ng sc_cthread_process.
NOTE 1It is a common coding idiomto include an i nf i ni te l oop contai ni ng a cal l to f uncti on wait wi thi n a thread or
cl ocked thread process i n order to prevent the process f rom termi nati ng prematurel y.
NOTE 2When a process instance is resumed, any local variables defined within the process will retain the values they
had when the process was suspended.
NOTE 3If a thread or clocked thread process executes an infinite l oop that does not cal l f uncti on wait, the process wi l l
never suspend. Si nce the schedul er i s not pre-empti ve, no other process wi l l be abl e to execute.
NOTE 4Function wait can be cal l ed f rom a member f uncti on of the modul e i tself , f rom a member f uncti on of a
channel , or from any f uncti on subj ect onl y to the rul es of C++, provi ded that the f unction i s ul ti matel y call ed f rom a
thread or cl ocked thread process.
Exampl e:
SC_MODULE(synchronous_modul e)
{
sc_i n<bool> clock;
SC_CTOR(synchronous_module)
{
SC_THREAD(thread);
sensitive << cl ock.pos();
}
void thread() // Member functi on called once onl y
{
for (;;)
{
wait(); // Resume on positive edge of cl ock
...
}
}
...
} ;
5.2.12 Clocked thread processes
A clocked thread process shal l be a stati c process; clocked threads cannot be spawned processes.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


45
Copyright 2012 IEEE. All rights reserved.
A clocked thread process shall be stati call y sensitive to a si ngle cl ock, as determi ned by the event fi nder
passed as the second argument to macro SC_CTHREAD. The clocked thread process shal l be staticall y
sensitive to the event returned from the given event fi nder.
A clocked thread process may cal l either of the f ollowi ng f unctions:
void wait();
void wait( i nt );
It shall be an error f or a clocked thread process to call any other overloaded form of the functi on wait.
A cl ocked thread process may have any number of synchronous and asynchronous reset signal s specif ied
usi ng reset_signal_isand async_reset_signal_is, respecti vel y.
Any of the process control member functions of class sc_process_handlemay be cal led f or a cl ocked thread
process, although certain caveats apply to the use of member f uncti ons suspend, resume, reset, and
throw_it due to the f act that they can be cal led asynchronousl y with respect to the clock. These caveats are
descri bed bel ow.
I t is recommended to call disableand enablerather than suspend and resumefor cl ocked thread processes.
I n the case that resumeis call ed for a cl ocked thread process, i t is the responsibi lity of the cal ler to ensure
that resume i s cal led duri ng the eval uation phase that immediately fol lows the delta notif icati on or timed
noti fi cati on phase in which the clock event noti fi cati on occurs. If a cl ocked thread i s resumed at any other
ti me, that is, if the cal l to resumei s not synchroni zed wi th the cl ock, the behavior shall be impl ementation-
def ined.
The process control member f unctions kill, reset, and throw_it may be call ed asynchronousl y wi th respect
to the clock and thei r ef fect i s immediate, even in the case of a clocked thread process. Si mil arly, the ef fect
of an asynchronous reset attai ni ng i ts active value is immedi ate f or a cl ocked thread process.
I n summary, a cl ocked thread process shall have exactl y one cl ock signal and may have any number of
synchronous and asynchronous reset signal s as well as bei ng reset by call ing the process control member
f uncti on of cl ass sc_process_handle. As a consequence, the body of the associated functi on shoul d
normall y consist of reset behavi or f oll owed by a l oop statement that contains a cal l to wait f oll owed by the
behavior to be executed i n each cl ock cycl e (see the example below).
The fi rst time the clock event i s notif ied, the f unction associ ated with a clocked thread process shall be
cal led whether or not the reset signal is active. If a clocked thread process instance has been terminated, the
clock event shall be ignored for that process i nstance. A terminated process cannot be reset.
Exampl e:
sc_i n<bool> clock;
sc_i n<bool> reset;
sc_i n<bool> async_reset;
SC_CTOR(M)
{
SC_CTHREAD(CT1, clock.pos());
reset_si gnal _is(reset, true);
SC_CTHREAD(CT2, clock.pos());
async_reset_signal_is(async_reset, true);
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


46
Copyright 2012 IEEE. All rights reserved.
}
void CT1()
{
if (reset)
{
... // Reset acti ons
}
whil e(true)
{
wait(1); // Wait for 1 clock cycle
... // Clocked actions
}
}
void CT2()
{
... // Reset actions
whil e(true)
{
try {
whil e (true)
{
wait(); // Wai t f or 1 cl ock cycl e
... // Regul ar behavior
}
}
catch (...) // Some excepti on has been thrown
{
... // Handl e exception and go back to waiting for cl ock
}
}
}
5.2.13 reset_signal_is and async_reset_signal_is
void reset_signal_is( const sc_in<bool >& , bool );
void reset_signal_is( const sc_inout<bool>& , bool );
void reset_signal_is( const sc_out<bool >& , bool );
void reset_signal_is( const sc_si gnal _i n_i f<bool>& , bool );
void async_reset_signal_is( const sc_in<bool >& , bool );
void async_reset_signal_is( const sc_inout<bool >& , bool );
void async_reset_signal_is( const sc_out<bool >& , bool );
void async_reset_signal_is( const sc_si gnal _i n_i f<bool>& , bool );
Member f uncti ons reset_signal_is and async_reset_signal_is of class sc_module shall determine the
synchronous and asynchronous reset si gnals, respectively, of a thread, cl ocked thread, or method process.
These two member f unctions shall only be cal led i n the body of the constructor, i n the
before_end_of_elaboration callback of a modul e, or in a member f uncti on call ed f rom the constructor or
cal lback, and only after havi ng created a process instance within that same constructor or call back.
The order of execution of the statements wi thin the body of the constructor or the
before_end_of_elaboration cal lback shall be used to associ ate the cal l to reset_signal_is or
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


47
Copyright 2012 IEEE. All rights reserved.
async_reset_signal_is with a particular process instance; the cal l i s associated with the most recentl y
created process instance. If a module is instanti ated wi thin the constructor or call back between the process
bei ng created and f uncti on reset_signal_is or async_reset_signal_is bei ng cal led, the ef f ect of cal li ng
reset_signal_isor async_reset_signal_isshall be undef ined.
The f irst argument passed to f uncti on reset_signal_is or async_reset_signal_is shall identif y the signal
instance to be used as the reset. The si gnal may be identi fi ed indirectly by passi ng a port instance that i s
bound to the reset si gnal . The second argument shall be the active l evel of the reset si gnal, meaning that the
process is to be reset only when the val ue of the reset signal is equal to the val ue of this second argument.
When the reset signal (as specif ied by the fi rst argument) attains its active value (as specif ied by the second
argument), the process instance shall enter the synchr onous reset state. Whil e i n the synchronous reset state,
a process i nstance shal l be reset each ti me it is resumed, whether due to an event notif i cati on or to a time-
out. Bei ng reset in thi s sense shall have the same ef fect as would a cal l to the reset method of a process
handl e associ ated wi th the gi ven process instance. The synchronous reset state is descri bed more ful l y i n
5.6.6.3.
I f a process instance enters the synchronous reset state whil e it i s suspended (meaning that suspendhas been
cal led), the behavior shal l be impl ementation-defi ned (see 5.6.6.11).
I n the case of async_reset_signal_isonl y, the process shall also be reset whenever the reset si gnal attains i ts
active value. Being reset in thi s sense shall have the same ef fect as woul d a cal l to the reset method of a
process handle associ ated with the given process instance. Since the reset signal is itsel f a pri mitive channel
that can only change value i n the update phase, the process instance shall be reset by ef f ecti vel y cal li ng the
reset method of an associated process handle at some ti me duri ng the eval uation phase immediately
f ol lowi ng the reset si gnal attaining its active val ue and in an order determined by the kernel. An
asynchronous reset does not take priori ty over other processes that are due to run i n the same eval uation
phase.
When an asynchronous reset signal attai ns its acti ve value, the consequent reset shal l have the same priori ty
as a call to reset. When a process i nstance is reset whil e in the synchronous reset state, the consequent reset
shall have the same priori ty as sync_reset_on, regardless of whether the reset signal is synchronous or
asynchronous (see 5.6.6.11).
A gi ven process i nstance may have any number of synchronous and asynchronous reset signal s. When al l
such reset signals attain the negati on of their acti ve value, the process instance shal l leave the synchronous
reset state unl ess a call to sync_reset_on is in f orce f or the given process instance (see 5.6.6.3).
reset_signal_is and async_reset_signal_is are permi tted for method processes. The eff ect of resetti ng a
method process shall be to cancel any dynami c sensi ti vity, to restore the stati c sensitivi ty, and to cal l the
f uncti on associ ated with that process instance.
Exampl e:
SC_METHOD(rtl _proc);
sensitive << cl ock.pos();
async_reset_signal _i s(reset, true);
...
void rtl_proc()
{
if (reset)
// Asynchronous reset behavi or, executed whenever the reset i s acti ve
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


48
Copyright 2012 IEEE. All rights reserved.
else
// Synchronous behavior, only executed on a posi ti ve clock edge
}
5.2.14 sensitive
sc_sensi ti ve

sensitive;
This subcl ause descri bes the static sensi ti vity of an unspawned process. Static sensi ti vi ty for a spawned
process is created usi ng member function set_sensitivity of class sc_spawn_options(see 5.5).
Data member sensitive of class sc_module can be used to create the stati c sensiti vity of an unspawned
process i nstance usi ng operator<< of cl ass sc_sensi ti ve

(see 5.4). This shall be the onl y way to create static


sensiti vity f or an unspawned process instance. However, static sensi ti vity may be enabl ed or di sabled by
cal li ng f uncti on next_trigger (see 5.2.17) or functi on wait (see 5.2.18).
Static sensitivity shal l onl y be created i n the body of the constructor, in the before_end_of_elaboration or
end_of_elaboration call backs of a module, or in a member function cal led f rom the constructor or cal lback,
and only after having created an unspawned process instance wi thin that same constructor or call back. I t
shall be an error to modi fy the stati c sensitivi ty of an unspawned process duri ng simul ation.
The order of execution of the statements wi thin the body of the constructor or the
before_end_of_elaboration or end_of_elaboration cal lbacks i s used to associate stati c sensi ti vity with a
parti cul ar unspawned process i nstance; sensitivity is associ ated with the process i nstance most recently
created wi thi n the body of the current constructor or call back.
A clocked thread process cannot have stati c sensitivity other than to the clock i tself . Usi ng data member
sensitiveto create static sensitivity for a clocked thread process shal l have no ef fect.
NOTE 1Unrelated statements may be executed between creating an unspawned process i nstance and creati ng the
stati c sensi ti vi ty f or that same process i nstance. Stati c sensiti vi ty may be created i n a di ff erent f uncti on body f rom the
one i n whi ch the process i nstance was created.
NOTE 2Data member sensitive can be used more than once to add to the stati c sensi ti vi ty of any parti cul ar
unspawned process i nstance; each cal l to operator<< adds f urther events to the stati c sensi ti vi ty of the most recentl y
created process i nstance.
5.2.15 dont_initialize
void dont_initialize();
This subcl ause describes member f unction dont_initialize of class sc_module, which determines the
behavior of an unspawned process instance during initiali zation. The i niti ali zati on behavior of a spawned
process is determined by the member functi on dont_initializeof class sc_spawn_options(see 5.5).
Member f unction dont_initializeof cl ass sc_moduleshal l prevent a particular unspawned process i nstance
f rom bei ng made runnable duri ng the ini tial ization phase of the schedul er. In other words, the member
f uncti on associated with the gi ven process i nstance shall not be cal led by the schedul er until the process
instance is triggered or resumed because of the occurrence of an event.
dont_initialize shal l only be call ed in the body of the constructor, in the before_end_of_elaboration or
end_of_elaboration call backs of a module, or in a member function cal led f rom the constructor or cal lback,
and only after havi ng created an unspawned process instance wi thin that same constructor or cal lback.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


49
Copyright 2012 IEEE. All rights reserved.
The order of execution of the statements wi thin the body of the constructor or the
before_end_of_elaboration or end_of_elaboration cal lbacks is used to associate the cal l to
dont_initializewi th a parti cul ar unspawned process instance; it is associ ated wi th the most recentl y created
process i nstance. I f a module is i nstantiated within the constructor or call back between the process being
created and function dont_initializebei ng call ed, the eff ect of cal li ng dont_initializeshall be undef ined.
dont_initializeshall have no ef fect if called f or a clocked thread process, whi ch is not made runnabl e during
the ini ti al ization phase i n any case. An impl ementation may generate a warni ng but i s not obli ged to do so.
Exampl e:
SC_MODULE(Mod)
{
sc_signal<bool > A, B, C, D, E;
SC_CTOR(Mod)
{
sensitive << A; // Has no eff ect. Poor codi ng styl e

SC_THREAD(T);
sensitive << B << C; // Thread process T is made sensitive to B and C.
SC_METHOD(M);
f (); // Method process M is made sensitive to D.
sensitive << E; // Method process M is made sensitive to E as well as D.
dont_initiali ze(); // Method process M is not made runnabl e during initiali zation.
}
void f() { sensi ti ve << D; } // An unusual coding styl e
void T();
void M();
...
} ;
5.2.16 set_stack_size
void set_stack_size( si ze_t );
This subcl ause describes member f uncti on set_stack_sizeof class sc_module, which sets the stack si ze of
an unspawned process instance duri ng ini ti al ization. The stack size of a spawned process i s set by the
member f uncti on set_stack_sizeof class sc_spawn_options(see 5.5).
An appli cation may call member f uncti on set_stack_size to request a change to the si ze of the executi on
stack for the thread or clocked thread process instance for which the functi on is call ed. The ef f ect of this
functi on i s i mplementati on-defi ned.
set_stack_size shal l only be called i n the body of the constructor, i n the before_end_of_elaboration or
end_of_elaboration call backs of a module, or in a member function cal led f rom the constructor or cal lback,
and only after having created an unspawned process instance wi thin that same constructor or call back. I t
shal l be an error to call set_stack_sizeat other times or to call set_stack_sizefor a method process i nstance.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


50
Copyright 2012 IEEE. All rights reserved.
The order of execution of the statements wi thin the body of the constructor or the
before_end_of_elaborationor end_of_elaboration cal lbacks i s used to associ ate the cal l to set_stack_size
wi th a particular unspawned process i nstance; i t i s associated wi th the most recentl y created unspawned
process instance.
5.2.17 next_trigger
This subclause shall apply to both spawned and unspawned process instances.
This subclause shall apply to member functi on next_trigger of class sc_module, member function
next_trigger of class sc_prim_channel, and non-member functi on next_trigger.
When cal led wi th one or more arguments, the f unction next_trigger shal l set the dynamic sensitivi ty of the
method process instance from which it is called f or the very next occasi on on whi ch that process instance is
triggered, and for that occasi on only. The dynamic sensitivity is determined by the arguments passed to
functi on next_trigger.
If functi on next_trigger is cal led more than once duri ng a si ngl e executi on of a parti cul ar method process
instance, the last call to be executed shal l prevail . The ef fects of earl ier call s to f uncti on next_trigger f or
that particular process instance shal l be cancell ed.
I f function next_trigger is not cal led during a parti cular executi on of a method process i nstance, the method
process instance shall next be tri ggered according to its static sensi ti vi ty.
A call to the function next_trigger wi th one or more arguments shal l override the stati c sensi ti vity of the
process instance.
I t shall be an error to call function next_trigger from a thread or cl ocked thread process.
NOTEThe function next_trigger does not suspend the method process i nstance; a method process cannot be
suspended but al ways executes to compl etion bef ore returni ng control to the kernel .
void next_trigger();
The process shall be tri ggered on the static sensitivi ty. In the absence of static sensi ti vity for this
parti cul ar process instance, the process shall not be tri ggered again during the current simul ation.
Call ing next_trigger wi th an empty argument li st shal l cancel the eff ect of any earlier cal ls to
next_trigger duri ng the current execution of the method process i nstance and, thus, in eff ect shal l
be equivalent to not cal li ng next_trigger at all during a given process executi on.
void next_trigger( const sc_event& );
The process shal l be tri ggered when the event passed as an argument is notif ied.
void next_trigger( const sc_event_or_li st & );
The argument shal l take the form of a li st of events separated by the operator| of class sc_event or
sc_event_or_list. The process shall be triggered when any one of the given events i s noti fi ed. The
occurrence or non-occurrence of the other events in the l ist shall have no ef fect on that parti cul ar
triggeri ng of the process. I f a particular event appears more than once in the l ist, the behavior shal l
be the same as if that event had appeared only once. I t shall be an error to pass an empty event l ist
object as an argument to next_trigger (see 5.8 and 5.9).
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


51
Copyright 2012 IEEE. All rights reserved.
void next_trigger( const sc_event_and_li st & );
The argument shall take the form of a l ist of events separated by the operator& of cl ass sc_event or
sc_event_and_list. I n order f or the process to be triggered, every si ngl e one of the gi ven events
shal l be noti fi ed, wi th no expli ci t constraints on the time or order of those notif icati ons. The process
is triggered when the last such event is noti fi ed, last in the sense of being at the l atest point i n
simul ation ti me, not last in the li st. An event i n the l ist may be noti fi ed more than once before the
last event is noti fi ed. I f a particul ar event appears more than once i n the l ist, the behavior shal l be the
same as if that event had appeared onl y once. It shall be an error to pass an empty event li st object as
an argument to next_trigger (see 5.8 and 5.9).
void next_trigger( const sc_ti me& );
The process shal l be triggered after the time gi ven as an argument has elapsed. The time shall be
taken to be relati ve to the ti me at whi ch f uncti on next_trigger is call ed. When a process is tri ggered
in thi s way, a ti me-out is said to have occurred. I n this method cal l and i n those that f oll ow below,
the argument that specif ies the time-out shall not be negati ve.
void next_trigger( double v , sc_time_uni t tu );
is equi val ent to the f oll owing:
void next_tri gger( sc_ti me( v , tu ) );
void next_trigger( const sc_ti me& , const sc_event& );
The process shall be triggered after the gi ven time or when the given event is notif ied, whi chever
occurs f irst.
void next_trigger( double , sc_ti me_unit , const sc_event& );
void next_trigger( const sc_ti me& , const sc_event_or_li st & );
void next_trigger( double , sc_ti me_unit , const sc_event_or_li st & );
void next_trigger( const sc_ti me& , const sc_event_and_li st & );
void next_trigger( double , sc_ti me_unit , const sc_event_and_li st & );
Each of these compound f orms combi nes a time with an event or event l ist. The semantics of these
compound forms shal l be deduced from the rul es given f or the simpl e f orms. In each case, the
process shall be triggered after the given time-out or in response to the given event or event l ist,
whichever is sati sf ied fi rst.
Exampl e:
SC_MODULE(M)
{
SC_CTOR(M)
{
SC_METHOD(entry);
sensitive << si g;
}
void entry() // Run first at ini ti al ization.
{
if (sig == 0) next_tri gger(e1 | e2); // Trigger on event e1 or event e2 next ti me
else i f (si g == 1) next_tri gger(1, SC_NS); // Ti me-out after 1 nanosecond.
else next_tri gger(); // Tri gger on si gnal sig next ti me.
}
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


52
Copyright 2012 IEEE. All rights reserved.
sc_signal <int> si g;
sc_event e1, e2;
...
} ;
5.2.18 wait
This subclause shall apply to both spawned and unspawned process instances.
I n addition to causing the process instance to suspend, the functi on wait may set the dynami c sensitivity of
the thread or clocked thread process instance from whi ch it i s cal led f or the very next occasion on whi ch that
process i nstance is resumed, and for that occasion only. The dynami c sensitivity i s determi ned by the
arguments passed to function wait.
A call to the function wait wi th an empty argument list or with a si ngl e i nteger argument shall use the static
sensitivity of the process i nstance. This is the onl y f orm of wait permi tted wi thin a cl ocked thread process.
A cal l to the f uncti on wait with one or more non-integer arguments shal l overri de the static sensi tivi ty of the
process instance.
When cal ling functi on wait wi th a passed-by-reference parameter, the appli cation shall be obli ged to ensure
that the li feti mes of any actual arguments passed by reference extend f rom the ti me the functi on i s call ed to
the time the functi on call reaches compl eti on, and moreover in the case of a parameter of type sc_time, the
appl icati on shal l not modif y the value of the actual argument duri ng that peri od.
I t shall be an error to call function wait from a method process.
void wait();
The process shall be resumed on the stati c sensitivi ty. In the absence of stati c sensitivi ty for thi s
particul ar process, the process shal l not be resumed agai n during the current si mulati on.
void wait( i nt );
A cal l to this functi on shal l be equivalent to call ing the function wait wi th an empty argument l ist
f or a number of ti mes in i mmedi ate successi on, the number of times bei ng passed as the val ue of the
argument. I t shall be an error to pass an argument val ue less than or equal to zero. The
impl ementation i s expected to opti mize the executi on speed of thi s function f or clocked thread
processes.
void wait( const sc_event& );
The process shal l be resumed when the event passed as an argument i s noti fi ed.
void wait( const sc_event_or_l ist &);
The argument shal l take the form of a l ist of events separated by the operator| of cl asses sc_event
and sc_event_or_list. The process shal l be resumed when any one of the gi ven events is notif ied.
The occurrence or non-occurrence of the other events in the l ist shall have no eff ect on the
resumpti on of that particular process. I f a parti cul ar event appears more than once in the li st, the
behavior shal l be the same as i f i t appeared onl y once. It shall be an error to pass an empty event l ist
object as an argument to wait (see 5.8 and 5.9).
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


53
Copyright 2012 IEEE. All rights reserved.
void wait( const sc_event_and_li st & );
The argument shall take the f orm of a li st of events separated by the operator& of classes sc_event
and sc_event_and_list. I n order f or the process to be resumed, every si ngl e one of the given events
shal l be noti fi ed, wi th no expli ci t constraints on the time or order of those notif icati ons. The process
is resumed when the l ast such event i s noti fi ed, l ast i n the sense of bei ng at the l atest poi nt in
simul ation ti me, not last in the li st. An event i n the l ist may be noti fi ed more than once before the
last event is noti fi ed. I f a particul ar event appears more than once i n the l ist, the behavior shal l be the
same as i f it appeared only once. I t shall be an error to pass an empty event l ist obj ect as an argument
to wait (see 5.8 and 5.9).
void wait( const sc_ti me& );
The process shall be resumed after the ti me given as an argument has el apsed. The time shall be
taken to be relati ve to the ti me at whi ch functi on wait is call ed. When a process is resumed in this
way, a ti me-out i s said to have occurred. In this method cal l and in those that f ol low below, the
argument that speci fi es the time-out shall not be negati ve.
void wait( double v , sc_time_unit tu );
is equi val ent to the f oll owing:
void wait( sc_ti me( v, tu ) );
void wait( const sc_ti me& , const sc_event& );
The process shal l be resumed after the given time or when the given event i s notif ied, whi chever
occurs f irst.
void wait( double , sc_time_unit , const sc_event& );
void wait( const sc_ti me& , const sc_event_or_l ist & );
void wait( double , sc_time_unit , const sc_event_or_l ist & );
void wait( const sc_ti me& , const sc_event_and_l ist & );
void wait( double , sc_time_unit , const sc_event_and_l ist & );
Each of these compound f orms combi nes a time with an event or event l ist. The semantics of these
compound forms shal l be deduced from the rul es given f or the simpl e f orms. In each case, the
process shall be resumed after the given ti me-out or i n response to the gi ven event or event li st,
whichever is sati sf ied fi rst.
5.2.19 Positional port binding
Ports can be bound usi ng ei ther positional binding or named bi ndi ng. Positional bi nding is perf ormed usi ng
the operator() def ined in the current subcl ause. Named binding is perf ormed using the operator() or the
functi on bind of the class sc_port (see 5.12).
void operator() (
const sc_bi nd_proxy

& p001,
const sc_bi nd_proxy

& p002 = SC_BIND_PROXY_NIL,


...
const sc_bi nd_proxy

& p063 = SC_BIND_PROXY_NIL,


const sc_bi nd_proxy

& p064 = SC_BIND_PROXY_NIL );


This operator shal l bi nd the port instances within the module instance f or whi ch the operator i s call ed to the
channel instances and port instances passed as actual arguments to the operator, the port order being
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


54
Copyright 2012 IEEE. All rights reserved.
determi ned by the order i n which the ports were constructed. The f irst port to be constructed shall be bound
to the f irst argument, the second port to the second argument, and so f orth. I t shal l be an error i f the number
of actual arguments i s greater than the number of ports to be bound.
A mul ti port i nstance (see 5.12.3) shall be treated as a single port i nstance when posi ti onal binding is used
and may only be bound once, to a si ngl e channel instance or port instance. However, if a multiport instance
P is bound by position to another mul ti port instance Q, the chil d mul ti port P may be bound indirectl y to
more than one channel through the parent mul tiport Q. A gi ven multiport shal l not be bound both by position
and by name.
This operator shall only bind ports, not exports. Any export i nstances contained within the modul e instance
shall be i gnored by this operator.
An i mplementation may permi t more than 64 ports to be bound i n a si ngl e call to operator() by all owing
more than 64 arguments but i s not obl iged to do so. operator() shal l not be cal led more than once f or a given
module instance.
The f oll owi ng obj ects, and these alone, can be used as actual arguments to operator():
a) A channel, which is an object of a class derived f rom cl ass sc_interface
b) A port, whi ch i s an obj ect of a cl ass derived f rom cl ass sc_port
The type of a por t i s the name of the interface passed as a templ ate argument to class sc_port when the port
is instanti ated. The i nterf ace impl emented by the channel in case a) or the type of the port i n case b) shall be
the same as or deri ved from the type of the port bei ng bound.
An implementation may def er the completi on of port binding until a later time duri ng el aboration because
the port to whi ch a port i s bound may not yet i tself have been bound. Such def erred port binding shal l be
completed by the impl ementation bef ore the call backs to f unction end_of_elaboration.
NOTE 1To bind more than 64 ports of a single modul e instance, named bi ndi ng should be used.
NOTE 2Class sc_bi nd_proxy

, the parameter type of operator(), may provi de user-def i ned conversi ons i n the form of
two constructors, one havi ng a parameter type of sc_interface, and the other a parameter type of sc_port_base.
NOTE 3The actual argument cannot be an export, because thi s woul d requi re the C++ compi l er to perf orm two
i mpl i ci t conversi ons. However, i t i s possibl e to pass an export as an actual argument by expl i ci tl y cal l i ng the user-
defi ned conversi on sc_export::operator I F&. I t i s al so possi bl e to bi nd a port to an export usi ng named port bi ndi ng.
Exampl e:
SC_MODULE(M1)
{
sc_inout<i nt> P, Q, R; // Ports
...
} ;
SC_MODULE(Top1)
{
sc_i nout <i nt> A, B;
sc_signal <int> C;
M1 m1; // Module instance
SC_CTOR(Top1)
: m1("m1")
{
m1(A, B, C); // Binds P-to-A, Q-to-B, R-to-C
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


55
Copyright 2012 IEEE. All rights reserved.
}
...
} ;
SC_MODULE(M2)
{
sc_inout<i nt> S;
sc_i nout<i nt> * T; // Pointer-to-port (an unusual coding styl e)
sc_i nout<i nt> U;
SC_CTOR(M2) { T = new sc_inout<i nt>; }
...
} ;
SC_MODULE(Top2)
{
sc_i nout <i nt> D, E;
sc_signal <int> F;
M2 m2; // Module instance
SC_CTOR(Top2)
: m2("m2")
{
m2(D, E, F); // Bi nds S-to-D, U-to-E, (* T)-to-F
// Note that binding order depends on the order of port construction
}
...
} ;
5.2.20 before_end_of_elaboration, end_of_elaboration, start_of_simulation,
end_of_simulation
See 4.4.
5.2.21 get_child_objects and get_child_events
virtual const std::vector<sc_object* >& get_child_objects() const;
Member f uncti on get_child_objectsshall return a std::vector containi ng a pointer to every i nstance
of class sc_object that li es wi thi n the modul e in the object hi erarchy. This shall i nclude pointers to
all modul e, port, pri mi ti ve channel , unspawned process, and spawned process i nstances wi thi n the
module and any other appl icati on-def ined obj ects deri ved from cl ass sc_object wi thin the modul e.
virtual const std::vector<sc_event* >& get_child_events() const;
Member functi on get_child_eventsshall return a std::vector contai ni ng a poi nter to every object of
type sc_event that i s a hierarchicall y named event and whose parent is the current module.
NOTE 1The phrase wi thi n a modul edoes not i ncl ude i nstances nested wi thi n modules i nstances but only i ncl udes the
i mmedi ate chi l dren of the gi ven modul e.
NOTE 2An application can identi f y the i nstances by cal l i ng the member f uncti ons nameand kind of cl ass sc_object
or can determi ne thei r types usi ng a dynami c cast.
NOTE 3An event may have a hierarchical name and may have a parent i n the obj ect hi erarchy, but in any case events
are not themsel ves part of the obj ect hi erarchy.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


56
Copyright 2012 IEEE. All rights reserved.
Exampl e:
int sc_main (i nt argc, char* argv[] )
{
Top_l evel_module top("top");
std::vector<sc_obj ect* > chil dren = top.get_chil d_objects();
// Pri nt out names and kinds of top-level objects
f or (unsigned i = 0; i < chi ldren.si ze(); i++)
std::cout << chil dren[i ]->name() << " " << chi ldren[ i] ->kind() << std::endl;
sc_start();
return 0;
}
5.2.22 sc_gen_unique_name
const char* sc_gen_unique_name( const char* seed );
The functi on sc_gen_unique_name shall return a uni que character string that depends on the context from
which the f uncti on i s call ed. For this purpose, each module instance shal l have a separate space of uni que
string names, and there shall be a single global space of unique stri ng names for cal ls to
sc_gen_unique_name not made from within any module. These spaces of unique stri ng names shal l be
maintai ned by f uncti on sc_gen_unique_name and are onl y vi si bl e outside thi s functi on i n so f ar as they
aff ect the value of the stri ngs returned f rom this f uncti on. Functi on sc_gen_unique_name shal l onl y
guarantee the uniqueness of strings withi n each space of unique string names. There shal l be no guarantee
that the generated name does not cl ash with a string that was not generated by f unction
sc_gen_unique_name.
The unique string shall be constructed by appending a stri ng of two or more characters as a suf fi x to the
character stri ng passed as argument seed, subject to the rules given i n the remainder of this subcl ause. The
appended suff ix shall take the f orm of a single underscore character, foll owed by a series of one of more
deci mal digits f rom the character set 0-9. The number and choice of digits shal l be impl ementation-defi ned.
There shall be no restrictions on the character set of the seed argument to function sc_gen_unique_name.
The seed argument may be the empty stri ng.
String names are case-sensitive, and every character in a string name is si gni fi cant. For example, a, A,
a_, and A_ are each unique string names with respect to one another.
NOTEThe intended use of sc_gen_unique_nameis to generate uni que stri ng names f or obj ects of cl ass sc_object.
Cl ass sc_object does impose restri ctions on the character set of stri ng names passed as constructor arguments. The value
returned f rom f uncti on sc_gen_unique_namemay be used f or other unrel ated purposes.
5.2.23 sc_behavior and sc_channel
typedef sc_modul e sc_behavior;
typedef sc_modul e sc_channel;
The typedefs sc_behavior and sc_channel are provided f or users to express their intent.
NOTEThere is no distinction between a behavi or and a hi erarchi cal channel other than a dif f erence of i ntent. Ei ther
may i ncl ude both ports and publ i c member functi ons.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


57
Copyright 2012 IEEE. All rights reserved.
Exampl e:
class bus_interface
: vi rtual publi c sc_i nterf ace
{
publ ic:
virtual void wri te(i nt addr, int data) = 0;
virtual void read (int addr, i nt& data) = 0;
} ;
class bus_adapter
: publi c bus_i nterf ace, publi c sc_channel
{
publ ic:
virtual void wri te(i nt addr, int data); // Interface methods impl emented in channel
virtual void read (int addr, int& data);
sc_i n<bool> clock; // Ports
sc_out<bool> wr, rd;
sc_out<i nt> addr_bus;
sc_out<i nt> data_out;
sc_in <i nt> data_i n;
SC_CTOR(bus_adapter) { ... } // Module constructor
pri vate:
...
} ;
5.3 sc_module_name
5.3.1 Description
Cl ass sc_module_nameacts as a contai ner for the string name of a modul e and provi des the mechanism f or
buil di ng the hierarchi cal names of instances in the modul e hi erarchy duri ng elaborati on.
When an appli cation creates an object of a class derived di rectly or indi rectly from cl ass sc_module, the
appl icati on typicall y passes an argument of type char* to the module constructor, whi ch itsel f has a single
parameter of class sc_module_nameand thus the constructor sc_module_name( const char* ) i s call ed as
an i mpli ci t conversi on. On the other hand, when an applicati on deri ves a new cl ass di rectl y or i ndi rectl y
f rom class sc_module, the derived cl ass constructor call s the base class constructor wi th an argument of
class sc_module_name and thus the copy constructor sc_module_name( const sc_module_name& ) i s
cal led.
5.3.2 Class definition
namespace sc_core {
class sc_module_name
{
publ ic:
sc_module_name( const char* );
sc_module_name( const sc_modul e_name& );
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


58
Copyright 2012 IEEE. All rights reserved.
~sc_module_name();
operator const char*() const;
pri vate:
// Di sabl ed
sc_module_name();
sc_module_name& operator= ( const sc_modul e_name& );
} ;
} // namespace sc_core
5.3.3 Constraints on usage
Cl asssc_module_nameshall onl y be used as the type of a parameter of a constructor of a class derived from
class sc_module. Moreover, every such constructor shal l have exactl y one parameter of type
sc_module_name, which need not be the fi rst parameter of the constructor.
I n the case that the constructor of a class C derived di rectly or i ndi rectly from cl ass sc_module is call ed
f rom the constructor of a class D deri ved di rectly from class C, the parameter of type sc_module_nameof
the constructor of class D shal l be passed di rectl y through as an argument to the constructor of cl ass C. I n
other words, the derived class constructor shall pass the sc_module_name through to the base cl ass
constructor as a constructor argument.
NOTE 1The macro SC_CTOR defines such a constructor.
NOTE 2In the case of a class C derived di rectl y f rom class sc_module, the constructor f or cl ass C i s not obl i ged to
pass the sc_module_namethrough to the constructor f or cl ass sc_module. The defaul t constructor f or cl ass sc_module
may be cal l ed expli ci tl y or i mpl ici tl y f rom the constructor f or cl ass C.
5.3.4 Module hierarchy
To keep track of the module hierarchy during elaborati on, the impl ementation may mai ntain an i nternal
stack of poi nters to obj ects of cl ass sc_module_name, referred to below as the stack. For the purpose of
buildi ng hierarchical names, when objects of class sc_module, sc_port, sc_export, sc_prim_channel, or
sc_event are constructed or when spawned or unspawned processes i nstances are created, they are assumed
to exist wi thin the module identif ied by the sc_module_nameobj ect on the top of the stack. In other words,
each i nstance in the modul e hierarchy is named as if it were a chi ld of the module i denti fi ed by the item on
the top of the stack at the poi nt when the instance is created.
The impl ementation is not obli ged to use these parti cul ar mechanisms (a stack of pointers), but if not, the
impl ementation shall substitute an al ternati ve mechanism that is semanti cal ly equi val ent.
NOTE 1The hi erar chi cal nameof an i nstance i n the obj ect hierarchy is returned f rom member f uncti on nameof cl ass
sc_object, whi ch i s the base cl ass of al l such i nstances.
NOTE 2An object of type sc_event may have a hi erarchi cal name and may have a parent i n the obj ect hi erarchy, but
i n any casesc_event i s not deri ved f rom sc_object and events are not themsel ves part of the obj ect hierarchy.
5.3.5 Member functions
sc_module_name( const char* );
This constructor shall push a poi nter to the obj ect being constructed onto the top of the stack. The
constructor argument shal l be used as the string name of the module being i nstantiated wi thin the
module hierarchy by ultimatel y being passed as an argument to the constructor of cl ass sc_object.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


59
Copyright 2012 IEEE. All rights reserved.
sc_module_name( const sc_modul e_name& );
This constructor shall copy the constructor argument but shal l not modif y the stack.
~sc_module_name();
I f and onl y if the object being destroyed was constructed by sc_module_name( const char* ), the
destructor shal l remove the sc_module_namepoi nter f rom the top of the stack.
operator const char*() const;
This conversi on f unction shall return the string name (not the hierarchi cal name) associated with the
sc_module_name.
NOTE 1When a compl ete obj ect of a cl ass deri ved f rom sc_modulei s constructed, the constructor f or that
deri ved cl ass i s passed an argument of type char*. The f i rst constructor above wi l l be cal l ed to perf orm an
i mpl i ci t conversi on f rom type char* to type sc_module_name, thus pushi ng the newl y created modul e name
onto the stack and si gni f yi ng the entry i nto a new l evel i n the modul e hierarchy. On return f rom the constructor
f or the cl ass of the compl ete obj ect, the destructor f or cl ass sc_module_namewi l l be cal l ed and wi l l remove
the modul e name f rom the stack.
NOTE 2When an sc_module_name i s passed as an argument to the constructor of a base class, the above
copy constructor i s cal l ed. The sc_module_name parameter of the base cl ass may be unused. The reason for
mandati ng that every such constructor have a parameter of cl ass sc_module_name (even i f the parameter i s
unused) i s to ensure that every such deri ved cl ass can be i nstanti ated as a modul e in i ts own ri ght.
Exampl e:
struct A: sc_module
{
A(sc_modul e_name) { } // Cal ls sc_module()
} ;
struct B: sc_modul e
{
B(sc_modul e_name n)
: sc_modul e(n) { } // Cal ls sc_modul e(sc_module_name&)
} ;
struct C: B // One module derived from another
{
C(sc_modul e_name n)
: B(n) { } // Cal ls sc_module_name(sc_modul e_name&) then
// B(sc_modul e_name)
} ;
struct Top: sc_modul e
{
A a;
C c;
Top(sc_module_name n)
: sc_modul e(n), // Cal ls sc_modul e(sc_module_name&)
a("a"), // Cal ls sc_module_name(char* ) then cal ls A(sc_modul e_name)
c("c") { } // Calls sc_module_name(char* ) then cal ls C(sc_modul e_name)
} ;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


60
Copyright 2012 IEEE. All rights reserved.
5.4 sc_sensitive

5.4.1 Description
Cl ass sc_sensi ti ve

provides the operators used to bui ld the stati c sensitivi ty of an unspawned process
instance. To create stati c sensi ti vity f or a spawned process, use the member function set_sensitivity of the
class sc_spawn_options(see 5.5).
5.4.2 Class definition
namespace sc_core {
class sc_sensi ti ve

{
publ ic:
sc_sensi ti ve

& operator<< ( const sc_event& );


sc_sensi ti ve

& operator<< ( const sc_interface& );


sc_sensi ti ve

& operator<< ( const sc_port_base& );


sc_sensi ti ve

& operator<< ( sc_event_fi nder& );


// Other members
i mpl ementati on-defi ned
} ;
} // namespace sc_core
5.4.3 Constraints on usage
An appl ication shall not expli ci tl y create an obj ect of cl ass sc_sensi ti ve

.
Cl ass sc_module shal l have a data member named sensitive of type sc_sensi ti ve

. The use of sensitive to


create static sensitivity i s described i n 5.2.14.
5.4.4 operator<<
sc_sensi ti ve

& operator<< ( const sc_event& );


The event passed as an argument shal l be added to the static sensitivity of the process i nstance.
sc_sensi ti ve

& operator<< ( const sc_interface& );


The event returned by member functi on default_event of the channel instance passed as an
argument to operator<< shal l be added to the stati c sensitivi ty of the process instance.
NOTE 1If the channel passed as an argument does not overri de f uncti on default_event, the member f uncti on
default_event of cl ass sc_interfacei s cal l ed through i nheri tance.
NOTE 2An export can be passed as an actual argument to thi s operator because of the exi stence of the user-
defi ned conversi on sc_export<I F>::operator.
sc_sensi ti ve

& operator<< ( const sc_port_base& );


The event returned by member function default_event of the channel instance to whi ch the port
instance passed as an argument to operator<< is bound shall be added to the stati c sensi ti vi ty of the
process i nstance. I n other words, the process i s made sensi ti ve to the given port, call ing function
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


61
Copyright 2012 IEEE. All rights reserved.
default_event to determine to whi ch parti cul ar event i t shoul d be made sensiti ve. If the port i nstance
is a multiport (see 5.12.3), the events returned by cal li ng member f unction default_event f or each
and every channel instance to whi ch the mul ti port is bound shal l be added to the static sensitivity of
the process instance.
sc_sensi ti ve

& operator<< ( sc_event_fi nder& );


The event found by the event fi nder passed as an argument to operator<< shal l be added to the
stati c sensitivi ty of the process instance (see 5.7).
NOTEAn event finder is necessary to create static sensitivity when the application needs to select between
multi pl e events def i ned i n the channel . In a such a case, the default_event mechani sm i s i nadequate.
5.5 sc_spawn_options and sc_spawn
5.5.1 Description
Function sc_spawn is used to create a stati c or dynamic spawned process instance.
Cl ass sc_spawn_optionsi s used to create an object that is passed as an argument to function sc_spawn
when creati ng a spawned process instance. The spawn opti ons determine certai n properties of the spawned
process instance when used i n this way. Cal li ng the member functions of an sc_spawn_optionsobject shal l
have no ef fect on any process i nstance unless the object is passed as an argument to sc_spawn.
5.5.2 Class definition
namespace sc_core {
class sc_spawn_options
{
publ ic:
sc_spawn_options();
void spawn_method();
void dont_initialize();
void set_stack_size( i nt );
void set_sensitivity( const sc_event* );
void set_sensitivity( sc_port_base* );
void set_sensitivity( sc_export_base* );
void set_sensitivity( sc_interf ace* );
void set_sensitivity( sc_event_fi nder* );
void reset_signal_is( const sc_in<bool >& , bool );
void reset_signal_is( const sc_inout<bool >& , bool );
void reset_signal_is( const sc_out<bool >& , bool );
void reset_signal_is( const sc_si gnal _i n_i f<bool>& , bool );
void async_reset_signal_is( const sc_in<bool >& , bool );
void async_reset_signal_is( const sc_inout<bool >& , bool );
void async_reset_signal_is( const sc_out<bool >& , bool );
void async_reset_signal_is( const sc_si gnal _i n_i f<bool>& , bool );
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


62
Copyright 2012 IEEE. All rights reserved.
pri vate:
// Di sabl ed
sc_spawn_options( const sc_spawn_options& );
sc_spawn_options& operator= ( const sc_spawn_options& );
} ;
templ ate <typename T>
sc_process_handle sc_spawn(
T obj ect ,
const char* name_p = 0 ,
const sc_spawn_opti ons* opt_p = 0 );
templ ate <typename T>
sc_process_handle sc_spawn(
typename T::resul t_type* r_p ,
T obj ect ,
const char* name_p = 0 ,
const sc_spawn_opti ons* opt_p = 0 );
#def ine sc_bind boost::bi nd
#def ine sc_ref(r) boost::ref (r)
#def ine sc_cref(r) boost::cref (r)
#def ine SC_FORK i mpl ementati on-defi ned
#def ine SC_JOI N i mpl ementati on-defi ned
} // namespace sc_core
namespace sc_unnamed {
i mpl ementati on-defi ned _1;
i mpl ementati on-defi ned _2;
i mpl ementati on-defi ned _3;
i mpl ementati on-defi ned _4;
i mpl ementati on-defi ned _5;
i mpl ementati on-defi ned _6;
i mpl ementati on-defi ned _7;
i mpl ementati on-defi ned _8;
i mpl ementati on-defi ned _9;
} // namespace sc_unnamed
5.5.3 Constraints on usage
Function sc_spawn may be call ed during elaborati on or from a static, dynami c, spawned, or unspawned
process during si mulati on. Simi larl y, obj ects of class sc_spawn_optionsmay be created or modif ied during
elaborati on or simul ation.
5.5.4 Constructors
sc_spawn_options();
The default constructor shall create an obj ect havi ng the def aul t val ues f or the properties set by the f unctions
spawn_method, dont_initialize, set_stack_size, and set_sensitivity.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


63
Copyright 2012 IEEE. All rights reserved.
5.5.5 Member functions
void spawn_method();
Member f unction spawn_method shal l set a property of the spawn opti ons to i ndi cate that the
spawned process shal l be a method process. The default is a thread process.
void dont_initialize();
Member f uncti on dont_initialize shall set a property of the spawn opti ons to i ndi cate that the
spawned process instance shal l not be made runnabl e during the i niti ali zati on phase or when i t is
created. By default, this property i s not set, and thus by default the spawned process i nstance shall be
made runnabl e during the ini ti al izati on phase of the schedul er i f spawned duri ng el aboration, or i t
shal l be made runnable i n the current or next eval uation phase if spawned duri ng simul ation
irrespecti ve of the static sensi ti vi ty of the spawned process instance. I f the process i s spawned
duri ng el aboration, member functi on dont_initialize of cl ass sc_spawn_optionsshall provide the
same behavi or for spawned processes as the member functi on dont_initialize of class sc_module
provides for unspawned processes.
void set_stack_size( i nt );
Member f uncti on set_stack_sizeshall set a property of the spawn options to set the stack size of the
spawned process. Thi s member f uncti on shal l provi de the same behavior f or spawned processes as
the member f uncti on set_stack_size of cl ass sc_module provi des f or unspawned processes. The
eff ect of cal li ng this functi on i s i mplementati on-def ined.
I t shall be an error to call set_stack_sizefor a method process.
void set_sensitivity( const sc_event* );
void set_sensitivity( sc_port_base* );
void set_sensitivity( sc_export_base* );
void set_sensitivity( sc_interf ace* );
void set_sensitivity( sc_event_fi nder* );
Member f uncti on set_sensitivity shall set a property of the spawn opti ons to add the object passed
as an argument to set_sensitivity to the static sensitivity of the spawned process, as described f or
operator<< i n 5.4.4, or if the argument is the address of an export, the process is made sensi ti ve to
the channel i nstance to which that export i s bound. I f the argument i s the address of a multiport, the
process shal l be made sensi ti ve to the events returned by call ing member f unction default_event for
each and every channel instance to whi ch the mul ti port is bound. By def aul t, the stati c sensitivity is
empty. Call s to set_sensitivity are cumulati ve: each call to set_sensitivity extends the stati c
sensitivity as set i n the spawn options. Call s to the f our di ff erent overl oaded member f uncti ons can
be mixed.
void reset_signal_is( const sc_in<bool >& , bool );
void reset_signal_is( const sc_inout<bool>& , bool );
void reset_signal_is( const sc_out<bool>& , bool );
void reset_signal_is( const sc_si gnal _i n_i f<bool>& , bool );
void async_reset_signal_is( const sc_in<bool >& , bool );
void async_reset_signal_is( const sc_inout<bool >& , bool );
void async_reset_signal_is( const sc_out<bool >& , bool );
void async_reset_signal_is( const sc_si gnal _i n_i f<bool>& , bool );
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


64
Copyright 2012 IEEE. All rights reserved.
Member functions reset_signal_is and async_reset_signal_is shal l set a property of the spawn
opti ons to add the obj ect passed as an argument as a synchronous or an asynchronous reset si gnal of
the spawned process instance, respecti vely, as described i n 5.2.13. Each call to ei ther of these
member functions shall add a reset si gnal to the gi ven spawn options obj ect. The signal may be
identi fi ed indirectly by passing a port instance that is bound to the reset signal . A spawned process
instance may have any number of synchronous and asynchronous reset signal s.
NOTE 1There are no member functions to set the spawn options to spawn a thread process or to make a process
runnabl e duri ng ini ti al i zati on. This f uncti onal i ty i s rel i ant on the def aul t val ues of the sc_spawn_optionsobj ect.
NOTE 2It is not possible to spawn a dynami c cl ocked thread process.
5.5.6 sc_spawn
templ ate <typename T>
sc_process_handle sc_spawn(
T obj ect ,
const char* name_p = 0 ,
const sc_spawn_opti ons* opt_p = 0 );
templ ate <typename T>
sc_process_handle sc_spawn(
typename T::resul t_type* r_p ,
T obj ect ,
const char* name_p = 0 ,
const sc_spawn_opti ons* opt_p = 0 );
#def ine sc_bind boost::bi nd
#def ine sc_ref(r) boost::ref (r)
#def ine sc_cref(r) boost::cref (r)
Function sc_spawn shal l create a stati c or dynamic spawned process instance.
Function sc_spawn may be cal led during elaborati on, i n which case the spawned process is a chi l d of the
module instance within which functi on sc_spawn is cal led or i s a top-l evel obj ect i f f unction sc_spawn is
cal led from function sc_main.
Function sc_spawn may be cal led duri ng si mulation, in which case the spawned process is a chil d of the
process that cal led f unction sc_spawn. Functi on sc_spawn may be cal led f rom a method process, a thread
process, or a cl ocked thread process.
The process or module from whi ch sc_spawn is cal led i s the parent of the spawned process. Thus a set of
dynami c process i nstances may have a hi erarchical rel ati onship, simi lar to the modul e hi erarchy, whi ch wi ll
be refl ected in the hierarchical names of the process instances.
If function sc_spawn is call ed duri ng the evaluati on phase, the spawned process shall be made runnable i n
the current evaluati on phase (unl ess dont_initialize has been cal led f or this process instance). I f functi on
sc_spawn i s call ed during the update phase, the spawned process shall be made runnable i n the very next
eval uation phase (unl ess dont_initializehas been cal led f or thi s process instance).
The argument of typeT shall be either a function pointer or a functi on object, that i s, an obj ect of a cl ass that
overloads operator() as a member f uncti on and shall speci fy the functi on associated with the spawned
process instance, that is, the functi on to be spawned. This shal l be the only mandatory argument to f unction
sc_spawn.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


65
Copyright 2012 IEEE. All rights reserved.
I f present, the argument of type T::result_type* shal l pass a poi nter to a memory l ocati on that shal l receive
the value returned from the f uncti on associ ated with the process i nstance. I n thi s case, the argument of type
T shall be a f unction object of a cl ass that exposes a nested type named result_type. Furthermore,
operator() of the function object shall have the return type result_type. I t is the responsi bil ity of the
appl icati on to ensure that the memory location is stil l val id when the spawned f uncti on returns. For example,
the memory location could be a data member of an encl osi ng sc_modulebut should not be a stack vari able
that would have been deal located by the time the spawned f uncti on returns. See the example bel ow.
The macros sc_bind, sc_ref, and sc_cref are provi ded for convenience when usi ng the f ree Boost C++
li brari es to bind arguments to spawned functions. Passi ng arguments to spawned processes i s a powerful
mechanism that al lows processes to be parameteri zed when they are spawned and permi ts processes to
update variables over time through ref erence arguments. boost::bind provi des a conveni ent way to pass
value arguments, ref erence arguments, and const reference arguments to spawned functions, but i ts use is
not mandatory. See the examples below and the Boost documentati on avai lable on the Internet.
The onl y purpose of namespace sc_unnamed i s to al low the i mplementati on to provide a set of argument
placeholders for use with sc_bind. _1, _2, _3 ... shal l be provi ded by the impl ementation to give access to
the pl aceholders of the same names from the Boost l ibrari es. These pl acehol ders can be passed as arguments
to sc_bind in order to defer the binding of function arguments until the cal l to the function obj ect returned
f rom sc_bind. Agai n, see the Boost documentati on f or detai ls.
The argument of type const char* shall gi ve the stri ng name of the spawned process i nstance and shal l be
passed by the i mplementati on to the constructor f or the sc_object that f orms the base class sub-obj ect of the
spawned process i nstance. I f no such argument i s gi ven or i f the argument i s an empty string, the
impl ementation shal l create a string name f or the process instance by call ing f unction sc_gen_unique_name
wi th the seed stri ng "thread_p" in the case of a thread process or "method_p" in the case of a method
process.
The argument of type sc_spawn_options* shall set the spawn options for the spawned process instance. If
no such argument i s provided, the spawned process instance shall take the default values as def ined for the
member functions of classsc_spawn_options. The appli cation i s not obli ged to keep the sc_spawn_options
object val id after the return f rom f uncti on sc_spawn.
Function sc_spawnshal l return a vali d process handl e to the spawned process i nstance. A process instance
can be suspended, resumed, disabled, enabled, kil led, or reset using the member f unctions of cl ass
sc_process_handle.
I f a spawn options argument is given, a process stri ng name argument shal l also be given, al though that
string name argument may be an empty stri ng.
NOTEFunction sc_spawnprovi des asuperset of the functi onal i ty of the macros SC_THREAD and SC_METHOD. I n
addi ti on to the f unctional i ty provi ded by these macros, f uncti on sc_spawnprovi des the passi ng of arguments and return
val ues to and f rom processes spawned duri ng el aborati on or si mul ati on. The macros are retai ned f or compati bi l i ty wi th
earli er versi ons of SystemC.
Exampl e:
int f();
struct Functor
{
typedef int result_type;
result_type operator() ();
} ;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


66
Copyright 2012 IEEE. All rights reserved.
Functor::resul t_typeFunctor::operator() () { returnf(); }
int h(int a, i nt& b, const int& c);
struct MyMod: sc_module
{
sc_signal <int> si g;
void g();
SC_CTOR(MyMod)
{
SC_THREAD(T);
}
int ret;
void T()
{
sc_spawn(&f); // Spawn afunction wi thout argumentsand di scard any return value.
// Spawn asi mil ar process and createaprocess handle.
sc_process_handlehandle= sc_spawn(&f);
Functor fr;
sc_spawn(&ret, fr); // Spawn afuncti onobject andcatch thereturn value.
sc_spawn_optionsopt;
opt.spawn_method();
opt.set_sensi ti vi ty(&si g);
opt.dont_initiali ze();
sc_spawn(f, "f1", &opt); // Spawn amethod processnamed "f1", sensi ti veto sig, not initiali zed.
// Spawn asi mil ar process named "f2" and catch thereturn value.
sc_spawn(&ret, fr, "f2", &opt);
// Spawn amember function usi ng Boost bi nd.
sc_spawn(sc_bind(&MyMod::g, thi s));
int A = 0, B, C;
// Spawn afunction usi ng Boost bind, passarguments
// and catch thereturn val ue.
sc_spawn(&ret, sc_bi nd(&h, A, sc_ref(B), sc_cref(C)));
}
} ;
5.5.7 SC_FORK and SC_JOIN
#defineSC_FORK i mpl ementati on-defi ned
#defineSC_JOIN i mpl ementati on-defi ned
The macros SC_FORK and SC_JOIN can onl y be used as a pai r to bracket a set of cal ls to functi on
sc_spawn from within a thread or clocked thread process. It i s an error to use the fork-joi n construct in a
method process. Each call to sc_spawn (encl osed between SC_FORK and SC_JOIN) shall result i n a
separate process i nstance being spawned when control enters the fork-j oin construct. The chil d processes
shall be spawned without del ay and may potenti al ly all become runnable i n the current eval uation phase
(dependi ng on their spawn options). Thespawned process instances shal l be thread processes. It is an error
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


67
Copyright 2012 IEEE. All rights reserved.
to spawn amethod process withi n a fork-join construct. Control l eaves thefork-j oin construct when all the
spawned processi nstances haveterminated.
The text between SC_FORK and SC_JOIN shall consist of a series of one or more cal ls to function
sc_spawn separated by commas. Thevaluereturnedfromthefunction call may bedi scardedor thefuncti on
cal l may betheonly expressi onontheright-hand-sideof an assi gnment toavariable, wherethevari ablewil l
beset totheprocess handlereturned fromsc_spawn.
Thecommaafter thefi nal cal l to sc_spawn andi mmediatel y beforeSC_JOIN shal l beoptional . Thereshal l
be no other characters other than white space separati ng SC_FORK, the functi on cal ls, or variable
assignments, thecommas, and SC_JOIN. If anappl icati on violatestheserules, theeffect shall beundefi ned.
Exampl e 1:
SC_FORK
sc_spawn( arguments ) ,
sc_spawn( arguments ) ,
sc_spawn( arguments )
SC_JOIN
Exampl e 2:
sc_process_handleh1, h2, h3;
SC_FORK
h1 = sc_spawn( ar guments ) ,
h2 = sc_spawn( ar guments ) ,
h3 = sc_spawn( ar guments )
SC_JOIN
5.6 sc_process_handle
5.6.1 Description
Cl ass sc_process_handl e provi des a process handl e to an underlyi ng spawned or unspawned process
instance. A process handl e can be i n one of two states: val i d or i nval i d. A val i d process handle shal l be
associ ated with a si ngl e underl yi ng processi nstance, whi ch may or may not bei n thetermi nated state. An
i nval i d process handle may be associated wi th a single underlyi ng process i nstance provided that process
instance has termi nated. An empty process handle is an i nvali d handl e that is not associ ated wi th any
underlying process instance. In other words, an i nvali d process handl e is either an empty handl e or is
associ ated withaterminated processi nstance. A processi nstancemay beassoci ated withzero, oneor many
process handles, andthenumber and i denti ty of such processhandl esmay changeover ti me.
Since dynamic process i nstances can be created and destroyed dynamicall y duri ng simul ation, it is i n
general unsafeto manipulateaprocessinstancethrough araw pointer to theprocessinstance(or to thebase
class sub-object of class sc_obj ect). The purpose of class sc_process_handle i s to provide a safe and
uniform mechani sm for manipulating both spawned and unspawned process i nstances without reli ance on
raw pointers. If control returns from the functi on associated with a thread process instance (that is, the
process terminates), theunderl yi ng processi nstancemay bedel eted, but theprocesshandlewil l conti nueto
exi st.
The provi si on of oper ator <, which suppl ies a stri ct weak orderi ng relation on the underlyi ng process
instances, al lows processhandlestobestoredi n astandardC++ container such as std::map.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


68
Copyright 2012 IEEE. All rights reserved.
5.6.2 Class definition
namespace sc_core {
enum sc_curr_proc_kind
{
SC_NO_PROC_ ,
SC_METHOD_PROC_ ,
SC_THREAD_PROC_ ,
SC_CTHREAD_PROC_
} ;
enum sc_descendant_inclusion_info
{
SC_NO_DESCENDANTS,
SC_INCLUDE_DESCENDANTS
} ;
class sc_unwind_exception: publi c std::exception
{
publ ic:
virtual const char* what() const throw();
virtual bool is_reset() const;
protected:
sc_unwind_exception();
sc_unwind_exception( const sc_unwi nd_excepti on& );
virtual ~sc_unwind_exception() throw();
} ;
class sc_process_handle
{
publ ic:
sc_process_handle();
sc_process_handle( const sc_process_handl e& );
expl icit sc_process_handle( sc_obj ect* );
~sc_process_handle();
bool valid() const;
sc_process_handle& operator= ( const sc_process_handl e& );
bool operator== ( const sc_process_handl e& ) const;
bool operator!= ( const sc_process_handl e& ) const;
bool operator< ( const sc_process_handl e& ) const;
void swap( sc_process_handl e& );
const char* name() const;
sc_curr_proc_kind proc_kind() const;
const std::vector<sc_object* >& get_child_objects() const;
const std::vector<sc_event* >& get_child_events() const;
sc_object* get_parent_object() const;
sc_object* get_process_object() const;
bool dynamic() const;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


69
Copyright 2012 IEEE. All rights reserved.
bool terminated() const;
const sc_event& terminated_event() const;
void suspend ( sc_descendant_i ncl usi on_i nf o include_descendants = SC_NO_DESCENDANTS );
void resume ( sc_descendant_i ncl usi on_i nf o include_descendants = SC_NO_DESCENDANTS );
void disable ( sc_descendant_i ncl usi on_i nf o include_descendants = SC_NO_DESCENDANTS );
void enable ( sc_descendant_i ncl usi on_i nf o include_descendants = SC_NO_DESCENDANTS );
void kill ( sc_descendant_i ncl usi on_i nf o include_descendants = SC_NO_DESCENDANTS );
void reset ( sc_descendant_i ncl usi on_i nf o include_descendants = SC_NO_DESCENDANTS );
bool is_unwinding() const;
const sc_event& reset_event() const;
void sync_reset_on
( sc_descendant_i ncl usi on_i nf o include_descendants = SC_NO_DESCENDANTS );
void sync_reset_off
( sc_descendant_i ncl usi on_i nf o include_descendants = SC_NO_DESCENDANTS );
templ ate <typename T>
void throw_it( const T& user_defi ned_excepti on,
sc_descendant_inclusion_info include_descendants = SC_NO_DESCENDANTS );
} ;
sc_process_handle sc_get_current_process_handle();
bool sc_is_unwinding();
} // namespace sc_core
5.6.3 Constraints on usage
None. A process handl e may be created, copi ed, or del eted at any time during el aborati on or simulation. The
handl e may be vali d or i nval id.
5.6.4 Constructors
sc_process_handle();
The default constructor shall create an empty process handle. An empty process handle shall be an
invali d process handl e.
sc_process_handle( const sc_process_handl e& );
The copy constructor shall dupl icate the process handl e passed as an argument. The resul t wil l be
two handl es to the same underlyi ng process instance or two empty handl es.
expl icit sc_process_handle( sc_obj ect* );
I f the argument is a poi nter to a process i nstance, this constructor shall create a val id process handle
to the given process instance. Otherwi se, thi s constructor shal l create an empty process handle.
5.6.5 Member functions
bool valid() const;
Member f uncti on valid shall return trueif and only if the process handl e i s vali d.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


70
Copyright 2012 IEEE. All rights reserved.
sc_process_handle& operator= ( const sc_process_handl e& );
The assignment operator shal l dupl icate the process handle passed as an argument. The resul t wil l be
two handl es to the same underlyi ng process instance or two empty handl es.
bool operator== ( const sc_process_handl e& ) const;
The equali ty operator shal l return truei f and onl y if the two processhandles are both vali d and share
the same underlying process i nstance.
bool operator!= ( const sc_process_handl e& ) const;
The inequali ty operator shal l return false i f and onl y i f the two process handles are both vali d and
share the same underlying process instance.
bool operator< ( const sc_process_handl e& ) const;
The l ess-than operator shall def ine a str i ct weak or der i ng relation on the underl ying process
instances in the fol lowing sense. Gi ven three process handles H1, H2, and H3:
str i ct means that H1 < H1 shall return false(whether H1 i s vali d, i nvali d, or empty)
weak means that i f H1 and H2 are both handles (val id or i nval id) associated with the same
underlying process i nstance or both are empty handl es, then H1 < H2 shal l return falseand H2 < H1
shal l return false. Otherwise, if H1 and H2 are handl es associated wi th dif ferent underl ying process
instances or i f only one i s an empty handle, then exactly one of H1 < H2 and H2 < H1 shal l return
true.
orderi ng rel ati on means that i f H1 < H2 and H2 < H3, then H1 < H3 (whether H1, H2, or H3 are
val id or i nvali d).
Exampl e:
sc_process_handle a, b; // Two empty handles
sc_assert( !a.val id() && ! b.vali d() ); // Both are i nvali d
sc_assert( a != b );
sc_assert( ! (a < b) && ! (b < a) );

a = sc_spawn(...);
b = sc_spawn(...);
sc_assert( a != b );
sc_assert( (a < b) || (b < a) ); // Two handles to di ff erent processes

sc_process_handle c = b;
sc_assert( b == c );
sc_assert( ! (b < c) && ! (c < b) ); // Two handles to the same process
wait( a.terminated_event() & b.termi nated_event() );
sc_assert( (a < b) || (b < a) ); // Same orderi ng whether handl es are val id or not

if ( b.val id() ) // Handles may or may not have been inval idated
sc_assert( b == c );
else
sc_assert( b != c );
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


71
Copyright 2012 IEEE. All rights reserved.
sc_assert( b.val id() == c.vali d() ); // I nvali dation is consistent
sc_assert( ! (b < c) && ! (c < b) ); // Two handles to the same process, whether vali d or not
sc_assert( c.terminated() );
voi d swap( sc_process_handl e& );
Member f uncti on swap shall exchange the process i nstances underl ying the process handl es * this
and the sc_process_handleargument. I f H1 < H2 prior to the cal l H1.swap(H2), then H2 < H1 af ter
the cal l. Either handle may be invali d.
Exampl e:
sc_process_handle a, b = sc_get_current_process_handle();
sc_assert( b.val id() );

a.swap( b );
sc_assert( a == sc_get_current_process_handl e() );
sc_assert( ! b.vali d() );
const char* name() const;
Member function nameshal l return the hierarchi cal name of the underl yi ng process instance. I f the
process handle i s i nvali d, member f uncti on name shal l return an empty stri ng, that is, a pointer to
the string . The implementation is only obliged to keep the returned string valid while the process
handl e i s vali d.
sc_curr_proc_kind proc_kind() const;
For a vali d process handle, member f unction proc_kind shall return one of the three val ues
SC_METHOD_PROC_, SC_THREAD_PROC_, or SC_CTHREAD_PROC_, depending on the
kind of the underlying process i nstance, that i s, method process, thread process, or cl ocked thread
process, respectively. For an invali d process handle, member functi on proc_kind shall return the
val ue SC_NO_PROC_.
const std::vector<sc_object* >& get_child_objects() const;
Member f uncti on get_child_objectsshall return a std::vector containi ng a pointer to every i nstance
of cl ass sc_object that is a chil d of the underlying process i nstance. Thi s shall include every
dynami c process i nstance that has been spawned during the executi on of the underl ying process
instance and has not yet been deleted, and any other appl icati on-def ined objects deri ved from class
sc_object created during the execution of the underlyi ng process i nstance that have not yet been
del eted. Processes that are spawned f rom chil d processes are not included (grandchil dren, as i t
were). I f the process handle i s i nval id, member function get_child_objects shall return an empty
std::vector.
This same functi on shal l be overridden i n any impl ementation-defi ned classes deri ved from
sc_object and associ ated wi th spawned and unspawned process i nstances. Such functions shal l have
identi cal behavi or provided that the process handl e i s vali d.
const std::vector<sc_event* >& get_child_events() const;
Member functi on get_child_eventsshall return a std::vector contai ni ng a poi nter to every object of
type sc_event that is a hierarchi cal ly named event and whose parent is the current process instance.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


72
Copyright 2012 IEEE. All rights reserved.
I f the process handle i s i nvali d, member functi on get_child_events shal l return an empty
std::vector.
This same functi on shal l be overridden i n any impl ementation-defi ned classes deri ved from
sc_object and associ ated wi th spawned and unspawned process i nstances. Such functions shal l have
identi cal behavi or provided that the process handl e i s vali d.
sc_object* get_parent_object() const;
Member functi on get_parent_object shall return a pointer to the modul e i nstance or process
instance from whi ch the underlyi ng process i nstance was spawned. I f the process handle i s invali d,
member function get_parent_object shall return the nul l poi nter. If the parent object i s a process
instance and that process has termi nated, get_parent_object shall return a pointer to that process
instance. A process i nstance shal l not be del eted (nor any associated process handles i nvali dated)
whil e the process has surviving chi ldren, but it may be deleted once all i ts chi ld objects have been
del eted.
sc_object* get_process_object() const;
I f the process handl e is vali d, member function get_process_object shall return a poi nter to the
process i nstance associ ated with the process handle. I f the process handle i s invali d, member
f uncti on get_process_object shall return the nul l poi nter. An appl icati on should test f or a null
pointer before dereferenci ng the poi nter. Moreover, an appl ication should assume that the poi nter
remains val id only until the call ing process suspends.
bool dynamic() const;
Member f unction dynamicshal l return truei f the underlying process instance is a dynamic process
and f alse i f the underlying process instance i s a stati c process. If the process handle is invali d,
member f uncti on dynamicshal l return the value false.
bool terminated() const;
Member f uncti on terminated shall return true if and onl y if the underlying process i nstance has
ter mi nated. A thread or clocked thread process i s ter mi nated af ter the point when control is returned
f rom the associ ated functi on. A process can al so be ter mi nated by call ing the kill method of a
process handl e associated wi th that process. This i s the only way i n which a method process can be
terminated. I f the process handle is empty, member functi on terminated shall return the val ue false.
When the underl ying process i nstance terminates, if the process instance has no surviving chi ldren,
an impl ementation may choose to i nvali date any associ ated process handles, but i t is not obl iged to
do so. An impl ementation shal l not i nvali date a process handl e whil e the process i nstance has child
objects. However, if an impl ementation chooses to invali date a process handl e, it shall inval idate
every process handle associated with the underlyi ng process i nstance at that time. I n other words, i t
shal l not be possi ble to have a vali d and an invali d handl e to the same underlyi ng process i nstance in
exi stence at the same time. Af ter the process instance has termi nated, f uncti on terminated wi ll
continue to return true, even i f the process handle becomes inval id. The process instance shal l
continue to exist as long as the process handl e is val id. Once al l the handles associ ated with a gi ven
process instance have been i nval idated, an impl ementation is f ree to del ete the process instance, but
it is not obli ged to do so. With respect to the value of functi on terminated and the ordering relati on
that def ines the behavior of operator< and method swap, in ef fect an inval id process handle
remai ns associ ated wi th a process i nstance even after that process instance has been del eted.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


73
Copyright 2012 IEEE. All rights reserved.
const sc_event& terminated_event() const;
Member functi on terminated_event shall return a reference to an event that i s noti fi ed when the
underlying process instance terminates. It shall be an error to cal l member function
terminated_event for an i nvali d process handl e.
5.6.6 Member functions for process control
The member f unctions of class sc_process_handledescri bed in this clause and its subcl auses are concerned
wi th process control . Exampl es of process control i nclude suspending, resumi ng, ki ll ing, or resetting a
process instance. Process control i nvolves a cal l i ng process control li ng a tar get process. I n each case, the
cal l i ng pr ocess cal ls a member f unction of a process handl e associated with the tar get pr ocess (or with i ts
parent obj ect, grandparent obj ect, and so f orth).
The call ing process and the target process may be disti nct process i nstances or may be the same process
instance. In the l atter case, certai n process control member f uncti ons are meaningless, such as havi ng a
process i nstance attempt to resume itsel f.
Several of the process control member functions are organized as complementary pai rs:
suspend and resume
disableand enable
sync_reset_on and sync_reset_off
kill
reset
throw_it
Each of the above member f uncti ons may be call ed where the underlying process instance is a method
process, a thread process, or a clocked thread process. There are certain caveats concerni ng the use of
suspend, resume, reset, and throw_it with cl ocked thread processes (see 5.2.12).
The disti nction between suspend/resume and disable/enable lies i n the sensi tivi ty of the target process
during the peri od while it is suspended or di sabled. Wi th suspend, the kernel keeps track of the sensitivity of
the target process whil e i t is suspended such that a rel evant event noti fi cation or time-out whi le suspended
would cause the process to become runnable immediatel y when resume is call ed. Wi th disable, the
sensitivity of the target process i s nul li fied whi le i t is suspended such that the process is not made runnable
by the call to enable, but only on the next relevant event notif icati on or ti me-out subsequent to the call to
enable. I n other words, with suspend/resume, the kernel keeps a record of whether the target process woul d
have awoken whi le i n f act being suspended, whereas with disable/enable, the kernel entirely i gnores the
sensitivity of the target process while disabled. Also see 5.2.12 regardi ng clocked thread processes.
Exampl e:
struct M1: sc_module
{
M1(sc_modul e_name _name)
{
SC_THREAD(ticker);
SC_THREAD(call ing);
SC_THREAD(target);
t = sc_get_current_process_handle();
}

sc_process_handle t;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


74
Copyright 2012 IEEE. All rights reserved.
sc_event ev;
void ti cker()
{
for (;;)
{
wait(10, SC_NS);
ev.noti fy();
}
}
void cal ling()
{
wait(15, SC_NS);
// Target runs at ti me 10 NS due to noti fi cati on
t.suspend();
wait(10, SC_NS);
// Target does not run at ti me 20 NS whil e suspended

t.resume();
// Target runs at ti me 25 NS when resume is call ed

wait(10, SC_NS);
// Target runs at ti me 30 NS due to noti fi cati on

t.di sable();
wait(10, SC_NS);
// Target does not run at ti me 40 NS whil e di sabled

t.enabl e();
// Target does not run at ti me 45 NS when enabl e i s call ed

wait(10, SC_NS);
// Target runs at ti me 50 NS due to noti fi cati on

sc_stop();
}
void target()
{
for (;;)
{
wait(ev);
cout << "Target awoke at " << sc_time_stamp() << endl;
}
}

SC_HAS_PROCESS(M1);
} ;
sync_reset_on and sync_reset_off provi de a procedural way of putti ng a process instance into and out of
the synchronous r eset state (see 5.6.6.3). Thi s i s equivalent i n eff ect to having specif ied a reset signal usi ng
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


75
Copyright 2012 IEEE. All rights reserved.
the member f unction reset_signal_is of cl ass sc_module or sc_spawn_options and that reset signal
attai ning i ts active val ue or the negation of its active val ue, respecti vel y.
Exampl e:
struct M2: sc_module
{
M2(sc_modul e_name _name)
{
SC_THREAD(ticker);
SC_THREAD(call ing);
SC_THREAD(target);
t = sc_get_current_process_handle();
}

sc_process_handle t;
sc_event ev;
void ti cker()
{
for (;;)
{
wait(10, SC_NS);
ev.noti fy();
}
}

void cal ling()
{
wait(15, SC_NS);
// Target runs at ti me 10 NS due to noti fi cati on

t.sync_reset_on();
// Target does not run at ti me 15 NS

wait(10, SC_NS);
// Target is reset at time 20 NS due to noti ficati on

wait(10, SC_NS);
// Target is reset again at ti me 30 NS due to notif ication

t.sync_reset_off ();
// Target does not run at ti me 35 NS

wait(10, SC_NS);
// Target runs at ti me 40 NS due to noti fi cati on

sc_stop();
}
void target()
{
cout << "Target call ed/reset at " << sc_ti me_stamp() << endl ;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


76
Copyright 2012 IEEE. All rights reserved.
for (;;)
{
wait(ev);
cout << "Target awoke at " << sc_time_stamp() << endl;
}
}

SC_HAS_PROCESS(M2);
} ;
kill interrupts and i rrevocably terminates the target process. reset interrupts the target process and, in the
case of a thread process, cal ls the associated function again from the top. kill and reset both cause an
excepti on to be thrown wi thi n the target process, and that exception may be caught and handled by the
appl icati on. Both have i mmediate semanti cs such that the target process is kil led or reset before return f rom
the functi on cal l.
Exampl e:
struct M3: sc_module
{
M3(sc_modul e_name _name)
{
SC_THREAD(ticker);
SC_THREAD(call ing);
SC_THREAD(target);
t = sc_get_current_process_handle();
}

sc_process_handle t;
sc_event ev;
int count;
void ti cker()
{
for (;;)
{
wait(10, SC_NS);
ev.noti fy();
}
}

void cal ling()
{
wait(15, SC_NS);
// Target runs at ti me 10 NS due to noti fi cati on
sc_assert( count == 1 );

wait(10, SC_NS);
// Target runs again at ti me 20 NSdue to notif ication
sc_assert( count == 2 );

t.reset();
// Target reset immedi atel y at ti me 25 NS
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


77
Copyright 2012 IEEE. All rights reserved.
sc_assert( count == 0 );

wait(10, SC_NS);
// Target runs again at ti me 30 NSdue to notif ication
sc_assert( count == 1 );

t.ki ll();
// Target kil led i mmediatel y at time 35 NS
sc_assert( t.termi nated() );

sc_stop();
}
void target()
{
cout << "Target call ed/reset at " << sc_ti me_stamp() << endl ;
count = 0;
for (;;)
{
wait(ev);
cout << "Target awoke at " << sc_time_stamp() << endl;
++count;
}
}

SC_HAS_PROCESS(M3);
} ;
A process may be reset i n several ways: by a synchronous or asynchronous reset si gnal specif ied using
reset_signal_isor async_reset_signal_is, respecti vel y (see 5.2.13), by cal li ng sync_reset_on, or by cal li ng
reset. Whichever al ternati ve i s used, the reset acti on i tself is ul ti mately equi val ent to a call to reset.
throw_it permi ts a user-defi ned exception to be thrown withi n the target process.
For each of the nine member f uncti ons f or process control described in thi s cl ause and its subcl auses, i f the
process handle is invali d, the i mplementati on shal l generate a warni ng and the member f uncti on shal l return
immedi ately without having any other ef fect.
I n thi s cl ause, the phrase duri ng el abor ati on or befor e the pr ocess has fi r st executed shall encompass the
f ol lowi ng cases:
At any time during elaboration
From one of the callbacks before_end_of_elaboration, end_of_elaboration, or
start_of_simulation
During simulation but before the given process i nstance has executed for the f irst ti me
I n each case, i f the include_descendantsargument has the value SC_INCLUDE_DESCENDANTS, the
member f unction shall be appli ed to the associated process instance and recursively in bottom-up order to
all its chil dren in the object hierarchy that are also process instances, where each process i nstance shall in
turn act as the target process. I n other words, the member functi on shall be appl ied to the chi ldren,
grandchi ldren, great grandchi ldren, and so f orth, of the associated process instance, starti ng with the
deepest descendant, and fi ni shi ng wi th the associ ated process instance itsel f. If the include_descendants
argument has the val ue SC_NO_DESCENDANTS, the member f unction shall only be appli ed to the
associ ated process instance. There are no restricti ons concerni ng how this argument may be used across
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


78
Copyright 2012 IEEE. All rights reserved.
pai rs of cal ls to suspend-resume, disable-enable, or sync_reset_on-sync_reset_off. For example, it is
permi tted to suspend a process and al l of i ts descendants but only resume the process itself .
The member f unctions f or process control shal l not be call ed duri ng the update phase.
Beware that the rul es gi ven in the f ol lowi ng subclauses are to be understood al ongside the rules gi ven i n
5.6.6.11 concerni ng the i nteracti on between the member f uncti ons for process control , whi ch shal l take
precedence where appropriate.
5.6.6.1 suspend and resume
void suspend( sc_descendant_i ncl usi on_inf o i ncl ude_descendants = SC_NO_DESCENDANTS );
Member function suspend shal l suspend the target process instance such that it cannot be made
runnabl e agai n unti l it i s resumed by a cal l to member function resume, at the earliest (but see
5.6.6.11 for the rul es concerni ng reset). If the process instance i s i n the set of runnable processes, it
shal l be removed from that set immedi ately such that i t does not run in the current eval uation phase.
Whi le the process is suspended in this way, i f an event notif ication or time-out occurs to which the
process was sensi ti ve at the time the process was suspended, and i f resumeis call ed subsequently,
the process instance shal l become runnable in the evaluation phase i n which resume is call ed. In
other words, the impl ementation shall in eff ect add an i mplici t event to the sensitivity of the process
instance usi ng the event_and_l i st operator&, and shal l create an i mmediate notif ication f or this
event when resumeis cal led.
Call ing suspend on a process instance that i s al ready suspended shall have no eff ect on that
parti cul ar process instance, although i t may cause descendants to be suspended. Only a single call to
resumeis required to resume a suspended process instance.
I f a method process suspends itsel f, the associated function shal l run to the end bef ore returning
control to the kernel. If that same method process call s the resumemethod before returni ng control
to the kernel, the ef f ect of the call to suspendshall be removed as if suspend had not been cal led.
I f a thread process suspends itself , the process instance shall be suspended immedi atel y wi thout
control being returned f rom the suspend method back to the associ ated f unction.
I f suspend i s call ed f or a target process instance that is not suspended (meaning that suspend has
not been cal led) and i s in the synchronous reset state, the behavi or shal l be i mpl ementation-defi ned
(see 5.6.6.11).
Call ing suspend on a termi nated process i nstance shal l have no ef fect on that parti cul ar process
instance, although i t may cause the suspension of any non-termi nated descendant process i nstances.
Call ing suspend during el aborati on or bef ore the process has fi rst executed i s permitted. I f
dont_initializei s i n force, the implementation shal l i n eff ect add an impl icit event to the sensi ti vity
of the process i nstance using the event_and_l i st operator&, and shal l create an immedi ate
noti fi cati on for thi s event when resume i s cal led. Otherwise, the implementati on shall make the
process instance runnabl e immediatel y when resumeis cal led, in eff ect def erri ng initiali zation until
the process i nstance is resumed.
void resume( sc_descendant_i ncl usi on_inf o i ncl ude_descendants = SC_NO_DESCENDANTS);
Member functi on resume shall remove the ef fect of any previous cal l to suspend such that the
process instance shal l be made runnable i n the current eval uation phase if and only i f the sensi ti vi ty
of the process instance would have caused i t to become runnable whil e i t was in fact suspended. I f
the process i nstance was in the set of runnabl e processes at the time is was suspended, member
f uncti on resume shall cause the process i nstance to be made runnable in the current eval uati on
phase (but see 5.6.6.11 f or the rul es concerni ng the i nteraction between process control member
f uncti ons). I f the process i nstance was not i n the set of runnabl e processes at the ti me i t was
suspended and if there were no event notif ications or ti me-outs that woul d have caused the process
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


79
Copyright 2012 IEEE. All rights reserved.
instance to become runnable while it was i n f act suspended, member f uncti on resume shall not
make the target process i nstance runnable.
Member f uncti on resume shall restore the sensitivi ty of the target process as it was when suspend
was call ed.
I f a resumeis preceded by a reset, any event notif ications or time-outs that occurred before the ti me
of the reset shall be i gnored when determini ng the eff ect of resume.
A thread process shall be resumed f rom the executabl e statement foll owing the call to suspend. A
method process shall be resumed by cal li ng the associ ated f uncti on.
Call ing resumeon a process instance that i s not suspended shal l have no eff ect on that particul ar
process i nstance, al though it may cause suspended descendants to be resumed. As a consequence,
multipl e cal ls to resumefrom the same or from mul ti pl e processes wi thin the same eval uation phase
may cause the target process to run only once or to run more than once wi thin that eval uation phase,
depending on the precise order of process executi on.
I f mul ti pl e target processes become runnable within an evaluati on phase as a result of multipl e call s
to resume, they wil l be run i n an implementation-def ined order (see 4.2.1.2).
I f resume is cal led for a target process instance that i s both suspended (meaning that suspend has
been cal led) and disabl ed, the behavior shall be i mplementati on-def ined (see 5.6.6.11).
Call ing resume on a terminated process i nstance shall have no eff ect on that parti cular process
instance, although i t may cause any non-termi nated descendant process i nstances to be resumed.
Call ing resume during el aboration or bef ore the process has fi rst executed is permitted, in which
case the above rul es shal l appl y.
The function associated with any process instance can cal l suspend or resume: there i s no
obli gati on that a process instance be suspended and resumed by the same process instance.
5.6.6.2 disable and enable
void disable( sc_descendant_i ncl usi on_inf o i ncl ude_descendants = SC_NO_DESCENDANTS );
Member functi on disable shall disable the target process i nstance such that it cannot be made
runnabl e again unti l it is enabled by a cal l to member function enable, at the earli est. I f the di sabled
process instance is in the set of runnabl e processes, it shall not be removed from that set but shall be
all owed to run in the current eval uation phase. Whi le a process instance is disabl ed i n this way, any
events or time-outs to whi ch it is sensitive shal l be ignored f or that particular process i nstance such
that it wil l not be i nserted into the set of runnable processes. As a consequence of thi s rule, a
disabl ed process instance may run once and onl y once whil e it remai ns disabl ed, and then only if it
was already runnabl e at the time it was disabl ed.
Call ing disableon a process instance that is al ready di sabled shall have no ef f ect on that particular
process instance, al though i t may cause descendants to be disabl ed. Only a single call to enableis
required to enabl e a disabl ed process instance.
I f a process di sabl es i tself , whether it be a method process or a thread process the associated f uncti on
shal l conti nue to run to the poi nt where i t cal ls wait or to the end before returni ng control to the
kernel. If that same process calls the enablemethod before returning control to the kernel, the eff ect
of the cal l to disableshall be removed as if disablehad not been called.
I f disablei s cal led f or a target process instance that i s not di sabled and is waiting on a ti me-out (with
or wi thout an event or event l ist), the behavi or shall be i mplementati on-def ined (see 5.6.6.11).
Call ing disable on a termi nated process instance shall have no ef fect on that parti cul ar process
instance, although i t may cause any non-termi nated descendant process i nstances to be di sabled.
Call ing disable during el aboration or bef ore the process has f irst executed is permitted: i f the
process is already in the set of runnabl e processes at the time disablei s call ed, duri ng i nitiali zation,
f or example, i t shall be all owed to run.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


80
Copyright 2012 IEEE. All rights reserved.
void enable( sc_descendant_i ncl usi on_i nf o include_descendants = SC_NO_DESCENDANTS );
Member f unction enable shal l remove the ef fect of any previous disable such that the process
instance can be made runnabl e by subsequent event noti fi cations or time-outs. Unli ke resume, an
enabled process shal l not become runnabl e due to event noti fi cation or ti me-outs that occurred whil e
it was disabled.
I f a ti me-out occurs whi le a process instance is disabled and that process i nstance is sensi ti ve to no
other events aside f rom the time-out itself , the process instance wi ll not run again (unl ess it is reset)
and the impl ementation may issue a warni ng.
When the enabled process instance next executes, if i t is a wai ti ng thread process it shal l execute
from the statement foll owing the call to wait at which i t was di sabl ed, and i f a method process i t
shal l execute by cal li ng the associ ated f unction.
Call ing enable on a process i nstance that is not di sabled shall have no eff ect on that particular
process i nstance, al though it may cause di sabl ed descendants to be enabled.
Call ing enable on a terminated process i nstance shall have no ef fect on that parti cul ar process
instance, although i t may cause any non-termi nated descendant process i nstances to be enabled.
Call ing enableduring elaborati on or before the process has f irst executed is permitted, in which case
the above rules shall apply.
I f disable is cal led duri ng el aboration and enable is onl y call ed after the initial ization phase, the
target process i nstance shal l not become runnabl e during the initiali zation phase, and shall not
become runnabl e when enableis cal led.
The functi on associated wi th any process instance can cal l disableor enable: there i s no obl igati on
that a process instance be disabl ed and enabl ed by the same process i nstance.
5.6.6.3 Member functions to reset processes
A process instance can be reset in one of three ways:
By a call to member function reset of a process handle associated wi th that process i nstance, which
shal l reset the target process i nstance i mmediatel y
By a reset signal specified using async_reset_signal_isattaining i ts reset value, at which ti me the
process instance shall be reset immedi ately (see 5.2.13)
By the process instance being resumed while it is in the synchronous r eset state, def ined as foll ows:
A process instance can be put into the synchronous r eset state in one of three ways:
By a call to member function sync_reset_on of a process handle associated with that process
instance
When any reset signal specified using reset_signal_is for that process instance attains its active
val ue
When any reset signal specified using async_reset_signal_is for that process i nstance attai ns its
active val ue
A process instance can onl y leave the synchronous reset state when all of the fol lowi ng appl y:
Member function sync_reset_off i s cal led or member functi on sync_reset_on has not yet been
cal led for a process handle associ ated with that process i nstance
Every reset signal specified using reset_signal_is for that process i nstance has the negati on of i ts
active val ue
Every reset signal specified using async_reset_signal_isf or that process i nstance has the negation
of i ts acti ve value
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


81
Copyright 2012 IEEE. All rights reserved.
I n each case, any resultant reset shal l be equi val ent to a call to member function reset, and hence, the event
returned by member function reset_event shall be noti fi ed.
Any given process i nstance can have mul tipl e resets specif ied usi ng reset_signal_is and
async_reset_signal_isi n addition to being the target of call s to member f uncti ons reset and sync_reset_on
of an associated process handle.
5.6.6.4 kill
void kill( sc_descendant_i ncl usi on_i nf o include_descendants = SC_NO_DESCENDANTS );
Member functi on kill shall kil l the target process i nstance such that an sc_unwind_exception shall
be thrown (see 5.6.6.6) for the ki lled process instance and the kill ed process instance shall not be
made runnable again duri ng the current si mulati on. A ki ll ed process shal l be termi nated.
I n the case of an exception thrown for a ki ll , member f unction is_reset of cl ass
sc_unwind_exceptionshall return the value false.
kill shal l have i mmediate eff ect; that is, the kil led process i nstance shall be removed f rom the set of
runnabl e processes, the cal l stack unwound, the process i nstance put into the termi nated state, and
the terminated event noti fi ed before the return from the kill functi on. Calls to kill can have side-
eff ects. I f a process kil ls another process, control shall return to the f uncti on that call ed kill. If a
process kil ls i tsel f, the statements fol lowi ng the cal l to kill shal l not be executed agai n during the
current si mulati on, and control shall return to the kernel .
Call ing kill on a terminated process instance shall have no eff ect on that particular process i nstance,
although it may cause any non-termi nated descendant process i nstances to be ki ll ed.
Call ing kill before the process has fi rst executed is permi tted, i n whi ch case the target process
instance shal l not be run during the current si mulati on.
I t shall be an error to call kill during el aboration, before the initial ization phase, or while the
simul ation is paused or stopped.
5.6.6.5 reset
void reset( sc_descendant_i ncl usi on_i nf o incl ude_descendants = SC_NO_DESCENDANTS);
Member f unction reset shal l reset the target process i nstance such that the process shall be removed
f rom the set of runnable processes, an sc_unwind_exception shal l be thrown f or the process
instance, any dynami c sensitivity associated with the process removed, and the static sensi ti vi ty
restored. The target process shal l not be termi nated. The process handl e shal l remain vali d. The
associ ated functi on shal l then be cal led agai n and, as a consequence, wi ll execute until it cal ls wait,
suspends itself , or returns.
reset shall have immedi ate ef fect; that i s, the target process i nstance shal l be removed f rom the set
of runnabl e processes, the cal l stack unwound, and the reset event notifi ed bef ore the return from the
reset function. Calls to reset can have si de-eff ects. In parti cular, care should be taken to avoi d
mutual recursi on between processes that reset one another. sc_unwind_exception may be caught
provided it i s i mmediatel y re-thrown.
I n the case of an sc_unwind_exception thrown for a reset, member f uncti on is_reset of cl ass
sc_unwind_exceptionshall return the value true.
A method process may be reset, although the associated function wil l not have a call stack to be
unwound except i n the case where a method process resets itself . When a method process is reset,
any dynamic sensitivity associ ated wi th the process shal l be removed, the static sensi ti vity restored,
and the associ ated f unction cal led again.
A thread or a method process i nstance may reset i tsel f (by a cal l to the reset method of an associated
process handle), i n whi ch case the call stack shal l be unwound i mmedi ately.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


82
Copyright 2012 IEEE. All rights reserved.
Call ing reset on a termi nated process i nstance shal l have no ef f ect on that particular process
instance, although i t may cause any non-termi nated descendant process i nstances to be reset.
Call ing reset bef ore the process has fi rst executed i s permitted, but i t shall have no eff ect other than
to noti fy the event returned by reset_event.
I t shall be an error to cal l reset duri ng elaborati on, bef ore the initiali zation phase, or whil e the
simul ation is paused or stopped.
5.6.6.6 Class sc_unwind_exception
Cl ass sc_unwind_exceptionis the type of the exception thrown by member functions kill and reset.
I n the case of a thread process suspended by a cal l to wait, or a thread or method process that ki ll s or resets
itsel f, the sc_unwind_exception shall cause the cal l stack of the associated function to be unwound and any
local objects to have thei r destructors call ed. I n the case of a method process, the associ ated f uncti on does
not have a call stack to be unwound unless the process ki lls or resets i tself , but a cal l to kill shall cause the
method process to be terminated nonetheless.
As a process i s being ki ll ed or reset, the unwinding of the call stack may have si de-ef fects, incl udi ng call s to
destructors f or local objects. Such side-eff ects shall not incl ude call s to wait or next_trigger, but they may
include call s to process control member functions f or other process i nstances, i ncl udi ng the call ing process
itsel f. In other words, calls to kill or reset can be nested (as can calls to throw_it, as descri bed in 5.6.6.10).
(The def aul t actions of the SystemC report handler f oll owing an error include the SC_THROW acti on,
which by def aul t throws an exception. An impl ementation i s obl iged to catch the sc_unwind_exception
bef ore havi ng the sc_report_handler throw another excepti on.)
The target process is permi tted to catch the sc_unwind_exception withi n i ts associated f unction body, in
which case i t shall re-throw the exception such that the impl ementation can properly execute the kil l or reset.
It shall be an error f or an appl ication to catch the sc_unwind_exception without re-throwi ng i t.
The catch block i n the target process shal l execute in the context of the target process, not the call ing
process. As a consequence, the f uncti on sc_get_current_process_handleshal l return a handle to the target
process instance when cal led from the catch bl ock.
virtual const char* what() const;
Member f uncti on what shall return an impl ementation-defi ned string descri bi ng the excepti on.
virtual bool is_reset() const;
Member f unction is_reset shal l return the val ue trueif the excepti on i s thrown by reset and falsei f
the exception is thrown by kill.
sc_unwind_exception();
sc_unwind_exception( const sc_unwi nd_excepti on& );
virtual ~sc_unwind_exception();
This exception shal l onl y be thrown by the kernel . Hence, the constructors and destructor shal l be
protected members.
Exampl e:
SC_MODULE(m)
{
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


83
Copyright 2012 IEEE. All rights reserved.
SC_CTOR(m)
{
SC_THREAD(run);
}
void run()
{
try {
...
}
catch (const sc_unwind_exception& ex) {
// Perform clean-up
if (ex.is_reset())
...
else
...
throw ex;
}
}
...
} ;
5.6.6.7 is_unwinding
bool is_unwinding() const;
Member f unction is_unwindingshal l return the val ue true f rom the point when the kernel throws
an sc_unwind_exceptionto the poi nt when the kernel catches that same sc_unwind_exception, and
otherwi se shall return the value false. Hence, is_unwindingshall return truewhen call ed duri ng the
unwinding of the cal l stack fol lowing a call to kill or reset, but not f ollowi ng a call to throw_it. The
intent is that this member f uncti on can be call ed f rom the destructor of a local object defi ned wi thi n
the function associ ated wi th a process i nstance, where it can be used to diff erenti ate between the
case where a process is ki ll ed or reset and the end of simul ation.
I f call ed for an invalid process handle, the impl ementation shal l generate a warning and
is_unwindingshall return the value false.
There also exists a non-member f uncti on that cal ls is_unwindingf or the currently executing process
(see 5.6.8).
5.6.6.8 reset_event
const sc_event& reset_event() const;
Member functi on reset_event shall return a ref erence to an event that is notif ied whenever the target
process instance i s reset, whether that be through an expl icit cal l to member f uncti on reset, through
a process instance being resumed whi le i t is in the synchronous reset state, or through a reset signal
attai ning i ts acti ve value. The reset event shal l be schedul ed usi ng an i mmediate notif ication in the
eval uation phase i n which the expli cit or implici t cal l to reset occurs. I t shal l be an error to call
member f uncti on reset_event for an i nvali d process handle.
5.6.6.9 sync_reset_on and sync_reset_off
void sync_reset_on( sc_descendant_i ncl usion_inf o i ncl ude_descendants = SC_NO_DESCENDANTS );
void sync_reset_off( sc_descendant_i ncl usi on_inf o include_descendants = SC_NO_DESCENDANTS );
Member f unction sync_reset_on shal l cause the target process instance to enter the synchronous
r eset state. Whi le i n the synchronous reset state, a process instance shall be reset each ti me it is
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


84
Copyright 2012 IEEE. All rights reserved.
resumed, whether due to an event noti f ication or to a ti me-out. The call to sync_reset_on shall not
itsel f cause the process to be reset immedi atel y; the process shal l onl y be reset each ti me it is
subsequentl y resumed. Being reset in this sense shal l have the same ef fect as woul d a cal l to the
reset method, as descri bed above.
Member f uncti on sync_reset_off shall cause the target process instance to leave the synchronous
r eset state (unl ess any reset signal specif ied using reset_signal_isor async_reset_signal_isfor that
process i nstance has i ts acti ve val ue), thereby reversing the ef f ect of any previ ous call to
sync_reset_on for that process i nstance. sync_reset_off shall not modif y the eff ect of any reset
signal and shal l not modif y the ef f ect of any expli cit call to the reset method.
As a consequence of the above rul es, if a cal l to sync_reset_on is f ollowed by a call to
sync_reset_off bef ore a parti cul ar process i nstance has been resumed, that process i nstance cannot
have been reset due to the sync_reset_on cal l, although it may have been reset due to the ef fect of a
reset si gnal (specif ied using reset_signal_isor async_reset_signal_is) or a cal l to the reset method.
I t is permi ssibl e to cal l sync_reset_on and sync_reset_off wi th the include_descendantsargument
havi ng the val ue SC_INCLUDE_DESCENDANTSand where the descendants are a mixture of
method and thread processes; the appropri ate action shall be taken for each descendant process
instance accordi ng to whether i t i s a method process or a thread process.
Call ing sync_reset_on for a process instance that is al ready i n the synchronous reset state shal l have
no ef fect on that parti cul ar process i nstance, although it may cause descendants to enter the
synchronous reset state. Only a si ngl e cal l to sync_reset_off is required for a particular process
instance to l eave the synchronous reset state (assuming there is no reset signal active).
Call ing sync_reset_off f or a process instance that i s not currently i n the synchronous reset state shal l
have no eff ect on that particular process i nstance, although i t may cause descendants to l eave the
synchronous reset state.
A process instance may call sync_reset_on or sync_reset_off wi th itself as the target. As a
consequence of the above rules, the eff ect of the call will onl y be visible the next time the process
instance i s resumed.
I f sync_reset_on i s call ed f or a target process i nstance that i s not in the synchronous reset state and
is suspended (meaning that suspendhas been call ed), the behavi or shal l be impl ementation-defi ned
(see 5.6.6.11).
Call ing sync_reset_on or sync_reset_off for a termi nated process instance shal l have no ef fect on
that particul ar process i nstance, al though it may cause descendant process instances to enter or l eave
the synchronous reset state.
Call ing sync_reset_on or sync_reset_off during el aboration or bef ore the process has f irst executed
is permitted, i n which case the target process instance shall enter or l eave the synchronous reset state
accordi ngl y. Bei ng in the synchronous reset state shal l have no eff ect on the i nitiali zati on of a
process instance; that is, the process instance shal l be resumed during the f irst eval uati on phase and
shal l run up to the point where it either returns or calls wait. I f a process i nstance is sti ll in the
synchronous reset state when it i s f irst resumed (f rom a cal l to wait), then it shal l be reset as
descri bed above.
The f uncti on associated wi th any process i nstance can call sync_reset_on or sync_reset_off: there
is no obl igati on that sync_reset_on and sync_reset_off shoul d be cal led by the same process
instance.
5.6.6.10 throw_it
templ ate <typename T>
void throw_it( const T& user_defi ned_excepti on,
sc_descendant_inclusion_info include_descendants = SC_NO_DESCENDANTS);
Member functi on throw_it shall throw an excepti on wi thin the target process instance. The
excepti on to be thrown shall be passed as the f irst argument to f unction throw_it. The exception
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


85
Copyright 2012 IEEE. All rights reserved.
shal l be thrown in the context of the target process, not i n the context of the cal ler. Excepting the
special case where a process throws an exception to i tsel f, this shall require two context switches:
f rom the cal ler to the target process and from the target process back to the cal ler.
I t is recommended that the exception bei ng thrown shoul d be derived f rom class std::exception, but
an appli cati on may throw an excepti on not derived from cl ass std::exception.
Any dynamic sensitivi ty associated with the target process instance shall be removed and the stati c
sensitivity restored. The target process instance shal l not be termi nated by vi rtue of the f act that
throw_it was cal led, although a thread process may immedi atel y terminate i f control i s returned
f rom the associ ated f uncti on af ter the exception has been caught.
throw_it shall have immedi ate eff ect; that is, control shall be passed f rom the call er to the target
process and the excepti on thrown and caught bef ore the return from the throw_it f unction. Call s to
throw_it can have si de-ef f ects.
The target process i nstance shal l catch the exception i n its associ ated f uncti on. It shall be an error for
the target process i nstance not to catch the exception. Af ter catching the exception, the associated
f uncti on may return (and thus terminate i n the case of a thread process) or may call wait. I t shal l be
an error f or the target process to throw another exception whil e handli ng the f irst exception.
I f a process throws an exception to another process, control shall return to the f uncti on that cal led
throw_it. If a process throws an excepti on to itsel f, f uncti on throw_it does not return control to the
cal ler because its executi on i s i nterrupted by the exception, but control shal l pass to a catch block in
the functi on associ ated with the process.
The act of catching and handli ng the exception may have si de-ef fects, incl udi ng call s to destructors
f or l ocal obj ects. Such si de-ef f ects shall not i ncl ude call s to wait or next_trigger, but they may
include call s to process control member functi ons for other process i nstances, including the cal li ng
process itsel f. I n other words, call s to throw_it can be nested (as can cal ls to kill or reset, as
described i n 5.6.6.6).
throw_it is only appli cabl e when the target is a non-terminated thread process. Calls to throw_it
where the target process i nstance i s a method process or a termi nated process are permitted and shal l
have no eff ect except that an impl ementation may issue a warni ng. This shall i ncl ude the case where
a method process throws an exception to i tsel f. In parti cul ar, i t is permissible to call throw_it with
the include_descendantsargument having the value SC_INCLUDE_DESCENDANTSand where
the descendants are a mi xture of method and thread processes, some of whi ch may have terminated;
the appropri ate acti on shall be taken f or each descendant process i nstance. If the target process is a
non-terminated method process, that process shall not be terminated by the cal l to throw_it.
throw_it is only appl icabl e when the target process instance has been suspended duri ng executi on,
that i s, has cal led wait or has been the target of a call to suspend or disable. A call to throw_it in
any other context during si mulati on shall have no ef f ect except that an implementation may generate
a warning. In parti cul ar, a call to throw_it during si mulation before the target process has fi rst
executed shall have no ef f ect except to generate a warni ng.
I t shall be an error to cal l throw_it during elaborati on, bef ore the initiali zation phase, or whi le the
simul ation is paused or stopped.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


86
Copyright 2012 IEEE. All rights reserved.
5.6.6.11 Interactions between member functions for process control
I n Table 2, the phrase The curr ent eval uati on phase means that the ef fect on the target process becomes
visibl e duri ng the evaluation phase in which the process control member f uncti on i s call ed. For exampl e, a
cal l to suspend coul d remove the target process f rom the set of runnable processes, and an immedi ate
notif icati on fol lowing a call to enablecould cause the target process to run in the current eval uati on phase.
The next eval uati on phase implies that disable would not prevent the target process f rom running i n the
current eval uati on phase, but i t would prevent the target process f rom running i n the subsequent eval uation
phase. Immedi ate means that an exception i s thrown and any associ ated actions are completed in the target
process bef ore return to the call er.
As described above, member functi ons kill and reset each achi eve thei r eff ect by throwing an object of class
sc_unwind_exception, whi le member function throw_it throws an excepti on of a user-defi ned cl ass. Cal ls
to kill, reset, and throw_it may be nested such that a process catching an exception may kill or reset another
process instance or may throw an excepti on i n another process i nstance before i tself returni ng control to the
kernel . Si mil arly, the destructor of an object that i s going out-of-scope during stack unwi ndi ng (as a result of
an sc_unwind_exceptionhaving been thrown) may itself ki ll or reset another process instance or may throw
an excepti on in another process instance. It i s possibl e that such a chain of cal ls can get interrupted by a
process instance kil li ng or resetti ng itself , either directl y or indi rectly. For example, if a given process
instance attempts to kil l al l the descendants of i ts parent process wi th the call
handle.kill(SC_I NCLUDE_DESCENDANTS), the descendant process i nstances wi ll be kil led one-by-
one until the call ing process instance is reached, at which point the cal ler itsel f wil l be kil led and the cal l
stack unwound.
Care should be taken to avoi d mutual recursi on between processes that ki ll or reset one another, as such
mutual recursion can resul t i n stack overf low.
The rel ative priorities of the process control member functions are gi ven bel ow, ordered f rom highest
pri ority to lowest priority:
1) kill, reset, throw_it
2) disable, enable
3) suspend, resume
4) sync_reset_on, sync_reset_off
Table 2When process control member functions take effect
Member function Whenit takeseffect on thetarget processinstance
suspend The current eval uati on phase
resume The current eval uati on phase
disable The next eval uati on phase
enable The current eval uati on phase
kill I mmedi ate
reset I mmedi ate
throw_it I mmedi ate
sync_reset_on The current eval uati on phase
sync_reset_off The current eval uati on phase
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


87
Copyright 2012 IEEE. All rights reserved.
For each process i nstance, the impl ementation shall in ef fect maintai n three i ndependent fl ags to track the
state of call s to the member functions disable/enable, suspend/resume, and sync_reset_on/sync_reset_off,
and shal l then act accordi ng to the relati ve priority of those cal ls as l isted above. Each of these three f lags
shal l be set and cleared by call s to the correspondi ng pai r of member functions irrespecti ve of the val ues of
the remai ning two fl ags and i rrespective of the f act that certain i nteractions between the process control
member functions are impl ementation-defi ned. For exampl e, given two successive call s to resume with no
interveni ng call to suspend, the second cal l to resumewould have no eff ect, irrespecti ve of any intervening
cal ls to disableor enable.
Member functi ons kill, reset, and throw_it have i mmediate semantics that are executed immedi atel y even if
the target process instance is di sabled, suspended, or in the synchronous reset state. I n such a case, the target
process shal l remain di sabled, suspended, or i n the synchronous reset state after the immedi ate action has
been completed. For example, a call to throw_it where the target process was di sabled mi ght cause the
target process to wake up, catch the exception, call wait withi n i ts catch bl ock, and f inall y yield control back
to the kernel , all the whi le remaining in the disabl ed state.
The behavior of certai n i nteracti ons between the process control member f unctions shall be impl ementation-
def ined, as fol lows:
a) I f resumei s call ed for a target process i nstance that i s currently both suspended and disabl ed, the
behavior shall be impl ementation-defi ned (where suspended means suspend has been cal led and
disabl ed means disablehas been cal led).
b) I f sync_reset_on i s call ed or if a synchronous or asynchronous reset signal attains its active value
f or a target process i nstance that is currently both suspended and not in the synchronous reset state,
the behavior shal l be impl ementation-defi ned.
c) I f suspend i s cal led for a target process instance that is currentl y both in the synchronous reset state
(whether by means of a cal l to sync_reset_on or by means of a synchronous or asynchronous reset
signal having attai ned its acti ve value) and not suspended, the behavi or shall be i mplementati on-
def ined.
d) I f disable is called f or a target process i nstance that is currentl y both not disabl ed and wai ti ng on a
ti me-out (whether or not the ti me-out is accompanied by an event or an event l ist), the behavior shall
be i mplementati on-def ined.
If reset i s cal led whil e a target process instance i s suspended, reset shal l remove the dynami c sensitivity of
the target process such that any event noti fi cati on or time-out that occurred bef ore the time of the reset wi ll
be ignored when determini ng the behavi or of a subsequent cal l to resume f or that same target process. I n
other words, a reset shall wipe the sl ate cl ean when determi ni ng the behavior of resume.
I t shall be an error to cal l the three member f uncti ons with i mmediate semantics duri ng elaboration, before
the i ni ti al izati on phase, or whi le the simul ation i s paused or stopped, but the remai ni ng member functi ons
may be cal led whil e i n those states.
NOTEThe intent of making certain interactions between the process control member f uncti ons i mpl ementation-
def ined i s to shi el d the user from surprisi ng behavior whi le al so al l owi ng for more speci f i c semanti cs to be def i ned i n the
f uture as and when the use cases f or the process control member f uncti ons are cl ari f i ed.
Exampl e:
sc_process_handle h;
...
t.sync_reset_on(); // Target process put into the synchronous reset state
A(); // Bl ocking cal l
t.suspend(); // Target process suspended
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


88
Copyright 2012 IEEE. All rights reserved.
B(); // Blocking call
t.di sable(); // Target process disabl ed
C(); // Blocking call
t.reset(); // Target process immediatel y reset but sti ll di sabled
// Stati c sensitivi ty restored for target process
D(); // Blocking call
t.enabl e(); // Target process enabled but stil l suspended
E(); // Blocking call
t.di sable(); // Target process disabl ed
F(); // Blocking call
t.enabl e(); // Target process enabled but stil l suspended
G(); // Blocking call
t.resume(); // Target process resumed but sti ll i n the synchronous reset state
// Target process is made runnabl e i f sensitive to an event notifi ed by E or G
// Target process not made runnabl e i f sensitive to an event notif ied by A, B, C, D,
// or F
5.6.7 sc_get_current_process_handle
sc_process_handle sc_get_current_process_handle();
The val ue returned f rom functi on sc_get_current_process_handleshall depend on the context i n which i t is
cal led. When call ed during elaborati on from the body of a module constructor or from a f unction called f rom
the body of a module constructor, sc_get_current_process_handleshall return a handl e to the spawned or
unspawned process instance most recentl y created within that module, i f any. When cal led f rom one of the
cal lbacks before_end_of_elaboration or end_of_elaboration, sc_get_current_process_handle shall
return a handle to the spawned or unspawned process instance most recentl y created wi thin that specif ic
cal lback f uncti on, i f any. I f the most recently created process i nstance was not withi n the current modul e, or
in the case of before_end_of_elaboration or end_of_elaboration was not created within that speci fi c
cal lback, an implementati on may return either a handl e to the most recentl y created process instance or an
invali d handle. When call ed f rom sc_main duri ng elaborati on or from the cal lback start_of_simulation,
sc_get_current_process_handlemay return either a handle to the most recently created process instance or
an inval id handl e. When cal led during simul ation, sc_get_current_process_handleshal l return a handle to
the currently executing spawned or unspawned process i nstance, if any. I f there i s no such process instance,
sc_get_current_process_handle shall return an i nvali d handl e. When cal led from sc_main duri ng
simul ation, sc_get_current_process_handleshall return an invalid handl e.
Exampl e:
SC_MODULE(Mod)
{
...
SC_CTOR(Mod)
{
SC_METHOD(Run);
sensitive << i n;
sc_process_handle h1 = sc_get_current_process_handle(); // Returns a handl e to process Run
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


89
Copyright 2012 IEEE. All rights reserved.
}
void Run()
{
sc_process_handle h2 = sc_get_current_process_handle(); // Returns a handl e to process Run
if (h2.proc_ki nd() == SC_METHOD_PROC_)
... // Runni ng a method process
sc_object* parent = h2.get_parent_object(); // Returns a pointer to the
// modul e instance
if (parent)
{
handl e = sc_process_handle(parent); // Invalid handle - parent is not a process
if (handl e.vali d())
... // Executed if parent were a
// val id process
}
}
...
} ;
5.6.8 sc_is_unwinding
bool sc_is_unwinding();
Function sc_is_unwinding shall return the value returned f rom member function is_unwinding of the
process handle returned f rom sc_get_current_process_handle. In other words, sc_is_unwinding shal l
return trueif and only if the call er is currentl y the target process i nstance of a call to kill or reset.
Exampl e:
struct wai t_on_exit
{
~wai t_on_exi t() {
if ( ! sc_i s_unwinding() ) // needed, because we mi ght get ki ll ed
wait( 10, SC_NS ) ; // ... and this wai t would be ill egal
}
} ;
void some_module::some_process()
{
whil e( true )
{
try {
wait_on_exi t w; // local obj ect, destroyed before catch
// ...
} catch( const sc_unwi nd_excepti on& ) {
// some other cleanup
throw;
}
}
}
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


90
Copyright 2012 IEEE. All rights reserved.
5.7 sc_event_finder and sc_event_finder_t
5.7.1 Description
An event fi nder is a member function of a port class with a return type of sc_event_finder&. When a port
instance is bound to a channel instance contai ning mul ti ple events, an event fi nder permi ts a speci fi c event
f rom the channel to be retrieved through the port instance and added to the static sensi ti vi ty of a process
instance. sc_event_finder_t is a templ ated wrapper for class sc_event_finder, where the templ ate parame-
ter is the i nterf ace type of the port.
An event f inder f unction is cal led when creati ng stati c sensitivity to events through a port. Because port
binding may be deferred, it may not be possi bl e for the i mplementati on to retri eve an event to whi ch a pro-
cess is to be made sensitive at the ti me the process instance is created. Instead, an appl icati on shoul d call an
event fi nder f unction, in which case the i mplementati on shall defer the adding of events to the stati c sensitiv-
ity of the process until port binding has been completed. These def erred acti ons shal l be compl eted by the
impl ementation bef ore the call backs to f unction end_of_elaboration.
I f an event f inder f unction i s call ed for a mul ti port bound to more than one channel instance, the events f or
all such channel i nstances shall be added to the stati c sensitivi ty of the process.
5.7.2 Class definition
namespace sc_core {
class sc_event_finder i mpl ementati on-defi ned ;
templ ate <cl ass I F>
class sc_event_finder_t
: publi c sc_event_fi nder
{
publ ic:
sc_event_finder_t( const sc_port_base& port_, const sc_event& (I F::* event_method_) () const );
// Other members
i mpl ementati on-defi ned
} ;
} // namespace sc_core
5.7.3 Constraints on usage
An appl icati on shall onl y use class sc_event_finder as the return type (passed by ref erence) of a member
f uncti on of a port class, or as the base cl ass f or an appli cati on-specif ic event f inder class template that may
possess additional template parameters and event method parameters.
An appli cation shal l only use class sc_event_finder_t<interface> in constructi ng the obj ect returned f rom
an event fi nder.
An event fi nder shall have a return type of sc_event_finder& and shall return an obj ect of cl ass
sc_event_finder_t<interface> or an appli cation-specif ic event f inder class template, where:
a) i nter face shal l be the name of an interface to which said port can be bound, and
b) the fi rst argument passed to the constructor f or sai d object shal l be the port obj ect itself , and
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


91
Copyright 2012 IEEE. All rights reserved.
c) the second argument shall be the address of a member f uncti on of sai d interface. The event found by
the event f inder is the event returned by this functi on.
An event f inder member f uncti on may only be call ed when creati ng the stati c sensi ti vity of a process usi ng
operator<<, function set_sensitivity, or macro SC_CTHREAD. An event f inder member function shall
only be call ed during elaborati on, either f rom a constructor or f rom the before_end_of_elaboration call -
back. An event fi nder member f uncti on shall not be cal led from the end_of_elaboration callback or duri ng
simul ation. Instead, an appli cati on may make a process directly sensitive to an event.
I n the case of a mul ti port, an event f inder member f unction cannot f ind an event from an i ndi vidual channel
instance to which the multiport is bound using an index number. An appl icati on can work around this
restricti on by getti ng the events f rom the individual channel i nstances in the end_of_elaboration cal lback
after port bi ndi ng i s complete (see exampl e below).
Exampl e:
#include "systemc.h"
class if _cl ass
: vi rtual publi c sc_i nterf ace
{
publ ic:
virtual const sc_event& ev_f unc() const = 0;
...
} ;
class chan_cl ass
: publi c i f_class, publ ic sc_pri m_channel
{
publ ic:
virtual const sc_event& ev_f unc() const { return an_event; }
...
pri vate:
sc_event an_event;
} ;
templ ate<int N = 1>
class port_class
: publi c sc_port<if _cl ass,N>
{
publ ic:
sc_event_f inder& event_f inder() const
{
return * new sc_event_f inder_t<i f_class>( * this , & if _cl ass::ev_func );
}
...
} ;
SC_MODULE(mod_cl ass)
{
port_class<1> port_var;
port_class<0> mul ti port;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


92
Copyright 2012 IEEE. All rights reserved.
SC_CTOR(mod_class)
{
SC_METHOD(method);
sensitive << port_var.event_fi nder(); // Sensitive to chan_cl ass::an_event
}
void method();
...
void end_of_elaboration()
{
SC_METHOD(method2);
f or (i nt i = 0; i < multiport.si ze(); i ++)
sensitive << multiport[ i] ->ev_func(); // Sensi tive to chan_cl ass::an_event
}
void method2();
...
} ;
NOTEFor particular examples of event f i nders, ref er to the f uncti ons posand negof cl ass sc_in<bool> (see 6.9).
5.8 sc_event_and_list and sc_event_or_list
5.8.1 Description
The cl asses sc_event_and_list and sc_event_or_list are used to represent expli cit event l ist objects which
may be constructed and mani pul ated pri or to bei ng passed as arguments to the functions next_trigger (see
5.2.17) and wait (see 5.2.18). An event li st object shall store pointers or ref erences to zero or more event
objects. An event l ist may contain mul ti pl e references to the same event obj ect. The order of the events
wi thin the event l ist shall have no eff ect on the behavior of the event l ist when it i s used to create dynamic
sensitivity.
5.8.2 Class definition
namespace sc_core {
class sc_event_and_list
{
publ ic:
sc_event_and_list();
sc_event_and_list( const sc_event_and_l ist& );
sc_event_and_list( const sc_event& );
sc_event_and_l ist& operator= ( const sc_event_and_l ist& );
~sc_event_and_list();
int size() const;
void swap( sc_event_and_li st& );
sc_event_and_l ist& operator&= ( const sc_event& );
sc_event_and_l ist& operator&= ( const sc_event_and_l ist& );
sc_event_and_expr

operator& ( const sc_event& ) const;


sc_event_and_expr

operator& ( const sc_event_and_li st& ) const;


} ;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


93
Copyright 2012 IEEE. All rights reserved.
class sc_event_or _li st
{
publ ic:
sc_event_or _li st();
sc_event_or _li st( const sc_event_or_l ist& );
sc_event_or _li st( const sc_event& );
sc_event_or_l ist& oper ator = ( const sc_event_or_li st& );
~sc_event _or _li st ();
int size() const;
void swap( sc_event_or_li st& );
sc_event_or_l ist& oper ator |= ( const sc_event& );
sc_event_or_l ist& oper ator |= ( const sc_event_or_l ist& );
sc_event_or _expr

oper ator | ( const sc_event& ) const;


sc_event_or _expr

oper ator | ( const sc_event_or_li st& ) const;


} ;
} // namespacesc_core
5.8.3 Constraints and usage
The intended usage for obj ects of class sc_event_and_li st and sc_event _or _li st i sthat they are passed as
arguments to the functions wait and next_tr igger . Unl ike the case of event expressi on obj ects, whi ch are
del eted automaticall y by the implementation (see 5.9.3), the appl icati on shall be responsi bl e for del eting
event l ist objects whenthey areno longer required. Theappli cation shall beresponsi bl efor ensuring that an
event li st obj ect i sstil l val id (that i s, hasnot been destroyed) when aprocessinstanceresumesor i striggered
asadi rect result of thenoti ficati onof oneor moreeventsi n theevent li st. If theevent l ist object hasal ready
been destroyed at thi spoint, thebehavior of thei mplementati onshal l beundefi ned.
5.8.4 Constructors, destructor, assignment
sc_event _and_li st();
sc_event _or _li st();
Each defaul t constructor shal l construct an empty event li st obj ect. It shall be an error to pass an
empty event l ist object asan argument to thefunctionswait or next_tr igger .
sc_event _and_li st( const sc_event_and_l ist& );
sc_event _or _li st( const sc_event_or_l ist& );
sc_event_and_l ist& oper ator = ( const sc_event_and_li st& );
sc_event_or_l ist& oper ator = ( const sc_event_or_li st& );
Thecopy constructors and assi gnment operators shall permi t event l ist objectsto bei nitiali zed and
assignedby theappli cation.
sc_event _and_li st( const sc_event& );
sc_event _or _li st( const sc_event& );
These constructors shall construct event list obj ects contai ni ng the si ngl e event passed as an argu-
ment totheconstructor.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


94
Copyright 2012 IEEE. All rights reserved.
~sc_event_and_list();
~sc_event_or_list();
An event li st object may be constructed as a stack or as a heap vari abl e. In the case of the heap, the
appl icati on is responsibl e f or del eting an event l ist object when it i s no longer required.
5.8.5 Member functions and operators
int size() const;
Member f uncti on sizeshall return the number of events in the event l ist. Any dupli cate events in the
event l ist shal l not count toward the val ue of size.
Exampl e:
sc_event ev;
sc_event_or_l ist l ist = ev | ev;
sc_assert( l ist.size() == 1 );
void swap( sc_event_and_li st& );
void swap( sc_event_or_li st& );
Member functi on swapshall exchange the current event list object *thiswith the event li st passed as
an argument.
sc_event_and_l ist& operator&= ( const sc_event& );
sc_event_and_l ist& operator&= ( const sc_event_and_l ist& );
sc_event_and_expr

operator& ( const sc_event& ) const;


sc_event_and_expr

operator& ( const sc_event_and_li st& ) const;


sc_event_or_l ist& operator|= ( const sc_event& );
sc_event_or_l ist& operator|= ( const sc_event_or_l ist& );
sc_event_or _expr

operator| ( const sc_event& ) const;


sc_event_or _expr

operator| ( const sc_event_or_li st& ) const;


Each of these operators shal l append the event or event l ist passed as an argument to the current
event l ist obj ect *this, and shal l return the resultant el ongated event l ist as the val ue of the operator.
I n the case of the assi gnment operators &= and |=, the operator shal l return a reference to the current
object, which shal l have been modif ied to contain the el ongated event l ist. I n the case of the remai n-
ing operators & and |, the current object *thisshall not be modif ied.
Exampl e:
struct M: sc_module
{
sc_port<sc_si gnal_i n_i f<i nt>, 0> p; // Mul ti port

M(sc_module_name _name)
{
SC_THREAD(T);
}

sc_event_or_l ist all _events() const
{
sc_event_or_l ist or_l ist;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


95
Copyright 2012 IEEE. All rights reserved.
for (i nt i = 0; i < p.size(); i ++)
or_l ist |= p[i]->default_event();
return or_li st;
}

sc_event event1, event2;
...

void T()
{
for (;;)
{
wait( all _events() );
...
sc_event_and_l ist l ist;
sc_assert( l ist.size() == 0 );

li st = li st & event1;
sc_assert( l ist.size() == 1 );

li st &= event2;
sc_assert( l ist.size() == 2 );

wait(l ist);
sc_assert( l ist.size() == 2 );
...
}
}
SC_HAS_PROCESS(M);
} ;
5.9 sc_event_and_expr

and sc_event_or_expr

5.9.1 Description
Thecl assessc_event_and_expr

and sc_event_or _expr

provi dethe& and | operatorsused to construct the


event expressi onspassed as argumentsto thefunctions wait (see5.2.17) and next _tr igger (see5.2.18). An
event expressi on object shal l storepointersor referencesto zero or moreevent obj ects. An event expressi on
may contain multipl e references to the same event object. The order of the events within the event
expression shal l have no effect on the behavior of theevent expression when it is used to create dynamic
sensitivity.
5.9.2 Class definition
namespacesc_core{
class sc_event_and_expr

{
publ ic:
oper ator const sc_event_and_l ist & () const;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


96
Copyright 2012 IEEE. All rights reserved.
// Other members
i mpl ementati on-defi ned
} ;
sc_event_and_expr

oper ator & ( sc_event_and_expr

, sc_event const& );
sc_event_and_expr

oper ator & ( sc_event_and_expr

, sc_event_and_l ist const& );


classsc_event_or _expr

{
publ ic:
oper ator const sc_event _or _li st & () const;
// Other members
i mpl ementati on-defi ned
} ;
sc_event_or _expr

oper ator | ( sc_event_or _expr

, sc_event const& );
sc_event_or _expr

oper ator | ( sc_event_or _expr

, sc_event_or_l ist const& );


} // namespacesc_core
5.9.3 Constraints on usage
An appl icati on shal l not expl icitly createan object of cl ass sc_event_and_expr

or sc_event_or _expr

. An
appl icati on wishi ng to create expl ici t event l ist obj ects should use the classes sc_event_and_li st and
sc_event_or _li st.
Cl asses sc_event_and_expr

and sc_event_or _expr

are the return types of oper ator & and oper ator |,
respectivel y, of cl asses sc_event, sc_event _and_li st, and sc_event _or _li st .
The existence of the type conversi on operators from type sc_event_and_expr

to type const
sc_event_and_li st & and fromtypesc_event_or _expr

to typeconst sc_event_or_l ist & all ow expressi ons


of type sc_event_and_expr

and sc_event_or _expr

to be passed as arguments to the functions wait and


next _tr igger, for exampl e, wait (ev1 & ev2). The obj ects of type sc_event_and_expr

and
sc_event_or _expr

aretemporaries returned by oper ator & or oper ator | in an event expressi on, and would
bedestroyed automati call y after thecal l to wait or next _tr igger . Theimpl ementation shal l deletetheevent
li st object when the process instanceresumes or i s tri ggered as adi rect result of the notification of one or
more events in the event expression. In other words, the impl ementation shal l be responsible for the
creati on, deleti on, and memory management of event li st objects returned fromthe above type conversion
operators.
5.9.4 Operators
oper ator const sc_event _and_l ist & () const;
oper ator const sc_event _or _li st & () const;
Each of thesetypeconversion operators shall return areferenceto an event l ist object equivalent to
the event l ist expressi on represented by the current obj ect * thi s, equivalent i n the sense that the
event l ist object shal l contai n references to thesameset of eventsastheevent l ist expression.
sc_event_and_expr

oper ator & ( sc_event_and_expr

, sc_event const& );
sc_event_and_expr

oper ator & ( sc_event_and_expr

, sc_event_and_l ist const& );


sc_event_or _expr

oper ator | ( sc_event_or _expr

, sc_event const& );
sc_event_or _expr

oper ator | ( sc_event_or _expr

, sc_event_or_l ist const& );


IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


97
Copyright 2012 IEEE. All rights reserved.
A cal l to ei ther operator shal l append the event or events passed as the second argument to the event
expression passed as the fi rst argument, and shall return the resul tant elongated event expression as
the val ue of the operator.
Exampl e:
sc_event event1, event2;
void thread_process()
{
...
wait( event1 | event2 );
// When the thread process resumes fol lowi ng the noti fi cation of event1 or event2,
// the impl ementation shall del ete the object of type sc_event_or_expr returned from operator|
...
}
5.10 sc_event
5.10.1 Description
An event is an obj ect of class sc_event used f or process synchronizati on. A process instance may be
triggered or resumed on the occur rence of an event, that i s, when the event is notif ied. Any given event may
be noti fi ed on many separate occasions.
Events can be hi er ar chi cal l y named or not. An event wi thout a hi erarchical name shal l have an
impl ementation-def ined name. A hierarchi cal ly named event shall either have a parent in the object
hierarchy (in which case the event woul d be returned f rom member f unction get_child_events of that
parent) or be a top-level event (in which case the event woul d be returned by f unction
sc_get_top_level_events). I f an event has a parent, that parent shall be ei ther a module instance or a process
instance. An event wi thout a hi erarchical name shal l not have a parent i n the object hierarchy.
A ker nel event i s an event that is instantiated by the impl ementati on, such as an event wi thi n a predefi ned
pri mi tive channel. A kernel event shall not be hierarchi call y named but shal l have an impl ementation-
def ined name, regardless of whether i t i s i nstantiated duri ng elaborati on or duri ng simul ation.
Wi th the exception of kernel events, every event that i s instantiated duri ng el aboration or bef ore the
ini ti al izati on phase shall be a hi erarchical ly named event.
NOTE 1Events without a hierarchical name are provided for backward compatibi l i ty wi th earl i er versi ons of thi s
standard and to avoi d the potential performance i mpact of creati ng hi erachi cal names duri ng si mul ati on.
NOTE 2Although an event may have a parent of type sc_object, an event obj ect i s not i tsel f an sc_object, and hence
an event cannot be returned by member f unction get_child_objects. Member f uncti on get_child_eventsi s provi ded f or
the purpose of retrievi ng the events wi thi n a gi ven modul e or process i nstance.
NOTE 3In the case of a hierarchically named event, the rules f or hi erachi cal nami ng impl y that the name of the event
i s f ormed by concatenati ng the hi erarchi cal name of the parent of the event wi th the basename of the event, wi th the two
parts separated by a peri od character.
5.10.2 Class definition
namespace sc_core {
class sc_event
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


98
Copyright 2012 IEEE. All rights reserved.
{
publ ic:
sc_event();
expl icit sc_event( const char* );
~sc_event();
const char* name() const;
const char* basename() const;
bool in_hierarchy() const;
sc_object* get_parent_object() const;
void notify();
void notify( const sc_ti me& );
void notify( double , sc_time_unit );
void cancel();
sc_event_and_expr

operator& ( const sc_event& ) const;


sc_event_and_expr

operator& ( const sc_event_and_li st& ) const;


sc_event_or _expr

operator| ( const sc_event& ) const;


sc_event_or _expr

operator| ( const sc_event_or_li st& ) const;


pri vate:
// Di sabl ed
sc_event( const sc_event& );
sc_event& operator= ( const sc_event& );
} ;
const std::vector<sc_event* >& sc_get_top_level_events();
sc_event* sc_find_event( const char* );
} // namespace sc_core
5.10.3 Constraints on usage
Objects of cl ass sc_event may be constructed during elaborati on or simul ation. Events may be notif ied
during elaboration or simulati on, except that i t shal l be an error to create an i mmedi ate notif ication duri ng
elaborati on or from one of the cal lbacks before_end_of_elaboration, end_of_elaboration, or
start_of_simulation.
5.10.4 Constructors, destructor, and event naming
sc_event();
expl icit sc_event( const char* );
Call ing the constructor sc_event(const char*) with an empty string shall have the same ef fect as
cal li ng the default constructor, regardl ess of when it is cal led by the appli cation.
When call ed by the applicati on during elaboration or bef ore the initiali zation phase, each of the
above two constructors shall create a hierarchi cal ly named event.
When the def aul t constructor i s call ed by the applicati on f rom the i ni ti al izati on phase onwards,
whether or not a hi erarchically named event i s created shall be implementation-defi ned on a per-
instance basi s.
When the constructor sc_event(const char*) i s call ed by the appli cati on from the i ni ti al izati on
phase onward wi th a non-empty stri ng argument, the impl ementation shall create a hierachicall y
named event.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


99
Copyright 2012 IEEE. All rights reserved.
When a hi erarchical ly named event is constructed, if a non-empty string is passed as a constructor
argument, that string shall be used to set the string name of the event. Otherwi se, the stri ng name
shal l be set to "event". The string name shal l be used to determi ne the hierarchi cal name as
described in 5.17.
I f a constructor needs to substitute a new string name in place of the ori gi nal stri ng name as the
result of a name cl ash, the constructor shal l generate a single warning.
An event that is not hi erarchi cal ly named shall have a non-empty i mplementati on-def ined name.
That name shall take the form of a hi erachi cal name as descri bed in 5.17 but may contain one or
more characters that are not i n the recommended character set f or appl ication-def ined hi erarchical
names (such as punctuati on characters and mathemati cal symbol s). The i ntent is that an
impl ementation may use speci al characters to disti ngui sh impl ementation-defi ned names f rom
appl icati on-def ined names, although it i s not obli ged to do so.
Kernel events shall obey the same rul es as appl icati on-def ined events that are not hierarchi call y
named.
NOTEAn implementation is not required to guarantee that each i mpl ementation-def i ned event name i s
uni que. The i ntent i s that the i mplementati on wi l l use characters not recommended i n appl i cati on-def i ned
names to reduce the probabi l i ty of a name clash between a hi erarchi cal name and an i mpl ementati on-def i ned
name.
~sc_event();
The destructor shall del ete the obj ect and shall remove the event f rom the object hi erarchy such that
the event i s no longer a top-level event or a chi ld event.
5.10.5 Functions for naming and hierarchy traversal
const char* name() const;
Member functi on name shall return the hierarchical name of the event i nstance in the case of a
hierarchi cal ly named event, or otherwi se, i t shall return the impl ementation-defi ned name of the
event i nstance. The name shall al ways be non-empty.
const char* basename() const;
Member f unction basename shal l return the string name of the event instance in the case of a
hierarchi cal ly named event, or otherwise, it shal l return an impl ementation-def ined name. Thi s i s the
string name created when the event instance was constructed. In the case of an i mplementati on-
def ined name, the relati onship between the stri ngs returned from member functions name and
basenameis also implementati on-defi ned.
bool in_hierarchy() const;
Member f unction in_hierarchyshall return the val ue trueif and onl y i f the event is a hierarchi cal ly
named event.
The three f unctions below return information that supports the traversal of events that have a parent in the
object hi erarchy. An i mplementation shal l al low each of these three functi ons to be call ed at any stage
during elaborati on or simul ation. If cal led bef ore elaboration i s complete, they shal l return i nf ormation
concerning the parti al ly constructed object hierarchy as i t exi sts at the time the functions are call ed. I n other
words, a f unction shal l return pointers to any sc_event obj ects that have been constructed before the time the
f uncti on i s cal led but wil l excl ude any objects constructed af ter the f unction i s call ed.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


100
Copyright 2012 IEEE. All rights reserved.
sc_object* get_parent_object() const;
Member function get_parent_object shal l return a pointer to the sc_object that i s the parent of the
current sc_event object in the case of hierarchi cal ly named events, or otherwi se, it shall return the
null pointer. get_parent_object shall also return a null pointer for a top-level event. I f the parent
object is a process i nstance and that process has terminated, get_parent_object shall return a
pointer to that process instance. A process instance shal l not be deleted (nor any associated process
handl es inval idated) whil e the process has surviving chi ldren, but i t may be del eted once all i ts chi ld
objects have been deleted.
const std::vector<sc_event* >& sc_get_top_level_events();
Function sc_get_top_level_events shall return a std::vector contai ni ng pointers to all of the top-
level sc_event objects, that i s, events that are hi erarchicall y named but have no parent.
sc_event* sc_find_event( const char* );
Function sc_find_event shal l return a poi nter to the hierarchi cal ly named sc_event object that has a
name that exactl y matches the value of the string argument or shall return the nul l pointer if there is
no hi erarchicall y named sc_event wi th that name. Functi on sc_find_event shal l not return a poi nter
to an event that has an i mplementati on-def ined name.
5.10.6 notify and cancel
void notify();
A cal l to member functi on notify with an empty argument li st shall create an immediate notif icati on.
Any and all process i nstances sensi tive to the event shall be made runnabl e bef ore control i s returned
from functi on notify, with the exception of the currentl y executing process instance, which shall not
be made runnabl e due to an immedi ate notif icati on regardless of its stati c or dynamic sensi ti vi ty (see
4.2.1.2).
NOTE 1Process instances sensi ti ve to the event wi l l not be resumed or tri ggered unti l the process that cal l ed
notifyhas suspended or returned.
NOTE 2All process instances sensitive to the event wi l l be run i n the current eval uati on phase and i n an order
that i s i mpl ementati on-def i ned. The presence of i mmedi ate noti f i cati on can i ntroduce non-determi ni sti c
behavi or.
NOTE 3Member function update of class sc_prim_channel shal l not cal l notify to create an i mmedi ate
notif i cati on.
void notify( const sc_ti me& );
void notify( double , sc_time_unit );
A call to member f unction notify wi th an argument that represents a zero time shall create a delta
noti ficati on.
A cal l to f uncti on notify with an argument that represents a non-zero ti me shall create a ti med
noti ficati on at the given time, expressed rel ati ve to the simul ation ti me when function notify is
cal led. In other words, the val ue of the ti me argument is added to the current si mulati on time to
determi ne the time at which the event wi ll be notif ied. The ti me argument shall not be negati ve.
NOTEIn the case of a delta notification, all processes that are sensitive to the event in the delta notification
phase wi l l be made runnabl e i n the subsequent eval uati on phase. I n the case of a ti med noti f i cation, al l
processes sensi ti ve to the event at the ti me the event occurs wi ll be made runnabl e at the ti me, which wi ll be a
f uture si mul ati on ti me.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


101
Copyright 2012 IEEE. All rights reserved.
void cancel();
Member f uncti on cancel shall del ete any pending notif ication for thi s event.
NOTE 1At most one pending notification can exist for any gi ven event.
NOTE 2Immediate notificati on cannot be cancel l ed.
5.10.7 Event lists
sc_event_and_expr

operator& ( const sc_event& ) const;


sc_event_and_expr

operator& ( const sc_event_and_li st& ) const;


sc_event_or _expr

operator| ( const sc_event& ) const;


sc_event_or _expr

operator| ( const sc_event_or_l ist& ) const;


A call to ei ther operator shall return an event expression formed by appending the current event
object to the event or event li st passed as an argument.
NOTEEvent lists are used as arguments to functions wait (see 5.2.18) and next_trigger (see 5.2.17).
5.10.8 Multiple event notifications
A given event shall have no more than one pendi ng noti fi cati on.
If f uncti on notify i s call ed f or an event that already has a notif icati on pending, onl y the notif icati on
schedul ed to occur at the earli est time shal l survi ve. The noti fi cati on scheduled to occur at the l ater ti me
shal l be cancel led (or never be scheduled i n the fi rst pl ace). An i mmedi ate notif icati on i s taken to occur
earli er than a delta notif ication, and a del ta noti fi cati on earlier than a ti med notif icati on. Thi s i s irrespecti ve
of the order i n whi ch f uncti on notify is cal led.
Exampl e:
sc_event e;
e.notif y(SC_ZERO_TIME); // Delta noti fi cation
e.notif y(1, SC_NS); // Timed notif icati on i gnored due to pendi ng delta noti fi cation
e.notif y(); // I mmediate notif ication cancel s pendi ng delta notifi cation. e i s noti fi ed
e.notif y(2, SC_NS); // Timed notif i cati on
e.notif y(3, SC_NS); // Timed notif icati on i gnored due to earli er pendi ng timed notif ication
e.notif y(1, SC_NS); // Timed notif icati on cancels pending ti med noti fi cation
e.notif y(SC_ZERO_TIME); // Delta noti fication cancel s pendi ng timed notif icati on
// e i s noti fi ed i n the next del ta cycle
5.11 sc_time
5.11.1 Description
Cl ass sc_time i s used to represent simul ation time and time interval s, including delays and time-outs. An
object of cl ass sc_time is constructed f rom a double and an sc_time_unit. Ti me shall be represented
internal ly as an unsigned integer of at l east 64 bi ts. For i mplementati ons using more than 64 bi ts, the return
val ue of member function valueneed not be of type sc_dt::uint64 (see member f unction valuein 5.11.2).
5.11.2 Class definition
namespace sc_core {
enum sc_time_unit { SC_FS = 0, SC_PS, SC_NS, SC_US, SC_MS, SC_SEC} ;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


102
Copyright 2012 IEEE. All rights reserved.
class sc_time
{
publ ic:
sc_time();
sc_time( double , sc_ti me_unit );
sc_time( const sc_ti me& );
sc_time& operator= ( const sc_ti me& );
sc_dt::uint64 value() const;
doubl e to_double() const;
doubl e to_seconds() const;
const std::string to_string() const;
bool operator== ( const sc_ti me& ) const;
bool operator!= ( const sc_ti me& ) const;
bool operator< ( const sc_ti me& ) const;
bool operator<= ( const sc_ti me& ) const;
bool operator> ( const sc_ti me& ) const;
bool operator>= ( const sc_ti me& ) const;
sc_time& operator+= ( const sc_ti me& );
sc_time& operator-= ( const sc_ti me& );
sc_time& operator*= ( double );
sc_time& operator/= ( double );
void print( std::ostream& = std::cout ) const;
} ;
const sc_time operator+ ( const sc_time& , const sc_ti me& );
const sc_time operator- ( const sc_ti me& , const sc_ti me& );
const sc_time operator* ( const sc_ti me&, double );
const sc_time operator* ( double, const sc_ti me& );
const sc_time operator/ ( const sc_ti me& , double );
doubl e operator/ ( const sc_ti me& , const sc_ti me& );
std::ostream& operator<< ( std::ostream&, const sc_time& );
const sc_time SC_ZERO_TIME;
void sc_set_time_resolution( double, sc_time_unit );
sc_time sc_get_time_resolution();
const sc_time& sc_max_time();
} // namespace sc_core
5.11.3 Time resolution
Time shal l be represented i nternall y as an i nteger mul tipl e of the time resol uti on. The def aul t ti me resolution
is 1 picosecond. Every object of class sc_timeshal l share a si ngl e common global ti me resol ution.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


103
Copyright 2012 IEEE. All rights reserved.
The ti me resol ution can only be changed by cal ling the f uncti on sc_set_time_resolution. Thi s functi on shall
only be cal led during el aboration, shall not be cal led more than once, and shal l not be call ed after
constructing an object of type sc_time with a non-zero time value. The value of the doubleargument shal l
be positive and shal l be a power of 10. I t shall be an error f or an appli cation to break the rul es gi ven i n thi s
paragraph.
The constructor f or sc_time shal l scale and round the gi ven time val ue to the nearest multiple of the ti me
resoluti on. Whether the value is rounded up or down is i mplementati on-def ined. The def aul t constructor
shal l create an obj ect having a time val ue of zero.
The val ues of enum sc_time_unit shal l be taken to have thei r standard physical meanings, for example,
SC_FS = f emtosecond = 10E-15 seconds.
The f unction sc_get_time_resolution shall return the time resoluti on.
5.11.4 Function sc_max_time
The i mplementati on shall provi de a function sc_max_timewi th the foll owing declaration:
const sc_time& sc_max_time();
The f unction sc_max_time shal l return the maxi mum val ue of type sc_time, cal cul ated af ter taki ng into
account the time resoluti on. Si nce f unction sc_max_timenecessari ly returns a reference to an object of type
sc_time that represents a non-zero time value, the time resolution cannot be modif ied after a cal l to
sc_max_time. Every call to sc_max_time duri ng a given si mulati on run shal l return an object havi ng the
same value and representi ng the maximum si mulati on ti me. The actual val ue is impl ementation-defi ned.
Whether each cal l to sc_max_time returns a reference to the same obj ect or a dif f erent obj ect i s
impl ementation-defi ned.
5.11.5 Functions and operators
Al l arithmetic, relational , equal ity, and assignment operators declared in 5.11.2 shal l be taken to have their
natural meanings when perf ormi ng i nteger arithmetic on the underlying representation of ti me. The resul ts
of i nteger underfl ow and divi de-by-zero shall be impl ementation-defi ned.
sc_dt::uint64 value() const;
doubl e to_double() const;
doubl e to_seconds() const;
These f unctions shal l return the underl yi ng representati on of the time val ue, fi rst converting the
val ue to a double in each of the two cases to_double and to_seconds, and then also scaling the
resultant value to units of 1 second in the case of to_seconds.
const std::string to_string() const;
void print( std::ostream& = std::cout ) const;
std::ostream& operator<< ( std::ostream& , const sc_time& );
These functi ons shal l return the ti me val ue converted to a stri ng or pri nt that string to the gi ven
stream. The f ormat of the stri ng is impl ementation-defi ned.
5.11.6 SC_ZERO_TIME
Constant SC_ZERO_TI ME represents a time value of zero. It i s good practice to use this constant whenever
writi ng a time val ue of zero, for example, when creati ng a del ta notif icati on or a del ta ti me-out.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


104
Copyright 2012 IEEE. All rights reserved.
Exampl e:
sc_event e;
e.notif y(SC_ZERO_TIME); // Delta noti fi cation
wait(SC_ZERO_TIME); // Delta ti me-out
5.12 sc_port
5.12.1 Description
Ports provide the means by whi ch a module can be written such that i t is i ndependent of the context i n which
it i s i nstantiated. A port forwards interface method call s to the channel to which the port is bound. A port
def ines a set of services (as identi fi ed by the type of the port) that are required by the module contai ni ng the
port.
I f a module i s to cal l a member functi on belonging to a channel that i s outsi de the modul e itself , that cal l
should be made usi ng an interface method cal l through a port of the module. To do otherwise is considered
bad coding style. However, a cal l to a member function belonging to a channel instanti ated wi thi n the
current module may be made di rectl y. This is known as portl ess channel access. If a module is to cal l a
member function bel onging to a channel i nstance wi thin a chi ld modul e, that cal l should be made through an
export of the chi ld module (see 5.13).
5.12.2 Class definition
namespace sc_core {
enum sc_port_policy
{
SC_ONE_OR_MORE_BOUND , // Def aul t
SC_ZERO_OR_MORE_BOUND ,
SC_ALL_BOUND
} ;
class sc_port_base
: publi c sc_object { i mpl ementati on-defi ned } ;
templ ate <cl ass I F>
class sc_port_b
: publi c sc_port_base
{
publ ic:
void operator() ( I F& );
void operator() ( sc_port_b<IF>& );
virtual void bind( IF& );
virtual void bind( sc_port_b<IF>& );
int size() const;
IF* operator->();
const I F* operator-> () const;
IF* operator[] ( i nt );
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


105
Copyright 2012 IEEE. All rights reserved.
const I F* operator[] ( i nt ) const;
virtual sc_i nterf ace* get_interface();
virtual const sc_i nterf ace* get_interface() const;
protected:
virtual void before_end_of_elaboration();
virtual void end_of_elaboration();
virtual void start_of_simulation();
virtual void end_of_simulation();
expl icit sc_port_b( i nt , sc_port_poli cy );
sc_port_b( const char* , int , sc_port_pol icy );
virtual ~sc_port_b();
pri vate:
// Di sabl ed
sc_port_b();
sc_port_b( const sc_port_b<I F>& );
sc_port_b<I F>& operator = ( const sc_port_b<IF>& );
} ;
templ ate <class I F, i nt N = 1, sc_port_poli cy P = SC_ONE_OR_MORE_BOUND>
class sc_port
: publi c sc_port_b<IF>
{
publ ic:
sc_port();
expl icit sc_port( const char* );
virtual ~sc_port();
virtual const char* kind() const;
pri vate:
// Di sabl ed
sc_port( const sc_port<I F,N,P>& );
sc_port<I F,N,P>& operator= ( const sc_port<I F,N,P>& );
} ;
} // namespace sc_core
5.12.3 Template parameters
The fi rst argument to templ ate sc_port shal l be the name of an i nter face proper. This i nterf ace i s said to be
the type of the por t. A port can onl y be bound to a channel deri ved f rom the type of the port or to another
port or export with a type deri ved f rom the type of the port.
The second argument to templ ate sc_port is an optional integer val ue. If present, thi s argument shall speci fy
the maxi mum number of channel instances to whi ch any one i nstance of the port bel ongi ng to any specifi c
module i nstance may be bound. If the value of this argument is zero, the port may be bound to an arbi trary
number of channel instances. It shall be an error to bind a port to more channel instances than the number
permi tted by the second template argument.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


106
Copyright 2012 IEEE. All rights reserved.
The default value of the second argument i s 1. I f the value of the second argument i s not 1, the port is said to
be a mul ti port. If a port i s bound to another port, the value of this argument may dif fer between the two
ports.
The third argument to template sc_port is an optional port poli cy of type sc_port_policy. The port poli cy
argument determi nes the rules f or binding multiports and the rules f or unbound ports.
The poli cy SC_ONE_OR_MORE_BOUND means that the port i nstance shal l be bound to one or more
channel instances, the maxi mum number being determined by the value of the second template argument. It
shall be an error f or the port i nstance to remain unbound at the end of el aboration.
The pol icy SC_ZERO_OR_MORE_BOUND means that the port instance shall be bound to zero or more
channel i nstances, the maximum number being determi ned by the value of the second template argument.
The port instance may remain unbound at the end of elaborati on.
The poli cy SC_ALL_BOUND means that the port i nstance shall be bound to exactl y the number of channel
instances gi ven by value of the second templ ate argument, no more and no l ess, provi ded that val ue i s
greater than zero. If the value of the second template argument i s zero, pol icy SC_ALL_BOUND shall have
the same meaning as poli cy SC_ONE_OR_MORE_BOUND. I t shal l be an error for the port i nstance to
remai n unbound at the end of el aboration, or to be bound to fewer channel instances than the number
required by the second template argument.
I t shall be an error to bi nd a given port i nstance to a gi ven channel i nstance more than once, whether di rectl y
or through another port.
The port poli cy shall apply i ndependentl y to each port instance, even when a port i s bound to another port.
For example, if a port on a chi ld modul e wi th a type sc_port<I F> is bound to a port on a parent modul e wi th
a type sc_port<I F,2,SC_ALL_BOUND>, the two port polici es are contradi ctory and one or other wi ll
inevitabl y resul t in an error at the end of el aboration.
The port poli ci es shal l hol d when port bi ndi ng is compl eted by the i mplementati on j ust bef ore the cal lbacks
to f uncti on end_of_elaboration but are not required to hold any earli er. For exampl e, a port of type
sc_port<I F,2,SC_ALL_BOUND> could be bound once i n a modul e constructor and once i n the cal lback
functi on before_end_of_elaboration.
Exampl e:
sc_port<IF> // Bound to exactl y 1 channel i nstance
sc_port<IF,0> // Bound to 1 or more channel i nstances
// with no upper l imit
sc_port<IF,3> // Bound to 1, 2, or 3 channel i nstances
sc_port<IF,0,SC_ZERO_OR_MORE_BOUND> // Bound to 0 or more channel i nstances
// with no upper l imit
sc_port<IF,1,SC_ZERO_OR_MORE_BOUND> // Bound to 0 or 1 channel instances
sc_port<IF,3,SC_ZERO_OR_MORE_BOUND> // Bound to 0, 1, 2, or 3 channel i nstances
sc_port<IF,3,SC_ALL_BOUND> // Bound to exactl y 3 channel i nstances
NOTEA port may be bound indirectly to a channel by bei ng bound to another port or export (see 4.1.3).
5.12.4 Constraints on usage
An impl ementation shall derive cl ass sc_port_basefrom class sc_object.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


107
Copyright 2012 IEEE. All rights reserved.
Ports shal l only be i nstanti ated duri ng elaborati on and only from within a module. It shall be an error to
instanti ateaport other than withi n amodule. It shall bean error toi nstanti ateaport during si mulati on.
The member functi ons size and get_interface can be call ed duri ng elaborati on or si mulati on, whereas
operator->and operator[] should only becalled fromend_of_elaboration or duri ng simul ation.
It i sstrongl y recommended that aport wi thi nagiven modul ebebound at thepoint wherethegi ven module
is i nstantiated, that is, wi thin the constructor from which the module is i nstantiated. Furthermore, i t i s
strongl y recommended that theport bebound to achannel or another port that isitself i nstantiated wi thin the
modulecontaining theinstanceof thegi ven modul eor to an export that isi nstanti ated wi thin achi ld module.
This recommendati on may be viol ated on occasion. For example, it is convenient to bind an otherwise
unbound port fromthebefore_end_of_elaboration cal lback of theport instanceitself.
Theconstraint that aport bei nstanti ated wi thi n a modul e al lowsfor consi derabl eflexibil ity. However, it i s
strongly recommended that aport i nstancebeadatamember of amodul ewherever practical; otherwise, the
syntax necessary for named port bindi ng becomessomewhat arcanein that it requiresmorethan simpl ecl ass
member access usi ngthedot operator.
Supposeaparticular port i s instantiated within moduleC, and modul eCisi tsel f i nstantiated wi thin module
P. It i spermi ssibl efor theport to bebound at somepoint i n thecoderemotefromthepoi nt at which module
C i s i nstantiated, it is permi ssibl e for the port to be bound to a channel (or another port) that i s itself
instanti ated in amodul eother than themoduleP, and i t i spermi ssibl efor theport to bebound to an export
that i s instanti ated somewhere other than in a chil d modul e of module P. However, all such cases would
result i n a breakdown of the normal discipli ne of the modul e hierarchy and are strongly di scouraged in
typical usage.
5.12.5 Constructors
expl icit sc_port_b( i nt , sc_port_poli cy );
sc_port_b( const char* , int , sc_port_pol icy );
virtual ~sc_port_b();
Theconstructor for class sc_port_b shal l passtheval uesof itsargumentsthough to theconstructor
for thebase cl ass sub-obj ect. Thecharacter string argument shall bethestring nameof thei nstance
in the modul ehierarchy, the int argument shal l bethe maximum number of channel i nstances, and
thesc_port_policy argument shall betheport poli cy.
sc_port();
expl icit sc_port( const char* );
Theconstructor for class sc_port shall pass thecharacter string argument (if such argument exists)
through to the constructor bel ongi ng to the base class sc_port_b to set the stri ng name of the
instancein themodul ehi erarchy, and shal l passthetwo templateparametersN and Pasarguments
to theconstructor for cl asssc_port_b.
Thedefaul t constructor shall call function sc_gen_unique_name("port") to generateauniquestri ng name
that i t shal l then pass through to theconstructor for thebasecl asssc_object.
NOTEA port instance need not be given an explicit string namewithin theapplication when it isconstructed.
5.12.6 kind
Member functi on kind shall return thestring "sc_port".
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


108
Copyright 2012 IEEE. All rights reserved.
5.12.7 Named port binding
Ports can be bound ei ther usi ng the functi ons l isted in thi s subclause for named bindi ng or usi ng the
operator() f rom cl ass sc_module f or positional bindi ng. An impl ementation may defer the compl etion of
port bi ndi ng unti l a later time during el aboration because the port to which a port i s bound may not yet i tself
have been bound. Such deferred port bi nding shal l be compl eted by the i mplementati on before the cal lbacks
to f uncti on end_of_elaboration.
void operator() ( I F& );
virtual void bind( IF& );
Each of these two functi ons shall bind the port instance f or which the function is cal led to the
channel i nstance passed as an argument to the f unction. The actual argument can be an export, i n
which case the C++ compil er wi ll call the i mpli ci t conversi on sc_export<IF>::operator IF&. The
impl ementation of operator() shall achieve i ts ef f ect by cal l ing the virtual member f unction bind.
void operator() ( sc_port_b<IF>& );
virtual void bind( sc_port_b<IF>& );
Each of these two f unctions shal l bind the port instance f or which the f unction i s call ed to the port
instance passed as an argument to the f unction. The i mplementati on of operator() shall achi eve its
eff ect by cal li ng the virtual member f uncti on bind.
Exampl e:
SC_MODULE(M)
{
sc_i nout<i nt> P, Q, R, S; // Ports
sc_i nout<i nt> * T; // Poi nter-to-port (not a recommended codi ng styl e)
SC_CTOR(M) { T = new sc_i nout<i nt>; }
...
} ;
SC_MODULE(Top)
{
sc_i nout <i nt> A, B;
sc_signal <int> C, D;
M m; // Module instance
SC_CTOR(Top)
: m("m")
{
m.P(A); // Binds P-to-A
m.Q.bind(B); // Bi nds Q-to-B
m.R(C); // Binds R-to-C
m.S.bind(D); // Bi nds S-to-D
m.T->bind(E); // Bi nds T-to-E
}
...
} ;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


109
Copyright 2012 IEEE. All rights reserved.
5.12.8 Member functions for bound ports and port-to-port binding
The member f uncti ons descri bed in thi s subcl ause return i nformation about ports that have been bound
duri ng el aboration. These functi ons return informati on concerning the ordered set of channel i nstances to
which a particular port instance (whi ch may or may not be a mul ti port) is bound.
The ordered set S of channel instances to whi ch a gi ven port i s bound (f or the purpose of defi ning the
semantics of the f uncti ons given in thi s subclause) is determined as foll ows.
a) When the port or export is bound to a channel i nstance, that channel instance shall be added to the
end of the ordered set S.
b) When the port or export i s bound to an export, rules a) and b) shal l be applied recursivel y to the
export.
c) When the port is bound to another port, rules a), b), and c) shal l be appl ied recursively to the other
port.
Because an i mplementati on may def er the compl etion of port bi ndi ng unti l a later time duri ng elaborati on,
the number and order of the channel instances as returned from the member f unctions descri bed in thi s
subclause may change during el aborati on and the f inal order is impl ementation-defi ned, but i t shal l not
change duri ng the end_of_elaboration cal lback or duri ng simul ation.
NOTEAs a consequence of the above rules, a given channel instance may appear to li e at a dif f erent posi ti on i n the
ordered set of channel i nstances when vi ewed f rom ports at di f ferent posi ti ons i n the modul e hierarchy. For exampl e, a
gi ven channel i nstance may be the f i rst channel i nstance to which a port of a parent modul e i s bound but the thi rd
channel i nstance to whi ch a port of a chi l d modul e i s bound.
5.12.8.1 size
int size() const;
Member f unction sizeshal l return the number of channel instances to which the port i nstance for which it i s
cal led has been bound.
I f member function sizei s cal led during elaborati on and before the call back end_of_elaboration, the value
returned is impl ementation-def ined because the time at which port bi ndi ng is completed is i mplementati on-
def ined.
NOTEThe value returned by sizewi l l be 1 f or a typical port but may be 0 i f the port is unbound or greater than 1 f or a
mul ti port.
5.12.8.2 operator->
IF* operator-> ();
const I F* operator-> () const;
operator-> shal l return a poi nter to the fi rst channel instance to which the port was bound during
elaborati on.
I t shal l be an error to cal l operator-> f or an unbound port. If operator-> i s call ed during elaborati on and
bef ore the call back end_of_elaboration, the behavi or i s impl ementation-def ined because the time at which
port bi ndi ng i s completed is impl ementation-defi ned.
NOTEoperator-> i s key to the i nterf ace method cal l paradi gm i n that i t permi ts a process to cal l a member f uncti on,
def ined i n a channel, through a port bound to that channel .
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


110
Copyright 2012 IEEE. All rights reserved.
Exampl e:
struct i face
: vi rtual sc_i nterf ace
{
virtual int read() const = 0;
} ;
struct chan
: i face, sc_prim_channel
{
virtual int read() const;
} ;
int chan::read() const { ... }
SC_MODULE(modu)
{
sc_port<if ace> P;
SC_CTOR(modu)
{
SC_THREAD(thread);
}
void thread()
{
int i = P->read(); // I nterf ace method call
}
} ;
SC_MODULE(top)
{
modu * mo;
chan * ch;
SC_CTOR(top)
{
ch = new chan;
mo = new modu("mo");
mo->P(* ch); // Port Pbound to channel * ch
}
} ;
5.12.8.3 operator[]
IF* operator[] ( i nt );
const I F* operator[] ( i nt ) const;
operator[] shall return a poi nter to a channel i nstance to whi ch a port i s bound. The argument identi fies
which channel i nstance shall be returned. The i nstances are numbered starting f rom zero i n the order in
which the port binding was completed, the order bei ng i mplementati on-def ined.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


111
Copyright 2012 IEEE. All rights reserved.
The value of the argument shall li e i n the range 0 to N 1, where N is the number of instances to which the
port is bound. It shall be an error to cal l operator[] wi th an argument val ue that li es outside thi s range. If
operator[] i s call ed duri ng el aboration and before the call back end_of_elaboration, the behavior is
impl ementation-def ined because the time at whi ch port bi ndi ng i s completed is impl ementation-defi ned.
operator[] may be cal led f or a port that i s not a multiport, in whi ch case the val ue of the argument should be
0.
Exampl e:
class bus_interface;
class slave_i nterf ace
: vi rtual publi c sc_i nterf ace
{
publ ic:
virtual void sl ave_wri te(int addr, int data) = 0;
virtual void sl ave_read (i nt addr, int& data) = 0;
} ;
class bus_channel
: publi c bus_i nterf ace, publi c sc_modul e
{
publ ic:
...
sc_port<sl ave_interface, 0> slave_port; // Multi port f or attaching sl aves to bus
SC_CTOR(bus_channel)
{
SC_THREAD(acti on);
}
pri vate:
void action()
{
f or (i nt i = 0; i < sl ave_port.size(); i++) // Functi on size() returns number of slaves
slave_port[i ]->sl ave_wri te(0,0); // Operator[ ] i ndexes slave port
}
} ;
class memory
: publi c slave_i nterf ace, publ ic sc_modul e
{
publ ic:
virtual void sl ave_wri te(int addr, int data);
virtual void sl ave_read (int addr, int& data);
...
} ;
SC_MODULE(top_level )
{
bus_channel bus;
memory ram0, ram1, ram2, ram3;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


112
Copyright 2012 IEEE. All rights reserved.
SC_CTOR(top_l evel)
: bus("bus"), ram0("ram0"), ram1("ram1"), ram2("ram2"), ram3("ram3")
{
bus.slave_port(ram0);
bus.slave_port(ram1);
bus.slave_port(ram2);
bus.slave_port(ram3); // One mul tiport bound to four memory channel s
}
} ;
5.12.8.4 get_interface
virtual sc_i nterf ace* get_interface();
virtual const sc_i nterf ace* get_interface() const;
Member functi on get_interfaceshall return a poi nter to the fi rst channel i nstance to which the port is bound.
I f the port i s unbound, a null poi nter shall be returned. This member function may be cal led during
elaboration to test whether a port has yet been bound. Because the ti me at which deferred port binding i s
compl eted i s impl ementation-defi ned, it i s impl ementation-defi ned whether get_interface returns a pointer
to a channel i nstance or a null poi nter when cal led duri ng construction or from the callback
before_end_of_elaboration.
get_interfaceis intended f or use i n i mplementi ng speciali zed port cl asses derived f rom sc_port. In general ,
an appl ication shoul d cal l operator-> i nstead. However, get_interface permi ts an applicati on to call a
member f uncti on of the cl ass of the channel to which the port i s bound, even i f such a function is not a
member of the i nterf ace type of the port.
NOTEFunction get_interfacecannot return channel s beyond the f i rst channel i nstance to whi ch a mul ti port is bound;
use operator[] i nstead.
Exampl e:
SC_MODULE(Top)
{
sc_i n<bool> clock;
void bef ore_end_of_el aboration()
{
sc_i nterf ace* i _f = clock.get_i nterf ace();
sc_clock* clk = dynami c_cast<sc_clock* >(i_f );
sc_ti me t = clk->period(); // Cal l method of clock object to whi ch port is bound
...
5.12.9 before_end_of_elaboration, end_of_elaboration, start_of_simulation,
end_of_simulation
See 4.4.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


113
Copyright 2012 IEEE. All rights reserved.
5.13 sc_export
5.13.1 Description
Cl ass sc_export all ows a modul e to provi de an i nterf ace to its parent modul e. An export forwards interf ace
method call s to the channel to which the export i s bound. An export def ines a set of servi ces (as identif ied by
the type of the export) that are provided by the module contai ni ng the export.
Providi ng an interf ace through an export i s an alternative to a modul e si mply i mplementing the interface.
The use of an expli ci t export al lows a single modul e i nstance to provide mul ti ple interfaces in a structured
manner.
If a module i s to cal l a member function bel onging to a channel i nstance wi thi n a chil d module, that call
should be made through an export of the chil d module.
5.13.2 Class definition
namespace sc_core {
class sc_export_base
: publi c sc_object { i mpl ementati on-defi ned } ;
templ ate<cl ass I F>
class sc_export
: publi c sc_export_base
{
publ ic:
sc_export();
expl icit sc_export( const char* );
virtual ~sc_export();
virtual const char* kind() const;
void operator() ( I F& );
virtual void bind( IF& );
operator IF& ();
operator const I F& () const;
IF* operator->();
const I F* operator-> () const;
virtual sc_i nterf ace* get_interface();
virtual const sc_i nterf ace* get_interface() const;
protected:
virtual void before_end_of_elaboration();
virtual void end_of_elaboration();
virtual void start_of_simulation();
virtual void end_of_simulation();
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


114
Copyright 2012 IEEE. All rights reserved.
pri vate
// Di sabl ed
sc_export( const sc_export<IF>& );
sc_export<I F>& operator= ( const sc_export<IF>& );
} ;
} // namespace sc_core
5.13.3 Template parameters
The argument to templ ate sc_export shall be the name of an interface proper. This interface i s sai d to be the
type of the expor t. An export can onl y be bound to a channel deri ved f rom the type of the export or to
another export with a type derived f rom the type of the export.
NOTEAn export may be bound indirectly to a channel by bei ng bound to another export (see 4.1.3).
5.13.4 Constraints on usage
An impl ementation shall derive cl ass sc_export_basefrom class sc_object.
Exports shall only be i nstanti ated duri ng elaborati on and only from withi n a modul e. I t shall be an error to
instanti ate an export other than within a modul e. It shal l be an error to i nstanti ate an export duri ng
simul ation.
Every export of every modul e instance shal l be bound once and once only duri ng el aborati on. It shal l be an
error to have an export remai ning unbound at the end of elaborati on. I t shal l be an error to bind an export to
more than one channel .
The member f unction get_interface can be cal led during el aborati on or simul ation, whereas operator->
should only be called during si mulation.
I t is strongly recommended that an export within a given module be bound within that same module.
Furthermore, i t i s strongly recommended that the export be bound to a channel that is i tsel f instantiated
wi thin the current module or implemented by the current module or bound to an export that is i nstantiated
wi thin a child module. Any other usage would result in a breakdown of the normal discipli ne of the module
hierarchy and is strongly discouraged (see 5.12.4).
5.13.5 Constructors
sc_export();
expl icit sc_export( const char* );
The constructor f or class sc_export shall pass the character string argument (i f there i s one) through
to the constructor bel ongi ng to the base class sc_object i n order to set the string name of the i nstance
in the module hi erarchy.
The default constructor shall cal l f uncti on sc_gen_unique_name("export") in order to generate a
unique string name that i t shal l then pass through to the constructor for the base cl ass sc_object.
NOTEAn export instance need not be given an expli ci t stri ng name wi thi n the appl i cati on when i t i s
constructed.
5.13.6 kind
Member f uncti on kind shall return the string "sc_export".
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


115
Copyright 2012 IEEE. All rights reserved.
5.13.7 Export binding
Exports can be bound usi ng ei ther of the two f unctions defi ned here. The noti on of positional bi ndi ng i s not
appl icabl e to exports. Each of these functi ons shal l bi nd the export i mmediately, i n contrast to ports f or
which the impl ementation may need to defer the binding.
void operator() ( I F& );
virtual void bind( IF& );
Each of these two functions shal l bi nd the export instance for which the f uncti on i s call ed to the
channel i nstance passed as an argument to the f uncti on. The i mplementati on of operator() shal l
achi eve its eff ect by cal li ng the virtual member f unction bind.
NOTEThe actual argument could be an export, in which case operator I F& woul d be cal l ed as an i mpli ci t
conversi on.
Exampl e:
struct i_f: vi rtual sc_interface
{
virtual void pri nt() = 0;
} ;
struct Chan: sc_channel, i_f
{
SC_CTOR(Chan) { }
void pri nt() { std::cout << "I'm Chan, name=" << name() << std::endl; }
} ;
struct Cal ler: sc_modul e
{
sc_port<i_f> p;
...
} ;
struct Bottom: sc_modul e
{
sc_export<i _f > xp;
Chan ch;
SC_CTOR(Bottom) : ch("ch")
{
xp.bi nd(ch); // Bind export xp to channel ch
}
} ;
struct Middle: sc_modul e
{
sc_export<i _f > xp;
Bottom* b;
SC_CTOR(Middle)
{
b = new Bottom ("b");
xp.bi nd(b->xp); // Bi nd export xp to export b->xp
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


116
Copyright 2012 IEEE. All rights reserved.
b->xp->print(); // Call method of export withi n chil d modul e
}
} ;
struct Top: sc_modul e
{
Call er* c;
Mi ddl e* m;
SC_CTOR(Top)
{
c = new Call er ("c");
m = new Middle ("m");
c->p(m->xp); // Bi nd port c->p to export m->xp
}
} ;
5.13.8 Member functions for bound exports and export-to-export binding
The member functi ons described in this subcl ause return i nformation about exports that have been bound
duri ng el aboration, and hence, these member functions shoul d only be call ed af ter the export has been bound
duri ng elaboration or simulation. These functi ons return i nf ormation concerning the channel i nstance to
which a particular export instance has been bound.
I t shall be an error to bi nd an export more than once. I t shall be an error f or an export to be unbound at the
end of elaborati on.
The channel i nstance to whi ch a given export is bound (f or the purpose of def ini ng the semantics of the
f uncti ons given i n this subcl ause) i s determi ned as f oll ows:
a) I f the export is bound to a channel i nstance, that i s the channel instance i n question.
b) I f the export i s bound to another export, rules a) and b) shal l be appl ied recursively to the other
export.
5.13.8.1 operator-> and operator IF&
IF* operator-> ();
const I F* operator-> () const;
operator IF& ();
operator const I F& () const;
operator-> and operator I F& shall both return a pointer to the channel instance to whi ch the export
was bound duri ng el aborati on.
I t shall be an error for an appl ication to cal l thi s operator i f the export i s unbound.
NOTE 1operator-> i s i ntended f or use duri ng si mul ati on when maki ng an i nterf ace method cal l through an
export i nstance f rom a parent modul e of the modul e contai ni ng the export.
NOTE 2operator I F& is i ntended f or use duri ng el aborati on as an impl i ci t conversi on when passi ng an
object of class sc_export i n a context that requi res an sc_interface, f or exampl e, when bi ndi ng a port to an
export or when addi ng an export to the stati c sensi ti vi ty of a process.
NOTE 3There is no operator[] f or cl ass sc_export, and there i s no noti on of a mul ti -export. Each export can
onl y be bound to a si ngl e channel .
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


117
Copyright 2012 IEEE. All rights reserved.
5.13.8.2 get_interface
virtual sc_i nterf ace* get_interface();
virtual const sc_i nterf ace* get_interface() const;
Member functi on get_interfaceshal l return a pointer to the channel i nstance to whi ch the export is
bound. I f the export is unbound, a null pointer shall be returned. Thi s member function may be
cal led during el aboration to test whether an export has yet been bound.
5.13.9 before_end_of_elaboration, end_of_elaboration, start_of_simulation,
end_of_simulation
See 4.4.
5.14 sc_interface
5.14.1 Description
sc_interfaceis the abstract base class f or al l i nterf aces.
An i nter face is a class derived f rom the class sc_interface. An i nter face pr oper is an abstract cl ass deri ved
f rom class sc_interface but not deri ved f rom class sc_object. An interface proper contains a set of pure
virtual functions that shal l be def ined in one or more channels deri ved f rom that interface proper. Such a
channel is said to i mpl ement the interface.
NOTE 1The term i nter face pr oper i s used to di sti ngui sh an i nterf ace proper f rom a channel. A channel is a cl ass
deri ved i ndi rectl y f rom cl ass sc_interface, and i n that sense, a channel i s an i nterf ace. However, a channel i s not an
i nterf ace proper.
NOTE 2As a consequence of the rules of C++, an i nstance of a channel deri ved f rom an i nterf ace I F or a poi nter to
such an i nstance can be passed as the argument to a functi on wi th a parameter of type I F& or I F*, respecti vel y, or a port
of type I F can be bound to such a channel .
5.14.2 Class definition
namespace sc_core {
class sc_interface
{
publ ic:
virtual void register_port( sc_port_base& , const char* );
virtual const sc_event& default_event() const;
virtual ~sc_interface();
protected:
sc_interface();
pri vate:
// Di sabl ed
sc_interface( const sc_interface& );
sc_i nterf ace& operator= ( const sc_interface& );
} ;
} // namespace sc_core
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


118
Copyright 2012 IEEE. All rights reserved.
5.14.3 Constraints on usage
An appli cation shoul d not use class sc_interfaceas the di rect base cl ass f or any class other than an interface
proper.
An interface proper shal l obey the f ol lowi ng rul es:
a) I t shall be publi cl y deri ved directly or indirectly f rom class sc_interface.
b) I f directly derived f rom cl ass sc_interface, it shall use the virtual specif ier.
c) I t shall not be deri ved directl y or indirectly from cl ass sc_object.
An interface proper shoul d typi cal ly obey the foll owing rules:
a) I t should contain one or more pure virtual functi ons.
b) It should not be derived f rom any other cl ass that is not itself an i nterf ace proper.
c) I t should not contai n any function decl arations or function def ini ti ons apart from the pure virtual
f uncti ons.
d) I t should not contai n any data members.
NOTE 1An interface proper may be derived from another i nterf ace proper or f rom two or more other i nterf aces
proper, thus creati ng a multi pl e i nheri tance hi erarchy.
NOTE 2A channel class may be deri ved f rom any number of i nterfaces proper.
5.14.4 register_port
virtual void register_port( sc_port_base& , const char* );
The defi ni ti on of this function in class sc_interfacedoes nothi ng. An appli cation may overri de this f unction
in a channel .
The purpose of functi on register_port is to enable an appli cation to perf orm actions that depend on port
binding during elaboration, such as checking connectivi ty errors.
Member functi on register_port of a channel shal l be call ed by the impl ementation whenever a port is bound
to a channel i nstance. The f irst argument shal l be a ref erence to the port instance being bound. The second
argument shall be the value returned from the expression typeid( I F ).name(), where I F is the i nterf ace type
of the port.
Member f uncti on register_port shall not be cal led when an export i s bound to a channel .
I f a port P i s bound to another port Q, and port Q is in turn bound to a channel instance, the f irst argument to
member function register_port shall be the port P. I n other words, register_port i s not passed a ref erence to
a port on a parent modul e if a port on a chil d module is i n turn bound to that port; i nstead, i t is passed as a
ref erence to the port on the chi ld module, and so on recursi vel y down the modul e hi erarchy.
I n the case that multipl e ports are bound to the same si ngle channel i nstance or port instance, member
functi on register_port shal l be call ed once for each port so bound.
Exampl e:
void register_port( sc_port_base& port_, const char* if _typename_ )
{
std::stri ng nm( if _typename_ );
if ( nm == typeid( my_i nterf ace ).name() )
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


119
Copyright 2012 IEEE. All rights reserved.
std::cout << " channel " << name() << " bound to port " << port_.name() << std::endl;
}
5.14.5 default_event
virtual const sc_event& default_event() const;
Member f uncti on default_event shall be call ed by the implementation in every case where a port or channel
instance i s used to def ine the static sensitivi ty of a process instance by bei ng passed directly as an argument
to operator<< of class sc_sensi ti ve

. I n such a case, the appl ication shall override thi s f unction in the
channel in questi on to return a reference to an event to whi ch the process instance wil l be made sensi ti ve.
I f this f uncti on is call ed by the i mpl ementation but not overri dden by the appli cation, the i mplementati on
may generate a warning.
Exampl e:
struct my_i f
: vi rtual sc_i nterf ace
{
virtual i nt read() = 0;
} ;
class my_ch
: publi c my_i f, publ ic sc_modul e
{
publ ic:
virtual int read() { return m_val; }
virtual const sc_event& def ault_event() const { return m_ev; }
pri vate:
int m_val ;
sc_event m_ev;
...
} ;
5.15 sc_prim_channel
5.15.1 Description
sc_prim_channel is the base cl ass f or all primitive channels and provides such channels with uni que access
to the update phase of the scheduler. In common with hi erarchical channel s, a pri mitive channel may
provide publ ic member f uncti ons that can be cal led usi ng the i nterf ace method call paradi gm.
This standard provi des a number of predef ined pri mitive channels to model common communication
mechanisms (see Cl ause 6).
5.15.2 Class definition
namespace sc_core {
class sc_prim_channel
: publi c sc_object
{
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


120
Copyright 2012 IEEE. All rights reserved.
publ ic:
virtual const char* kind() const;
protected:
sc_prim_channel();
expl icit sc_prim_channel( const char* );
virtual ~sc_prim_channel();
void request_update();
void async_request_update();
virtual void update();
void next_trigger();
void next_trigger( const sc_event& );
void next_trigger( const sc_event_or_li st & );
void next_trigger( const sc_event_and_li st & );
void next_trigger( const sc_ti me& );
void next_trigger( double , sc_ti me_unit );
void next_trigger( const sc_ti me& , const sc_event& );
void next_trigger( double , sc_ti me_unit , const sc_event& );
void next_trigger( const sc_ti me& , const sc_event_or_li st & );
void next_trigger( double , sc_ti me_unit , const sc_event_or_li st & );
void next_trigger( const sc_ti me& , const sc_event_and_li st & );
void next_trigger( double , sc_ti me_unit , const sc_event_and_li st & );
void wait();
void wait( i nt );
void wait( const sc_event& );
void wait( const sc_event_or_l ist & );
void wait( const sc_event_and_l ist & );
void wait( const sc_ti me& );
void wait( double , sc_time_unit );
void wait( const sc_ti me& , const sc_event& );
void wait( double , sc_time_unit , const sc_event& );
void wait( const sc_ti me& , const sc_event_or_l ist & );
void wait( double , sc_time_unit , const sc_event_or_l ist & );
void wait( const sc_ti me& , const sc_event_and_l ist & );
void wait( double , sc_time_unit , const sc_event_and_li st & );
virtual void before_end_of_elaboration();
virtual void end_of_elaboration();
virtual void start_of_simulation();
virtual void end_of_simulation();
pri vate:
// Di sabl ed
sc_prim_channel( const sc_prim_channel& );
sc_pri m_channel & operator= ( const sc_prim_channel& );
} ;
} // namespace sc_core
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


121
Copyright 2012 IEEE. All rights reserved.
5.15.3 Constraints on usage
Objects of class sc_prim_channel can only be constructed duri ng el aborati on. I t shall be an error to
instanti ate a pri mitive channel during si mulati on.
A pri mi tive channel should be publ i cl y derived from cl ass sc_prim_channel.
A pri mi tive channel shall i mplement one or more i nterf aces.
Member f uncti ons request_update and async_request_update may be cal led during elaborati on or
simul ation. If call ed duri ng elaborati on, the update request shal l be executed duri ng the i ni ti al izati on phase.
NOTEBecause the constructors are protected, cl ass sc_prim_channel cannot be i nstanti ated di rectl y but may be used
as a base cl ass for a pri miti ve channel .
5.15.4 Constructors, destructor, and hierarchical names
sc_prim_channel();
expl icit sc_prim_channel( const char* );
The constructor for class sc_prim_channel shall pass the character stri ng argument (i f such argument
exi sts) through to the constructor belonging to the base class sc_object to set the string name of the instance
in the module hierarchy.
NOTEA class derived from class sc_prim_channel i s not obl i ged to have a constructor, in whi ch case the def ault
constructor f or cl ass sc_object wi l l generate a uni que stri ng name. As a consequence, a pri mi ti ve channel i nstance need
not be gi ven an expl i ci t stri ng name wi thi n the appl i cati on when it i s constructed.
5.15.5 kind
Member f uncti on kind shall return the string "sc_prim_channel".
5.15.6 request_update and update
Member functions request_updateand async_request_updateeach cause the schedul er to queue an update
request. An appli cation shoul d not cal l both request_update and async_request_update for a gi ven
pri mitive channel i nstance at any ti me duri ng el aboration or si mulati on, but it may do so f or di ff erent
pri mitive channel i nstances. If both request_update and async_request_update are cal led for the same
pri mitive channel instance, the behavi or of the impl ementation is undefi ned.
void request_update();
Member function request_update shal l cause the scheduler to queue an update request f or the
current primi ti ve channel (see 4.2.1.3). No more than one update request shall be queued f or any
given primi ti ve channel i nstance i n any given update phase; that is, mul ti ple call s to
request_updatein the same eval uation phase shal l result i n a single update request.
void async_request_update();
Member function async_request_update shal l cause the scheduler to queue an update request f or
the current primitive channel in a thread-safe manner with respect to the host operating system. The
intent of async_request_update i s that it may be call ed rel iably f rom an operating system thread
other than those in whi ch the SystemC kernel and any SystemC thread processes are executing.
An appli cati on may cal l async_request_update at any time during elaborati on or simul ati on, and
these call s may be asynchronous wi th respect to the SystemC kernel . The impl ementation shall
guarantee that each call to async_request_updatebehaves as i f i t were executed in an eval uation
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


122
Copyright 2012 IEEE. All rights reserved.
phase. No morethanoneupdaterequest shall bequeued for any given primitivechannel instancein
any given update phase; that is, multiple cal ls to async_request_update recei ved by the kernel
between two consecuti veupdatephases shall result in asi ngl eupdaterequest. Thepreci sephasei n
which any gi ven cal l to async_request_update i s received and processed by the kernel i s
undefined. As a consequence, two cal ls to async_request_update for the same primiti ve channel
and occurring wi thin a narrow time window may resul t in a si ngl e update request, two update
requests in consecutivedeltacycles, or two updaterequestsi nnon-consecutivedel tacycles.
The appli cation i s responsi ble for synchronizing access to any shared memory across cal ls to
async_request_update and update. The software thread that cal ls async_request_update would
typi call y need towriteavalueto somevari abl ethat i sread by function update. Theimpl ementation
can givenoguaranteewi th regard to theintegrity of any such shared memory.
It is not recommended to cal l member function async_request_update fromfunctions executed i n
the context of the SystemC kernel, such as SystemC thread or method processes, but only by
operating system threads separate from the kernel . Cal li ng async_request_update may cause a
performancedegradati oncompared to request_update.
virtual void update();
Member functi on updateshall becal led back by theschedul er duri ng theupdatephasein response
to a cal l to request_update or async_request_update. An appl ication may override this member
functi on i n aprimi ti vechannel. Thedefinition of thi sfunction in cl ass sc_prim_channel itsel f does
nothing.
When overridden in aderi ved class, member function updateshall not performany of thefol lowi ng
actions:
a) Cal l any member functi on of cl ass sc_prim_channel wi th the exception of member function
updateitsel f i f overri dden within abaseclassof thecurrent object
b) Cal l member function notify() of cl ass sc_event wi th no arguments to create an immediate
notificati on
c) Cal l any of the member functi ons of class sc_process_handlefor process control (suspend or
kill, for example)
If the appli cation viol ates the three rul es just given, the behavior of the impl ementation shal l be
undefined.
Member function updateshoul dnot changethestateof any storageexcept for datamembersof the
current object. Doi ng somay resul t i n non-deterministi c behavi or.
Member functi on update should not read thestate of any primi ti vechannel i nstanceother than the
current object. Doi ng somay resul t i n non-deterministi c behavi or.
Member functi on updateshould not cal l interfacemethodsof other channel instances. Inparticular,
member functi on updateshould not writetoany si gnals.
Member function updatemay call functi on sc_spawn to createadynami c process instance. Such a
processshall not becomerunnableuntil thenext eval uati on phase.
NOTE 1The purpose of the member functions request_update and update is to permit simultaneous
requeststoachannel madeduring theevaluationphasetoberesolved or arbitrated during theupdatephase. The
natureof thearbitration is theresponsibility of theapplication; for example, thebehavior of member function
updatemay bedeterministic or random.
NOTE 2update will typically only read and modify data members of the current object and create delta
notifications.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


123
Copyright 2012 IEEE. All rights reserved.
5.15.7 next_trigger and wait
The behavior of the member functi ons wait and next_trigger of cl ass sc_prim_channel shall be i denti cal to
that of the member functions of cl ass sc_modulewith the same function names and si gnatures. Aside f rom
the fact that they are members of di f ferent classes and so have dif ferent scopes, the restri ctions concerni ng
the context in which the member functi ons may be cal led i s also i dentical . For example, the member
functi on next_trigger shall onl y be cal led from a method process.
5.15.8 before_end_of_elaboration, end_of_elaboration, start_of_simulation,
end_of_simulation
See 4.4.
Exampl e:
struct my_i f
: vi rtual sc_interf ace // An i nterf ace proper
{
virtual i nt read() = 0;
virtual void wri te(int) = 0;
} ;
struct my_prim
: sc_prim_channel, my_if // A pri mitive channel
{
my_pri m() // Default constructor
:
sc_pri m_channel ( sc_gen_unique_name("my_pri m") ),
m_req(false),
m_written(f al se),
m_cur_val (0) { }
virtual void wri te(i nt val)
{
if (! m_req) // Only keeps the 1st val ue wri tten in any one delta
{
m_new_val = val;
request_update(); // Schedul es an update request
m_req = true;
}
}
virtual void update() // Called back by the schedul er in the update phase
{
m_cur_val = m_new_val;
m_req = false;
m_written = true;
m_write_event.notify(SC_ZERO_TI ME); // A delta noti fi cation
}
virtual int read()
{
if (! m_wri tten) wai t(m_write_event); // Blocked unti l update() is cal led
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


124
Copyright 2012 IEEE. All rights reserved.
m_written = f alse;
return m_cur_val ;
}
bool m_req, m_wri tten;
sc_event m_wri te_event;
int m_new_val, m_cur_val ;
} ;
5.16 sc_object
5.16.1 Description
Cl ass sc_object i s the common base cl ass f or cl asses sc_module, sc_port, sc_export, and
sc_prim_channel, and f or the i mplementati on-def i ned classes associ ated with spawned and unspawned
process i nstances. The set of sc_objects shall be organized i nto an obj ect hi erar chy, where each sc_object
has no more than one parent but may have multipl e sibli ngs and mul ti pl e chil dren. Onl y modul e objects and
process obj ects can have chi ldren.
An sc_object i s a chi l d of a module i nstance if and only i f that obj ect li es wi thi n the modul e instance, as
def ined in 3.1.4. An sc_object is a chi l d of a process instance i f and onl y if that object was created duri ng
the executi on of the function associ ated wi th that process i nstance. Obj ect P is a parent of object C i f and
only if C is a chil d of P.
An sc_object that has no parent obj ect i s said to be a top-l evel object. Modul e i nstances, spawned process
instances, and obj ects of an appl ication-defi ned cl ass deri ved from cl ass sc_object may be top-l evel obj ects.
Each call to f unction sc_spawnshall create a spawned process i nstance that is either a chi ld of the cal ler or a
top-l evel object. The parent of the spawned process instance so created may be another spawned process
instance, an unspawned process instance, or a module instance. Alternatively, the spawned process instance
may be a top-l evel object.
Each sc_object shal l have a unique hi erarchical name ref lecting its posi ti on i n the object hierarchy.
Except where expl icitly f orbidden (as is the case for the cl asses sc_module, sc_port, sc_export, and
sc_prim_channel), objects of a class derived f rom sc_object may be deleted at any ti me. When such an
sc_object i s deleted, it ceases to be a chi ld. The object associated wi th a process i nstance shall not be del eted
whil e the process has surviving chil dren, but i t may be deleted by the impl ementation once al l its chi ld
objects have been deleted.
Attributes may be added to each sc_object.
NOTEAn implementation may permit multiple top-level sc_objects (see 4.3).
5.16.2 Class definition
namespace sc_core {
class sc_object
{
publ ic:
const char* name() const;
const char* basename() const;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


125
Copyright 2012 IEEE. All rights reserved.
virtual const char* kind() const;
virtual void print( std::ostream& = std::cout ) const;
virtual void dump( std::ostream& = std::cout ) const;
virtual const std::vector<sc_object* >& get_child_objects() const;
virtual const std::vector<sc_event* >& get_child_events() const;
sc_object* get_parent_object() const;
bool add_attribute( sc_attr_base& );
sc_attr_base* get_attribute( const std::stri ng& );
const sc_attr_base* get_attribute( const std::string& ) const;
sc_attr_base* remove_attribute( const std::string& );
void remove_all_attributes();
int num_attributes() const;
sc_attr_cltn& attr_cltn();
const sc_attr_cltn& attr_cltn() const;
protected:
sc_object();
sc_object(const char* );
sc_object( const sc_obj ect& );
sc_object& operator= ( const sc_obj ect& );
virtual ~sc_object();
} ;
const std::vector<sc_object* >& sc_get_top_level_objects();
sc_object* sc_find_object( const char* );
} // namespace sc_core
5.16.3 Constraints on usage
An appli cation may use class sc_object as a base class f or other classes besi des modul es, ports, exports,
pri mitive channels, and processes. An appli cation may access the hierarchi cal name of such an object or may
add attri butes to such an obj ect.
An appl ication shal l not def ine a class that has two or more base class sub-obj ects of class sc_object.
Objects of class sc_object may be i nstantiated duri ng el aboration or may be instantiated during simul ation.
However, modul es, ports, exports, and primitive channels can only be i nstantiated during el aboration. It is
permi tted to create a channel that is nei ther a hierarchi cal channel nor a primitive channel but i s nonethel ess
derived from cl ass sc_object, and to instantiate such a channel ei ther during el aboration or simul ation.
Portless channel access is permi tted for any channel , but a port or export cannot be bound to a channel that i s
instanti ated duri ng simul ation.
NOTE 1Because the constructors are protected, cl ass sc_object cannot be i nstanti ated di rectl y.
NOTE 2Since the classes having sc_object as a di rect base cl ass (that is, sc_module, sc_port, sc_export, and
sc_prim_channel) have cl ass sc_object as a non-virtual base cl ass, any cl ass deri ved f rom these cl asses can have at
most one direct base cl ass deri ved f rom class sc_object. I n other words, mul ti pl e i nheri tance f rom the cl asses deri ved
f rom cl ass sc_object i s not permi tted.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


126
Copyright 2012 IEEE. All rights reserved.
5.16.4 Constructors and destructor
sc_object();
sc_object(const char* );
Both constructors shal l register the sc_object as part of the obj ect hi erarchy and shall construct a
hierarchi cal name for the obj ect usi ng the stri ng name passed as an argument. Cal li ng the constructor
sc_object(const char*) with an empty string shall have the same behavior as the def aul t constructor; that i s,
the stri ng name shall be set to "object".
The rules f or composing a hi erarchi cal name are given i n 5.17.
I f the constructor needs to substi tute a new string name i n place of the ori gi nal stri ng name as the resul t of a
name clash, the constructor shall generate a single warni ng.
sc_object( const sc_obj ect& arg );
The copy constructor shal l create a new sc_object as if i t had been created by the cal l sc_object(
arg.basename() ). I n other words, the new obj ect shal l be a chi ld of a module i nstance i f created
f rom the constructor of that modul e or a chi ld of a process instance i f created from the functi on asso-
ciated wi th that process. The string name of the existi ng obj ect shall be used as the seed f or the string
name of the new object. Attri butes or chi ldren of the existing object shall not be copied to the new
object.
sc_object& operator= ( const sc_obj ect& );
The assi gnment operator shall not modif y the hierarchi cal name or the parent of the destinati on
object in the object hi erarchy. In other words, the desti nation object shall retain i ts current position
in the obj ect hierarchy. Attributes and chi ldren of the destination object shall not be modi fi ed.
operator= shall return a ref erence to *this.
virtual ~sc_object();
The destructor shall del ete the obj ect, shall del ete any attribute collection attached to the object, and
shal l remove the object f rom the obj ect hierarchy such that it is no l onger a chil d.
NOTEIf an implementation were to create internal objects of class sc_object, the i mpl ementati on woul d be obl i ged by
the rul es of thi s subcl ause to excl ude those obj ects f rom the obj ect hi erarchy and from the namespace of hierarchi cal
names. Thi s woul d necessitate an extensi on to the semanti cs of cl ass sc_object, and the i mplementati on woul d be
obl iged to make such an extension transparent to the appl i cati on.
5.16.5 name, basename, and kind
const char* name() const;
Member function name shall return the hi er ar chi cal name of the sc_object i nstance i n the object
hierarchy.
const char* basename() const;
Member f uncti on basenameshall return the stri ng name of the sc_object instance. Thi s i s the stri ng
name created when the sc_object instance was constructed.
virtual const char* kind() const;
Member f unction kind returns a character string i dentif yi ng the ki nd of the sc_object. Member
f uncti on kind of class sc_object shal l return the stri ng "sc_object". Every cl ass that is part of the
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


127
Copyright 2012 IEEE. All rights reserved.
implementati on and that i s derived f rom cl ass sc_object shal l override member f uncti on kind to
return an appropriate string.
Exampl e:
#include "systemc.h"
SC_MODULE(Mod)
{
sc_port<sc_si gnal _i n_i f<i nt> > p;
SC_CTOR(Mod) // p.name() returns "top.mod.p"
: p("p") // p.basename() returns "p"
{ } // p.ki nd() returns "sc_port"
} ;
SC_MODULE(Top)
{
Mod * mod; // mod->name() returns "top.mod"
sc_signal <int> si g; // si g.name() returns "top.sig"
SC_CTOR(Top)
: sig("si g")
{
mod = new Mod("mod");
mod->p(si g);
}
} ;
int sc_main(i nt argc, char* argv[] )
{
Top top("top"); // top.name() returns "top"
sc_start();
return 0;
}
5.16.6 print and dump
virtual void print( std::ostream& = std::cout ) const;
Member f uncti on print shall print the character string returned by member function name to the
stream passed as an argument. No additi onal characters shall be printed.
virtual void dump( std::ostream& = std::cout ) const;
Member f uncti on dump shal l pri nt at least the name and the kind of the sc_object to the stream
passed as an argument. The formatting shall be impl ementation-dependent. The purpose of dump is
to all ow an impl ementation to pri nt diagnostic informati on to help the user debug an applicati on.
5.16.7 Functions for object hierarchy traversal
The four f uncti ons in this subcl ause return i nformation that supports the traversal of the object hierarchy. An
impl ementation shall allow each of these f our functi ons to be call ed at any stage during el aboration or
simul ation. I f cal led before el aboration i s complete, they shal l return inf ormati on concerning the partiall y
constructed obj ect hierarchy as i t exi sts at the ti me the f uncti ons are cal led. In other words, a f uncti on shal l
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


128
Copyright 2012 IEEE. All rights reserved.
return poi nters to any objects that have been constructed before the time the function is call ed but wil l
excl ude any objects constructed after the function is cal led.
virtual const std::vector<sc_object* >& get_child_objects() const;
Member f uncti on get_child_objectsshall return a std::vector containi ng a pointer to every i nstance
of class sc_object that i s a child of the current sc_object i n the obj ect hierarchy. The vi rtual functi on
sc_object::get_child_objects shall return an empty vector but shal l be overri dden by the
impl ementation in those cl asses derived from cl ass sc_object that do have chi ldren, that i s, class
sc_module and the impl ementation-defi ned classes associ ated with spawned and unspawned
process instances.
virtual const std::vector<sc_event* >& get_child_events() const;
Member functi on get_child_eventsshall return a std::vector contai ni ng a poi nter to every object of
type sc_event that i s a hierarchi cal ly named event and whose parent is the current obj ect. The virtual
f uncti on sc_object::get_child_events shall return an empty vector but shal l be overri dden by the
impl ementation in those cl asses derived from cl ass sc_object that do have chi ldren, that i s, class
sc_module and the impl ementation-defi ned classes associ ated with spawned and unspawned
process instances.
sc_object* get_parent_object() const;
Member function get_parent_object shal l return a pointer to the sc_object that i s the parent of the
current object in the obj ect hierarchy. If the current obj ect i s a top-level object, member function
get_parent_object shall return the nul l pointer. If the parent object i s a process instance and that
process has terminated, get_parent_object shal l return a poi nter to that process instance. A process
instance shall not be del eted (nor any associ ated process handl es i nval idated) while the process has
surviving chi ldren, but it may be deleted once al l i ts chi ld obj ects have been deleted.
const std::vector<sc_object* >& sc_get_top_level_objects();
Function sc_get_top_level_objectsshal l return a std::vector containing pointers to all of the top-
level sc_objects.
sc_object* sc_find_object( const char* );
Function sc_find_object shal l return a pointer to the sc_object that has a hierarchi cal name that
exactl y matches the val ue of the string argument or shall return the nul l poi nter if there is no
sc_object havi ng a matching name.
Exampl es:
void scan_hi erarchy(sc_object* obj ) // Traverse the enti re obj ect subhierarchy
// bel ow a given obj ect
{
std::vector<sc_obj ect* > chil dren = obj ->get_chi ld_obj ects();
f or ( unsi gned i = 0; i < chi ldren.si ze(); i++ )
if ( chil dren[ i] )
scan_hi erarchy( children[ i] );
}
std::vector<sc_obj ect* > tops = sc_get_top_l evel_objects();
f or ( unsi gned i = 0; i < tops.size(); i++ )
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


129
Copyright 2012 IEEE. All rights reserved.
if ( tops[i ] )
scan_hi erarchy( tops[ i] ); // Traverse the object hierarchy bel ow
// each top-l evel object
sc_object* obj = sc_fi nd_object("f oo.f oobar"); // Find an obj ect gi ven i ts hi erarchical name
sc_module* m;
if (m = dynamic_cast<sc_module* >(obj )) // Test whether the given object i s a modul e
... // The given obj ect i s a modul e

sc_object* parent = obj->get_parent_obj ect(); // Get the parent of the gi ven obj ect
if (parent) // parent is a null poi nter f or a top-level obj ect
std::cout << parent->name() << " " << parent->kind();// Print the name and kind
5.16.8 Member functions for attributes
bool add_attribute( sc_attr_base& );
Member f unction add_attributeshal l attempt to attach to the obj ect of class sc_object the attri bute
passed as an argument. I f an attri bute having the same name as the new attribute is already attached
to this obj ect, member function add_attributeshal l not attach the new attribute and shall return the
val ue false. Otherwise, member function add_attribute shal l attach the new attri bute and shall
return the value true. The argument should be an object of cl ass sc_attribute, not sc_attr_base.
The l if etime of an attribute shall extend unti l the attribute has been completel y removed f rom al l
objects. If an appli cati on del etes an attribute that is stil l attached to an obj ect, the behavi or of the
impl ementation shall be undef ined.
sc_attr_base* get_attribute( const std::stri ng& );
const sc_attr_base* get_attribute( const std::string& ) const;
Member functi on get_attribute shall attempt to retrieve f rom the object of class sc_object an
attri bute havi ng the name passed as an argument. If an attribute with the gi ven name is attached to
thi s object, member f unction get_attribute shall return a pointer to that attribute. Otherwi se,
member f uncti on get_attributeshall return the null poi nter.
sc_attr_base* remove_attribute( const std::string& );
Member f uncti on remove_attributeshall attempt to remove f rom the obj ect of class sc_object an
attri bute havi ng the name passed as an argument. If an attribute with the gi ven name is attached to
thi s obj ect, member function remove_attribute shal l return a pointer to that attri bute and remove
the attribute f rom this obj ect. Otherwi se, member functi on remove_attributeshall return the nul l
pointer.
void remove_all_attributes();
Member functi on remove_all_attributes shall remove al l attributes f rom the obj ect of class
sc_object.
int num_attributes() const;
Member functi on num_attributes shall return the number of attributes attached to the object of
class sc_object.
sc_attr_cltn& attr_cltn();
const sc_attr_cl tn& attr_cltn() const;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


130
Copyright 2012 IEEE. All rights reserved.
Member f unction attr_cltn shal l return the col lecti on of attributes attached to the object of cl ass
sc_object (see 5.20).
NOTEA pointer returned fromfunction get_attributeneeds to be cast to type sc_attribute<T>* in order to
access data member valueof cl ass sc_attribute.
Exampl e:
sc_signal <int> si g;
...
// Add an attribute to an sc_object
sc_attri bute<i nt> a("number", 1);
sig.add_attribute(a);
// Retri eve the attri bute by name and modif y the value
sc_attri bute<i nt>* ap;
ap = (sc_attribute<i nt>* )sig.get_attribute("number");
++ ap->value;
5.17 Hierarachical naming of objects and events
This clause describes the rul es that determi ne the hierarchi cal nami ng of obj ects of type sc_object and of
hierarchi call y named events. The nami ng of events that are not hi erarchical ly named is descri bed in 5.10.4.
namespace sc_core {
bool sc_hierarchical_name_exists( const char* );
} // namespace sc_core
Function sc_hierarchical_name_exists shall return the val ue true if and only if the value of the string
argument exactl y matches the hierarchi cal name of an sc_object or of a hierarchi cal ly named event. I f the
val ue of the string argument exactly matches an impl ementation-def ined event name, f unction
sc_hierarchical_name_exists shall return the value false unless the string argument al so matches a
hierarchi cal name.
A hierarchi cal name shal l be composed of a set of string names separated by the period character '.', starting
wi th the stri ng name of a top-l evel sc_object i nstance and including the string name of each modul e instance
or process i nstance descendi ng down through the object hi erarchy unti l the current sc_object or sc_event is
reached. The hierarchi cal name shall end with the string name of the sc_object or sc_event itsel f.
Hi erarchical names are case-sensi ti ve.
I t shal l be an error i f a stri ng name i ncl udes the peri od character (.) or any white-space characters. I t is
strongly recommended that an appli cati on l imit the character set of a string name to the fol lowing:
a) Lowercase letters az
b) Uppercase letters AZ
c) Decimal digits 09
d) Underscore character _
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


131
Copyright 2012 IEEE. All rights reserved.
An i mplementati on may generate a warning if a stri ng name contai ns characters outsi de thi s set but is not
obl iged to do so.
There shall be a si ngl e gl obal namespace f or hierarchi cal names. Each sc_object and each hierarchi cal ly
named sc_event shall have a uni que non-empty hierarchical name. An i mplementati on shal l not add any
names to thi s namespace other than the hierarchi cal names of sc_objects expli ci tl y constructed by an
appl ication and the hierarchi cal names of hierarchicall y named events.
The constructor shall bui ld a hi erarchi cal name f rom the stri ng name (either passed in as an argument or the
def aul t name "object" f or an sc_object or "event" for an sc_event) and test whether that hierarchi cal name
is unique. If it i s unique, that hi erarchi cal name shall become the hi erarchical name of the object. If not, the
constructor shall cal l function sc_gen_unique_name, passi ng the stri ng name as a seed. It shal l use the
val ue returned as a replacement f or the string name and shal l repeat thi s process unti l a uni que hi erarchical
name i s generated.
I f f uncti on sc_gen_unique_name i s call ed more than once i n the course of constructing any gi ven object,
the choi ce of seed passed to sc_gen_unique_name on the second and subsequent call s shal l be
implementation-def ined but shal l i n any case be ei ther the stri ng name passed as the seed on the fi rst such
cal l or shall be one of the stri ng names returned from sc_gen_unique_namei n the course of constructi ng
the given object. In other words, the fi nal stri ng name shall have the original string name as a prefi x.
5.18 sc_attr_base
5.18.1 Description
Cl ass sc_attr_basei s the base cl ass f or attributes, stori ng onl y the name of the attri bute. The name is used as
a key when retrieving an attri bute f rom an obj ect. Every attribute attached to a specif ic obj ect shall have a
unique name but two or more attri butes wi th identical names may be attached to distinct obj ects.
5.18.2 Class definition
namespace sc_core {
class sc_attr_base
{
publ ic:
sc_attr_base( const std::string& );
sc_attr_base( const sc_attr_base& );
virtual ~sc_attr_base();
const std::string& name() const;
pri vate:
// Di sabl ed
sc_attr_base();
sc_attr_base& operator= ( const sc_attr_base& );
} ;
} // namespace sc_core
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


132
Copyright 2012 IEEE. All rights reserved.
5.18.3 Member functions
The constructors f or classsc_attr_baseshal l set the name of the attri bute to the string passed as an argument
to the constructor.
Member f uncti on nameshal l return the name of the attribute.
5.19 sc_attribute
5.19.1 Description
Cl ass sc_attribute stores the val ue of an attribute. I t i s derived from class sc_attr_base, whi ch stores the
name of the attri bute. An attri bute can be attached to an obj ect of class sc_object.
5.19.2 Class definition
namespace sc_core {
templ ate <class T>
class sc_attribute
: publi c sc_attr_base
{
publ ic:
sc_attribute( const std::string& );
sc_attribute( const std::string&, const T& );
sc_attribute( const sc_attribute<T>& );
virtual ~sc_attribute();
T val ue;
pri vate:
// Di sabl ed
sc_attribute();
sc_attri bute<T>& operator= ( const sc_attribute<T>& );
} ;
} // namespace sc_core
5.19.3 Template parameters
The argument passed to template sc_attributeshal l be of a copy-constructi bl e type.
5.19.4 Member functions and data members
The constructors shal l set the name and value of the attri bute using the name (of type std::string) and val ue
(of type T) passed as arguments to the constructor. I f no value i s passed to the constructor, the default
constructor (of type T) shall be cal led to construct the value.
Data member valueis the val ue of the attri bute. An appl ication may read or assi gn this publi c data member.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


133
Copyright 2012 IEEE. All rights reserved.
5.20 sc_attr_cltn
5.20.1 Description
Cl ass sc_attr_cltn is a container class for attri butes, as used in the implementation of cl ass sc_object. It
provides i terators f or traversing al l of the attri butes in an attribute col lection.
5.20.2 Class definition
namespace sc_core {
class sc_attr_cltn
{
publ ic:
typedef sc_attr_base* elem_type;
typedef el em_type* iterator;
typedef const elem_type* const_iterator;
iterator begin();
const_i terator begin() const;
iterator end();
const_i terator end() const;
// Other members
I mpl ementati on-defi ned
pri vate:
// Di sabl ed
sc_attr_cltn( const sc_attr_cl tn& );
sc_attr_cltn& operator= ( const sc_attr_cl tn& );
} ;
} // namespace sc_core
5.20.3 Constraints on usage
An appl ication shall not expli ci tly create an object of class sc_attr_cltn. An appli cation may use the
iterators to traverse the attribute collecti on returned by member f uncti on attr_cltn of class sc_object.
An i mplementati on is only obl iged to keep an attri bute col lecti on val id unti l a new attri bute is attached to the
sc_object or an existi ng attri bute i s removed f rom the sc_object in questi on. Hence, an appl ication should
traverse the attribute col lecti on i mmedi ately on return f rom member f uncti on attr_cltn.
5.20.4 Iterators
iterator begin();
const_i terator begin() const;
iterator end();
const_i terator end() const;
Member function beginshall return a pointer to the fi rst el ement of the coll ecti on. Each el ement of
the col lecti on i s i tsel f a poi nter to an attribute.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


134
Copyright 2012 IEEE. All rights reserved.
Member functi on end shall return a poi nter to the element f oll owing the last el ement of the
col lecti on.
Exampl e:
sc_signal <int> si g;
...
// Iterate through al l the attri butes of an sc_object
sc_attr_cltn& c = sig.attr_cl tn();
f or (sc_attr_cltn::iterator i = c.begi n(); i < c.end(); i++)
{
sc_attri bute<i nt>* ap = dynamic_cast<sc_attri bute<i nt>* >(* i );
if (ap) std::cout << ap->name() << "=" << ap->val ue << std::endl ;
}
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


135
Copyright 2012 IEEE. All rights reserved.
6. Predefined channel class definitions
6.1 sc_signal_in_if
6.1.1 Description
Cl ass sc_signal_in_if is an i nterf ace proper used by predef ined channels, including sc_signal. Interface
sc_signal_in_if gives read access to the value of a si gnal.
6.1.2 Class definition
namespace sc_core {
templ ate <class T>
class sc_signal_in_if
: vi rtual publi c sc_i nterf ace
{
publ ic:
virtual const T& read() const = 0;
virtual const sc_event& value_changed_event() const = 0;
virtual bool event() const = 0;
protected:
sc_signal_in_if();
pri vate:
// Di sabl ed
sc_signal_in_if( const sc_si gnal _i n_i f<T>& );
sc_signal _in_if <T>& operator= ( const sc_si gnal_i n_i f<T>& );
} ;
} // namespace sc_core
6.1.3 Member functions
The f oll owing member functions are all pure vi rtual functi ons. The descriptions refer to the expected
def ini ti ons of the functions when overri dden i n a channel that impl ements this i nterf ace. The preci se
semanti cs wi ll be channel -speci fi c.
Member f uncti on read shall return a ref erence to the current val ue of the channel.
Member functi on value_changed_event shall return a reference to an event that i s noti fi ed whenever the
val ue of the channel i s written or modifi ed.
Member f uncti on event shall return the val ue true if and onl y i f the val ue of the channel was written or
modif ied in the immediatel y preceding delta cycl e and at the current si mulati on time.
NOTEThe value of the channel may have been modified i n the eval uati on phase or i n the update phase of the
i mmedi atel y precedi ng del ta cycl e, dependi ng on whether it i s a hi erarchi cal channel or a pri mi ti ve channel (f or
exampl e, sc_signal).
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


136
Copyright 2012 IEEE. All rights reserved.
6.2 sc_signal_in_if<bool> and sc_signal_in_if<sc_dt::sc_logic>
6.2.1 Description
Cl asses sc_signal_in_if<bool> and sc_signal_in_if<sc_dt::sc_logic> are interfaces proper that provide
addi ti onal member f uncti ons appropriate f or two-val ued signal s.
6.2.2 Class definition
namespace sc_core {
templ ate <>
class sc_signal_in_if<bool>
: vi rtual publi c sc_i nterf ace
{
publ ic:
virtual const T& read() const = 0;
virtual const sc_event& value_changed_event() const = 0;
virtual const sc_event& posedge_event() const = 0;
virtual const sc_event& negedge_event() const = 0;
virtual bool event() const = 0;
virtual bool posedge() const = 0;
virtual bool negedge() const = 0;
protected:
sc_signal_in_if();
pri vate:
// Di sabl ed
sc_signal_in_if( const sc_si gnal_i n_i f<bool>& );
sc_signal _in_if <bool >& operator= ( const sc_si gnal_i n_i f<bool>& );
} ;
templ ate <>
class sc_signal_in_if<sc_dt::sc_logic>
: vi rtual publi c sc_i nterf ace
{
publ ic:
virtual const T& read() const = 0;
virtual const sc_event& value_changed_event() const = 0;
virtual const sc_event& posedge_event() const = 0;
virtual const sc_event& negedge_event() const = 0;
virtual bool event() const = 0;
virtual bool posedge() const = 0;
virtual bool negedge() const = 0;
protected:
sc_signal_in_if();
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


137
Copyright 2012 IEEE. All rights reserved.
pri vate:
// Di sabl ed
sc_signal_in_if( const sc_si gnal_i n_i f<sc_dt::sc_logic>& );
sc_signal _in_if <sc_dt::sc_logi c>& operator= ( const sc_si gnal_i n_i f<sc_dt::sc_logic>& );
} ;
} // namespace sc_core
6.2.3 Member functions
The f ol lowi ng li st is i ncomplete. For the remai ning member functi ons, refer to the defi nitions of the member
f uncti ons for cl ass sc_signal_in_if (see 6.1.3).
Member functi on posedge_event shall return a ref erence to an event that i s notif ied whenever the val ue of
the channel (as returned by member f unction read) changes and the new val ue of the channel i s trueor '1'.
Member functi on negedge_event shall return a ref erence to an event that is notif ied whenever the val ue of
the channel (as returned by member f unction read) changes and the new val ue of the channel i s falseor '0'.
Member functi on posedgeshall return the val ue true if and onl y i f the value of the channel changed in the
update phase of the immedi ately preceding del ta cycl e and at the current simul ation ti me, and the new val ue
of the channel is trueor '1'.
Member function negedgeshall return the value truei f and onl y if the val ue of the channel changed in the
update phase of the immedi ately preceding del ta cycl e and at the current simul ation ti me, and the new val ue
of the channel is false or '0'.
6.3 sc_signal_inout_if
6.3.1 Description
Cl ass sc_signal_inout_if i s an i nterf ace proper that i s used by predef ined channels, i ncludi ng sc_signal.
I nterf ace sc_signal_inout_if gives both read and wri te access to the value of a si gnal , and it is derived from
a further interface proper sc_signal_write_if.
6.3.2 Class definition
namespace sc_core {
enum sc_writer_policy
{
SC_ONE_WRI TER,
SC_MANY_WRITERS
} ;
templ ate <class T>
class sc_signal_write_if
: vi rtual publi c sc_i nterf ace
{
publ ic:
virtual sc_writer_pol icy get_writer_policy() const { return SC_ONE_WRI TER; }
virtual void write( const T& ) = 0;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


138
Copyright 2012 IEEE. All rights reserved.
protected:
sc_signal_write_if();
pri vate:
// Di sabl ed
sc_signal_write_if( const sc_si gnal _wri te_i f<T>& );
sc_signal _wri te_if <T>& operator= ( const sc_si gnal_write_i f<T>& );
} ;
templ ate <class T>
class sc_signal_inout_if
: publi c sc_signal_in_i f<T> , publ ic sc_si gnal _write_i f<T>
{
protected:
sc_signal_inout_if();
pri vate:
// Di sabl ed
sc_signal_inout_if( const sc_si gnal _i nout_if <T>& );
sc_signal _inout_if <T>& operator= ( const sc_si gnal _i nout_if <T>& );
} ;
} // namespace sc_core
6.3.3 Member functions
The f ollowi ng text describes the expected def ini ti ons of the member f unctions when overri dden i n a channel
that i mplements this interface. The precise semantics will be channel-speci fi c.
virtual sc_writer_pol icy get_writer_policy() const { return SC_ONE_WRITER; }
Member f uncti on get_writer_policy shall return the val ue of the writer pol icy f or the channel
instance. Unless overri dden i n a channel , this f unction shall return the val ue SC_ONE_WRITER f or
backward compatibil ity with previous versi ons of thi s standard.
virtual void write( const T& ) = 0;
Member function writeshal l modi fy the val ue of the channel such that the channel appears to have
the new val ue (as returned by member function read) i n the next del ta cycl e but not before then. The
new val ue is passed as an argument to the f unction.
Member functi on writeshall honor the val ue of the writer poli cy set for the channel i nstance; that i s,
it shall permi t either one wri ter or many wri ters.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


139
Copyright 2012 IEEE. All rights reserved.
6.4 sc_signal
6.4.1 Description
Cl ass sc_signal is a predef ined primiti ve channel i ntended to model the behavior of a si ngl e pi ece of wi re
carryi ng a digital el ectronic signal .
6.4.2 Class definition
namespace sc_core {
templ ate <cl ass T, sc_wri ter_poli cy WRITER_POLICY = SC_ONE_WRITER>
class sc_signal
: publi c sc_signal_inout_i f<T>, publ ic sc_pri m_channel
{
publ ic:
sc_signal();
expl icit sc_signal( const char* );
virtual ~sc_signal();
virtual void register_port( sc_port_base&, const char* );
virtual const T& read() const;
operator const T& () const;
virtual sc_writer_pol icy get_writer_policy() const;
virtual void write( const T& );
sc_signal<T,WRI TER_POLICY>& operator= ( const T& );
sc_signal<T,WRI TER_POLICY>& operator= ( const sc_si gnal<T,WRITER_POLI CY>& );
virtual const sc_event& default_event() const;
virtual const sc_event& value_changed_event() const;
virtual bool event() const;
virtual void print( std::ostream& = std::cout ) const;
virtual void dump( std::ostream& = std::cout ) const;
virtual const char* kind() const;
protected:
virtual void update();
pri vate:
// Di sabl ed
sc_signal( const sc_si gnal <T,WRI TER_POLI CY>& );
} ;
templ ate <cl ass T, sc_writer_pol icy WRI TER_POLICY>
inl ine std::ostream& operator<< ( std::ostream&, const sc_signal <T,WRI TER_POLI CY>& );
} // namespace sc_core
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


140
Copyright 2012 IEEE. All rights reserved.
6.4.3 Template parameter T
The argument passed to templatesc_signal shall be either a C++ type for whi ch the predefi ned semantics f or
assignment and equali ty are adequate (for exampl e, a f undamental type or a pointer), or a type T that obeys
each of the fol lowing rul es:
a) The f oll owing equali ty operator shall be defi ned for the type T and shoul d return the val ue trueif
and onl y if the two val ues being compared are to be regarded as indisti nguishabl e for the purposes of
signal propagation (that is, an event occurs onl y i f the val ues are dif ferent). The impl ementation
shal l use this operator wi thi n the impl ementation of the si gnal to determine whether an event has
occurred.
bool T::operator== ( const T& );
b) The f ol lowi ng stream operator shall be defi ned and should copy the state of the obj ect given as the
second argument to the stream given as the fi rst argument. The way in whi ch the state i nf ormation i s
f ormatted is undef ined by this standard. The i mplementati on shal l use this operator i n i mplementi ng
the behavior of the member f unctions print and dump.
std::ostream& operator<< ( std::ostream&, const T& );
c) I f the def aul t assignment semantics are i nadequate (i n the sense given in this subcl ause), the
f ol lowi ng assignment operator should be def ined for the type T. I n either case (def aul t assignment or
expl icit operator), the semantics of assi gnment shoul d be suf fi ci ent to assi gn the state of an object of
type T such that the val ue of the left operand i s indistingui shable from the value of the ri ght operand
usi ng the equal ity operator mentioned i n thi s subclause. The i mplementati on shall use this
assignment operator wi thi n the i mplementati on of the signal when assi gni ng or copying values of
type T.
const T& operator= ( const T& );
d) I f any constructor f or type T exi sts, a def aul t constructor for type T shal l be defi ned.
e) I f the cl ass template is used to defi ne a signal to which a port of type sc_in, sc_inout, or sc_out is
bound, the foll owing function shall be defi ned:
void sc_trace( sc_trace_f il e* , const T&, const std::string& );
NOTE 1The equality and assignment operators are not obl i ged to compare and assi gn the compl ete state of the obj ect,
al though they shoul d typi call y do so. For exampl e, diagnosti c i nf ormati on may be associated wi th an obj ect that is not to
be propagated through the si gnal .
NOTE 2The SystemC data types proper (sc_dt::sc_int, sc_dt::sc_logic, and so f orth) all conf orm to the rul e set j ust
gi ven.
NOTE 3It is illegal to pass class sc_module (for exampl e) as a templ ate argument to cl ass sc_signal, because
sc_module::operator== does not exi st. I t i s l egal to pass type sc_module* through a si gnal , al though this woul d be
regarded as an abuse of the module hi erarchy and thus bad practi ce.
6.4.4 Reading and writing signals
A signal is r ead by call ing member functi on read or operator const T& ().
A si gnal i swr i tten by cal li ng member function writeor operator= of the given signal obj ect. If the templ ate
argument WRI TER_POLI CY has the value SC_ONE_WRITER, it shal l be an error to wri te to a given
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


141
Copyright 2012 IEEE. All rights reserved.
signal instance from more than one process instance at any ti me during si mulation. I f the templ ate argument
WRITER_POLICY has the value SC_MANY_WRITERS, it shal l be an error to wri te to a given signal
instance f rom more than one process i nstance during any gi ven eval uation phase, but dif ferent process
instances may wri te to a given si gnal i nstance during di f ferent delta cycl es. A si gnal may be written duri ng
elaboration (including the elaborati on and si mulation cal lbacks as described in 4.4) to ini ti al ize the val ue of
the si gnal . A signal may be wri tten from function sc_main during el aboration or whil e si mul ation i s paused,
that i s, before or after the cal l to f uncti on sc_start.
Signals are typicall y read and written duri ng the eval uation phase, but the val ue of the si gnal is onl y
modif ied during the subsequent update phase. If and onl y i f the val ue of the si gnal actual ly changes as a
result of being written, an event (the val ue-changed event) shall be notif ied in the del ta notif i cati on phase
that i mmediately f ol lows.
I f a gi ven signal is written on mul ti pl e occasions withi n a particular eval uation phase, or during el aboration,
or f rom f unction sc_main, the val ue to which the si gnal changes in the i mmediately f ollowi ng update phase
shal l be determined by the most recent wri te; that i s, the l ast wr i te wi ns.
NOTE 1The specialized ports sc_inout and sc_out have a member f uncti on initializef or the purpose of i ni ti al i zi ng
the value of a signal duri ng el aborati on.
NOTE 2If the value of a signal is read duri ng el aborati on, the val ue returned wi l l be the i niti al val ue of the si gnal as
created by the def aul t constructor f or type T.
NOTE 3If a given signal is written and read during the same evaluati on phase, the ol d val ue wi l l be read. The val ue
written wi l l not be avai lable to be read unti l the subsequent eval uati on phase.
6.4.5 Constructors
sc_signal();
This constructor shall cal l the base class constructor f rom i ts ini tial izer li st as f ol lows:
sc_pri m_channel ( sc_gen_uni que_name( "si gnal" ) )
expl icit sc_signal( const char* name_ );
This constructor shall cal l the base class constructor f rom i ts ini tial izer li st as f ol lows:
sc_pri m_channel ( name_ )
Both constructors shal l initial ize the val ue of the signal by cal li ng the def aul t constructor for type T f rom
their initial izer li sts.
6.4.6 register_port
virtual void register_port( sc_port_base&, const char* );
Member functi on register_port of cl ass sc_interface shall be overridden in cl ass sc_signal and
shal l perf orm the fol lowing error check. If the templ ate argument WRI TER_POLI CY has the value
SC_ONE_WRI TER, i t shall be an error to bind more than one port of type sc_signal_inout_if to a
given si gnal . If the WRI TER_POLI CY has the val ue SC_MANY_WRITERS, one or more ports of
type sc_signal_inout_if may be bound to a gi ven signal .
6.4.7 Member functions for reading
virtual const T& read() const;
Member f uncti on readshall return a reference to the current value of the signal but shall not modi fy
the state of the si gnal .
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


142
Copyright 2012 IEEE. All rights reserved.
operator const T& () const;
operator const T& () shall return a reference to the current value of the si gnal (as returned by
member f uncti on read).
6.4.8 Member functions for writing
virtual sc_writer_pol icy get_writer_policy() const;
Member f unction get_writer_policy shal l return the val ue of the WRI TER_POLICY template
parameter f or the channel instance.
virtual void write( const T& );
Member function writeshal l modi fy the val ue of the signal such that the signal appears to have the
new val ue (as returned by member function read) i n the next delta cycle but not bef ore then. Thi s
shal l be accompli shed usi ng the update request mechani sm of the primitive channel . The new value
is passed as an argument to member f uncti on write. Member f unction write may be call ed during
elaborati on, in which case the update request shall be executed duri ng the i ni ti al izati on phase.
operator=
The behavi or of operator= shall be equi val ent to the foll owing def initions:
sc_signal<T,WRI TER_POLICY>& operator= ( const T& arg ) { write( arg ); return * thi s; }
sc_signal<T,WRI TER_POLICY>& operator= ( const sc_si gnal<T,WRITER_POLI CY>& arg ) {
write( arg.read() ); return * this; }
virtual void update();
Member function updateof class sc_prim_channel shal l be overridden by the impl ementation in
class sc_signal to impl ement the updati ng of the si gnal value that occurs as a result of the si gnal
bei ng wri tten. Member f unction updateshal l modif y the current val ue of the si gnal such that it gets
the new value (as passed as an argument to member f uncti on write), and i t shall cause the val ue-
changed event to be notif ied i n the i mmedi ately foll owing del ta notif ication phase i f the val ue of the
signal has changed.
NOTEMember function update i s cal l ed by the schedul er but typi cal l y i s not cal l ed by an appl i cati on.
However, member f uncti on updateof cl ass sc_signal may be cal l ed from member f uncti on updateof a cl ass
deri ved f rom cl ass sc_signal.
6.4.9 Member functions for events
virtual const sc_event& default_event() const;
virtual const sc_event& value_changed_event() const;
Member f uncti ons default_event and value_changed_event shall both return a ref erence to the
value-changed event.
virtual bool event() const;
Member functi on event shall return the value true if and only if the val ue of the si gnal changed i n
the update phase of the immedi atel y preceding delta cycl e and at the current si mulation time; that is,
a member f uncti on writeor operator= was call ed in the immedi ately precedi ng evaluation phase,
and the value wri tten or assi gned was dif ferent f rom the previous value of the signal .
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


143
Copyright 2012 IEEE. All rights reserved.
NOTEMember function event returns tr ue when cal l ed f rom a process that was executed as a di rect resul t of
the val ue-changed event of that same si gnal i nstance bei ng notif i ed.
6.4.10 Diagnostic member functions
virtual void pr int( std::ostream& = std::cout ) const;
Member function pr int shal l print the current val ue of the signal to the stream passed as an
argument by call ing oper ator << (std::ostream& , T& ). No additional characters shall be pri nted.
virtual void dump( std::ostream& = std::cout ) const;
Member f unction dump shall pri nt at least the hi erarchical name, the current value, and the new
val ue of the si gnal to the stream passed as an argument. The formatti ng shall be i mplementati on-
def ined.
virtual const char* kind() const;
Member f uncti on kind shal l return the string " sc_signal" .
6.4.11 operator<<
templ ate <cl ass T, sc_writer_pol icy WRI TER_POLICY>
inl ine std::ostream& oper ator << ( std::ostream& , const sc_ si gnal <T,WRITER_POLI CY>& );
oper ator << shal l pri nt the current value of the signal passed as the second argument to the stream
passed as the f irst argument by cal li ng oper ator << ( std::ostream& , T& ).
Exampl e:
SC_MODULE(M)
{
sc_signal <int> si g;
SC_CTOR(M)
{
SC_THREAD(wri ter);
SC_THREAD(reader);
SC_METHOD(writer2);
sensitive << si g; // Sensitive to the default event
}
void wri ter()
{
wait(50, SC_NS);
sig.wri te(1);
sig.wri te(2);
wait(50, SC_NS);
sig = 3; // Calls operator= ( const T& )
}
void reader()
{
wait(sig.value_changed_event());
int i = si g.read(); // Reads a value of 2
wait(sig.value_changed_event());
i = sig; // Calls operator const T& (), whi ch returns a val ue of 3
}
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


144
Copyright 2012 IEEE. All rights reserved.
void wri ter2()
{
sig.wri te(sig + 1); // An error. A signal shall not have multi ple wri ters
}
} ;
NOTEThe following classes are related to class sc_signal:
The classes sc_signal<bool,WRI TER_POLICY> and sc_signal<sc_dt::sc_logic,WRI TER_POLICY>
provi de addi ti onal member f uncti ons appropri ate f or two-val ued si gnal s.
The class sc_buffer i s derived f rom sc_signal but di ff ers i n that the val ue-changed event i s noti f i ed whenever
the buff er i s wri tten whether or not the value of the buf f er has changed.
The class sc_clock i s deri ved f rom sc_signal and generates a peri odi c cl ock si gnal .
The class sc_signal_r esolved al l ows mul ti pl e wri ters.
The classes sc_in, sc_out, and sc_inout are speci al i zed ports that may be bound to signal s, and whi ch provi de
f uncti ons to access the member f uncti ons of the si gnal conveni entl y through the port.
6.5 sc_signal<bool,WRITER_POLICY> and
sc_signal<sc_dt::sc_logic,WRITER_POLICY>
6.5.1 Description
Cl asses sc_signal<bool,W RI TER_POLI CY > and sc_signal<sc_dt::sc_logic,W RI TER_POLI CY> are
predef ined primi ti ve channels that provi de addi tional member functi ons appropriate for two-valued signals.
6.5.2 Class definition
namespace sc_core {
templ ate <sc_writer_poli cy WRITER_POLICY>
class sc_signal<bool,WRITER_POLICY>
: publi c sc_signal_inout_if <bool >, publ ic sc_prim_channel
{
publ ic:
sc_signal();
expl icit sc_signal( const char* );
virtual ~sc_signal();
virtual void register _por t( sc_port_base&, const char* );
virtual const bool& read() const;
oper ator const bool& () const;
virtual sc_writer_pol icy get_wr iter _policy() const;
virtual void wr ite( const bool & );
sc_signal<bool,WRI TER_POLICY>& oper ator = ( const bool& );
sc_signal<bool,WRI TER_POLICY>& oper ator = ( const sc_si gnal <bool,WRITER_POLI CY>& );
virtual const sc_event& default_event() const;
virtual const sc_event& value_changed_event() const;
virtual const sc_event& posedge_event() const;
virtual const sc_event& negedge_event() const;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


145
Copyright 2012 IEEE. All rights reserved.
virtual bool event() const;
virtual bool posedge() const;
virtual bool negedge() const;
virtual void pr int( std::ostream& = std::cout ) const;
virtual void dump( std::ostream& = std::cout ) const;
virtual const char* kind() const;
protected:
virtual void update();
pri vate:
// Di sabl ed
sc_signal( const sc_si gnal <bool ,WRI TER_POLI CY>& );
} ;
templ ate <sc_writer_poli cy WRITER_POLICY>
class sc_signal<sc_dt::sc_logic,WRITER_POLICY>
: publi c sc_signal_inout_if <sc_dt::sc_l ogi c,WRI TER_POLICY>, publ ic sc_pri m_channel
{
publ ic:
sc_signal();
expl icit sc_signal( const char* );
virtual ~sc_signal();
virtual void register _por t( sc_port_base&, const char* );
virtual const sc_dt::sc_logic& read() const;
oper ator const sc_dt::sc_logic& () const;
virtual void wr ite( const sc_dt::sc_l ogi c& );
sc_signal <sc_dt::sc_l ogi c,WRITER_POLICY>& oper ator = ( const sc_dt::sc_logi c& );
sc_signal <sc_dt::sc_l ogi c,WRITER_POLICY>&
oper ator = ( const sc_si gnal<sc_dt::sc_logic,WRITER_POLICY>& );
virtual const sc_event& default_event() const;
virtual const sc_event& value_changed_event() const;
virtual const sc_event& posedge_event() const;
virtual const sc_event& negedge_event() const;
virtual bool event() const;
virtual bool posedge() const;
virtual bool negedge() const;
virtual void pr int( std::ostream& = std::cout ) const;
virtual void dump( std::ostream& = std::cout ) const;
virtual const char* kind() const;
protected:
virtual void update();
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


146
Copyright 2012 IEEE. All rights reserved.
pri vate:
// Di sabl ed
sc_signal( const sc_si gnal <sc_dt::sc_logic,WRI TER_POLICY>& );
} ;
} // namespace sc_core
6.5.3 Member functions
The f ol lowi ng li st is i ncomplete. For the remai ning member functi ons, refer to the defi nitions of the member
f uncti ons for cl ass sc_signal (see 6.4).
virtual const sc_event& posedge_event () const;
Member f unction posedge_event shal l return a reference to an event that is notif ied whenever the
val ue of the signal (as returned by member f uncti on read) changes and the new value of the signal i s
true or ' 1' .
virtual const sc_event& negedge_event() const;
Member function negedge_event shal l return a ref erence to an event that is notif ied whenever the
val ue of the signal (as returned by member f uncti on read) changes and the new value of the signal i s
false or '0' .
virtual bool posedge () const;
Member functi on posedgeshall return the value true i f and onl y if the val ue of the si gnal changed i n
the update phase of the i mmediatel y precedi ng del ta cycle and at the current simulation time, and the
new val ue of the si gnal is true or ' 1'.
virtual bool negedge() const;
Member functi on negedge shall return the val ue true if and onl y i f the value of the si gnal changed
in the update phase of the immediatel y preceding del ta cycl e and at the current si mulati on time, and
the new value of the si gnal i s false or ' 0'.
Exampl e:
sc_signal <bool > cl k;
...
void thread_process()
{
for (;;)
{
if (clk.posedge())
wait(clk.negedge_event());
...
}
}
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


147
Copyright 2012 IEEE. All rights reserved.
6.6 sc_buffer
6.6.1 Description
Cl ass sc_buffer i s a predefi ned primi ti ve channel deri ved f rom class sc_signal. Cl ass sc_buffer di ff ers f rom
class sc_signal i n that a value-changed event is notif ied whenever the buff er is wri tten rather than only when
the val ue of the signal is changed. A buffer is an object of the class sc_buffer.
6.6.2 Class definition
namespace sc_core {
templ ate <cl ass T, sc_writer_pol icy WRI TER_POLICY>
class sc_buffer
: publi c sc_signal<T,WRITER_POLICY>
{
publ ic:
sc_buffer ();
expl icit sc_buffer( const char* );
virtual void wr ite( const T& );
sc_buff er<T,WRI TER_POLICY>& oper ator = ( const T& );
sc_buff er<T,WRI TER_POLICY>& oper ator = ( const sc_si gnal<T,WRITER_POLI CY>& );
sc_buff er<T,WRI TER_POLICY>& oper ator = ( const sc_buf fer<T,WRI TER_POLI CY>& );
virtual const char* kind() const;
protected:
virtual void update();
pri vate:
// Di sabl ed
sc_buffer ( const sc_buf fer<T,WRI TER_POLI CY>& );
} ;
} // namespace sc_core
6.6.3 Constructors
sc_buffer();
This constructor shall cal l the base class constructor f rom i ts ini tial izer li st as f ol lows:
sc_signal ( sc_gen_uni que_name( "buf fer" ) )
expl icit sc_buffer ( const char* name_ );
This constructor shall cal l the base class constructor f rom i ts ini tial izer li st as f ol lows:
sc_signal ( name_ )
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


148
Copyright 2012 IEEE. All rights reserved.
6.6.4 Member functions
virtual void wr ite( const T& );
Member f unction wr ite shal l modi fy the value of the buf fer such that the buff er appears to have the
new val ue (as returned by member function read) i n the next delta cycle but not bef ore then. Thi s
shal l be accompli shed usi ng the update request mechani sm of the primitive channel . The new value
is passed as an argument to member functi on wr ite.
oper ator =
The behavi or of oper ator = shall be equi val ent to the foll owing def initions:
sc_buff er<T,WRI TER_POLICY>& oper ator = ( const T& arg ) { write( arg ); return * thi s; }
sc_buff er<T,WRI TER_POLICY>&
oper ator = ( const sc_si gnal <T,WRITER_POLI CY>& arg ) { write( arg.read() ); return * this; }
sc_buff er<T,WRI TER_POLICY>&
oper ator = ( const sc_buf fer<T,WRITER_POLI CY>& arg ) { wri te( arg.read() ); return * this; }
virtual void update();
Member f unction update of cl ass sc_signal shal l be overri dden by the i mplementati on i n cl ass
sc_buffer to i mplement the updating of the buff er value that occurs as a resul t of the buf fer bei ng
written. Member f uncti on update shal l modi fy the current val ue of the buff er such that it gets the
new value (as passed as an argument to member f uncti on wr ite) and shall cause the value-changed
event to be notif ied i n the immedi atel y foll owing delta notif ication phase, regardless of whether the
val ue of the buf fer has changed (see 6.4.4 and 6.4.8). (Thi s is in contrast to member function update
of the base class sc_signal, which onl y causes the val ue-changed event to be noti fi ed if the new
val ue i s dif ferent from the old val ue.)
I n other words, suppose the current value of the buf fer is V, and member functi on wr ite i s cal led
wi th argument value V. Functi on wr ite wil l store the new value V (in some impl ementation-defi ned
storage area disti nct f rom the current value of the buff er) and will cal l request_update. Member
f uncti on update wil l be cal led back duri ng the update phase and wi ll set the current val ue of the
buff er to the new val ue V. The current val ue of the buff er wi ll not change, because the ol d value i s
equal to the new val ue but the value-changed event wil l be noti fi ed nonethel ess.
virtual const char* kind() const;
Member f uncti on kind shal l return the string " sc_buffer" .
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


149
Copyright 2012 IEEE. All rights reserved.
Exampl e:
SC_MODULE(M)
{
sc_buff er<int> buf ;
SC_CTOR(M)
{
SC_THREAD(wri ter);
SC_METHOD(reader);
sensitive << buf ;
}
void wri ter()
{
buf.write(1);
wait(SC_ZERO_TI ME);
buf.write(1);
}
void reader()
{ // Executed duri ng i ni ti al izati on and then twice more with buf = 0, 1, 1
std::cout << buf << std::endl ;
}
} ;
6.7 sc_clock
6.7.1 Description
Cl ass sc_clock is a predefi ned pri mi tive channel deri ved f rom the class sc_signal and intended to model the
behavior of a digital cl ock si gnal. A cl ock is an obj ect of the class sc_clock. The val ue and events associ ated
wi th the cl ock are accessed through the interface sc_signal_in_if<bool>.
6.7.2 Class definition
namespace sc_core {
class sc_clock
: publi c sc_signal<bool>
{
publ ic:
sc_clock();
expl icit sc_clock( const char* name_ );
sc_clock( const char* name_,
const sc_time& peri od_,
doubl e duty_cycl e_ = 0.5,
const sc_time& start_ti me_ = SC_ZERO_TI ME,
bool posedge_fi rst_ = true );
sc_clock( const char* name_,
doubl e peri od_v_,
sc_time_uni t peri od_tu_,
doubl e duty_cycl e_ = 0.5 );
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


150
Copyright 2012 IEEE. All rights reserved.
sc_clock( const char* name_,
doubl e peri od_v_,
sc_time_uni t peri od_tu_,
doubl e duty_cycl e_,
doubl e start_ti me_v_,
sc_ti me_uni t start_time_tu_,
bool posedge_fi rst_ = true );
virtual ~sc_clock();
virtual void wr ite( const bool & );
const sc_time& period() const;
doubl e duty_cycle() const;
const sc_time& star t_time() const;
bool posedge_fir st() const;
virtual const char* kind() const;
protected:
virtual void before_end_of_elaboration();
pri vate:
// Di sabl ed
sc_clock( const sc_cl ock& );
sc_clock& oper ator = ( const sc_cl ock& );
} ;
typedef sc_in<bool > sc_in_clk ;
} // namespace sc_core
6.7.3 Characteristic properties
A clock i s characteri zed by the fol lowing properti es:
a) Peri odThe time interval between two consecutive transitions from value false to value true,
which shall be equal to the ti me interval between two consecutive transitions from val ue true to
val ue false. The peri od shal l be greater than zero. The def aul t peri od i s 1 nanosecond.
b) Duty cycl eThe proportion of the period during which the clock has the value true. The duty cycle
shal l li e between the limits 0.0 and 1.0, excl usive. The default duty cycl e i s 0.5.
c) Star t ti meThe absolute time of the first transition of the value of the clock (false to true or true to
false). The def aul t start ti me i s zero.
d) Posedge_fi r stIf posedge_first is true, the clock i s i nitiali zed to the val ue false, and changes from
false to true at the start time. If posedge_fi rst is false, the cl ock i s ini ti al ized to the val ue true, and
changes f rom true to false at the start time. The defaul t value of posedge_f irst i s true.
NOTEA clock does not have a stop time but wil l stop i n any case when f uncti on sc_stop i s cal l ed.
6.7.4 Constructors
The constructors shall set the characteri stic properties of the cl ock as def ined by the constructor arguments.
Any characteristi c property not defi ned by the constructor arguments shal l take a default val ue as def ined i n
6.7.3.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


151
Copyright 2012 IEEE. All rights reserved.
The default constructor shall call the base class constructor f rom i ts initiali zer li st as foll ows:
sc_signal ( sc_gen_uni que_name( "cl ock" ) )
6.7.5 write
virtual void wr ite( const bool & );
I t shal l be an error for an appli cati on to call member f unction wr ite. The member function wr ite of
the base cl ass sc_signal is not appl icabl e to cl ocks.
6.7.6 Diagnostic member functions
const sc_time& period() const;
Member f uncti on period shall return the peri od of the clock.
doubl e duty_cycle() const;
Member f uncti on duty_cycle shall return the duty cycle of the clock.
const sc_time& star t_time() const;
Member f uncti on star t_time shall return the start ti me of the cl ock.
bool posedge_fir st() const;
Member f uncti on posedge_fir st shal l return the value of the posedge_fi rst property of the clock.
virtual const char* kind() const;
Member f uncti on kind shal l return the string " sc_clock".
6.7.7 before_end_of_elaboration
virtual void before_end_of_elaboration();
Member functi on before_end_of_elaboration, whi ch i s def ined i n the cl ass sc_pr im_channel,
shal l be overridden by the impl ementation i n the current cl ass wi th a behavior that is
impl ementation-def ined.
NOTE 1An implementation may use befor e_end_of_elabor ation to spawn one or more stati c processes to generate
the cl ock.
NOTE 2If this member function is overridden i n a cl ass deri ved f rom the current cl ass, f uncti on
befor e_end_of_elabor ation as overri dden i n the current cl ass shoul d be cal led expl i ci tl y f rom the overri dden member
f uncti on of the deri ved cl ass i n order to i nvoke the i mpl ementati on-def i ned behavi or.
6.7.8 sc_in_clk
typedef sc_in<bool > sc_in_clk ;
The typedef sc_in_clk i s provided for conveni ence when adding clock inputs to a modul e and f or
backward compatibi li ty wi th earli er versions of SystemC. An appl icati on may use sc_in_clk or
sc_in<bool> interchangeably.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


152
Copyright 2012 IEEE. All rights reserved.
6.8 sc_in
6.8.1 Description
Cl ass sc_in is a speci alized port cl ass f or use wi th si gnals. I t provides functions to access conveni ently
certain member f uncti ons of the channel to whi ch the port is bound. I t may be used to model an input pin on
a modul e.
6.8.2 Class definition
namespace sc_core {
templ ate <class T>
class sc_in
: publi c sc_port<sc_signal _in_if <T>,1>
{
publ ic:
sc_in();
expl icit sc_in( const char* );
virtual ~sc_in();
virtual void bind ( const sc_si gnal _i n_if <T>& );
void oper ator () ( const sc_si gnal _i n_i f<T>& );
virtual void bind ( sc_port<sc_signal_in_if <T>, 1>& );
void oper ator () ( sc_port<sc_signal_in_i f<T>, 1>& );
virtual void bind ( sc_port<sc_signal _inout_if <T>, 1>& );
void oper ator () ( sc_port<sc_signal _inout_if <T>, 1>& );
virtual void end_of_elabor ation();
const T& read() const;
oper ator const T& () const;
const sc_event& default_event() const;
const sc_event& value_changed_event() const;
bool event() const;
sc_event_f inder& value_changed() const;
virtual const char* kind() const;
pri vate:
// Di sabl ed
sc_in( const sc_in<T>& );
sc_i n<T>& oper ator = ( const sc_in<T>& );
} ;
templ ate <class T>
inl ine voi d sc_trace( sc_trace_f il e* , const sc_i n<T>&, const std::stri ng& );
} // namespace sc_core
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


153
Copyright 2012 IEEE. All rights reserved.
6.8.3 Member functions
The constructors shal l pass their arguments to the corresponding constructor for the base class sc_por t.
The i mplementati on of oper ator () shall achieve i ts eff ect by cal li ng the virtual member f unction bind.
Member function bind shal l call member f unction bind of the base class sc_por t, passing through thei r
parameters as arguments to f unction bind, in order to bind the object of cl ass sc_in to the channel or port
instance passed as an argument.
Member function read and oper ator const T& () shall each cal l member f unction read of the object to
which the port i s bound usi ng oper ator-> of class sc_por t, that i s:
(* this)->read()
Member functi ons default_event, value_changed_event, and event shall each cal l the correspondi ng
member functi on of the object to whi ch the port i s bound usi ng oper ator-> of class sc_por t, for example:
(* this)->event()
Member f uncti on value_changed shall return a reference to class sc_event_finder , where the event f inder
object itself shall be constructed using the member function value_changed_event (see 5.7).
Member f uncti on kind shall return the string " sc_in" .
6.8.4 Function sc_trace
templ ate <class T>
inl ine voi d sc_trace( sc_trace_f il e* , const sc_i n<T>&, const std::stri ng& );
Function sc_trace shal l trace the channel to which the port passed as the second argument i s bound
(see 8.1) by call ing f unction sc_trace with a second argument of type const T& (see 6.4.3). The port
need not have been bound at the point duri ng el aborati on when functi on sc_trace i s cal led. In thi s
case, the impl ementation shal l def er the cal l to trace the signal until af ter the port has been bound
and the identi ty of the signal is known.
6.8.5 end_of_elaboration
virtual void end_of_elabor ation();
Member functi on end_of_elabor ation, which i s defi ned in the class sc_por t, shall be overridden by
the impl ementation in the current class wi th a behavi or that i s i mplementati on-def ined.
NOTE 1An implementation may use end_of_elabor ation to impl ement the def erred cal l to sc_tr ace.
NOTE 2If this member function is overridden in a cl ass deri ved f rom the current cl ass, f uncti on end_of_elabor ation
as overri dden i n the current cl ass should be cal l ed expl i ci tl y f rom the overri dden member f uncti on of the deri ved cl ass in
order to invoke the i mpl ementati on-def i ned behavi or.
6.9 sc_in<bool> and sc_in<sc_dt::sc_logic>
6.9.1 Description
Cl ass sc_in<bool> and sc_in<sc_dt::sc_logic> are speciali zed port classes that provide additi onal member
f uncti ons for two-valued si gnals.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


154
Copyright 2012 IEEE. All rights reserved.
6.9.2 Class definition
namespace sc_core {
templ ate <>
class sc_in<bool>
: publi c sc_port<sc_signal _in_if <bool>,1>
{
publ ic:
sc_in();
expl icit sc_in( const char* );
virtual ~sc_in();
virtual void bind ( const sc_si gnal_i n_i f<bool>& );
void oper ator () ( const sc_si gnal _i n_i f<bool>& );
virtual void bind ( sc_port<sc_signal_in_if <bool >, 1>& );
void oper ator () ( sc_port<sc_signal_in_if <bool >, 1>& );
virtual void bind ( sc_port<sc_signal_inout_if <bool >, 1>& );
void oper ator () ( sc_port<sc_signal_inout_if <bool >, 1>& );
virtual void end_of_elabor ation();
const bool& read() const;
oper ator const bool& () const;
const sc_event& default_event() const;
const sc_event& value_changed_event() const;
const sc_event& posedge_event() const;
const sc_event& negedge_event() const;
bool event() const;
bool posedge() const;
bool negedge() const;
sc_event_f inder& value_changed() const;
sc_event_f inder& pos() const;
sc_event_f inder& neg() const;
virtual const char* kind() const;
pri vate:
// Di sabl ed
sc_in( const sc_in<bool >& );
sc_i n<bool>& oper ator = ( const sc_in<bool >& );
} ;
templ ate <>
inl ine voi d sc_trace<bool>( sc_trace_f il e* , const sc_i n<bool >&, const std::stri ng& );
templ ate <>
class sc_in<sc_dt::sc_logic>
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


155
Copyright 2012 IEEE. All rights reserved.
: publi c sc_port<sc_signal _in_if <sc_dt::sc_l ogi c>,1>
{
publ ic:
sc_in();
expl icit sc_in( const char* );
virtual ~sc_in();
virtual void bind ( const sc_si gnal_i n_i f<sc_dt::sc_logic>& );
void oper ator () ( const sc_si gnal _i n_i f<sc_dt::sc_logic>& );
virtual void bind ( sc_port<sc_signal_in_if <sc_dt::sc_l ogi c>, 1>& );
void oper ator () ( sc_port<sc_signal_in_if <sc_dt::sc_l ogi c>, 1>& );
virtual void bind ( sc_port<sc_signal _inout_if <sc_dt::sc_l ogic>, 1>& );
void oper ator () ( sc_port<sc_signal _inout_if <sc_dt::sc_l ogic>, 1>& );
virtual void end_of_elabor ation();
const sc_dt::sc_l ogic& read() const;
oper ator const sc_dt::sc_logic& () const;
const sc_event& default_event() const;
const sc_event& value_changed_event() const;
const sc_event& posedge_event() const;
const sc_event& negedge_event() const;
bool event() const;
bool posedge() const;
bool negedge() const;
sc_event_f inder& value_changed() const;
sc_event_f inder& pos() const;
sc_event_f inder& neg() const;
virtual const char* kind() const;
pri vate:
// Di sabl ed
sc_in( const sc_in<sc_dt::sc_l ogi c>& );
sc_in<sc_dt::sc_logic>& oper ator = ( const sc_in<sc_dt::sc_l ogi c>& );
} ;
templ ate <>
inl ine voi d
sc_trace<sc_dt::sc_logic>( sc_trace_f il e* , const sc_i n<sc_dt::sc_logic>&, const std::string& );
} // namespace sc_core
6.9.3 Member functions
The f ollowi ng l ist i s i ncomplete. For the remaini ng member f uncti ons and for the f uncti on sc_trace, refer to
the def ini ti ons of the member functions f or class sc_in (see 6.8.3).
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


156
Copyright 2012 IEEE. All rights reserved.
Member functi ons posedge_event, negedge_event, posedge, and negedge shall each cal l the correspondi ng
member functi on of the object to whi ch the port i s bound usi ng oper ator-> of class sc_por t, for example:
(* this)->negedge()
Member f unctions pos and neg shal l return a reference to cl ass sc_event_finder, where the event f inder
object itsel f shal l be constructed using the member f uncti on posedge_event or negedge_event, respecti vel y
(see 5.7).
6.10 sc_inout
6.10.1 Description
Cl ass sc_inout is a speci al ized port cl ass for use with signal s. I t provi des functions to access conveni entl y
certai n member f unctions of the channel to whi ch the port i s bound. I t may be used to model an output pin or
a bi directi onal pi n on a modul e.
6.10.2 Class definition
namespace sc_core {
templ ate <class T>
class sc_inout
: publi c sc_port<sc_signal _inout_if <T>,1>
{
publ ic:
sc_inout();
expl icit sc_inout( const char* );
virtual ~sc_inout();
void initialize( const T& );
void initialize( const sc_si gnal _i n_i f<T>& );
virtual void end_of_elabor ation();
const T& read() const;
oper ator const T& () const;
void wr ite( const T& );
sc_i nout<T>& oper ator = ( const T& );
sc_i nout<T>& oper ator = ( const sc_si gnal _i n_i f<T>& );
sc_i nout<T>& oper ator = ( const sc_port< sc_signal_in_if <T>, 1>& );
sc_i nout<T>& oper ator = ( const sc_port< sc_signal_inout_if <T>, 1>& );
sc_i nout<T>& oper ator = ( const sc_inout<T>& );
const sc_event& default_event() const;
const sc_event& value_changed_event() const;
bool event() const;
sc_event_f inder& value_changed() const;
virtual const char* kind() const;
pri vate:
// Di sabl ed
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


157
Copyright 2012 IEEE. All rights reserved.
sc_inout( const sc_inout<T>& );
} ;
templ ate <class T>
inl ine voi d sc_trace( sc_trace_f il e* , const sc_i nout<T>& , const std::stri ng& );
} // namespace sc_core
6.10.3 Member functions
The constructors shal l pass their arguments to the corresponding constructor for the base class sc_por t.
Member function read and oper ator const T& () shall each cal l member f unction read of the object to
which the port i s bound usi ng oper ator-> of class sc_por t, that i s:
(* this)->read()
Member f unction wr ite and oper ator = shal l each call the member function wr ite of the object to which the
port i s bound usi ng oper ator-> of class sc_por t, cal ling member functi on read to get the value of the
parameter, where the parameter is an i nterf ace or a port, for example:
sc_inout<T>& operator= ( const sc_i nout<T>& port_ )
{ (* this)->write( port_->read() ); return * this; }
Member f uncti on wr ite shall not be cal led during el aboration bef ore the port has been bound (see 6.10.4).
Member functi ons default_event, value_changed_event, and event shall each cal l the correspondi ng
member functi on of the object to whi ch the port i s bound usi ng oper ator-> of class sc_por t, for example:
(* this)->event()
Member f uncti on value_changed shall return a reference to class sc_event_finder , where the event f inder
object itself shall be constructed using the member function value_changed_event (see 5.7).
Member f uncti on kind shall return the string " sc_inout" .
6.10.4 initialize
Member function initialize shal l set the ini ti al val ue of the si gnal to whi ch the port is bound by call ing
member function wr ite of that signal usi ng the value passed as an argument to member f unction initialize. I f
the actual argument is a channel , the initial value shall be determined by reading the val ue of the channel.
The port need not have been bound at the poi nt during el aboration when member functi on initialize is
cal led. I n this case, the implementati on shal l def er the call to wr ite until af ter the port has been bound and
the identity of the si gnal i s known.
NOTE 1A port of class sc_in wi l l be bound to exactl y one si gnal , but the bi ndi ng may be perf ormed i ndi rectl y through
a port of the parent module.
NOTE 2The purpose of member function initialize i s to al l ow the val ue of a port to be i ni ti al i zed duri ng elaboration
bef ore the port bei ng bound. However, member functi on initializemay be cal l ed duri ng el aborati on or si mul ati on.
6.10.5 Function sc_trace
templ ate <class T>
inl ine voi d sc_trace( sc_trace_f il e* , const sc_i nout<T>& , const std::stri ng& );
Function sc_trace shal l trace the channel to which the port passed as the second argument i s bound
(see 8.1) by cal li ng function sc_trace wi th a second argument of type const T& (see 6.4.3). The
port need not have been bound at the point duri ng elaboration when f uncti on sc_trace is cal led. I n
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


158
Copyright 2012 IEEE. All rights reserved.
thi s case, the i mplementati on shall defer the call to trace the signal unti l af ter the port has been
bound and the identi ty of the si gnal is known.
6.10.6 end_of_elaboration
virtual void end_of_elabor ation();
Member functi on end_of_elabor ation, which i s defi ned in the class sc_por t, shall be overridden by
the impl ementation in the current class wi th a behavi or that i s i mplementati on-def ined.
NOTE 1An implementation may use end_of_elabor ation to i mpl ement the def erred cal l s f or initializeand sc_tr ace.
NOTE 2If this member function is overridden in a cl ass deri ved f rom the current cl ass, f uncti on end_of_elabor ation
as overri dden i n the current cl ass should be cal l ed expl i ci tl y f rom the overri dden member f uncti on of the deri ved cl ass in
order to invoke the i mpl ementati on-def i ned behavi or.
6.10.7 Binding
Because interface sc_signal_inout_if is derived f rom interface sc_signal_in_if, a port of cl ass sc_in of a
chi ld modul e may be bound to a port of cl ass sc_inout of a parent modul e but a port of cl ass sc_inout of a
chi ld module cannot be bound to a port of cl ass sc_in of a parent modul e.
6.11 sc_inout<bool> and sc_inout<sc_dt::sc_logic>
6.11.1 Description
Cl ass sc_inout<bool> and sc_inout<sc_dt::sc_logic> are speciali zed port cl asses that provide addi tional
member functi ons for two-val ued si gnals.
6.11.2 Class definition
namespace sc_core {
templ ate <>
class sc_inout<bool>
: publi c sc_port<sc_signal _inout_if <bool >,1>
{
publ ic:
sc_inout();
expl icit sc_inout( const char* );
virtual ~sc_inout();
void initialize( const bool& );
void initialize( const sc_si gnal _i n_i f<bool>& );
virtual void end_of_elabor ation();
const bool& r ead() const;
oper ator const bool& () const;
void wr ite( const bool& );
sc_inout<bool>& oper ator = ( const bool& );
sc_inout<bool>& oper ator = ( const sc_si gnal_i n_i f<bool>& );
sc_inout<bool>& oper ator = ( const sc_port< sc_signal_in_if <bool >, 1>& );
sc_inout<bool>& oper ator = ( const sc_port< sc_signal_inout_if <bool >, 1>& );
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


159
Copyright 2012 IEEE. All rights reserved.
sc_inout<bool>& oper ator = ( const sc_inout<bool >& );
const sc_event& default_event() const;
const sc_event& value_changed_event() const;
const sc_event& posedge_event() const;
const sc_event& negedge_event() const;
bool event() const;
bool posedge() const;
bool negedge() const;
sc_event_f inder& value_changed() const;
sc_event_f inder& pos() const;
sc_event_f inder& neg() const;
virtual const char* kind() const;
pri vate:
// Di sabl ed
sc_inout( const sc_inout<bool>& );
} ;
templ ate <>
inl ine voi d sc_trace<bool>( sc_trace_f il e* , const sc_i nout<bool >&, const std::stri ng& );
templ ate <>
class sc_inout<sc_dt::sc_logic>
: publi c sc_port<sc_signal _inout_if <sc_dt::sc_l ogi c>,1>
{
publ ic:
sc_inout();
expl icit sc_inout( const char* );
virtual ~sc_inout();
void initialize( const sc_dt::sc_logic& );
void initialize( const sc_si gnal _i n_i f<sc_dt::sc_logic>& );
virtual void end_of_elabor ation();
const sc_dt::sc_l ogic& r ead() const;
oper ator const sc_dt::sc_logic& () const;
void wr ite( const sc_dt::sc_logic& );
sc_inout<sc_dt::sc_logic>& oper ator = ( const sc_dt::sc_logic& );
sc_inout<sc_dt::sc_logic>& oper ator = ( const sc_si gnal_i n_i f<sc_dt::sc_logic>& );
sc_inout<sc_dt::sc_logic>& oper ator = ( const sc_port< sc_signal_in_if <sc_dt::sc_l ogi c>, 1>& );
sc_inout<sc_dt::sc_logic>& oper ator = ( const sc_port< sc_si gnal _i nout_if <sc_dt::sc_logic>, 1>&);
sc_inout<sc_dt::sc_logic>& oper ator = ( const sc_inout<sc_dt::sc_logic>& );
const sc_event& default_event() const;
const sc_event& value_changed_event() const;
const sc_event& posedge_event() const;
const sc_event& negedge_event() const;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


160
Copyright 2012 IEEE. All rights reserved.
bool event() const;
bool posedge() const;
bool negedge() const;
sc_event_f inder& value_changed() const;
sc_event_f inder& pos() const;
sc_event_f inder& neg() const;
virtual const char* kind() const;
pri vate:
// Di sabl ed
sc_inout( const sc_inout<sc_dt::sc_l ogi c>& );
} ;
templ ate <>
inl ine voi d
sc_trace<sc_dt::sc_logic>( sc_trace_f il e* , const sc_inout<sc_dt::sc_l ogic>&, const std::stri ng& );
} // namespace sc_core
6.11.3 Member functions
The f ollowi ng l ist i s i ncomplete. For the remaini ng member f uncti ons and for the f uncti on sc_trace, refer to
the def ini ti ons of the member functions f or class sc_inout.
Member functi ons posedge_event, negedge_event, posedge, and negedge shall each cal l the correspondi ng
member functi on of the object to whi ch the port i s bound usi ng oper ator-> of class sc_por t, for example:
(* this)->negedge()
Member f unctions pos and neg shal l return a reference to cl ass sc_event_finder, where the event f inder
object itsel f shal l be constructed using the member f uncti on posedge_event or negedge_event, respecti vel y
(see 5.7).
Member f uncti on kind shall return the string " sc_inout" .
6.12 sc_out
6.12.1 Description
Cl ass sc_out is derived from cl ass sc_inout and is identical to class sc_inout except for di ff erences i nherent
in it bei ng a derived class, f or example, constructors and assignment operators. The purpose of havi ng both
classes is to al low users to express their i ntent, that is, sc_out f or output pi ns and sc_inout f or bi directi onal
pins.
6.12.2 Class definition
namespace sc_core {
templ ate <class T>
class sc_out
: publi c sc_i nout<T>
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


161
Copyright 2012 IEEE. All rights reserved.
{
publ ic:
sc_out();
expl icit sc_out( const char* );
virtual ~sc_out();
sc_out<T>& oper ator = ( const T& );
sc_out<T>& oper ator = ( const sc_si gnal _i n_i f<T>& );
sc_out<T>& oper ator = ( const sc_port< sc_signal_in_i f<T>, 1>& );
sc_out<T>& oper ator = ( const sc_port< sc_signal _inout_if <T>, 1>& );
sc_out<T>& oper ator = ( const sc_out<T>& );
virtual const char* kind() const;
pri vate:
// Di sabl ed
sc_out( const sc_out<T>& );
} ;
} // namespace sc_core
6.12.3 Member functions
The constructors shall pass their arguments to the corresponding constructors for the base cl ass
sc_inout<T>.
The behavi or of the assi gnment operators shal l be i dentical to that of class sc_inout but wi th the class name
sc_out substi tuted in place of the class name sc_inout wherever appropri ate.
Member f uncti on kind shall return the string " sc_out" .
6.13 sc_signal_resolved
6.13.1 Description
Cl ass sc_signal_resolved i s a predef ined pri mitive channel deri ved from class sc_signal. A resol ved si gnal
is an obj ect of class sc_signal_resolved or cl ass sc_signal_r v. Class sc_signal_resolved di ff ers f rom class
sc_signal in that a resol ved signal may be wri tten by mul ti ple processes, confli cti ng val ues bei ng resolved
wi thin the channel .
6.13.2 Class definition
namespace sc_core {
class sc_signal_r esolved
: publi c sc_signal<sc_dt::sc_logic,SC_MANY_WRITERS>
{
publ ic:
sc_signal_r esolved();
expl icit sc_signal_r esolved( const char* );
virtual ~sc_signal_r esolved();
virtual void r egister_port( sc_port_base&, const char* );
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


162
Copyright 2012 IEEE. All rights reserved.
virtual void wr ite( const sc_dt::sc_l ogi c& );
sc_signal _resol ved& oper ator = ( const sc_dt::sc_logic& );
sc_signal _resol ved& oper ator = ( const sc_si gnal _resol ved& );
virtual const char* kind() const;
protected:
virtual void update();
pri vate:
// Di sabl ed
sc_signal_r esolved( const sc_si gnal _resolved& );
} ;
} // namespace sc_core
6.13.3 Constructors
sc_signal_resolved();
This constructor shall cal l the base class constructor f rom i ts ini tial izer li st as f ol lows:
sc_signal ( sc_gen_uni que_name( "si gnal_resolved" ) )
expl icit sc_signal_resolved( const char* name_ );
This constructor shall cal l the base class constructor f rom i ts ini tial izer li st as f ol lows:
sc_signal ( name_ )
6.13.4 Resolution semantics
A resolved si gnal i s written by call ing member f uncti on wr ite or oper ator = of the given si gnal obj ect. Li ke
class sc_signal, oper ator = shall cal l member functi on wr ite.
Each resolved si gnal shal l mai ntai n a l i st of wri tten val ues contai ni ng one val ue f or each distinct process
instance that writes to the resol ved signal obj ect. Thi s l ist shal l store the value most recentl y written to the
resolved signal object by each such process instance.
I f and only i f the wri tten value i s diff erent from the previ ous written value or this i s the f irst occasion on
which the particular process i nstance has wri tten to the particular signal object, the member f uncti on wr ite
shall then call the member function request_update.
Duri ng the update phase, member function update shal l f irst use the l ist of wri tten values to calculate a
single r esol ved val ue for the resol ved si gnal , and then perf orm update semanti cs si mi lar to class sc_signal
but usi ng the resolved value j ust cal cul ated.
A value shall be added to the l ist of wri tten values on the f irst occasi on that each particul ar process instance
writes to the resol ved si gnal object. Val ues shal l not be removed f rom the l ist of written values. Bef ore the
f irst occasion on whi ch a gi ven process i nstance writes to a given resol ved si gnal, that process instance shall
not contri bute to the calcul ati on of the resol ved val ue f or that si gnal.
The resolved value shall be cal cul ated f rom the l ist of wri tten val ues usi ng the fol lowi ng algori thm:
1) Take a copy of the li st.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


163
Copyright 2012 IEEE. All rights reserved.
2) Take any two val ues f rom the copy of the l ist and repl ace them with one value according to the
truth table shown in Tabl e 3.
3) Repeat step 2) unti l only a single val ue remains. This is the resol ved val ue.
Before the f irst occasion on whi ch a given process i nstance writes to a gi ven resolved signal , the val ue
written by that process instance i s ef fecti vel y 'Z' in terms of i ts ef fect on the resoluti on cal cul ation. On the
other hand, the def ault i nitial val ue for a resol ved si gnal (as would be returned by member f unction read
bef ore the fi rst wr ite) is 'X '. Thus, it i s strongl y recommended that each process i nstance that writes to a
given resolved si gnal perf orm a write to that si gnal at time zero.
NOTE 1The order in which values are passed to the function def i ned by the truth table i n Tabl e 3 does not af f ect the
resul t of the cal cul ati on.
NOTE 2The calculation of the resolved value is performed usi ng the val ue most recentl y wri tten by each and every
process that wri tes to that parti cul ar si gnal obj ect, regardl ess of whether the most recent wri te occurred i n the current
del ta cycl e, i n a previ ous del ta cycl e, or at an earl ier ti me.
NOTE 3These same resolution semanti cs appl y, whether the resolved si gnal i s accessed di rectl y by a process or i s
accessed i ndi rectl y through a port bound to the resol ved si gnal .
6.13.5 Member functions
Member function register _por t of class sc_signal shall be overri dden i n class sc_signal_resolved, such that
the error check for mul ti ple output ports perf ormed by sc_signal::r egister _port is di sabled for channel
objects of cl ass sc_signal_resolved.
Member function wr ite, oper ator =, and member f uncti on update shal l have the same behavi or as the
correspondi ng members of cl ass sc_signal, except where the behavior diff ers f or multiple writers as defi ned
in 6.13.4.
Member f uncti on kind shall return the string " sc_signal_resolved" .
Exampl e:
SC_MODULE(M)
{
sc_signal _resol ved si g;
SC_CTOR(M)
{
SC_THREAD(T1);
SC_THREAD(T2);
SC_THREAD(T3);
}
Table 3Resolution table for sc_signal_resolved
' 0' '1' ' Z' 'X'
' 0' '0' 'X' '0' 'X'
' 1' 'X' '1' '1' 'X'
'Z' '0' '1' 'Z' 'X'
'X' 'X' 'X' 'X' ' X'
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


164
Copyright 2012 IEEE. All rights reserved.
voi d T1()
{ // Ti me=0 ns, no written values si g=X
wait(10, SC_NS);
sig = sc_dt::SC_LOGIC_0; // Time=10 ns, written values=0 sig=0
wait(20, SC_NS);
sig = sc_dt::SC_LOGIC_Z; // Time=30 ns, written values=Z,Z sig=Z
}
voi d T2()
{
wait(20, SC_NS);
sig = sc_dt::SC_LOGIC_Z; // Time=20 ns, written values=0,Z sig=0
wait(30, SC_NS);
sig = sc_dt::SC_LOGIC_0; // Time=50 ns, written values=Z,0,1 sig=X
}
voi d T3()
{
wait(40, SC_NS);
sig = sc_dt::SC_LOGIC_1; // Time=40 ns, written values=Z,Z,1 sig=1
}
} ;
6.14 sc_in_resolved
6.14.1 Description
Cl ass sc_in_r esolved is a speciali zed port class for use wi th resol ved si gnals. It i s simi lar i n behavior to port
class sc_in<sc_dt::sc_logic> f rom whi ch i t i s derived. The onl y dif ference is that a port of class
sc_in_r esolved shall be bound to a channel of class sc_signal_resolved, whereas a port of class
sc_in<sc_dt::sc_logic> may be bound to a channel of class
sc_signal<sc_dt::sc_logic,W RI TER_POLI CY > or class sc_signal_resolved.
6.14.2 Class definition
namespace sc_core {
class sc_in_r esolved
: publi c sc_i n<sc_dt::sc_logic>
{
publ ic:
sc_in_r esolved();
expl icit sc_in_r esolved( const char* );
virtual ~sc_in_r esolved();
virtual void end_of_elabor ation();
virtual const char* kind() const;
pri vate:
// Di sabl ed
sc_in_r esolved( const sc_in_resolved& );
sc_i n_resolved& operator = (const sc_in_resol ved& );
} ;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


165
Copyright 2012 IEEE. All rights reserved.
} // namespace sc_core
6.14.3 Member functions
The constructors shall pass their arguments to the corresponding constructors for the base cl ass
sc_in<sc_dt::sc_logic>.
Member function end_of_elaboration shal l perform an error check. I t is an error i f the port i s not bound to
a channel of cl ass sc_signal_resolved.
Member f uncti on kind shall return the string " sc_in_resolved" .
NOTEAs always, the port may be bound indirectl y through a port of a parent modul e.
6.15 sc_inout_resolved
6.15.1 Description
Cl ass sc_inout_r esolved i s a speci al ized port cl ass for use wi th resolved signal s. I t is si mi lar in behavior to
port class sc_inout<sc_dt::sc_logic> from which i t is derived. The only dif ference is that a port of cl ass
sc_inout_r esolved shall be bound to a channel of cl ass sc_signal_resolved, whereas a port of class
sc_inout<sc_dt::sc_logic> may be bound to a channel of cl ass
sc_signal<sc_dt::sc_logic,W RI TER_POLI CY > or class sc_signal_resolved.
6.15.2 Class definition
namespace sc_core {
class sc_inout_r esolved
: publi c sc_i nout<sc_dt::sc_logi c>
{
publ ic:
sc_inout_r esolved();
expl icit sc_inout_r esolved( const char* );
virtual ~sc_inout_resolved();
virtual void end_of_elabor ation();
sc_inout_resolved& oper ator = ( const sc_dt::sc_logic& );
sc_inout_resolved& oper ator = ( const sc_si gnal_i n_i f<sc_dt::sc_logic>& );
sc_inout_resolved& oper ator = ( const sc_port<sc_signal_in_if <sc_dt::sc_l ogic>, 1>& );
sc_inout_resolved& oper ator = ( const sc_port<sc_signal_inout_i f<sc_dt::sc_logic>, 1>& );
sc_inout_resolved& oper ator = ( const sc_inout_resol ved& );
virtual const char* kind() const;
pri vate:
// Di sabl ed
sc_inout_r esolved( const sc_inout_resol ved& );
} ;
} // namespace sc_core
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


166
Copyright 2012 IEEE. All rights reserved.
6.15.3 Member functions
The constructors shall pass their arguments to the corresponding constructors for the base cl ass
sc_inout<sc_dt::sc_logic>.
Member function end_of_elaboration shal l perform an error check. I t is an error i f the port i s not bound to
a channel of cl ass sc_signal_resolved.
The behavi or of the assi gnment operators shal l be identical to that of cl ass sc_inout<sc_dt::sc_logic> but
wi th the cl ass name sc_inout_r esolved substi tuted in place of the class name sc_inout<sc_dt::sc_logic>
wherever appropriate.
Member f uncti on kind shall return the string " sc_inout_r esolved" .
NOTEAs always, the port may be bound indirectl y through a port of a parent modul e.
6.16 sc_out_resolved
6.16.1 Description
Cl ass sc_out_resolved i s derived f rom cl ass sc_inout_r esolved, and i t is identi cal to cl ass
sc_inout_r esolved except for dif ferences i nherent in it bei ng a derived cl ass, f or exampl e, constructors and
assignment operators. The purpose of havi ng both cl asses is to all ow users to express thei r intent, that is,
sc_out_r esolved f or output pi ns connected to resolved si gnals and sc_inout_r esolved f or bidi recti onal pi ns
connected to resol ved si gnal s.
6.16.2 Class definition
namespace sc_core {
class sc_out_r esolved
: publi c sc_i nout_resol ved
{
publ ic:
sc_out_r esolved();
expl icit sc_out_r esolved( const char* );
virtual ~sc_out_r esolved();
sc_out_resolved& oper ator = ( const sc_dt::sc_l ogi c& );
sc_out_resolved& oper ator = ( const sc_si gnal _i n_i f<sc_dt::sc_logic>& );
sc_out_resolved& oper ator = ( const sc_port<sc_si gnal_i n_i f<sc_dt::sc_logic>, 1>& );
sc_out_resolved& oper ator = ( const sc_port<sc_signal_i nout_i f<sc_dt::sc_l ogi c>, 1>& );
sc_out_resolved& oper ator = ( const sc_out_resol ved& );
virtual const char* kind() const;
pri vate:
// Di sabl ed
sc_out_r esolved( const sc_out_resol ved& );
} ;
} // namespace sc_core
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


167
Copyright 2012 IEEE. All rights reserved.
6.16.3 Member functions
The constructors shall pass their arguments to the corresponding constructors for the base cl ass
sc_inout_r esolved.
The behavior of the assignment operators shall be identical to that of class sc_inout_r esolved but with the
class name sc_out_resolved substituted i n place of the cl ass name sc_inout_r esolved wherever appropri ate.
Member f uncti on kind shall return the string " sc_out_resolved" .
6.17 sc_signal_rv
6.17.1 Description
Cl ass sc_signal_r v is a predefi ned pri mitive channel derived f rom class sc_signal. Class sc_signal_r v is
simi lar to cl ass sc_signal_resolved. The di ff erence is that the argument to the base class templ ate sc_signal
is type sc_dt::sc_lv<W > instead of type sc_dt::sc_logic.
6.17.2 Class definition
namespace sc_core {
templ ate <i nt W>
class sc_signal_r v
: publi c sc_si gnal<sc_dt::sc_lv<W>,SC_MANY_WRI TERS>
{
publ ic:
sc_signal_r v();
expl icit sc_signal_r v( const char* );
virtual ~sc_signal_r v();
virtual void r egister_port( sc_port_base&, const char* );
virtual void wr ite( const sc_dt::sc_lv<W>& );
sc_signal_rv<W>& oper ator = ( const sc_dt::sc_lv<W>& );
sc_signal_rv<W>& oper ator = ( const sc_si gnal _rv<W>& );
virtual const char* kind() const;
protected:
virtual void update();
pri vate:
// Di sabl ed
sc_signal_r v( const sc_si gnal _rv<W>& );
} ;
} // namespace sc_core
6.17.3 Semantics and member functions
The semantics of cl ass sc_signal_r v shall be i denti cal to the semantics of class sc_signal_resolved except
f or dif ferences due to the fact that the val ue to be resol ved is of type sc_dt::sc_lv (see 6.13.4).
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


168
Copyright 2012 IEEE. All rights reserved.
The val ue shall be propagated through the resolved signal as an atomi c val ue; that i s, an event shal l be
noti fi ed, and the entire val ue of the vector shal l be resolved and updated whenever any bi t of the vector
written by any process changes.
The l i st of wr i tten val ues shall contai n values of type sc_dt::sc_lv, and each value of type sc_dt::sc_lv shall
be treated atomicall y f or the purpose of buildi ng and updating the li st.
I f and onl y if the written val ue dif fers from the previous wri tten val ue (i n one or more bi t posi tions) or this i s
the f irst occasi on on which the particular process has wri tten to the parti cul ar signal object, the member
functi on wr ite shall then call the member function request_update.
The resolved val ue shall be calculated f or the enti re vector by applyi ng the rule descri bed in 6.13.4 to each
bit position within the vector i n turn.
The default constructor shall call the base class constructor f rom i ts initiali zer li st as foll ows:
sc_signal ( sc_gen_uni que_name( "si gnal_rv" ) )
Member f uncti on kind shall return the string " sc_signal_rv" .
6.18 sc_in_rv
6.18.1 Description
Cl ass sc_in_r v i s a special ized port class f or use with resolved signal s. I t is si mi lar i n behavi or to port cl ass
sc_in<sc_dt::sc_lv<W>> from which it is derived. The onl y di ff erence is that a port of cl ass sc_in_r v shal l
be bound to a channel of class sc_signal_r v, whereas a port of cl ass sc_in<sc_dt::sc_lv<W>> may be
bound to a channel of cl ass sc_signal<sc_dt::sc_lv<W >,W RI TER_POLI CY > or class sc_signal_r v.
6.18.2 Class definition
namespace sc_core {
templ ate <i nt W>
class sc_in_r v
: publi c sc_i n<sc_dt::sc_lv<W>>
{
publ ic:
sc_in_r v();
expl icit sc_in_r v( const char* );
virtual ~sc_in_r v();
virtual void end_of_elabor ation();
virtual const char* kind() const;
pri vate:
// Di sabl ed
sc_in_r v( const sc_in_rv<W>& );
sc_in_rv<W>& oper ator = ( const sc_i n_rv<W>& );
} ;
} // namespace sc_core
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


169
Copyright 2012 IEEE. All rights reserved.
6.18.3 Member functions
The constructors shall pass their arguments to the corresponding constructors for the base cl ass
sc_in<sc_dt::sc_lv<W>>.
Member function end_of_elaboration shal l perform an error check. I t is an error i f the port i s not bound to
a channel of cl ass sc_signal_r v.
Member f uncti on kind shall return the string " sc_in_r v".
NOTEAs always, the port may be bound indirectl y through a port of a parent modul e.
6.19 sc_inout_rv
6.19.1 Description
Cl ass sc_inout_rv is a speciali zed port cl ass for use wi th resolved signals. It is si mi lar i n behavi or to port
class sc_inout<sc_dt::sc_lv<W>> f rom whi ch i t i s deri ved. The onl y di ff erence is that a port of cl ass
sc_inout_r v shal l be bound to a channel of cl ass sc_signal_r v, whereas a port of cl ass
sc_inout<sc_dt::sc_lv<W>> may be bound to a channel of class
sc_signal<sc_dt::sc_lv<W >,W RI TER_POLI CY > or class sc_signal_r v.
6.19.2 Class definition
namespace sc_core {
templ ate <i nt W>
class sc_inout_r v
: publi c sc_i nout<sc_dt::sc_l v<W>>
{
publ ic:
sc_inout_r v();
expl icit sc_inout_r v( const char* );
virtual ~sc_inout_rv();
sc_inout_rv<W>& oper ator = ( const sc_dt::sc_lv<W>& );
sc_inout_rv<W>& oper ator = ( const sc_si gnal_i n_i f<sc_dt::sc_lv<W>>& );
sc_inout_rv<W>& oper ator = ( const sc_port<sc_signal_i n_i f<sc_dt::sc_l v<W>>, 1>& );
sc_inout_rv<W>& oper ator = ( const sc_port<sc_signal_i nout_if <sc_dt::sc_lv<W>>, 1>& );
sc_inout_rv<W>& oper ator = ( const sc_inout_rv<W>& );
virtual void end_of_elabor ation();
virtual const char* kind() const;
pri vate:
// Di sabl ed
sc_inout_r v( const sc_inout_rv<W>& );
} ;
} // namespace sc_core
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


170
Copyright 2012 IEEE. All rights reserved.
6.19.3 Member functions
The constructors shall pass their arguments to the corresponding constructors for the base cl ass
sc_inout<sc_dt::sc_lv<W>>.
Member function end_of_elaboration shal l perform an error check. I t is an error i f the port i s not bound to
a channel of cl ass sc_signal_r v.
The behavior of the assi gnment operators shall be identical to that of class sc_inout<sc_dt::sc_lv<W >> but
wi th the class name sc_inout_r v substituted i n place of the cl ass name sc_inout<sc_dt::sc_lv<W>>
wherever appropriate.
Member f uncti on kind shall return the string " sc_inout_r v" .
NOTEThe port may be bound indirectly through a port of a parent module.
6.20 sc_out_rv
6.20.1 Description
Cl ass sc_out_r v i s derived f rom cl ass sc_inout_r v, and i t i s identi cal to cl ass sc_inout_r v except f or
dif ferences inherent i n it being a derived cl ass, for exampl e, constructors and assignment operators. The
purpose of having both classes i s to al low users to express their i ntent, that is, sc_out_r v for output pins
connected to resol ved vectors and sc_inout_rv for bi directi onal pi ns connected to resolved vectors.
6.20.2 Class definition
namespace sc_core {
templ ate <i nt W>
class sc_out_r v
: publi c sc_i nout_rv<W>
{
publ ic:
sc_out_r v();
expl icit sc_out_r v( const char* );
virtual ~sc_out_r v();
sc_out_rv<W>& operator = ( const sc_dt::sc_lv<W>& );
sc_out_rv<W>& oper ator = ( const sc_si gnal _i n_i f<sc_dt::sc_lv<W>>& );
sc_out_rv<W>& oper ator = ( const sc_port<sc_si gnal_i n_i f<sc_dt::sc_lv<W>>, 1>& );
sc_out_rv<W>& oper ator = ( const sc_port<sc_si gnal_i nout_i f<sc_dt::sc_lv<W>>, 1>& );
sc_out_rv<W>& oper ator = ( const sc_out_rv<W>& );
virtual const char* kind() const;
pri vate:
// Di sabl ed
sc_out_r v( const sc_out_rv<W>& );
} ;
} // namespace sc_core
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


171
Copyright 2012 IEEE. All rights reserved.
6.20.3 Member functions
The constructors shall pass their arguments to the corresponding constructors for the base cl ass
sc_inout_r v<W >.
The behavi or of the assi gnment operators shal l be i denti cal to that of cl ass sc_inout_r v<W > but with the
class name sc_out_r v<W> substi tuted in place of the class name sc_inout_r v<W > wherever appropri ate.
Member f uncti on kind shall return the string " sc_out_r v" .
6.21 sc_fifo_in_if
6.21.1 Description
Cl ass sc_fifo_in_if i s an interface proper and i s impl emented by the predef ined channel sc_fifo. I nterf ace
sc_fifo_in_if gi ves read access to a f if o channel, and it i s derived from two further interfaces proper,
sc_fifo_nonblocking_in_if and sc_fifo_blocking_in_if.
6.21.2 Class definition
namespace sc_core {
templ ate <cl ass T>
class sc_fifo_nonblocking_in_if
: vi rtual publi c sc_i nterf ace
{
publ ic:
virtual bool nb_read( T& ) = 0;
virtual const sc_event& data_wr itten_event() const = 0;
} ;
templ ate <cl ass T>
class sc_fifo_blocking_in_if
: vi rtual publi c sc_i nterf ace
{
publ ic:
virtual void read( T& ) = 0;
virtual T read() = 0;
} ;
templ ate <class T>
class sc_fifo_in_if : publi c sc_f if o_nonblocki ng_i n_i f<T>, publ ic sc_f if o_blocking_in_if <T>
{
publ ic:
virtual i nt num_available() const = 0;
protected:
sc_fifo_in_if();
pri vate:
// Di sabl ed
sc_fifo_in_if( const sc_fi fo_in_if <T>& );
sc_f if o_i n_i f<T>& oper ator = ( const sc_fi fo_in_if <T>& );
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


172
Copyright 2012 IEEE. All rights reserved.
} ;
} // namespace sc_core
6.21.3 Member functions
The f oll owing member functions are all pure vi rtual functi ons. The descriptions refer to the expected
def ini ti ons of the functions when overri dden i n a channel that impl ements this i nterf ace. The preci se
semanti cs wi ll be channel -speci fi c.
Member functi ons read and nb_read shall return the val ue least recently wri tten into the fi fo and shal l
remove that val ue f rom the f if o such that i t cannot be read agai n. I f the fi fo i s empty, member functi on read
shall suspend unti l a value has been wri tten to the fi fo, whereas member f unction nb_read shall return
immedi ately. The return val ue of the f unction nb_read shal l indicate whether a value was read.
When call ing member f uncti on void read(T& ) of cl ass sc_fifo_blocking_in_if, the appl icati on shall be
obli ged to ensure that the li fetime of the actual argument extends from the ti me the f unction is call ed to the
ti me the f unction call reaches compl eti on. Moreover, the appli cati on shal l not modif y the value of the actual
argument during that peri od.
Member function data_wr itten_event shal l return a ref erence to an event that is noti fied whenever a val ue
is written i nto the fi fo.
Member f uncti on num_available shall return the number of values currentl y avail able in the fi fo to be read.
6.22 sc_fifo_out_if
6.22.1 Description
Cl ass sc_fifo_out_if is an i nterf ace proper and i s i mplemented by the predef ined channel sc_fifo. I nterface
sc_fifo_out_if gives wri te access to a fi fo channel and is derived from two f urther interfaces proper,
sc_fifo_nonblocking_out_if and sc_fifo_blocking_out_if.
6.22.2 Class definition
namespace sc_core {
templ ate <cl ass T>
class sc_fifo_nonblocking_out_if
: vi rtual publi c sc_i nterf ace
{
publ ic:
virtual bool nb_write( const T& ) = 0;
virtual const sc_event& data_read_event() const = 0;
} ;
templ ate <cl ass T>
class sc_fifo_blocking_out_if
: vi rtual publi c sc_i nterf ace
{
publ ic:
virtual void wr ite( const T& ) = 0;
} ;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


173
Copyright 2012 IEEE. All rights reserved.
templ ate <class T>
class sc_fifo_out_if : publi c sc_f if o_nonblocki ng_out_i f<T>, publ ic sc_f ifo_blocking_out_i f<T>
{
publ ic:
virtual i nt num_fr ee() const = 0;
protected:
sc_fifo_out_if();
pri vate:
// Di sabl ed
sc_fifo_out_if( const sc_fi fo_out_if <T>& );
sc_f if o_out_i f<T>& oper ator = ( const sc_fi fo_out_if <T>& );
} ;
} // namespace sc_core
6.22.3 Member functions
The f oll owing member functions are all pure vi rtual functi ons. The descriptions refer to the expected
def ini ti ons of the functions when overri dden i n a channel that impl ements this i nterf ace. The preci se
semanti cs wi ll be channel -speci fi c.
Member f uncti ons wr ite and nb_write shall wri te the value passed as an argument i nto the f if o. I f the fi fo is
f ul l, member f uncti on wr ite shal l suspend unti l a val ue has been read f rom the fi f o, whereas member
functi on nb_write shal l return i mmediatel y. The return value of the functi on nb_write shal l i ndi cate
whether a val ue was written into an empty slot.
When call ing member functi on void wr ite(const T& ) of class sc_fifo_blocking_out_if, the appli cation
shall be obl iged to ensure that the l if etime of the actual argument extends f rom the time the functi on is cal led
to the time the function cal l reaches completi on, and moreover, the appli cation shall not modi fy the val ue of
the actual argument duri ng that period.
Member f uncti on data_read_event shall return a reference to an event that i s noti fi ed whenever a value i s
read from the f if o.
Member f unction num_fr ee shal l return the number of unoccupied slots i n the fi fo avai lable to accept
written values.
6.23 sc_fifo
6.23.1 Description
Cl ass sc_fifo i s a predef ined pri mitive channel i ntended to model the behavior of a f if o, that is, a fi rst-in-
f irst-out buf fer. In this clause, fi fo refers to an object of cl ass sc_fifo. Each f if o has a number of sl ots f or
stori ng values. The number of slots i s f ixed when the obj ect i s constructed.
6.23.2 Class definition
namespace sc_core {
templ ate <class T>
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


174
Copyright 2012 IEEE. All rights reserved.
class sc_fifo
: publi c sc_f if o_in_if <T>, publi c sc_fif o_out_i f<T>, publ ic sc_pri m_channel
{
publ ic:
expl icit sc_fifo( i nt size_ = 16 );
expl icit sc_fifo( const char* name_, i nt si ze_ = 16);
virtual ~sc_fifo();
virtual void register _por t( sc_port_base&, const char* );
virtual void read( T& );
virtual T read();
virtual bool nb_read( T& );
oper ator T ();
virtual void wr ite( const T& );
virtual bool nb_write( const T& );
sc_f if o<T>& oper ator = ( const T& );
virtual const sc_event& data_wr itten_event() const;
virtual const sc_event& data_read_event() const;
virtual i nt num_available() const;
virtual i nt num_fr ee() const;
virtual void pr int( std::ostream& = std::cout ) const;
virtual void dump( std::ostream& = std::cout ) const;
virtual const char* kind() const;
protected:
virtual void update();
pri vate:
// Di sabl ed
sc_fifo( const sc_fi fo<T>& );
sc_f if o& oper ator = ( const sc_fi fo<T>& );
} ;
templ ate <class T>
inl ine std::ostream& oper ator << ( std::ostream& , const sc_fi fo<T>& );
} // namespace sc_core
6.23.3 Template parameter T
The argument passed to template sc_fifo shall be ei ther a C++ type for which the predefi ned semanti cs for
assignment are adequate (f or exampl e, a fundamental type or a pointer) or a type T that obeys each of the
f ol lowi ng rul es:
a) The f ol lowi ng stream operator shall be defi ned and should copy the state of the obj ect given as the
second argument to the stream given as the fi rst argument. The way in whi ch the state i nf ormation i s
f ormatted is undef ined by this standard. The i mplementati on shal l use this operator i n i mplementi ng
the behavior of the member f unctions pr int and dump.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


175
Copyright 2012 IEEE. All rights reserved.
std::ostream& oper ator << ( std::ostream&, const T& );
b) I f the def aul t assignment semantics are i nadequate to assign the state of the object, the foll owing
assignment operator shoul d be def ined f or the type T. The impl ementation shall use this operator to
copy the val ue being wri tten into a f if o slot or the value being read out of a f if o slot.
const T& oper ator = ( const T& );
c) I f any constructor f or type T exi sts, a def aul t constructor for type T shal l be defi ned.
NOTE 1The assignment operator is not obli ged to assi gn the compl ete state of the obj ect, al though i t shoul d typi cal l y
do so. For exampl e, di agnosti c i nf ormati on may be associ ated wi th an obj ect that i s not to be propagated through the
f i f o.
NOTE 2The SystemC data types proper (sc_dt::sc_int, sc_dt::sc_logic, and so f orth) al l conform to the above rul e
set.
NOTE 3It is legal to pass type sc_module* through a f if o, al though thi s woul d be regarded as an abuse of the modul e
hi erarchy and thus bad practice.
6.23.4 Constructors
expl icit sc_fifo( i nt size_ = 16 );
This constructor shall cal l the base class constructor f rom i ts ini tial izer li st as f ol lows:
sc_pri m_channel ( sc_gen_unique_name( "f if o" ) )
expl icit sc_fifo( const char* name_, i nt si ze_ = 16 );
This constructor shall cal l the base cl ass constructor f rom its ini ti al izer li st as f ol lows:
sc_pri m_channel ( name_ )
Both constructors shal l i nitiali ze the number of sl ots i n the fi fo to the val ue gi ven by the parameter size_.
The number of slots shal l be greater than zero.
6.23.5 register_port
virtual void register _por t( sc_port_base&, const char* );
Member f uncti on register _por t of class sc_interface shall be overri dden in cl ass sc_fifo and shall
perf orm an error check. I t i s an error if more than one port of type sc_fifo_in_if i s bound to a given
f if o, and i t is an error i f more than one port of type sc_fifo_out_if is bound to a gi ven fi fo.
6.23.6 Member functions for reading
virtual void read( T& );
virtual T read();
virtual bool nb_read( T& );
Member functions read and nb_read shal l return the val ue l east recentl y written into the f if o and
shal l remove that val ue from the f i f o such that i t cannot be read again. Mul ti pl e val ues may be read
wi thin a si ngle delta cycle. The order in whi ch val ues are read from the fi fo shall precisely match the
order i n which val ues were written into the f if o. Values written into the fif o duri ng the current delta
cycl e are not avail able f or reading in that del ta cycle but become avail abl e f or reading i n the
immedi ately fol lowi ng del ta cycl e.
The value read from the f if o shal l be returned as the val ue of the member f uncti on or as an argument
passed by reference, as appropriate.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


176
Copyright 2012 IEEE. All rights reserved.
I f the f if o i s empty (that is, no val ues are avai lable for reading), member function read shall suspend
unti l the data-wr i tten event is notif ied. At that poi nt, it shall resume (i n the i mmediatel y f ol lowi ng
eval uation phase) and compl ete the readi ng of the value l east recently wri tten into the f if o bef ore
returning.
I f the f if o i s empty, member f unction nb_read shal l return immedi ately without modif yi ng the state
of the fi fo, without call ing request_update, and with a return value of false. Otherwi se, if a val ue i s
avai lable for reading, the return value of member functi on nb_read shall be true.
oper ator T ();
The behavi or of oper ator T() shall be equival ent to the foll owing def ini ti on:
operator T (){ return read(); }
6.23.7 Member functions for writing
virtual void wr ite( const T& );
virtual bool nb_write( const T& );
Member f unctions wr ite and nb_write shal l write the value passed as an argument into the f if o.
Mul ti pl e values may be written wi thi n a single del ta cycl e. If values are read from the f if o duri ng the
current delta cycle, the empty sl ots in the fi fo so created do not become free f or the purposes of
writing unti l the i mmedi ately fol lowi ng delta cycl e.
I f the fi fo is full (that i s, no f ree slots exist for the purposes of wri ti ng), member f unction wr ite shall
suspend until the data-r ead event is notif ied. At which poi nt, it shall resume (i n the i mmediately
f ol lowi ng evaluati on phase) and complete the writing of the argument val ue into the f if o bef ore
returning.
I f the f if o i s ful l, member f unction nb_write shall return immedi atel y wi thout modif yi ng the state of
the f if o, wi thout call ing request_update, and wi th a return val ue of false. Otherwi se, i f a slot is f ree,
the return value of member f uncti on nb_write shall be true.
oper ator =
The behavi or of oper ator = shall be equi val ent to the foll owing def inition:
sc_f if o<T>& operator= ( const T& a ) { wri te( a ); return * this; }
6.23.8 The update phase
Member f unctions read, nb_read, wr ite, and nb_write shal l complete the act of reading or wri ti ng the fi fo
by call ing member functi on request_update of class sc_pr im_channel.
virtual void update();
Member function update of class sc_pr im_channel shal l be overridden in class sc_fifo to update
the number of values available f or readi ng and the number of f ree sl ots f or writing and shall cause
the data-wr i tten event or the data-r ead event to be notif ied i n the immedi ately f ollowi ng del ta
noti ficati on phase as necessary.
NOTEIf a fifo is empty and member functions wr ite and r ead are both cal led (f rom the same process or f rom
two di f f erent processes) duri ng the eval uation phase of the same del ta cycl e, the wri te wi l l compl ete i n that
del ta cycl e, but the read wil l suspend because the f i f o i s empty. The number of val ues avai l abl e f or readi ng wi l l
be i ncremented to one duri ng the update phase, and the read wi l l compl ete i n the f ol l owi ng del ta cycl e,
returni ng the value j ust wri tten.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


177
Copyright 2012 IEEE. All rights reserved.
6.23.9 Member functions for events
virtual const sc_event& data_wr itten_event() const;
Member function data_wr itten_event shall return a ref erence to an event, the data-wri tten event,
that i s noti fi ed in the del ta notif icati on phase that occurs at the end of the del ta cycle in which a
val ue i s written into the fi fo.
virtual const sc_event& data_read_event() const;
Member functi on data_read_event shall return a reference to an event, the data-r ead event, that i s
noti fied i n the del ta notif icati on phase that occurs at the end of the delta cycl e i n which a val ue i s
read from the f if o.
6.23.10 Member functions for available values and free slots
virtual int num_available() const;
Member function num_available shall return the number of val ues that are available f or readi ng in
the current del ta cycl e. The cal cul ation shal l deduct any val ues read duri ng the current delta cycle
but shall not add any values written during the current delta cycl e.
virtual int num_fr ee() const;
Member function num_fr ee shall return the number of empty sl ots that are f ree for writing in the
current delta cycle. The calculation shal l deduct any slots wri tten during the current del ta cycle but
shal l not add any slots made f ree by reading in the current del ta cycl e.
6.23.11 Diagnostic member functions
virtual void pr int( std::ostream& = std::cout ) const;
Member f uncti on pr int shall print a li st of the val ues stored in the fi fo and that are avail abl e f or
reading. They wil l be printed i n the order they were written to the fi fo and are pri nted to the stream
passed as an argument by call ing oper ator << (std::ostream& , T& ). The f ormatting shal l be
impl ementation-def ined.
virtual void dump( std::ostream& = std::cout ) const;
Member functi on dump shall pri nt at l east the hi erarchical name of the f if o and a l ist of the values
stored i n the fi fo that are avail able f or readi ng. They are pri nted to the stream passed as an argument.
The f ormatting shall be implementation-def ined.
virtual const char* kind() const;
Member f uncti on kind shal l return the string " sc_fifo" .
6.23.12 operator<<
templ ate <class T>
inl ine std::ostream& oper ator << ( std::ostream& , const sc_fi fo<T>& );
oper ator << shal l cal l member f uncti on pr int to pri nt the contents of the f if o passed as the second
argument to the stream passed as the fi rst argument by cal li ng operator oper ator <<
(std::ostream& , T& ).
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


178
Copyright 2012 IEEE. All rights reserved.
Exampl e:
SC_MODULE(M)
{
sc_f if o<i nt> f if o;
SC_CTOR(M) : fi fo(4)
{
SC_THREAD(T);
}
void T()
{
int d;
fi fo.write(1);
f if o.pri nt(std::cout); // 1
fi fo.write(2);
f if o.pri nt(std::cout); // 1 2
fi fo.write(3);
f if o.pri nt(std::cout); // 1 2 3
std::cout << f if o.num_avai lable(); // 0 val ues available to read
std::cout << f if o.num_f ree(); // 1 f ree sl ot
f if o.read(d); // read suspends and returns i n the next delta cycl e
f if o.pri nt(std::cout); // 2 3
std::cout << f if o.num_avai lable(); // 2 val ues available to read
std::cout << f if o.num_f ree(); // 1 f ree sl ot
f if o.read(d);
f if o.pri nt(std::cout); // 3
f if o.read(d);
f if o.pri nt(std::cout); // Empty
std::cout << f if o.num_avai lable(); // 0 val ues available to read
std::cout << f if o.num_f ree(); // 1 f ree sl ot
wait(SC_ZERO_TI ME);
std::cout << f if o.num_f ree(); // 4 f ree sl ots
}
} ;
6.24 sc_fifo_in
6.24.1 Description
Cl ass sc_fifo_in i s a speciali zed port cl ass f or use when readi ng from a f if o. I t provi des f unctions to access
conveniently certai n member f unctions of the f if o to which the port is bound.
6.24.2 Class definition
namespace sc_core {
templ ate <class T>
class sc_fifo_in
: publi c sc_port<sc_f if o_i n_i f<T>,0>
{
publ ic:
sc_fifo_in();
expl icit sc_fifo_in( const char* );
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


179
Copyright 2012 IEEE. All rights reserved.
virtual ~sc_fifo_in();
void read( T& );
T read();
bool nb_read( T& );
const sc_event& data_wr itten_event() const;
sc_event_f inder& data_wr itten() const;
int num_available() const;
virtual const char* kind() const;
pri vate:
// Di sabl ed
sc_fifo_in( const sc_fi fo_in<T>& );
sc_f if o_i n<T>& oper ator = ( const sc_fi fo_in<T>& );
} ;
} // namespace sc_core
6.24.3 Member functions
The constructors shal l pass their arguments to the corresponding constructor for the base class sc_por t.
Member functi ons read, nb_read, data_wr itten_event, and num_available shall each cal l the
corresponding member f unction of the obj ect to which the port is bound using oper ator-> of cl ass sc_por t,
f or example:
T read() { return (* thi s)->read(); }
Member f unction data_wr itten shall return a reference to cl ass sc_event_finder, where the event f inder
object itself shall be constructed using the member function data_wr itten_event (see 5.7).
Member f uncti on kind shall return the string " sc_fifo_in" .
6.25 sc_fifo_out
6.25.1 Description
Cl ass sc_fifo_out i s a speci al ized port cl ass f or use when writing to a f if o. I t provi des f uncti ons to access
conveniently certai n member f unctions of the f if o to which the port is bound.
6.25.2 Class definition
namespace sc_core {
templ ate <class T>
class sc_fifo_out
: publi c sc_port<sc_f if o_out_if <T>,0>
{
publ ic:
sc_fifo_out();
expl icit sc_fifo_out( const char* );
virtual ~sc_fifo_out();
void wr ite( const T& );
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


180
Copyright 2012 IEEE. All rights reserved.
bool nb_write( const T& );
const sc_event& data_read_event() const;
sc_event_f inder& data_read() const;
int num_fr ee() const;
virtual const char* kind() const;
pri vate:
// Di sabl ed
sc_fifo_out( const sc_fi fo_out<T>& );
sc_f if o_out<T>& oper ator = ( const sc_fi fo_out<T>& );
} ;
} // namespace sc_core
6.25.3 Member functions
The constructors shal l pass their arguments to the corresponding constructor for the base class sc_por t.
Member functions wr ite, nb_write, data_read_event, and num_fr ee shal l each call the corresponding
member functi on of the object to whi ch the port i s bound usi ng oper ator-> of class sc_por t, for example:
void wri te( const T& a ) { (* this)->wri te( a ); }
Member f uncti on data_read shall return a reference to class sc_event_finder , where the event f inder obj ect
itsel f shal l be constructed using the member functi on data_read_event (see 5.7).
Member f uncti on kind shall return the string " sc_fifo_out" .
Exampl e:
// Type passed as templ ate argument to sc_fi fo<>
class U
{
publ ic:
U(int val = 0) // If any constructor exi sts, a def aul t constructor is required.
{
ptr = new i nt;
* ptr = val;
}
int get() const { return * ptr; }
void set(i nt i) { * ptr = i; }
// Default assi gnment semanti cs are i nadequate
const U& operator= (const U& arg) { * (thi s->ptr) = * (arg.ptr); return * thi s; }
pri vate:
int * ptr;
} ;
// operator<< required
std::ostream& operator<< (std::ostream& os, const U& arg) { return (os << arg.get()); }
SC_MODULE(M1)
{
sc_f if o_out<U> f if o_out;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


181
Copyright 2012 IEEE. All rights reserved.
SC_CTOR(M1)
{
SC_THREAD(producer);
}
void producer()
{
U u;
f or (i nt i = 0; i < 4; i++)
{
u.set(i);
bool status;
do {
wait(1, SC_NS);
status = f if o_out.nb_wri te(u); // Non-blocki ng write
} whi le (! status);
}
}
} ;
SC_MODULE(M2)
{
sc_f ifo_i n<U> fif o_in;
SC_CTOR(M2)
{
SC_THREAD(consumer);
sensitive << f if o_in.data_written();
}
void consumer()
{
for (;;)
{
wait(f if o_i n.data_written_event());
U u;
bool status = f if o_i n.nb_read(u);
std::cout << u << " "; // 0 1 2 3
}
}
} ;
SC_MODULE(Top)
{
sc_f if o<U> f if o;
M1 m1;
M2 m2;
SC_CTOR(Top)
: m1("m1"), m2("m2")
{
m1.f ifo_out(fi fo);
m2.fi fo_i n (fi fo);
}
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


182
Copyright 2012 IEEE. All rights reserved.
} ;
6.26 sc_mutex_if
6.26.1 Description
Cl ass sc_mutex_if is an i nterf ace proper and is impl emented by the predef ined channel sc_mutex.
6.26.2 Class definition
namespace sc_core {
class sc_mutex_if
: vi rtual publi c sc_i nterf ace
{
publ ic:
virtual i nt lock() = 0;
virtual i nt trylock() = 0;
virtual i nt unlock() = 0;
protected:
sc_mutex_if();
pri vate:
// Di sabl ed
sc_mutex_if( const sc_mutex_i f& );
sc_mutex_if & oper ator = ( const sc_mutex_if & );
} ;
} // namespace sc_core
6.26.3 Member functions
The behavi or of the member functi ons of cl ass sc_mutex_if is def ined i n cl ass sc_mutex.
6.27 sc_mutex
6.27.1 Description
Cl ass sc_mutex is a predef ined channel intended to model the behavi or of a mutual excl usi on lock used to
control access to a resource shared by concurrent processes. A mutex i s an obj ect of class sc_mutex. A
mutex shal l be i n one of two excl usi ve states: unl ocked or l ocked. Only one process can l ock a given mutex
at one time. A mutex can only be unl ocked by the parti cul ar process instance that locked the mutex but may
be l ocked subsequently by a dif ferent process.
6.27.2 Class definition
namespace sc_core {
class sc_mutex
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


183
Copyright 2012 IEEE. All rights reserved.
: publi c sc_mutex_i f, publ ic sc_object
{
publ ic:
sc_mutex();
expl icit sc_mutex( const char* );
virtual i nt lock();
virtual i nt trylock();
virtual i nt unlock();
virtual const char* kind() const;
pri vate:
// Di sabl ed
sc_mutex( const sc_mutex& );
sc_mutex& oper ator = ( const sc_mutex& );
} ;
} // namespace sc_core
6.27.3 Constructors
sc_mutex();
This constructor shall cal l the base class constructor f rom i ts ini tial izer li st as f ol lows:
sc_object( sc_gen_uni que_name( "mutex" ) )
expl icit sc_mutex( const char* name_ );
This constructor shall cal l the base class constructor f rom i ts ini tial izer li st as f ol lows:
sc_object( name_ )
Both constructors shal l unlock the mutex.
6.27.4 Member functions
virtual int lock();
I f the mutex is unl ocked, member f unction lock shal l lock the mutex and return.
I f the mutex is l ocked, member f uncti on lock shal l suspend until the mutex is unlocked (by another
process). At that poi nt, it shall resume and attempt to lock the mutex by applying these same rul es
agai n.
Member f uncti on lock shall unconditi onal ly return the value 0.
I f mul ti pl e processes attempt to lock the mutex in the same del ta cycl e, the choice of whi ch process
instance is gi ven the l ock in that del ta cycle shall be non-deterministi c; that is, i t wi ll rel y on the
order i n whi ch processes are resumed wi thin the eval uation phase.
virtual int trylock();
I f the mutex i s unlocked, member function trylock shall lock the mutex and shall return the value 0.
I f the mutex i s l ocked, member f uncti on trylock shall immediately return the value 1. The mutex
shal l remain l ocked.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


184
Copyright 2012 IEEE. All rights reserved.
virtual int unlock();
I f the mutex i s unlocked, member function unlock shall return the value 1. The mutex shall remain
unlocked.
I f the mutex was l ocked by a process instance other than the call ing process, member functi on
unlock shall return the value 1. The mutex shall remain locked.
I f the mutex was locked by the call ing process, member f uncti on unlock shall unl ock the mutex and
shal l return the val ue 0. If processes are suspended and are wai ti ng f or the mutex to be unlocked, the
lock shal l be gi ven to exactly one of these processes (the choi ce of process i nstance bei ng non-
determi nisti c) whi le the remaini ng processes shall suspend again. This shall be accompli shed wi thi n
a si ngl e evaluati on phase; that i s, an i mplementati on shall use i mmediate noti ficati on to si gnal the
act of unlocki ng a mutex to other processes.
virtual const char* kind() const;
Member f uncti on kind shal l return the string " sc_mutex" .
6.28 sc_semaphore_if
6.28.1 Description
Cl ass sc_semaphore_if is an i nterf ace proper and is impl emented by the predef ined channel sc_semaphore.
6.28.2 Class definition
namespace sc_core {
class sc_semaphore_if
: vi rtual publi c sc_i nterf ace
{
publ ic:
virtual i nt wait() = 0;
virtual i nt trywait() = 0;
virtual i nt post() = 0;
virtual i nt get_value() const = 0;
protected:
sc_semaphore_if();
pri vate:
// Di sabl ed
sc_semaphore_if( const sc_semaphore_if& );
sc_semaphore_if & oper ator = ( const sc_semaphore_i f& );
} ;
} // namespace sc_core
6.28.3 Member functions
The behavi or of the member functi ons of cl ass sc_semaphore_if is def ined in cl ass sc_semaphor e.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


185
Copyright 2012 IEEE. All rights reserved.
6.29 sc_semaphore
6.29.1 Description
Cl ass sc_semaphore i s a predef ined channel intended to model the behavior of a sof tware semaphore used
to provi de l imi ted concurrent access to a shared resource. A semaphore has an i nteger val ue, the semaphore
val ue, which is set to the permi tted number of concurrent accesses when the semaphore is constructed.
6.29.2 Class definition
namespace sc_core {
class sc_semaphore
: publi c sc_semaphore_if , publ ic sc_obj ect
{
publ ic:
expl icit sc_semaphore( i nt );
sc_semaphore( const char* , i nt );
virtual i nt wait();
virtual i nt trywait();
virtual i nt post();
virtual i nt get_value() const;
virtual const char* kind() const;
pri vate:
// Di sabl ed
sc_semaphore( const sc_semaphore& );
sc_semaphore& oper ator = ( const sc_semaphore& );
} ;
} // namespace sc_core
6.29.3 Constructors
expl icit sc_semaphore( i nt );
This constructor shall cal l the base class constructor f rom i ts ini tial izer li st as f ol lows:
sc_object( sc_gen_uni que_name( "semaphore" ) )
sc_semaphore( const char* name_, i nt );
This constructor shall cal l the base class constructor f rom i ts ini tial izer li st as f ol lows:
sc_object( name_ )
Both constructors shall set the semaphore val ue to the val ue of the int parameter, which shall be non-
negati ve.
6.29.4 Member functions
virtual int wait();
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


186
Copyright 2012 IEEE. All rights reserved.
I f the semaphore value is greater than 0, member f unction wait shall decrement the semaphore value
and return.
I f the semaphore value is equal to 0, member f uncti on wait shal l suspend unti l the semaphore value
is incremented (by another process). At that poi nt, i t shall resume and attempt to decrement the
semaphore val ue by applyi ng these same rules agai n.
Member f uncti on wait shall unconditi onal ly return the value 0.
The semaphore value shall not become negati ve. I f multiple processes attempt to decrement the
semaphore value in the same del ta cycle, the choi ce of whi ch process instance decrements the
semaphore value and which processes suspend shall be non-determi ni stic; that is, i t wi ll rel y on the
order i n whi ch processes are resumed wi thin the eval uation phase.
virtual int trywait();
I f the semaphore value is greater than 0, member f unction trywait shal l decrement the semaphore
val ue and shall return the val ue 0.
I f the semaphore value i s equal to 0, member function tr ywait shall immediately return the value 1
wi thout modif yi ng the semaphore val ue.
virtual int post();
Member functi on post shall i ncrement the semaphore value. I f processes exist that are suspended
and are wai ti ng f or the semaphore val ue to be i ncremented, exactl y one of these processes shal l be
permi tted to decrement the semaphore val ue (the choice of process instance being non-
determi nisti c) whi le the remaini ng processes shall suspend again. This shall be accompli shed wi thi n
a si ngl e evaluati on phase; that i s, an i mplementati on shall use i mmediate noti ficati on to si gnal the
act of incrementi ng the semaphore val ue to any wai ti ng processes.
Member f uncti on post shall unconditi onal ly return the value 0.
virtual int get_value() const;
Member f uncti on get_value shall return the semaphore value.
virtual const char* kind() const;
Member f uncti on kind shal l return the string " sc_semaphore" .
NOTE 1The semaphore value may be decremented and i ncremented by di f f erent processes.
NOTE 2The semaphore value may exceed the value set by the constructor.
6.30 sc_event_queue
6.30.1 Description
Cl ass sc_event_queue represents an event queue. Like cl ass sc_event, an event queue has a member
functi on notify. Unl ike an sc_event, an event queue is a hierarchical channel and can have multiple
notif icati ons pending.
6.30.2 Class definition
namespace sc_core {
class sc_event_queue_if
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


187
Copyright 2012 IEEE. All rights reserved.
: publi c vi rtual sc_i nterf ace
{
publ ic:
virtual void notify( double , sc_time_unit ) = 0;
virtual void notify( const sc_ti me& ) = 0;
virtual void cancel_all() = 0;
} ;
class sc_event_queue
: publi c sc_event_queue_if , publ ic sc_modul e
{
publ ic:
sc_event_queue( sc_modul e_name name_=
sc_module_name(sc_gen_unique_name(event_queue)));
~sc_event_queue();
virtual const char* kind() const;
virtual void notify( double , sc_time_unit );
virtual void notify( const sc_ti me& );
virtual void cancel_all();
virtual const sc_event& default_event() const;
} ;
} // namespace sc_core
6.30.3 Constraints on usage
Cl ass sc_event_queue i s a hierarchi cal channel , and thus, sc_event_queue objects can only be constructed
duri ng elaborati on.
NOTEAn object of class sc_event_queue cannot be used i n most contexts requi ri ng an sc_event but can be used to
create stati c sensi ti vi ty because i t i mpl ements member f unction sc_inter face::default_event.
6.30.4 Constructors
sc_event_queue( sc_module_name name_= sc_module_name(sc_gen_unique_name(event_queue)));
This constructor shal l pass the module name argument through to the constructor for the base class
sc_module.
6.30.5 kind
Member f uncti on kind shall return the string " sc_event_queue" .
6.30.6 Member functions
virtual void notify( double , sc_time_unit );
virtual void notify( const sc_ti me& );
A call to member f uncti on notify wi th an argument that represents a zero time shall cause a del ta
noti ficati on on the def aul t event.
A call to functi on notify wi th an argument that represents a non-zero time shall cause a timed
noti ficati on on the default event at the given ti me, expressed rel ative to the simul ation time when
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


188
Copyright 2012 IEEE. All rights reserved.
f uncti on notify i s cal led. In other words, the value of the time argument i s added to the current
simul ation ti me to determine the time at whi ch the event wi ll be noti fied.
I f f uncti on notify i s call ed when there is a al ready one or more notif ications pending, the new
noti ficati on shal l be queued i n addi ti on to the pending noti fi cations. Each queued notif icati on shal l
occur at the ti me determined by the semantics of function notify, i rrespective of the order i n which
the cal ls to notify are made.
The defaul t event shal l not be notif ied more than once in any one del ta cycl e. I f multiple
noti ficati ons are pendi ng f or the same del ta cycl e, those noti fi cati ons shal l occur in successive del ta
cycl es. I f mul ti ple ti med notif icati on are pending f or the same si mulati on ti me, those noti fi cati ons
shal l occur in successive del ta cycl es starting wi th the f irst del ta cycl e at that si mulati on time step
and wi th no gaps i n the del ta cycl e sequence.
virtual void cancel_all();
Member f uncti on cancel_all shall immedi atel y del ete every pendi ng noti ficati on f or thi s event
queue object including both delta and ti med noti fi cati ons, but i t shall have no ef fect on other event
queue obj ects.
virtual const sc_event& default_event() const;
Member f uncti on default_event shal l return a ref erence to the default event.
The mechanism used to queue noti ficati ons shal l be impl ementation-defi ned, with the proviso that
an event queue object must provi de a single default event that is notif ied once for every cal l to
member f uncti on notify.
NOTEEvent queue notifications are anonymous i n the sense that the onl y inf ormati on carri ed by the defaul t
event i s the ti me of noti f i cati on. A process i nstance sensi ti ve to the def aul t event cannot tel l whi ch cal l to
f uncti on notify caused the noti f i cation.
Exampl e:
sc_event_queue EQ;
SC_CTOR(Mod)
{
SC_THREAD(T);
SC_METHOD(M);
sensitive << EQ;
dont_initiali ze();
}
void T()
{
EQ.notif y(2, SC_NS); // M runs at time 2ns
EQ.notif y(1, SC_NS); // M runs at time 1ns, 1
st
or 2
nd
del ta cycle
EQ.notif y(SC_ZERO_TIME); // M runs at time 0ns
EQ.notif y(1, SC_NS); // M runs at time 1ns, 2
nd
or 1
st
del ta cycle
}
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


189
Copyright 2012 IEEE. All rights reserved.
7. SystemC data types
7.1 Introduction
Al l native C++ types are supported within a SystemC appl ication. SystemC provides addi tional data type
classes within thesc_dt namespaceto represent valueswith appl icati on-speci fi c word lengthsappl icabl eto
digi tal hardware. Thesedatatypesarereferred to asSystemC data types.
TheSystemCdatatypeclassesconsi st of thefol lowing:
Li mi ted-pr eci si on i nteger s, which areclassesderi ved fromclasssc_i nt_base, cl ass sc_uint_base, or
instances of such cl asses. A li mi ted-precision integer shall represent a signed or unsi gned integer
val ueat apreci si onli mi tedby itsunderlying nati veC++ representation and i tsspecified wordlength.
Fi ni te-pr eci si on i nteger s, which are cl asses deri ved from class sc_signed, class sc_unsi gned, or
instancesof such cl asses. A fini te-preci si oninteger shall represent asigned or unsigned integer val ue
at apreci si onl imited onl y by i tsspecified word length.
Fi ni te-pr eci si on fi xed-poi nt types, which are classes derived from cl ass sc_fxnum or instances of
such cl asses. A fi nite-preci sion fi xed-point type shal l represent a signed or unsigned fixed-point
val ue at a precision l imi ted onl y by i ts speci fi ed word length, integer word l ength, quantization
mode, and overflow mode.
Li mi ted-pr eci si on fi xed-poi nt types, whi ch areclassesderivedfromclasssc_fxnum_fast or instances
of such classes. A l imited-preci si onfixed-point typeshal l represent asi gned or unsi gned fi xed-poi nt
val ueat a preci si on li mited by itsunderlying nati veC++ floati ng-point representation and i tsspeci-
fiedword l ength, i nteger word l ength, quantizati on mode, and overflow mode.
Vari abl e-preci si on fi xed-poi nt type, which is the cl ass sc_fxval. A variable-preci si on fixed-point
typeshall represent afi xed-point valuewithapreci sion that may vary over timeandi snot subj ect to
quantization or overfl ow.
Li mi ted var i abl e-pr eci si on fi xed-poi nt type, which i s the class sc_fxval _fast. A li mited vari abl e-
precision fixed-point type shal l represent a fi xed-poi nt value wi th a preci si on that is l imi ted by i ts
underlying C++ fl oati ng-point representati on and that may vary over ti me and i s not subj ect to
quantization or overfl ow.
Si ngl e-bi t l ogi c types impl ement a four-val ued logic data type with states l ogi c 0, l ogi c 1, hi gh-
i mpedance, and unknown and shall berepresented by thesymbol s ' 0' , ' 1' , ' X' , and 'Z' , respectively.
The lowercase symbols ' x' and 'z' are acceptabl e alternatives for ' X' and ' Z' , respectively, as
character literals assigned tosi ngl e-bit l ogi c types.
Bi t vector s, whi ch are cl asses deri ved from cl ass sc_bv_base, or instances of such cl asses. A bit
vector shal l i mplement amul ti plebit datatype, whereeach bi t hasastateof l ogi c 0 or l ogi c 1 and i s
representedby thesymbols ' 0' or ' 1', respecti vel y.
Logi c vector s, which arecl assesderived fromclasssc_l v_base, or i nstancesof such classes. A logic
vector shall impl ement a multipl e-bit data type, whereeach bit hasa state of l ogi c 0, l ogi c 1, hi gh-
i mpedance, or unknown and isrepresented by thesymbol s' 0' , ' 1', ' X' , or 'Z' . Thelowercasesymbols
' x' and 'z' are acceptable alternativesfor ' X' and ' Z' , respectivel y, within string li terals assi gned to
logic vectors.
Apart from the si ngle-bit logi c types, the vari abl e-precision fi xed-poi nt types, and the limited vari abl e-
precision fixed-poi nt types, the classes within each category are organized as an object-ori ented hi erarchy
wi th common behavi or definedin baseclasses. A cl asstemplateshal l bederivedfromeach basecl assby the
impl ementation such that appl icationscan speci fy wordl engthsastempl atearguments.
Theterm fi xed-poi nt type i s used in thi sstandard to refer to any finite-precision fixed-poi nt typeor li mi ted-
precision fi xed-point type. Thevariabl e-precision and l imi ted vari abl e-precision fi xed-poi nt typesarefixed-
point types onl y in the restricted sense that they store a representation of a fi xed-poi nt val ue and can be
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


190
Copyright 2012 IEEE. All rights reserved.
mi xed with other fi xed-poi nt types i n expressions, but they are not f ixed-poi nt types in the sense that they do
not model quanti zation or overfl ow ef fects and are not intended to be used directl y by an appli cation.
The term numer i c type is used i n this standard to refer to any l imi ted-preci si on integer, fi nite-precision
integer, fi nite-preci sion f ixed-point type, or l imi ted-precisi on fi xed-poi nt type. The term vector is used to
ref er to any bi t vector or l ogi c vector. The word l ength of a numeric type or vector object shall be set when
the object is i ni ti al ized and shall not subsequentl y be altered. Each bi t withi n a word shall have an index. The
right-hand bi t shal l have index 0 and is the least-signif icant bit f or numeri c types. The i ndex of the lef t-hand
bit shall be the word length mi nus 1.
The li mi ted-precision signed i nteger base class is sc_int_base. The l imited-preci si on unsigned integer base
class i s sc_uint_base. The correspondi ng class templ ates are sc_int and sc_uint, respecti vel y.
The fi nite-precision si gned i nteger base cl ass i s sc_signed. The f ini te-precisi on unsigned i nteger base cl ass
is sc_unsigned. The correspondi ng class templ ates are sc_bigint and sc_biguint, respecti vel y.
The si gned f ini te-precisi on fixed-point base class is sc_fix. The unsi gned f ini te-precision f ixed-point base
class i s sc_ufix. Both base classes are deri ved f rom cl ass sc_fxnum. The correspondi ng cl ass templ ates are
sc_fixed and sc_ufixed, respecti vel y.
The signed li mited-precision f ixed-poi nt base class is sc_fix_fast. The unsigned li mited-precision f ixed-
point base class is sc_ufix_fast. Both base classes are deri ved from classsc_fxnum_fast. The correspondi ng
class templ ates are sc_fixed_fast and sc_ufixed_fast, respecti vel y.
The vari abl e-precision fi xed-point cl ass is sc_fxval. The l imited variable-preci si on f ixed-point class i s
sc_fxval_fast. These two classes are used as the operand types and return types of many fi xed-poi nt
operations.
The bi t vector base cl ass i s sc_bv_base. The correspondi ng class templ ate i s sc_bv.
The l ogi c vector base class is sc_lv_base. The correspondi ng class templ ate i s sc_lv.
The single-bi t l ogi c type is sc_logic.
I t is recommended that appli cati ons create SystemC data type objects using the class templ ates gi ven in thi s
clause (f or exampl e, sc_int) rather than the untempl ated base cl asses (for example, sc_int_base).
The rel ati onships between the SystemC data type cl asses are shown in Tabl e 4.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


191
Copyright 2012 IEEE. All rights reserved.
7.2 Common characteristics
This subcl ause speci fi es some common characteri stics of the SystemC data types such as common operators
and functions. This subclause should be taken as speci f yi ng a set of obl igati ons on the impl ementation to
provide operators and f uncti ons wi th the gi ven behavi or. In some cases the i mplementati on has some
f lexi bil ity wi th regard to how the given behavior is impl emented. The remainder of Cl ause 7 gi ves a detai led
def ini ti on of the SystemC data type classes.
An underlyi ng principl e is that native C++ integer and f loati ng-poi nt types, C++ stri ng types, and SystemC
data types may be mi xed in expressions.
Equal ity and bi twise operators can be used f or all SystemC data types. Ari thmeti c and relational operators
can be used wi th the numeri c types only. The semanti cs of the equali ty operators, bitwise operators,
ari thmeti c operators, and relational operators are the same i n SystemC as i n C++.
User-defi ned conversi ons suppl ied by the i mplementation support translati on from SystemC types to C++
native types and other SystemC types.
Bit-select, part-sel ect, and concatenation operators return an instance of a proxy class. The term proxy cl ass
is used i n this standard to refer to a cl ass whose purpose is to represent a SystemC data type obj ect withi n an
expression and which provi des addi tional operators or f eatures not otherwi se present i n the represented
object. An example is a proxy cl ass that all ows an sc_int variable to be used as i f it were a C++ array of bool
and to disti ngui sh between its use as an rvalue or an l val ue withi n an expression. Instances of proxy cl asses
are only i ntended to be used wi thi n the expressions that create them. An appl i cation shoul d not cal l a proxy
Table 4SystemC data types
Class template Base class Gener ic base class Repr esentation Precision
sc_i nt sc_i nt_base sc_val ue_base si gned i nteger l i mi ted
sc_ui nt sc_ui nt_base sc_val ue_base unsi gned integer l i mi ted
sc_bi gi nt sc_si gned sc_val ue_base si gned i nteger f i ni te
sc_bi gui nt sc_unsi gned sc_val ue_base unsi gned i nteger f i ni te
sc_fi xed sc_f i x sc_f xnum si gned f i xed-poi nt f i ni te
sc_uf i xed sc_ufi x sc_f xnum unsi gned f i xed-poi nt f i ni te
sc_fi xed_fast sc_f ix_f ast sc_f xnum_fast si gned f i xed-poi nt l imi ted
sc_uf i xed_f ast sc_uf i x_f ast sc_f xnum_fast unsi gned f i xed-poi nt l i mi ted
sc_fxval f i xed-poi nt vari able
sc_fxval _f ast f i xed-poi nt l i mi ted-vari abl e
sc_l ogi c si ngl e bi t
sc_bv sc_bv_base bi t vector
sc_l v sc_l v_base l ogi c vector
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


192
Copyright 2012 IEEE. All rights reserved.
class constructor to createanamed obj ect and should not decl areapointer or referencetoaproxy class. It is
strongly recommended that an appli cation avoid the use of a proxy class as the return type of a functi on
becausetheli fetimeof theobj ect to which theproxy class refers may not extend beyond thefuncti onreturn
statement.
NOTE 1The bitwise shift left or shift right operation hasnomeaning for asingle-bit logic typeand isundefined.
NOTE 2The termuser -defi ned conver sions inthiscontext has thesamemeaningasin theC++ standard. It appliesto
type conversions of class objects by calling constructors and conversion functions that are used for implicit type
conversions and explicit typeconversions.
NOTE 3Care should be taken when mixing signed and unsigned numeric types in expressions that useimplicit type
conversions sincean implementationisnot requiredto issueawarning if thepolarity of aconvertedvalueischanged.
7.2.1 Initialization and assignment operators
Overl oaded constructors shall be provided by the i mplementation for al l i nteger (li mited-preci si on integer
and fi ni te-preci si on integer) class templates that all ow i ni ti ali zati on with an object of any SystemC data
type.
Overl oaded constructors shall be provided for al l vector (bit vector and l ogic vector) class templates that
all ow i nitiali zation withan obj ect of any SystemCi nteger or vector datatype.
Overloaded constructors shall be provided for all fini te-preci si on fixed-poi nt and l imi ted preci si on fixed-
point classtempl atesthat al low ini ti al ization wi th an object of any SystemCinteger datatype.
Al l SystemCdatatypeclassesshal l defineacopy constructor that createsacopy of thespeci fi edobject with
thesameval ueand thesameword length.
Overl oaded assi gnment operators and constructors shall perform di rect or indi rect conversion between
types. The data type basecl asses may define arestricted set of constructors and assi gnment operators that
only permi t direct initial ization froma subset of the SystemC datatypes. As a general principl e, data type
class templ ate constructors may be cal led impli ci tl y by an appli cation to perform conversion from other
typessincetheir word l ength isspeci fi ed by atempl ateargument. Ontheother hand, thedatatypebasecl ass
constructors wi th a single parameter of a di fferent type should only be cal led expl icitly si nce the required
word l ength is not specified.
If thetarget of an assi gnment operation has awordl engththat isi nsuffici ent to hol d thevalueassi gned to i t,
thel eft-hand bi tsof thevaluestored shal l betruncated to fit thetarget word length. If truncation occurs, an
implementation may generate a warni ng but i s not obl iged to do so, and an appli cation can in any case
disabl esuch awarning (see3.3.5).
If adata typeobject or string li teral i sassi gned to atarget havi ng a greater word l ength, the val ue shall be
extended with additional bits at i ts left-hand si de to match the target word l ength. Extension of a si gned
numeri c typeshall preservebothi ts si gn and magni tudeand isreferredtoassi gn extensi on. Extension of all
other types shall i nsert bitswi th avalueof logic 0 and is referred to as zer o extensi on.
Assi gnment of a fi xed-poi nt type to an integer type shal l use the i nteger component only; any fractional
component is discarded.
Assi gnment of avaluewithaword length greater than 1to asingle-bit logic typeshall bean error.
NOTEAn integer literal is always treated as unsigned unless prefixedby aminus symbol. An unsigned integer literal
will always beextended with leading zeroswhen assigned to adatatypeobject having alarger word length, regardless
of whether theobject itself issigned or unsigned.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


193
Copyright 2012 IEEE. All rights reserved.
7.2.2 Precision of arithmetic expressions
The type of the value returned by any arithmetic expression containing onl y l imi ted-precisi on integers or
li mi ted-precision i ntegers and native C++ i nteger types shal l be an impl ementation-defi ned C++ integer type
wi th a maxi mum word l ength of 64 bi ts. The acti on taken by an impl ementation i f the precision required by
the return value exceeds 64 bi ts i s undef ined and the val ue is impl ementation-dependent.
The val ue returned by any ari thmeti c expressi on containi ng onl y f ini te-precisi on i ntegers or f inite-precision
integers and any combinati on of li mi ted-precision or nati ve C++ integer types shall be a fi ni te-preci si on
integer wi th a word-l ength suff icient to contain the val ue wi th no l oss of accuracy.
The val ue returned by any ari thmeti c expression contai ning any fi xed-poi nt type shall be a vari abl e-
precision or li mi ted vari abl e-precisi on fi xed-point type (see 7.10.4).
Appli cati ons should use expl ici t type casts withi n expressions combining multiple types where an
impl ementation does not provi de overl oaded operators wi th si gnatures exactl y matchi ng the operand types.
Exampl e:
int i = 10;
sc_dt::i nt64 i 64 = 100; // long long i nt
sc_i nt<16> sci = 2;
sc_bigi nt<16> bi = 20;
fl oat f = 2.5;
sc_f ixed<16,8> scf = 2.5;
( i * sci ); // Ambiguous
( i * static_cast<sc_dt::i nt_type>(sci) ); // Impl ementation-defi ned C++ integer
( i * bi ); // 48-bit fi ni te-preci si on i nteger (assumes int = 32 bits)
( i 64 * bi ); // 80-bit fi ni te-precision integer
( f * bi ); // Ambiguous
( static_cast<int>(f ) * bi ); // 48-bit fi nite-precision integer (assumes int = 32 bits)
( scf * sci ); // Vari able-preci si on f ixed-point type
7.2.3 Base class default word length
The def ault word length of a data type base class shal l be used where i ts def aul t constructor is call ed
(impli citly or expli ci tl y). The def aul t word length shall be set by the l ength par ameter in context at the poi nt
of construction. A l ength parameter may be brought into context by creati ng a l ength context obj ect. Length
contexts shall have local scope and by def aul t be activated i mmediately. Once activated, they shal l remain in
eff ect f or as long as they are i n scope, or unti l another l ength context i s activated. Acti vation of a length
context shall be def erred i f its second constructor argument i s SC_LATER (the default value is SC_NOW).
A deferred l ength context can be activated by cal li ng i ts member function begin.
Length contexts shall be managed by a global l ength context stack. When a length context i s activated, it
shal l be pl aced at the top of the stack. A l ength context may be deactivated and removed f rom the top of the
stack by call ing its member f uncti on end. The end method shal l onl y be call ed f or the l ength context
currentl y at the top of the context stack. A length context i s i mpli citl y deacti vated and removed f rom the
stack when i t goes out of scope. A deferred l ength context that has been activated by cal li ng i ts member
functi on begin should be expl icitly deactivated and removed from the stack by call ing i ts member functi on
end. The current context shal l always be the length context at the top of the stack.
A length context shall onl y be acti vated once. An active length context shall onl y be deacti vated once.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


194
Copyright 2012 IEEE. All rights reserved.
The classes sc_length_param and sc_length_context shall be used to create l ength parameters and length
contexts, respectively, for SystemC integers and vectors.
I n addi ti on to the word length, the fi xed-point types shal l have default i nteger word length and mode
attri butes. These shall be set by the fi xed-poi nt type par ameter in context at the point of constructi on. A
f ixed-poi nt type parameter shall be brought i nto context by creating a fi xed-poi nt type context obj ect. The
use of a f ixed-point type context shall f oll ow the same rul es as a l ength context. A stack for f ixed-point type
contexts wi th the same characteristi cs as the length context stack shall exist.
The cl asses sc_fxtype_params and sc_fxtype_context shal l be used to create f ixed-poi nt type parameters
and f ixed-poi nt type contexts, respecti vel y.
Exampl e:
sc_length_param length10(10);
sc_length_context cntxt10(length10); // l ength10 now i n context
sc_i nt_base i nt_array[ 2] ; // Array of 10-bit integers
sc_core::sc_si gnal <sc_int_base> S1; // Signal of 10-bi t i nteger
{
sc_l ength_param length12(12);
sc_l ength_context cntxt12(length12,SC_LATER); // cntxt12 def erred
sc_l ength_param length14(14);
sc_l ength_context cntxt14(length14,SC_LATER); // cntxt14 def erred
sc_ui nt_base var1; // l ength 10
cntxt12.begi n(); // Bring length12 i nto context
sc_ui nt_base var2; // l ength 12
cntxt14.begi n(); // Bring length14 i nto context
sc_ui nt_base var3; // l ength 14
cntxt14.end(); // end cntx14, cntx12 restored
sc_bv_base var4; // l ength 12
} // cntxt12 out of scope, cntx10 restored
sc_bv_base var5; // l ength 10
NOTE 1The context stacks allow a def aul t context to be local l y repl aced by an alternative context and subsequentl y
restored.
NOTE 2An activated context remains acti ve f or thel i f eti me of the context obj ect or unti l i t i sexpli ci tl y deactivated. A
context can theref ore af fect the def aul t parameters of data type obj ects created outsi de of the functi on i n whi ch i t i s
activated. An appl i cation should ensure that any contexts created or activated wi thin f uncti ons whose executi on order i s
non-determi ni stic do not resul t i n temporal orderi ng dependenci es i n other parts of the appl i cati on. Fai l ure to meet thi s
condi ti on coul d resul t i n behavi or that i s i mplementati on-dependent.
7.2.4 Word length
The word l ength (a positive integer indicati ng the number of bits) of a SystemC i nteger, vector, part-sel ect,
or concatenation shall be returned by the member f uncti on length.
7.2.5 Bit-select
Bi t-sel ects are instances of a proxy class that reference the bi t at the speci fi ed posi tion withi n an associ ated
object that i s a SystemC numeri c type or vector.
The C++ subscri pt operator (oper ator [] ) shal l be overloaded by the implementati on to create a bit-select
when cal led wi th a single non-negative i nteger argument speci f yi ng the bi t position. I t shal l be an error i f the
specif ied bi t posi ti on i s outside the bounds of i ts numeric type or vector obj ect.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


195
Copyright 2012 IEEE. All rights reserved.
User-def ined conversions shall all ow bit-selects to be used i n expressions where a bool obj ect operand is
expected. A bi t-select of an lvalue may be used as an rval ue or an lvalue. A bi t-select of an rvalue shall only
be used as an rvalue.
A bit-sel ect or a bool val ue may be assigned to an l val ue bit-sel ect. The assignment shall modi fy the state of
the selected bi t wi thin the associated numeric type or vector object represented by the lvalue. An appl ication
shall not assign a value to an rval ue bi t-select.
Bit-selects f or integer, bit vector, and logic vector types shal l have an expli cit to_bool conversi on f uncti on
that returns the state of the selected bi t.
Exampl e:
sc_int<4> I 1; // 4 bi t signed i nteger
I 1[ 1] = true; // Selected bit used as l val ue
bool b0 = I 1[ 0].to_bool(); // Selected bit used as rvalue
NOTE 1Bit-selects corresponding to lvalues and rvalues of a particular type are themsel ves objects of two disti nct
cl asses.
NOTE 2A bit-select class can contain user-defined conversions for both impl i ci t and expl ici t conversion of the
sel ected bi t val ue to bool .
7.2.6 Part-select
Part-sel ects are instances of a proxy class that provi de access to a conti guous subset of bi ts wi thin an
associ ated object that i s a numeric type or vector.
The member f unction r ange( int , int ) of a numeri c type, bit vector, or l ogic vector shall create a part-select.
The two non-negati ve integer arguments speci fy the l eft- and ri ght-hand index positions. A part-sel ect shall
provide a reference to a word within its associated obj ect, starting at the l ef t-hand index position and
extendi ng to, and i ncl udi ng, the right-hand i ndex posi ti on. I t shal l be an error if the l ef t-hand index position
or right-hand index posi ti on l ies outside the bounds of the object.
The C++ functi on call operator (oper ator ()) shall be overl oaded by the i mplementati on to create a part-
sel ect and may be used as a direct replacement f or the r ange functi on.
User-def ined conversions shall all ow a part-sel ect to be used i n expressions where the expected operand is
an object of the numeric type or vector type associated wi th the part-sel ect, subj ect to certai n constraints (see
7.5.7.3, 7.6.8.3, and 7.9.8.3). A part-sel ect of an lvalue may be used as an rvalue or as an l value. A part-
sel ect of an rval ue shal l only be used as an rvalue.
I nteger part-sel ects may be di rectl y assigned to an object of any other SystemC data type, wi th the
excepti on of bi t-sel ects. Fixed-point part-sel ects may be directl y assigned to any SystemC i nteger or vector,
any part-select or any concatenation. Vector part-sel ects may onl y be di rectly assi gned to a vector, vector
part-sel ect, or vector concatenation (assi gnments to other types are ambiguous or require an expli cit
conversion).
The bits wi thin a part-sel ect do not ref lect the si gn of thei r associ ated object and shal l be taken as
representing an unsi gned binary number when converted to a numeric val ue. Assignments of part-selects to
a target having a greater word length shall be zero extended, regardl ess of the type of their associated obj ect.
Exampl e:
sc_int<8> I2 = 2; // "0b00000010"
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


196
Copyright 2012 IEEE. All rights reserved.
I 2.range(3,2) = I2.range(1,0); // "0b00001010"
sc_int<8> I 3 = I2.range(3,0); // "0b00001010"
// Zero-extended to 8 bi ts
sc_bv<8> b1 = "0b11110000";
b1.range(5,2) = b1.range(2,5); // "0b11001100"
// Reversed bi t-order between posi ti on 5 and 2
NOTE 1A part-select cannot be used to reverse the bi t-order of a l i mi ted-preci si on i nteger type.
NOTE 2Part-selects corresponding to lvalues and rval ues of a particul ar type are themsel ves obj ects of two di sti nct
cl asses.
NOTE 3A part-select is not required to be an acceptabl e repl acement where an obj ect ref erence operand i s expected. I f
an impl ementation provi des a mechani sm to al l ow such repl acements (for exampl e, by def i ni ng the appropri ate
overl oaded member f uncti ons), i t i s not requi red to do so f or al l data types.
7.2.7 Concatenation
Concatenati ons are instances of a proxy cl ass that ref erence the bits wi thin multiple obj ects as i f they were
part of a single aggregate obj ect.
The concat( arg0 , arg1 ) function shal l create a concatenati on. The concatenati on ar guments (arg0 and
arg1) may be two SystemC integer, vector, bit-sel ect, part-sel ect, or concatenati on objects. The C++ comma
operator (oper ator,) shal l al so be overl oaded to create a concatenati on and may be used as a di rect
replacement for the concat functi on.
The type of a concatenation argument shal l be a concatenati on base type, or it shal l be derived f rom a
concatenation base type. An i mplementati on shall provi de a common concatenation base type for all
SystemC i ntegers and a common concatenation base type f or all vectors. The concatenati on base type of bit-
sel ect and part-sel ect concatenation arguments is the same as thei r associated integer or vector obj ects. The
concatenation arguments may be any combinati on of two obj ects having the same concatenati on base type.
A concatenati on object shal l have the same concatenation base type as the concatenation arguments passed
to the functi on that created the object. The set of permi ssi bl e concatenation arguments f or a given
concatenation base type consists of the fol lowi ng:
a) Objects whose base class or concatenati on base type matches the gi ven concatenation base type
b) Bi t-selects of item a)
c) Part-selects of i tem a)
d) Concatenati ons of item a) and/or item b) and/or item c) in any combination
When both concatenation arguments are lvalues, the concatenati on shal l be an l val ue. I f any concatenation
argument is an rval ue, the concatenation shall be an rval ue.
A si ngl e concatenation argument may be a bool val ue when the other argument is a SystemC i nteger, vector,
bit-sel ect, part-select, or concatenation obj ect. The resulting concatenation shall be an rval ue.
An expressi on may be assigned to an l val ue concatenati on if the base type of the expression return val ue is
the same as the base type of the lvalue concatenati on. If the word length of a val ue assigned to a
concatenation wi th a si gned base type i s small er than the word length of the concatenati on, the value shal l be
sign-extended to match the word l ength of the concatenation. Assignments to concatenations of al l other
numeri c types and vectors shal l be zero-extended (if requi red). Assi gnment to a concatenati on shall update
the val ues of the objects speci fi ed by i ts concatenati on arguments.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


197
Copyright 2012 IEEE. All rights reserved.
A concatenati on may be assi gned to an object whose base cl ass i s the same as the concatenati on base type.
Where a concatenati on i s assigned to a target having a greater word l ength than the concatenation, i t i s zero-
extended to the target length. When a concatenati on i s assigned to a target havi ng a shorter word length than
the concatenation, the l ef t-hand bits of the val ue shall be truncated to fi t the target word l ength. If truncati on
occurs, an i mplementati on may generate a warni ng but i s not obliged to do so, and an applicati on can i n any
case di sable such a warning (see 3.3.5).
Exampl e:
The f oll owi ng concatenations are wel l-formed:
sc_uint<8> U1 = 2; // "0b00000010"
sc_uint<2> U2 = 1; // "0b01"
sc_uint<8> U3 = (true,U1.range(3,0),U2,U2[ 0]); // U3 = "0b10010011"
// Base cl ass same as concatenation base type
(U2[0],U1[ 0],U1.range(7,1)) = (U1[7],U1); // Copies U1[ 7] to U2[ 0] , U1 rotated lef t
concat(U2[0],concat(U1[ 0] ,U1.range(7,1))) = concat(U1[ 7] ,U1);
// Same as previ ous example but usi ng concat
The f oll owi ng concatenati ons are il l-formed:
sc_bv<8> Bv1;
(Bv1,U1) = "0xff ff "; // Bv1 and U1 do not share common base type
bool C1=true; bool C2 = fal se;
U2 = (C1,C1); // Cannot concatenate 2 bool obj ects
(C1,I 1) = "0x1f f"; // Bool concatenation argument creates rvalue
NOTE 1Parentheses are required around the concatenation arguments when usi ng the C++ comma operator because
of i ts l ow operator precedence.
NOTE 2An implementation is not requi red to support bi t-sel ects and part-sel ects of concatenati ons.
NOTE 3Concatenations corresponding to lvalues and rval ues of a parti cul ar type are themsel ves objects of two
di sti nct cl asses.
7.2.8 Reduction operators
The reduction operators shal l perf orm a sequence of bi twise operations on a SystemC i nteger or vector to
produce a bool result. The fi rst step shall be a boolean operation appl ied to the f irst and second bits of the
object. The boolean operation shal l then be re-appl ied usi ng the previ ous resul t and the next bi t of the object.
This process shal l be repeated unti l every bi t of the object has been processed. The value returned shall be
the resul t of the f inal bool ean operation. The f ol lowi ng reducti on operators shall be provi ded:
a) and_r educe performs a bitwise AND between all bi ts.
b) nand_r educe performs a bitwise NAND between all bits.
c) or_r educe performs a bitwise OR between all bi ts.
d) nor_reduce perf orms a bitwi se NOR between all bi ts.
e) xor_reduce performs a bitwise XOR between all bi ts.
f) xnor _reduce performs a bitwise XNOR between all bits.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


198
Copyright 2012 IEEE. All rights reserved.
7.2.9 Integer conversion
Al l SystemC data types shal l provi de an assignment operator that can accept a C++ i nteger value. A signed
val ue shal l be si gn-extended to match the l ength of the SystemC data type target.
SystemC data types shall provi de member f unctions f or expl ici t type conversi on to C++ integer types as
fol lows:
a) to_int converts to native C++ int type.
b) to_uint converts to nati ve C++ unsigned type.
c) to_long converts to native C++ long type.
d) to_ulong converts to nati ve C++ unsigned long type.
e) to_uint64() converts to a native C++ unsigned i nteger type havi ng a word l ength of 64 bits.
f) to_int64() converts to nati ve C++ integer type havi ng a word length of 64 bi ts.
These member f uncti ons shal l i nterpret the bits within a SystemC integer, f ixed-point type or vector, or any
part-sel ect or concatenation thereof , as representi ng an unsigned binary val ue, wi th the excepti on of si gned
integers and signed f ixed-point types.
Truncation shall be perf ormed where necessary for the value to be represented as a C++ i nteger.
Attempti ng to convert a logic vector containi ng 'X ' or 'Z ' val ues to an i nteger shall be an error.
7.2.10 String input and output
void scan( std::i stream& i s = std::ci n );
void pr int( std::ostream& os = std::cout ) const;
Al l SystemC data types shall provi de a member f unction scan that allows an obj ect value to be set
by reading a string f rom the speci fi ed C++ i nput stream. The stri ng content may use any of the
representations permitted by 7.3.
Al l SystemC data types shal l provi de a member f unction pr int that al lows an object value to be
written to a C++ output stream.
SystemC numeri c types shal l be pri nted as si gned or unsigned decimal values. SystemC vector types
shal l be printed as a string of bit val ues.
Al l SystemC data types shall support the output stream i nserter (oper ator <<) for f ormatted printi ng
to a C++ stream. The f ormat shal l be the same as f or the member functi on pr int.
The C++ ostream mani pul ators dec, oct, and hex shall have the same ef f ect f or li mited-preci si on
and f inite-precision integers and vector types as they do for standard C++ integers: that i s, they shall
cause the val ues of such obj ects to be pri nted in decimal , octal, or hexadeci mal formats,
respecti vel y. The formats used shall be those descri bed i n 7.3 with the exception that vectors shal l
be printed as a bi t-pattern string when the dec manipulator is acti ve.
Al l SystemC data types shal l support the i nput stream i nserter (oper ator >>) for f ormatted input
f rom a C++ i nput stream. The permi tted f ormats shall be the same as those permi tted f or the member
f uncti on scan.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


199
Copyright 2012 IEEE. All rights reserved.
void dump ( std::ostream& os = std::cout ) const;
Al l f ixed-poi nt types shall additional ly provide a member functi on dump that shal l print at least the
type name and value to the stream passed as an argument. The purpose of dump i s to all ow an
impl ementation to dump out diagnosti c i nf ormation to hel p the user debug an appl ication.
7.2.11 Conversion of application-defined types in integer expressions
The generi c base proxy cl ass templ atesc_gener ic_base shall be provided by the i mplementati on and may be
used as a base class f or appl ication-defi ned classes.
Al l SystemC integer, i nteger part-select, and i nteger concatenation cl asses shall provi de an assi gnment
operator that accepts an obj ect derived f rom the generic base proxy class template. All SystemC integer
classes shall additionally provi de an overloaded constructor with a single argument that is a constant
ref erence to a generic base proxy object.
NOTEThe generic base proxy class is not i ncl uded i n the col l ecti on of cl asses described by the term SystemC data
types as used in this standard.
7.3 String literals
A string l iteral representati on may be used as the value of a SystemC numeri c or vector type obj ect. It shall
consist of a standard pref ix f ol lowed by a magni tude expressed as one or more digi ts.
The magnitude representation for SystemC i nteger types shall be based on that of C++ i nteger literals.
The magni tude representati on for SystemC vector types shall be based on that of C++ unsi gned i nteger
li teral s.
The magnitude representati on f or SystemC f ixed-point types shall be based on that of C++ f loati ng li teral s
but wi thout the optional fl oating suff ix.
Where al phabetic characters appear i n the pref ix or magnitude representati ons, each indi vi dual character
may be a lowercase letter or an uppercase letter. A string l iteral representation shall not be case sensi ti ve.
The permi tted representations are identi fi ed wi th a symbol from the enumerated type sc_numr ep as
specif ied in Tabl e 5.
An i mplementati on shall provide overl oaded constructors and assi gnment operators that permit the val ue of
any SystemC numeric type or vector to be set by a character string havi ng one of the pref ixes specif ied in
Table 5. The character + or - may optionally be placed before the prefix for decimal and sign &
magnitude formats to indicate polarity. The prefix shall be foll owed by an unsi gned i nteger value, except in
the cases of the bi nary, octal, and hexadeci mal formats, where the prefix shall be followed by a twos
complement value expressed as a bi nary, octal , or hexadeci mal i nteger, respecti vely. An i mplementati on
shal l sign-extend any i nteger stri ng l iteral used to set the val ue of an obj ect having a l onger word l ength.
The canoni cal signed di gi t representation shall use the character - to represent the bit value 1.
A bit-pattern stri ng (containi ng bit or logic character val ues with no pref ix) may be assigned to a vector. If
the number of characters in the bit-pattern stri ng is less than the vector word length, the string shal l be zero
extended at i ts lef t-hand si de to the vector word length. The result of assi gni ng such a stri ng to a numeric
type is undefi ned.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


200
Copyright 2012 IEEE. All rights reserved.
An instance of a SystemC numeric type, vector, part-select, or concatenati on may be converted to a C++
std::str ing obj ect by call ing itsmember functi on to_str ing. Thesignatureof to_str ing shal l beasfoll ows:
std::stri ngto_stri ng( sc_numrepnumrep , bool with_prefix );
The numrep argument shall be one of the sc_numr ep values given in Table5. The magnitude
representation in a stri ng created from an unsigned i nteger or vector shal l be prefi xed by a single zero,
except where numrep i s SC_DEC. If the wi th_prefi x argument i s true, the prefix correspondi ng to the
numrep valuei n Tabl e5 shal l beappended to theleft-hand sideof theresulting stri ng. Thedefaul t val ueof
wi th_prefi x shal l betrue.
It shal l bean error to call themember functi on to_str ing of al ogi c-vector object if any of itsel ementshave
theval ue'X ' or 'Z '.
The val ue of an i nstance of a si ngle-bi t logic type may be converted to a si ngl e character by cal li ng its
member functi on to_char.
Exampl e:
sc_int<4> I1; // 4-bit si gned integer
I1 = "0b10100"; // 5-bit si gned bi nary literal truncated to 4 bi ts
std::stri ngS1 = I1.to_string(SC_BIN,true); // Thecontents of S1 wil l bethestring "0b0100"
sc_int<10> I2; // 10-bit integer
I2= "0d478"; // Deci mal equi val ent of "0b0111011110"
std::stri ngS2 = I2.to_string(SC_CSD,fal se); // Thecontentsof S2 wil l bethestri ng "1000-000-0"
sc_uint<8> I3; // 8-bit unsignedi nteger
Table 5String literal representation
sc_numr ep Pr efix (not case sensitive) M agnitude for mat
SC_NOBASE implementation-defined implementation-defined
SC_DEC 0d decimal
SC_BIN 0b binary
SC_BIN_US 0bus binary unsigned
SC_BIN_SM 0bsm binary sign & magnitude
SC_OCT 0o octal
SC_OCT_US 0ous octal unsigned
SC_OCT_SM 0osm octal sign & magnitude
SC_HEX 0x hexadecimal
SC_HEX_US 0xus hexadecimal unsigned
SC_HEX_SM 0xsm hexadecimal sign & magnitude
SC_CSD 0csd canonical signed digit
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


201
Copyright 2012 IEEE. All rights reserved.
I 3 = "0x7"; // Zero-extended to 8-bi t val ue "0x07"
std::stri ng S3 = I3.to_string(SC_HEX); // The contents of S3 wil l be the string "0x007"
sc_lv<16> lv; // 16-bit logic vector
lv = "0xff "; // Sign-extended to 16-bit val ue "0xf ff f"
std::stri ng S4 = lv.to_string(SC_HEX); // The contents of S4 wil l be the stri ng "0x0ff ff "
sc_bv<8> bv; // 8-bit bi t vector
bv = "11110000"; // Bit-pattern stri ng
std::stri ng S5 = bv.to_string(SC_BI N); // The contents of S5 wil l be the stri ng "0b011110000"
NOTESystemC data types may provi de addi ti onal overl oaded to_str ing f uncti ons that requi re a di f f erent number of
arguments.
7.4 sc_value_base

7.4.1 Description
Cl ass sc_val ue_base

provides a common base class f or all SystemC l imited-preci si on i ntegers and fi nite-
precision integers. I t provides a set of vi rtual methods that may be call ed by an i mplementati on to perform
concatenation operations.
7.4.2 Class definition
namespace sc_dt {
class sc_val ue_base


{
f ri end cl ass sc_concatr ef

;
pri vate:
virtual void concat_clear _data( bool to_ones=f al se );
virtual bool concat_get_ctr l( i mpl ementati on-defi ned* dst_p , int l ow_i ) const;
virtual bool concat_get_data( i mpl ementati on-defi ned* dst_p , int l ow_i ) const;
virtual uint64 concat_get_uint64() const;
virtual i nt concat_length( bool* xz_present_p=0 ) const;
virtual void concat_set( i nt64 src , i nt low_i );
virtual void concat_set( const sc_si gned& src , int l ow_i );
virtual void concat_set( const sc_unsi gned& src , i nt l ow_i );
virtual void concat_set( ui nt64 src , int low_i );
} ;
} // namespace sc_dt
7.4.3 Constraints on usage
An appli cati on should not create an object of type sc_val ue_base

and shoul d not di rectly call any member


f uncti on i nherited by a derived cl ass from an sc_val ue_base

parent.
I f an appl icati on-def ined cl ass deri ved from the generi c base proxy class templ ate sc_gener ic_base is also
derived f rom sc_val ue_base

, objects of thi s class may be used as arguments to an i nteger concatenati on.


Such a class shal l overri de the vi rtual member f uncti ons of sc_val ue_base

as private members to provide


the concatenation operati ons permi tted f or obj ects of that type.
I t shal l be an error for any member functi on of sc_val ue_base

that i s not overri den i n a derived class to be


cal led for an obj ect of the derived class.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


202
Copyright 2012 IEEE. All rights reserved.
7.4.4 Member functions
virtual void concat_clear _data( bool to_ones=f al se );
Member f unction concat_clear _data shal l set every bit in the sc_val ue_base

object to the state


provided by the argument.
virtual bool concat_get_ctr l( i mpl ementati on-defi ned* dst_p , int l ow_i ) const;
Member f unction concat_get_ctr l shal l copy control data to the packed-array given as the f irst
argument, starti ng at the bi t posi ti on wi thi n the packed-array gi ven by the second argument. The
return val ue shal l always be false. The type of the f irst argument shall be a poi nter to an unsi gned
integral type.
virtual bool concat_get_data( i mpl ementati on-defi ned* dst_p , int l ow_i ) const;
Member functi on concat_get_data shall copy data to the packed-array given as the fi rst argument,
starting at the bi t posi tion wi thin the packed-array gi ven by the second argument. The return val ue
shal l be true i f the data i s non-zero; otherwise, i t shall be false. The type of the fi rst argument shall
be a pointer to an unsigned i ntegral type.
virtual uint64 concat_get_uint64() const;
Member function concat_get_uint64 shal l return the value of the sc_val ue_base

object as a C++
unsi gned integer havi ng a word length of exactl y 64-bi ts.
virtual int concat_length( bool* xz_present_p=0 ) const;
Member f unction concat_length shal l return the number of bi ts in the sc_val ue_base

object. The
val ue of the obj ect associ ated wi th the optional argument shal l be set to true if any bits have the
val ue ' X' ' or ' Z' .
virtual void concat_set( i nt64 src , i nt low_i );
virtual void concat_set( const sc_si gned& src , i nt l ow_i );
virtual void concat_set( const sc_unsi gned& src , i nt l ow_i );
virtual void concat_set( ui nt64 src , int low_i );
Member functi on concat_set shall set the value of the sc_val ue_base

obj ect to the bi t-pattern of the


integer given by the f irst argument. The bi t-pattern shall be read as a contiguous sequence of bi ts
starting at the position gi ven by the second argument.
7.5 Limited-precision integer types
7.5.1 Type definitions
The f ol lowi ng type defi ni ti ons are used i n the li mi ted-precision integer type cl asses:
namespace sc_dt {
typedef i mpl ementati on-defi ned int_type;
typedef i mpl ementati on-defi ned uint_type;
typedef i mpl ementati on-defi ned int64;
typedef i mpl ementati on-defi ned uint64;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


203
Copyright 2012 IEEE. All rights reserved.
} // namespace sc_dt
int_type is an implementati on-dependent nati ve C++ integer type. An impl ementation shall provide a
mi nimum representati on size of 64 bits.
uint_type is an i mpl ementation-dependent nati ve C++ unsigned integer type. An impl ementation shal l
provide a minimum representati on size of 64 bi ts.
int64 is a nati ve C++ i nteger type havi ng a word l ength of exactl y 64 bits.
uint64 is a nati ve C++ unsi gned integer type havi ng a word length of exactl y 64 bits.
7.5.2 sc_int_base
7.5.2.1 Description
Cl ass sc_int_base represents a l imi ted word-length i nteger. The word length i s speci fi ed by a constructor
argument or, by default, by the sc_length_context object currentl y i n scope. The word length of an
sc_int_base obj ect shall be f ixed duri ng i nstantiati on and shal l not subsequentl y be changed.
The integer value shal l be hel d in an impl ementation-dependent native C++ integer type. A mini mum
representation si ze of 64 bits is required.
sc_int_base is the base cl ass f or the sc_int class template.
7.5.2.2 Class definition
namespace sc_dt {
class sc_int_base
: publi c sc_val ue_base

{
f ri end cl ass sc_ui nt_bi tr ef_r

;
f ri end cl ass sc_ui nt_bi tr ef

;
f ri end cl ass sc_ui nt_subref_r

;
f ri end cl ass sc_ui nt_subref

;
publ ic:
// Constructors
expl icit sc_int_base( i nt w = sc_l ength_param().len() );
sc_int_base( i nt_type v , i nt w );
sc_int_base( const sc_int_base& a );
templ ate< typename T >
expl icit sc_int_base( const sc_generi c_base<T>& a );
expl icit sc_int_base( const sc_i nt_subref_r

& a );
expl icit sc_int_base( const sc_si gned& a );
expl icit sc_int_base( const sc_unsi gned& a );
expl icit sc_int_base( const sc_bv_base& v );
expl icit sc_int_base( const sc_lv_base& v );
expl icit sc_int_base( const sc_ui nt_subref_r

& v );
expl icit sc_int_base( const sc_si gned_subr ef_r

& v );
expl icit sc_int_base( const sc_unsi gned_subref_r

& v );
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


204
Copyright 2012 IEEE. All rights reserved.
// Destructor
~sc_int_base();
// Assi gnment operators
sc_i nt_base& oper ator = ( i nt_type v );
sc_i nt_base& oper ator = ( const sc_int_base& a );
sc_i nt_base& oper ator = ( const sc_i nt_subref_r

& a );
templ ate<cl ass T>
sc_i nt_base& oper ator = ( const sc_generi c_base<T>& a );
sc_i nt_base& oper ator = ( const sc_si gned& a );
sc_i nt_base& oper ator = ( const sc_unsigned& a );
sc_i nt_base& oper ator = ( const sc_fxval& a );
sc_i nt_base& oper ator = ( const sc_fxval_fast& a );
sc_i nt_base& oper ator = ( const sc_fxnum& a );
sc_i nt_base& oper ator = ( const sc_fxnum_fast& a );
sc_i nt_base& oper ator = ( const sc_bv_base& a );
sc_i nt_base& oper ator = ( const sc_lv_base& a );
sc_i nt_base& oper ator = ( const char* a );
sc_i nt_base& oper ator = ( unsigned long a );
sc_i nt_base& oper ator = ( l ong a );
sc_i nt_base& oper ator = ( unsigned int a );
sc_i nt_base& oper ator = ( i nt a );
sc_i nt_base& oper ator = ( ui nt64 a );
sc_i nt_base& oper ator = ( double a );
// Prefi x and postf ix increment and decrement operators
sc_i nt_base& oper ator ++ (); // Prefi x
const sc_i nt_base oper ator ++ ( i nt ); // Postf ix
sc_i nt_base& oper ator-- (); // Prefi x
const sc_i nt_base oper ator-- ( i nt ); // Postf ix
// Bit selecti on
sc_i nt_bi tr ef

oper ator [] ( i nt i );
sc_i nt_bi tr ef_r

oper ator [] ( i nt i ) const;


// Part selection
sc_i nt_subref

oper ator () ( i nt left , int right );


sc_i nt_subref_r

oper ator () ( i nt left , int right ) const;


sc_i nt_subref

r ange( i nt l ef t , int right );


sc_i nt_subref_r

r ange( i nt lef t , int right ) const;


// Capacity
int length() const;
// Reduce methods
bool and_r educe() const;
bool nand_r educe() const;
bool or_r educe() const;
bool nor_reduce() const;
bool xor_reduce() const;
bool xnor _reduce() const;
// Impl icit conversi on to int_type
oper ator int_type() const;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


205
Copyright 2012 IEEE. All rights reserved.
// Expl icit conversions
int to_int() const;
unsi gned int to_uint() const;
long to_long() const;
unsi gned long to_ulong() const;
int64 to_int64() const;
uint64 to_uint64() const;
doubl e to_double() const;
// Expl icit conversion to character stri ng
const std::string to_str ing( sc_numrep numrep = SC_DEC ) const;
const std::string to_str ing( sc_numrep numrep , bool w_pref ix ) const;
// Other methods
void pr int( std::ostream& os = std::cout ) const;
void scan( std::i stream& i s = std::ci n );
} ;
} // namespace sc_dt
7.5.2.3 Constraints on usage
The word length of an sc_int_base object shall not be greater than the maxi mum size of the integer
representation used to hol d i ts val ue.
7.5.2.4 Constructors
expl icit sc_int_base( i nt w = sc_length_param().len() );
Constructor sc_int_base shall create an object of word l ength speci fi ed by w. I t is the def aul t
constructor when w i s not specif ied (in whi ch case i ts value shal l be set by the current l ength
context). The i niti al val ue of the obj ect shal l be 0.
sc_int_base( i nt_type v , i nt w );
Constructor sc_int_base shal l create an obj ect of word l ength specif i ed by w wi th ini ti al val ue
specif ied by v. Truncation of most signi fi cant bits shall occur i f the val ue cannot be represented i n
the specif ied word l ength.
templ ate< cl ass T >
sc_int_base( const sc_generi c_base<T>& a );
Constructor sc_int_base shal l create an sc_int_base object wi th a word length matching the
constructor argument. The constructor shal l set the i ni ti al val ue of the object to the val ue returned
f rom the member functi on to_int64 of the constructor argument.
The other constructors shal l create an sc_int_base object whose si ze and value matches that of the
argument. The size of the argument shall not be greater than the maximum word l ength of an sc_int_base
object.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


206
Copyright 2012 IEEE. All rights reserved.
7.5.2.5 Assignment operators
Overl oaded assi gnment operators shall provide conversion f rom SystemC data types and the nati ve C++
integer representati on to sc_int_base, usi ng truncation or si gn-extension as descri bed in 7.2.1.
7.5.2.6 Implicit type conversion
oper ator int_type() const;
Operator int_type can be used f or impl icit type conversi on from sc_int_base to the native C++
integer representati on.
NOTE 1This operator enables the use of standard C++ bi twi se l ogi cal and ari thmeti c operators wi th
sc_int_base obj ects.
NOTE 2This operator is used by the C++ output stream operator and by the member f uncti ons of other data
type cl asses that are not expl i ci tl y overl oad f or sc_int_base.
7.5.2.7 Explicit type conversion
const std::string to_str ing( sc_numrep numrep = SC_DEC ) const;
const std::string to_str ing( sc_numrep numrep, bool w_pref ix ) const;
Member function to_str ing shal l perf orm the conversion to an std::str ing, as described in 7.2.11.
Call ing the to_str ing f uncti on with a single argument is equi valent to call ing the to_str ing f uncti on
wi th two arguments where the second argument is true. Cal li ng the to_str ing functi on with no
arguments is equival ent to cal li ng the to_str ing f unction with two arguments, where the fi rst
argument is SC_DEC and the second argument is true.
7.5.2.8 Arithmetic, bitwise, and comparison operators
Operati ons specif ied i n Table 6 are permitted. The foll owing appl ies:
n represents an obj ect of type sc_int_base.
i represents an obj ect of integer type int_type.
The arguments of the comparison operators may al so be of any other class that i s deri ved from sc_int_base.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


207
Copyright 2012 IEEE. All rights reserved.
Arithmetic and bitwise operati ons permi tted for C++ integer types shal l be permitted for sc_int_base objects
usi ng i mplici t type conversions. The return type of these operations is an impl ementation-dependent C++
integer type.
NOTEAn implementation is required to suppl y overl oaded operators on sc_int_base objects to sati sf y the
requi rements of thi s subclause. I t i s unspeci f i ed whether these operators are members of sc_int_base, gl obal operators,
or provi ded i n some other way.
7.5.2.9 Other member functions
void scan( std::i stream& i s = std::ci n );
Member functi on scan shall set the value by reading the next formatted character stri ng from the
specif ied input stream (see 7.2.10).
void pr int( std::ostream& os = std::cout ) const;
Member f uncti on pr int shal l write the val ue as a f ormatted character string to the specif ied output
stream (see 7.2.10).
Table 6sc_int_base arithmetic, bitwise, and comparison operations
Expr ession Retur n type Oper ation
n += i sc_i nt_base& sc_i nt_base assi gn sum
n -= i sc_i nt_base& sc_i nt_base assi gn di ff erence
n * = i sc_i nt_base& sc_i nt_base assign product
n /= i sc_i nt_base& sc_i nt_base assi gn quoti ent
n %= i sc_i nt_base& sc_i nt_base assi gn remai nder
n & = i sc_i nt_base& sc_i nt_base assi gn bi twi se and
n |= i sc_i nt_base& sc_i nt_base assi gn bi twi se or
n ^= i sc_i nt_base& sc_i nt_base assi gn bitwi se excl usi ve or
n<<= i sc_i nt_base& sc_i nt_base assi gn l eft-shi f t
n >>= i sc_i nt_base& sc_i nt_base assi gn ri ght-shi ft
n == n bool test equal
n ! = n bool test not equal
n < n bool test l ess than
n <= n bool test l ess than or equal
n > n bool test greater than
n >= n bool test greater than or equal
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


208
Copyright 2012 IEEE. All rights reserved.
int length() const;
Member f uncti on length shall return the word length (see 7.2.4).
7.5.3 sc_uint_base
7.5.3.1 Description
Cl ass sc_uint_baserepresents a l imited word-l ength unsi gned i nteger. The word l ength shall be speci fied by
a constructor argument or, by default, by the sc_length_context object currentl y in scope. The word length
of an sc_uint_base obj ect shall be f ixed duri ng i nstantiati on and shal l not subsequentl y be changed.
The i nteger val ue shal l be hel d i n an impl ementation-dependent nati ve C++ unsi gned integer type. A
mi nimum representation size of 64 bits i s required.
sc_uint_base is the base class f or the sc_uint class template.
7.5.3.2 Class definition
namespace sc_dt {
class sc_uint_base
: publi c sc_val ue_base

{
f ri end cl ass sc_ui nt_bi tr ef_r

;
f ri end cl ass sc_ui nt_bi tr ef

;
f ri end cl ass sc_ui nt_subref_r

;
f ri end cl ass sc_ui nt_subref

;
publ ic:
// Constructors
expl icit sc_uint_base( i nt w = sc_l ength_param().len() );
sc_uint_base( ui nt_type v , int w );
sc_uint_base( const sc_uint_base& a );
expl icit sc_uint_base( const sc_ui nt_subref_r

& a );
templ ate <class T>
expl icit sc_uint_base( const sc_generi c_base<T>& a );
expl icit sc_uint_base( const sc_bv_base& v );
expl icit sc_uint_base( const sc_lv_base& v );
expl icit sc_uint_base( const sc_i nt_subref_r

& v );
expl icit sc_uint_base( const sc_si gned_subr ef_r

& v );
expl icit sc_uint_base( const sc_unsi gned_subref_r

& v );
expl icit sc_uint_base( const sc_si gned& a );
expl icit sc_uint_base( const sc_unsigned& a );
// Destructor
~sc_uint_base();
// Assi gnment operators
sc_uint_base& oper ator = ( ui nt_type v );
sc_uint_base& oper ator = ( const sc_uint_base& a );
sc_uint_base& oper ator = ( const sc_ui nt_subref_r

& a );
templ ate <class T>
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


209
Copyright 2012 IEEE. All rights reserved.
sc_uint_base& oper ator = ( const sc_generi c_base<T>& a );
sc_uint_base& oper ator = ( const sc_si gned& a );
sc_uint_base& oper ator = ( const sc_unsigned& a );
sc_uint_base& oper ator = ( const sc_fxval& a );
sc_uint_base& oper ator = ( const sc_fxval _fast& a );
sc_uint_base& oper ator = ( const sc_fxnum& a );
sc_uint_base& oper ator = ( const sc_fxnum_fast& a );
sc_uint_base& oper ator = ( const sc_bv_base& a );
sc_uint_base& oper ator = ( const sc_lv_base& a );
sc_uint_base& oper ator = ( const char* a );
sc_uint_base& oper ator = ( unsigned long a );
sc_uint_base& oper ator = ( l ong a );
sc_uint_base& oper ator = ( unsigned int a );
sc_uint_base& oper ator = ( i nt a );
sc_uint_base& oper ator = ( i nt64 a );
sc_uint_base& oper ator = ( double a );
// Prefi x and postf ix increment and decrement operators
sc_uint_base& oper ator ++ (); // Prefi x
const sc_ui nt_base oper ator ++ ( i nt ); // Postfi x
sc_uint_base& oper ator-- (); // Prefi x
const sc_ui nt_base oper ator-- ( i nt ); // Postfi x
// Bit selecti on
sc_ui nt_bi tr ef

oper ator [] ( i nt i );
sc_ui nt_bi tr ef_r

oper ator [] ( i nt i ) const;


// Part selection
sc_ui nt_subref

oper ator () ( i nt l ef t, int right );


sc_ui nt_subref_r

oper ator () ( i nt lef t, int right ) const;


sc_ui nt_subref

r ange( i nt lef t, int ri ght );


sc_ui nt_subref_r

r ange( i nt lef t, int ri ght ) const;


// Capacity
int length() const;
// Reduce methods
bool and_r educe() const;
bool nand_r educe() const;
bool or_r educe() const;
bool nor_reduce() const;
bool xor_reduce() const;
bool xnor _reduce() const;
// Impl icit conversi on to ui nt_type
operator uint_type() const;
// Expl icit conversions
int to_int() const;
unsi gned int to_uint() const;
long to_long() const;
unsi gned long to_ulong() const;
int64 to_int64() const;
uint64 to_uint64() const;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


210
Copyright 2012 IEEE. All rights reserved.
doubl e to_double() const;
// Expli ci t conversi on to character string
const std::string to_str ing( sc_numrep numrep = SC_DEC ) const;
const std::string to_str ing( sc_numrep numrep , bool w_pref ix ) const;
// Other methods
void pr int( std::ostream& os = std::cout ) const;
void scan( std::i stream& i s = std::ci n );
} ;
} // namespace sc_dt
7.5.3.3 Constraints on usage
The word l ength of an sc_uint_base object shall not be greater than the maxi mum size of the unsi gned
integer representati on used to hold its value.
7.5.3.4 Constructors
expl icit sc_uint_base( i nt w = sc_l ength_param().len() );
Constructor sc_uint_base shal l create an object of word l ength speci fi ed by w. This i s the def aul t
constructor when w is not specif ied (i n which case its val ue is set by the current length context). The
ini ti al val ue of the obj ect shal l be 0.
sc_uint_base( ui nt_type v , int w );
Constructor sc_uint_base shal l create an object of word length specif ied by w wi th i niti al value
specif ied by v. Truncation of most signi fi cant bits shall occur i f the val ue cannot be represented i n
the specif ied word l ength.
templ ate< cl ass T >
sc_uint_base( const sc_generi c_base<T>& a );
Constructor sc_uint_base shal l create an sc_uint_base object wi th a word length matching the
constructor argument. The constructor shal l set the i ni ti al val ue of the object to the val ue returned
f rom the member functi on to_uint64 of the constructor argument.
The other constructors shal l create an sc_uint_base object whose si ze and value matches that of the
argument. The size of the argument shall not be greater than the maximum word l ength of an sc_uint_base
object.
7.5.3.5 Assignment operators
Overl oaded assi gnment operators shall provide conversion f rom SystemC data types and the nati ve C++
integer representati on to sc_uint_base, usi ng truncation or si gn-extensi on as descri bed i n 7.2.1.
7.5.3.6 Implicit type conversion
operator uint_type() const;
Operator uint_type can be used f or impl ici t type conversion from sc_uint_base to the native C++
unsi gned integer representation.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


211
Copyright 2012 IEEE. All rights reserved.
NOTE 1This operator enables the use of standard C++ bi twi se l ogi cal and ari thmeti c operators wi th
sc_uint_base obj ects.
NOTE 2This operator is used by the C++ output stream operator and by the member f uncti ons of other data
type cl asses that are not expl i ci tl y overl oad f or sc_uint_base.
7.5.3.7 Explicit type conversion
const std::string to_str ing( sc_numrep numrep = SC_DEC ) const;
const std::string to_str ing( sc_numrep numrep , bool w_pref ix ) const;
Member function to_str ing shal l perf orm the conversion to an std::str ing, as described in 7.2.11.
Call ing the to_str ing f uncti on with a single argument is equi valent to call ing the to_str ing f uncti on
wi th two arguments, where the second argument is true. Call ing the to_str ing f unction wi th no
arguments is equival ent to cal li ng the to_str ing f unction with two arguments, where the fi rst
argument is SC_DEC and the second argument is true.
7.5.3.8 Arithmetic, bitwise, and comparison operators
Operati ons specif ied i n Table 7 are permitted. The foll owing appl ies:
U represents an obj ect of type sc_uint_base.
u represents an obj ect of integer type uint_type.
The arguments of the compari son operators may also be of any other class that is deri ved from
sc_uint_base.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


212
Copyright 2012 IEEE. All rights reserved.
Arithmetic and bi twi se operati ons permi tted f or C++ i nteger types shal l be permi tted f or sc_uint_base
objects using impl ici t type conversions. The return type of these operations i s an impl ementation-dependent
C++ integer type.
NOTEAn implementation is required to suppl y overl oaded operators on sc_uint_base obj ects to sati sf y the
requi rements of thi s subcl ause. I t i s unspeci f i ed whether these operators are members of sc_uint_base, global operators,
or provi ded i n some other way.
7.5.3.9 Other member functions
void scan( std::i stream& i s = std::ci n );
Member functi on scan shall set the value by reading the next formatted character stri ng from the
specif ied input stream (see 7.2.10).
void pr int( std::ostream& os = std::cout ) const;
Member f uncti on pr int shal l write the val ue as a f ormatted character string to the specif ied output
stream (see 7.2.10).
Table 7sc_uint_base arithmetic, bitwise, and comparison operations
Expr ession Retur n type Oper ation
U += u sc_ui nt_base& sc_ui nt_base assi gn sum
U -= u sc_ui nt_base& sc_ui nt_base assi gn di f f erence
U * = u sc_ui nt_base& sc_ui nt_base assi gn product
U /= u sc_ui nt_base& sc_ui nt_base assi gn quoti ent
U %= u sc_ui nt_base& sc_ui nt_base assi gn remai nder
U & = u sc_ui nt_base& sc_ui nt_base assi gn bi twi se and
U |= u sc_ui nt_base& sc_ui nt_base assi gn bi twi se or
U ^= u sc_ui nt_base& sc_ui nt_base assi gn bitwi se exclusi ve or
U <<= u sc_ui nt_base& sc_ui nt_base assi gn l ef t-shi f t
U >>= u sc_ui nt_base& sc_ui nt_base assi gn right-shi f t
U == U bool test equal
U ! = U bool test not equal
U < U bool test l ess than
U <= U bool test l ess than or equal
U > U bool test greater than
U >= U bool test greater than or equal
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


213
Copyright 2012 IEEE. All rights reserved.
int length() const;
Member f uncti on length shall return the word length (see 7.2.4).
7.5.4 sc_int
7.5.4.1 Description
Class templ ate sc_int represents a limited word-length signed i nteger. The word length shall be specif ied by
a template argument.
Any publi c member functi ons of the base cl ass sc_int_base that are overridden in class sc_int shall have the
same behavior in the two cl asses. Any publ ic member f uncti ons of the base class not overridden i n this way
shall be publi cl y i nherited by cl ass sc_int.
7.5.4.2 Class definition
namespace sc_dt {
templ ate <i nt W>
class sc_int
: publi c sc_i nt_base
{
publ ic:
// Constructors
sc_int();
sc_int( i nt_type v );
sc_int( const sc_int<W>& a );
sc_int( const sc_int_base& a );
sc_int( const sc_i nt_subref_r

& a );
templ ate <class T>
sc_int( const sc_generi c_base<T>& a );
sc_int( const sc_si gned& a );
sc_int( const sc_unsigned& a );
expl icit sc_int( const sc_fxval& a );
expl icit sc_int( const sc_fxval_fast& a );
expl icit sc_int( const sc_fxnum& a );
expl icit sc_int( const sc_fxnum_fast& a );
sc_int( const sc_bv_base& a );
sc_int( const sc_lv_base& a );
sc_int( const char* a );
sc_int( unsigned long a );
sc_int( l ong a );
sc_int( unsigned i nt a );
sc_int( i nt a );
sc_int( ui nt64 a );
sc_int( double a );
// Assi gnment operators
sc_i nt<W>& oper ator = ( i nt_type v );
sc_i nt<W>& oper ator = ( const sc_int_base& a );
sc_int<W>& oper ator = ( const sc_i nt_subref_r

& a );
sc_i nt<W>& oper ator = ( const sc_int<W>& a );
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


214
Copyright 2012 IEEE. All rights reserved.
templ ate <class T>
sc_i nt<W>& oper ator = ( const sc_generi c_base<T>& a );
sc_i nt<W>& oper ator = ( const sc_si gned& a );
sc_i nt<W>& oper ator = ( const sc_unsigned& a );
sc_i nt<W>& oper ator = ( const sc_fxval& a );
sc_i nt<W>& oper ator = ( const sc_fxval _fast& a );
sc_i nt<W>& oper ator = ( const sc_fxnum& a );
sc_i nt<W>& oper ator = ( const sc_fxnum_fast& a );
sc_i nt<W>& oper ator = ( const sc_bv_base& a );
sc_i nt<W>& oper ator = ( const sc_lv_base& a );
sc_i nt<W>& oper ator = ( const char* a );
sc_i nt<W>& oper ator = ( unsigned long a );
sc_i nt<W>& oper ator = ( l ong a );
sc_i nt<W>& oper ator = ( unsigned int a );
sc_i nt<W>& oper ator = ( i nt a );
sc_i nt<W>& oper ator = ( ui nt64 a );
sc_i nt<W>& oper ator = ( double a );
// Prefi x and postf ix increment and decrement operators
sc_i nt<W>& oper ator ++ (); // Prefi x
const sc_i nt<W> oper ator ++ ( i nt ); // Postf ix
sc_i nt<W>& oper ator-- (); // Prefi x
const sc_i nt<W> oper ator-- ( i nt ); // Postf ix
} ;
} // namespace sc_dt
7.5.4.3 Constraints on usage
The word l ength of an sc_int object shall not be greater than the maxi mum word l ength of an sc_int_base.
7.5.4.4 Constructors
sc_int();
Default constructor sc_int shal l create an sc_int object of word length specif ied by the templ ate
argument W. The i ni ti al val ue of the object shal l be 0.
templ ate< cl ass T >
sc_int( const sc_generi c_base<T>& a );
Constructor sc_int shall create an sc_int obj ect of word l ength speci f ied by the template argument.
The constructor shal l set the ini ti al value of the object to the val ue returned f rom the member
f uncti on to_int64 of the constructor argument.
The other constructors shall create an sc_int object of word length specif ied by the template argument W
and value corresponding to the i nteger magni tude of the constructor argument. If the word length of the
specif ied i nitial value di ffers from the template argument, truncati on or si gn-extension shall be used as
descri bed in 7.2.1.
7.5.4.5 Assignment operators
Overl oaded assi gnment operators shall provide conversion f rom SystemC data types and the nati ve C++
integer representati on to sc_int, usi ng truncation or si gn-extension as descri bed in 7.2.1.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


215
Copyright 2012 IEEE. All rights reserved.
7.5.4.6 Arithmetic and bitwise operators
Operati ons specif ied i n Table 8 are permitted. The foll owing appl ies:
n represents an obj ect of type sc_int.
i represents an obj ect of integer type int_type.
Arithmetic and bitwise operations permi tted for C++ i nteger types shall be permi tted for sc_int obj ects using
implici t type conversions. The return type of these operations is an impl ementation-dependent C++ i nteger
type.
NOTEAn implementation is required to suppl y overl oaded operators on sc_int objects to sati sf y the requi rements of
thi s subcl ause. It i s unspeci f i ed whether these operators are members of sc_int, gl obal operators, or provi ded i n some
other way.
7.5.5 sc_uint
7.5.5.1 Description
Class template sc_uint represents a limited word-l ength unsi gned i nteger. The word l ength shall be
specif ied by a template argument. Any publi c member f unctions of the base cl ass sc_uint_base that are
overri dden i n class sc_uint shall have the same behavior i n the two classes. Any publi c member functions of
the base cl ass not overridden i n this way shal l be publi cl y inherited by cl ass sc_uint.
7.5.5.2 Class definition
namespace sc_dt {
templ ate <i nt W>
class sc_uint
Table 8sc_int arithmetic and bitwise operations
Expr ession Retur n type Oper ation
n += i sc_int<W>& sc_int assi gn sum
n -= i sc_i nt<W>& sc_i nt assi gn di ff erence
n * = i sc_i nt<W>& sc_i nt assi gn product
n /= i sc_i nt<W>& sc_i nt assi gn quoti ent
n %= i sc_i nt<W>& sc_i nt assi gn remai nder
n & = i sc_int<W>& sc_int assi gn bi twi se and
n |= i sc_i nt<W>& sc_i nt assi gn bi twi se or
n ^= i sc_i nt<W>& sc_i nt assi gn bi twi se excl usi ve or
n <<= i sc_i nt<W>& sc_i nt assi gn l ef t-shi f t
n >>= i sc_i nt<W>& sc_i nt assi gn ri ght-shi f t
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


216
Copyright 2012 IEEE. All rights reserved.
: publi c sc_ui nt_base
{
publ ic:
// Constructors
sc_uint();
sc_uint( ui nt_type v );
sc_uint( const sc_ui nt<W>& a );
sc_uint( const sc_uint_base& a );
sc_uint( const sc_ui nt_subref_r

& a );
templ ate <class T>
sc_uint( const sc_generi c_base<T>& a );
sc_uint( const sc_si gned& a );
sc_uint( const sc_unsigned& a );
expl icit sc_uint( const sc_fxval& a );
expl icit sc_uint( const sc_fxval _fast& a );
expl icit sc_uint( const sc_fxnum& a );
expl icit sc_uint( const sc_fxnum_fast& a );
sc_uint( const sc_bv_base& a );
sc_uint( const sc_lv_base& a );
sc_uint( const char* a );
sc_uint( unsigned l ong a );
sc_uint( l ong a );
sc_uint( unsigned i nt a );
sc_uint( i nt a );
sc_uint( i nt64 a );
sc_uint( double a );
// Assi gnment operators
sc_uint<W>& oper ator = ( ui nt_type v );
sc_uint<W>& oper ator = ( const sc_uint_base& a );
sc_uint<W>& oper ator = ( const sc_ui nt_subref_r

& a );
sc_uint<W>& oper ator = ( const sc_ui nt<W>& a );
templ ate <class T>
sc_uint<W>& oper ator = ( const sc_generi c_base<T>& a );
sc_uint<W>& oper ator = ( const sc_si gned& a );
sc_uint<W>& oper ator = ( const sc_unsigned& a );
sc_uint<W>& oper ator = ( const sc_fxval & a );
sc_uint<W>& oper ator = ( const sc_fxval_fast& a );
sc_uint<W>& oper ator = ( const sc_fxnum& a );
sc_uint<W>& oper ator = ( const sc_fxnum_fast& a );
sc_uint<W>& oper ator = ( const sc_bv_base& a );
sc_uint<W>& oper ator = ( const sc_lv_base& a );
sc_uint<W>& oper ator = ( const char* a );
sc_uint<W>& oper ator = ( unsigned l ong a );
sc_uint<W>& oper ator = ( l ong a );
sc_uint<W>& oper ator = ( unsigned i nt a );
sc_uint<W>& oper ator = ( i nt a );
sc_uint<W>& oper ator = ( i nt64 a );
sc_uint<W>& oper ator = ( doubl e a );
// Prefi x and postf ix increment and decrement operators
sc_uint<W>& oper ator ++ (); // Prefi x
const sc_ui nt<W> oper ator ++ ( i nt ); // Postfi x
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


217
Copyright 2012 IEEE. All rights reserved.
sc_uint<W>& oper ator-- (); // Pref ix
const sc_uint<W> oper ator-- ( i nt ); // Postfi x
} ;
} // namespace sc_dt
7.5.5.3 Constraints on usage
The word length of an sc_uint object shal l not be greater than the maximum word length of an
sc_uint_base.
7.5.5.4 Constructors
sc_uint();
Default constructor sc_uint shall create an sc_uint obj ect of word l ength specif ied by the template
argument W. The i ni ti al val ue of the object shal l be 0.
templ ate< cl ass T >
sc_uint( const sc_generi c_base<T>& a );
Constructor sc_uint shal l create an sc_uint object of word length specif ied by the template
argument. The constructor shall set the initial val ue of the object to the val ue returned from the
member f uncti on to_uint64 of the constructor argument.
The other constructors shall create an sc_uint obj ect of word length speci fi ed by the templ ate argument W
and value corresponding to the integer magnitude of the constructor argument. If the word length of the
specif ied i nitial value di ffers from the template argument, truncati on or si gn-extension shall be used as
descri bed in 7.2.1.
7.5.5.5 Assignment operators
Overl oaded assi gnment operators shall provide conversion f rom SystemC data types and the nati ve C++
integer representation to sc_uint. I f the si ze of a data type or string l iteral operand dif fers from the sc_uint
word l ength, truncati on or si gn-extension shall be used as descri bed in 7.2.1.
7.5.5.6 Arithmetic and bitwise operators
Operati ons specif ied i n Table 9 are permitted. The foll owing appl ies:
U represents an obj ect of type sc_uint.
u represents an obj ect of integer type uint_type.
Arithmetic and bitwise operations permi tted f or C++ integer types shal l be permitted for sc_uint objects
usi ng i mplici t type conversions. The return type of these operations is an impl ementation-dependent C++
integer.
NOTEAn implementation is required to suppl y overl oaded operators on sc_uint obj ects to sati sf y the requi rements of
thi s subcl ause. I t i s unspeci fi ed whether these operators are members of sc_uint, gl obal operators, or provi ded i n some
other way.
7.5.6 Bit-selects
7.5.6.1 Description
Class sc_i nt_bi tr ef_r

represents a bit selected from an sc_int_base used as an rval ue.


IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


218
Copyright 2012 IEEE. All rights reserved.
Cl ass sc_i nt_bi tr ef

represents a bit selected f rom an sc_int_base used as an l val ue.


Cl ass sc_ui nt_bi tr ef_r

represents a bi t sel ected f rom an sc_uint_base used as an rval ue.


Cl ass sc_ui nt_bi tr ef

represents a bit selected f rom an sc_uint_base used as an l val ue.


7.5.6.2 Class definition
namespace sc_dt {
class sc_i nt_bi tr ef_r

: publi c sc_val ue_base

{
f riend cl ass sc_int_base;
publ ic:
// Copy constructor
sc_i nt_bi tr ef_r

( const sc_i nt_bi tref_r

& a );
// Destructor
virtual ~sc_i nt_bi tr ef_r

();
// Capacity
int length() const;
// Impl icit conversi on to ui nt64
oper ator uint64 () const;
bool oper ator ! () const;
bool oper ator ~ () const;
Table 9sc_uint arithmetic and bitwise operations
Expr ession Retur n type Oper ation
U += u sc_ui nt<W>& sc_ui nt assi gn sum
U -= u sc_ui nt<W>& sc_ui nt assi gn di f f erence
U * = u sc_ui nt<W>& sc_ui nt assi gn product
U /= u sc_ui nt<W>& sc_ui nt assi gn quoti ent
U %= u sc_ui nt<W>& sc_ui nt assi gn remai nder
U & = u sc_ui nt<W>& sc_ui nt assi gn bitwi se and
U |= u sc_ui nt<W>& sc_ui nt assi gn bi twi se or
U ^= u sc_ui nt<W>& sc_ui nt assi gn bitwi se excl usi ve or
U <<= u sc_ui nt<W>& sc_ui nt assi gn lef t-shi ft
U >>= u sc_ui nt<W>& sc_ui nt assi gn ri ght-shi f t
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


219
Copyright 2012 IEEE. All rights reserved.
// Expl icit conversions
bool to_bool() const;
// Other methods
void pr int( std::ostream& os = std::cout ) const;
protected:
sc_i nt_bi tr ef_r

();
pri vate:
// Di sabl ed
sc_i nt_bi tr ef_r

& oper ator = ( const sc_i nt_bi tr ef_r

& );
} ;
// -------------------------------------------------------------
class sc_i nt_bi tr ef

: publi c sc_i nt_bi tr ef_r

{
f riend cl ass sc_int_base;
publ ic:
// Copy constructor
sc_i nt_bi tr ef

( const sc_i nt_bi tr ef

& a );
// Assi gnment operators
sc_i nt_bi tr ef

& oper ator = ( const sc_i nt_bi tr ef_r

& b );
sc_i nt_bi tr ef

& oper ator = ( const sc_i nt_bi tr ef

& b );
sc_i nt_bi tr ef

& oper ator = ( bool b );


sc_i nt_bi tr ef

& oper ator & = ( bool b );


sc_i nt_bi tr ef

& oper ator |= ( bool b );


sc_i nt_bi tr ef

& oper ator ^= ( bool b );


// Other methods
void scan( std::i stream& i s = std::ci n );
pri vate:
sc_i nt_bi tr ef

();
} ;
// -------------------------------------------------------------
class sc_ui nt_bi tr ef_r


: publi c sc_val ue_base

{
f riend cl ass sc_ui nt_base;
publ ic:
// Copy constructor
sc_ui nt_bi tr ef_r

( const sc_ui nt_bi tr ef_r

& a );
// Destructor
virtual ~sc_ui nt_bi tr ef_r

();
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


220
Copyright 2012 IEEE. All rights reserved.
// Capacity
int length() const;
// Impl icit conversi on to ui nt64
oper ator uint64 () const;
bool oper ator ! () const;
bool oper ator ~ () const;
// Expl icit conversions
bool to_bool() const;
// Other methods
voi d pr int( std::ostream& os = std::cout ) const;
protected:
sc_ui nt_bi tr ef_r

();
pri vate:
// Di sabl ed
sc_ui nt_bi tr ef_r

& oper ator = ( const sc_ui nt_bi tr ef_r

& );
} ;
// -------------------------------------------------------------
class sc_ui nt_bi tr ef

: publi c sc_ui nt_bi tr ef_r

{
f riend cl ass sc_ui nt_base;
publ ic:
// Copy constructor
sc_ui nt_bi tr ef

( const sc_ui nt_bi tr ef

& a );
// Assi gnment operators
sc_ui nt_bi tr ef

& oper ator = ( const sc_ui nt_bi tr ef_r

& b );
sc_ui nt_bi tr ef

& oper ator = ( const sc_ui nt_bi tr ef

& b );
sc_ui nt_bi tr ef

& oper ator = ( bool b );


sc_ui nt_bi tr ef

& oper ator & = ( bool b );


sc_ui nt_bi tr ef

& operator |= ( bool b );


sc_ui nt_bi tr ef

& oper ator ^= ( bool b );


// Other methods
void scan( std::i stream& i s = std::ci n );
pri vate:
sc_ui nt_bi tr ef

();
} ;
} // namespace sc_dt
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


221
Copyright 2012 IEEE. All rights reserved.
7.5.6.3 Constraints on usage
Bi t-select obj ects shall only be created usi ng the bi t-sel ect operators of an sc_int_base or sc_uint_base
object (or an instance of a cl ass derived f rom sc_int_base or sc_uint_base).
An appl ication shall not expli citl y create an i nstance of any bi t-sel ect class.
An appl ication should not decl are a reference or pointer to any bit-sel ect obj ect.
I t is strongly recommended that an appl ication avoi d the use of a bi t-sel ect as the return type of a f unction
because the l if etime of the obj ect to whi ch the bi t-select ref ers may not extend beyond the f uncti on return
statement.
Exampl e:
sc_dt::sc_i nt_bitref get_bit_n(sc_int_base i, i nt n) {
return i[ n] ; // Unsaf e: returned bit-sel ect references local variable
}
7.5.6.4 Assignment operators
Overl oaded assi gnment operators f or the lvalue bi t-sel ects shall provide conversi on from bool val ues.
Assi gnment operators f or rvalue bi t-sel ects shall be declared as pri vate to prevent their use by an
appl ication.
7.5.6.5 Implicit type conversion
oper ator uint64() const;
Operator uint64 can be used for impl icit type conversi on from a bi t-select to the nati ve C++
unsi gned i nteger having exactly 64 bits. If the sel ected bi t has the value ' 1' (true), the conversi on
shal l return the value 1; otherwi se, it shall return 0.
bool oper ator ! () const;
bool oper ator ~ () const;
oper ator ! and oper ator ~ shall return a C++ bool val ue that is the i nverse of the sel ected bit.
7.5.6.6 Other member functions
void scan( std::i stream& i s = std::ci n );
Member f unction scan shal l set the value of the bit referenced by an lvalue bit-sel ect. The val ue
shal l correspond to the C++ bool val ue obtai ned by reading the next formatted character string from
the specif ied i nput stream (see 7.2.10).
void pr int( std::ostream& os = std::cout ) const;
Member function pr int shal l print the value of the bi t referenced by the bi t-select to the speci fi ed
output stream (see 7.2.10). The formatti ng shal l be i mplementati on-defi ned but shall be equi val ent
to pri nti ng the val ue returned by member functi on to_bool.
int length() const;
Member f uncti on length shall unconditi onal ly return a word l ength of 1 (see 7.2.4).
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


222
Copyright 2012 IEEE. All rights reserved.
7.5.7 Part-selects
7.5.7.1 Description
Class sc_i nt_subref_r

represents a si gned integer part-select from an sc_int_base used as an rval ue.


Cl ass sc_i nt_subref

represents a si gned integer part-sel ect f rom an sc_int_base used as an l val ue.
Class sc_ui nt_subr ef_r

represents an unsigned i nteger part-select f rom an sc_uint_base used as an rval ue.


Cl ass sc_ui nt_subref

represents an unsigned i nteger part-select f rom an sc_uint_base used as an l val ue.


7.5.7.2 Class definition
namespace sc_dt {
class sc_i nt_subref_r

{
f riend cl ass sc_int_base;
f ri end cl ass sc_i nt_subref

;
publ ic:
// Copy constructor
sc_i nt_subref_r

( const sc_i nt_subref_r

& a );
// Destructor
virtual ~sc_i nt_subref_r

();
// Capacity
int length() const;
// Reduce methods
bool and_r educe() const;
bool nand_r educe() const;
bool or_r educe() const;
bool nor_reduce() const;
bool xor_reduce() const;
bool xnor _reduce() const;
// Impl icit conversi on to ui nt_type
oper ator uint_type() const;
// Expl icit conversions
int to_int() const;
unsi gned int to_uint() const;
long to_long() const;
unsi gned long to_ulong() const;
int64 to_int64() const;
uint64 to_uint64() const;
doubl e to_double() const;
// Expl icit conversion to character stri ng
const std::string to_str ing( sc_numrep numrep = SC_DEC ) const;
const std::string to_str ing( sc_numrep numrep , bool w_pref ix ) const;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


223
Copyright 2012 IEEE. All rights reserved.
// Other methods
void pr int( std::ostream& os = std::cout ) const;
protected:
sc_i nt_subref_r

();
pri vate:
// Di sabl ed
sc_i nt_subref_r

& oper ator = ( const sc_i nt_subref_r

& );
} ;
// -------------------------------------------------------------
class sc_i nt_subref

: publi c sc_i nt_subref_r

{
f riend cl ass sc_int_base;
publ ic:
// Copy constructor
sc_i nt_subref

( const sc_i nt_subref

& a );
// Assi gnment operators
sc_i nt_subref

& oper ator = ( i nt_type v );


sc_i nt_subref

& oper ator = ( const sc_int_base& a );


sc_i nt_subref

& oper ator = ( const sc_i nt_subref_r

& a );
sc_i nt_subref

& oper ator = ( const sc_i nt_subref

& a );
templ ate< cl ass T >
sc_i nt_subref

& oper ator = ( const sc_generi c_base<T>& a );


sc_i nt_subref

& oper ator = ( const char* a );


sc_i nt_subref

& oper ator = ( unsigned long a );


sc_i nt_subref

& oper ator = ( l ong a );


sc_i nt_subref

& oper ator = ( unsigned int a );


sc_i nt_subref

& oper ator = ( i nt a );


sc_i nt_subref

& oper ator = ( ui nt64 a );


sc_i nt_subref

& oper ator = ( double a );


sc_i nt_subref

& oper ator = ( const sc_si gned& );


sc_i nt_subref

& oper ator = ( const sc_unsigned& );


sc_i nt_subref

& oper ator = ( const sc_bv_base& );


sc_i nt_subref

& oper ator = ( const sc_lv_base& );


// Other methods
void scan( std::i stream& i s = std::ci n );
protected:
sc_i nt_subref

();
} ;
// -------------------------------------------------------------
class sc_ui nt_subref_r

{
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


224
Copyright 2012 IEEE. All rights reserved.
f riend cl ass sc_ui nt_base;
f ri end cl ass sc_ui nt_subref

;
publ ic:
// Copy constructor
sc_ui nt_subref_r

( const sc_ui nt_subref_r

& a );
// Destructor
virtual ~sc_uint_subref_r ();
// Capacity
int length() const;
// Reduce methods
bool and_r educe() const;
bool nand_r educe() const;
bool or_r educe() const;
bool nor_reduce() const;
bool xor_reduce() const;
bool xnor _reduce() const;
// Impl icit conversi on to ui nt_type
operator uint_type() const;
// Expl icit conversions
int to_int() const;
unsi gned int to_uint() const;
long to_long() const;
unsi gned long to_ulong() const;
int64 to_int64() const;
uint64 to_uint64() const;
doubl e to_double() const;
// Expl icit conversion to character stri ng
const std::string to_str ing( sc_numrep numrep = SC_DEC ) const;
const std::string to_str ing( sc_numrep numrep , bool w_pref ix ) const;
// Other methods
void pr int( std::ostream& os = std::cout ) const;
protected:
sc_ui nt_subref_r

();
pri vate:
// Di sabl ed
sc_uint_subref_r& oper ator = ( const sc_uint_subref_r& );
} ;
// -------------------------------------------------------------
class sc_ui nt_subref

: publi c sc_ui nt_subref_r

{
f riend cl ass sc_ui nt_base;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


225
Copyright 2012 IEEE. All rights reserved.
publ ic:
// Copy constructor
sc_ui nt_subref

( const sc_ui nt_subref

& a );
// Assi gnment operators
sc_ui nt_subref

& oper ator = ( uint_type v );


sc_ui nt_subref

& oper ator = ( const sc_ui nt_base& a );


sc_ui nt_subref

& oper ator = ( const sc_ui nt_subref _r& a );


sc_ui nt_subref

& oper ator = ( const sc_ui nt_subref & a );


templ ate<cl ass T>
sc_ui nt_subref

& oper ator = ( const sc_generic_base<T>& a );


sc_ui nt_subref

& oper ator = ( const char* a );


sc_ui nt_subref

& oper ator = ( unsi gned long a );


sc_ui nt_subref

& oper ator = ( l ong a );


sc_ui nt_subref

& oper ator = ( unsi gned int a );


sc_ui nt_subref

& oper ator = ( i nt a );


sc_ui nt_subref

& oper ator = ( i nt64 a );


sc_ui nt_subref

& oper ator = ( doubl e a );


sc_ui nt_subref

& oper ator = ( const sc_si gned& );


sc_ui nt_subref

& oper ator = ( const sc_unsigned& );


sc_ui nt_subref

& oper ator = ( const sc_bv_base& );


sc_ui nt_subref

& oper ator = ( const sc_lv_base& );


// Other methods
void scan( std::i stream& i s = std::ci n );
protected:
sc_ui nt_subref

();
} ;
} // namespace sc_dt
7.5.7.3 Constraints on usage
I nteger part-select objects shall only be created using the part-sel ect operators of an sc_int_base or
sc_uint_base object (or an i nstance of a cl ass deri ved f rom sc_int_base or sc_uint_base), as descri bed in
7.2.6.
An appl ication shall not expli citl y create an instance of any integer part-sel ect cl ass.
An appl ication should not declare a reference or pointer to any i nteger part-select object.
I t shal l be an error if the l ef t-hand i ndex of a li mited-preci si on integer part-select i s less than the ri ght-hand
index.
I t i s strongly recommended that an appli cation avoi d the use of a part-select as the return type of a functi on
because the li feti me of the obj ect to which the part-select refers may not extend beyond the functi on return
statement.
Exampl e:
sc_dt::sc_i nt_subref get_byte(sc_int_base i b, i nt pos) {
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


226
Copyright 2012 IEEE. All rights reserved.
return ib(pos+7,pos); // Unsafe: returned part-select ref erences l ocal vari abl e
}
7.5.7.4 Assignment operators
Overl oaded assi gnment operators shall provide conversion f rom SystemC data types and the nati ve C++
integer representation to lval ue integer part-sel ects. I f the size of a data type or stri ng li teral operand dif fers
f rom the i nteger part-sel ect word l ength, truncati on, zero-extensi on, or si gn-extension shall be used as
descri bed in 7.2.1.
Assi gnment operators for rvalue integer part-selects shal l be decl ared as pri vate to prevent their use by an
appl ication.
7.5.7.5 Implicit type conversion
sc_i nt_subref_r

::oper ator uint_type() const;


sc_ui nt_subref_r

::oper ator uint_type() const;


oper ator int_type and oper ator uint_type can be used f or impl icit type conversi on from i nteger
part-sel ects to the nati ve C++ unsi gned integer representation.
NOTE 1These operators enable the use of standard C++ bi twi se l ogi cal and ari thmeti c operators wi th i nteger
part-sel ect obj ects.
NOTE 2These operators are used by the C++ output stream operator and by member functi ons of other data
type cl asses that are not expl i ci tly overl oad f or i nteger part-sel ects.
7.5.7.6 Explicit type conversion
const std::string to_str ing( sc_numrep numrep = SC_DEC ) const;
const std::string to_str ing( sc_numrep numrep , bool w_pref ix ) const;
Member function to_str ing shal l perf orm the conversion to an std::str ing, as described in 7.2.11.
Call ing the to_str ing f uncti on with a single argument is equi valent to call ing the to_str ing f uncti on
wi th two arguments, where the second argument is true. Call ing the to_str ing f unction wi th no
arguments is equival ent to cal li ng the to_str ing f unction with two arguments, where the fi rst
argument is SC_DEC and the second argument is true.
7.5.7.7 Other member functions
void scan( std::i stream& i s = std::ci n );
Member function scan shal l set the values of the bi ts ref erenced by an lvalue part-select by reading
the next formatted character string from the specif ied i nput stream (see 7.2.10).
void pr int( std::ostream& os = std::cout ) const;
Member functi on pr int shall print the val ues of the bi ts referenced by the part-sel ect to the specif ied
output stream (see 7.2.10).
int length() const;
Member f uncti on length shall return the word length of the part-select (see 7.2.4).
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


227
Copyright 2012 IEEE. All rights reserved.
7.6 Finite-precision integer types
7.6.1 Type definitions
The f ol lowi ng type def i ni ti ons are used i n the f ini te-precision integer type classes:
namespace sc_dt{
typedef i mpl ementati on-defi ned int64;
typedef i mpl ementati on-defi ned uint64;
} // namespace sc_dt
int64 is a nati ve C++ i nteger type havi ng a word l ength of exactl y 64 bits.
uint64 is a nati ve C++ unsi gned integer type havi ng a word length of exactl y 64 bits.
7.6.2 Constraints on usage
Overl oaded ari thmeti c and comparison operators all ow fi ni te-preci si on integer objects to be used in
expressions f ol lowi ng simi lar but not identi cal rules to standard C++ i nteger types. The di ff erences f rom the
standard C++ i nteger operator behavi or are the fol lowing:
a) Where one operand i s unsi gned and the other is si gned, the unsi gned operand shal l be converted to
signed and the return type shall be signed.
b) The return type of a subtraction shall al ways be signed.
c) The word l ength of the return type of an arithmeti c operator shall depend only on the nature of the
operation and on the word length of its operands.
d) A f loating-poi nt variable or l iteral shal l not be di rectl y used as an operand. It should fi rst be
converted to an appropriate si gned or unsi gned integer type.
7.6.3 sc_signed
7.6.3.1 Description
Cl ass sc_signed represents a fini te word-length i nteger. The word l ength shall be speci fi ed by a constructor
argument or, by default, by the length context obj ect currentl y in scope. The word length of an sc_signed
object shall be f ixed duri ng i nstantiati on and shal l not subsequentl y be changed.
The integer value shal l be stored with a fi ni te preci sion determi ned by the speci fi ed word l ength. The
precision shall not depend on the l imited resoluti on of any standard C++ integer type.
sc_signed is the base cl ass for the sc_bigint class templ ate.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


228
Copyright 2012 IEEE. All rights reserved.
7.6.3.2 Class definition
namespace sc_dt {
class sc_signed
: publi c sc_val ue_base

{
f ri end cl ass sc_concatr ef

;
f ri end cl ass sc_si gned_bi tref_r

;
f ri end cl ass sc_si gned_bi tref

;
f ri end cl ass sc_si gned_subr ef_r

;
f ri end cl ass sc_si gned_subr ef

;
f riend cl ass sc_unsigned;
f riend cl ass sc_unsigned_subref;
publ ic:
// Constructors
expl icit sc_signed( i nt nb = sc_length_param().l en() );
sc_signed( const sc_si gned& v );
sc_signed( const sc_unsigned& v );
templ ate<cl ass T>
expl icit sc_signed( const sc_generi c_base<T>& v );
expl icit sc_signed( const sc_bv_base& v );
expl icit sc_signed( const sc_lv_base& v );
expl icit sc_signed( const sc_int_subref_r& v );
expl icit sc_signed( const sc_uint_subref _r& v );
expl icit sc_signed( const sc_si gned_subref _r& v );
expl icit sc_signed( const sc_unsigned_subref_r& v );
// Assi gnment operators
sc_signed& oper ator = ( const sc_si gned& v );
sc_signed& oper ator = ( const sc_si gned_subr ef_r

& a );
templ ate< cl ass T >
sc_signed& oper ator = ( const sc_generi c_base<T>& a );
sc_signed& oper ator = ( const sc_unsigned& v );
sc_signed& oper ator = ( const sc_unsi gned_subref_r

& a );
sc_signed& oper ator = ( const char* v );
sc_signed& oper ator = ( i nt64 v );
sc_signed& oper ator = ( ui nt64 v );
sc_signed& oper ator = ( l ong v );
sc_signed& oper ator = ( unsigned long v );
sc_signed& oper ator = ( i nt v );
sc_signed& oper ator = ( unsigned int v );
sc_signed& oper ator = ( double v );
sc_signed& oper ator = ( const sc_int_base& v );
sc_signed& oper ator = ( const sc_ui nt_base& v );
sc_signed& oper ator = ( const sc_bv_base& );
sc_signed& oper ator = ( const sc_lv_base& );
sc_signed& oper ator = ( const sc_fxval & );
sc_signed& oper ator = ( const sc_fxval _fast& );
sc_signed& oper ator = ( const sc_fxnum& );
sc_signed& oper ator = ( const sc_fxnum_fast& );
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


229
Copyright 2012 IEEE. All rights reserved.
// Destructor
~sc_signed();
// Increment operators.
sc_signed& oper ator ++ ();
const sc_signed oper ator ++ ( i nt );
// Decrement operators.
sc_signed& oper ator-- ();
const sc_signed oper ator-- ( i nt );
// Bit selecti on
sc_si gned_bi tref

oper ator [] ( i nt i );
sc_si gned_bi tref_r

operator [] ( i nt i ) const;
// Part selection
sc_si gned_subr ef

r ange( i nt i , i nt j );
sc_si gned_subr ef_r

r ange( i nt i , i nt j ) const;
sc_si gned_subr ef

oper ator () ( i nt i , int j );


sc_si gned_subr ef_r

oper ator () ( i nt i , int j ) const;


// Expl icit conversions
int to_int() const;
unsi gned int to_uint() const;
long to_long() const;
unsi gned long to_ulong() const;
int64 to_int64() const;
uint64 to_uint64() const;
doubl e to_double() const;
// Expl icit conversion to character stri ng
const std::string to_str ing( sc_numrep numrep = SC_DEC ) const;
const std::string to_str ing( sc_numrep numrep, bool w_pref i x ) const;
// Pri nt functions
void pr int( std::ostream& os = std::cout ) const;
void scan( std::i stream& i s = std::ci n );
// Capacity
int length() const;
// Reduce methods
bool and_r educe() const;
bool nand_r educe() const;
bool or_r educe() const;
bool nor_reduce() const;
bool xor_reduce() const;
bool xnor _reduce() const;
// Overloaded operators
} ;
} // namespace sc_dt
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


230
Copyright 2012 IEEE. All rights reserved.
7.6.3.3 Constraints on usage
An obj ect of type sc_signed shall not be used as a di rect replacement f or a C++ integer type si nce no
implici t type conversi on member f unctions are provi ded. An expl icit type conversion is required to pass the
val ue of an sc_signed object as an argument to a f uncti on expecti ng a C++ integer value argument.
7.6.3.4 Constructors
expl icit sc_signed( i nt nb = sc_length_param().l en() );
Constructor sc_signed shall create an sc_signed obj ect of word l ength specif ied by nb. Thi s i s the
def aul t constructor when nb i s not speci fi ed (in whi ch case i ts val ue i s set by the current length
context). The i niti al val ue of the obj ect shal l be 0.
templ ate< cl ass T >
sc_signed( const sc_generi c_base<T>& a );
Constructor sc_signed shal l create an sc_signed object wi th a word length matching the constructor
argument. The constructor shall set the initial val ue of the object to the val ue returned from the
member f uncti on to_sc_signed of the constructor argument.
The other constructors create an sc_signed obj ect with the same word l ength and val ue as the constructor
argument.
7.6.3.5 Assignment operators
Overl oaded assi gnment operators shall provide conversion f rom SystemC data types and the nati ve C++
integer representati on to sc_signed, usi ng truncation or si gn-extension as descri bed i n 7.2.1.
7.6.3.6 Explicit type conversion
const std::string to_str ing( sc_numrep numrep = SC_DEC ) const;
const std::string to_str ing( sc_numrep numrep, bool w_pref ix ) const;
Member f uncti on to_str ing shall perf orm conversi on to an std::str ing representation, as described
in 7.2.11. Call ing the to_str ing f unction wi th a si ngl e argument i s equivalent to call ing the to_str ing
f uncti on with two arguments, where the second argument i s true. Call ing the to_str ing f uncti on
wi th no arguments i s equivalent to call ing the to_str ing f unction wi th two arguments, where the fi rst
argument is SC_DEC and the second argument is true.
7.6.3.7 Arithmetic, bitwise, and comparison operators
Operati ons specif ied i n Tabl e 10, Table 11, and Tabl e 12 are permitted. The foll owing appl ies:
S represents an obj ect of type sc_signed.
U represents an obj ect of type sc_unsigned.
i represents an obj ect of integer type int, long, unsigned int, unsigned long, sc_signed,
sc_unsigned, sc_int_base, or sc_uint_base.
s represents an obj ect of si gned integer type int, long, sc_signed, or sc_int_base.
The operands may al so be of any other cl ass that i s derived from those just given.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


231
Copyright 2012 IEEE. All rights reserved.
Table 10sc_signed arithmetic operations
Expr ession Retur n type Oper ation
S + i sc_si gned sc_si gned addi ti on
i + S sc_si gned sc_si gned addi ti on
U + s sc_si gned addi ti on of sc_unsi gned and si gned
s + U sc_si gned addi ti on of si gned and sc_unsi gned
S += i sc_si gned& sc_si gned assi gn sum
S - i sc_si gned sc_si gned subtracti on
i - S sc_si gned sc_si gned subtraction
U - i sc_si gned sc_unsi gned subtracti on
i - U sc_si gned sc_unsi gned subtracti on
S -= i sc_si gned& sc_si gned assi gn di f f erence
S * i sc_si gned sc_si gned mul ti pl i cati on
i * S sc_si gned sc_si gned mul ti pl i cati on
U * s sc_si gned mul ti pl i cati on of sc_unsi gned by signed
s * U sc_si gned mul ti pl i cati on of si gned by sc_unsigned
S * = i sc_si gned& sc_si gned assi gn product
S / i sc_si gned sc_si gned divi si on
i / S sc_si gned sc_si gned divi si on
U / s sc_si gned di vi si on of sc_unsi gned by si gned
s / U sc_si gned di vi si on of si gned by sc_unsi gned
S /= i sc_si gned& sc_si gned assi gn quoti ent
S % i sc_si gned sc_si gned remai nder
i % S sc_si gned sc_si gned remai nder
U % s sc_si gned remai nder of sc_unsi gned wi th si gned
s % U sc_si gned remai nder of si gned wi th sc_unsigned
S %= i sc_si gned& sc_si gned assi gn remainder
+S sc_si gned sc_si gned unary pl us
-S sc_si gned sc_si gned unary mi nus
-U sc_si gned sc_unsi gned unary mi nus
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


232
Copyright 2012 IEEE. All rights reserved.
I f the result of any arithmetic operati on i s zero, the word length of the return value shall be set by the
sc_length_context in scope. Otherwi se, the foll owing rules apply:
Addition shall return a result with a word length that is equal to the word length of the longest
operand plus one.
Multiplication shall return a result with a word length that is equal to the sum of the word lengths of
the two operands.
Remainder shall return a result with a word length that is equal to the word length of the shortest
operand.
All other arithmetic operators shall return a result with a word length that is equal to the word length
of the longest operand.
Table 11sc_signed bitwise operations
Expr ession Retur n type Oper ation
S & i sc_si gned sc_si gned bi twi se and
i & S sc_si gned sc_si gned bi twi se and
U & s sc_si gned sc_unsi gned bi twi se and si gned
s & U sc_si gned si gned bi twi se and sc_unsigned
S & = i sc_si gned& sc_si gned assi gn bi twi se and
S | i sc_si gned sc_si gned bi twi se or
i | S sc_si gned sc_si gned bi twi se or
U | s sc_si gned sc_unsi gned bi twi se or si gned
s | U sc_si gned si gned bi twi se or sc_unsigned
S |= i sc_si gned& sc_si gned assi gn bi twi se or
S ^ i sc_si gned sc_si gned bi twi se excl usi ve or
i ^ S sc_si gned sc_si gned bi twi se excl usi ve or
U ^ s sc_si gned sc_unsi gned bi twise excl usive or si gned
s ^ U sc_si gned sc_unsi gned bi twise excl usive or si gned
S ^= i sc_si gned& sc_si gned assi gn bi twi se exclusi ve or
S << i sc_si gned sc_si gned l ef t-shi f t
U << S sc_unsi gned sc_unsi gned lef t-shif t
S <<= i sc_si gned& sc_si gned assi gn l ef t-shi f t
S >> i sc_si gned sc_si gned ri ght-shi f t
U >> S sc_unsi gned sc_unsi gned ri ght-shi ft
S >>= i sc_si gned& sc_si gned assi gn ri ght-shi f t
~S sc_si gned sc_si gned bi twi se compl ement
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


233
Copyright 2012 IEEE. All rights reserved.
Binary bi twise operators shal l return a result wi th a word length that i s equal to the word length of the
longest operand.
The left shif t operator shal l return a result wi th a word length that i s equal to the word l ength of i ts sc_signed
operand plus the right (integer) operand. Bits added on the ri ght-hand si de of the result shall be set to zero.
The ri ght shi ft operator shal l return a resul t wi th a word length that i s equal to the word length of i ts
sc_signed operand. Bi ts added on the left-hand si de of the result shall be set to the same val ue as the left-
hand bit of the sc_signed operand (a right-shif t preserves the sign).
The behavi or of a shif t operator i s undef ined if the right operand i s negative.
NOTEAn implementation is required to suppl y overl oaded operators on sc_signed obj ects to sati sfy the requi rements
of thi s subcl ause. I t i s unspeci f i ed whether these operators are members of sc_signed, global operators, or provi ded i n
some other way.
7.6.3.8 Other member functions
void scan( std::i stream& i s = std::ci n );
Member functi on scan shall set the value by reading the next formatted character stri ng from the
specif ied input stream (see 7.2.10).
void pr int( std::ostream& os = std::cout ) const;
Member f uncti on pr int shal l write the val ue as a f ormatted character string to the specif ied output
stream (see 7.2.10).
Table 12sc_signed comparison operations
Expr ession Retur n type Oper ation
S == i bool test equal
i == S bool test equal
S ! = i bool test not equal
i ! = S bool test not equal
S < i bool test l ess than
i < S bool test l ess than
S <= i bool test l ess than or equal
i <= S bool test l ess than or equal
S > i bool test greater than
i > S bool test greater than
S >= i bool test greater than or equal
i >= S bool test greater than or equal
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


234
Copyright 2012 IEEE. All rights reserved.
int length() const;
Member f uncti on length shall return the word length (see 7.2.4).
7.6.4 sc_unsigned
7.6.4.1 Description
Cl ass sc_unsigned represents a fi nite word-length unsi gned i nteger. The word l ength shal l be speci fi ed by a
constructor argument or, by defaul t, by the length context currentl y in scope. The word length of an
sc_unsigned obj ect is fi xed during instanti ation and shall not be subsequently changed.
The integer value shal l be stored with a fi ni te preci sion determi ned by the speci fi ed word l ength. The
precision shall not depend on the l imited resoluti on of any standard C++ integer type.
sc_unsigned is the base class f or the sc_biguint class template.
7.6.4.2 Class definition
namespace sc_dt {
class sc_unsigned
: publi c sc_val ue_base

{
f ri end cl ass sc_concatr ef

;
f ri end cl ass sc_unsi gned_bi tr ef_r

;
f ri end cl ass sc_unsi gned_bi tr ef

;
f ri end cl ass sc_unsi gned_subref_r

;
f ri end cl ass sc_unsi gned_subref

;
f riend cl ass sc_si gned;
f ri end cl ass sc_si gned_subr ef

;
publ ic:
// Constructors
expl icit sc_unsigned( i nt nb = sc_length_param().l en() );
sc_unsigned( const sc_unsigned& v );
sc_unsigned( const sc_si gned& v );
templ ate<cl ass T>
expl icit sc_unsigned( const sc_generi c_base<T>& v );
expl icit sc_unsigned( const sc_bv_base& v );
expl icit sc_unsigned( const sc_lv_base& v );
expl icit sc_unsigned( const sc_int_subref_r& v );
expl icit sc_unsigned( const sc_uint_subref_r& v );
expl icit sc_unsigned( const sc_si gned_subref _r& v );
expl icit sc_unsigned( const sc_unsigned_subref_r& v );
// Assi gnment operators
sc_unsi gned& oper ator = ( const sc_unsigned& v);
sc_unsi gned& oper ator = ( const sc_unsi gned_subref_r

& a );
templ ate<cl ass T>
sc_unsi gned& oper ator = ( const sc_generi c_base<T>& a );
sc_unsi gned& oper ator = ( const sc_si gned& v );
sc_unsi gned& oper ator = ( const sc_si gned_subr ef_r

& a );
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


235
Copyright 2012 IEEE. All rights reserved.
sc_unsi gned& oper ator = ( const char* v);
sc_unsi gned& oper ator = ( i nt64 v );
sc_unsi gned& oper ator = ( ui nt64 v );
sc_unsi gned& oper ator = ( l ong v );
sc_unsi gned& oper ator = ( unsigned long v );
sc_unsigned& oper ator = ( i nt v );
sc_unsi gned& oper ator = ( unsigned int v );
sc_unsi gned& oper ator = ( double v );
sc_unsi gned& oper ator = ( const sc_int_base& v );
sc_unsi gned& oper ator = ( const sc_uint_base& v );
sc_unsi gned& oper ator = ( const sc_bv_base& );
sc_unsi gned& oper ator = ( const sc_lv_base& );
sc_unsigned& oper ator = ( const sc_fxval& );
sc_unsi gned& oper ator = ( const sc_fxval _fast& );
sc_unsi gned& oper ator = ( const sc_fxnum& );
sc_unsi gned& oper ator = ( const sc_fxnum_fast& );
// Destructor
~sc_unsigned();
// Increment operators
sc_unsi gned& oper ator ++ ();
const sc_unsigned oper ator ++ ( i nt );
// Decrement operators
sc_unsi gned& oper ator-- ();
const sc_unsigned oper ator-- ( i nt) ;
// Bit selecti on
sc_unsi gned_bi tr ef

oper ator [] ( i nt i );
sc_unsi gned_bi tr ef_r

oper ator [] ( i nt i ) const;


// Part selection
sc_unsi gned_subref

r ange ( i nt i , int j );
sc_unsi gned_subref_r

r ange( i nt i , i nt j ) const;
sc_unsi gned_subref

oper ator () ( i nt i , i nt j );
sc_unsi gned_subref_r

oper ator () ( i nt i , i nt j ) const;


// Expl icit conversions
int to_int() const;
unsi gned int to_uint() const;
long to_long() const;
unsi gned long to_ulong() const;
int64 to_int64() const;
uint64 to_uint64() const;
doubl e to_double() const;
// Expl icit conversion to character stri ng
const std::string to_str ing( sc_numrep numrep = SC_DEC ) const;
const std::string to_str ing( sc_numrep numrep, bool w_pref i x ) const;
// Pri nt functions
void pr int( std::ostream& os = std::cout ) const;
void scan( std::i stream& i s = std::ci n );
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


236
Copyright 2012 IEEE. All rights reserved.
// Capacity
int length() const; // Bit width
// Reduce methods
bool and_r educe() const;
bool nand_r educe() const;
bool or_r educe() const;
bool nor_reduce() const;
bool xor_reduce() const;
bool xnor _reduce() const;
// Overloaded operators
} ;
} // namespace sc_dt
7.6.4.3 Constraints on usage
An obj ect of type sc_unsigned may not be used as a di rect repl acement f or a C++ i nteger type since no
implici t type conversi on member f unctions are provi ded. An expl icit type conversion is required to pass the
val ue of an sc_unsigned object as an argument to a f unction expecting a C++ i nteger val ue argument.
7.6.4.4 Constructors
expl icit sc_unsigned( i nt nb = sc_length_param().l en() );
Constructor sc_unsigned shal l create an sc_unsigned obj ect of word l ength specif ied by nb. This i s
the default constructor when nb i s not speci fied (in whi ch case its val ue is set by the current length
context). The i nitial val ue shal l be 0.
templ ate< cl ass T >
sc_unsigned( const sc_generi c_base<T>& a );
Constructor sc_unsigned shal l create an sc_unsigned object wi th a word l ength matchi ng the
constructor argument. The constructor shal l set the i ni ti al val ue of the object to the val ue returned
f rom the member functi on to_sc_unsigned of the constructor argument.
The other constructors create an sc_unsigned obj ect with the same word length and val ue as the
constructor argument.
7.6.4.5 Assignment operators
Overl oaded assi gnment operators shall provide conversion f rom SystemC data types and the nati ve C++
integer representati on to sc_unsigned, usi ng truncation or si gn-extension as descri bed in 7.2.1.
7.6.4.6 Explicit type conversion
const std::string to_str ing( sc_numrep numrep = SC_DEC ) const;
const std::string to_str ing( sc_numrep numrep, bool w_pref ix ) const;
Member function to_str ing shal l perf orm the conversion to an std::str ing, as described in 7.2.11.
Call ing the to_str ing f uncti on with a single argument is equi valent to call ing the to_str ing f uncti on
wi th two arguments, where the second argument is true. Call ing the to_str ing f unction wi th no
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


237
Copyright 2012 IEEE. All rights reserved.
arguments is equival ent to cal li ng the to_str ing f unction with two arguments, where the fi rst
argument is SC_DEC and the second argument is true.
7.6.4.7 Arithmetic, bitwise, and comparison operators
Operati ons specif ied i n Tabl e 13, Table 14, and Tabl e 15 are permitted. The foll owing appl ies:
S represents an obj ect of type sc_signed.
U represents an obj ect of type sc_unsigned.
i represents an obj ect of integer type int, long, unsigned int, unsigned long, sc_signed,
sc_unsigned, sc_int_base, or sc_uint_base.
s represents an obj ect of si gned integer type int, long, sc_signed, or sc_int_base.
u represents an object of unsigned integer type unsigned int, unsigned long, sc_unsigned, or
sc_uint_base.
The operands may al so be of any other cl ass that i s derived from those just given.
Table 13sc_unsigned arithmetic operations
Expr ession Retur n type Oper ation
U + u sc_unsi gned sc_unsi gned addi ti on
u + U sc_unsi gned sc_unsi gned addi ti on
U + s sc_si gned addi ti on of sc_unsi gned and si gned
s + U sc_si gned additi on of si gned and sc_unsigned
U += i sc_unsi gned& sc_unsi gned assi gn sum
U - i sc_si gned sc_unsi gned subtracti on
i - U sc_si gned sc_unsi gned subtracti on
U -= i sc_unsi gned& sc_unsi gned assi gn di f ference
U * u sc_unsi gned sc_unsi gned mul ti pl icati on
u * U sc_unsi gned sc_unsi gned mul ti pl icati on
U * s sc_si gned multi pl i cati on of sc_unsi gned by si gned
s * U sc_si gned multi pl i cati on of si gned by sc_unsigned
U * = i sc_unsi gned& sc_unsi gned assi gn product
U / u sc_unsi gned sc_unsi gned di vi si on
u / U sc_unsi gned sc_unsi gned di vi si on
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


238
Copyright 2012 IEEE. All rights reserved.
I f the result of any arithmetic operati on i s zero, the word length of the return value shall be set by the
sc_length_context in scope. Otherwi se, the foll owing rules apply:
Addition shall return a result with a word length that is equal to the word length of the longest
operand plus one.
Multiplication shall return a result with a word length that is equal to the sum of the word lengths of
the two operands.
Remainder shall return a result with a word length that is equal to the word length of the shortest
operand.
All other arithmetic operators shall return a result with a word length that is equal to the word length
of the longest operand.
Binary bi twise operators shal l return a result wi th a word length that i s equal to the word length of the
longest operand.
The lef t shi ft operator shal l return a resul t with a word length that i s equal to the word l ength of its
sc_unsigned operand pl us the right (integer) operand. Bits added on the right-hand si de of the resul t shall be
set to zero.
The ri ght shi ft operator shal l return a resul t wi th a word length that i s equal to the word length of i ts
sc_unsigned operand. Bits added on the l ef t-hand si de of the resul t shal l be set to zero.
NOTEAn implementation is required to suppl y overl oaded operators on sc_unsigned obj ects to sati sf y the
requi rements of this subcl ause. It i s unspeci f i ed whether these operators are members of sc_unsigned, gl obal operators,
or provi ded i n some other way.
U / s sc_si gned di vi si on of sc_unsi gned by si gned
s / U sc_si gned di visi on of si gned by sc_unsi gned
U /= i sc_unsi gned& sc_unsi gned assi gn quoti ent
U % u sc_unsi gned sc_unsi gned remai nder
u % U sc_unsi gned sc_unsi gned remai nder
U % s sc_si gned remai nder of sc_unsi gned with si gned
s % U sc_si gned remai nder of si gned wi th sc_unsi gned
U %= i sc_unsi gned& sc_unsi gned assi gn remai nder
+U sc_unsi gned sc_unsi gned unary pl us
-U sc_si gned sc_unsi gned unary mi nus
Table 13sc_unsigned arithmetic operations (continued)
Expr ession Retur n type Oper ation
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


239
Copyright 2012 IEEE. All rights reserved.
7.6.4.8 Other member functions
void scan( std::i stream& i s = std::ci n );
Member functi on scan shall set the value by reading the next formatted character stri ng from the
specif ied input stream (see 7.2.10).
Table 14sc_unsigned bitwise operations
Expr ession Retur n type Oper ation
U & u sc_unsi gned sc_unsi gned bi twi se and
u & U sc_unsi gned sc_unsi gned bi twi se and
U & s sc_si gned sc_unsi gned bi twi se and si gned
s & U sc_si gned si gned bi twise and sc_unsi gned
U & = i sc_unsi gned& sc_unsi gned assi gn bi twise and
U | u sc_unsi gned sc_unsi gned bi twi se or
u | U sc_unsi gned sc_unsi gned bi twi se or
U | s sc_si gned sc_unsi gned bi twi se or si gned
s | U sc_si gned si gned bi twi se or sc_unsi gned
U |= i sc_unsi gned& sc_unsi gned assi gn bi twi se or
U ^ u sc_unsi gned sc_unsi gned bi twi se excl usi ve or
u ^ U sc_unsi gned sc_unsi gned bi twi se excl usi ve or
U ^ s sc_si gned sc_unsi gned bi twi se excl usi ve or si gned
s ^ U sc_si gned sc_unsi gned bi twi se excl usi ve or si gned
U ^= i sc_unsi gned& sc_unsi gned assign bi twi se excl usi ve or
U << i sc_unsi gned sc_unsi gned l ef t-shi f t
S << U sc_si gned sc_si gned l eft-shi f t
U <<= i sc_unsi gned& sc_unsi gned assi gn l ef t-shi f t
U >> i sc_unsi gned sc_unsi gned ri ght-shi f t
S >> U sc_si gned sc_si gned right-shif t
U >>= i sc_unsi gned& sc_unsi gned assi gn ri ght-shi f t
~U sc_unsi gned sc_unsi gned bi twi se compl ement
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


240
Copyright 2012 IEEE. All rights reserved.
void pr int( std::ostream& os = std::cout ) const;
Member f uncti on pr int shal l write the val ue as a f ormatted character string to the specif ied output
stream (see 7.2.10).
int length() const;
Member f uncti on length shall return the word length (see 7.2.4).
7.6.5 sc_bigint
7.6.5.1 Description
Class templ ate sc_bigint represents a f inite word-length si gned integer. The word l ength shall be specif ied
by a template argument. The i nteger value shall be stored wi th a fi ni te preci si on determined by the speci fi ed
word l ength. The precision shall not depend on the limited resoluti on of any standard C++ integer type.
Any publi c member f unctions of the base class sc_signed that are overri dden in class sc_bigint shall have
the same behavior i n the two cl asses. Any publi c member functions of the base cl ass not overri dden i n thi s
way shal l be publ icly inherited by cl ass sc_bigint. The operati ons speci fi ed in 7.6.3.7 are permitted f or
objects of type sc_bigint.
7.6.5.2 Class definition
namespace sc_dt {
templ ate< i nt W >
Table 15sc_unsigned comparison operations
Expr ession Retur n type Oper ation
U == i bool test equal
i == U bool test equal
U ! = i bool test not equal
i ! = U bool test not equal
U < i bool test l ess than
i < U bool test l ess than
U <= i bool test l ess than or equal
i <= U bool test l ess than or equal
U > i bool test greater than
i > U bool test greater than
U >= i bool test greater than or equal
i >= U bool test greater than or equal
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


241
Copyright 2012 IEEE. All rights reserved.
class sc_bigint
: publi c sc_signed
{
publ ic:
// Constructors
sc_bigint();
sc_bigint( const sc_bigint<W>& v );
sc_bigint( const sc_si gned& v );
sc_bigint( const sc_si gned_subr ef

& v );
templ ate< cl ass T >
sc_bigint( const sc_generi c_base<T>& a );
sc_bigint( const sc_unsigned& v );
sc_bigint( const sc_unsi gned_subref

& v );
sc_bigint( const char* v );
sc_bigint( i nt64 v );
sc_bigint( ui nt64 v );
sc_bigint( l ong v );
sc_bigint( unsigned long v );
sc_bigint( i nt v );
sc_bigint( unsigned int v );
sc_bigint( double v );
sc_bigint( const sc_bv_base& v );
sc_bigint( const sc_lv_base& v );
expl icit sc_bigint( const sc_fxval & v );
expl icit sc_bigint( const sc_fxval _fast& v );
expl icit sc_bigint( const sc_fxnum& v );
expl icit sc_bigint( const sc_fxnum_fast& v );
// Destructor
~sc_bigint();
// Assi gnment operators
sc_bigi nt<W>& oper ator = ( const sc_bi gint<W>& v );
sc_bigi nt<W>& oper ator = ( const sc_si gned& v );
sc_bigi nt<W>& oper ator = (const sc_si gned_subr ef

& v );
templ ate< cl ass T >
sc_bigi nt<W>& oper ator = ( const sc_generi c_base<T>& a );
sc_bigi nt<W>& oper ator = ( const sc_unsigned& v );
sc_bigi nt<W>& oper ator = ( const sc_unsi gned_subref

& v );
sc_bigi nt<W>& oper ator = ( const char* v );
sc_bigi nt<W>& oper ator = ( i nt64 v );
sc_bigi nt<W>& oper ator = ( ui nt64 v );
sc_bigi nt<W>& oper ator = ( l ong v );
sc_bigi nt<W>& oper ator = ( unsigned long v );
sc_bigi nt<W>& oper ator = ( i nt v );
sc_bigi nt<W>& oper ator = ( unsigned int v );
sc_bigi nt<W>& oper ator = ( double v );
sc_bigi nt<W>& oper ator = ( const sc_bv_base& v );
sc_bigi nt<W>& oper ator = ( const sc_lv_base& v );
sc_bigi nt<W>& oper ator = ( const sc_int_base& v );
sc_bigi nt<W>& oper ator = ( const sc_ui nt_base& v );
sc_bigi nt<W>& oper ator = ( const sc_fxval & v );
sc_bigi nt<W>& oper ator = ( const sc_fxval_fast& v );
sc_bigi nt<W>& oper ator = ( const sc_fxnum& v );
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


242
Copyright 2012 IEEE. All rights reserved.
sc_bigi nt<W>& oper ator = ( const sc_fxnum_fast& v );
} ;
} // namespace sc_dt
7.6.5.3 Constraints on usage
An obj ect of type sc_bigint may not be used as a di rect replacement f or a C++ i nteger type si nce no i mpli ci t
type conversion member functions are provi ded. An expli ci t type conversion is required to pass the val ue of
an sc_bigint object as an argument to a f unction expecting a C++ i nteger val ue argument.
7.6.5.4 Constructors
sc_bigint();
Default constructor sc_bigint shall create an sc_bigint object of word l ength speci fi ed by the
templ ate argument W and shal l set the i niti al value to 0.
templ ate< cl ass T >
sc_bigint( const sc_generi c_base<T>& a );
Constructor sc_bigint shal l create an sc_bigint object of word length speci fi ed by the template
argument. The constructor shall set the initial val ue of the object to the val ue returned from the
member f uncti on to_sc_signed of the constructor argument.
Other constructors shal l create an sc_bigint obj ect of word length specif ied by the template argument W and
val ue corresponding to the integer magni tude of the constructor argument. If the word length of the specif ied
ini ti al val ue di ff ers from the template argument, truncation or sign-extension shall be used as described in
7.2.1.
NOTEMost constructors can be used as impli ci t conversi ons f rom f undamental types or SystemC data types to
sc_bigint. Hence, a f uncti on havi ng an sc_bigint parameter can be passed a f l oating-poi nt argument, f or example, and
the argument wi l l be i mpl ici tl y converted. The excepti ons are the conversions f rom f i xed-poi nt types to sc_bigint, whi ch
must be cal l ed expl i ci tl y.
7.6.5.5 Assignment operators
Overl oaded assi gnment operators shall provide conversion f rom SystemC data types and the nati ve C++
integer representati on to sc_bigint, usi ng truncation or si gn-extension as descri bed i n 7.2.1.
7.6.6 sc_biguint
7.6.6.1 Description
Class template sc_biguint represents a fi nite word-l ength unsigned integer. The word l ength shall be
specif ied by a template argument. The integer val ue shal l be stored wi th a f ini te preci si on determined by the
specif ied word l ength. The precision shall not depend on the l imi ted resoluti on of any standard C++ i nteger
type.
Any publi c member functions of the base cl ass sc_unsigned that are overri dden i n class sc_biguint shall
have the same behavior in the two cl asses. Any publ ic member f unctions of the base cl ass not overri dden in
thi s way shal l be publ icly inherited by class sc_biguint. The operations specif ied i n 7.6.4.7 are permi tted for
objects of type sc_biguint.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


243
Copyright 2012 IEEE. All rights reserved.
7.6.6.2 Class definition
namespace sc_dt {
templ ate< i nt W >
class sc_biguint
: publi c sc_unsigned
{
publ ic:
// Constructors
sc_biguint();
sc_biguint( const sc_biguint<W>& v );
sc_biguint( const sc_unsigned& v );
sc_biguint( const sc_unsi gned_subref

& v );
templ ate< cl ass T >
sc_biguint( const sc_generi c_base<T>& a );
sc_biguint( const sc_si gned& v );
sc_biguint( const sc_si gned_subr ef

& v );
sc_biguint( const char* v );
sc_biguint( i nt64 v );
sc_biguint( ui nt64 v );
sc_biguint( l ong v );
sc_biguint( unsigned l ong v );
sc_biguint( i nt v );
sc_biguint( unsigned int v );
sc_biguint( double v );
sc_biguint( const sc_bv_base& v );
sc_biguint( const sc_lv_base& v );
expl icit sc_biguint( const sc_fxval& v );
expl icit sc_biguint( const sc_fxval_fast& v );
expl icit sc_biguint( const sc_fxnum& v );
expl icit sc_biguint( const sc_fxnum_fast& v );
// Destructor
~sc_biguint();
// Assi gnment operators
sc_biguint<W>& oper ator = ( const sc_bi gui nt<W>& v );
sc_biguint<W>& oper ator = ( const sc_unsigned& v );
sc_biguint<W>& oper ator = ( const sc_unsi gned_subref

& v );
templ ate< cl ass T >
sc_biguint<W>& oper ator = ( const sc_generi c_base<T>& a );
sc_biguint<W>& oper ator = ( const sc_si gned& v );
sc_biguint<W>& oper ator = ( const sc_si gned_subr ef

& v );
sc_biguint<W>& oper ator = ( const char* v );
sc_biguint<W>& oper ator = ( i nt64 v );
sc_biguint<W>& oper ator = ( ui nt64 v );
sc_biguint<W>& oper ator = ( l ong v );
sc_biguint<W>& oper ator = ( unsigned long v );
sc_biguint<W>& oper ator = ( i nt v );
sc_biguint<W>& oper ator = ( unsigned int v );
sc_biguint<W>& oper ator = ( double v );
sc_biguint<W>& oper ator = ( const sc_bv_base& v );
sc_biguint<W>& oper ator = ( const sc_lv_base& v );
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


244
Copyright 2012 IEEE. All rights reserved.
sc_biguint<W>& oper ator = ( const sc_int_base& v );
sc_biguint<W>& oper ator = ( const sc_ui nt_base& v );
sc_biguint<W>& oper ator = ( const sc_fxval & v );
sc_biguint<W>& oper ator = ( const sc_fxval _fast& v );
sc_biguint<W>& oper ator = ( const sc_fxnum& v );
sc_biguint<W>& oper ator = ( const sc_fxnum_fast& v );
} ;
} // namespace sc_dt
7.6.6.3 Constraints on usage
An obj ect of type sc_biguint may not be used as a direct repl acement for a C++ i nteger type si nce no
implici t type conversi on member f unctions are provi ded. An expl icit type conversion is required to pass the
val ue of an sc_biguint obj ect as an argument to a functi on expecti ng a C++ integer value argument.
7.6.6.4 Constructors
sc_biguint();
Default constructor sc_biguint shal l create an sc_biguint object of word length specif ied by the
templ ate argument W and shal l set the i niti al value to 0.
templ ate< cl ass T >
sc_biguint( const sc_generi c_base<T>& a );
Constructor shall create an sc_biguint obj ect of word length specifi ed by the template argument.
The constructor shal l set the ini ti al value of the object to the val ue returned f rom the member
f uncti on to_sc_unsigned of the constructor argument.
The other constructors shal l create an sc_biguint obj ect of word length specif i ed by the template argument
W and value correspondi ng to the i nteger magnitude of the constructor argument. I f the word l ength of the
specif ied i nitial value di ff ers from the template argument, truncati on or si gn-extension shall be used as
descri bed in 7.2.1.
NOTEMost constructors can be used as impli ci t conversi ons f rom f undamental types or SystemC data types to
sc_biguint. Hence, a f uncti on havi ng an sc_biguint parameter can be passed a f l oati ng-poi nt argument, f or exampl e,
and the argument wi ll be i mpl i ci tl y converted. The excepti ons are the conversi ons f rom fi xed-poi nt types to sc_biguint,
whi ch must be cal l ed expl i ci tly.
7.6.6.5 Assignment operators
Overl oaded assi gnment operators shall provide conversion f rom SystemC data types and the nati ve C++
integer representati on to sc_biguint, usi ng truncati on or si gn-extension, as descri bed in 7.2.1.
7.6.7 Bit-selects
7.6.7.1 Description
Cl ass sc_si gned_bi tref_r

represents a bit selected from an sc_signed used as an rval ue.


Class sc_si gned_bi tref

represents a bit selected f rom an sc_signed used as an l val ue.


Cl ass sc_unsi gned_bi tr ef_r

represents a bit selected f rom an sc_unsigned used as an rval ue.


IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


245
Copyright 2012 IEEE. All rights reserved.
Cl ass sc_unsi gned_bi tr ef

represents a bit sel ected f rom an sc_unsigned used as an l val ue.


7.6.7.2 Class definition
namespace sc_dt {
class sc_si gned_bi tref_r

: publi c sc_val ue_base

{
f riend cl ass sc_si gned;
f ri end cl ass sc_si gned_bi tref

;
publ ic:
// Copy constructor
sc_si gned_bi tref_r

( const sc_si gned_bi tref_r

& a );
// Destructor
virtual ~sc_si gned_bi tref_r

();
// Capacity
int length() const;
// Impl icit conversi on to ui nt64
oper ator uint64 () const;
bool oper ator ! () const;
bool oper ator ~ () const;
// Expl icit conversions
bool to_bool() const;
// Other methods
void pr int( std::ostream& os = std::cout ) const;
protected:
sc_si gned_bi tref_r

();
pri vate:
// Di sabl ed
sc_si gned_bi tref_r

& oper ator = ( const sc_si gned_bi tref_r

& );
} ;
// -----------------------------------------------------------------
class sc_si gned_bi tref

: publi c sc_si gned_bi tref_r

{
f riend cl ass sc_si gned;
publ ic:
// Copy constructor
sc_si gned_bi tref

( const sc_si gned_bi tref

& a );
// Assi gnment operators
sc_si gned_bi tref

& oper ator = ( const sc_si gned_bi tref_r

& );
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


246
Copyright 2012 IEEE. All rights reserved.
sc_si gned_bi tref

& oper ator = ( const sc_si gned_bi tref

& );
sc_si gned_bi tref

& oper ator = ( bool );


sc_si gned_bi tref

& oper ator & = ( bool );


sc_si gned_bi tref

& oper ator |= ( bool );


sc_si gned_bi tref

& oper ator ^= ( bool );


// Other methods
void scan( std::i stream& i s = std::ci n );
protected:
sc_si gned_bi tref

();
} ;
// -----------------------------------------------------------------
class sc_unsi gned_bi tr ef_r


: publi c sc_val ue_base

{
f riend cl ass sc_unsigned;
publ ic:
// Copy constructor
sc_unsi gned_bi tr ef_r

( const sc_unsi gned_bi tr ef_r

& a );
// Destructor
virtual ~sc_unsi gned_bi tr ef_r

();
// Capacity
int length() const;
// Impl icit conversi on to ui nt64
oper ator uint64 () const;
bool oper ator ! () const;
bool oper ator ~ () const;
// Expl icit conversions
bool to_bool() const;
// Other methods
void pr int( std::ostream& os = std::cout ) const;
protected:
sc_unsi gned_bi tr ef_r

();
pri vate:
// Di sabl ed
sc_unsi gned_bi tr ef_r

& oper ator = ( const sc_unsi gned_bi tr ef_r

& );
} ;
// -----------------------------------------------------------------
class sc_unsi gned_bi tr ef

: publi c sc_unsi gned_bi tr ef_r

IEEE Std 1666-2011


IEEE Standard for Standard SystemC

Language Reference Manual


247
Copyright 2012 IEEE. All rights reserved.
{
f riend cl ass sc_unsigned;
publ ic:
// Copy constructor
sc_unsi gned_bi tr ef

( const sc_unsi gned_bi tr ef

& a );
// Assi gnment operators
sc_unsi gned_bi tr ef

& oper ator = ( const sc_unsi gned_bi tr ef_r

& );
sc_unsi gned_bi tr ef

& oper ator = ( const sc_unsi gned_bi tr ef

& );
sc_unsi gned_bi tr ef

& oper ator = ( bool );


sc_unsi gned_bi tr ef

& oper ator & = ( bool );


sc_unsi gned_bi tr ef

& oper ator |= ( bool );


sc_unsi gned_bi tr ef

& oper ator ^= ( bool );


// Other methods
void scan( std::i stream& i s = std::ci n );
protected:
sc_unsi gned_bi tr ef

();
} ;
} // namespace sc_dt
7.6.7.3 Constraints on usage
Bit-select objects shal l only be created usi ng the bi t-sel ect operators of an sc_signed or sc_unsigned object
(or an i nstance of a class deri ved from sc_signed or sc_unsigned).
An appl ication shall not expli citl y create an i nstance of any bi t-sel ect class.
An appl ication should not decl are a reference or pointer to any bit-sel ect obj ect.
I t is strongly recommended that an appl ication avoi d the use of a bi t-sel ect as the return type of a f unction
because the l if etime of the obj ect to whi ch the bi t-select ref ers may not extend beyond the f uncti on return
statement.
Exampl e:
sc_dt::sc_signed_bi tref get_bit_n(sc_si gned iv, int n) {
return iv[n] ; // Unsafe: returned bi t-sel ect ref erences local vari abl e
}
7.6.7.4 Assignment operators
Overl oaded assi gnment operators f or the lvalue bi t-sel ects shall provide conversi on from bool val ues.
Assi gnment operators f or rvalue bi t-sel ects shall be declared as pri vate to prevent their use by an
appl ication.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


248
Copyright 2012 IEEE. All rights reserved.
7.6.7.5 Implicit type conversion
oper ator uint64 () const;
oper ator uint64 can be used for i mpli ci t type conversi on f rom a bi t-sel ect to a native C++ unsi gned
integer having exactly 64 bits. If the selected bit has the val ue ' 1' (true), the conversi on shall return
the val ue 1; otherwise, i t shal l return 0.
bool oper ator ! () const;
bool oper ator ~ () const;
oper ator ! and oper ator ~ shall return a C++ bool val ue that is the inverse of the sel ected bi t.
7.6.7.6 Other member functions
void scan( std::i stream& i s = std::ci n );
Member f unction scan shal l set the value of the bit referenced by an lvalue bit-sel ect. The val ue
shal l correspond to the C++ bool val ue obtai ned by reading the next formatted character string from
the specif ied i nput stream (see 7.2.10).
void pr int( std::ostream& os = std::cout ) const;
Member function pr int shal l print the value of the bi t referenced by the bi t-select to the speci fi ed
output stream (see 7.2.10). The formatti ng shal l be i mplementati on-defi ned but shall be equi val ent
to pri nti ng the val ue returned by member functi on to_bool.
int length() const;
Member f uncti on length shall unconditi onal ly return a word l ength of 1 (see 7.2.4).
7.6.8 Part-selects
7.6.8.1 Description
Cl ass sc_si gned_subr ef_r

represents a signed integer part-select from an sc_signed used as an rval ue.


Cl ass sc_si gned_subr ef

represents a si gned integer part-sel ect f rom an sc_signed used as an l val ue.
Cl ass sc_unsi gned_subref_r

represents an unsigned integer part-select from an sc_unsigned used as an


rvalue.
Cl ass sc_unsi gned_subref

represents an unsi gned integer part-select from an sc_unsigned used as an


lvalue.
7.6.8.2 Class definition
namespace sc_dt {
class sc_si gned_subr ef_r


: publ ic sc_val ue_base

{
f riend cl ass sc_si gned;
f riend cl ass sc_unsigned;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


249
Copyright 2012 IEEE. All rights reserved.
publ ic:
// Copy constructor
sc_si gned_subr ef_r

( const sc_si gned_subr ef_r

& a );
// Destructor
virtual ~sc_unsi gned_subref_r

();
// Capacity
int length() const;
// Impl icit conversion to sc_unsigned
oper ator sc_unsigned () const;
// Expl icit conversions
int to_int() const;
unsi gned int to_uint() const;
long to_long() const;
unsi gned long to_ulong() const;
int64 to_int64() const;
uint64 to_uint64() const;
doubl e to_double() const;
// Expl icit conversion to character stri ng
const std::string to_str ing( sc_numrep numrep = SC_DEC ) const;
const std::string to_str ing( sc_numrep numrep, bool w_pref i x ) const;
// Reduce methods
bool and_r educe() const;
bool nand_r educe() const;
bool or_r educe() const;
bool nor_reduce() const;
bool xor_reduce() const;
bool xnor _reduce() const;
// Other methods
void pr int( std::ostream& os = std::cout ) const;
protected:
sc_si gned_subr ef_r

();
pri vate:
// Di sabl ed
sc_si gned_subr ef_r

& oper ator = ( const sc_si gned_subr ef_r

& );
} ;
// --------------------------------------------------------------
class sc_si gned_subr ef

: publi c sc_si gned_subr ef_r

{
f riend cl ass sc_si gned;
publ ic:
// Copy constructor
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


250
Copyright 2012 IEEE. All rights reserved.
sc_si gned_subr ef

( const sc_si gned_subr ef

& a );
// Assi gnment operators
sc_si gned_subr ef

& oper ator = ( const sc_si gned_subr ef_r

& a );
sc_si gned_subr ef

& oper ator = ( const sc_si gned_subr ef

& a );
sc_si gned_subr ef

& oper ator = ( const sc_si gned& a );


templ ate< cl ass T >
sc_si gned_subr ef

& oper ator = ( const sc_generi c_base<T>& a );


sc_si gned_subr ef

& oper ator = ( const sc_unsi gned_subref_r

& a );
sc_si gned_subr ef

& oper ator = ( const sc_unsigned& a );


sc_si gned_subr ef

& oper ator = ( const char* a );


sc_si gned_subr ef

& oper ator = ( unsigned l ong a );


sc_si gned_subr ef

& oper ator = ( l ong a );


sc_si gned_subr ef

& oper ator = ( unsigned i nt a );


sc_si gned_subr ef

& oper ator = ( i nt a );


sc_si gned_subr ef

& oper ator = ( ui nt64 a );


sc_si gned_subr ef

& oper ator = ( i nt64 a );


sc_si gned_subr ef

& oper ator = ( double a );


sc_si gned_subr ef

& oper ator = ( const sc_int_base& a );


sc_si gned_subr ef

& oper ator = ( const sc_uint_base& a );


// Other methods
void scan( std::i stream& i s = std::ci n );
pri vate:
// Di sabl ed
sc_si gned_subr ef

();
} ;
// --------------------------------------------------------------
class sc_unsi gned_subref_r

: publi c sc_val ue_base

{
f riend cl ass sc_si gned;
f riend cl ass sc_unsigned;
publ ic:
// Copy constructor
sc_unsi gned_subref_r

( const sc_unsi gned_subref_r

& a );
// Destructor
virtual ~sc_unsi gned_subref_r

();
// Capacity
int length() const;
// Impl icit conversion to sc_unsigned
oper ator sc_unsigned () const;
// Expl icit conversions
int to_int() const;
unsi gned int to_uint() const;
long to_long() const;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


251
Copyright 2012 IEEE. All rights reserved.
unsi gned long to_ulong() const;
int64 to_int64() const;
uint64 to_uint64() const;
doubl e to_double() const;
// Expl icit conversion to character stri ng
const std::string to_str ing( sc_numrep numrep = SC_DEC ) const;
const std::string to_str ing( sc_numrep numrep , bool w_pref ix ) const;
// Reduce methods
bool and_r educe() const;
bool nand_r educe() const;
bool or_r educe() const;
bool nor_reduce() const;
bool xor_reduce() const;
bool xnor _reduce() const;
// Other methods
void pr int( std::ostream& os = std::cout ) const;
protected:
sc_unsi gned_subref_r

();
pri vate:
// Di sabl ed
sc_unsi gned_subref _r& oper ator = ( const sc_unsi gned_subref_r

& );
} ;
// --------------------------------------------------------------
class sc_unsi gned_subref

: publi c sc_unsi gned_subref_r

{
f riend cl ass sc_unsigned;
publ ic:
// Copy constructor
sc_unsi gned_subref

( const sc_unsi gned_subref

& a );
// Assi gnment operators
sc_unsi gned_subref

& oper ator = ( const sc_unsi gned_subref_r

& a );
sc_unsi gned_subref

& oper ator = ( const sc_unsi gned_subref

& a );
sc_unsi gned_subref

& oper ator = ( const sc_unsigned& a );


templ ate<cl ass T>
sc_unsi gned_subref

& oper ator = ( const sc_generi c_base<T>& a );


sc_unsi gned_subref

& oper ator = ( const sc_si gned_subref_r& a );


sc_unsi gned_subref

& oper ator = ( const sc_si gned& a );


sc_unsi gned_subref

& oper ator = ( const char* a );


sc_unsi gned_subref

& oper ator = ( unsi gned long a );


sc_unsi gned_subref

& oper ator = ( l ong a );


sc_unsi gned_subref

& oper ator = ( unsi gned int a );


sc_unsi gned_subref

& oper ator = ( i nt a );


sc_unsi gned_subref

& oper ator = ( uint64 a );


sc_unsi gned_subref

& oper ator = ( i nt64 a );


IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


252
Copyright 2012 IEEE. All rights reserved.
sc_unsi gned_subref

& oper ator = ( double a );


sc_unsi gned_subref

& oper ator = ( const sc_int_base& a );


sc_unsi gned_subref

& oper ator = ( const sc_ui nt_base& a );


// Other methods
void scan( std::i stream& i s = std::ci n );
protected:
sc_unsi gned_subref

();
} ;
} // namespace sc_dt
7.6.8.3 Constraints on usage
I nteger part-select objects shal l only be created using the part-select operators of an sc_signed or
sc_unsigned obj ect (or an i nstance of a class derived f rom sc_signed or sc_unsigned), as descri bed i n 7.2.6.
An appl ication shall not expli citl y create an instance of any integer part-sel ect cl ass.
An appl ication should not declare a reference or pointer to any i nteger part-select object.
I t i s strongly recommended that an appli cation avoi d the use of a part-select as the return type of a functi on
because the li feti me of the obj ect to which the part-select refers may not extend beyond the functi on return
statement.
Exampl e:
sc_dt::sc_signed_subref get_byte(sc_signed s, int pos) {
return s(pos+7,pos); // Unsafe: returned part-select ref erences l ocal vari abl e
}
NOTEThe left-hand index of a finite-precisi on i nteger part-sel ect may be l ess than the ri ght-hand i ndex. The bi t order
i n the part-sel ect i s then the reverse of that i n the ori gi nal i nteger.
7.6.8.4 Assignment operators
Overl oaded assi gnment operators shall provide conversion f rom SystemC data types and the nati ve C++
integer representation to lval ue integer part-sel ects. I f the size of a data type or stri ng li teral operand dif fers
f rom the i nteger part-sel ect word l ength, truncation, zero-extensi on, or sign-extensi on shall be used, as
descri bed in 7.2.1.
Assi gnment operators for rvalue integer part-selects shal l be decl ared as pri vate to prevent their use by an
appl ication.
7.6.8.5 Implicit type conversion
sc_si gned_subr ef_r

:: oper ator sc_unsigned () const;


sc_unsi gned_subr ef_r

:: oper ator sc_unsigned () const;


oper ator sc_unsigned can be used f or impl icit type conversi on f rom integer part-sel ects to
sc_unsigned.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


253
Copyright 2012 IEEE. All rights reserved.
NOTEThese operators are used by the output stream operator and by member f uncti ons of other data type
cl asses that are not expl i ci tl y overl oaded f or f i ni te-preci sion i nteger part-sel ects.
7.6.8.6 Explicit type conversion
const std::string to_str ing( sc_numrep numrep = SC_DEC ) const;
const std::string to_str ing( sc_numrep numrep , bool w_pref ix ) const;
Member functi on to_str ing shall perf orm a conversi on to an std::str ing representati on, as descri bed
in 7.2.11. Call ing the to_str ing f unction wi th a si ngl e argument i s equivalent to call ing the to_str ing
f uncti on with two arguments, where the second argument i s true. Call ing the to_str ing f uncti on
wi th no arguments i s equi val ent to call ing the to_str ing functi on with two arguments where the f irst
argument is SC_DEC and the second argument is true.
7.6.8.7 Other member functions
void scan( std::i stream& i s = std::ci n );
Member function scan shal l set the values of the bi ts ref erenced by an lvalue part-select by reading
the next formatted character string from the specif ied i nput stream (see 7.2.10).
void pr int( std::ostream& os = std::cout ) const;
Member functi on pr int shall print the val ues of the bi ts referenced by the part-sel ect to the specif ied
output stream (see 7.2.10).
int length() const;
Member f uncti on length shall return the word length of the part-select (see 7.2.4).
7.7 Integer concatenations
7.7.1 Description
Cl ass sc_concatr ef

represents a concatenation of bits f rom one or more objects whose concatenati on base
types are SystemC integers.
7.7.2 Class definition
namespace sc_dt {
class sc_concatr ef


: publi c sc_generic_base<sc_concatr ef

>, publ ic sc_val ue_base

{
publ ic:
// Destructor
virtual ~sc_concatr ef

();
// Capacity
unsi gned int length() const;
// Expl icit conversions
int to_int() const;
unsi gned int to_uint() const;
long to_long() const;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


254
Copyright 2012 IEEE. All rights reserved.
unsi gned long to_ulong() const;
int64 to_int64() const;
uint64 to_uint64() const;
doubl e to_double() const;
void to_sc_signed( sc_si gned& target ) const;
void to_sc_unsigned( sc_unsigned& target ) const;
// Impl icit conversions
oper ator uint64() const;
oper ator const sc_unsigned& () const;
// Unary operators
sc_unsi gned oper ator + () const;
sc_unsi gned oper ator- () const;
sc_unsi gned oper ator ~ () const;
// Expl icit conversion to character stri ng
const std::string to_str ing( sc_numrep numrep = SC_DEC ) const;
const std::string to_str ing( sc_numrep numrep , bool w_pref ix ) const;
// Assi gnment operators
const sc_concatr ef

& oper ator = ( i nt v );


const sc_concatr ef

& oper ator = ( unsigned int v );


const sc_concatr ef

& oper ator = ( l ong v );


const sc_concatr ef

& oper ator = ( unsi gned long v );


const sc_concatr ef

& oper ator = ( i nt64 v );


const sc_concatr ef

& oper ator = ( ui nt64 v );


const sc_concatr ef

& oper ator = ( const sc_concatr ef

& v );
const sc_concatr ef

& oper ator = ( const sc_si gned& v );


const sc_concatr ef

& oper ator = ( const sc_unsigned& v );


const sc_concatr ef

& oper ator = ( const char* v_p );


const sc_concatr ef

& oper ator = ( const sc_bv_base& v );


const sc_concatr ef

& oper ator = ( const sc_lv_base& v );


// Reduce methods
bool and_r educe() const;
bool nand_r educe() const;
bool or_r educe() const;
bool nor_reduce() const;
bool xor_reduce() const;
bool xnor _reduce() const;
// Other methods
void pr int( std::ostream& os = std::cout ) const;
void scan( std::i stream& is );
pri vate:
sc_concatr ef

( const sc_concatr ef

& );
~sc_concatr ef

();
} ;
sc_concatr ef

& concat( sc_val ue_base

& a , sc_val ue_base

& b );
const sc_concatr ef

& concat( const sc_val ue_base

& a , const sc_val ue_base

& b );
const sc_concatr ef

& concat( const sc_val ue_base

& a, bool b );
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


255
Copyright 2012 IEEE. All rights reserved.
const sc_concatr ef

& concat( bool a , const sc_val ue_base

& b );
sc_concatr ef

& oper ator, ( sc_val ue_base

& a , sc_val ue_base

& b );
const sc_concatr ef

& oper ator, ( const sc_val ue_base

& a , const sc_val ue_base

& b );
const sc_concatr ef

& oper ator, ( const sc_val ue_base

& a , bool b );
const sc_concatr ef

& oper ator, ( bool a , const sc_val ue_base

& b );
} // namespace sc_dt
7.7.3 Constraints on usage
I nteger concatenati on objects shall only be created using the concat functi on (or oper ator,) accordi ng to the
rul es in 7.2.7.
At least one of the concatenation arguments shall be an object wi th a SystemC integer concatenati on base
type, that is, an i nstance of a class derived directly or i ndi rectly f rom class sc_val ue_base

.
A si ngl e concatenation argument (that is, one of the two arguments to the concat function or oper ator,) may
be a bool value, a reference to a sc_core::sc_signal<bool,WRI TER_POLI CY> channel, or a reference to a
sc_core::sc_in<bool>, sc_core::sc_inout<bool>, or sc_core::sc_out<bool> port.
An appli cation shall not expl icitly create an i nstance of any i nteger concatenation class. An appl ication shall
not impl icitly create an instance of any integer concatenation cl ass by using it as a f uncti on argument or as a
f uncti on return val ue.
An appl ication should not declare a ref erence or poi nter to any i nteger concatenation object.
7.7.4 Assignment operators
Overl oaded assi gnment operators shall provide conversion f rom SystemC data types and the nati ve C++
integer representation to lvalue integer concatenati ons. If the size of a data type or string li teral operand
dif fers f rom the integer concatenation word l ength, truncation, zero-extension, or sign-extension shall be
used, as descri bed in 7.2.1.
Assi gnment operators f or rval ue integer concatenations shall not be cal led by an appl icati on.
7.7.5 Implicit type conversion
oper ator uint64 () const;
oper ator const sc_unsigned& () const;
Operators uint64 and sc_unsigned shal l provide impl ici t unsigned type conversion f rom an i nteger
concatenation to a nati ve C++ unsigned i nteger having exactly 64 bits or a an sc_unsigned obj ect
wi th a length equal to the total number of bi ts contained wi thin the obj ects referenced by the
concatenation.
NOTEEnables the use of standard C++ and SystemC bitwi se logi cal and ari thmeti c operators wi th i nteger
concatenati on obj ects.
7.7.6 Explicit type conversion
const std::string to_str ing( sc_numrep numrep = SC_DEC ) const;
const std::string to_str ing( sc_numrep numrep , bool w_pref ix ) const;
Member f unction to_str ing shal l convert the object to an std::str ing representation, as described in
7.2.11. Cal li ng the to_str ing function with a single argument is equivalent to call ing the to_str ing
f uncti on with two arguments, where the second argument i s true. Call ing the to_str ing f unction wi th
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


256
Copyright 2012 IEEE. All rights reserved.
no arguments is equi val ent to call ing the to_str ing f unction wi th two arguments, where the f i rst
argument is SC_DEC and the second argument is true.
7.7.7 Other member functions
void scan( std::i stream& i s = std::ci n );
Member f uncti on scan shall set the val ues of the bits ref erenced by an lvalue concatenati on by
reading the next f ormatted character stri ng f rom the specif ied i nput stream (see 7.2.10).
void pr int( std::ostream& os = std::cout ) const;
Member f uncti on pr int shal l pri nt the val ues of the bits ref erenced by the concatenation to the
specif ied output stream (see 7.2.10).
int length() const;
Member f uncti on length shall return the word length of the concatenation (see 7.2.4).
7.8 Generic base proxy class
7.8.1 Description
Class templ ate sc_gener ic_base provides a common proxy base cl ass f or appli cation-defi ned data types that
are required to be converted to a SystemC i nteger.
7.8.2 Class definition
namespace sc_dt {
templ ate< cl ass T >
class sc_gener ic_base
{
publ ic:
inl ine const T* oper ator-> () const;
inl ine T* oper ator-> ();
} ;
} // namespace sc_dt
7.8.3 Constraints on usage
An appl ication shall not explici tly create an i nstance of sc_gener ic_base.
Any appli cation-defi ned type deri ved f rom sc_gener ic_base shall provide the f oll owing publi c const
member functi ons:
int length() const;
Member f uncti on length shall return the number of bi ts requi red to hol d the i nteger val ue.
uint64 to_uint64() const;
Member functi on to_uint64 shall return the val ue as a native C++ unsigned i nteger having exactly
64 bi ts.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


257
Copyright 2012 IEEE. All rights reserved.
int64 to_int64() const;
Member f unction to_int64 shal l return the val ue as a nati ve C++ signed i nteger having exactl y 64
bits.
void to_sc_unsigned( sc_unsigned& ) const;
Member function to_sc_unsigned shal l return the value as an unsigned i nteger using the
sc_unsi gned argument passed by ref erence.
void to_sc_signed( sc_si gned& ) const;
Member function to_sc_signed shall return the value as a signed integer using the sc_si gned
argument passed by reference.
7.9 Logic and vector types
7.9.1 Type definitions
The fol lowi ng enumerated type defini ti on is used by the l ogi c and vector type classes. Its li teral values
represent (i n numerical order) the four possi bl e l ogic states: l ogi c 0, l ogi c 1, hi gh-i mpedance, and unknown,
respecti vel y. This type i s not intended to be used di rectly by an appli cati on, which should instead use the
character li teral s ' 0' , ' 1' , ' Z' , and ' X ' to represent the logic states, or the appl icati on may use the constants
SC_LOGI C_0, SC_LOGIC_1, SC_LOGI C_Z, and SC_LOGI C_X i n contexts where the character l iterals
would be ambiguous.
namespace sc_dt {
enum sc_logic_value_t
{
Log_0 = 0,
Log_1,
Log_Z,
Log_X
} ;
} // namespace sc_dt
7.9.2 sc_logic
7.9.2.1 Description
Cl ass sc_logic represents a single bit with a value corresponding to any one of the four l ogi c states.
Appli cations should use the character li teral s '0' , '1' , 'Z ', and ' X' to represent the states logi c 0, logi c 1, high-
impedance, and unknown, respecti vel y. The lowercase character li teral s ' z' and ' x' are acceptable
alternatives to ' Z' and 'X ' , respectively. Any other character used as an sc_logic li teral shall be i nterpreted as
the unknown state.
The C++ bool val ues false and true may be used as arguments to sc_logic constructors and operators. They
shal l be i nterpreted as l ogi c 0 and l ogi c 1, respectivel y.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


258
Copyright 2012 IEEE. All rights reserved.
Logi c operations shal l be permi tted f or sc_logic values f ol lowi ng the truth tables shown in Tabl e 16,
Tabl e 17, Tabl e 18, and Tabl e 19.
Table 16sc_logic AND truth table
' 0' ' 1' ' Z' ' X'
' 0' '0' '0' '0' '0'
' 1' '0' '1' ' X' 'X'
' Z' '0' 'X' 'X' 'X'
' X' '0' 'X' 'X' 'X'
Table 17sc_logic OR truth table
' 0' ' 1' ' Z' ' X'
' 0' '0' '1' ' X' 'X'
' 1' '1' '1' '1' '1'
' Z' 'X' '1' 'X' 'X'
' X' 'X' '1' 'X' 'X'
Table 18sc_logic exclusive or truth table
' 0' ' 1' ' Z' ' X'
' 0' '0' '1' ' X' 'X'
' 1' '1' '0' ' X' 'X'
' Z' 'X' 'X' 'X' 'X'
' X' 'X' 'X' 'X' 'X'
Table 19sc_logic complement truth table
' 0' ' 1' ' Z' ' X'
'1' '0' ' X' 'X'
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


259
Copyright 2012 IEEE. All rights reserved.
7.9.2.2 Class definition
namespace sc_dt {
class sc_logic
{
publ ic:
// Constructors
sc_logic();
sc_logic( const sc_logic& a );
sc_logic( sc_l ogi c_value_t v );
expl icit sc_logic( bool a );
expl icit sc_logic( char a );
expl icit sc_logic( i nt a );
// Destructor
~sc_logic();
// Assi gnment operators
sc_logi c& oper ator = ( const sc_logic& a );
sc_logi c& oper ator = ( sc_l ogic_value_t v );
sc_l ogi c& oper ator = ( bool a );
sc_logi c& oper ator = ( char a );
sc_logi c& oper ator = ( i nt a );
// Expl icit conversions
sc_logi c_value_t value() const;
char to_char() const;
bool to_bool() const;
bool is_01() const;
void pr int( std::ostream& os = std::cout ) const;
void scan( std::i stream& i s = std::ci n );
pri vate:
// Di sabl ed
expl icit sc_logic( const char* );
sc_logi c& oper ator = ( const char* );
} ;
} // namespace sc_dt
7.9.2.3 Constraints on usage
An integer argument to an sc_logic constructor or operator shall be equi val ent to the correspondi ng
sc_logic_value_t enumerated value. I t shall be an error if any such integer argument i s outside the range 0 to
3.
A literal val ue assi gned to an sc_logicobject or used to i nitiali ze an sc_logicobj ect may be a character l iteral
but not a string li teral .
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


260
Copyright 2012 IEEE. All rights reserved.
7.9.2.4 Constructors
sc_logic();
Default constructor sc_logic shall create an sc_logic obj ect with a val ue of unknown.
sc_logic( const sc_logic& a );
sc_logic( sc_l ogi c_value_t v );
expl icit sc_logic( bool a );
expl icit sc_logic( char a );
expl icit sc_logic( i nt a );
Constructor sc_logic shall create an sc_logic obj ect with the value speci fi ed by the argument.
7.9.2.5 Explicit type conversion
sc_logi c_value_t value() const;
Member f uncti on value shall convert the sc_logic val ue to the sc_logic_value_t equi val ent.
char to_char() const;
Member f uncti on to_char shall convert the sc_logic val ue to the char equi val ent.
bool to_bool() const;
Member f uncti on to_bool shall convert the sc_logic val ue to false or true. It shall be an error to call
thi s f unction i f the sc_logic val ue i s not l ogi c 0 or l ogi c 1.
bool is_01() const;
Member functi on is_01 shall return true i f the sc_logic value i s logic 0 or logic 1; otherwi se, the
return val ue shal l be false.
7.9.2.6 Bitwise and comparison operators
The operati ons speci fi ed i n Table 20 shall be permitted. The f ol lowi ng appl ies:
L represents an obj ect of type sc_logic.
n represents an obj ect of type int, sc_logic, sc_logic_value_t, bool, char , or int.
NOTEAn implementation is required to supply overloaded operators on sc_logic obj ects to sati sf y therequi rementsof
thi s subcl ause. I t i s unspeci f i ed whether these operators are members of sc_logic, gl obal operators, or provi ded i n some
other way.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


261
Copyright 2012 IEEE. All rights reserved.
7.9.2.7 Other member functions
void scan( std::i stream& i s = std::ci n );
Member function scan shall set the val ue by readi ng the next non-white-space character from the
specif ied input stream (see 7.2.10).
void pr int( std::ostream& os = std::cout ) const;
Member functi on pr int shall write the value as the character li teral ' 0' , ' 1', ' X' , or ' Z' to the specif ied
output stream (see 7.2.10).
7.9.2.8 sc_logic constant definitions
A constant of type sc_logic shal l be defi ned f or each of the four possibl e sc_logic_value_t states. These
constants should be used by appl ications to assign val ues to, or compare values wi th, other sc_logic obj ects,
parti cul arl y i n those cases where an i mpli ci t conversion from a C++ char val ue would be ambi guous.
namespace sc_dt {
const sc_l ogi c SC_LOGI C_0( Log_0 );
const sc_l ogi c SC_LOGI C_1( Log_1 );
const sc_l ogic SC_LOGIC_Z( Log_Z );
const sc_l ogi c SC_LOGI C_X( Log_X );
Table 20sc_logic bitwise and comparison operations
Expr ession Retur n type Oper ation
~L const sc_l ogi c sc_l ogic bi twise complement
L & n const sc_l ogi c sc_l ogi c bi twi se and
n & L const sc_l ogi c sc_l ogi c bi twi se and
L & = n sc_l ogi c& sc_l ogi c assign bi twi se and
L | n const sc_l ogic sc_l ogi c bi twi se or
n | L const sc_l ogic sc_l ogi c bi twi se or
L |= n sc_l ogi c& sc_l ogic assi gn bi twi se or
L ^ n const sc_l ogic sc_l ogic bi twise excl usive or
n^ L const sc_l ogic sc_l ogic bi twise excl usive or
L ^= n sc_l ogi c& sc_l ogi c assi gn bi twi se excl usi ve or
L == n bool test equal
n == L bool test equal
L ! = n bool test not equal
n ! = L bool test not equal
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


262
Copyright 2012 IEEE. All rights reserved.
} // namespace sc_dt
Exampl e:
sc_core::sc_si gnal <sc_logic> A;
A = '0'; // Error: ambiguous conversion
A = stati c_cast<sc_logic>('0'); // Correct but not recommended
A = SC_LOGIC_0; // Recommended representati on of l ogi c 0
7.9.3 sc_bv_base
7.9.3.1 Description
Cl ass sc_bv_base represents a f inite word-l ength bit vector. I t can be treated as an array of bool or as an
array of sc_logic_value_t (with the restriction that only the states l ogi c 0 and l ogic 1 are l egal). The word
length shall be speci fi ed by a constructor argument or, by def aul t, by the length context object currently in
scope. The word length of an sc_bv_base object shal l be fi xed duri ng instantiati on and shal l not
subsequently be changed.
sc_bv_base is the base class f or the sc_bv class template.
7.9.3.2 Class definition
namespace sc_dt {
class sc_bv_base
{
f riend cl ass sc_lv_base;
publ ic:
// Constructors
expl icit sc_bv_base( i nt nb = sc_length_param().l en() );
expl icit sc_bv_base( bool a, int nb = sc_length_param().l en() );
sc_bv_base( const char* a );
sc_bv_base( const char* a , int nb );
templ ate <cl ass X>
sc_bv_base( const sc_subr ef_r

< X>& a );
templ ate <class T1, class T2>
sc_bv_base( const sc_concr ef_r

<T1,T2> & a );
sc_bv_base( const sc_lv_base& a );
sc_bv_base( const sc_bv_base& a );
// Destructor
virtual ~sc_bv_base();
// Assi gnment operators
templ ate <cl ass X>
sc_bv_base& oper ator = ( const sc_subr ef_r

< X>& a );
templ ate <class T1, class T2>
sc_bv_base& oper ator = ( const sc_concr ef_r

< T1,T2>& a );
sc_bv_base& oper ator = ( const sc_bv_base& a );
sc_bv_base& oper ator = ( const sc_lv_base& a );
sc_bv_base& oper ator = ( const char* a );
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


263
Copyright 2012 IEEE. All rights reserved.
sc_bv_base& oper ator = ( const bool* a );
sc_bv_base& oper ator = ( const sc_logic* a );
sc_bv_base& oper ator = ( const sc_unsigned& a );
sc_bv_base& oper ator = ( const sc_si gned& a );
sc_bv_base& oper ator = ( const sc_ui nt_base& a );
sc_bv_base& oper ator = ( const sc_int_base& a );
sc_bv_base& oper ator = ( unsi gned long a );
sc_bv_base& oper ator = ( l ong a );
sc_bv_base& oper ator = ( unsi gned int a );
sc_bv_base& oper ator = ( i nt a );
sc_bv_base& oper ator = ( uint64 a );
sc_bv_base& oper ator = ( i nt64 a );
// Bitwise rotati ons
sc_bv_base& lr otate( i nt n );
sc_bv_base& r rotate( i nt n );
// Bitwise reverse
sc_bv_base& reverse();
// Bit selecti on
sc_bi tref

< sc_bv_base> oper ator [] ( i nt i );


sc_bi tref_r

< sc_bv_base> oper ator [] ( i nt i ) const;


// Part selection
sc_subr ef

< sc_bv_base> oper ator () ( i nt hi , int lo );


sc_subr ef_r

<sc_bv_base> oper ator () ( i nt hi , int lo ) const;


sc_subr ef

< sc_bv_base> r ange( i nt hi , int l o );


sc_subr ef_r

<sc_bv_base> r ange( i nt hi , int l o ) const;


// Reduce f unctions
sc_logi c_value_t and_r educe() const;
sc_logi c_value_t nand_r educe() const;
sc_logi c_value_t or _r educe() const;
sc_logi c_value_t nor_r educe() const;
sc_logi c_value_t xor_reduce() const;
sc_logi c_value_t xnor _reduce() const;
// Common methods
int length() const;
// Expl icit conversions to character stri ng
const std::string to_str ing() const;
const std::string to_str ing( sc_numrep ) const;
const std::string to_str ing( sc_numrep , bool ) const;
// Expl icit conversions
int to_int() const;
unsi gned int to_uint() const;
long to_long() const;
unsi gned long to_ulong() const;
int64 to_int64() const;
uint64 to_uint64() const;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


264
Copyright 2012 IEEE. All rights reserved.
bool is_01() const;
// Other methods
void pr int( std::ostream& os = std::cout ) const;
void scan( std::i stream& i s = std::ci n );
} ;
} // namespace sc_dt
7.9.3.3 Constraints on usage
Attempti ng to assign the sc_logic_value_t val ues hi gh-impedance or unknown to any el ement of an
sc_bv_base obj ect shall be an error.
The resul t of assigning an array of bool or an array of sc_logic to an sc_bv_base object havi ng a greater
word l ength than the number of array el ements i s undef ined.
7.9.3.4 Constructors
expl icit sc_bv_base( i nt nb = sc_length_param().l en() );
Default constructor sc_bv_base shal l create an sc_bv_base object of word length specif ied by nb
and shal l set the i ni ti al val ue of each element to l ogi c 0. This is the default constructor when nb is
not specif ied (i n whi ch case its value is set by the current l ength context).
expl icit sc_bv_base( bool a , int nb = sc_length_param().len() );
Constructor sc_bv_base shall create an sc_bv_base obj ect of word length speci fi ed by nb. I f nb is
not speci fi ed, the length shal l be set by the current l ength context. The constructor shal l set the i ni ti al
val ue of each el ement to the value of a.
sc_bv_base( const char* a );
Constructor sc_bv_base shall create an sc_bv_base obj ect with an initial value set by the stri ng a.
The word l ength shall be set to the number of characters i n the string.
sc_bv_base( const char* a , int nb );
Constructor sc_bv_base shal l create an sc_bv_base object wi th an i ni ti al val ue set by the stri ng and
word length nb. I f the number of characters i n the string does not match the val ue of nb, the initial
val ue shal l be truncated or zero extended to match the word length.
templ ate <cl ass X> sc_bv_base( const sc_subr ef_r

< X>& a );
templ ate <class T1, class T2> sc_bv_base( const sc_concr ef_r

< T1,T2>& a );
sc_bv_base( const sc_lv_base& a );
sc_bv_base( const sc_bv_base& a );
Constructor sc_bv_base shall create an sc_bv_base obj ect wi th the same word length and value as
a.
NOTEAn implementation may provide a different set of constructors to create an sc_bv_base obj ect f rom an
sc_subr ef_r

< T>, sc_concr ef_r

< T1,T2> , or sc_lv_base obj ect, for exampl e, by provi di ng a cl ass templ ate that i s used
as a common base cl ass f or all these types.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


265
Copyright 2012 IEEE. All rights reserved.
7.9.3.5 Assignment operators
Overl oaded assi gnment operators shall provide conversion f rom SystemC data types and the nati ve C++
integer representati on to sc_bv_base, usi ng truncation or zero-extension, as descri bed in 7.2.1.
7.9.3.6 Explicit type conversion
const std::string to_str ing() const;
const std::string to_str ing( sc_numrep ) const;
const std::string to_str ing( sc_numrep , bool ) const;
Member function to_str ing shal l perform the conversion to an std::str ing representati on, as
descri bed in 7.2.11. Cal li ng the to_str ing f unction wi th a si ngl e argument i s equivalent to call ing the
to_str ing functi on wi th two arguments, where the second argument i s true.
Call ing the to_str ing f unction wi th no arguments shall create a binary stri ng with a single ' 1' or ' 0'
corresponding to each bit. Thi s string shall not be prefi xed by " 0b" or a leadi ng zero.
Exampl e:
sc_bv_base B(4); // 4-bit vector
B = "0xf "; // Each bi t set to logi c 1
std::stri ng S1 = B.to_stri ng(SC_BIN,f al se); // The contents of S1 wi ll be the stri ng "01111"
std::stri ng S2 = B.to_stri ng(SC_BIN); // The contents of S2 wil l be the stri ng "0b01111"
std::stri ng S3 = B.to_stri ng(); // The contents of S3 wil l be the stri ng "1111"
bool is_01() const;
Member f unction is_01 shall always return true since an sc_bv_base object can only contai n
elements with a val ue of l ogi c 0 or l ogi c 1.
Member f uncti ons that return the integer equi val ent of the bit representation shall be provided to
satisfy the requirements of 7.2.9.
7.9.3.7 Bitwise and comparison operators
Operati ons specif ied i n Table 21 and Table 22 are permi tted. The f ollowi ng applies:
B represents an obj ect of type sc_bv_base.
Vi represents an obj ect of logic vector type sc_bv_base, sc_lv_base, sc_subr ef_r

< T> , or
sc_concr ef_r

< T1,T2> or integer type int, long, unsigned int, unsigned long, sc_signed,
sc_unsigned, sc_int_base, or sc_uint_base.
i represents an obj ect of integer type int.
A represents an array obj ect with el ements of type char , bool, or sc_logic.
The operands may al so be of any other cl ass that i s derived from those just given.
Binary bi twise operators shal l return a result wi th a word length that i s equal to the word length of the
longest operand.
The lef t shi ft operator shal l return a resul t with a word length that i s equal to the word l ength of its
sc_bv_base operand pl us the right (integer) operand. Bits added on the ri ght-hand si de of the resul t shal l be
set to zero.
The right shif t operator returns a resul t wi th a word length that is equal to the word l ength of its sc_bv_base
operand. Bits added on the l ef t-hand side of the resul t shall be set to zero.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


266
Copyright 2012 IEEE. All rights reserved.
I t is an error i f the ri ght operand of a shif t operator i s negative.
sc_bv_base& lr otate( i nt n );
Member f uncti on lr otate shall rotate an sc_bv_base obj ect n places to the l eft.
Table 21sc_bv_base bitwise operations
Expr ession Retur n type Oper ation
B & Vi const sc_l v_base sc_bv_base bi twi se and
Vi & B const sc_l v_base sc_bv_base bi twi se and
B & A const sc_l v_base sc_bv_base bi twi se and
A & B const sc_l v_base sc_bv_base bi twi se and
B & = Vi sc_bv_base& sc_bv_base assi gn bi twi se and
B & = A sc_bv_base& sc_bv_base assi gn bi twi se and
B | Vi const sc_l v_base sc_bv_base bi twi se or
Vi | B const sc_l v_base sc_bv_base bi twi se or
B | A const sc_l v_base sc_bv_base bi twi se or
A | B const sc_l v_base sc_bv_base bi twi se or
B |= Vi sc_bv_base& sc_bv_base assi gn bi twi se or
B |= A sc_bv_base& sc_bv_base assi gn bi twi se or
B ^ Vi const sc_l v_base sc_bv_base bi twi se excl usi ve or
Vi ^ B const sc_l v_base sc_bv_base bi twi se excl usi ve or
B ^ A const sc_l v_base sc_bv_base bi twi se excl usi ve or
A ^ B const sc_l v_base sc_bv_base bi twi se excl usi ve or
B ^= Vi sc_bv_base& sc_bv_base assi gn bi twi se excl usi ve or
B ^= A sc_bv_base& sc_bv_base assi gn bi twi se excl usi ve or
B << i const sc_l v_base sc_bv_base lef t-shif t
B <<= i sc_bv_base& sc_bv_base assi gn l ef t-shif t
B >> i const sc_l v_base sc_bv_base ri ght-shi f t
B >>= i sc_bv_base& sc_bv_base assign ri ght-shi f t
~B const sc_l v_base sc_bv_base bi twi se compl ement
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


267
Copyright 2012 IEEE. All rights reserved.
sc_bv_base& r rotate( i nt n );
Member f uncti on r rotate shal l rotate an sc_bv_base obj ect n places to the ri ght.
sc_bv_base& reverse();
Member f uncti on reverse shall reverse the bi t order in an sc_bv_base object.
NOTEAn implementation is required to supply overloaded operators on sc_bv_base objects to sati sf y the
requi rements of thi s subclause. I t i s unspeci f ied whether these operators are members of sc_bv_base, gl obal operators,
or provi ded i n some other way.
7.9.3.8 Other member functions
void scan( std::i stream& i s = std::ci n );
Member functi on scan shall set the value by reading the next formatted character stri ng from the
specif ied input stream (see 7.2.10).
void pr int( std::ostream& os = std::cout ) const;
Member f uncti on pr int shal l write the val ue as a f ormatted character string to the specif ied output
stream (see 7.2.10).
int length() const;
Member f uncti on length shall return the word length (see 7.2.4).
7.9.4 sc_lv_base
7.9.4.1 Description
Cl ass sc_lv_base represents a fini te word-length bi t vector. It can be treated as an array of sc_logic_value_t
val ues. The word l ength shall be speci fi ed by a constructor argument or, by default, by the length context
object currently i n scope. The word length of an sc_lv_base object shall be fi xed duri ng instantiati on and
shall not subsequently be changed.
sc_lv_base is the base cl ass for the sc_lv class templ ate.
7.9.4.2 Class definition
namespace sc_dt {
class sc_lv_base
Table 22sc_bv_base comparison operations
Expr ession Retur n type Oper ation
B == Vi bool test equal
Vi == B bool test equal
B == A bool test equal
A == B bool test equal
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


268
Copyright 2012 IEEE. All rights reserved.
{
f riend cl ass sc_bv_base;
publ ic:
// Constructors
expl icit sc_lv_base( i nt l ength_ = sc_length_param().len() );
expl icit sc_lv_base( const sc_logic& a, int l ength_ = sc_length_param().len() );
sc_lv_base( const char* a );
sc_lv_base( const char* a , i nt l ength_ );
templ ate <cl ass X>
sc_lv_base( const sc_subr ef_r

< X>& a );
templ ate <class T1, class T2>
sc_lv_base( const sc_concr ef_r

<T1,T2>& a );
sc_lv_base( const sc_bv_base& a );
sc_lv_base( const sc_lv_base& a );
// Destructor
virtual ~sc_lv_base();
// Assi gnment operators
templ ate <cl ass X>
sc_l v_base& oper ator = ( const sc_subr ef_r

< X> & a );


templ ate <class T1, class T2>
sc_l v_base& oper ator = ( const sc_concr ef_r

< T1,T2>& a );
sc_l v_base& oper ator = ( const sc_bv_base& a );
sc_l v_base& oper ator = ( const sc_lv_base& a );
sc_l v_base& oper ator = ( const char* a );
sc_l v_base& oper ator = ( const bool* a );
sc_lv_base& oper ator = ( const sc_logic* a );
sc_l v_base& oper ator = ( const sc_unsigned& a );
sc_l v_base& oper ator = ( const sc_si gned& a );
sc_l v_base& oper ator = ( const sc_ui nt_base& a );
sc_l v_base& oper ator = ( const sc_int_base& a );
sc_l v_base& oper ator = ( unsi gned long a );
sc_l v_base& oper ator = ( l ong a );
sc_l v_base& oper ator = ( unsi gned int a );
sc_l v_base& oper ator = ( i nt a );
sc_l v_base& oper ator = ( uint64 a );
sc_l v_base& oper ator = ( i nt64 a );
// Bitwise rotati ons
sc_l v_base& lr otate( i nt n );
sc_l v_base& r rotate( i nt n );
// Bitwise reverse
sc_l v_base& reverse();
// Bit selecti on
sc_bi tref

< sc_bv_base> oper ator [] ( i nt i );


sc_bi tref_r

< sc_bv_base> oper ator [] ( i nt i ) const;


// Part selection
sc_subr ef

< sc_l v_base> oper ator () ( i nt hi , int lo );


sc_subr ef_r

< sc_l v_base> oper ator () ( i nt hi , int lo ) const;


IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


269
Copyright 2012 IEEE. All rights reserved.
sc_subr ef

< sc_l v_base> r ange( i nt h i, int l o );


sc_subr ef_r

<sc_l v_base> r ange( i nt hi , int l o ) const;


// Reduce f unctions
sc_logi c_value_t and_r educe() const;
sc_logi c_value_t nand_r educe() const;
sc_logi c_value_t or _r educe() const;
sc_logi c_value_t nor_r educe() const;
sc_logi c_value_t xor_reduce() const;
sc_logi c_value_t xnor _reduce() const;
// Common methods
int length() const;
// Expl icit conversions to character stri ng
const std::string to_str ing() const;
const std::string to_str ing( sc_numrep ) const;
const std::string to_str ing( sc_numrep , bool ) const;
// Expl icit conversions
int to_int() const;
unsi gned int to_uint() const;
long to_long() const;
unsi gned long to_ulong() const;
int64 to_int64() const;
uint64 to_uint64() const;
bool is_01() const;
// Other methods
void pr int( std::ostream& os = std::cout ) const;
void scan( std::i stream& i s = std::ci n );
} ;
} // namespace sc_dt
7.9.4.3 Constraints on usage
The resul t of assi gni ng an array of bool or an array of sc_logic to an sc_lv_base object having a greater word
length than the number of array el ements is undef ined.
7.9.4.4 Constructors
expl icit sc_lv_base( i nt nb = sc_length_param().l en() );
Constructor sc_lv_base shall create an sc_lv_base obj ect of word length specif ied by nb and shal l
set the i nitial value of each element to l ogi c 0. This i s the def aul t constructor when nb i s not
specif ied (i n whi ch case its val ue shal l be set by the current length context).
expl icit sc_lv_base( bool a, int nb = sc_length_param().len() );
Constructor sc_lv_base shall create an sc_lv_base obj ect of word length specif ied by nb and shal l
set the initial value of each element to the val ue of a. I f nb i s not specif ied, the l ength shal l be set by
the current l ength context.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


270
Copyright 2012 IEEE. All rights reserved.
sc_lv_base( const char* a);
Constructor sc_l v_base shall createan sc_l v_base obj ect wi th an i nitial val ueset by thestri ng li teral
a. Thewordl engthshal l beset tothenumber of charactersi n thestri ng l iteral .
sc_lv_base( const char* a, int nb );
Constructor sc_l v_base shall createan sc_l v_base obj ect wi th an i nitial val ueset by thestri ng li teral
and word length nb. If thenumber of characters in thestri ng l iteral does not match thevalueof nb,
theini ti al valueshall betruncated or zero extendedto matchthewordl ength.
templ ate<cl assX> sc_l v_base( const sc_subr ef_r

< X> & a);


templ ate<classT1, classT2> sc_l v_base( const sc_concr ef_r

< T1,T2> & a);


sc_l v_base( const sc_bv_base& a);
Constructor sc_l v_base shall createansc_l v_base obj ect wi th thesameword l engthandvalueasa.
sc_l v_base( const sc_l v_base& a);
Constructor sc_l v_base shall createansc_l v_base obj ect wi th thesameword l engthandvalueasa.
NOTEAn implementation may provide a different set of constructors to create an sc_lv_base object from an
sc_subr ef_r

< T>, sc_concr ef_r

, or sc_bv_base object, for example, by providing a class template that is used as a


common baseclass for all thesetypes.
7.9.4.5 Assignment operators
Overl oaded assi gnment operators shall provide conversion from SystemC data types and the nati ve C++
integer representati ontosc_l v_base, usi ng truncation or zero-extension, asdescri bed in 7.2.1.
7.9.4.6 Explicit type conversion
const std::string to_str ing() const;
const std::string to_str ing( sc_numrep) const;
const std::string to_str ing( sc_numrep, bool ) const;
Member functi on to_str ing shall performaconversi onto anstd::str ing representati on, asdescri bed
in 7.2.11. Call ing theto_str ing function wi th asi ngl eargument i sequivalent to call ing theto_str ing
functi on with two arguments, where the second argument is true. Attempting to call the si ngl e or
doubl eargument to_str ing functi on for an sc_l v_base object with one or more elementsset to the
high-i mpedanceor unknown stateshal l bean error.
Call ing theto_str ing function with no arguments shall createa logic val ue stri ng wi th asingle '1',
'0' , 'Z ', or 'X ' corresponding to each bi t. Thisstring shal l not beprefi xed by " 0b" or al eading zero.
Exampl e:
sc_lv_baseL(4); // 4-bit vector
L = "0xf"; // Each bi t set to logic 1
std::stri ngS1 = L.to_stri ng(SC_BIN,fal se); // Thecontentsof S1 wil l bethestring "01111"
std::stri ngS2 = L.to_stri ng(SC_BIN); // Thecontentsof S2 wil l bethestring "0b01111"
std::stri ngS3 = L.to_stri ng(); // Thecontentsof S3 wil l bethestri ng "1111"
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


271
Copyright 2012 IEEE. All rights reserved.
bool is_01() const;
Member f uncti on is_01 shall return true onl y when every element of an sc_lv_base obj ect has a
val ue of l ogi c 0 or l ogic 1. If any element has the val ue hi gh-impedance or unknown, it shal l return
false.
Member f uncti ons that return the integer equi val ent of the bit representation shall be provided to
satisfy the requirements of 7.2.9. Call ing any such integer conversi on function f or an obj ect havi ng
one or more bi ts set to the hi gh-impedance or unknown state shal l be an error.
7.9.4.7 Bitwise and comparison operators
Operati ons specif ied i n Table 23 and Table 24 are permi tted. The f ollowi ng applies:
L represents an obj ect of type sc_lv_base.
Vi represents an obj ect of logic vector type sc_bv_base, sc_lv_base, sc_subr ef_r

< T> , or
sc_concr ef_r

< T1,T2>, or integer type int, long, unsigned int, unsigned long, sc_signed,
sc_unsigned, sc_int_base, or sc_uint_base.
i represents an obj ect of integer type int.
A represents an array obj ect with el ements of type char , bool, or sc_logic.
The operands may al so be of any other cl ass that i s derived from those just given.
Binary bi twise operators shal l return a result wi th a word length that i s equal to the word length of the
longest operand.
The lef t shi ft operator shal l return a resul t with a word length that i s equal to the word l ength of its
sc_lv_base operand plus the right (i nteger) operand. Bi ts added on the ri ght-hand si de of the resul t shall be
set to zero.
The ri ght shi ft operator shal l return a resul t wi th a word length that i s equal to the word length of i ts
sc_lv_base operand. Bits added on the l eft-hand side of the result shall be set to zero.
I t is an error i f the ri ght operand of a shif t operator i s negative.
sc_l v_base& lr otate( i nt n );
Member f uncti on lr otate shall rotate an sc_lv_base obj ect n places to the left.
sc_l v_base& r rotate( i nt n );
Member f uncti on r rotate shal l rotate an sc_lv_base object n places to the ri ght.
sc_l v_base& reverse();
Member f uncti on reverse shall reverse the bi t order in an sc_lv_base obj ect.
NOTEAn implementation i s requi red to suppl y overl oaded operators on sc_lv_base obj ects to sati sf y the
requi rements of this subcl ause. I t i s unspeci f i ed whether these operators are members of sc_lv_base, gl obal operators, or
provi ded i n some other way.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


272
Copyright 2012 IEEE. All rights reserved.
Table 23sc_lv_base bitwise operations
Expr ession Retur n type Oper ation
L & Vi const sc_l v_base sc_l v_base bi twi se and
Vi & L const sc_l v_base sc_l v_base bi twi se and
L & A const sc_l v_base sc_l v_base bi twi se and
A & L const sc_l v_base sc_l v_base bi twi se and
L & = Vi sc_l v_base& sc_l v_base assign bi twi se and
L & = A sc_l v_base& sc_l v_base assign bi twi se and
L | Vi const sc_l v_base sc_l v_base bitwi se or
Vi | L const sc_l v_base sc_l v_base bitwi se or
L | A const sc_l v_base sc_l v_base bi twi se or
A | L const sc_l v_base sc_l v_base bi twi se or
L |= Vi sc_l v_base& sc_l v_base assi gn bi twi se or
L |= A sc_l v_base& sc_l v_base assi gn bi twi se or
L ^ Vi const sc_l v_base sc_l v_base bi twi se excl usi ve or
Vi ^ L const sc_l v_base sc_l v_base bi twi se excl usi ve or
L ^ A const sc_l v_base sc_l v_base bi twi se excl usi ve or
A ^ L const sc_l v_base sc_l v_base bi twi se excl usi ve or
L ^= Vi sc_l v_base& sc_l v_base assign bi twi se excl usi ve or
L ^= A sc_l v_base& sc_l v_base assign bi twi se excl usi ve or
L << i const sc_l v_base sc_l v_base l eft-shi f t
L <<= i sc_l v_base& sc_l v_base assi gn l ef t-shi ft
L >> i const sc_l v_base sc_l v_base ri ght-shif t
L >>= i sc_l v_base& sc_l v_base assi gn ri ght-shi ft
~L const sc_l v_base sc_l v_base bi twi se complement
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


273
Copyright 2012 IEEE. All rights reserved.
7.9.4.8 Other member functions
void scan( std::i stream& i s = std::ci n );
Member functi on scan shall set the value by reading the next formatted character stri ng from the
specif ied input stream (see 7.2.10).
void pr int( std::ostream& os = std::cout ) const;
Member f uncti on pr int shal l write the val ue as a f ormatted character string to the specif ied output
stream (see 7.2.10).
int length() const;
Member f uncti on length shall return the word length (see 7.2.4).
7.9.5 sc_bv
7.9.5.1 Description
Class template sc_bv represents a f inite word-l ength bi t vector. I t can be treated as an array of bool or as an
array of sc_logic_value_t values (wi th the restricti on that onl y the states l ogi c 0 and logic 1 are legal ). The
word l ength shal l be speci fi ed by a templ ate argument.
Any publ ic member functi ons of the base cl ass sc_bv_base that are overridden in class sc_bv shal l have the
same behavior in the two cl asses. Any publ ic member f uncti ons of the base class not overridden i n this way
shall be publi cl y i nherited by cl ass sc_bv.
7.9.5.2 Class definition
namespace sc_dt {
templ ate <i nt W>
class sc_bv
: publi c sc_bv_base
{
publ ic:
// Constructors
sc_bv();
expl icit sc_bv( bool i nit_value );
expl icit sc_bv( char ini t_val ue );
sc_bv( const char* a );
Table 24sc_lv_base comparison operations
Expr ession Retur n type Oper ation
L == Vi bool test equal
Vi == L bool test equal
L == A bool test equal
A == L bool test equal
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


274
Copyright 2012 IEEE. All rights reserved.
sc_bv( const bool* a );
sc_bv( const sc_logic* a );
sc_bv( const sc_unsigned& a );
sc_bv( const sc_si gned& a );
sc_bv( const sc_uint_base& a );
sc_bv( const sc_int_base& a );
sc_bv( unsigned long a );
sc_bv( l ong a );
sc_bv( unsigned i nt a );
sc_bv( i nt a );
sc_bv( ui nt64 a );
sc_bv( i nt64 a );
templ ate <cl ass X>
sc_bv( const sc_subr ef_r

< X> & a );


templ ate <class T1, class T2>
sc_bv( const sc_concr ef_r

< T1,T2> & a );


sc_bv( const sc_bv_base& a );
sc_bv( const sc_lv_base& a );
sc_bv( const sc_bv<W>& a );
// Assi gnment operators
templ ate <cl ass X>
sc_bv<W>& oper ator = ( const sc_subr ef_r

< X>& a );
templ ate <class T1, class T2>
sc_bv<W>& oper ator = ( const sc_concr ef_r

< T1,T2>& a );
sc_bv<W>& oper ator = ( const sc_bv_base& a );
sc_bv<W>& oper ator = ( const sc_lv_base& a );
sc_bv<W>& oper ator = ( const sc_bv<W>& a );
sc_bv<W>& oper ator = ( const char* a );
sc_bv<W>& oper ator = ( const bool* a );
sc_bv<W>& oper ator = ( const sc_logic* a );
sc_bv<W>& oper ator = ( const sc_unsigned& a );
sc_bv<W>& oper ator = ( const sc_si gned& a );
sc_bv<W>& oper ator = ( const sc_ui nt_base& a );
sc_bv<W>& oper ator = ( const sc_int_base& a );
sc_bv<W>& oper ator = ( unsi gned long a );
sc_bv<W>& oper ator = ( l ong a );
sc_bv<W>& oper ator = ( unsi gned int a );
sc_bv<W>& oper ator = ( i nt a );
sc_bv<W>& oper ator = ( uint64 a );
sc_bv<W>& oper ator = ( i nt64 a );
} ;
} // namespace sc_dt
7.9.5.3 Constraints on usage
Attempti ng to assign the sc_logic_value_t val ues hi gh-impedance or unknown to any el ement of an sc_bv
object shall be an error.
The result of assigning an array of bool or an array of sc_logic to an sc_bv obj ect havi ng a greater word
length than the number of array el ements is undef ined.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


275
Copyright 2012 IEEE. All rights reserved.
7.9.5.4 Constructors
sc_bv();
The def aul t constructor sc_bv shal l create an sc_bv object of word length specif ied by the template
argument W, and it shall set the i ni ti al val ue of every el ement to logic 0.
The other constructors shall create an sc_bv object of word length speci fi ed by the templ ate argument W
and value correspondi ng to the constructor argument. If the word length of a data type or stri ng l iteral
argument di ff ers f rom the template argument, truncati on or zero-extensi on shal l be appli ed, as described i n
7.2.1. I f the number of elements in an array of bool or array of sc_logic used as the constructor argument i s
less than the word length, the initial value of al l el ements shall be undef ined.
NOTEAn implementation may provide a di f f erent set of constructors to create an sc_bv obj ect f rom an
sc_subr ef_r

< T>, sc_concr ef_r

< T1,T2>, sc_bv_base, or sc_lv_base obj ect, for example, by provi ding a cl ass
templ ate that i s used as a common base cl ass f or al l these types.
7.9.5.5 Assignment operators
Overl oaded assi gnment operators shall provide conversion f rom SystemC data types and the nati ve C++
integer representati on to sc_bv, usi ng truncation or zero-extension, as descri bed i n 7.2.1. The excepti on is
assignment of an array of bool or an array of sc_logic to an sc_bv object, as descri bed in 7.9.5.4.
7.9.6 sc_lv
7.9.6.1 Description
Class template sc_lv represents a f inite word-l ength bi t vector. I t can be treated as an array of
sc_logic_value_t val ues. The word l ength shal l be specif ied by a template argument.
Any publi c member functions of the base cl ass sc_lv_base that are overri dden in cl ass sc_lv shall have the
same behavior in the two cl asses. Any publ ic member f uncti ons of the base class not overridden i n this way
shall be publi cl y i nherited by cl ass sc_lv.
7.9.6.2 Class definition
namespace sc_dt {
templ ate <i nt W>
class sc_lv
: publi c sc_l v_base
{
publ ic:
// Constructors
sc_lv();
expl icit sc_lv( const sc_logic& i ni t_value );
expl icit sc_lv( bool i ni t_value );
expl icit sc_lv( char ini t_val ue );
sc_lv( const char* a );
sc_lv( const bool * a );
sc_lv( const sc_logic* a );
sc_lv( const sc_unsi gned& a );
sc_lv( const sc_si gned& a );
sc_lv( const sc_uint_base& a );
sc_lv( const sc_int_base& a );
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


276
Copyright 2012 IEEE. All rights reserved.
sc_lv( unsigned l ong a );
sc_lv( l ong a );
sc_lv( unsigned i nt a );
sc_lv( i nt a );
sc_lv( ui nt64 a );
sc_lv( i nt64 a );
templ ate <cl ass X>
sc_lv( const sc_subr ef_r

< X>& a );
template <class T1, cl ass T2>
sc_lv( const sc_concr ef_r

< T1,T2>& a );
sc_lv( const sc_bv_base& a );
sc_lv( const sc_lv_base& a );
sc_lv( const sc_lv<W>& a );
// Assi gnment operators
templ ate <cl ass X>
sc_lv<W>& oper ator = ( const sc_subr ef_r

< X> & a );


template <class T1, cl ass T2>
sc_lv<W>& oper ator = ( const sc_concr ef_r

< T1,T2> & a );


sc_lv<W>& oper ator = ( const sc_bv_base& a );
sc_lv<W>& oper ator = ( const sc_lv_base& a );
sc_lv<W>& oper ator = ( const sc_lv<W>& a );
sc_lv<W>& oper ator = ( const char* a );
sc_lv<W>& oper ator = ( const bool* a );
sc_lv<W>& oper ator = ( const sc_logic* a );
sc_l v<W>& oper ator = ( const sc_unsigned& a );
sc_lv<W>& oper ator = ( const sc_si gned& a );
sc_lv<W>& oper ator = ( const sc_ui nt_base& a );
sc_lv<W>& oper ator = ( const sc_int_base& a );
sc_lv<W>& oper ator = ( unsi gned long a );
sc_lv<W>& oper ator = ( l ong a );
sc_lv<W>& oper ator = ( unsi gned int a );
sc_lv<W>& oper ator = ( i nt a );
sc_lv<W>& oper ator = ( uint64 a );
sc_lv<W>& oper ator = ( i nt64 a );
} ;
} // namespace sc_dt
7.9.6.3 Constraints on usage
The result of assigning an array of bool or an array of sc_logic to an sc_lv obj ect having a greater word
length than the number of array el ements is undef ined.
7.9.6.4 Constructors
sc_lv();
Default constructor sc_lv shal l create an sc_lv object of word length specif ied by the template
argument W and shal l set the i nitial value of every element to unknown.
The other constructors shall create an sc_lv obj ect of word l ength specifi ed by the templ ate argument W and
val ue corresponding to the constructor argument. If the word l ength of a data type or string li teral argument
dif fers f rom the templ ate argument, truncati on or zero-extension shall be appl ied, as described in 7.2.1. If
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


277
Copyright 2012 IEEE. All rights reserved.
the number of elements in an array of bool or array of sc_logic used as the constructor argument is less than
the word length, the initial value of all el ements shall be undef ined.
NOTEAn implementation may provide a different set of constructors to create an sc_lv obj ect f rom an
sc_subr ef_r

< T>, sc_concr ef_r

< T1,T2>, sc_bv_base, or sc_lv_base obj ect, for example, by provi ding a cl ass
templ ate that i s used as a common base cl ass f or al l these types.
7.9.6.5 Assignment operators
Overl oaded assi gnment operators shall provide conversion f rom SystemC data types and the nati ve C++
integer representation to sc_lv, using truncation or zero-extensi on, as described in 7.2.1. The excepti on is
assignment f rom an array of bool or an array of sc_logic to an sc_lv obj ect, as descri bed in 7.9.6.4.
7.9.7 Bit-selects
7.9.7.1 Description
Class template sc_bi tref_r

< T> represents a bit selected f rom a vector used as an rvalue.


Class template sc_bi tref

< T> represents a bit selected f rom a vector used as an l value.


The use of the term vector here includes part-selects and concatenati ons of bi t vectors and l ogi c vectors.
The templ ate parameter is the name of the cl ass accessed by the bi t-select.
7.9.7.2 Class definition
namespace sc_dt {
templ ate <class T>
class sc_bi tref_r

{
f riend cl ass sc_bv_base;
f riend cl ass sc_lv_base;
publ ic:
// Copy constructor
sc_bi tref_r

( const sc_bi tref_r

< T>& a );
// Bitwise compl ement
const sc_l ogi c oper ator ~ () const;
// Impl icit conversi on to sc_logic
oper ator const sc_logic() const;
// Expl icit conversions
bool is_01() const;
bool to_bool() const;
char to_char() const;
// Common methods
int length() const;
// Other methods
void pr int( std::ostream& os = std::cout ) const;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


278
Copyright 2012 IEEE. All rights reserved.
pri vate:
// Di sabl ed
sc_bi tref_r

();
sc_bi tref_r

< T> & oper ator = ( const sc_bi tref_r

< T> & );


} ;
// -------------------------------------------------------------
templ ate <class T>
class sc_bi tref

: publi c sc_bi tref_r

< T>
{
f riend cl ass sc_bv_base;
f riend cl ass sc_lv_base;
publ ic:
// Copy constructor
sc_bi tref

( const sc_bi tref

< T>& a );
// Assi gnment operators
sc_bi tref

< T>& oper ator = ( const sc_bi tref_r

< T>& a );
sc_bi tref

< T>& oper ator = ( const sc_bi tref

< T> & a );


sc_bi tref

< T>& oper ator = ( const sc_logic& a );


sc_bi tref

< T>& oper ator = ( sc_l ogic_value_t v );


sc_bi tref

< T>& oper ator = ( bool a );


sc_bi tref

< T>& oper ator = ( char a );


sc_bi tref

< T>& oper ator = ( i nt a );


// Bitwise assi gnment operators
sc_bi tref

< T>& oper ator & = ( const sc_bi tref_r

< T>& a );
sc_bi tref

< T>& oper ator & = ( const sc_logic& a );


sc_bi tref

< T>& oper ator & = ( sc_l ogic_value_t v );


sc_bi tref

< T>& oper ator & = ( bool a );


sc_bi tref

< T>& oper ator & = ( char a );


sc_bi tref

< T>& oper ator & = ( i nt a );


sc_bi tref

< T>& oper ator |= ( const sc_bi tref_r

< T>& a );
sc_bi tref

< T>& oper ator |= ( const sc_logic& a );


sc_bi tref

< T>& oper ator |= ( sc_l ogi c_value_t v );


sc_bi tref

< T>& oper ator |= ( bool a );


sc_bi tref

< T>& oper ator |= ( char a );


sc_bi tref

< T>& oper ator |= ( i nt a );


sc_bi tref

< T>& oper ator ^= ( const sc_bi tref_r

< T>& a );
sc_bi tref

< T>& oper ator ^= ( const sc_logic& a );


sc_bi tref

< T>& oper ator ^= ( sc_l ogic_value_t v );


sc_bi tref

< T>& oper ator ^= ( bool a );


sc_bi tref

< T>& oper ator ^= ( char a );


sc_bi tref

< T>& oper ator ^= ( i nt a );


// Other methods
voi d scan( std::i stream& i s = std::ci n );
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


279
Copyright 2012 IEEE. All rights reserved.
pri vate:
// Di sabl ed
sc_bitref();
} ;
} // namespace sc_dt
7.9.7.3 Constraints on usage
Bi t-select objects shal l only be created using the bit-select operators of an sc_bv_base or sc_lv_base object
(or an instance of a class deri ved f rom sc_bv_base or sc_lv_base) or a part-select or concatenation thereof,
as described i n 7.2.6.
An appl ication shall not expli citl y create an i nstance of any bi t-sel ect class.
An appl ication should not decl are a reference or pointer to any bit-sel ect obj ect.
I t is strongly recommended that an appl ication avoi d the use of a bi t-sel ect as the return type of a f unction
because the l if etime of the obj ect to whi ch the bi t-select ref ers may not extend beyond the f uncti on return
statement.
Exampl e:
sc_dt::sc_bi tref <sc_bv_base> get_bit_n(sc_bv_base bv, i nt n) {
return bv[ n]; // Unsaf e: returned bit-select references local variable
}
7.9.7.4 Assignment operators
Overl oaded assignment operators for the lval ue bit-select shall provide conversi on to sc_logic_value_t
val ues. The assi gnment operator for the rvalue bit-sel ect shal l be declared as private to prevent i ts use by an
appl ication.
7.9.7.5 Implicit type conversion
oper ator const sc_logic() const;
Operator sc_logic shal l create an sc_logic object with the same value as the bit-sel ect.
7.9.7.6 Explicit type conversion
char to_char() const;
Member f uncti on to_char shall convert the bi t-select val ue to the char equi val ent.
bool to_bool() const;
Member function to_bool shall convert the bit-select value to false or true. I t shall be an error to call
thi s f unction i f the sc_logic val ue i s not l ogi c 0 or l ogi c 1.
bool is_01() const;
Member functi on is_01 shall return true i f the sc_logic value i s logic 0 or logic 1; otherwi se, the
return val ue shal l be false.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


280
Copyright 2012 IEEE. All rights reserved.
7.9.7.7 Bitwise and comparison operators
Operati ons specif ied i n Tabl e 25 are permitted. The foll owing appl ies:
B represents an obj ect of type sc_bi tref_r

< T> (or any derived cl ass).


NOTEAn implementation is required to suppl y overl oaded operators on sc_bi tr ef_r

< T> obj ects to sati sf y the


requi rements of thi s subcl ause. I t i s unspeci f i ed whether these operators are members of sc_bi tr ef_r

< T> , gl obal


operators, or provi ded in some other way.
7.9.7.8 Other member functions
void scan( std::i stream& i s = std::ci n );
Member f unction scan shal l set the value of the bit referenced by an lvalue bit-sel ect. The val ue
shal l correspond to the C++ bool val ue obtai ned by reading the next formatted character string from
the specif ied i nput stream (see 7.2.10).
void pr int( std::ostream& os = std::cout ) const;
Member function pr int shal l print the value of the bi t referenced by the bi t-select to the speci fi ed
output stream (see 7.2.10). The formatti ng shal l be i mplementati on-defi ned but shall be equi val ent
to pri nti ng the val ue returned by member functi on to_bool.
int length() const;
Member f uncti on length shall unconditi onal ly return a word l ength of 1 (see 7.2.4).
7.9.8 Part-selects
7.9.8.1 Description
Class template sc_subr ef_r

< T> represents a part-select f rom a vector used as an rvalue.


Class template sc_subr ef

< T> represents a part-sel ect f rom a vector used as an lvalue.


The use of the term vector here includes part-selects and concatenati ons of bi t vectors and l ogi c vectors.
The templ ate parameter is the name of the class accessed by the part-sel ect.
Table 25sc_bitref_r

<T> bitwise and comparison operations


Expr ession Retur n type Oper ation
B & B const sc_l ogi c sc_bi tr ef_r

< T> bi twi se and


B | B const sc_l ogi c sc_bi tr ef_r

< T> bi twi se or


B ^ B const sc_l ogic sc_bi tr ef_r

< T> bi twi se excl usi ve or


B == B bool test equal
B ! = B bool test not equal
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


281
Copyright 2012 IEEE. All rights reserved.
The set of operations that can be perf ormed on a part-select shall be i dentical to that of i ts associated vector
(subject to the constrai nts that appl y to rvalue objects).
7.9.8.2 Class definition
namespace sc_dt {
templ ate <class T>
class sc_subr ef_r

{
publ ic:
// Copy constructor
sc_subr ef_r

( const sc_subr ef_r

< T>& a );
// Bit selecti on
sc_bi tref_r

<sc_subr ef_r

< T> > oper ator [] ( i nt i ) const;


// Part selection
sc_subr ef_r

< sc_subref_r

< T> > oper ator () ( i nt hi , int l o ) const;


sc_subr ef_r

< sc_subref_r

< T> > r ange( i nt hi , int lo ) const;


// Reduce f unctions
sc_logi c_value_t and_r educe() const;
sc_logi c_value_t nand_r educe() const;
sc_logi c_value_t or _r educe() const;
sc_logi c_value_t nor_r educe() const;
sc_logi c_value_t xor_reduce() const;
sc_logi c_value_t xnor _reduce() const;
// Common methods
int length() const;
// Expl icit conversions to character stri ng
const std::string to_str ing() const;
const std::string to_str ing( sc_numrep ) const;
const std::string to_str ing( sc_numrep , bool ) const;
// Expl icit conversions
int to_int() const;
unsi gned int to_uint() const;
long to_long() const;
unsi gned long to_ulong() const;
int64 to_int64() const;
uint64 to_uint64() const;
bool is_01() const;
// Other methods
void pr int( std::ostream& os = std::cout ) const;
bool reversed() const;
pri vate:
// Di sabl ed
sc_subr ef_r

();
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


282
Copyright 2012 IEEE. All rights reserved.
sc_subr ef_r

< T>& oper ator = ( const sc_subr ef_r

< T>& );
} ;
// -------------------------------------------------------------
templ ate <class T>
class sc_subr ef

: publi c sc_subr ef_r

< T>
{
publ ic:
// Copy constructor
sc_subr ef

( const sc_subr ef

< T>& a );
// Assi gnment operators
templ ate <class T>
sc_subr ef

< T>& oper ator = ( const sc_subr ef_r

< T> & a );


templ ate <class T1, class T2>
sc_subr ef

< T>& oper ator = ( const sc_concr ef_r

< T1,T2>& a );
sc_subr ef

< T>& oper ator = ( const sc_bv_base& a );


sc_subr ef

< T>& oper ator = ( const sc_lv_base& a );


sc_subr ef

< T>& oper ator = ( const sc_subr ef_r

< T> & a );


sc_subr ef

< T>& oper ator = ( const sc_subr ef

< T>& a );
sc_subr ef

< T>& oper ator = ( const char* a );


sc_subr ef

< T>& oper ator = ( const bool* a );


sc_subr ef

< T>& oper ator = ( const sc_logic* a );


sc_subr ef

< T>& oper ator = ( const sc_unsigned& a );


sc_subr ef

< T>& oper ator = ( const sc_si gned& a );


sc_subr ef

< T>& oper ator = ( const sc_ui nt_base& a );


sc_subr ef

< T>& oper ator = ( const sc_int_base& a );


sc_subr ef

< T>& oper ator = ( unsi gned long a );


sc_subr ef

< T>& oper ator = ( l ong a );


sc_subr ef

< T>& oper ator = ( unsi gned int a );


sc_subr ef

< T>& oper ator = ( i nt a );


sc_subr ef

< T>& oper ator = ( uint64 a );


sc_subr ef

< T>& oper ator = ( i nt64 a );


// Bitwise rotati ons
sc_subr ef

< T>& lr otate( i nt n );


sc_subr ef

< T>& r rotate( i nt n );


// Bitwise reverse
sc_subr ef

< T>& reverse();


// Bit selection
sc_bi tref

< sc_subref

< T> > oper ator [] ( i nt i );


// Part selection
sc_subr ef

< sc_subref

< T> > oper ator () ( i nt hi , int lo );


sc_subr ef

< sc_subref

< T> > r ange( i nt hi , int lo );


// Other methods
void scan( std::i stream& = std::cin );
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


283
Copyright 2012 IEEE. All rights reserved.
pri vate:
// Di sabl ed
sc_subr ef

();
} ;
} // namespace sc_dt
7.9.8.3 Constraints on usage
Part-sel ect objects shall only be created using the part-select operators of an sc_bv_base or sc_lv_base
object (or an i nstance of a class derived from sc_bv_base or sc_lv_base) or a part-sel ect or concatenati on
thereof , as described in 7.2.6.
An appl ication shall not expli citl y create an i nstance of any part-select class.
An appl ication should not decl are a reference or pointer to any part-sel ect obj ect.
An rvalue part-select shal l not be used to modif y the vector wi th which it is associ ated.
I t i s strongly recommended that an appli cation avoi d the use of a part-select as the return type of a functi on
because the li feti me of the obj ect to which the part-select refers may not extend beyond the functi on return
statement.
Exampl e:
sc_dt::sc_subref<sc_bv_base> get_byte(sc_bv_base bv, i nt pos) {
return bv(pos+7,pos); // Unsafe: returned part-select ref erences l ocal vari abl e
}
7.9.8.4 Assignment operators
Overl oaded assi gnment operators shall provide conversion f rom SystemC data types and the nati ve C++
integer representation to l val ue part-selects. If the size of a data type or string l iteral operand dif fers from the
part-sel ect word l ength, truncation or zero-extensi on shall be used, as described in 7.2.1. If an array of bool
or array of sc_logic is assi gned to a part-sel ect and i ts number of elements i s less than the part-select word
length, the val ue of the part-sel ect shall be undefi ned.
The default assi gnment operator for an rvalue part-select i s pri vate to prevent its use by an appl ication.
7.9.8.5 Explicit type conversion
const std::string to_str ing() const;
const std::string to_str ing( sc_numrep ) const;
const std::string to_str ing( sc_numrep , bool ) const;
Member f unction to_str ing shal l convert to an std::str ing representation, as described i n 7.2.11.
Call ing the to_str ing f uncti on with a single argument is equi valent to call ing the to_str ing f uncti on
wi th two arguments, where the second argument i s true. Attempti ng to cal l the si ngl e or doubl e
argument to_str ing function for a part-select wi th one or more elements set to the hi gh-impedance
or unknown state shall be an error.
Call ing the to_str ing function with no arguments shall create a logic val ue stri ng wi th a single '1',
'0' , 'Z ' , or 'X ' corresponding to each bit. Thi s string shall not pref ixed by " 0b" or a leadi ng zero.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


284
Copyright 2012 IEEE. All rights reserved.
bool is_01() const;
Member f uncti on is_01 shall return true onl y when every element of a part-select has a value of
logi c 0 or logi c 1. If any el ement has the value hi gh-impedance or unknown, i t shal l return fal se.
Member f uncti ons that return the integer equi val ent of the bit representation shall be provided to
satisfy the requirements of 7.2.9. Call ing any such integer conversi on function f or an obj ect havi ng
one or more bi ts set to the hi gh-impedance or unknown state shal l be an error.
7.9.8.6 Bitwise and comparison operators
Operati ons specif ied i n Table 26 and Table 28 are permitted for al l vector part-selects. Operations specif ied
in Table 27 are permi tted for lvalue vector part-sel ects only. The f ol lowi ng applies:
P represents an lvalue or rvalue vector part-sel ect.
L represents an lvalue vector part-sel ect.
Vi represents an obj ect of logic vector type sc_bv_base, sc_l v_base, sc_subr ef_r

< T>, or
sc_concr ef_r

< T1,T2>, or i nteger type int, l ong, unsi gned int, unsi gned long, sc_signed,
sc_unsi gned, sc_i nt_base, or sc_uint_base.
i represents an obj ect of integer type int.
A represents an array obj ect with el ements of type char , bool , or sc_l ogi c.
The operands may al so be of any other cl ass that i s derived from those just given.
Table 26sc_subref_r

<T> bitwise operations


Expr ession Retur n type Oper ation
P & Vi const sc_l v_base sc_subr ef_r

< T> bi twi se and


Vi & P const sc_l v_base sc_subr ef_r

< T> bi twi se and


P & A const sc_l v_base sc_subr ef_r

< T> bi twi se and


A & P const sc_l v_base sc_subr ef_r

< T> bi twi se and


P | Vi const sc_l v_base sc_subr ef_r

< T> bi twi se or


Vi | P const sc_l v_base sc_subr ef_r

< T> bi twi se or


P | A const sc_l v_base sc_subr ef_r

< T> bi twi se or


A | P const sc_l v_base sc_subr ef_r

< T> bi twi se or


P ^ Vi const sc_l v_base sc_subr ef_r

< T> bi twi se excl usi ve or


Vi ^ P const sc_l v_base sc_subr ef_r

< T> bi twi se excl usi ve or


P ^ A const sc_l v_base sc_subr ef_r

< T> bi twi se excl usi ve or


A ^ P const sc_l v_base sc_subr ef_r

< T> bi twi se excl usi ve or


P << i const sc_l v_base sc_subr ef_r

< T> l ef t-shi f t


P >> i const sc_l v_base sc_subr ef_r

< T> ri ght-shi f t


~P const sc_l v_base sc_subr ef_r

< T> bi twi se compl ement


IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


285
Copyright 2012 IEEE. All rights reserved.
Binary bi twise operators shal l return a result wi th a word length that i s equal to the word length of the
longest operand.
The left shif t operator shal l return a result with a word length that i s equal to the word length of its part-
sel ect operand plus the right (integer) operand. Bits added on the ri ght-hand si de of the resul t shall be set to
zero.
The right shif t operator shall return a resul t wi th a word length that i s equal to the word l ength of i ts part-
sel ect operand. Bi ts added on the left-hand si de of the result shal l be set to zero.
I t is an error i f the ri ght operand of a shif t operator i s negative.
sc_subr ef

< T>& lr otate( i nt n );


Member f uncti on lr otate shall rotate an lvalue part-select n places to the left.
sc_subr ef

< T>& r rotate( i nt n );


Member f uncti on r rotate shal l rotate an lvalue part-select n pl aces to the ri ght.
Table 27sc_subref

<T> bitwise operations


Expr ession Retur n type Oper ation
L & = Vi sc_subr ef_r

< T> & sc_subr ef_r

< T> assign bi twi se and


L & = A sc_subr ef_r

< T> & sc_subr ef_r

< T> assign bi twi se and


L |= Vi sc_subr ef_r

< T> & sc_subr ef_r

< T> assi gn bi twi se or


L |= A sc_subr ef_r

< T> & sc_subr ef_r

< T> assi gn bi twi se or


L ^= Vi sc_subr ef_r

< T> & sc_subr ef_r

< T> assign bi twi se excl usi ve or


L ^= A sc_subr ef_r

< T> & sc_subr ef_r

< T> assign bi twi se excl usi ve or


L <<= i sc_subr ef_r

< T> & sc_subr ef_r

< T> assign lef t-shif t


L >>= i sc_subr ef_r

< T> & sc_subr ef_r

< T> assi gn ri ght-shi f t


Table 28sc_subref_r

<T> comparison operations


Expr ession Retur n type Oper ation
P == Vi bool test equal
Vi == P bool test equal
P == A bool test equal
A == P bool test equal
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


286
Copyright 2012 IEEE. All rights reserved.
sc_subr ef

< T>& reverse();


Member f uncti on reverse shal l reverse the bit order in an lvalue part-select.
NOTEAn implementation is required to suppl y overl oaded operators on sc_subr ef_r

< T> and sc_subr ef

< T> obj ects


to sati sf y the requirements of thi s subcl ause. I t i s unspeci f i ed whether these operators are members of sc_subr ef

< T> ,
members of sc_subr ef

< T> , global operators, or provi ded i n some other way.


7.9.8.7 Other member functions
void scan( std::i stream& i s = std::ci n );
Member function scan shal l set the values of the bi ts ref erenced by an lvalue part-select by reading
the next formatted character string from the specif ied i nput stream (see 7.2.10).
void pr int( std::ostream& os = std::cout ) const;
Member functi on pr int shall print the val ues of the bi ts referenced by the part-sel ect to the specif ied
output stream (see 7.2.10).
int length() const;
Member f uncti on length shall return the word length of the part-select (see 7.2.4).
bool reversed() const;
Member functi on rever sed shall return true if the el ements of a part-select are i n the reverse order
to those of i ts associated vector (if the lef t-hand index used to form the part-select i s l ess than the
right-hand index); otherwi se, the return value shall be false.
7.9.9 Concatenations
7.9.9.1 Description
Class templ ate sc_concr ef_r

< T1,T2> represents a concatenation of bi ts f rom one or more vector used as an


rvalue.
Class templ ate sc_concr ef

< T1,T2> represents a concatenation of bi ts from one or more vector used as an


lvalue.
The use of the term vector here includes part-selects and concatenati ons of bi t vectors and l ogi c vectors.
The template parameters are the class names of the two vectors used to create the concatenati on.
The set of operati ons that can be performed on a concatenation shal l be i denti cal to that of its associated
vectors (subj ect to the constraints that appl y to rvalue objects).
7.9.9.2 Class definition
namespace sc_dt {
templ ate <class T1, class T2>
class sc_concr ef_r

{
publ ic:
// Copy constructor
sc_concr ef_r

( const sc_concr ef_r

< T1,T2>& a );
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


287
Copyright 2012 IEEE. All rights reserved.
// Destructor
virtual ~sc_concr ef_r

();
// Bit selecti on
sc_bi tref_r

<sc_concr ef_r

< T1,T2> > oper ator [] ( i nt i ) const;


// Part sel ection
sc_subr ef_r

< sc_concr ef_r

< T1,T2> > oper ator () ( i nt hi , int l o ) const;


sc_subr ef_r

< sc_concr ef_r

< T1,T2> > r ange( i nt hi , int lo ) const;


// Reduce f unctions
sc_logi c_value_t and_r educe() const;
sc_logi c_value_t nand_r educe() const;
sc_logi c_value_t or _r educe() const;
sc_logi c_value_t nor_r educe() const;
sc_logi c_value_t xor_reduce() const;
sc_logi c_value_t xnor _reduce() const;
// Common methods
int length() const;
// Expl icit conversions to character stri ng
const std::string to_str ing() const;
const std::string to_str ing( sc_numrep ) const;
const std::string to_str ing( sc_numrep , bool ) const;
// Expl icit conversions
int to_int() const;
unsi gned int to_uint() const;
long to_long() const;
unsi gned long to_ulong() const;
int64 to_int64() const;
uint64 to_uint64() const;
bool is_01() const;
// Other methods
voi d pr int( std::ostream& os = std::cout ) const;
pri vate:
// Di sabl ed
sc_concr ef

();
sc_concr ef_r

< T1,T2>& oper ator = ( const sc_concr ef_r

< T1,T2>& );
} ;
// -------------------------------------------------------------
templ ate <class T1, class T2>
class sc_concr ef

: publi c sc_concr ef_r

<T1,T2>
{
publ ic:
// Copy constructor
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


288
Copyright 2012 IEEE. All rights reserved.
sc_concr ef

( const sc_concr ef

< T1,T2>& a );
// Assi gnment operators
templ ate <class T>
sc_concr ef

< T1,T2>& oper ator = ( const sc_subr ef_r

<T> & a );
templ ate <class T1, class T2>
sc_concr ef

< T1,T2>& oper ator = ( const sc_concr ef_r

< T1,T2>& a );
sc_concr ef

< T1,T2>& oper ator = ( const sc_bv_base& a );


sc_concr ef

< T1,T2>& oper ator = ( const sc_lv_base& a );


sc_concr ef

< T1,T2>& oper ator = ( const sc_concr ef

< T1,T2>& a );
sc_concr ef

< T1,T2>& oper ator = ( const char* a );


sc_concr ef

< T1,T2>& oper ator = ( const bool* a );


sc_concr ef

< T1,T2>& oper ator = ( const sc_logic* a );


sc_concr ef

< T1,T2>& oper ator = ( const sc_unsigned& a );


sc_concr ef

< T1,T2>& oper ator = ( const sc_si gned& a );


sc_concr ef

< T1,T2>& oper ator = ( const sc_ui nt_base& a );


sc_concr ef

< T1,T2>& oper ator = ( const sc_int_base& a );


sc_concr ef

< T1,T2>& oper ator = ( unsi gned long a );


sc_concr ef

< T1,T2>& oper ator = ( l ong a );


sc_concr ef

< T1,T2>& oper ator = ( unsi gned int a );


sc_concr ef

< T1,T2>& oper ator = ( i nt a );


sc_concr ef

< T1,T2>& oper ator = ( uint64 a );


sc_concr ef

< T1,T2>& oper ator = ( i nt64 a );


// Bitwise rotati ons
sc_concr ef

< T1,T2>& lr otate( i nt n );


sc_concr ef

< T1,T2>& r rotate( i nt n );


// Bitwise reverse
sc_concr ef

< T1,T2>& reverse();


// Bit selecti on
sc_bi tref

< sc_concr ef

<T1,T2> > oper ator [] ( i nt i );


// Part selection
sc_subr ef

< sc_concr ef

< T1,T2> > oper ator () ( i nt hi , int lo );


sc_subr ef

< sc_concr ef

< T1,T2> > r ange( i nt hi , int lo );


// Other methods
void scan( std::i stream& = std::cin );
pri vate:
// Di sabl ed
sc_concr ef

();
} ;
// r-val ue concatenation operators and functi ons
templ ate <typename C1, typename C2>
sc_concr ef_r

< C1,C2> oper ator, ( C1 , C2 );


templ ate <typename C1, typename C2>
sc_concr ef_r

< C1,C2> concat( C1 , C2 );


IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


289
Copyright 2012 IEEE. All rights reserved.
// l-val ue concatenation operators and functi ons
templ ate <typename C1, typename C2>
sc_concr ef

< C1,C2> oper ator, ( C1 , C2 );


templ ate <typename C1, typename C2>
sc_concr ef

< C1,C2> concat( C1 , C2 );


} // namespace sc_dt
7.9.9.3 Constraints on usage
Concatenati on obj ects shal l only be created usi ng the concat function (or oper ator,) accordi ng to the rules
in 7.2.7. The concatenation arguments shall be objects wi th a common concatenation base type of
sc_bv_baseor sc_lv_base(or an instance of a class derived from sc_bv_base or sc_lv_base) or a part-sel ect
or concatenation of them.
An appl ication shall not expli citl y create an instance of any concatenation class.
An appl ication should not decl are a reference or pointer to any concatenati on object.
An rvalue concatenation shall be created when any argument to the concat functi on (or oper ator,) is an
rvalue. An rvalue concatenati on shal l not be used to modif y any vector wi th which it i s associated.
I t is strongl y recommended that an applicati on avoi d the use of a concatenati on as the return type of a
f uncti on because the lif eti me of the objects to which the concatenati on refer may not extend beyond the
f uncti on return statement.
Exampl e:
sc_dt::sc_concref_r<sc_bv_base,sc_bv_base> pad(sc_bv_base& bv, char pchar) {
const sc_bv<4> padword(pchar); // Unsaf e: returned concatenation references
// a non-static local variable (padword)
return concat(bv,padword);
}
7.9.9.4 Assignment operators
Overl oaded assi gnment operators shall provide conversion f rom SystemC data types and the nati ve C++
integer representation to lvalue concatenations. If the size of a data type or string literal operand di ff ers f rom
the concatenati on word length, truncation or zero-extension shall be used, as described i n 7.2.1. If an array
of bool or array of sc_logic is assigned to a concatenation and its number of elements is less than the
concatenation word length, the value of the concatenati on shal l be undef ined.
The def ault assignment operator for an rvalue concatenation shall be declared as pri vate to prevent i ts use by
an appli cati on.
7.9.9.5 Explicit type conversion
const std::string to_str ing() const;
const std::string to_str ing( sc_numrep ) const;
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


290
Copyright 2012 IEEE. All rights reserved.
const std::string to_str ing( sc_numrep , bool ) const;
Member function to_str ing shal l perform the conversion to an std::str ing representati on, as
descri bed in 7.2.11. Cal li ng the to_str ing f unction wi th a si ngl e argument i s equivalent to call ing the
to_str ing functi on wi th two arguments, where the second argument is true. Attempti ng to call the
single or double argument to_str ing function for a concatenation with one or more elements set to
the high-i mpedance or unknown state shall be an error.
Call ing the to_str ing function with no arguments shall create a logic val ue stri ng wi th a single '1',
'0' , 'Z ', or 'X ' corresponding to each bit. This string shall not pref ixed by " 0b" or a leadi ng zero.
bool is_01() const;
Member f unction is_01 shal l return true only when every element of a concatenati on has a value of
logi c 0 or logi c 1. If any el ement has the value hi gh-impedance or unknown, i t shal l return false.
Member f uncti ons that return the integer equi val ent of the bit representation shall be provided to
satisfy the requirements of 7.2.9. Call ing any such integer conversi on function f or an obj ect havi ng
one or more bi ts set to the hi gh-impedance or unknown state shal l be an error.
7.9.9.6 Bitwise and comparison operators
Operati ons speci fi ed in Table 29 and Tabl e 31 are permitted f or al l vector concatenations; operati ons
specif ied in Tabl e 30 are permitted for l val ue vector concatenations onl y. The foll owing appli es:
C represents an lvalue or rvalue vector concatenati on.
L represents an lvalue vector concatenation.
Vi represents an obj ect of logic vector type sc_bv_base, sc_lv_base, sc_subr ef_r

< T>, or
sc_concr ef_r

< T1,T2>, or i nteger type int, long, unsigned int, unsigned long, sc_signed,
sc_unsigned, sc_int_base, or sc_uint_base.
i represents an obj ect of integer type int.
A represents an array obj ect with el ements of type char , bool, or sc_logic.
The operands may al so be of any other cl ass that i s derived from those just given.
Binary bi twise operators shal l return a result wi th a word length that i s equal to the word length of the
longest operand.
The lef t shi ft operator shal l return a resul t with a word length that i s equal to the word l ength of its
concatenation operand plus the ri ght (i nteger) operand. Bi ts added on the ri ght-hand side of the resul t shal l
be set to zero.
The ri ght shi ft operator shal l return a resul t wi th a word length that i s equal to the word length of i ts
concatenation operand. Bits added on the lef t-hand side of the resul t shal l be set to zero.
sc_concr ef

< T1,T2> & lr otate( i nt n );


Member f uncti on lr otate shall rotate an lvalue part-select n places to the left.
sc_concr ef

< T1,T2> & r rotate( i nt n );


Member f uncti on r rotate shal l rotate an lvalue part-select n pl aces to the ri ght.
sc_concr ef

< T1,T2> & reverse();


Member f uncti on reverse shal l reverse the bit order in an lvalue part-select.
IEEE Std 1666-2011
IEEE Standard for Standard SystemC

Language Reference Manual


291
Copyright 2012 IEEE. All rights reserved.
Table 29sc_concref_r

<T1,T2> bitwise operations


Expr ession Retur n type Oper ation
C & Vi const sc_l v_base sc_concr ef_r

< T1,T2> bi twi se and


Vi & C const sc_l v_base sc_concr ef_r

< T1,T2> bi twi se and


C & A const sc_l v_base sc_concr ef_r

< T1,T2> bi twi se and


A & C const sc_l v_base sc_concr ef_r

< T1,T2> bi twi se and


C | Vi const sc_l v_base sc_concr ef_r

< T1,T2> bi twi se or


Vi | C const sc_l v_base sc_concr ef_r < T1,T2> bi twi se or
C | A const sc_l v_base sc_concr ef_r < T1,T2> bi twi se or
A | C const sc_l v_base sc_concr ef_r < T1,T2> bi twi se or
C ^ Vi const sc_l v_base sc_concr ef_r < T1,T2> bi twi se excl usi ve or
Vi ^ C const sc_l v_base sc_concr ef_r < T1,T2>

bi twi se excl usi ve or
C ^ A const sc_l v_base sc_concr ef_r < T1,T2> bi twi se excl usi ve or
A ^ C const sc_l v_base sc_concr ef_r < T1,T2> bi twi se excl usi ve or
C << i const sc_l v_base sc_concr ef_r < T1,T2> l ef t-shi f t
C >> i const sc_l v_base sc_concr ef_r < T1,T2> ri ght-shi f t
~C const sc_l v_base sc_concr ef_r < T1,T2> bi twi se compl ement
Table 30sc_concref

<T1,T2> bitwise operations


Expr ession Retur n type Oper ation
L & = Vi sc_concr ef

< T1,T2>& sc_concr ef

< T1,T2> assign bi twi se and


L & = A sc_concr ef

< T1,T2>& sc_concr ef

< T1,T2> assi gn bi twi se and


L |= Vi sc_concr ef

< T1,T2>& sc_concr ef

< T1,T2> assign bi twi se or


L |= A sc_concr ef

< T1,T2>& sc_concr ef

< T1,T2> assi gn bi twi se or


L ^= Vi sc_concr ef

< T1,T2>& sc_concr ef

< T1,T2> assi gn bitwi se excl usi ve or


L ^= A sc_concr ef

< T1,T2>& sc_concr ef

< T1,T2> assign bi twi se excl usi ve or


L <<= i sc_concr ef

< T1,T2>& sc_concr ef

< T1,T2> assign l ef t-shif t


L >>= i sc_concr ef

< T1,T2>& sc_concr ef

< T1,T2> assign ri ght-shi f t


IEEE Std 1666-2011
IEEE Standard for Standard SystemC