sc_bit_proxies.hh (12853:e23d6f09069a) sc_bit_proxies.hh (13138:31951157e41e)
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

--- 1721 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 {
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

--- 1721 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 {
1738 SC_REPORT_ERROR("out of bounds", 0);
1738 SC_REPORT_ERROR("(E5) 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 {
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 {
1750 SC_REPORT_ERROR("out of bounds", 0);
1750 SC_REPORT_ERROR("(E5) 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 {
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 {
1762 SC_REPORT_ERROR("out of bounds", 0);
1762 SC_REPORT_ERROR("(E5) 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 {
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 {
2071 SC_REPORT_ERROR("out of bounds", 0);
2071 SC_REPORT_ERROR("(E5) 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 {
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 {
2087 SC_REPORT_ERROR("out of bounds", 0);
2087 SC_REPORT_ERROR("(E5) 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 {
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 {
2103 SC_REPORT_ERROR("out of bounds", 0);
2103 SC_REPORT_ERROR("(E5) 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) {
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) {
2202 SC_REPORT_ERROR("out of bounds", 0);
2202 SC_REPORT_ERROR("(E5) 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 {
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 {
2671 SC_REPORT_ERROR("out of bounds", 0);
2671 SC_REPORT_ERROR("(E5) 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 {
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 {
2686 SC_REPORT_ERROR("out of bounds", 0);
2686 SC_REPORT_ERROR("(E5) 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()) {
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()) {
2695 SC_REPORT_ERROR("out of bounds", 0);
2695 SC_REPORT_ERROR("(E5) 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()) {
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()) {
2729 SC_REPORT_ERROR("out of bounds", 0);
2729 SC_REPORT_ERROR("(E5) 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()) {
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()) {
2768 SC_REPORT_ERROR("out of bounds", 0);
2768 SC_REPORT_ERROR("(E5) 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()) {
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()) {
2802 SC_REPORT_ERROR("out of bounds", 0);
2802 SC_REPORT_ERROR("(E5) 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 ---
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 ---