-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No Modulo / Remainder Operator "%" for integer types #202
Comments
My log of notes in implementing this This function is saying left_t = partially_complete_logic.wire_to_c_type[partially_complete_logic.inputs[0]]
right_t = partially_complete_logic.wire_to_c_type[partially_complete_logic.inputs[1]] Which leads us to error out if the types arent floats atm. Inside Notice Lets do signed integers first actually There is also commented out code that was checking types too well use the signed version if VHDL.WIRES_ARE_INT_N(partially_complete_logic.inputs, partially_complete_logic):
return GET_BIN_OP_MOD_INT_N_C_CODE(partially_complete_logic, out_dir) and change the error message to say only for floats and ints for now... So we introduced At this point some point in past forget to get the After copying Running pipelinec on the original example code again Back into elif VHDL.WIRES_ARE_UINT_N(partially_complete_logic.inputs, partially_complete_logic):
return GET_BIN_OP_MOD_UINT_N_C_CODE(partially_complete_logic, out_dir, parser_state) and change error message to something like not floats or ints wtf? Similar to before This function generates PipelineC code to do unsigned division like it was written before PipelineC supported for loops but now our MOD func will output the Running the example code again now
In the output directory you can see the generated C code for those ops as described in the python: #include "intN_t.h"
#include "uintN_t.h"
#include "bit_manip.h"
// 32b % 32b mod
int32_t BIN_OP_MOD_int32_t_int32_t(int32_t left, int32_t right)
{
// Record sign bits
uint1_t l_signed = int32_31_31(left);
uint1_t r_signed = int32_31_31(right);
// Resize to unsigned values of same width
uint32_t left_resized = int32_abs(left);
uint32_t right_resized = int32_abs(right);
// Do mod on uints
uint32_t unsigned_result = left_resized % right_resized;
// Adjust sign
int32_t output = unsigned_result;
if(l_signed ^ r_signed)
{
output = -unsigned_result;
}
return output;
} And should be done assuming the sign bit fixing using unsigned mod to do signed mod makes sense... |
The integer modulo (remainder) Operator "%" insn't implemented...
Demo code:
Tool Output:
GET_BIN_OP_MOD_C_CODE Only mod between float for now!
Possible [Slow | Non-Generic] Fix is overloading the operator:
This generates:
BIN_OP_DIV_int32_t_int32_t BIN_OP_MINUS_uint32_t_uint1_t UNARY_OP_NOT_uint32_t MUX_uint1_t_uint32_t_uint32_t BIN_OP_DIV_uint32_t_uint32_t BIN_OP_GTE_uint32_t_uint32_t BIN_OP_MINUS_int33_t_int33_t UNARY_OP_NOT_uint1_t BIN_OP_MINUS_uint32_t_uint32_t BIN_OP_XOR_uint1_t_uint1_t MUX_uint1_t_int32_t_int32_t UNARY_OP_NEGATE_uint32_t UNARY_OP_NOT_uint33_t BIN_OP_PLUS_uint33_t_uint1_t BIN_OP_INFERRED_MULT_int32_t_int32_t BIN_OP_MINUS_int32_t_int64_t
The text was updated successfully, but these errors were encountered: