* int vs uint
@ 2008-07-20 0:46 Jon Smirl
[not found] ` <9e4733910807191746oe5aca3av581bdc5cfab293c3-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
0 siblings, 1 reply; 6+ messages in thread
From: Jon Smirl @ 2008-07-20 0:46 UTC (permalink / raw)
To: Linux I2C
There are a lot places in the i2c API where int is used when the
parameter can't be negative. For example, there are more....
/*
* The master routines are the ones normally used to transmit data to devices
* on a bus (or read from them). Apart from two basic transfer functions to
* transmit one message at a time, a more complex version can be used to
* transmit an arbitrary number of messages without interruption.
*/
extern int i2c_master_send(struct i2c_client *,const char* ,int);
extern int i2c_master_recv(struct i2c_client *,char* ,int);
/* Transfer num messages.
*/
extern int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg
*msgs, int num);
u8 level; /* nesting level for lockdep */
Wouldn't these generate more efficient code if switched to uints?
--
Jon Smirl
jonsmirl-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c
^ permalink raw reply [flat|nested] 6+ messages in thread[parent not found: <9e4733910807191746oe5aca3av581bdc5cfab293c3-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: int vs uint [not found] ` <9e4733910807191746oe5aca3av581bdc5cfab293c3-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2008-07-20 16:23 ` Ben Dooks [not found] ` <20080720162356.GA8318-elnMNo+KYs3pIgCt6eIbzw@public.gmane.org> 0 siblings, 1 reply; 6+ messages in thread From: Ben Dooks @ 2008-07-20 16:23 UTC (permalink / raw) To: Jon Smirl; +Cc: Linux I2C On Sat, Jul 19, 2008 at 08:46:41PM -0400, Jon Smirl wrote: > There are a lot places in the i2c API where int is used when the > parameter can't be negative. For example, there are more.... > > /* > * The master routines are the ones normally used to transmit data to devices > * on a bus (or read from them). Apart from two basic transfer functions to > * transmit one message at a time, a more complex version can be used to > * transmit an arbitrary number of messages without interruption. > */ > extern int i2c_master_send(struct i2c_client *,const char* ,int); > extern int i2c_master_recv(struct i2c_client *,char* ,int); > > /* Transfer num messages. > */ > extern int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg > *msgs, int num); > > u8 level; /* nesting level for lockdep */ > > > Wouldn't these generate more efficient code if switched to uints? I'm not sure, most of the time there's not a lot of difference between the signed and unsigned case. If you can provide an example of where this is actually true then I would be interested to see... Technically, an unsigned int or simply an unsigned would be a reasonable change given that you can't really have a minus number of transfers. -- Ben (ben-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org, http://www.fluff.org/) 'a smiley only costs 4 bytes' _______________________________________________ i2c mailing list i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org http://lists.lm-sensors.org/mailman/listinfo/i2c ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <20080720162356.GA8318-elnMNo+KYs3pIgCt6eIbzw@public.gmane.org>]
* Re: int vs uint [not found] ` <20080720162356.GA8318-elnMNo+KYs3pIgCt6eIbzw@public.gmane.org> @ 2008-07-20 16:44 ` Jon Smirl [not found] ` <9e4733910807200944m71728a9eldd5a9099ff2829a5-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 6+ messages in thread From: Jon Smirl @ 2008-07-20 16:44 UTC (permalink / raw) To: Ben Dooks; +Cc: Linux I2C On 7/20/08, Ben Dooks <ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org> wrote: > On Sat, Jul 19, 2008 at 08:46:41PM -0400, Jon Smirl wrote: > > There are a lot places in the i2c API where int is used when the > > parameter can't be negative. For example, there are more.... > > > > /* > > * The master routines are the ones normally used to transmit data to devices > > * on a bus (or read from them). Apart from two basic transfer functions to > > * transmit one message at a time, a more complex version can be used to > > * transmit an arbitrary number of messages without interruption. > > */ > > extern int i2c_master_send(struct i2c_client *,const char* ,int); > > extern int i2c_master_recv(struct i2c_client *,char* ,int); > > > > /* Transfer num messages. > > */ > > extern int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg > > *msgs, int num); > > > > u8 level; /* nesting level for lockdep */ > > > > > > Wouldn't these generate more efficient code if switched to uints? > > > I'm not sure, most of the time there's not a lot of difference > between the signed and unsigned case. If you can provide an example > of where this is actually true then I would be interested to see... Assigning between lengths causes sign extended instructions. Mixing signed and unsigned in expressions can cause them too. You get the best code generation by using int or unsigned int as appropriate and supplying the compiler with the correct description of the variable. > > Technically, an unsigned int or simply an unsigned would be a > reasonable change given that you can't really have a minus number > of transfers. > > > -- > Ben (ben-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org, http://www.fluff.org/) > > 'a smiley only costs 4 bytes' > -- Jon Smirl jonsmirl-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org _______________________________________________ i2c mailing list i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org http://lists.lm-sensors.org/mailman/listinfo/i2c ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <9e4733910807200944m71728a9eldd5a9099ff2829a5-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: int vs uint [not found] ` <9e4733910807200944m71728a9eldd5a9099ff2829a5-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2008-07-20 16:47 ` Jon Smirl [not found] ` <9e4733910807200947t7abeb0f3i8217766b5392096a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 6+ messages in thread From: Jon Smirl @ 2008-07-20 16:47 UTC (permalink / raw) To: Ben Dooks; +Cc: Linux I2C On 7/20/08, Jon Smirl <jonsmirl-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > On 7/20/08, Ben Dooks <ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org> wrote: > > On Sat, Jul 19, 2008 at 08:46:41PM -0400, Jon Smirl wrote: > > > There are a lot places in the i2c API where int is used when the > > > parameter can't be negative. For example, there are more.... > > > > > > /* > > > * The master routines are the ones normally used to transmit data to devices > > > * on a bus (or read from them). Apart from two basic transfer functions to > > > * transmit one message at a time, a more complex version can be used to > > > * transmit an arbitrary number of messages without interruption. > > > */ > > > extern int i2c_master_send(struct i2c_client *,const char* ,int); > > > extern int i2c_master_recv(struct i2c_client *,char* ,int); > > > > > > /* Transfer num messages. > > > */ > > > extern int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg > > > *msgs, int num); > > > > > > u8 level; /* nesting level for lockdep */ > > > > > > > > > Wouldn't these generate more efficient code if switched to uints? > > > > > > I'm not sure, most of the time there's not a lot of difference > > between the signed and unsigned case. If you can provide an example > > of where this is actually true then I would be interested to see... > > > Assigning between lengths causes sign extended instructions. Mixing > signed and unsigned in expressions can cause them too. > > You get the best code generation by using int or unsigned int as > appropriate and supplying the compiler with the correct description of > the variable. The compiler is also able to catch more errors. If the math can only yield a negative result and it is being compared to a unsigned int, you'll get compiler errors like " expression is constant". > > > > > > Technically, an unsigned int or simply an unsigned would be a > > reasonable change given that you can't really have a minus number > > of transfers. > > > > > > -- > > Ben (ben-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org, http://www.fluff.org/) > > > > 'a smiley only costs 4 bytes' > > > > > > -- > Jon Smirl > jonsmirl-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > -- Jon Smirl jonsmirl-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org _______________________________________________ i2c mailing list i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org http://lists.lm-sensors.org/mailman/listinfo/i2c ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <9e4733910807200947t7abeb0f3i8217766b5392096a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: int vs uint [not found] ` <9e4733910807200947t7abeb0f3i8217766b5392096a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2008-07-21 9:48 ` Ben Dooks [not found] ` <20080721094838.GB8318-elnMNo+KYs3pIgCt6eIbzw@public.gmane.org> 0 siblings, 1 reply; 6+ messages in thread From: Ben Dooks @ 2008-07-21 9:48 UTC (permalink / raw) To: Jon Smirl; +Cc: Linux I2C, Ben Dooks On Sun, Jul 20, 2008 at 12:47:38PM -0400, Jon Smirl wrote: > On 7/20/08, Jon Smirl <jonsmirl-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > On 7/20/08, Ben Dooks <ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org> wrote: > > > On Sat, Jul 19, 2008 at 08:46:41PM -0400, Jon Smirl wrote: > > > > There are a lot places in the i2c API where int is used when the > > > > parameter can't be negative. For example, there are more.... > > > > > > > > /* > > > > * The master routines are the ones normally used to transmit data to devices > > > > * on a bus (or read from them). Apart from two basic transfer functions to > > > > * transmit one message at a time, a more complex version can be used to > > > > * transmit an arbitrary number of messages without interruption. > > > > */ > > > > extern int i2c_master_send(struct i2c_client *,const char* ,int); > > > > extern int i2c_master_recv(struct i2c_client *,char* ,int); > > > > > > > > /* Transfer num messages. > > > > */ > > > > extern int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg > > > > *msgs, int num); > > > > > > > > u8 level; /* nesting level for lockdep */ > > > > > > > > > > > > Wouldn't these generate more efficient code if switched to uints? > > > > > > > > > I'm not sure, most of the time there's not a lot of difference > > > between the signed and unsigned case. If you can provide an example > > > of where this is actually true then I would be interested to see... > > > > > > Assigning between lengths causes sign extended instructions. Mixing > > signed and unsigned in expressions can cause them too. Entirely dependant on the architecture, so very rarely see anything like this happening on ARM. > > You get the best code generation by using int or unsigned int as > > appropriate and supplying the compiler with the correct description of > > the variable. > > The compiler is also able to catch more errors. If the math can only > yield a negative result and it is being compared to a unsigned int, > you'll get compiler errors like " expression is constant". The compiler checking argument is the most compelling of these, are you offering to do the necessary changes, or is this fishing to find someone else to do it? -- Ben (ben-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org, http://www.fluff.org/) 'a smiley only costs 4 bytes' _______________________________________________ i2c mailing list i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org http://lists.lm-sensors.org/mailman/listinfo/i2c ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <20080721094838.GB8318-elnMNo+KYs3pIgCt6eIbzw@public.gmane.org>]
* Re: int vs uint [not found] ` <20080721094838.GB8318-elnMNo+KYs3pIgCt6eIbzw@public.gmane.org> @ 2008-07-21 14:26 ` Jon Smirl 0 siblings, 0 replies; 6+ messages in thread From: Jon Smirl @ 2008-07-21 14:26 UTC (permalink / raw) To: Ben Dooks; +Cc: Linux I2C On 7/21/08, Ben Dooks <ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org> wrote: > On Sun, Jul 20, 2008 at 12:47:38PM -0400, Jon Smirl wrote: > > On 7/20/08, Jon Smirl <jonsmirl-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On 7/20/08, Ben Dooks <ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org> wrote: > > > > On Sat, Jul 19, 2008 at 08:46:41PM -0400, Jon Smirl wrote: > > > > > There are a lot places in the i2c API where int is used when the > > > > > parameter can't be negative. For example, there are more.... > > > > > > > > > > /* > > > > > * The master routines are the ones normally used to transmit data to devices > > > > > * on a bus (or read from them). Apart from two basic transfer functions to > > > > > * transmit one message at a time, a more complex version can be used to > > > > > * transmit an arbitrary number of messages without interruption. > > > > > */ > > > > > extern int i2c_master_send(struct i2c_client *,const char* ,int); > > > > > extern int i2c_master_recv(struct i2c_client *,char* ,int); > > > > > > > > > > /* Transfer num messages. > > > > > */ > > > > > extern int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg > > > > > *msgs, int num); > > > > > > > > > > u8 level; /* nesting level for lockdep */ > > > > > > > > > > > > > > > Wouldn't these generate more efficient code if switched to uints? > > > > > > > > > > > > I'm not sure, most of the time there's not a lot of difference > > > > between the signed and unsigned case. If you can provide an example > > > > of where this is actually true then I would be interested to see... > > > > > > > > > Assigning between lengths causes sign extended instructions. Mixing > > > signed and unsigned in expressions can cause them too. > > > Entirely dependant on the architecture, so very rarely see anything > like this happening on ARM. > > > > > You get the best code generation by using int or unsigned int as > > > appropriate and supplying the compiler with the correct description of > > > the variable. > > > > The compiler is also able to catch more errors. If the math can only > > yield a negative result and it is being compared to a unsigned int, > > you'll get compiler errors like " expression is constant". > > > The compiler checking argument is the most compelling of these, are > you offering to do the necessary changes, or is this fishing to find > someone else to do it? Fishing. Changes like these go a lot smoother if one of the maintainers do them. Doing them as an outside patch will a generate a pile of merge conflicts with other patches made during the cycle. I'd just like to see the i2c interface be as accurate as possible. It is clear that some of those ints should be uints. > > > -- > > Ben (ben-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org, http://www.fluff.org/) > > 'a smiley only costs 4 bytes' > -- Jon Smirl jonsmirl-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org _______________________________________________ i2c mailing list i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org http://lists.lm-sensors.org/mailman/listinfo/i2c ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2008-07-21 14:26 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-20 0:46 int vs uint Jon Smirl
[not found] ` <9e4733910807191746oe5aca3av581bdc5cfab293c3-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-07-20 16:23 ` Ben Dooks
[not found] ` <20080720162356.GA8318-elnMNo+KYs3pIgCt6eIbzw@public.gmane.org>
2008-07-20 16:44 ` Jon Smirl
[not found] ` <9e4733910807200944m71728a9eldd5a9099ff2829a5-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-07-20 16:47 ` Jon Smirl
[not found] ` <9e4733910807200947t7abeb0f3i8217766b5392096a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-07-21 9:48 ` Ben Dooks
[not found] ` <20080721094838.GB8318-elnMNo+KYs3pIgCt6eIbzw@public.gmane.org>
2008-07-21 14:26 ` Jon Smirl
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox