X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=lib%2Fbch.c;h=c4fac77d611456b116b663b0553d4325c6861fda;hb=e731af4893f7741c66254161ad9b6f5280369895;hp=7f4ca927085775a3e7122f0a7a561c0b67256340;hpb=e390e8709149664ff96cf19384264c84573f3082;p=oweals%2Fu-boot.git diff --git a/lib/bch.c b/lib/bch.c index 7f4ca92708..c4fac77d61 100644 --- a/lib/bch.c +++ b/lib/bch.c @@ -1,19 +1,7 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Generic binary BCH encoding/decoding library * - * 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. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 51 - * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * * Copyright © 2011 Parrot S.A. * * Author: Ivan Djelic @@ -65,10 +53,38 @@ * finite fields GF(2^q). In Rapport de recherche INRIA no 2829, 1996. */ +#ifndef USE_HOSTCC #include #include #include +#else +#include +#if defined(__FreeBSD__) +#include +#elif defined(__APPLE__) +#include +#include +#else +#include +#endif +#include +#include +#include + +#undef cpu_to_be32 +#if defined(__APPLE__) +#define cpu_to_be32 OSSwapHostToBigInt32 +#else +#define cpu_to_be32 htobe32 +#endif +#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) +#define kmalloc(size, flags) malloc(size) +#define kzalloc(size, flags) calloc(1, size) +#define kfree free +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) +#endif + #include #include @@ -106,6 +122,39 @@ struct gf_poly_deg1 { unsigned int c[2]; }; +#ifdef USE_HOSTCC +#if !defined(__DragonFly__) && !defined(__FreeBSD__) && !defined(__APPLE__) +static int fls(int x) +{ + int r = 32; + + if (!x) + return 0; + if (!(x & 0xffff0000u)) { + x <<= 16; + r -= 16; + } + if (!(x & 0xff000000u)) { + x <<= 8; + r -= 8; + } + if (!(x & 0xf0000000u)) { + x <<= 4; + r -= 4; + } + if (!(x & 0xc0000000u)) { + x <<= 2; + r -= 2; + } + if (!(x & 0x80000000u)) { + x <<= 1; + r -= 1; + } + return r; +} +#endif +#endif + /* * same as encode_bch(), but process input data one byte at a time */