Last active
January 23, 2026 06:44
-
-
Save cgm999/ad8c800a8d2f7b00f45a2fc690ec3657 to your computer and use it in GitHub Desktop.
Weird issue with compiled C code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdint.h> | |
| uint16_t find_inv(uint16_t a) { | |
| uint16_t inv = 1; | |
| for (int i = 0; i < 16; i++) inv *= 2 - a * inv; | |
| return inv; | |
| } | |
| uint16_t mul_a,mul_a_inv; | |
| uint16_t encode(uint16_t x) { return mul_a*x; } | |
| uint16_t decode(uint16_t x) { return x * mul_a_inv; } | |
| int main() { | |
| for(int i=65535;i;i--) { | |
| mul_a = i; | |
| mul_a_inv = find_inv(i); | |
| if(i&1) { | |
| printf("checking i=%d\n",i); | |
| for(int j=65535;j;j--) { | |
| uint16_t rev_j = decode(encode(j)); | |
| if(j!=rev_j) printf("i=%d bad rev for j=%d\n",i,j); | |
| } | |
| } | |
| } | |
| return 0; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
some weirdness related to how fast code is executed..
Why is gcc compiled code perform worse?