Skip to content
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

Section 3.3: ambiguous code and statements to fix #193

Open
Andre1206 opened this issue Nov 23, 2022 · 0 comments
Open

Section 3.3: ambiguous code and statements to fix #193

Andre1206 opened this issue Nov 23, 2022 · 0 comments

Comments

@Andre1206
Copy link

Another, more complicated way to implement this whole sequence is to convert this sign bit into a mask and then use bitwise and instead of multiplication: ((a[i] - 50) >> 31 - 1) & a[i].

First, in the C language the minus operation has higher priority than the >> operation, hence that code is equivalent to ((a[i] - 50) >> 30) & a[i] and thus is not consistent with the assembly language code shown below.
Second, as mentioned in Section 4.4, the result of the >> operation on negative integer depends on the implementation, which is not specified in Section 3.3. Let us consider the following 2 cases:
Case 1. If the leftmost bit is extended: then ((a[i]-50)>>31) is -1 when a[i]<50 (ignoring underflow) and is 0 when a[i]>=50. Therefore there is no need of the -1 after 31 at all.
Case 2. If the leftmost bit is filled with 0: Then (a[i] - 50) >> 31 does get the sign bit of a[i]-50. In this case, (((a[i] - 50) >> 31) - 1) is 0 when a[i]<50 and is -1 when a[i]>=50. This is the reverse of what we want here: We want a '-1' when 'a[i]<50' and a '0' when 'a[i]>=50'.

To sum up, I think this part is pretty confusing and need to be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant