From 4f0380dafa4748ad12ebf39b5dc132eae6823c60 Mon Sep 17 00:00:00 2001 From: Koichi Nakamura Date: Wed, 5 May 2021 23:09:48 +0900 Subject: [PATCH] WIP: bitscan reverse --- lib/bitscan.fs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/bitscan.fs b/lib/bitscan.fs index 5c2f6bc..47d13e0 100644 --- a/lib/bitscan.fs +++ b/lib/bitscan.fs @@ -37,12 +37,29 @@ create bsf-modulo-131-table cells bsf-modulo-131-table + @ ; export -create msb-index-table +create msb-table + -1 , 0 , 1 , 1 , 2 , 2 , 2 , 2 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , + 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , + 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , + 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , + 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , + 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , + 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , + 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , + 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , + 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , + 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , + 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , + 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , + 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , + 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , + 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 , \ Find the index of the most significant 1 bit \ If u == 0, returns -1 : bitscan-reverse ( u -- u ) + dup 0xff u< if cells msb-table + @ exit then ; export }private @@ -56,3 +73,12 @@ T{ 5 bitscan-forward -> 0 }T T{ -1 bitscan-forward -> 0 }T T{ max-int bitscan-forward -> 0 }T T{ min-int bitscan-forward -> cell 8 * 1- }T + +T{ 0 bitscan-reverse -> -1 }T +T{ 1 bitscan-reverse -> 0 }T +T{ 2 bitscan-reverse -> 1 }T +T{ 3 bitscan-reverse -> 1 }T +T{ 4 bitscan-reverse -> 2 }T +T{ -1 bitscan-reverse -> cell 8 * 1- }T +T{ max-int bitscan-reverse -> cell 8 * 2 - }T +T{ min-int bitscan-reverse -> cell 8 * 1- }T