Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: Comparing Arbitrary-Precision Integers

Reply
Thread Tools

Re: Comparing Arbitrary-Precision Integers

 
 
Eric Sosman
Guest
Posts: n/a
 
      07-26-2012
On 7/26/2012 4:06 PM, David T. Ashley wrote:
> Hi,
>
> I'm using a 2's complement machine (and I'm comfortable baking this
> assumption into the code). I've implemented a large number of
> functions on signed integers that are longer than the machine
> supports.
>
> Does the code below for comparison look correct?


Looks plausible.

> typedef union
> {
> UNSIGNED32_T uw[3];
> SIGNED32_T sw[3];
> } APP_BIGINT_S96_T;


You may need to be vigilant about the type-punning here.
I think you're all right as long as you deal in pointers to the
union type itself, but it'd be a good idea to avoid passing
around pointers to the uw and sw members independently. Some
compiler might reason "Storing through this `unsigned int*'
cannot affect the value I've already loaded from this other
`signed int*' ..." (Disclaimer: Aliasing rules are slipperier
than my grasp is firm, and I may be worrying about nothing. But
if I were you I'd put a Bar-certified language lawyer on retainer.)

> //REENTRANCY
> // This function has not been evaluated for re-entrancy or thread
> safety. This function is
> // designed to be called from background (non-ISR) software only.


There cannot be reentrancy problems, since the function cannot
be re-entered. I see no concurrency issues in the function itself;
you need only ensure that the bigints aren't being changed while
you're in the act of inspecting them. The ISR restriction seems
irrelevant.

> //UNIT TEST HISTORY
> // 20120713: Not yet unit tested.


I trust you've remedied this in the last two weeks ...

--
Eric Sosman
d
 
Reply With Quote
 
 
 
 
Tim Rentsch
Guest
Posts: n/a
 
      09-07-2012
Eric Sosman <> writes:

> On 7/26/2012 4:06 PM, David T. Ashley wrote:
>> Hi,
>>
>> I'm using a 2's complement machine (and I'm comfortable baking this
>> assumption into the code). I've implemented a large number of
>> functions on signed integers that are longer than the machine
>> supports.
>>
>> Does the code below for comparison look correct?

>
> Looks plausible.
>
>> typedef union
>> {
>> UNSIGNED32_T uw[3];
>> SIGNED32_T sw[3];
>> } APP_BIGINT_S96_T;

>
> You may need to be vigilant about the type-punning here.
> I think you're all right as long as you deal in pointers to the
> union type itself, but it'd be a good idea to avoid passing
> around pointers to the uw and sw members independently. Some
> compiler might reason "Storing through this `unsigned int*'
> cannot affect the value I've already loaded from this other
> `signed int*' ..." (Disclaimer: Aliasing rules are slipperier
> than my grasp is firm, [snip elaboration]


The types signed/unsigned int are always allowed to alias, as are
all other corresponding pairs of signed/unsigned integer types.

However, it would be worth checking to see if gcc's 'strict-aliasing'
option may violate this rule (and possibly generate non-conforming
code as a result).
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
comparing two arrays of integers. Nag Java 3 06-23-2005 06:16 PM
comparing strings and integers beliavsky@aol.com Python 5 05-20-2004 03:55 PM
comparing long integers Elijah Bailey C++ 12 01-23-2004 03:47 PM
comparing long integers Elijah Bailey C Programming 11 01-23-2004 03:47 PM
Comparing char* with integers and characters Nicholas C Programming 13 09-09-2003 03:04 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57