1f08c3bdfSopenharmony_ciint simple(int s, unsigned int u, int p) 2f08c3bdfSopenharmony_ci{ 3f08c3bdfSopenharmony_ci s = s >> 100; 4f08c3bdfSopenharmony_ci u = u >> 101; 5f08c3bdfSopenharmony_ci u = u << 102; 6f08c3bdfSopenharmony_ci s = s >> -1; 7f08c3bdfSopenharmony_ci u = u >> -2; 8f08c3bdfSopenharmony_ci u = u << -3; 9f08c3bdfSopenharmony_ci if (0) return s >> 103; 10f08c3bdfSopenharmony_ci if (0) return u >> 104; 11f08c3bdfSopenharmony_ci if (0) return u << 105; 12f08c3bdfSopenharmony_ci if (0) return s >> -4; 13f08c3bdfSopenharmony_ci if (0) return u >> -5; 14f08c3bdfSopenharmony_ci if (0) return u << -6; 15f08c3bdfSopenharmony_ci if (p && 0) return s >> 106; 16f08c3bdfSopenharmony_ci if (p && 0) return u >> 107; 17f08c3bdfSopenharmony_ci if (p && 0) return u << 108; 18f08c3bdfSopenharmony_ci if (p && 0) return s >> -7; 19f08c3bdfSopenharmony_ci if (p && 0) return u >> -8; 20f08c3bdfSopenharmony_ci if (p && 0) return u << -9; 21f08c3bdfSopenharmony_ci s = s >> ((p & 0) + 109); u ^= p; // reloaded because now == 0 22f08c3bdfSopenharmony_ci u = u >> ((p & 0) + 110); u ^= p; // reloaded because now == 0 23f08c3bdfSopenharmony_ci u = u << ((p & 0) + 111); u ^= p; // reloaded because now == 0 24f08c3bdfSopenharmony_ci s = s >> ((p & 0) + -10); 25f08c3bdfSopenharmony_ci u = u >> ((p & 0) + -11); u ^= p; // reloaded because now == 0 26f08c3bdfSopenharmony_ci u = u << ((p & 0) + -12); u ^= p; // reloaded because now == 0 27f08c3bdfSopenharmony_ci return s + u; 28f08c3bdfSopenharmony_ci} 29f08c3bdfSopenharmony_ci 30f08c3bdfSopenharmony_ciint compound(int s, unsigned int u, int p) 31f08c3bdfSopenharmony_ci{ 32f08c3bdfSopenharmony_ci s >>= 100; 33f08c3bdfSopenharmony_ci u >>= 101; 34f08c3bdfSopenharmony_ci u <<= 102; 35f08c3bdfSopenharmony_ci s >>= -1; 36f08c3bdfSopenharmony_ci u >>= -2; 37f08c3bdfSopenharmony_ci u <<= -3; 38f08c3bdfSopenharmony_ci if (0) return s >>= 103; 39f08c3bdfSopenharmony_ci if (0) return u >>= 104; 40f08c3bdfSopenharmony_ci if (0) return u <<= 105; 41f08c3bdfSopenharmony_ci if (0) return s >>= -4; 42f08c3bdfSopenharmony_ci if (0) return u >>= -5; 43f08c3bdfSopenharmony_ci if (0) return u <<= -6; 44f08c3bdfSopenharmony_ci if (p && 0) return s >>= 106; 45f08c3bdfSopenharmony_ci if (p && 0) return u >>= 107; 46f08c3bdfSopenharmony_ci if (p && 0) return u <<= 108; 47f08c3bdfSopenharmony_ci if (p && 0) return s >>= -7; 48f08c3bdfSopenharmony_ci if (p && 0) return u >>= -8; 49f08c3bdfSopenharmony_ci if (p && 0) return u <<= -9; 50f08c3bdfSopenharmony_ci s >>= ((p & 0) + 109); u ^= p; // reloaded because now == 0 51f08c3bdfSopenharmony_ci u >>= ((p & 0) + 110); u ^= p; // reloaded because now == 0 52f08c3bdfSopenharmony_ci u <<= ((p & 0) + 111); u ^= p; // reloaded because now == 0 53f08c3bdfSopenharmony_ci s >>= ((p & 0) + -10); 54f08c3bdfSopenharmony_ci u >>= ((p & 0) + -11); u ^= p; // reloaded because now == 0 55f08c3bdfSopenharmony_ci u <<= ((p & 0) + -12); u ^= p; // reloaded because now == 0 56f08c3bdfSopenharmony_ci return s + u; 57f08c3bdfSopenharmony_ci} 58f08c3bdfSopenharmony_ci 59f08c3bdfSopenharmony_ciint ok(int s, unsigned int u, int p) 60f08c3bdfSopenharmony_ci{ 61f08c3bdfSopenharmony_ci // GCC doesn't warn on these 62f08c3bdfSopenharmony_ci if (0 && (s >> 100)) return 0; 63f08c3bdfSopenharmony_ci if (0 && (u >> 101)) return 0; 64f08c3bdfSopenharmony_ci if (0 && (u << 102)) return 0; 65f08c3bdfSopenharmony_ci if (0 && (s >> -1)) return 0; 66f08c3bdfSopenharmony_ci if (0 && (u >> -2)) return 0; 67f08c3bdfSopenharmony_ci if (0 && (u << -3)) return 0; 68f08c3bdfSopenharmony_ci if (0 && (s >>= 103)) return 0; 69f08c3bdfSopenharmony_ci if (0 && (u >>= 104)) return 0; 70f08c3bdfSopenharmony_ci if (0 && (u <<= 105)) return 0; 71f08c3bdfSopenharmony_ci if (0 && (s >>= -4)) return 0; 72f08c3bdfSopenharmony_ci if (0 && (u >>= -5)) return 0; 73f08c3bdfSopenharmony_ci if (0 && (u <<= -6)) return 0; 74f08c3bdfSopenharmony_ci return 1; 75f08c3bdfSopenharmony_ci} 76f08c3bdfSopenharmony_ci 77f08c3bdfSopenharmony_cistruct bf { 78f08c3bdfSopenharmony_ci unsigned int u:8; 79f08c3bdfSopenharmony_ci int s:8; 80f08c3bdfSopenharmony_ci}; 81f08c3bdfSopenharmony_ci 82f08c3bdfSopenharmony_ciint bf(struct bf *p) 83f08c3bdfSopenharmony_ci{ 84f08c3bdfSopenharmony_ci unsigned int r = 0; 85f08c3bdfSopenharmony_ci r += p->s << 8; 86f08c3bdfSopenharmony_ci r += p->s >> 8; 87f08c3bdfSopenharmony_ci r += p->u >> 8; 88f08c3bdfSopenharmony_ci return r; 89f08c3bdfSopenharmony_ci} 90f08c3bdfSopenharmony_ci 91f08c3bdfSopenharmony_ci/* 92f08c3bdfSopenharmony_ci * The following is used in the kernel at several places 93f08c3bdfSopenharmony_ci * It shouldn't emit any warnings. 94f08c3bdfSopenharmony_ci */ 95f08c3bdfSopenharmony_citypedef unsigned long long u64; 96f08c3bdfSopenharmony_citypedef unsigned int u32; 97f08c3bdfSopenharmony_ci 98f08c3bdfSopenharmony_ciextern void hw_w32x2(u32 hi, u32 lo); 99f08c3bdfSopenharmony_ci 100f08c3bdfSopenharmony_ciinline void hw_w64(u64 val) 101f08c3bdfSopenharmony_ci{ 102f08c3bdfSopenharmony_ci hw_w32x2(val >> 32, (u32) val); 103f08c3bdfSopenharmony_ci} 104f08c3bdfSopenharmony_ci 105f08c3bdfSopenharmony_civoid hw_write(u32 val) 106f08c3bdfSopenharmony_ci{ 107f08c3bdfSopenharmony_ci hw_w64(val); 108f08c3bdfSopenharmony_ci} 109f08c3bdfSopenharmony_ci 110f08c3bdfSopenharmony_ci/* 111f08c3bdfSopenharmony_ci * check-name: shift too big or negative 112f08c3bdfSopenharmony_ci * check-command: sparse -Wno-decl $file 113f08c3bdfSopenharmony_ci * 114f08c3bdfSopenharmony_ci * check-error-start 115f08c3bdfSopenharmony_cishift-undef.c:3:18: warning: shift too big (100) for type int 116f08c3bdfSopenharmony_cishift-undef.c:4:18: warning: shift too big (101) for type unsigned int 117f08c3bdfSopenharmony_cishift-undef.c:5:18: warning: shift too big (102) for type unsigned int 118f08c3bdfSopenharmony_cishift-undef.c:6:19: warning: shift count is negative (-1) 119f08c3bdfSopenharmony_cishift-undef.c:7:19: warning: shift count is negative (-2) 120f08c3bdfSopenharmony_cishift-undef.c:8:19: warning: shift count is negative (-3) 121f08c3bdfSopenharmony_cishift-undef.c:21:29: warning: shift too big (109) for type int 122f08c3bdfSopenharmony_cishift-undef.c:22:29: warning: shift too big (110) for type unsigned int 123f08c3bdfSopenharmony_cishift-undef.c:23:29: warning: shift too big (111) for type unsigned int 124f08c3bdfSopenharmony_cishift-undef.c:24:29: warning: shift count is negative (-10) 125f08c3bdfSopenharmony_cishift-undef.c:25:29: warning: shift count is negative (-11) 126f08c3bdfSopenharmony_cishift-undef.c:26:29: warning: shift count is negative (-12) 127f08c3bdfSopenharmony_cishift-undef.c:32:15: warning: shift too big (100) for type int 128f08c3bdfSopenharmony_cishift-undef.c:33:15: warning: shift too big (101) for type unsigned int 129f08c3bdfSopenharmony_cishift-undef.c:34:15: warning: shift too big (102) for type unsigned int 130f08c3bdfSopenharmony_cishift-undef.c:35:16: warning: shift count is negative (-1) 131f08c3bdfSopenharmony_cishift-undef.c:36:16: warning: shift count is negative (-2) 132f08c3bdfSopenharmony_cishift-undef.c:37:16: warning: shift count is negative (-3) 133f08c3bdfSopenharmony_cishift-undef.c:50:26: warning: shift too big (109) for type int 134f08c3bdfSopenharmony_cishift-undef.c:51:26: warning: shift too big (110) for type unsigned int 135f08c3bdfSopenharmony_cishift-undef.c:52:26: warning: shift too big (111) for type unsigned int 136f08c3bdfSopenharmony_cishift-undef.c:53:26: warning: shift count is negative (-10) 137f08c3bdfSopenharmony_cishift-undef.c:54:26: warning: shift count is negative (-11) 138f08c3bdfSopenharmony_cishift-undef.c:55:26: warning: shift count is negative (-12) 139f08c3bdfSopenharmony_ci * check-error-end 140f08c3bdfSopenharmony_ci */ 141