public inbox for jit@gcc.gnu.org
 help / color / mirror / Atom feed
* Question on libgccjit
@ 2023-03-20 19:16 Li, Yicheng
  0 siblings, 0 replies; 3+ messages in thread
From: Li, Yicheng @ 2023-03-20 19:16 UTC (permalink / raw)
  To: jit

[-- Attachment #1: Type: text/plain, Size: 333 bytes --]

Hi,

How to do pointer arithmetic in libgccjit?
I created a pointer type (char *) and an integer type (int or size_t or long).
When I use gcc_jit_context_binary_op with GCC_JIT_BINARY_OP_PLUS, it’s giving me error as mismatching types of (char*) and (int).
Is pointer arithmetic viable in libgccjit?

Thank you
Yicheng Li

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Question on libgccjit
  2023-03-20 19:38     ` Li, Yicheng
@ 2023-03-20 23:23       ` David Malcolm
  0 siblings, 0 replies; 3+ messages in thread
From: David Malcolm @ 2023-03-20 23:23 UTC (permalink / raw)
  To: Li, Yicheng, Basile Starynkevitch, jit

On Mon, 2023-03-20 at 19:38 +0000, Li, Yicheng via Jit wrote:
> Hi,
> 
> Here’s the question for libgccjit on pointer arithmetic.
> There’s error for type mismatching with char* and int.
> Please see full code at https://github.com/yli137/libgccjit_test
> 

GCC_JIT_BINARY_OP_PLUS doesn't properly work on pointers; libgccjit
currently requires you to express pointer arithmetic as an array
access; see:
https://gcc.gnu.org/onlinedocs/jit/topics/expressions.html#c.GCC_JIT_BINARY_OP_PLUS

Sorry that this is a bit clunky.
Dave


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Question on libgccjit
       [not found]   ` <f942f395-42b5-18cd-45a8-433437fcf752@starynkevitch.net>
@ 2023-03-20 19:38     ` Li, Yicheng
  2023-03-20 23:23       ` David Malcolm
  0 siblings, 1 reply; 3+ messages in thread
From: Li, Yicheng @ 2023-03-20 19:38 UTC (permalink / raw)
  To: Basile Starynkevitch, jit

[-- Attachment #1: Type: text/plain, Size: 5635 bytes --]

Hi,

Here’s the question for libgccjit on pointer arithmetic.
There’s error for type mismatching with char* and int.
Please see full code at https://github.com/yli137/libgccjit_test

Thank you
Yicheng Li

On Mar 20, 2023, at 3:32 PM, Basile Starynkevitch <basile@starynkevitch.net> wrote:

You don't often get email from basile@starynkevitch.net. Learn why this is important<https://aka.ms/LearnAboutSenderIdentification>

Improve your C code to have a full routine or program, then post it on the mailing list


(better yet, make your code open source on https://github.com/<https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2F&data=05%7C01%7Cyli137%40vols.utk.edu%7C56c5ed9bacfc42fcb34f08db2979e24b%7C515813d9717d45dd9eca9aa19c09d6f9%7C0%7C0%7C638149375644128233%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=aRcP%2BN%2Bldsmdob1Y%2B9c2I7nZ431o64M71CUa88Z3aAE%3D&reserved=0> ....)


On 20/03/2023 20:30, Li, Yicheng wrote:
Hi,

Here’s the code in C.
Basically, I have two params, both in char *.
And I want to do pointer arithmetic on them.

    gcc_jit_type *char_type, *char_ptr_type,, *sizet_type, *int_type;
    char_type = gcc_jit_context_get_type( ctxt, GCC_JIT_TYPE_CHAR );
    sizet_type = gcc_jit_context_get_type( ctxt, GCC_JIT_TYPE_SIZE_T );
    int_type = gcc_jit_context_get_type( ctxt, GCC_JIT_TYPE_INT );
    char_ptr_type = gcc_jit_type_get_pointer( char_type );

    gcc_jit_lvalue *dst_val = gcc_jit_function_new_local( func, NULL, char_ptr_type, "dst_val" ),
                   *src_val = gcc_jit_function_new_local( func, NULL, char_ptr_type, "src_val” );


    gcc_jit_block_add_assignment( block, NULL, dst_val, gcc_jit_param_as_rvalue( param[0] ) );
    gcc_jit_block_add_assignment( block, NULL, src_val, gcc_jit_param_as_rvalue( param[1] ) );

    gcc_jit_context_new_binary_op( ctxt, NULL,
            GCC_JIT_BINARY_OP_PLUS,
            char_ptr_type,
            gcc_jit_lvalue_as_rvalue( dst_val ),
            gcc_jit_context_new_rvalue_from_long( ctxt, sizet_type, 10 ) );

        gcc_jit_context_new_binary_op( ctxt, NULL,
            GCC_JIT_BINARY_OP_PLUS,
            char_ptr_type,
            gcc_jit_lvalue_as_rvalue( src_val ),
            gcc_jit_context_new_rvalue_from_long( ctxt, sizet_type, 10 ) );

The error is follows:
libgccjit.so: error: gcc_jit_context_new_binary_op: mismatching types for binary op: a: dst_val (type: char *) b: (size_t)0 (type: size_t)

libgccjit.so: error: gcc_jit_context_new_binary_op: mismatching types for binary op: a: src_val (type: char *) b: (size_t)0 (type: size_t)

Thank you
Yicheng Li


On Mar 20, 2023, at 3:24 PM, Basile Starynkevitch <basile@starynkevitch.net><mailto:basile@starynkevitch.net> wrote:


You don't often get email from basile@starynkevitch.net<mailto:basile@starynkevitch.net>. Learn why this is important<https://aka.ms/LearnAboutSenderIdentification>

You asked

> > How to do pointer arithmetic in libgccjit? I created a pointer type > (char *) and an integer type (int or size_t or long). When I use > gcc_jit_context_binary_op with GCC_JIT_BINARY_OP_PLUS, it’s giving me > error as mismatching types of (char*) and (int). Is pointer > arithmetic viable in libgccjit?


but I recommend to show some real C++ code in your question.... And the warnings you obtained.

BTW, you can construct pointer types in GCCJIT.

gcc_jit_type_get_pointer


Alternatively, generate some temporary C code and use GCC to compile it as a plugin


(see https://arxiv.org/abs/1109.0779v1<https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Farxiv.org%2Fabs%2F1109.0779v1&data=05%7C01%7Cyli137%40vols.utk.edu%7C56c5ed9bacfc42fcb34f08db2979e24b%7C515813d9717d45dd9eca9aa19c09d6f9%7C0%7C0%7C638149375644128233%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=LhxvKqPpyX8SdNHWd4IJpMRIfvW2EO4VQEEnmDxC8iM%3D&reserved=0> - it used to work)

My pet open source project is http://refpersys.org/<https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Frefpersys.org%2F&data=05%7C01%7Cyli137%40vols.utk.edu%7C56c5ed9bacfc42fcb34f08db2979e24b%7C515813d9717d45dd9eca9aa19c09d6f9%7C0%7C0%7C638149375644128233%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=b4zkXama7Lom4T7HUQxBlUZsu%2FHmu1QQqTofi51SLM0%3D&reserved=0> (inference engine) and we hope to generate code from higher level rules, like explained in Jacques Pitrat(s last book.

https://en.wikipedia.org/wiki/Jacques_Pitrat<https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FJacques_Pitrat&data=05%7C01%7Cyli137%40vols.utk.edu%7C56c5ed9bacfc42fcb34f08db2979e24b%7C515813d9717d45dd9eca9aa19c09d6f9%7C0%7C0%7C638149375644284457%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=aJ%2F%2BYj7SYHSW2iA0ZJMq9JHbh2dujbUYHqRbT6j7YhY%3D&reserved=0>

Regards

--
Basile Starynkevitch                  <basile@starynkevitch.net><mailto:basile@starynkevitch.net>
(only mine opinions / les opinions sont miennes uniquement)
92340 Bourg-la-Reine, France
web page: starynkevitch.net/Basile/ & refpersys.org




--
Basile Starynkevitch                  <basile@starynkevitch.net><mailto:basile@starynkevitch.net>
(only mine opinions / les opinions sont miennes uniquement)
92340 Bourg-la-Reine, France
web page: starynkevitch.net/Basile/ & refpersys.org




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-03-20 23:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-20 19:16 Question on libgccjit Li, Yicheng
     [not found] <4895236c-a56f-a8aa-d581-476e3072f72c@starynkevitch.net>
     [not found] ` <AFDF0F71-5CB3-47A0-95FF-2E23877F3DE7@vols.utk.edu>
     [not found]   ` <f942f395-42b5-18cd-45a8-433437fcf752@starynkevitch.net>
2023-03-20 19:38     ` Li, Yicheng
2023-03-20 23:23       ` David Malcolm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).