Author | Jamozed <[email protected]> |
Date | 2021-01-26 01:05:12 |
Commit | 8e42725bb6f8be78e274ee39b58f8baa56969588 |
Parent | b9d4a23d82423addb83cd3704c414e3665b7bdde |
misc: Add circular shift functions
Diffstat
M | README.md | | | 1 | + |
A | src/lib/misc.h | | | 48 | ++++++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 49 insertions, 0 deletions
diff --git a/README.md b/README.md index 98d4e8f..e4906f6 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ OMKOV lib is a lightweight generic library to be included locally in projects. | endian | Endianness related functions | | error | Error reporting functions | | mode | Parse numeric or symbolic POSIX modes | +| misc | Miscellaneous functions | | optget | Parse command line options | ## Build Instructions diff --git a/src/lib/misc.h b/src/lib/misc.h new file mode 100644 index 0000000..ff25df3 --- /dev/null +++ b/src/lib/misc.h @@ -0,0 +1,48 @@ +// misc.h, version 0.1.0 +// Misc header file for OMKOV lib +// Copyright (C) 2021, Jakob Wakeling +// All rights reserved. + +/* +OMKOV Permissive Licence, version 1.0 + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal with +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimers. +* Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimers in the documentation and/or + other materials provided with the distribution. +* Neither the names of the copyright holders, nor the names of its contributors + may be used to endorse or promote products derived from this Software without + specific prior written permission. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT +HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. +*/ + +#ifndef OMKOV_LIB_MISC_H_RDY6J5JV +#define OMKOV_LIB_MISC_H_RDY6J5JV + +#include <stdint.h> + +#define ROL8(x, n) (uint8_t)(((x) << (n)) | ((x) >> (8 - (n)))) +#define ROL16(x, n) (uint16_t)(((x) << (n)) | ((x) >> (16 - (n)))) +#define ROL32(x, n) (uint32_t)(((x) << (n)) | ((x) >> (32 - (n)))) +#define ROL64(x, n) (uint64_t)(((x) << (n)) | ((x) >> (64 - (n)))) + +#define ROR8(x, n) (uint8_t)(((x) >> (n)) | ((x) << (8 - (n)))) +#define ROR16(x, n) (uint16_t)(((x) >> (n)) | ((x) << (16 - (n)))) +#define ROR32(x, n) (uint32_t)(((x) >> (n)) | ((x) << (32 - (n)))) +#define ROR64(x, n) (uint64_t)(((x) >> (n)) | ((x) << (64 - (n)))) + +#endif // OMKOV_LIB_MISC_H_RDY6J5JV