2014-07-23 22:39:29 +02:00
|
|
|
#ifndef IVL_ufunc_H
|
|
|
|
|
#define IVL_ufunc_H
|
2002-03-18 01:19:34 +01:00
|
|
|
/*
|
2025-07-22 08:30:57 +02:00
|
|
|
* Copyright (c) 2002-2025 Stephen Williams (steve@icarus.com)
|
2002-03-18 01:19:34 +01:00
|
|
|
*
|
|
|
|
|
* This source code is free software; you can redistribute it
|
|
|
|
|
* and/or modify it in source code form under the terms of the GNU
|
|
|
|
|
* General Public License as published by the Free Software
|
|
|
|
|
* Foundation; either version 2 of the License, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-08-29 03:41:23 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-03-18 01:19:34 +01:00
|
|
|
*/
|
|
|
|
|
|
2009-11-29 06:39:35 +01:00
|
|
|
# include "config.h"
|
2002-03-18 01:19:34 +01:00
|
|
|
|
2015-12-27 22:07:42 +01:00
|
|
|
class __vpiScope;
|
|
|
|
|
|
2002-03-18 01:19:34 +01:00
|
|
|
/*
|
|
|
|
|
* The .ufunc statement creates functors to represent user defined
|
2005-03-18 03:56:03 +01:00
|
|
|
* functions within the netlist (as opposed to within behavioral
|
|
|
|
|
* code.) The function device itself is implemented as a thread with a
|
|
|
|
|
* bunch of functors to receive input and a functor to deliver the
|
|
|
|
|
* output. (Functions have exactly one output.) The input functors
|
|
|
|
|
* detect that a change has occurred, and invoke the thread to process
|
|
|
|
|
* the new values. The thread then uses the output functor to deliver
|
|
|
|
|
* the result. The relationships look like this:
|
2002-03-18 01:19:34 +01:00
|
|
|
*
|
2005-03-18 03:56:03 +01:00
|
|
|
* ufunc_input_functor --+--> ufunc_core --> ...
|
|
|
|
|
* |
|
|
|
|
|
* ufunc_input_functor --+
|
|
|
|
|
* |
|
|
|
|
|
* ufunc_input_functor --+
|
|
|
|
|
*
|
|
|
|
|
* There are enough input functors to take all the function inputs, 4
|
|
|
|
|
* per functor. These inputs deliver the changed input value to the
|
2008-01-29 21:19:59 +01:00
|
|
|
* ufunc_core, which carries the infrastructure for the thread. The
|
2005-03-18 03:56:03 +01:00
|
|
|
* ufunc_core is also a functor whose output is connected to the rest
|
|
|
|
|
* of the netlist. This is where the result is delivered back to the
|
|
|
|
|
* netlist.
|
2005-04-01 08:02:45 +02:00
|
|
|
*
|
|
|
|
|
* This class relies to the vvp_wide_fun_* classes in vvp_net.h.
|
2002-03-18 01:19:34 +01:00
|
|
|
*/
|
|
|
|
|
|
2005-04-01 08:02:45 +02:00
|
|
|
class ufunc_core : public vvp_wide_fun_core {
|
2002-03-18 01:19:34 +01:00
|
|
|
|
|
|
|
|
public:
|
2005-03-18 03:56:03 +01:00
|
|
|
ufunc_core(unsigned ow, vvp_net_t*ptr,
|
|
|
|
|
unsigned nports, vvp_net_t**ports,
|
2003-07-03 22:03:36 +02:00
|
|
|
vvp_code_t start_address,
|
2015-12-27 22:07:42 +01:00
|
|
|
__vpiScope*call_scope,
|
2008-09-27 01:54:13 +02:00
|
|
|
char*scope_label);
|
2016-01-18 01:23:28 +01:00
|
|
|
virtual ~ufunc_core() =0;
|
2002-03-18 01:19:34 +01:00
|
|
|
|
2015-12-27 22:07:42 +01:00
|
|
|
__vpiScope*call_scope() { return call_scope_; }
|
|
|
|
|
__vpiScope*func_scope() { return func_scope_; }
|
2002-03-18 01:19:34 +01:00
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
void assign_bits_to_ports(vvp_context_t context);
|
2016-01-18 01:23:28 +01:00
|
|
|
virtual void finish_thread() =0;
|
2002-03-18 01:19:34 +01:00
|
|
|
|
2008-12-22 22:48:34 +01:00
|
|
|
void recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit,
|
2025-07-22 08:30:57 +02:00
|
|
|
vvp_context_t context) override;
|
2008-12-22 22:48:34 +01:00
|
|
|
|
2016-01-18 01:23:28 +01:00
|
|
|
protected:
|
|
|
|
|
void finish_thread_real_();
|
2016-01-25 03:36:26 +01:00
|
|
|
void finish_thread_vec4_();
|
2016-01-18 01:23:28 +01:00
|
|
|
|
2005-03-18 03:56:03 +01:00
|
|
|
private:
|
2025-07-22 08:30:57 +02:00
|
|
|
void recv_vec4_from_inputs(unsigned port) override;
|
|
|
|
|
void recv_real_from_inputs(unsigned port) override;
|
2008-01-29 03:57:55 +01:00
|
|
|
|
|
|
|
|
void invoke_thread_(void);
|
|
|
|
|
|
2002-03-18 01:19:34 +01:00
|
|
|
|
|
|
|
|
private:
|
2005-03-18 03:56:03 +01:00
|
|
|
// output width of the function node.
|
2002-03-18 01:19:34 +01:00
|
|
|
unsigned owid_;
|
2005-04-01 08:02:45 +02:00
|
|
|
// The vvp_net_t* objects for the function input ports. We use
|
|
|
|
|
// these to write the input values to the reg input variable
|
|
|
|
|
// functors for the thread.
|
2005-03-18 03:56:03 +01:00
|
|
|
vvp_net_t**ports_;
|
|
|
|
|
|
2002-03-18 01:19:34 +01:00
|
|
|
// This is a thread to execute the behavioral portion of the
|
|
|
|
|
// function.
|
|
|
|
|
vthread_t thread_;
|
2015-12-27 22:07:42 +01:00
|
|
|
__vpiScope*call_scope_;
|
|
|
|
|
__vpiScope*func_scope_;
|
2003-07-03 22:03:36 +02:00
|
|
|
vvp_code_t code_;
|
2016-01-18 01:23:28 +01:00
|
|
|
};
|
2002-03-18 01:19:34 +01:00
|
|
|
|
2014-07-23 22:39:29 +02:00
|
|
|
#endif /* IVL_ufunc_H */
|