/* * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code 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 * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
TEST_VM(unsigned5, max_encoded_in_length) { int maxlen = UNSIGNED5::MAX_LENGTH;
EXPECT_EQ(maxlen, 5); for (int i = 0; i <= 190; i++) {
uint32_t interesting = i;
EXPECT_EQ(UNSIGNED5::encoded_length(interesting), 1);
EXPECT_EQ(UNSIGNED5::encoded_length(~interesting), maxlen);
} for (int len = 1; len <= maxlen; len++) {
uint32_t interesting = UNSIGNED5::max_encoded_in_length(len);
EXPECT_EQ(UNSIGNED5::encoded_length(interesting-1), len);
EXPECT_EQ(UNSIGNED5::encoded_length(interesting), len); if (len < 5) {
EXPECT_EQ(UNSIGNED5::encoded_length(interesting+1), len+1);
EXPECT_EQ(UNSIGNED5::encoded_length(interesting*2), len+1);
} constint offset = -123; constint good_limit = offset + len; constint bad_limit = good_limit - 1;
EXPECT_TRUE(UNSIGNED5::fits_in_limit(interesting, offset, good_limit));
EXPECT_TRUE(!UNSIGNED5::fits_in_limit(interesting, offset, bad_limit));
}
}
// Call FN on a nice list of "interesting" uint32_t values to encode/decode. // For each length in [1..5], the maximum encodable value of that // length is "interesting", as are one more and one less than that // value. For each nybble (aligned 4-bit field) of a uint32_t, each // possible value (in [0..15]) stored in that nybble is "interesting". // Also "interesting" are some other values created by perturbing // lower bits of that nybble-bearing number, by subtracting a power // of -7 (up to -7^7). That makes just over 1000 distinct numbers. // // Calls to this function are repeatable, so you can call it to pack // an output array, and then call it again to read an input array // verifying that the retrieved values match the stored ones. template<typename FN> inlineint enumerate_cases(FN fn) { // boundary values around the maximum encoded in each byte-length for (int len = 1; len <= 5; len++) {
uint32_t interesting = UNSIGNED5::max_encoded_in_length(len); int res = fn(interesting-1); if (res) return res;
res = fn(interesting); if (res) return res; if (interesting < (uint32_t)-1) {
res = fn(interesting+1); if (res) return res;
}
} // for each nybble, for each value in the nybble for (uint32_t npos = 0; npos < 32; npos += 4) { for (uint32_t nval = 0; nval <= 15; nval++) {
uint32_t interesting = nval << npos; int res = fn(interesting); if (res) return res; // mix in some crazy-looking values: powers of -7 to -7^7 for (int pon7 = 1; pon7 < 1000000; pon7 *= -7) {
uint32_t interesting2 = interesting - pon7;
res = fn(interesting2); if (res) return res;
}
}
} return 0;
}
// Here is some object code to look at if we want to do a manual // study. One could find the build file named test_unsigned5.o.cmdline // and hand-edit the command line to produce assembly code in // test_unsigned5.s. // // Or, given the two empty "fence functions", one could do a // quick scan like this: // // $ objdump -D $(find build/*release -name test_unsigned5.o) \ // | sed -n /start_code_quality/,/end_code_quality/p \ // | egrep -B10 bswap # or grep -B20 cfi_endproc
void start_code_quality_unsigned5() { }
uint32_t code_quality_max_encoded_in_length(int i) { return UNSIGNED5::max_encoded_in_length(i); // should compile like 5-switch
}
int code_quality_encoded_length(uint32_t x) { return UNSIGNED5::encoded_length(x); // should compile to 4-way comparison
}
int code_quality_check_length(char* a) { return UNSIGNED5::check_length(a, 0); // should compile with fast-path
}
int code_quality_read_int(char* a) { int i = 0; return UNSIGNED5::read_uint(a, i, 0); // should compile with fast-path
}
int code_quality_int_reader(char* a) {
MyReader r1(a); if (!r1.has_next()) return -1; return r1.next_uint();
}
int code_quality_int_sizer(int* a, int n) {
UNSIGNED5::Sizer<> s; for (int i = 0; i < n; i++) s.accept_uint(a[i]); return s.position();
}
void end_code_quality_unsigned5() { }
Messung V0.5
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.