author | Olivier Brunel
<jjk@jjacky.com> 2023-07-02 19:22:40 UTC |
committer | Olivier Brunel
<jjk@jjacky.com> 2023-07-24 10:16:42 UTC |
parent | 907342eb9a521fe9309c17b395db34b9681fc7fd |
src/doc/u64.h.0.md | +48 | -51 |
src/doc/{uint64.h => u64.h}/msb64.3.md | +1 | -1 |
src/doc/u64.h/{u640_bfmt.3.md => u64_0bfmt.3.md} | +0 | -0 |
src/doc/u64.h/{u640_fmt.3.md => u64_0fmt.3.md} | +0 | -0 |
src/doc/u64.h/{u640_fmt_generic.3.md => u64_0fmt_generic.3.md} | +0 | -0 |
src/doc/u64.h/{u640_ofmt.3.md => u64_0fmtg.3.md} | +0 | -0 |
src/doc/u64.h/{u640_xfmt.3.md => u64_0ofmt.3.md} | +0 | -0 |
src/doc/u64.h/u64_0xfmt.3.md | +1 | -0 |
src/doc/u64.h/{u640_bscan.3.md => u64_bscan0.3.md} | +0 | -0 |
src/doc/u64.h/u64_fmt.3.md | +17 | -16 |
src/doc/u64.h/u64_fmt_generic.3.md | +3 | -3 |
src/doc/u64.h/u64_le.3.md | +13 | -14 |
src/doc/u64.h/{u640_oscan.3.md => u64_oscan0.3.md} | +0 | -0 |
src/doc/u64.h/u64_pack.3.md | +15 | -23 |
src/doc/u64.h/u64_pack_trim.3.md | +52 | -1 |
src/doc/u64.h/u64_scan.3.md | +17 | -17 |
src/doc/u64.h/{u640_scan.3.md => u64_scan0.3.md} | +0 | -0 |
src/doc/u64.h/u64_unpack_trim.3.md | +1 | -1 |
src/doc/u64.h/{u640_xscan.3.md => u64_xscan0.3.md} | +0 | -0 |
src/doc/uint64.h.0.md | +0 | -28 |
src/doc/uint64.h/uint64_pack_trim.3.md | +0 | -47 |
src/doc/uint64.h/uint64_unpack_trim.3.md | +0 | -1 |
src/include/blake3.h | +1 | -1 |
src/liblimb/hmap.h/hmap_init.c | +1 | -1 |
src/liblimb/include/limb/u64.h | +17 | -13 |
src/liblimb/include/limb/uint64.h | +0 | -15 |
src/liblimb/nextsplit.h/nextsplit_buz.c | +1 | -1 |
src/liblimb/nextsplit.h/nextsplit_rabin.c | +1 | -1 |
src/liblimb/{uint64.h => u64.h}/msb64.c | +0 | -0 |
src/liblimb/{u640_fmt_generic.c => u64.h/u64_0fmt_generic.c} | +1 | -1 |
src/liblimb/{ => u64.h}/u64_fmt_generic.c | +0 | -0 |
src/liblimb/{uint64.h/uint64_pack_trim.c => u64.h/u64_pack_trim.c} | +4 | -5 |
src/liblimb/{uint64.h/uint64_unpack_trim.c => u64.h/u64_unpack_trim.c} | +6 | -6 |
src/mkrabintables/msb64.o | +1 | -1 |
src/mkrabintables/u64_fmt_generic.o | +1 | -1 |
diff --git a/src/doc/u64.h.0.md b/src/doc/u64.h.0.md index 1dc27ab..4769850 100644 --- a/src/doc/u64.h.0.md +++ b/src/doc/u64.h.0.md @@ -12,8 +12,6 @@ u64.h - 64bit unsigned integers # DESCRIPTION This header defines functions allowing to work with 64bit unsigned integers. -It is mainly composed of macros to their `uint64_*` counterparts, offering -slightly different interfaces. ## Constants @@ -40,101 +38,100 @@ The following constants are defined : The following functions/macros are defined : : [u64_be](3) -:: Same as [uint64_big](3) +:: Convert a u64 number to big endian. : [u64_le](3) -:: Same as [uint64_little](3) +:: Convert a u64 number to little endian. : [u64p_be](3) -:: Same as [uint64_bigp](3) +:: Similar to [u64_be](3) but takes a pointer. : [u64p_le](3) -:: Same as [uint64_littlep](3) +:: Similar to [u64_le](3) but takes a pointer. : [u64pa_be](3) -:: Same as [uint64_bign](3) +:: Similar to [u64p_be](3) but for an array of pointers. : [u64pa_le](3) -:: Same as [uint64_littlen](3) +:: Similar to [u64p_le](3) but for an array of pointers. : [u64_pack](3) -:: Same as [uint64_pack](3) +:: Store a u64 number encoded in little endian. : [u64_unpack](3) -:: Same as [uint64_unpack](3) +:: Read a u64 number encoded in little endian. : [u64_pack_big](3) -:: Same as [uint64_pack_big](3) +:: Store a u64 number encoded in big endian. : [u64_unpack_big](3) -:: Same as [uint64_unpack_big](3) +:: Read a u64 number encoded in big endian. : [u64_pack_trim](3) -:: Same as [uint64_pack_trim](3) +:: Store a 64 number encoded in little endian trimming "unneeded" bits. : [u64_unpack_trim](3) -:: Same as [uint64_unpack_trim](3) +:: Read a u64 number encoded in little endian with "unneeded" bits trimmed. : [u64_fmt](3) -:: Print u64 value as decimal into given byte array +:: Write a u64 number as decimal into a byte array. : [u64_fmtg](3) -:: Print u64 value as decimal, using coma as thousand separator, into given byte -:: array +:: Write a u64 number as decimal, using coma as thousand separator, into a +:: byte array. + +: [u64_fmt_generic](3) +:: Write a u64 number into a byte array, encoded in specified base and +:: optionally grouped using given separator. + +: [u64_0fmt_generic](3) +:: Same as [u64_fmt_generic](3) but filling with given character if less than +:: given size. : [u64_bfmt](3) -:: Same as [u64_fmt](3) but as binary +:: Similar to [u64_fmt](3) but as binary. : [u64_ofmt](3) -:: Same as [u64_fmt](3) but as octal +:: Similar to [u64_fmt](3) but as octal. : [u64_xfmt](3) -:: Same as [u64_fmt](3) but as hexadecimal +:: Similar to [u64_fmt](3) but as hexadecimal. -: [u640_fmt](3) -:: Same as [u64_fmt](3) but filling with zeroes if less than given size +: [u64_0fmt](3) +:: Similar to [u64_fmt](3) but filling with zeroes if less than given size. -: [u640_fmtg](3) -:: Same as [u64_fmtg](3) but filling with zeroes if less than given size +: [u64_0fmtg](3) +:: Similar to [u64_fmtg](3) but filling with zeroes if less than given size. -: [u640_bfmt](3) -:: Same as [u64_bfmt](3) but filling with zeroes if less than given size +: [u64_0bfmt](3) +:: Similar to [u64_bfmt](3) but filling with zeroes if less than given size. -: [u640_ofmt](3) -:: Same as [u64_ofmt](3) but filling with zeroes if less than given size +: [u64_0ofmt](3) +:: Similar to [u64_ofmt](3) but filling with zeroes if less than given size. -: [u640_xfmt](3) -:: Same as [u64_xfmt](3) but filling with zeroes if less than given size - -: [u64_fmt_generic](3) -:: Print u64 value into given byte array, encoded in specified base and -optionally grouped using given separator - -: [u640_fmt_generic](3) -:: Same as [u64_fmt_generic](3) but filling with given character if less than -:: specified size. +: [u64_0xfmt](3) +:: Similar to [u64_xfmt](3) but filling with zeroes if less than given size. : [u64_scan](3) -:: Read given byte array for decimal u64 value and load into given variable +:: Read a u64 value from a byte array. : [u64_bscan](3) -:: Same as [u64_scan](3) but for binary value +:: Similar to [u64_scan](3) but for binary value. : [u64_oscan](3) -:: Same as [u64_scan](3) but for octal value +:: Similar to [u64_scan](3) but for octal value. : [u64_xscan](3) -:: Same as [u64_scan](3) but for hexadecimal value - -: [u640_scan](3) -:: Same as [u64_scan](3) but expects a NUL-terminated string +:: Similar to [u64_scan](3) but for hexadecimal value. -: [u640_bscan](3) -:: Same as [u64_bscan](3) but expects a NUL-terminated string +: [u64_scan0](3) +:: Similar to [u64_scan](3) but expects a NUL-terminated string. -: [u640_oscan](3) -:: Same as [u64_oscan](3) but expects a NUL-terminated string +: [u64_bscan0](3) +:: Similar to [u64_bscan](3) but expects a NUL-terminated string. -: [u640_xscan](3) -:: Same as [u64_xscan](3) but expects a NUL-terminated string +: [u64_oscan0](3) +:: Similar to [u64_oscan](3) but expects a NUL-terminated string. +: [u64_xscan0](3) +:: Similar to [u64_xscan](3) but expects a NUL-terminated string. diff --git a/src/doc/uint64.h/msb64.3.md b/src/doc/u64.h/msb64.3.md similarity index 93% rename from src/doc/uint64.h/msb64.3.md rename to src/doc/u64.h/msb64.3.md index 35dbead..a87d12b 100644 --- a/src/doc/uint64.h/msb64.3.md +++ b/src/doc/u64.h/msb64.3.md @@ -12,7 +12,7 @@ msb64 - return the position of the most significant bit set #include <limb/uint64.h> ```pre hl -int msb64(uint64_t <em>val</em>) +int msb64(u64 <em>val</em>) ``` # DESCRIPTION diff --git a/src/doc/u64.h/u640_bfmt.3.md b/src/doc/u64.h/u64_0bfmt.3.md similarity index 100% rename from src/doc/u64.h/u640_bfmt.3.md rename to src/doc/u64.h/u64_0bfmt.3.md diff --git a/src/doc/u64.h/u640_fmt.3.md b/src/doc/u64.h/u64_0fmt.3.md similarity index 100% rename from src/doc/u64.h/u640_fmt.3.md rename to src/doc/u64.h/u64_0fmt.3.md diff --git a/src/doc/u64.h/u640_fmt_generic.3.md b/src/doc/u64.h/u64_0fmt_generic.3.md similarity index 100% rename from src/doc/u64.h/u640_fmt_generic.3.md rename to src/doc/u64.h/u64_0fmt_generic.3.md diff --git a/src/doc/u64.h/u640_ofmt.3.md b/src/doc/u64.h/u64_0fmtg.3.md similarity index 100% rename from src/doc/u64.h/u640_ofmt.3.md rename to src/doc/u64.h/u64_0fmtg.3.md diff --git a/src/doc/u64.h/u640_xfmt.3.md b/src/doc/u64.h/u64_0ofmt.3.md similarity index 100% rename from src/doc/u64.h/u640_xfmt.3.md rename to src/doc/u64.h/u64_0ofmt.3.md diff --git a/src/doc/u64.h/u64_0xfmt.3.md b/src/doc/u64.h/u64_0xfmt.3.md new file mode 120000 index 0000000..2ee1acc --- /dev/null +++ b/src/doc/u64.h/u64_0xfmt.3.md @@ -0,0 +1 @@ +u64_fmt.3.md \ No newline at end of file diff --git a/src/doc/u64.h/u640_bscan.3.md b/src/doc/u64.h/u64_bscan0.3.md similarity index 100% rename from src/doc/u64.h/u640_bscan.3.md rename to src/doc/u64.h/u64_bscan0.3.md diff --git a/src/doc/u64.h/u64_fmt.3.md b/src/doc/u64.h/u64_fmt.3.md index d6954b6..adfa1b5 100644 --- a/src/doc/u64.h/u64_fmt.3.md +++ b/src/doc/u64.h/u64_fmt.3.md @@ -3,13 +3,13 @@ # NAME -u64\_fmt, u64\_fmtg, u640\_fmt - print an u64 as decimal value into a byte array +u64_fmt, u64_fmtg, u64_0fmt - write an u64 as decimal value into a byte array -u64\_xfmt, u640\_xfmt - print an u64 as hexadecimal value into a byte array +u64_xfmt, u64_0xfmt - write an u64 as hexadecimal value into a byte array -u64\_ofmt, u640\_ofmt - print an u64 as octal value into a byte array +u64_ofmt, u64_0ofmt - write an u64 as octal value into a byte array -u64\_bfmt, u640\_bfmt - print an u64 as binary value into a byte array +u64_bfmt, u64_0bfmt - write an u64 as binary value into a byte array # SYNOPSIS @@ -18,43 +18,44 @@ u64\_bfmt, u640\_bfmt - print an u64 as binary value into a byte array ```pre hl size_t u64_fmt(char *<em>s</em>, u64 <em>u</em>) -size_t u640_fmt(char *<em>s</em>, u64 <em>u</em>, size_t <em>min</em>) +size_t u64_0fmt(char *<em>s</em>, u64 <em>u</em>, size_t <em>min</em>) size_t u64_fmtg(char *<em>s</em>, u64 <em>u</em>) -size_t u640_fmtg(char *<em>s</em>, u64 <em>u</em>, size_t <em>min</em>) +size_t u64_0fmtg(char *<em>s</em>, u64 <em>u</em>, size_t <em>min</em>) size_t u64_xfmt(char *<em>s</em>, u64 <em>u</em>) -size_t u640_xfmt(char *<em>s</em>, u64 <em>u</em>, size_t <em>min</em>) +size_t u64_0xfmt(char *<em>s</em>, u64 <em>u</em>, size_t <em>min</em>) size_t u64_ofmt(char *<em>s</em>, u64 <em>u</em>) -size_t u640_ofmt(char *<em>s</em>, u64 <em>u</em>, size_t <em>min</em>) +size_t u64_0ofmt(char *<em>s</em>, u64 <em>u</em>, size_t <em>min</em>) size_t u64_bfmt(char *<em>s</em>, u64 <em>u</em>) -size_t u640_bfmt(char *<em>s</em>, u64 <em>u</em>, size_t <em>min</em>) +size_t u64_0bfmt(char *<em>s</em>, u64 <em>u</em>, size_t <em>min</em>) ``` # DESCRIPTION -The `u64_fmt`() function will put into `s` the value of `u` in decimal. -The `u640_fmt`() function will put into `s` the value of `u` in decimal, +The `u64_fmt`() macro will write into `s` the value of `u` in decimal. +The `u64_0fmt`() macro will write into `s` the value of `u` in decimal, prefixing it with leading zeroes if it requires less than `min` characters to do so. -The `u64_fmtg`() and `u640_fmtg`() function are similar, only they will use a +The `u64_fmtg`() and `u64_0fmtg`() macros are similar, only they will use a coma (`,`) as thousand separator as needed. -The `u64_xfmt`() and `u640_xfmt`() functions are similar, only putting the value +The `u64_xfmt`() and `u64_0xfmt`() macros are similar, only putting the value of `u` in hexadecimal. -The `u64_ofmt`() and `u640_ofmt`() functions are similar, only putting the value +The `u64_ofmt`() and `u64_0ofmt`() macros are similar, only putting the value of `u` in octal. -The `u64_bfmt`() and `u640_bfmt`() functions are similar, only putting the value +The `u64_bfmt`() and `u64_0bfmt`() macros are similar, only putting the value of `u` in binary. It is possible to use `NULL` as `s` to only have length computation performed. -Note that those are macros to [u64_fmt_generic](3). +! INFO: Generic functions +! Note that those are macros to [u64_fmt_generic](3) and [u64_0fmt_generic](3). ## Constants diff --git a/src/doc/u64.h/u64_fmt_generic.3.md b/src/doc/u64.h/u64_fmt_generic.3.md index 85b85ca..41d983e 100644 --- a/src/doc/u64.h/u64_fmt_generic.3.md +++ b/src/doc/u64.h/u64_fmt_generic.3.md @@ -3,7 +3,7 @@ # NAME -u64\_fmt\_generic, u640\_fmt\_generic - print an u64 value into a byte array +u64_fmt_generic, u64_0fmt_generic - write an u64 number into a byte array # SYNOPSIS @@ -11,7 +11,7 @@ u64\_fmt\_generic, u640\_fmt\_generic - print an u64 value into a byte array ```pre hl size_t u64_fmt_generic(char *<em>s</em>, u64 <em>u</em>, u8 <em>base</em>, u8 <em>grp</em>, const char <em>sep</em>) -size_t u640_fmt_generic(char *<em>s</em>, u64 <em>u</em>, u8 <em>base</em>, size_t <em>min</em>, const char <em>fill</em>, +size_t u64_0fmt_generic(char *<em>s</em>, u64 <em>u</em>, u8 <em>base</em>, size_t <em>min</em>, const char <em>fill</em>, u8 <em>grp</em>, const char <em>sep</em>) ``` @@ -21,7 +21,7 @@ The `u64_fmt_generic`() function will put into `s` the value of `u` encoded in base `base`. If `grp` is not zero, `sep` will be used as separator every `grp` characters, starting from the end. -The `u640_fmt_generic`() function is similar, only if the size needed is less +The `u64_0fmt_generic`() function is similar, only if the size needed is less than `min` it will fill it up by prefixing it using as many instances of `fill` as needed. diff --git a/src/doc/u64.h/u64_le.3.md b/src/doc/u64.h/u64_le.3.md index 05c41f8..b16dbad 100644 --- a/src/doc/u64.h/u64_le.3.md +++ b/src/doc/u64.h/u64_le.3.md @@ -3,11 +3,9 @@ # NAME -u64\_le, u64\_be - convert a value to little\/big endian +u64_le, u64_be, u64p_le, u64p_be - convert an u64 to little/big endian -u64p\_le, u64p\_be - convert an u64 into little\/big endian - -u64pa\_le, u64pa\_be - convert an array of u64 into little\/big endian +u64pa_le, u64pa_be - convert an array of u64 into little/big endian # SYNOPSIS @@ -20,25 +18,26 @@ u64 u64_be(u64 <em>u</em>) void u64p_le(u64 *<em>val</em>) void u64p_be(u64 *<em>val</em>) -void u64pa_le(u64 *<em>val</em>, size_t <em>length</em>) -void u64pa_be(u64 *<em>val</em>, size_t <em>length</em>) +void u64pa_le(u64 *<em>val</em>, size_t <em>len</em>) +void u64pa_be(u64 *<em>val</em>, size_t <em>len</em>) ``` # DESCRIPTION All of these aim to ensure a value or variable is in expected endianness. -The `u64_le`() and `u64_be`() functions will return the value after having read -the given number `u` as a little endian and big endian value respectively. +The `u64_le`() and `u64_be`() macros will return the value after having read +the given number `u` as a little endian or big endian value, respectively. -The `u64p_le`() and `u64p_be`() functions are similar, only they take a pointer -to an u64 and will convert it into little endian and big endian, respectively. +The `u64p_le`() and `u64p_be`() macros are similar, only they take a pointer +to an u64 and will convert it into little endian or big endian, respectively. -Finally the `u64pa_le`() and `u64pa_be`() are similar to the previous two, only -they take an array of u64 of size `length` and convert every element. +Finally the `u64pa_le`() and `u64pa_be`() macros are similar to the previous +two, only they take an array of u64 of size `len` and convert every element. -These are actually macros to the relevant `uint64_*` functions as needed, i.e. -if the requested endianness is that of the host, no operation is performed. +! NOTE: +! Note that these are macros they may be either no-op or byte swapping functions +! depending on the endianness of the host. # RETURN VALUE diff --git a/src/doc/u64.h/u640_oscan.3.md b/src/doc/u64.h/u64_oscan0.3.md similarity index 100% rename from src/doc/u64.h/u640_oscan.3.md rename to src/doc/u64.h/u64_oscan0.3.md diff --git a/src/doc/u64.h/u64_pack.3.md b/src/doc/u64.h/u64_pack.3.md index a95089e..a176444 100644 --- a/src/doc/u64.h/u64_pack.3.md +++ b/src/doc/u64.h/u64_pack.3.md @@ -5,8 +5,8 @@ # NAME -u64\_pack, u64\_unpack, u64\_pack\_big, u64\_unpack\_big, u64\_pack\_trim, -u64\_unpack\_trim - pack\/unpack an integer (u64) into\/from a byte array +u64_pack, u64_unpack, u64_pack_big, u64_unpack_big - store/read an u64 into/from +a byte array # SYNOPSIS @@ -15,35 +15,27 @@ u64\_unpack\_trim - pack\/unpack an integer (u64) into\/from a byte array ```pre hl void u64_pack(void *<em>dst</em>, u64 <em>val</em>) void u64_unpack(u64 *<em>val</em>, const void *<em>sce</em>) + void u64_pack_big(void *<em>dst</em>, u64 <em>val</em>) void u64_unpack_big(u64 *<em>val</em>, const void *<em>sce</em>) -int u64_pack_trim(void *<em>dst</em>, size_t <em>dlen</em>, u64 <em>val</em>) -int u64_unpack_trim(u64 *<em>val</em>, const void *<em>sce</em>, size_t <em>slen</em>) ``` # DESCRIPTION -All of these aim to either pack the given integer (u64) `val` into the specified -byte array `dst`, or unpack from the specified byte array `sce` the integer -value into the pointed `val`. +All of these aim to either store the given number `val` into the specified +byte array `dst`, or read a number from the specified byte array `sce` and set +the value pointed by `val` to its value. + +The `u64_pack`() function stores the number `val` into the 8 bytes pointed by +`dst`, encoded as little endian. -The `u64_pack`() function packs `val` into 8 bytes encoded as little endian, -the `u64_pack_big`() function does the same encoded as big endian, and the -`u64_pack_trim`() function pack in a little endian mode but /trimming/ the -"unneeded" bits, i.e. all most significant bits set to zero need not be -included. It will therefore need to pack into from 1 to 9 bytes, depending on -the value. It will never write more than `dlen` bytes though. -See [uint64_pack_trim](3) for more. +The `u64_unpack`() function reads 8 bytes pointed by `sce` as little endian +encoded number, setting the value pointed by `val` to its value. -The `u64_unpack` family does the same, only unpacking from the byte array `sce` -into `val`. Similarly, the `u64_unpack_trim`() function will never read more -than `slen` bytes. +The `u64_pack_big`() function is similar to `u64_pack`() only as big endian. -These are actually macros to the relevant `uint64_*` functions, offering a -slightly different interface. +The `u64_unpack_big`() function is similar to `u64_unpack`() only as big endian. -# RETURN VALUE +# SEE ALSO -Only `u64_pack_trim`() and `u64_unpack_trim`() have a return value, that of the -number of bytes written to `dst` or read from `sce`, respectively, on success. -Otherwise - not enough byte could be written/read - they will return -1 +[u64_pack_trim](3) diff --git a/src/doc/u64.h/u64_pack_trim.3.md b/src/doc/u64.h/u64_pack_trim.3.md deleted file mode 120000 index b0b36e9..0000000 --- a/src/doc/u64.h/u64_pack_trim.3.md +++ /dev/null @@ -1 +0,0 @@ -u64_pack.3.md \ No newline at end of file diff --git a/src/doc/u64.h/u64_pack_trim.3.md b/src/doc/u64.h/u64_pack_trim.3.md new file mode 100644 index 0000000..858727b --- /dev/null +++ b/src/doc/u64.h/u64_pack_trim.3.md @@ -0,0 +1,52 @@ +% limb manual +% u64_pack_trim(3) +% limb 0.0.3 +% 2023-02-15 + +# NAME + +u64_pack_trim, u64_unpack_trim - store/read an u64 into/from a byte array + +# SYNOPSIS + + #include <limb/u64.h> + +```pre hl +int u64_pack_trim(char *<em>dst</em>, size_t <em>dlen</em>, u64 <em>val</em>) +int u64_unpack_trim(u64 *<em>val</em>, const char *<em>sce</em>, size_t <em>slen</em>) +``` + +# DESCRIPTION + +The `u64_pack_trim`() function will store the number `val` into the byte +array pointed by `dst` of length `dlen`, /trimming/ the "unneeded" bits, i.e. +all most significant bits set to zero need not be included. + +In other words, it will only use as many bytes as necessary: The value is +stored in little-endian mode using only 7 bits per byte, with the last (most +significant) bit used as indicator whether or not an additional byte is +required. + +Therefore the encoded number will take from only 1 up to 9 bytes. + + +The `u64_unpack_trim`() function performs the reverse, reading bytes from the +memory pointed by `sce` to get the encoded value, which will be placed into the +memory pointed by `val`. + +It will therefore read from 1 up to 9 bytes, depending on the actual value. +However it will only ever read up to `slen` bytes. + +# RETURN VALUE + +The `u64_pack_trim`() function returns the number of bytes written to into `dst` +to pack `val` on success. +Otherwise - i.e. more than `dlen` bytes are necessary - it returns -1. + +The `u64_unpack_trim`() function returns the number of bytes read from `sce` to +unpack `val` on success. +Otherwise - i.e. more than `slen` bytes were needed to be read - it returns -1. + +# SEE ALSO + +[u64_pack](3) diff --git a/src/doc/u64.h/u64_scan.3.md b/src/doc/u64.h/u64_scan.3.md index 5d0b2d5..1bf6715 100644 --- a/src/doc/u64.h/u64_scan.3.md +++ b/src/doc/u64.h/u64_scan.3.md @@ -3,13 +3,13 @@ # NAME -u64\_scan, u640\_scan - Read an u64 value from a decimal string +u64_scan, u64_scan0 - Read an u64 value from a decimal string -u64\_xscan, u640\_xscan - Read an u64 value from an hexadecimal string +u64_xscan, u64_xscan0 - Read an u64 value from an hexadecimal string -u64\_oscan, u640\_oscan - Read an u64 value from an octal string +u64_oscan, u64_oscan0 - Read an u64 value from an octal string -u64\_bscan, u640\_bscan - Read an u64 value from a binary string +u64_bscan, u64_bscan0 - Read an u64 value from a binary string # SYNOPSIS @@ -18,16 +18,16 @@ u64\_bscan, u640\_bscan - Read an u64 value from a binary string ```pre hl size_t u64_scan(u64 *<em>dst</em>, const char *<em>s</em>) -size_t u640_scan(u64 *<em>dst</em>, const char *<em>s</em>) +size_t u64_scan0(u64 *<em>dst</em>, const char *<em>s</em>) size_t u64_xscan(u64 *<em>dst</em>, const char *<em>s</em>) -size_t u640_xscan(u64 *<em>dst</em>, const char *<em>s</em>) +size_t u64_xscan0(u64 *<em>dst</em>, const char *<em>s</em>) size_t u64_oscan(u64 *<em>dst</em>, const char *<em>s</em>) -size_t u640_oscan(u64 *<em>dst</em>, const char *<em>s</em>) +size_t u64_oscan0(u64 *<em>dst</em>, const char *<em>s</em>) size_t u64_bscan(u64 *<em>dst</em>, const char *<em>s</em>) -size_t u640_bscan(u64 *<em>dst</em>, const char *<em>s</em>) +size_t u64_bscan0(u64 *<em>dst</em>, const char *<em>s</em>) ``` # DESCRIPTION @@ -35,30 +35,30 @@ size_t u640_bscan(u64 *<em>dst</em>, const char *<em>s</em>) The `u64_scan`() function will place into `dst` the number read as a decimal value from the string `s`, stopping as soon as a character isn't valid. -The `u640_scan`() function is similar but expects the string to contain a valid +The `u64_scan0`() function is similar but expects the string to contain a valid value and nothing else, stopping with a NUL-terminating byte. -The `u64_xscan`() and `u640_xscan`() functions are similar, but expecting an +The `u64_xscan`() and `u64_xscan0`() functions are similar, but expecting an hexadecimal value in `s`. -The `u64_oscan`() and `u640_oscan`() functions are similar, but expecting an +The `u64_oscan`() and `u64_oscan0`() functions are similar, but expecting an octal value in `s`. -The `u64_bscan`() and `u640_bscan`() functions are similar, but expecting a +The `u64_bscan`() and `u64_bscan0`() functions are similar, but expecting a binary value in `s`. # RETURN VALUE -The `u64_*` family of functions return the number of characters read from `s` -(starting at 0 when the first character is invalid). +The `u64_*scan` family of functions return the number of characters read from +`s` (starting at 0 when the first character is invalid). -The `u640_*` family of functions return the number of characters read from `s` -or 0 on error. +The `u64_*scan0` family of functions return the number of characters read from +`s` or 0 on error. # ERRORS -The `u640_*` family of functions may fail and set `errno` if : +The `u64_*scan0` family of functions may fail and set `errno` if : : *EINVAL* :: Invalid character in `s` diff --git a/src/doc/u64.h/u640_scan.3.md b/src/doc/u64.h/u64_scan0.3.md similarity index 100% rename from src/doc/u64.h/u640_scan.3.md rename to src/doc/u64.h/u64_scan0.3.md diff --git a/src/doc/u64.h/u64_unpack_trim.3.md b/src/doc/u64.h/u64_unpack_trim.3.md index b0b36e9..19ec84d 120000 --- a/src/doc/u64.h/u64_unpack_trim.3.md +++ b/src/doc/u64.h/u64_unpack_trim.3.md @@ -1 +1 @@ -u64_pack.3.md \ No newline at end of file +u64_pack_trim.3.md \ No newline at end of file diff --git a/src/doc/u64.h/u640_xscan.3.md b/src/doc/u64.h/u64_xscan0.3.md similarity index 100% rename from src/doc/u64.h/u640_xscan.3.md rename to src/doc/u64.h/u64_xscan0.3.md diff --git a/src/doc/uint64.h.0.md b/src/doc/uint64.h.0.md deleted file mode 100644 index 90adc28..0000000 --- a/src/doc/uint64.h.0.md +++ /dev/null @@ -1,28 +0,0 @@ -% limb manual -% uint64.h(0) - -# NAME - -uint64.h - 64bit unsigned integers - -# SYNOPSIS - - #include <limb/uint64.h> - -# DESCRIPTION - -This header defines functions allowing to work with 64bit unsigned integers. - -! INFO: skalibs -! This header is a complement to skalibs' own [skalibs/uint64.h](0) and thusly -! includes said header. - -## Functions - -The following functions are defined : - -: [uint64_pack_trim](3) -:: Store given value into given byte array, trimming "unneeded" bits - -: [uint64_unpack_trim](3) -:: Read given byte array and load value into given variable diff --git a/src/doc/uint64.h/uint64_pack_trim.3.md b/src/doc/uint64.h/uint64_pack_trim.3.md deleted file mode 100644 index f40c99e..0000000 --- a/src/doc/uint64.h/uint64_pack_trim.3.md +++ /dev/null @@ -1,47 +0,0 @@ -% limb manual -% uint64_pack_trim(3) -% limb 0.0.3 -% 2023-02-15 - -# NAME - -uint64\_pack\_trim, uint64\_unpack\_trim - pack\/unpack an integer (u64) -into\/from a byte array - -# SYNOPSIS - - #include <limb/uint64.h> - -```pre hl -int uint64_pack_trim(char *<em>dst</em>, size_t <em>dlen</em>, uint64_t <em>val</em>) -int uint64_unpack_trim(const char *<em>sce</em>, size_t <em>slen</em>, uint64_t *<em>val</em>) -``` - -# DESCRIPTION - -The `uint64_pack_trim`() function will store the number `val` into the byte -array pointed by `dst` of length `dlen`, /trimming/ the "unneeded" bits, i.e. -all most significant bits set to zero need not be included. - -In other words, it will only use as many bytes as necessary: The value is -stored in little-endian mode using only 7 bits per byte, with the last (most -significant) bit used as indicator whether or not an additional byte is -required. - -Therefore the encoded number will take from only 1 up to 9 bytes. - -The `uint64_unpack_trim`() function performs the reverse, reading bytes from the -memory pointed by `sce` to get the encoded value, which will be placed into the -memory pointed by `val`. -It will therefore read from 1 up to 9 bytes, depending on the actual value. -However it will only ever read up to `slen` bytes. - -# RETURN VALUE - -`uint64_pack_trim`() returns the number of bytes written to into `dst` to pack -`val` on success. Otherwise - i.e. more than `dlen` bytes are necessary - it -returns -1. - -`uint64_unpack_trim`() returns the number of bytes read from `sce` to unpack -`val` on success. Otherwise - i.e. more than `slen` bytes needed to be read - -it returns -1. diff --git a/src/doc/uint64.h/uint64_unpack_trim.3.md b/src/doc/uint64.h/uint64_unpack_trim.3.md deleted file mode 120000 index d17b485..0000000 --- a/src/doc/uint64.h/uint64_unpack_trim.3.md +++ /dev/null @@ -1 +0,0 @@ -uint64_pack_trim.3.md \ No newline at end of file diff --git a/src/include/blake3.h b/src/include/blake3.h index df935e2..0c21d50 100644 --- a/src/include/blake3.h +++ b/src/include/blake3.h @@ -10,7 +10,7 @@ #include <string.h> #include <limb/blake3.h> #include <limb/gccattributes.h> -#include <limb/uint64.h> +#include <limb/u64.h> /* internal flags */ enum blake3_flags { diff --git a/src/liblimb/hmap.h/hmap_init.c b/src/liblimb/hmap.h/hmap_init.c index 34b9636..ee1592b 100644 --- a/src/liblimb/hmap.h/hmap_init.c +++ b/src/liblimb/hmap.h/hmap_init.c @@ -2,7 +2,7 @@ * Copyright (C) 2023 Olivier Brunel jjk@jjacky.com */ /* SPDX-License-Identifier: GPL-2.0-only */ #include <errno.h> -#include <limb/uint64.h> +#include <limb/u64.h> #include "hmap.h" int diff --git a/src/liblimb/include/limb/u64.h b/src/liblimb/include/limb/u64.h index f2d369a..6f67174 100644 --- a/src/liblimb/include/limb/u64.h +++ b/src/liblimb/include/limb/u64.h @@ -4,8 +4,9 @@ #ifndef LIMB_U64_H #define LIMB_U64_H +#include <stddef.h> /* size_t */ +#include <skalibs/uint64.h> #include <limb/int.h> -#include <limb/uint64.h> #define u64_le(u) uint64_little(u) #define u64_be(u) uint64_big(u) @@ -19,11 +20,12 @@ #define u64_unpack(val,sce) uint64_unpack((const char *) (sce), val) #define u64_pack_big(dst,val) uint64_pack_big((char *) (dst), val) #define u64_unpack_big(val,sce) uint64_unpack_big((const char *) (sce), val) -#define u64_pack_trim(dst,dl,val) uint64_pack_trim((char *) (dst), dl, val) -#define u64_unpack_trim(val,sce,sl) uint64_unpack_trim((const char *) (sce), sl, val) + +extern int u64_pack_trim(char *dst, size_t dlen, u64 val); +extern int u64_unpack_trim(u64 *val, const char *sce, size_t slen); extern size_t u64_fmt_generic(char *s, u64 u, u8 base, u8 grp, const char sep); -extern size_t u640_fmt_generic(char *s, u64 u, u8 base, size_t min, const char fill, +extern size_t u64_0fmt_generic(char *s, u64 u, u8 base, size_t min, const char fill, u8 grp, const char sep); #define U64_FMT 21 @@ -38,20 +40,22 @@ extern size_t u640_fmt_generic(char *s, u64 u, u8 base, size_t min, const char f #define u64_ofmt(s,u) u64_fmt_generic(s, (u), 8, 0, 0) #define u64_bfmt(s,u) u64_fmt_generic(s, (u), 2, 0, 0) -#define u640_fmt(s,u,m) u640_fmt_generic(s, (u), 10, (m), '0', 0, 0) -#define u640_fmtg(s,u,m) u640_fmt_generic(s, (u), 10, (m), '0', 3, ',') -#define u640_xfmt(s,u,m) u640_fmt_generic(s, (u), 16, (m), '0', 0, 0) -#define u640_ofmt(s,u,m) u640_fmt_generic(s, (u), 8, (m), '0', 0, 0) -#define u640_bfmt(s,u,m) u640_fmt_generic(s, (u), 2, (m), '0', 0, 0) +#define u64_0fmt(s,u,m) u64_0fmt_generic(s, (u), 10, (m), '0', 0, 0) +#define u64_0fmtg(s,u,m) u64_0fmt_generic(s, (u), 10, (m), '0', 3, ',') +#define u64_0xfmt(s,u,m) u64_0fmt_generic(s, (u), 16, (m), '0', 0, 0) +#define u64_0ofmt(s,u,m) u64_0fmt_generic(s, (u), 8, (m), '0', 0, 0) +#define u64_0bfmt(s,u,m) u64_0fmt_generic(s, (u), 2, (m), '0', 0, 0) #define u64_scan(dst,s) uint64_scan(s, (dst)) #define u64_xscan(dst,s) uint64_xscan(s, (dst)) #define u64_oscan(dst,s) uint64_oscan(s, (dst)) #define u64_bscan(dst,s) uint64_bscan(s, (dst)) -#define u640_scan(dst,s) uint640_scan(s, (dst)) -#define u640_xscan(dst,s) uint640_xscan(s, (dst)) -#define u640_oscan(dst,s) uint640_oscan(s, (dst)) -#define u640_bscan(dst,s) uint640_bscan(s, (dst)) +#define u64_scan0(dst,s) uint640_scan(s, (dst)) +#define u64_xscan0(dst,s) uint640_xscan(s, (dst)) +#define u64_oscan0(dst,s) uint640_oscan(s, (dst)) +#define u64_bscan0(dst,s) uint640_bscan(s, (dst)) + +extern int msb64(u64 val); #endif /* LIMB_U64_H */ diff --git a/src/liblimb/include/limb/uint64.h b/src/liblimb/include/limb/uint64.h deleted file mode 100644 index bb1d8cb..0000000 --- a/src/liblimb/include/limb/uint64.h +++ /dev/null @@ -1,15 +0,0 @@ -/* This file is part of limb https://lila.oss/limb - * Copyright (C) 2023 Olivier Brunel jjk@jjacky.com */ -/* SPDX-License-Identifier: GPL-2.0-only */ -#ifndef LIMB_UINT64_H -#define LIMB_UINT64_H - -#include <skalibs/uint64.h> -#include <limb/int.h> - -extern int msb64(uint64_t val); - -extern int uint64_pack_trim(char *dst, size_t dlen, uint64_t val); -extern int uint64_unpack_trim(const char *sce, size_t slen, uint64_t *val); - -#endif /* LIMB_UINT64_H */ diff --git a/src/liblimb/nextsplit.h/nextsplit_buz.c b/src/liblimb/nextsplit.h/nextsplit_buz.c index ba7ecd8..319f2da 100644 --- a/src/liblimb/nextsplit.h/nextsplit_buz.c +++ b/src/liblimb/nextsplit.h/nextsplit_buz.c @@ -33,7 +33,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <limb/nextsplit.h> -#include <limb/uint64.h> +#include <limb/u64.h> size_t nextsplit_buz(size_t min, size_t avg, const void *data, size_t dlen) diff --git a/src/liblimb/nextsplit.h/nextsplit_rabin.c b/src/liblimb/nextsplit.h/nextsplit_rabin.c index 9dde5c7..c6a0ad3 100644 --- a/src/liblimb/nextsplit.h/nextsplit_rabin.c +++ b/src/liblimb/nextsplit.h/nextsplit_rabin.c @@ -2,7 +2,7 @@ * Copyright (C) 2023 Olivier Brunel jjk@jjacky.com */ /* SPDX-License-Identifier: GPL-2.0-only */ #include <limb/nextsplit.h> -#include <limb/uint64.h> +#include <limb/u64.h> #include <limb/rabin-tables.h> /* This is based on rabin fingerprint, using a miw of two different variants : diff --git a/src/liblimb/uint64.h/msb64.c b/src/liblimb/u64.h/msb64.c similarity index 100% rename from src/liblimb/uint64.h/msb64.c rename to src/liblimb/u64.h/msb64.c diff --git a/src/liblimb/u640_fmt_generic.c b/src/liblimb/u64.h/u64_0fmt_generic.c similarity index 89% rename from src/liblimb/u640_fmt_generic.c rename to src/liblimb/u64.h/u64_0fmt_generic.c index e07fdd9..d943e20 100644 --- a/src/liblimb/u640_fmt_generic.c +++ b/src/liblimb/u64.h/u64_0fmt_generic.c @@ -5,7 +5,7 @@ #include <limb/u64.h> size_t -u640_fmt_generic(char *s, u64 u, u8 base, size_t min, const char fill, +u64_0fmt_generic(char *s, u64 u, u8 base, size_t min, const char fill, u8 grp, const char sep) { size_t len = u64_fmt_generic(0, u, base, grp, sep); diff --git a/src/liblimb/u64_fmt_generic.c b/src/liblimb/u64.h/u64_fmt_generic.c similarity index 100% rename from src/liblimb/u64_fmt_generic.c rename to src/liblimb/u64.h/u64_fmt_generic.c diff --git a/src/liblimb/uint64.h/uint64_pack_trim.c b/src/liblimb/u64.h/u64_pack_trim.c similarity index 79% rename from src/liblimb/uint64.h/uint64_pack_trim.c rename to src/liblimb/u64.h/u64_pack_trim.c index b4252c1..1aaa415 100644 --- a/src/liblimb/uint64.h/uint64_pack_trim.c +++ b/src/liblimb/u64.h/u64_pack_trim.c @@ -1,18 +1,17 @@ /* This file is part of limb https://lila.oss/limb * Copyright (C) 2023 Olivier Brunel jjk@jjacky.com */ /* SPDX-License-Identifier: GPL-2.0-only */ -#include <skalibs/uint64.h> -#include <limb/uint64.h> +#include <limb/u64.h> int -uint64_pack_trim(char *dst_, size_t dlen, uint64_t val) +u64_pack_trim(char *dst_, size_t dlen, u64 val) { - uint8_t *dst = (uint8_t *) dst_; + u8 *dst = (u8 *) dst_; unsigned int bits = msb64(val); unsigned int b = 0; /* ensure little endianness */ - uint64_littlep(&val); + u64p_le(&val); for (;;) { int n = bits > 7 ? 7 : bits; diff --git a/src/liblimb/uint64.h/uint64_unpack_trim.c b/src/liblimb/u64.h/u64_unpack_trim.c similarity index 70% rename from src/liblimb/uint64.h/uint64_unpack_trim.c rename to src/liblimb/u64.h/u64_unpack_trim.c index dbece48..00546ed 100644 --- a/src/liblimb/uint64.h/uint64_unpack_trim.c +++ b/src/liblimb/u64.h/u64_unpack_trim.c @@ -1,12 +1,12 @@ /* This file is part of limb https://lila.oss/limb * Copyright (C) 2023 Olivier Brunel jjk@jjacky.com */ /* SPDX-License-Identifier: GPL-2.0-only */ -#include <limb/uint64.h> +#include <limb/u64.h> int -uint64_unpack_trim(const char *sce_, size_t slen, uint64_t *val) +u64_unpack_trim(u64 *val, const char *sce_, size_t slen) { - const uint8_t *sce = (const uint8_t *) sce_; + const u8 *sce = (const u8 *) sce_; unsigned int b = 0; *val = 0; @@ -14,14 +14,14 @@ uint64_unpack_trim(const char *sce_, size_t slen, uint64_t *val) /* is there a(nother) byte to read? */ if (b >= slen) return -1; - uint8_t byte = sce[b]; + u8 byte = sce[b]; /* if we're on the last byte, add the last 8 bits and be done */ if (b == 8) { - *val |= (uint64_t) byte << (7 * 8); + *val |= (u64) byte << (7 * 8); break; } /* extract the last 7 bits from byte and add them into our val */ - *val |= (uint64_t) (byte & 127) << (7 * b); + *val |= (u64) (byte & 127) << (7 * b); /* are we done? */ if (!(byte & 128)) break; diff --git a/src/mkrabintables/msb64.o b/src/mkrabintables/msb64.o index 933269a..d18ec1c 120000 --- a/src/mkrabintables/msb64.o +++ b/src/mkrabintables/msb64.o @@ -1 +1 @@ -liblimb/uint64.h/msb64.o \ No newline at end of file +liblimb/u64.h/msb64.o \ No newline at end of file diff --git a/src/mkrabintables/u64_fmt_generic.o b/src/mkrabintables/u64_fmt_generic.o index cf2a63c..37c8748 120000 --- a/src/mkrabintables/u64_fmt_generic.o +++ b/src/mkrabintables/u64_fmt_generic.o @@ -1 +1 @@ -liblimb/u64_fmt_generic.o \ No newline at end of file +liblimb/u64.h/u64_fmt_generic.o \ No newline at end of file