-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Remove printf() call on release builds. This is more deterministic than printf() modifiers. We only use it printing u64, f32 variables. - Add unit tests.
- Loading branch information
Showing
12 changed files
with
1,211 additions
and
387 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: test | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
pull_request: | ||
branches: [ "master" ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: install packages | ||
run: sudo apt-get install -y --no-install-recommends --no-install-suggests | ||
meson ninja-build | ||
liburing-dev | ||
libwayland-dev libwayland-client0 wayland-protocols | ||
|
||
- name: configure | ||
run: meson setup build --buildtype release -Dtest=true | ||
|
||
- name: test | ||
run: meson test -C build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
|
||
#if GAMEPAD_IDLE_INHIBIT_DEBUG | ||
#define debug_assert(x) \ | ||
if (!(x)) { \ | ||
__builtin_debugtrap(); \ | ||
} | ||
#else | ||
#define debug_assert(x) | ||
#endif | ||
|
||
#define runtime_assert(x) \ | ||
if (!(x)) { \ | ||
__builtin_trap(); \ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#pragma once | ||
|
||
#include "type.h" | ||
|
||
/* | ||
* Returns binary logarithm of π₯. | ||
* | ||
* ctz(π₯) 31^clz(π₯) clz(π₯) | ||
* uint32 π₯ bsf(π₯) tzcnt(π₯) ffs(π₯) bsr(π₯) lzcnt(π₯) | ||
* 0x00000000 wut 32 0 wut 32 | ||
* 0x00000001 0 0 1 0 31 | ||
* 0x80000001 0 0 1 31 0 | ||
* 0x80000000 31 31 32 31 0 | ||
* 0x00000010 4 4 5 4 27 | ||
* 0x08000010 4 4 5 27 4 | ||
* 0x08000000 27 27 28 27 4 | ||
* 0xffffffff 0 0 1 31 0 | ||
* | ||
* @param x is a 64-bit integer | ||
* @return number in range 0..63 or undefined if π₯ is 0 | ||
* | ||
* @note Adapted from https://github.com/jart/cosmopolitan/blob/master/libc/intrin/bsrl.c | ||
* @copyright | ||
* ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | ||
* β Copyright 2023 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. β | ||
* ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | ||
*/ | ||
static inline u8 | ||
bsrl(s64 x) | ||
{ | ||
static const u8 kDebruijn[64] = { | ||
0, 47, 1, 56, 48, 27, 2, 60, 57, 49, 41, 37, 28, 16, 3, 61, 54, 58, 35, 52, 50, 42, | ||
21, 44, 38, 32, 29, 23, 17, 11, 4, 62, 46, 55, 26, 59, 40, 36, 15, 53, 34, 51, 20, 43, | ||
31, 22, 10, 45, 25, 39, 14, 33, 19, 30, 9, 24, 13, 18, 8, 12, 7, 6, 5, 63, | ||
}; | ||
|
||
x |= x >> 1; | ||
x |= x >> 2; | ||
x |= x >> 4; | ||
x |= x >> 8; | ||
x |= x >> 16; | ||
x |= x >> 32; | ||
return kDebruijn[(x * 0x03f79d71b4cb0a89ull) >> 58]; | ||
} |
Oops, something went wrong.