X-Git-Url: https://yaffs.net/gitweb/?a=blobdiff_plain;f=direct%2Fyaffs_hweight.c;fp=direct%2Fyaffs_hweight.c;h=d283b875eae137ae8ec0102c4aeaaa4b025088ec;hb=acf9438692c78de0ca030e5408790572dbe06500;hp=0000000000000000000000000000000000000000;hpb=03ddd91b1bd421a53d76ebdce7bc647299c8965d;p=yaffs2.git diff --git a/direct/yaffs_hweight.c b/direct/yaffs_hweight.c new file mode 100644 index 0000000..d283b87 --- /dev/null +++ b/direct/yaffs_hweight.c @@ -0,0 +1,53 @@ +/* + * YAFFS: Yet Another Flash File System. A NAND-flash specific file system. + * + * Copyright (C) 2002-2010 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Charles Manning + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + + /* These functions have been renamed to hweightxx to match the + * equivaqlent functions in the Linux kernel. + */ + +#include "yaffs_hweight.h" + +static const char yaffs_count_bits_table[256] = { + 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 +}; + +int yaffs_hweight8(u8 x) +{ + int ret_val; + ret_val = yaffs_count_bits_table[x]; + return ret_val; +} + +int yaffs_hweight32(u32 x) +{ + return hweight8(x & 0xff) + + hweight8((x >> 8) & 0xff) + + hweight8((x >> 16) & 0xff) + + hweight8((x >> 24) & 0xff); +} +