tests: Add unit tests for mulu64 and muls64
Quoted 8 lines · Richard Henderson
Quoted 7 lines · Blue Swirl
Quoted 5 lines
(quoted diff) +4
-0+static const Test test_u_data[] = { + { 1, 1, 0, 1 }, + { 10000, 10000, 0, 100000000 }, + { -1ull, 2, 1, -2ull },
Quoted 6 lines
Quoted 1 line
Shouldn't '1' be '-1'? How can this test pass?
This is 0xffff_ffff_ffff_ffff * 2 = 0x1_ffff_ffff_ffff_fffe
with the knowledge that -1 = 0xf...f and -2 = 0xf...e.
OK, I somehow used signed multiplication rules.
Quoted 17 lines
Quoted 6 lines
Quoted 3 lines
+ { -1ull, -1ull, -2ull, 1 },
This looks buggy too.
See above.
Quoted 6 lines
Quoted 4 lines
(quoted diff) +4
-0+ { -10, -10, 0, 100 }, + { 10000, 10000, 0, 100000000 }, + { -1, 2, -1, -2 }, + { 0x1122334455667788ll, 0x1122334455667788ull,
Quoted 4 lines
Quoted 1 line
Spurious 'll', also below.
Why spurious?
I'd use ULL/ull everywhere for hex constants.
Quoted 27 lines
Quoted 14 lines
Review
Quoted 10 lines
(quoted diff) +8
-0+static void test_u(void) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(test_u_data); ++i) { + uint64_t rl, rh; + mulu64(&rl, &rh, test_u_data[i].a, test_u_data[i].b); + g_assert_cmpuint(rl, ==, test_u_data[i].rl);This could explain why the test passes:
g_assert_cmpuint()uses unsigned ints so there is truncation fromuint64_t.Does it? It sure doesn't look like it:
Quoted 7 lines
#define
g_assert_cmpuint(n1, cmp, n2)do { guint64__n1= (n1),__n2=(n2); \ if (__n1 cmp __n2) ; else \ g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ #n1 " " #cmp " " #n2,
__n1, #cmp,__n2, 'i'); } while (0)
Quoted 1 line
I see guint64 in there, thus no truncation.
The manual only talks about unsigned integers, maybe they really mean guint64:
http://developer.gnome.org/glib/2.34/glib-Testing.html#g-assert-cmpuint
Quoted 16 lines
Quoted 10 lines
Review
Quoted 7 lines
(quoted diff) +5
-0+static void test_s(void) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(test_u_data); ++i) {
test_s_dataGood catch. I wasn't running all of the
test_sdata points.r~