sc_bit_proxies.hh (13138:31951157e41e) sc_bit_proxies.hh (13322:7391057615bd)
1/*****************************************************************************
2
3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4 more contributor license agreements. See the NOTICE file distributed
5 with this work for additional information regarding copyright ownership.
6 Accellera licenses this file to you under the Apache License, Version 2.0
7 (the "License"); you may not use this file except in compliance with the
8 License. You may obtain a copy of the License at

--- 17 unchanged lines hidden (view full) ---

26 CHANGE LOG AT THE END OF THE FILE
27 *****************************************************************************/
28
29#ifndef __SYSTEMC_EXT_DT_BIT_SC_BIT_PROXIES_HH__
30#define __SYSTEMC_EXT_DT_BIT_SC_BIT_PROXIES_HH__
31
32#include <iostream>
33
1/*****************************************************************************
2
3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4 more contributor license agreements. See the NOTICE file distributed
5 with this work for additional information regarding copyright ownership.
6 Accellera licenses this file to you under the Apache License, Version 2.0
7 (the "License"); you may not use this file except in compliance with the
8 License. You may obtain a copy of the License at

--- 17 unchanged lines hidden (view full) ---

26 CHANGE LOG AT THE END OF THE FILE
27 *****************************************************************************/
28
29#ifndef __SYSTEMC_EXT_DT_BIT_SC_BIT_PROXIES_HH__
30#define __SYSTEMC_EXT_DT_BIT_SC_BIT_PROXIES_HH__
31
32#include <iostream>
33
34#include "../../utils/messages.hh"
34#include "sc_proxy.hh"
35
36namespace sc_dt
37{
38
39// classes defined in this module
40template <class X, class Traits>
41class sc_bitref_conv_r;

--- 1688 unchanged lines hidden (view full) ---

1730// common methods
1731template <class T>
1732inline typename sc_bitref_r<T>::value_type
1733sc_bitref_r<T>::get_bit(int n) const
1734{
1735 if (n == 0) {
1736 return m_obj.get_bit(m_index);
1737 } else {
35#include "sc_proxy.hh"
36
37namespace sc_dt
38{
39
40// classes defined in this module
41template <class X, class Traits>
42class sc_bitref_conv_r;

--- 1688 unchanged lines hidden (view full) ---

1731// common methods
1732template <class T>
1733inline typename sc_bitref_r<T>::value_type
1734sc_bitref_r<T>::get_bit(int n) const
1735{
1736 if (n == 0) {
1737 return m_obj.get_bit(m_index);
1738 } else {
1738 SC_REPORT_ERROR("(E5) out of bounds", 0);
1739 SC_REPORT_ERROR(sc_core::SC_ID_OUT_OF_BOUNDS_, 0);
1739 return Log_0;
1740 }
1741}
1742
1743template <class T>
1744inline sc_digit
1745sc_bitref_r<T>::get_word(int n) const
1746{
1747 if (n == 0) {
1748 return (get_bit(n) & SC_DIGIT_ONE);
1749 } else {
1740 return Log_0;
1741 }
1742}
1743
1744template <class T>
1745inline sc_digit
1746sc_bitref_r<T>::get_word(int n) const
1747{
1748 if (n == 0) {
1749 return (get_bit(n) & SC_DIGIT_ONE);
1750 } else {
1750 SC_REPORT_ERROR("(E5) out of bounds", 0);
1751 SC_REPORT_ERROR(sc_core::SC_ID_OUT_OF_BOUNDS_, 0);
1751 return 0;
1752 }
1753}
1754
1755template <class T>
1756inline sc_digit
1757sc_bitref_r<T>::get_cword(int n) const
1758{
1759 if (n == 0) {
1760 return ((get_bit(n) & SC_DIGIT_TWO) >> 1);
1761 } else {
1752 return 0;
1753 }
1754}
1755
1756template <class T>
1757inline sc_digit
1758sc_bitref_r<T>::get_cword(int n) const
1759{
1760 if (n == 0) {
1761 return ((get_bit(n) & SC_DIGIT_TWO) >> 1);
1762 } else {
1762 SC_REPORT_ERROR("(E5) out of bounds", 0);
1763 SC_REPORT_ERROR(sc_core::SC_ID_OUT_OF_BOUNDS_, 0);
1763 return 0;
1764 }
1765}
1766
1767// r-value concatenation operators and functions
1768template <class T1, class T2>
1769inline sc_concref_r<sc_bitref_r<T1>, sc_bitref_r<T2> >
1770operator , (sc_bitref_r<T1> a, sc_bitref_r<T2> b)

--- 292 unchanged lines hidden (view full) ---

2063// common methods
2064template <class X>
2065inline void
2066sc_bitref<X>::set_bit(int n, value_type value)
2067{
2068 if (n == 0) {
2069 this->m_obj.set_bit(this->m_index, value);
2070 } else {
1764 return 0;
1765 }
1766}
1767
1768// r-value concatenation operators and functions
1769template <class T1, class T2>
1770inline sc_concref_r<sc_bitref_r<T1>, sc_bitref_r<T2> >
1771operator , (sc_bitref_r<T1> a, sc_bitref_r<T2> b)

--- 292 unchanged lines hidden (view full) ---

2064// common methods
2065template <class X>
2066inline void
2067sc_bitref<X>::set_bit(int n, value_type value)
2068{
2069 if (n == 0) {
2070 this->m_obj.set_bit(this->m_index, value);
2071 } else {
2071 SC_REPORT_ERROR("(E5) out of bounds", 0);
2072 SC_REPORT_ERROR(sc_core::SC_ID_OUT_OF_BOUNDS_, 0);
2072 }
2073}
2074
2075template <class X>
2076inline void
2077sc_bitref<X>::set_word(int n, sc_digit w)
2078{
2079 unsigned int bi = this->m_index % (8 * sizeof(sc_digit));
2080 sc_digit temp;
2081 unsigned int wi = this->m_index / (8 * sizeof(sc_digit));
2082 if (n == 0) {
2083 temp = this->m_obj.get_word(wi);
2084 temp = (temp & ~(1 << bi)) | ((w & 1) << bi);
2085 this->m_obj.set_word(wi, temp);
2086 } else {
2073 }
2074}
2075
2076template <class X>
2077inline void
2078sc_bitref<X>::set_word(int n, sc_digit w)
2079{
2080 unsigned int bi = this->m_index % (8 * sizeof(sc_digit));
2081 sc_digit temp;
2082 unsigned int wi = this->m_index / (8 * sizeof(sc_digit));
2083 if (n == 0) {
2084 temp = this->m_obj.get_word(wi);
2085 temp = (temp & ~(1 << bi)) | ((w & 1) << bi);
2086 this->m_obj.set_word(wi, temp);
2087 } else {
2087 SC_REPORT_ERROR("(E5) out of bounds", 0);
2088 SC_REPORT_ERROR(sc_core::SC_ID_OUT_OF_BOUNDS_, 0);
2088 }
2089}
2090
2091template <class X>
2092inline void
2093sc_bitref<X>::set_cword(int n, sc_digit w)
2094{
2095 unsigned int bi = this->m_index % (8 * sizeof(sc_digit));
2096 sc_digit temp;
2097 unsigned int wi = this->m_index / (8 * sizeof(sc_digit));
2098 if (n == 0) {
2099 temp = this->m_obj.get_cword(wi);
2100 temp = (temp & ~(1 << bi)) | ((w & 1) << bi);
2101 this->m_obj.set_cword(wi, temp);
2102 } else {
2089 }
2090}
2091
2092template <class X>
2093inline void
2094sc_bitref<X>::set_cword(int n, sc_digit w)
2095{
2096 unsigned int bi = this->m_index % (8 * sizeof(sc_digit));
2097 sc_digit temp;
2098 unsigned int wi = this->m_index / (8 * sizeof(sc_digit));
2099 if (n == 0) {
2100 temp = this->m_obj.get_cword(wi);
2101 temp = (temp & ~(1 << bi)) | ((w & 1) << bi);
2102 this->m_obj.set_cword(wi, temp);
2103 } else {
2103 SC_REPORT_ERROR("(E5) out of bounds", 0);
2104 SC_REPORT_ERROR(sc_core::SC_ID_OUT_OF_BOUNDS_, 0);
2104 }
2105}
2106
2107// other methods
2108template <class X>
2109inline void
2110sc_bitref<X>::scan(::std::istream &is)
2111{

--- 82 unchanged lines hidden (view full) ---

2194// ----------------------------------------------------------------------------
2195
2196template <class X>
2197inline void
2198sc_subref_r<X>::check_bounds()
2199{
2200 int len = m_obj.length();
2201 if (m_hi < 0 || m_hi >= len || m_lo < 0 || m_lo >= len) {
2105 }
2106}
2107
2108// other methods
2109template <class X>
2110inline void
2111sc_bitref<X>::scan(::std::istream &is)
2112{

--- 82 unchanged lines hidden (view full) ---

2195// ----------------------------------------------------------------------------
2196
2197template <class X>
2198inline void
2199sc_subref_r<X>::check_bounds()
2200{
2201 int len = m_obj.length();
2202 if (m_hi < 0 || m_hi >= len || m_lo < 0 || m_lo >= len) {
2202 SC_REPORT_ERROR("(E5) out of bounds", 0);
2203 SC_REPORT_ERROR(sc_core::SC_ID_OUT_OF_BOUNDS_, 0);
2203 sc_core::sc_abort(); // can't recover from here
2204 }
2205 if (reversed()) {
2206 m_len = m_lo - m_hi + 1;
2207 } else {
2208 m_len = m_hi - m_lo + 1;
2209 }
2210}

--- 452 unchanged lines hidden (view full) ---

2663sc_concref_r<X, Y>::get_bit(int n) const
2664{
2665 int r_len = m_right.length();
2666 if (n < r_len) {
2667 return value_type(m_right.get_bit(n));
2668 } else if (n < r_len + m_left.length()) {
2669 return value_type(m_left.get_bit(n - r_len));
2670 } else {
2204 sc_core::sc_abort(); // can't recover from here
2205 }
2206 if (reversed()) {
2207 m_len = m_lo - m_hi + 1;
2208 } else {
2209 m_len = m_hi - m_lo + 1;
2210 }
2211}

--- 452 unchanged lines hidden (view full) ---

2664sc_concref_r<X, Y>::get_bit(int n) const
2665{
2666 int r_len = m_right.length();
2667 if (n < r_len) {
2668 return value_type(m_right.get_bit(n));
2669 } else if (n < r_len + m_left.length()) {
2670 return value_type(m_left.get_bit(n - r_len));
2671 } else {
2671 SC_REPORT_ERROR("(E5) out of bounds", 0);
2672 SC_REPORT_ERROR(sc_core::SC_ID_OUT_OF_BOUNDS_, 0);
2672 return Log_0;
2673 }
2674}
2675
2676template <class X, class Y>
2677inline void
2678sc_concref_r<X, Y>::set_bit(int n, value_type v)
2679{
2680 int r_len = m_right.length();
2681 if (n < r_len) {
2682 m_right.set_bit(n, typename Y::value_type(v));
2683 } else if (n < r_len + m_left.length()) {
2684 m_left.set_bit(n - r_len, typename X::value_type(v));
2685 } else {
2673 return Log_0;
2674 }
2675}
2676
2677template <class X, class Y>
2678inline void
2679sc_concref_r<X, Y>::set_bit(int n, value_type v)
2680{
2681 int r_len = m_right.length();
2682 if (n < r_len) {
2683 m_right.set_bit(n, typename Y::value_type(v));
2684 } else if (n < r_len + m_left.length()) {
2685 m_left.set_bit(n - r_len, typename X::value_type(v));
2686 } else {
2686 SC_REPORT_ERROR("(E5) out of bounds", 0);
2687 SC_REPORT_ERROR(sc_core::SC_ID_OUT_OF_BOUNDS_, 0);
2687 }
2688}
2689
2690template <class X, class Y>
2691inline sc_digit
2692sc_concref_r<X, Y>::get_word(int i) const
2693{
2694 if (i < 0 || i >= size()) {
2688 }
2689}
2690
2691template <class X, class Y>
2692inline sc_digit
2693sc_concref_r<X, Y>::get_word(int i) const
2694{
2695 if (i < 0 || i >= size()) {
2695 SC_REPORT_ERROR("(E5) out of bounds", 0);
2696 SC_REPORT_ERROR(sc_core::SC_ID_OUT_OF_BOUNDS_, 0);
2696 }
2697 // 0 <= i < size()
2698 Y &r = m_right;
2699 int r_len = r.length();
2700 int border = r_len / SC_DIGIT_SIZE;
2701 if (i < border) {
2702 return r.get_word(i);
2703 }

--- 17 unchanged lines hidden (view full) ---

2721 return (l.get_word(j - 1) >> nshift);
2722}
2723
2724template <class X, class Y>
2725inline void
2726sc_concref_r<X, Y>::set_word(int i, sc_digit w)
2727{
2728 if (i < 0 || i >= size()) {
2697 }
2698 // 0 <= i < size()
2699 Y &r = m_right;
2700 int r_len = r.length();
2701 int border = r_len / SC_DIGIT_SIZE;
2702 if (i < border) {
2703 return r.get_word(i);
2704 }

--- 17 unchanged lines hidden (view full) ---

2722 return (l.get_word(j - 1) >> nshift);
2723}
2724
2725template <class X, class Y>
2726inline void
2727sc_concref_r<X, Y>::set_word(int i, sc_digit w)
2728{
2729 if (i < 0 || i >= size()) {
2729 SC_REPORT_ERROR("(E5) out of bounds", 0);
2730 SC_REPORT_ERROR(sc_core::SC_ID_OUT_OF_BOUNDS_, 0);
2730 }
2731 // 0 <= i < size()
2732 Y &r = m_right;
2733 int r_len = r.length();
2734 int border = r_len / SC_DIGIT_SIZE;
2735 if (i < border) {
2736 r.set_word(i, w);
2737 return;

--- 22 unchanged lines hidden (view full) ---

2760 l.set_word(j, (l.get_word(j) & lh_mask) | (w >> shift));
2761}
2762
2763template <class X, class Y>
2764inline sc_digit
2765sc_concref_r<X, Y>::get_cword(int i) const
2766{
2767 if (i < 0 || i >= size()) {
2731 }
2732 // 0 <= i < size()
2733 Y &r = m_right;
2734 int r_len = r.length();
2735 int border = r_len / SC_DIGIT_SIZE;
2736 if (i < border) {
2737 r.set_word(i, w);
2738 return;

--- 22 unchanged lines hidden (view full) ---

2761 l.set_word(j, (l.get_word(j) & lh_mask) | (w >> shift));
2762}
2763
2764template <class X, class Y>
2765inline sc_digit
2766sc_concref_r<X, Y>::get_cword(int i) const
2767{
2768 if (i < 0 || i >= size()) {
2768 SC_REPORT_ERROR("(E5) out of bounds", 0);
2769 SC_REPORT_ERROR(sc_core::SC_ID_OUT_OF_BOUNDS_, 0);
2769 }
2770 // 0 <= i < size()
2771 Y &r = m_right;
2772 int r_len = r.length();
2773 int border = r_len / SC_DIGIT_SIZE;
2774 if (i < border) {
2775 return r.get_cword(i);
2776 }

--- 17 unchanged lines hidden (view full) ---

2794 return (l.get_cword( j - 1 ) >> nshift);
2795}
2796
2797template <class X, class Y>
2798inline void
2799sc_concref_r<X, Y>::set_cword(int i, sc_digit w)
2800{
2801 if (i < 0 || i >= size()) {
2770 }
2771 // 0 <= i < size()
2772 Y &r = m_right;
2773 int r_len = r.length();
2774 int border = r_len / SC_DIGIT_SIZE;
2775 if (i < border) {
2776 return r.get_cword(i);
2777 }

--- 17 unchanged lines hidden (view full) ---

2795 return (l.get_cword( j - 1 ) >> nshift);
2796}
2797
2798template <class X, class Y>
2799inline void
2800sc_concref_r<X, Y>::set_cword(int i, sc_digit w)
2801{
2802 if (i < 0 || i >= size()) {
2802 SC_REPORT_ERROR("(E5) out of bounds", 0);
2803 SC_REPORT_ERROR(sc_core::SC_ID_OUT_OF_BOUNDS_, 0);
2803 }
2804 // 0 <= i < size()
2805 Y &r = m_right;
2806 int r_len = r.length();
2807 int border = r_len / SC_DIGIT_SIZE;
2808 if (i < border) {
2809 r.set_cword(i, w);
2810 return;

--- 609 unchanged lines hidden ---
2804 }
2805 // 0 <= i < size()
2806 Y &r = m_right;
2807 int r_len = r.length();
2808 int border = r_len / SC_DIGIT_SIZE;
2809 if (i < border) {
2810 r.set_cword(i, w);
2811 return;

--- 609 unchanged lines hidden ---