Skip to content

Commit 335db49

Browse files
committed
Add vvp implementations for pop_back and pop_front methods.
1 parent 8c2d511 commit 335db49

File tree

7 files changed

+168
-0
lines changed

7 files changed

+168
-0
lines changed

tgt-vvp/eval_expr.c

+28
Original file line numberDiff line numberDiff line change
@@ -3126,6 +3126,29 @@ static struct vector_info draw_ternary_expr(ivl_expr_t expr, unsigned wid)
31263126
return res;
31273127
}
31283128

3129+
static struct vector_info draw_darray_pop(ivl_expr_t expr, unsigned wid)
3130+
{
3131+
struct vector_info res;
3132+
ivl_expr_t arg;
3133+
const char*fb;
3134+
3135+
if (strcmp(ivl_expr_name(expr), "$ivl_darray_method$pop_back")==0)
3136+
fb = "b";
3137+
else
3138+
fb = "f";
3139+
3140+
res.base = allocate_vector(wid);
3141+
res.wid = wid;
3142+
3143+
arg = ivl_expr_parm(expr, 0);
3144+
assert(ivl_expr_type(arg) == IVL_EX_SIGNAL);
3145+
3146+
fprintf(vvp_out, " %%qpop/%s v%p_0, %u, %u;\n", fb,
3147+
ivl_expr_signal(arg), res.base, res.wid);
3148+
3149+
return res;
3150+
}
3151+
31293152
static struct vector_info draw_sfunc_expr(ivl_expr_t expr, unsigned wid)
31303153
{
31313154
unsigned parm_count = ivl_expr_parms(expr);
@@ -3147,6 +3170,11 @@ static struct vector_info draw_sfunc_expr(ivl_expr_t expr, unsigned wid)
31473170

31483171
}
31493172

3173+
if (strcmp(ivl_expr_name(expr), "$ivl_darray_method$pop_back")==0)
3174+
return draw_darray_pop(expr, wid);
3175+
if (strcmp(ivl_expr_name(expr),"$ivl_darray_method$pop_front")==0)
3176+
return draw_darray_pop(expr, wid);
3177+
31503178
res = draw_vpi_func_call(expr, wid);
31513179

31523180
/* New basic block starts after VPI calls. */

tgt-vvp/eval_string.c

+20
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,22 @@ static void string_ex_substr(ivl_expr_t expr)
150150
clr_word(arg2);
151151
}
152152

153+
static void string_ex_pop(ivl_expr_t expr)
154+
{
155+
const char*fb;
156+
ivl_expr_t arg;
157+
158+
if (strcmp(ivl_expr_name(expr), "$ivl_darray_method$pop_back")==0)
159+
fb = "b";
160+
else
161+
fb = "f";
162+
163+
arg = ivl_expr_parm(expr, 0);
164+
assert(ivl_expr_type(arg) == IVL_EX_SIGNAL);
165+
166+
fprintf(vvp_out, " %%qpop/%s/str v%p_0;\n", fb, ivl_expr_signal(arg));
167+
}
168+
153169
void draw_eval_string(ivl_expr_t expr)
154170
{
155171

@@ -177,6 +193,10 @@ void draw_eval_string(ivl_expr_t expr)
177193
case IVL_EX_SFUNC:
178194
if (strcmp(ivl_expr_name(expr), "$ivl_string_method$substr") == 0)
179195
string_ex_substr(expr);
196+
else if (strcmp(ivl_expr_name(expr), "$ivl_darray_method$pop_back")==0)
197+
string_ex_pop(expr);
198+
else if (strcmp(ivl_expr_name(expr), "$ivl_darray_method$pop_front")==0)
199+
string_ex_pop(expr);
180200
else
181201
fallback_eval(expr);
182202
break;

vvp/codes.h

+4
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ extern bool of_POP_STR(vthread_t thr, vvp_code_t code);
167167
extern bool of_POW(vthread_t thr, vvp_code_t code);
168168
extern bool of_POW_S(vthread_t thr, vvp_code_t code);
169169
extern bool of_POW_WR(vthread_t thr, vvp_code_t code);
170+
extern bool of_QPOP_B(vthread_t thr, vvp_code_t code);
171+
extern bool of_QPOP_F(vthread_t thr, vvp_code_t code);
172+
extern bool of_QPOP_B_STR(vthread_t thr, vvp_code_t code);
173+
extern bool of_QPOP_F_STR(vthread_t thr, vvp_code_t code);
170174
extern bool of_PROP_OBJ(vthread_t thr, vvp_code_t code);
171175
extern bool of_PROP_R(vthread_t thr, vvp_code_t code);
172176
extern bool of_PROP_STR(vthread_t thr, vvp_code_t code);

vvp/compile.cc

+4
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ static const struct opcode_table_s opcode_table[] = {
223223
{ "%pushi/str", of_PUSHI_STR, 1,{OA_STRING, OA_NONE, OA_NONE} },
224224
{ "%pushv/str", of_PUSHV_STR, 2, {OA_BIT1,OA_BIT2, OA_NONE} },
225225
{ "%putc/str/v",of_PUTC_STR_V,3,{OA_FUNC_PTR,OA_BIT1, OA_BIT2} },
226+
{ "%qpop/b", of_QPOP_B, 3,{OA_FUNC_PTR,OA_BIT1, OA_BIT2} },
227+
{ "%qpop/f", of_QPOP_F, 3,{OA_FUNC_PTR,OA_BIT1, OA_BIT2} },
228+
{ "%qpop/b/str",of_QPOP_B_STR,1,{OA_FUNC_PTR,OA_NONE, OA_NONE} },
229+
{ "%qpop/f/str",of_QPOP_F_STR,1,{OA_FUNC_PTR,OA_NONE, OA_NONE} },
226230
{ "%release/net",of_RELEASE_NET,3,{OA_FUNC_PTR,OA_BIT1,OA_BIT2} },
227231
{ "%release/reg",of_RELEASE_REG,3,{OA_FUNC_PTR,OA_BIT1,OA_BIT2} },
228232
{ "%release/wr",of_RELEASE_WR,2,{OA_FUNC_PTR,OA_BIT1,OA_NONE} },

vvp/vthread.cc

+85
Original file line numberDiff line numberDiff line change
@@ -4850,6 +4850,91 @@ bool of_PUTC_STR_V(vthread_t thr, vvp_code_t cp)
48504850
return true;
48514851
}
48524852

4853+
bool of_QPOP_B(vthread_t thr, vvp_code_t cp)
4854+
{
4855+
unsigned bit = cp->bit_idx[0];
4856+
unsigned wid = cp->bit_idx[1];
4857+
4858+
vvp_net_t*net = cp->net;
4859+
vvp_fun_signal_object*obj = dynamic_cast<vvp_fun_signal_object*> (net->fun);
4860+
assert(obj);
4861+
4862+
vvp_queue*dqueue = obj->get_object().peek<vvp_queue>();
4863+
assert(dqueue);
4864+
4865+
size_t size = dqueue->get_size();
4866+
assert(size > 0);
4867+
4868+
vvp_vector4_t value;
4869+
dqueue->get_word(size-1, value);
4870+
dqueue->pop_back();
4871+
4872+
assert(value.size() == wid);
4873+
thr->bits4.set_vec(bit, value);
4874+
return true;
4875+
}
4876+
4877+
bool of_QPOP_F(vthread_t thr, vvp_code_t cp)
4878+
{
4879+
unsigned bit = cp->bit_idx[0];
4880+
unsigned wid = cp->bit_idx[1];
4881+
4882+
vvp_net_t*net = cp->net;
4883+
vvp_fun_signal_object*obj = dynamic_cast<vvp_fun_signal_object*> (net->fun);
4884+
assert(obj);
4885+
4886+
vvp_queue*dqueue = obj->get_object().peek<vvp_queue>();
4887+
assert(dqueue);
4888+
4889+
size_t size = dqueue->get_size();
4890+
assert(size > 0);
4891+
4892+
vvp_vector4_t value;
4893+
dqueue->get_word(0, value);
4894+
dqueue->pop_front();
4895+
4896+
assert(value.size() == wid);
4897+
thr->bits4.set_vec(bit, value);
4898+
return true;
4899+
}
4900+
4901+
bool of_QPOP_B_STR(vthread_t thr, vvp_code_t cp)
4902+
{
4903+
vvp_net_t*net = cp->net;
4904+
vvp_fun_signal_object*obj = dynamic_cast<vvp_fun_signal_object*> (net->fun);
4905+
assert(obj);
4906+
4907+
vvp_queue*dqueue = obj->get_object().peek<vvp_queue>();
4908+
assert(dqueue);
4909+
4910+
size_t size = dqueue->get_size();
4911+
assert(size > 0);
4912+
4913+
string value;
4914+
dqueue->get_word(size-1, value);
4915+
dqueue->pop_back();
4916+
4917+
thr->push_str(value);
4918+
return true;
4919+
}
4920+
4921+
bool of_QPOP_F_STR(vthread_t thr, vvp_code_t cp)
4922+
{
4923+
vvp_net_t*net = cp->net;
4924+
vvp_fun_signal_object*obj = dynamic_cast<vvp_fun_signal_object*> (net->fun);
4925+
assert(obj);
4926+
4927+
vvp_queue*dqueue = obj->get_object().peek<vvp_queue>();
4928+
assert(dqueue);
4929+
4930+
string value;
4931+
dqueue->get_word(0, value);
4932+
dqueue->pop_front();
4933+
4934+
thr->push_str(value);
4935+
return true;
4936+
}
4937+
48534938
/*
48544939
* These implement the %release/net and %release/reg instructions. The
48554940
* %release/net instruction applies to a net kind of functor by

vvp/vvp_darray.cc

+20
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,16 @@ void vvp_queue_string::get_word(unsigned adr, string&value)
231231
value = *cur;
232232
}
233233

234+
void vvp_queue_string::pop_back(void)
235+
{
236+
array_.pop_back();
237+
}
238+
239+
void vvp_queue_string::pop_front(void)
240+
{
241+
array_.pop_front();
242+
}
243+
234244
vvp_queue_vec4::~vvp_queue_vec4()
235245
{
236246
}
@@ -279,3 +289,13 @@ void vvp_queue_vec4::push_front(const vvp_vector4_t&val)
279289
{
280290
array_.push_front(val);
281291
}
292+
293+
void vvp_queue_vec4::pop_back(void)
294+
{
295+
array_.pop_back();
296+
}
297+
298+
void vvp_queue_vec4::pop_front(void)
299+
{
300+
array_.pop_front();
301+
}

vvp/vvp_darray.h

+7
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ class vvp_queue : public vvp_darray {
101101

102102
virtual void push_back(const std::string&value);
103103
virtual void push_front(const std::string&value);
104+
105+
virtual void pop_back(void) =0;
106+
virtual void pop_front(void)=0;
104107
};
105108

106109
class vvp_queue_vec4 : public vvp_queue {
@@ -113,6 +116,8 @@ class vvp_queue_vec4 : public vvp_queue {
113116
void get_word(unsigned adr, vvp_vector4_t&value);
114117
void push_back(const vvp_vector4_t&value);
115118
void push_front(const vvp_vector4_t&value);
119+
void pop_back(void);
120+
void pop_front(void);
116121

117122
private:
118123
std::list<vvp_vector4_t> array_;
@@ -129,6 +134,8 @@ class vvp_queue_string : public vvp_queue {
129134
void get_word(unsigned adr, std::string&value);
130135
void push_back(const std::string&value);
131136
//void push_front(const std::string&value);
137+
void pop_back(void);
138+
void pop_front(void);
132139

133140
private:
134141
std::list<std::string> array_;

0 commit comments

Comments
 (0)