| 1 | /* |
| 2 | * Copyright (c) 2015-2019, Intel Corporation |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * * Redistributions of source code must retain the above copyright notice, |
| 8 | * this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * * Neither the name of Intel Corporation nor the names of its contributors |
| 13 | * may be used to endorse or promote products derived from this software |
| 14 | * without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 26 | * POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #ifndef FDR_CONFIRM_H |
| 30 | #define FDR_CONFIRM_H |
| 31 | |
| 32 | #include "ue2common.h" |
| 33 | #include "hwlm/hwlm.h" |
| 34 | |
| 35 | static really_inline |
| 36 | u32 mul_hash_64(u64a lv, u64a andmsk, u64a mult, u32 nBits) { |
| 37 | return ((lv & andmsk) * mult) >> (sizeof(u64a)*8 - nBits); |
| 38 | } |
| 39 | |
| 40 | // data structures |
| 41 | // TODO: fix this hard-coding |
| 42 | #define CONF_TYPE u64a |
| 43 | #define CONF_HASH_CALL mul_hash_64 |
| 44 | |
| 45 | /** |
| 46 | * \brief Flag indicating this literal doesn't need to be delivered more than |
| 47 | * once, used in LitInfo::flags. |
| 48 | */ |
| 49 | #define FDR_LIT_FLAG_NOREPEAT 1 |
| 50 | |
| 51 | /** |
| 52 | * \brief Structure describing a literal, linked to by FDRConfirm. |
| 53 | * |
| 54 | * This structure is followed in memory by a variable-sized string prefix, for |
| 55 | * strings that are longer than CONF_TYPE. |
| 56 | */ |
| 57 | struct LitInfo { |
| 58 | CONF_TYPE v; |
| 59 | CONF_TYPE msk; |
| 60 | hwlm_group_t groups; |
| 61 | u32 id; // literal ID as passed in |
| 62 | u8 size; |
| 63 | u8 flags; //!< bitfield of flags from FDR_LIT_FLAG_* above. |
| 64 | u8 next; |
| 65 | u8 pure; //!< The pass-on of pure flag from hwlmLiteral. |
| 66 | }; |
| 67 | |
| 68 | #define FDRC_FLAG_NO_CONFIRM 1 |
| 69 | #define FDRC_FLAG_NOREPEAT 2 |
| 70 | |
| 71 | /** |
| 72 | * \brief FDR confirm header. |
| 73 | * |
| 74 | * This structure is followed in memory by: |
| 75 | * |
| 76 | * -# lit index mapping (array of u32) |
| 77 | * -# list of LitInfo structures |
| 78 | */ |
| 79 | struct FDRConfirm { |
| 80 | CONF_TYPE andmsk; |
| 81 | CONF_TYPE mult; |
| 82 | u32 nBits; |
| 83 | hwlm_group_t groups; |
| 84 | }; |
| 85 | |
| 86 | static really_inline |
| 87 | const u32 *getConfirmLitIndex(const struct FDRConfirm *fdrc) { |
| 88 | const u8 *base = (const u8 *)fdrc; |
| 89 | const u32 *litIndex = |
| 90 | (const u32 *)(base + ROUNDUP_N(sizeof(*fdrc), alignof(u32))); |
| 91 | assert(ISALIGNED(litIndex)); |
| 92 | return litIndex; |
| 93 | } |
| 94 | |
| 95 | #endif // FDR_CONFIRM_H |
| 96 | |