PipelineC++ #32
Replies: 10 comments 23 replies
-
I am all for supporting more advanced (i.e. C++) syntax. However, some initial reasons why it doesn't exist already:
Like I said, I would be happy to support this I just literally dont know how at the moment syntax wise + a little bit of complication+implementation needed for random access case (I suppose template <> values are compile time constant anyway, dont need to worry about random case yet). |
Beta Was this translation helpful? Give feedback.
-
I proppsed such template syntax of kind bits<5,2> doesn't support runtime
variables but compile time calculated constant so I seem then very suitable
for such cases. Using non constant expressions will raise an error in a C++
compiler and pipelineC can mimic such behavior
El dom., 3 oct. 2021 14:59, Julian Kemmerer ***@***.***>
escribió:
… I am all for supporting more advanced (i.e. C++) syntax.
However, some initial reasons why it doesn't exist already:
1. I dont know how to modify the pycparser
<https://github.com/eliben/pycparser> I am using to support C++ style
'<' '>' tokens for template types, etc.
2. Less importantly, it was originally done as text 5_2 in the
function name also because I didnt want people to think it could be used
with run-time variable values. I.e. compile time 'select bits 5:2' is
different from run time 'select bits M:N' (where M express evals to 5,
etc). So didnt want to do like bits(5,2)(x) with macros or something.
But looking back, its possible to implement the 'select bits M:N' run time
variable - its pretty much a random access looking thing like I have dealt
with for arrays already.
Like I said, I would be happy to support this I just literally dont know
how at the moment syntax wise + a little bit of complication+implementation
needed for random access case (I suppose template <> values are compile
time constant anyway, dont need to worry about random case yet).
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#32 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACBHVWJIL26AIALDRHOY6G3UFCKZJANCNFSM5FHSMUXA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Beta Was this translation helpful? Give feedback.
-
@suarezvictor Do you know about parsers 'lexers' yacc syntax trees etc? things https://github.com/eliben/pycparser deals with? That github recommends doing something different for parsing C++ (recommends LLVM based I think). But maybe we could modify the more simply pycparser to just add support for compile time constant |
Beta Was this translation helpful? Give feedback.
-
Definitely, I don't suggest supporting all C++ syntax. Just some tiny
portion that adds such functions. For the moment I suggest just the <>
operator for certain functions. Having calculated compile-time constantes
instead of numbers in symbol names will be a great addition.
There are manu good parsers to support needed features. Let me know if you
want me to collaborate selecting one.
El dom., 3 oct. 2021 23:34, Julian Kemmerer ***@***.***>
escribió:
… @suarezvictor <https://github.com/suarezvictor> Do you know about parsers
'lexers' yacc syntax trees etc? things https://github.com/eliben/pycparser
deals with?
That github recommends doing something different for parsing C++
(recommends LLVM based I think). But maybe we could modify the more simply
pycparser to just add support for compile time constant bits<5,2> kind of
syntax without doing the rest of C++ (yet?)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#32 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACBHVWPX45U77WFK3C2HSMTUFEHDNANCNFSM5FHSMUXA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Beta Was this translation helpful? Give feedback.
-
I can definitely help with that. Maybe I have more experience in software
as I see you have more experience in hardware design than me.
For exampĺe a project I did (with success) was to parse matlab code and
translate it to python with bit exact results for doing math processing
(for algorithms of hundreds of lines)
Again I'm time limited but from time to time, I'll have some.
…On Mon, Oct 4, 2021 at 1:56 PM Julian Kemmerer ***@***.***> wrote:
I suppose its not just collaborate selecting one but I need some serious
help even understanding "how to go from C-code to python C-abstract syntax
tree objects" (i.e how does pycparser work)
From pycparser outputs, the C-AST to traverse, I know how to proceed.
I dont know how to modify pycparser - and 'selecting a new parser' sounds
like lots and lots of work. I am sort of tied to pycparser until I
understand how to modify it or can fully replace it 🤷
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#32 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACBHVWMA2GO722F3TAL7C2LUFHMENANCNFSM5FHSMUXA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Beta Was this translation helpful? Give feedback.
-
One possible solution is to parse the file as C++ (considering that C is,
in practice, a subset of C). For that you can call clang to analyze the
file. You can call clang libs (notthe executable) from python and have the
AST in python. An example of that is here:
https://sudonull.com/post/907-An-example-of-parsing-C-code-using-libclang-in-Python
this was a quick search and the topic can't be solved in just minutes, but
the point is that there exist lots of similar solutions that we can reuse.
A main thing to solve is first to have a _design_ of what features would be
useful to incorporate. The first one was the bit access as I proposed, we
may start discovering more as we use them.
A feature I see really useful (and that doesn't need C++ syntax) is to have
the new types "uX_t" meaning "integer of at least X bits", then the type
"bool" would be equal to "u1_t", and implemented as 1 bit in hardware and
bit-exact simulation but as as real bool in raw C compiling. Let's start to
design some more desired features, that will influence the changes to the
parser needed.
In regards to the bit extract function, for example, uint12_3_2, what does
the first number mean? I think if we're asking for two bits, the results
should be a uint2_t. And in case the operand is of no more than 2 bits, be
rejected or zero-padded and a warning issued.
On Mon, Oct 4, 2021 at 2:04 PM Victor Suarez Rovere ***@***.***>
wrote:
… I can definitely help with that. Maybe I have more experience in software
as I see you have more experience in hardware design than me.
For exampĺe a project I did (with success) was to parse matlab code and
translate it to python with bit exact results for doing math processing
(for algorithms of hundreds of lines)
Again I'm time limited but from time to time, I'll have some.
On Mon, Oct 4, 2021 at 1:56 PM Julian Kemmerer ***@***.***>
wrote:
> I suppose its not just collaborate selecting one but I need some serious
> help even understanding "how to go from C-code to python C-abstract syntax
> tree objects" (i.e how does pycparser work)
> From pycparser outputs, the C-AST to traverse, I know how to proceed.
> I dont know how to modify pycparser - and 'selecting a new parser' sounds
> like lots and lots of work. I am sort of tied to pycparser until I
> understand how to modify it or can fully replace it 🤷
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#32 (reply in thread)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ACBHVWMA2GO722F3TAL7C2LUFHMENANCNFSM5FHSMUXA>
> .
> Triage notifications on the go with GitHub Mobile for iOS
> <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
> or Android
> <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
>
>
|
Beta Was this translation helpful? Give feedback.
-
In regards to the "uint12_3_2" that will first extend/truncate to 12 bits, it seems in majority of cases the first number is not needed. For example, if operand is unsigned, taking bits 3 to 2 will produce same results for operands of any size regardless the "12". That is, function " uintX_3_2" will be all equal for any X. In case of signed operands, the behavior will be such confusing that maybe it will be convenient to first do the size conversion and then the bit extracción with two function calls (and I think such signed operations will be uncommon) |
Beta Was this translation helpful? Give feedback.
-
I agree on everything, and liked your macro BITS(val, 3, 2). Maybe BITS(3,
2, val)? See below.
Additionally, I can provide a more syntax-sugarish implementation for C++
compilers like clang with a syntax as previously proposed: bits<3,2>(val),
equivalent to your macro. And hopefully we can tweak or replace the parser
to support that. The benefit is that with both forms we can use
compile-time constants that are next to a "must" to provide some
flexibility. Using template trickery (that I can write) we can offer some
compile-time calculations like detecting the most significant bit of a
constant, bit count, clog2 equivalent, "all ones" of some size, etc.
In regards to types, in C you have the basic types "char, int, long". Their
size is platform-dependent and never defined. In C++ you have the
additional "bool" value which is also platform dependent (you don't know
how many bits it has nor the values used, but in practice is like a char).
Then there are nonstandar compiler extensions like "long long" and the like.
Since such definitions has platform dependence (actually "indefinitions"),
there are handy typedefs in headers like stdint.h which provides uint32_t
and the like fixed-size types. They're fixed size, no possible extensions.
The extensibility proposed is mine (surely there are others that suggested
the same but I'm unaware).
…On Mon, Oct 4, 2021 at 8:40 PM Julian Kemmerer ***@***.***> wrote:
Yeah I understand and that makes alot of sense especially for the unsigned
case.
So its currently:
uint<Y-X+1>_t <type_prefix>_Y_X(<type> val)
ex.uint2_t uint12_3_2(uint12_t val)
Maybe something like this for 'assumed' input size based on the bit range.
Make it so the uint12 isnt needed
uint<Y-X+1>_t bits_Y_X(uint<Y+1>_t val)
ex.uint2_t bits_3_2(uint4_t val)
Which could be macro'd for now as
uint2_t b = BITS(val, 3, 2);
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#32 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACBHVWLHNLSAXPGNMXRNPPTUFI3ONANCNFSM5FHSMUXA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Beta Was this translation helpful? Give feedback.
-
auto keyword proposal.
The "auto" keyword from C++ can be copied, for example:
uint2_t a, uint2_t b;
auto c = a+b;
Then c will be uint3_t
This would be useful for lots of things, for example for floating point
operator implementations that depends on compile-time calculated constants,
so the same algorithm is written only once for single and double precision
or also arbitrary exponent and mantissa precision.
This idea like others are again here for the a future implementation.
El lun., 4 oct. 2021 20:53, Victor Suarez Rovere ***@***.***>
escribió:
… I agree on everything, and liked your macro BITS(val, 3, 2). Maybe BITS(3,
2, val)? See below.
Additionally, I can provide a more syntax-sugarish implementation for C++
compilers like clang with a syntax as previously proposed: bits<3,2>(val),
equivalent to your macro. And hopefully we can tweak or replace the parser
to support that. The benefit is that with both forms we can use
compile-time constants that are next to a "must" to provide some
flexibility. Using template trickery (that I can write) we can offer some
compile-time calculations like detecting the most significant bit of a
constant, bit count, clog2 equivalent, "all ones" of some size, etc.
In regards to types, in C you have the basic types "char, int, long".
Their size is platform-dependent and never defined. In C++ you have the
additional "bool" value which is also platform dependent (you don't know
how many bits it has nor the values used, but in practice is like a char).
Then there are nonstandar compiler extensions like "long long" and the like.
Since such definitions has platform dependence (actually "indefinitions"),
there are handy typedefs in headers like stdint.h which provides uint32_t
and the like fixed-size types. They're fixed size, no possible extensions.
The extensibility proposed is mine (surely there are others that suggested
the same but I'm unaware).
On Mon, Oct 4, 2021 at 8:40 PM Julian Kemmerer ***@***.***>
wrote:
> Yeah I understand and that makes alot of sense especially for the
> unsigned case.
>
> So its currently:
> uint<Y-X+1>_t <type_prefix>_Y_X(<type> val)
> ex.uint2_t uint12_3_2(uint12_t val)
>
> Maybe something like this for 'assumed' input size based on the bit
> range. Make it so the uint12 isnt needed
>
> uint<Y-X+1>_t bits_Y_X(uint<Y+1>_t val)
> ex.uint2_t bits_3_2(uint4_t val)
> Which could be macro'd for now as
> uint2_t b = BITS(val, 3, 2);
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#32 (reply in thread)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ACBHVWLHNLSAXPGNMXRNPPTUFI3ONANCNFSM5FHSMUXA>
> .
> Triage notifications on the go with GitHub Mobile for iOS
> <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
> or Android
> <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
>
>
|
Beta Was this translation helpful? Give feedback.
-
I think I'm closer to template parsung or any C++ construct using Clang's
cindex than using a custom parser with unknown bugs...
El vie., 27 may. 2022 22:40, Julian Kemmerer ***@***.***>
escribió:
… How Metron emphasizes a very limited subset of C++ into a very limited
subset of Verilog makes me feel like it would be valuable to start with
above A) easy hacky parsing of template the hacky barely working ~ parses
like C++ templates but isnt fully handled C++ templates
That said - how hard would it be to add just like dumbest layer of
bits<Y,X>(num) syntax parsing to pycparser? Like @makslevental
<https://github.com/makslevental> pointed out to start - just give me
whatever strings are "Y" and "X" and hack from there
—
Reply to this email directly, view it on GitHub
<#32 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACBHVWMAD5SPO2HF4G6OBLLVMF2PHANCNFSM5FHSMUXA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Idea: support some C++ features.
Example instead of uint12_5_2(x) (extract bits 5 to 2 of a 12 bit value) one can write: bits<5,2>(x)
No need to address all C++ syntax but this way it would be better to keep a source compiled with a regular compiler and would be easier to parametrize constants. For example:
#define BITS 10
bits<BITS,0>(x);
Beta Was this translation helpful? Give feedback.
All reactions