Commit 36ccf43c authored by Matthias Braun's avatar Matthias Braun
Browse files

bitop,shift,constant test

[r20477]
parent 8afe079f
int printf(const char *str, ...);
#define T unsigned
#define tname(x) u_##x
#include "shiftconst.h"
#undef tname
#undef T
#define T int
#define tname(x) i_##x
#include "shiftconst.h"
#undef tname
#undef T
#define T long long
#define tname(x) ll_##x
#include "shiftconst.h"
#undef tname
#undef T
#define T signed char
#define tname(x) sc_##x
#include "shiftconst.h"
#undef tname
#undef T
int main(void)
{
#define TEST(x) printf(#x "(0xAABBCCDD) = 0x%X\n", x(0xAABBCCDD))
#define ALLTESTS(pf) \
TEST(pf##k1); \
TEST(pf##k2); \
TEST(pf##k3); \
TEST(pf##k4); \
TEST(pf##k5); \
TEST(pf##k6); \
TEST(pf##k7); \
TEST(pf##k8);
ALLTESTS(u_);
ALLTESTS(i_);
ALLTESTS(ll_);
ALLTESTS(sc_);
return 0;
}
T tname(k1) (T x) {
return (x << 5) >> 24;
}
T tname(k2) (T x) {
return (x >> 5) << 24;
}
T tname(k3) (T x) {
return (x << 20) >> 20;
}
T tname(k4) (T x) {
return (x & 0xfff0) >> 8;
}
T tname(k5) (T x) {
unsigned short l = 24;
return (x << 5) >> l;
}
T tname(k6) (T x) {
return (x & 0xff) >> 8;
}
T tname(k7) (T x) {
return (x >> 10) << 5;
}
T tname(k8) (T x) {
return (x >> 10) << 5;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment