2 * Copyright (c) 2002 Stephen Williams (steve@icarus.com)
4 * This source code is free software; you can redistribute it
5 * and/or modify it in source code form under the terms of the GNU
6 * General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20 #ident "$Id: vpip_oct.cc,v 1.4 2006/02/21 02:39:27 steve Exp $"
24 # include "vpi_priv.h"
34 extern const char oct_digits
[64];
36 void vpip_oct_str_to_vec4(vvp_vector4_t
&val
, const char*str
)
38 unsigned str_len
= strlen(str
);
52 for (unsigned idx
= 0 ; idx
< val
.size() ; idx
+= 1) {
54 unsigned bit_off
= idx
%3;
55 unsigned str_off
= idx
/3;
58 if (str_off
>= str_len
)
61 ch
= str
[str_len
-str_off
-1];
73 val
.set_bit(idx
, ((tmp
>>bit_off
)&1)? BIT4_1
: BIT4_0
);
77 val
.set_bit(idx
, BIT4_X
);
81 val
.set_bit(idx
, BIT4_Z
);
84 fprintf(stderr
, "Unsupported digit %c(%d).\n", ch
, ch
);
92 void vpip_bits_to_oct_str(const unsigned char*bits
, unsigned nbits
,
93 char*buf
, unsigned nbuf
, bool signed_flag
)
95 unsigned slen
= (nbits
+ 2) / 3;
101 for (unsigned idx
= 0 ; idx
< nbits
; idx
+= 1) {
103 unsigned bs
= (idx
%4) * 2;
104 unsigned bit
= (bits
[bi
] >> bs
) & 3;
106 unsigned vs
= (idx
%3) * 2;
111 buf
[slen
] = oct_digits
[val
];
118 buf
[slen
] = oct_digits
[val
];
122 void vpip_vec4_to_oct_str(const vvp_vector4_t
&bits
, char*buf
, unsigned nbuf
,
125 unsigned slen
= (bits
.size() + 2) / 3;
131 for (unsigned idx
= 0 ; idx
< bits
.size() ; idx
+= 1) {
132 unsigned vs
= (idx
%3) * 2;
134 switch (bits
.value(idx
)) {
149 buf
[slen
] = oct_digits
[val
];
156 buf
[slen
] = oct_digits
[val
];