cosmopolitan/test/libc/intrin/bextra_test.c

116 lines
5.5 KiB
C
Raw Normal View History

2021-10-04 10:23:31 +00:00
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2021 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
2022-08-11 19:13:18 +00:00
#include "libc/intrin/bits.h"
2022-06-27 20:01:58 +00:00
#include "libc/calls/calls.h"
2021-10-04 10:23:31 +00:00
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
2022-07-25 05:34:13 +00:00
void SetUpOnce(void) {
ASSERT_SYS(0, 0, pledge("stdio", 0));
2022-06-27 20:01:58 +00:00
}
2021-10-04 10:23:31 +00:00
unsigned P[] = {
// 33333222222222111111111000000000
0b000011000000010000000001000000000, //
// 76666666665555555554444444443333
0b010000001100000001010000001000000, //
0b000101000000100100000100000000011, //
0b010000001101000001100000001011000, //
0b000100010000100000000011110000011, //
0b010100001010000001001100001001000, //
0b000011000000010111000010110000010, //
0b011000000110110000110100000110010, //
0b000001111100001111000001110100001, //
0b000011000100010000100001000100000, //
0b010001001100001001010001001000001, //
0b010101000010100100010100000010011, //
0b010000101101000101100000101011000, //
0b001100010001100000001011110001011, //
0b010100011010000011001100011001000, //
0b000111000000110111000110110000110, //
0b011000001110110001110100001110010, //
0b000011111100011111000011110100011, //
0b000011001000010001000001001000000, //
0b010010001100010001010010001000010, //
0b000101000100100100100100000100011, //
0b010001001101001001100001001011001, //
0b010100010010100000010011110010011, //
0b010100101010000101001100101001000, //
0b001011000001010111001010110001010, //
0b011000010110110010110100010110010, //
0b000101111100101111000101110100101, //
0b000011001100010001100001001100000, //
0b010011001100011001010011001000011, //
0b010101000110100100110100000110011, //
0b010001101101001101100001101011001, //
0b011100010011100000011011110011011, //
0b010100111010000111001100111001000, //
0b001111000001110111001110110001110, //
0b011000011110110011110100011110010, //
0b000111111100111111000111110100111, //
0b000011010000010010000001010000000, //
0b010100001100100001010100001000100, //
0b000101001000100101000100001000011, //
0b010010001101010001100010001011010, //
0b000100010100100000100011110100011, //
0b010101001010001001001101001001001, //
0b010011000010010111010010110010010, //
0b011000100110110100110100100110010, //
0b001001111101001111001001110101001, //
0b000011010100010010100001010100000, //
0b010101001100101001010101001000101, //
0b010101001010100101010100001010011, //
0b010010101101010101100010101011010, //
0b001100010101100000101011110101011, //
0b010101011010001011001101011001001, //
0b010111000010110111010110110010110, //
0b011000101110110101110100101110010, //
0b001011111101011111001011110101011, //
0b000011011000010011000001011000000, //
0b010110001100110001010110001000110, //
0b000101001100100101100100001100011, //
0b010011001101011001100011001011011, //
0b010100010110100000110011110110011, //
0b010101101010001101001101101001001, //
0b011011000011010111011010110011010, //
0b011000110110110110110100110110010, //
0b001101111101101111001101110101101, //
0b000011011100010011100001011100000, //
0b010111001100111001010111001000111, //
0b010101001110100101110100001110011, //
0b010011101101011101100011101011011, //
0b011100010111100000111011110111011, //
0b010101111010001111001101111001001, //
0b011111000011110111011110110011110, //
0b011000111110110111110100111110010, //
0b001111111101111111001111110101111, //
0b000000000000000000000000100000000, //
};
TEST(bextra, 9bit) {
int i;
for (i = 4; i < 257; ++i) {
ASSERT_EQ(i, bextra(P, i, 9));
}
}
BENCH(bextra, bench) {
EZBENCH2("bextra 1/31", donothing, bextra(P, 1, 31));
}