Add wasm tacle-bench targets

This commit is contained in:
2026-06-12 20:06:22 +02:00
parent 30daa8a00c
commit 08c2e9c13d
1122 changed files with 520422 additions and 0 deletions

View File

@ -0,0 +1,584 @@
(module $bitcount.wasm
(type (;0;) (func (param i32 i32)))
(type (;1;) (func))
(type (;2;) (func (result i32)))
(type (;3;) (func (param i32) (result i32)))
(import "__pragma" "loopbound" (func $__pragma_loopbound (type 0)))
(func $__wasm_apply_data_relocs (type 1))
(func $bitcount_main (type 1)
(local i32 i32 i32 i32 i32 i32)
i32.const 8
i32.const 8
call $__pragma_loopbound
i32.const 0
local.set 0
loop ;; label = @1
i32.const 10
i32.const 10
call $__pragma_loopbound
i32.const 0
i32.const 0
i32.load offset=1540
local.tee 1
i32.const 127773
i32.div_s
local.tee 2
i32.const -2836
i32.mul
local.get 1
local.get 2
i32.const 127773
i32.mul
i32.sub
i32.const 16807
i32.mul
i32.add
local.tee 1
i32.const 2147483647
i32.add
local.get 1
local.get 1
i32.const 1
i32.lt_s
select
local.tee 1
i32.store offset=1548
i32.const 0
local.get 1
i32.store offset=1540
block ;; label = @2
i32.const 0
i32.load offset=1544
i32.eqz
br_if 0 (;@2;)
i32.const 0
local.set 3
loop ;; label = @3
block ;; label = @4
block ;; label = @5
block ;; label = @6
block ;; label = @7
block ;; label = @8
block ;; label = @9
block ;; label = @10
block ;; label = @11
block ;; label = @12
local.get 0
br_table 0 (;@12;) 1 (;@11;) 2 (;@10;) 3 (;@9;) 4 (;@8;) 5 (;@7;) 6 (;@6;) 7 (;@5;) 0 (;@12;)
end
local.get 1
call $bitcount_bit_count
local.set 2
br 7 (;@4;)
end
local.get 1
call $bitcount_bitcount
local.set 2
br 6 (;@4;)
end
local.get 1
call $bitcount_ntbl_bitcnt
local.set 2
br 5 (;@4;)
end
local.get 1
call $bitcount_btbl_bitcnt
local.set 2
br 4 (;@4;)
end
local.get 1
call $bitcount_ntbl_bitcount
local.set 2
br 3 (;@4;)
end
local.get 1
call $bitcount_BW_btbl_bitcount
local.set 2
br 2 (;@4;)
end
local.get 1
call $bitcount_AR_btbl_bitcount
local.set 2
br 1 (;@4;)
end
i32.const 31
i32.const 31
call $__pragma_loopbound
block ;; label = @5
local.get 1
br_if 0 (;@5;)
i32.const 0
local.set 2
br 1 (;@4;)
end
i32.const 0
local.set 4
i32.const 0
local.set 2
loop ;; label = @5
local.get 1
i32.const 1
i32.and
local.get 2
i32.add
local.set 2
local.get 1
i32.const 2
i32.lt_u
br_if 1 (;@4;)
local.get 1
i32.const 1
i32.shr_s
local.set 1
local.get 4
i32.const 31
i32.lt_u
local.set 5
local.get 4
i32.const 1
i32.add
local.set 4
local.get 5
br_if 0 (;@5;)
end
end
i32.const 0
local.get 2
i32.store offset=1552
i32.const 0
i32.const 0
i32.load offset=1536
local.get 2
i32.add
i32.store offset=1536
i32.const 0
i32.const 0
i32.load offset=1548
i32.const 13
i32.add
local.tee 1
i32.store offset=1548
local.get 3
i32.const 1
i32.add
local.tee 3
i32.const 0
i32.load offset=1544
i32.lt_u
br_if 0 (;@3;)
end
end
local.get 0
i32.const 1
i32.add
local.tee 0
i32.const 8
i32.ne
br_if 0 (;@1;)
end)
(func $__original_main (type 2) (result i32)
i32.const 0
i32.const 1
i32.store offset=1540
i32.const 0
i32.const 10
i32.store offset=1544
i32.const 0
i32.const 0
i32.store offset=1536
call $bitcount_init3
call $bitcount_init4
call $bitcount_main
i32.const 0
i32.load offset=1536
i32.const 1095
i32.ne)
(func $bitcount_bit_count (type 3) (param i32) (result i32)
(local i32)
block ;; label = @1
local.get 0
br_if 0 (;@1;)
i32.const 0
return
end
i32.const 3
i32.const 8
call $__pragma_loopbound
i32.const 0
local.set 1
loop ;; label = @1
local.get 1
i32.const 1
i32.add
local.set 1
local.get 0
i32.const -1
i32.add
local.get 0
i32.and
local.tee 0
br_if 0 (;@1;)
end
local.get 1)
(func $bitcount_bitcount (type 3) (param i32) (result i32)
local.get 0
i32.const 1
i32.shr_u
i32.const 1431655765
i32.and
local.get 0
i32.const 1431655765
i32.and
i32.add
local.tee 0
i32.const 2
i32.shr_u
i32.const 858993459
i32.and
local.get 0
i32.const 858993459
i32.and
i32.add
local.tee 0
i32.const 4
i32.shr_u
i32.const 117901063
i32.and
local.get 0
i32.const 117901063
i32.and
i32.add
local.tee 0
i32.const 8
i32.shr_u
i32.const 983055
i32.and
local.get 0
i32.const 983055
i32.and
i32.add
local.tee 0
i32.const 16
i32.shr_u
local.get 0
i32.const 31
i32.and
i32.add)
(func $bitcount_init3 (type 1)
(local i32 i32)
global.get $__stack_pointer
i32.const 16
i32.sub
local.tee 0
i32.const 0
i32.store offset=12
local.get 0
i32.const 0
i32.store offset=12
block ;; label = @1
local.get 0
i32.load offset=12
i32.const 255
i32.gt_s
br_if 0 (;@1;)
loop ;; label = @2
local.get 0
i32.load offset=12
local.set 1
local.get 0
i32.load offset=12
i32.const 1568
i32.add
local.get 1
i32.const 1024
i32.add
i32.load8_u
i32.store8
local.get 0
local.get 0
i32.load offset=12
i32.const 1
i32.add
i32.store offset=12
local.get 0
i32.load offset=12
i32.const 256
i32.lt_s
br_if 0 (;@2;)
end
end)
(func $bitcount_ntbl_bitcount (type 3) (param i32) (result i32)
local.get 0
i32.const 4
i32.shr_u
i32.const 15
i32.and
i32.const 1568
i32.add
i32.load8_s
local.get 0
i32.const 15
i32.and
i32.const 1568
i32.add
i32.load8_s
i32.add
local.get 0
i32.const 8
i32.shr_u
i32.const 15
i32.and
i32.const 1568
i32.add
i32.load8_s
i32.add
local.get 0
i32.const 12
i32.shr_u
i32.const 15
i32.and
i32.const 1568
i32.add
i32.load8_s
i32.add
local.get 0
i32.const 16
i32.shr_u
i32.const 15
i32.and
i32.const 1568
i32.add
i32.load8_s
i32.add
local.get 0
i32.const 20
i32.shr_u
i32.const 15
i32.and
i32.const 1568
i32.add
i32.load8_s
i32.add
local.get 0
i32.const 24
i32.shr_u
i32.const 15
i32.and
i32.const 1568
i32.add
i32.load8_s
i32.add
local.get 0
i32.const 28
i32.shr_u
i32.const 1568
i32.add
i32.load8_s
i32.add)
(func $bitcount_BW_btbl_bitcount (type 3) (param i32) (result i32)
local.get 0
i32.const 8
i32.shr_u
i32.const 255
i32.and
i32.const 1568
i32.add
i32.load8_s
local.get 0
i32.const 255
i32.and
i32.const 1568
i32.add
i32.load8_s
i32.add
local.get 0
i32.const 24
i32.shr_u
i32.const 1568
i32.add
i32.load8_s
i32.add
local.get 0
i32.const 16
i32.shr_u
i32.const 255
i32.and
i32.const 1568
i32.add
i32.load8_s
i32.add)
(func $bitcount_AR_btbl_bitcount (type 3) (param i32) (result i32)
local.get 0
i32.const 8
i32.shr_u
i32.const 255
i32.and
i32.const 1568
i32.add
i32.load8_s
local.get 0
i32.const 255
i32.and
i32.const 1568
i32.add
i32.load8_s
i32.add
local.get 0
i32.const 16
i32.shr_u
i32.const 255
i32.and
i32.const 1568
i32.add
i32.load8_s
i32.add
local.get 0
i32.const 24
i32.shr_u
i32.const 1568
i32.add
i32.load8_s
i32.add)
(func $bitcount_init4 (type 1)
(local i32 i32)
global.get $__stack_pointer
i32.const 16
i32.sub
local.tee 0
i32.const 0
i32.store offset=12
local.get 0
i32.const 0
i32.store offset=12
block ;; label = @1
local.get 0
i32.load offset=12
i32.const 255
i32.gt_s
br_if 0 (;@1;)
loop ;; label = @2
local.get 0
i32.load offset=12
local.set 1
local.get 0
i32.load offset=12
i32.const 1824
i32.add
local.get 1
i32.const 1280
i32.add
i32.load8_u
i32.store8
local.get 0
local.get 0
i32.load offset=12
i32.const 1
i32.add
i32.store offset=12
local.get 0
i32.load offset=12
i32.const 256
i32.lt_s
br_if 0 (;@2;)
end
end)
(func $bitcount_ntbl_bitcnt (type 3) (param i32) (result i32)
(local i32 i32 i32)
local.get 0
i32.const 15
i32.and
i32.const 1824
i32.add
i32.load8_s
local.set 1
i32.const 0
local.set 2
block ;; label = @1
local.get 0
i32.const 16
i32.lt_u
br_if 0 (;@1;)
i32.const 0
local.set 2
loop ;; label = @2
local.get 1
local.get 2
i32.add
local.set 2
local.get 0
i32.const 255
i32.gt_u
local.set 3
local.get 0
i32.const 4
i32.shr_u
local.tee 0
i32.const 15
i32.and
i32.const 1824
i32.add
i32.load8_s
local.set 1
local.get 3
br_if 0 (;@2;)
end
end
local.get 1
local.get 2
i32.add)
(func $bitcount_btbl_bitcnt (type 3) (param i32) (result i32)
(local i32 i32 i32)
local.get 0
i32.const 255
i32.and
i32.const 1824
i32.add
i32.load8_s
local.set 1
i32.const 0
local.set 2
block ;; label = @1
local.get 0
i32.const 256
i32.lt_u
br_if 0 (;@1;)
i32.const 0
local.set 2
loop ;; label = @2
local.get 1
local.get 2
i32.add
local.set 2
local.get 0
i32.const 65535
i32.gt_u
local.set 3
local.get 0
i32.const 8
i32.shr_u
local.tee 0
i32.const 255
i32.and
i32.const 1824
i32.add
i32.load8_s
local.set 1
local.get 3
br_if 0 (;@2;)
end
end
local.get 1
local.get 2
i32.add)
(table (;0;) 1 1 funcref)
(memory (;0;) 1)
(global $__stack_pointer (mut i32) (i32.const 6176))
(global (;1;) i32 (i32.const 2080))
(global (;2;) i32 (i32.const 6176))
(export "memory" (memory 0))
(export "__wasm_apply_data_relocs" (func $__wasm_apply_data_relocs))
(export "entrypoint" (func $bitcount_main))
(export "main" (func $__original_main))
(export "__data_end" (global 1))
(export "__heap_base" (global 2))
(data $.rodata (i32.const 1024) "\00\01\01\02\01\02\02\03\01\02\02\03\02\03\03\04\01\02\02\03\02\03\03\04\02\03\03\04\03\04\04\05\01\02\02\03\02\03\03\04\02\03\03\04\03\04\04\05\02\03\03\04\03\04\04\05\03\04\04\05\04\05\05\06\01\02\02\03\02\03\03\04\02\03\03\04\03\04\04\05\02\03\03\04\03\04\04\05\03\04\04\05\04\05\05\06\02\03\03\04\03\04\04\05\03\04\04\05\04\05\05\06\03\04\04\05\04\05\05\06\04\05\05\06\05\06\06\07\01\02\02\03\02\03\03\04\02\03\03\04\03\04\04\05\02\03\03\04\03\04\04\05\03\04\04\05\04\05\05\06\02\03\03\04\03\04\04\05\03\04\04\05\04\05\05\06\03\04\04\05\04\05\05\06\04\05\05\06\05\06\06\07\02\03\03\04\03\04\04\05\03\04\04\05\04\05\05\06\03\04\04\05\04\05\05\06\04\05\05\06\05\06\06\07\03\04\04\05\04\05\05\06\04\05\05\06\05\06\06\07\04\05\05\06\05\06\06\07\05\06\06\07\06\07\07\08\00\01\01\02\01\02\02\03\01\02\02\03\02\03\03\04\01\02\02\03\02\03\03\04\02\03\03\04\03\04\04\05\01\02\02\03\02\03\03\04\02\03\03\04\03\04\04\05\02\03\03\04\03\04\04\05\03\04\04\05\04\05\05\06\01\02\02\03\02\03\03\04\02\03\03\04\03\04\04\05\02\03\03\04\03\04\04\05\03\04\04\05\04\05\05\06\02\03\03\04\03\04\04\05\03\04\04\05\04\05\05\06\03\04\04\05\04\05\05\06\04\05\05\06\05\06\06\07\01\02\02\03\02\03\03\04\02\03\03\04\03\04\04\05\02\03\03\04\03\04\04\05\03\04\04\05\04\05\05\06\02\03\03\04\03\04\04\05\03\04\04\05\04\05\05\06\03\04\04\05\04\05\05\06\04\05\05\06\05\06\06\07\02\03\03\04\03\04\04\05\03\04\04\05\04\05\05\06\03\04\04\05\04\05\05\06\04\05\05\06\05\06\06\07\03\04\04\05\04\05\05\06\04\05\05\06\05\06\06\07\04\05\05\06\05\06\06\07\05\06\06\07\06\07\07\08"))

View File

@ -0,0 +1,41 @@
/*
This program is part of the TACLeBench benchmark suite.
Version V 1.x
Name: bitcnt_1.c
Author: Ratko Tomic
Function: Test program for bit counting functions
Source: http://www.snippets.org/.
Changes: no major functional changes
License: May be used, modified, and re-distributed freely.
*/
#include "bitops.h"
// Wasm loop bounds
__attribute__((import_module("__pragma"), import_name("loopbound"))) extern void
__pragma_loopbound(unsigned int min_bound, unsigned int max_bound);
int
bitcount_bit_count(long x) {
int n = 0;
/*
** The loop will execute once for each bit of x set, this is in average
** twice as fast as the shift/test method.
*/
if (x) {
__pragma_loopbound(3, 8);
do {
n++;
} while (0 != (x = x & (x - 1)));
}
return (n);
}

View File

@ -0,0 +1,30 @@
/*
This program is part of the TACLeBench benchmark suite.
Version V 1.x
Name: bitcnt_2.c
Author: Bob Stout & Auke Reitsma
Function: Test program for bit counting functions
Source: http://www.snippets.org/
Changes: no major functional changes
License: May be used, modified, and re-distributed freely.
*/
#include "bitops.h"
int
bitcount_bitcount(long i) {
i = ((i & 0xAAAAAAAAL) >> 1) + (i & 0x55555555L);
i = ((i & 0xCCCCCCCCL) >> 2) + (i & 0x33333333L);
i = ((i & 0xF0F0F0F0L) >> 4) + (i & 0x0F0F0F0FL);
i = ((i & 0xFF00FF00L) >> 8) + (i & 0x00FF00FFL);
i = ((i & 0xFFFF0000L) >> 16) + (i & 0x0000FFFFL);
return (int) i;
}

View File

@ -0,0 +1,98 @@
/*
This program is part of the TACLeBench benchmark suite.
Version V 1.x
Name: bitcnt_3.c
Author: Bob Stout & Auke Reitsma
Function: Bit counting functions using table lookup
Source: http://www.snippets.org/
Changes: no major functional changes
License: May be used, modified, and re-distributed freely.
*/
#include "bitops.h"
static char bitcount_bits[256];
/*
** Count bits in each nybble
**
** Note: Only the first 16 table entries are used, the rest could be
** omitted.
*/
void
bitcount_init3(void) {
int volatile i = 0;
char bitcount_bits_tmp[256] = {
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4,
2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4,
2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6,
4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5,
3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6,
4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8};
for (i = 0; i < 256; i++)
bitcount_bits[i] = bitcount_bits_tmp[i];
}
int
bitcount_ntbl_bitcount(long int x) {
return bitcount_bits[(int) (x & 0x0000000FUL)] +
bitcount_bits[(int) ((x & 0x000000F0UL) >> 4)] +
bitcount_bits[(int) ((x & 0x00000F00UL) >> 8)] +
bitcount_bits[(int) ((x & 0x0000F000UL) >> 12)] +
bitcount_bits[(int) ((x & 0x000F0000UL) >> 16)] +
bitcount_bits[(int) ((x & 0x00F00000UL) >> 20)] +
bitcount_bits[(int) ((x & 0x0F000000UL) >> 24)] +
bitcount_bits[(int) ((x & 0xF0000000UL) >> 28)];
}
/*
** Count bits in each byte
**
** by Bruce Wedding, works best on Watcom & Borland
*/
int
bitcount_BW_btbl_bitcount(long int x) {
union {
unsigned char ch[4];
long y;
} U;
U.y = x;
return bitcount_bits[U.ch[0]] + bitcount_bits[U.ch[1]] +
bitcount_bits[U.ch[3]] + bitcount_bits[U.ch[2]];
}
/*
** Count bits in each byte
**
** by Auke Reitsma, works best on Microsoft, Symantec, and others
*/
int
bitcount_AR_btbl_bitcount(long int x) {
unsigned char *ptr = (unsigned char *) &x;
int accu;
accu = bitcount_bits[*ptr++];
accu += bitcount_bits[*ptr++];
accu += bitcount_bits[*ptr++];
accu += bitcount_bits[*ptr];
return accu;
}

View File

@ -0,0 +1,79 @@
/*
This program is part of the TACLeBench benchmark suite.
Version V 1.x
Name: bitcnt_4.c
Author: Bob Stout
Function: Recursive bit counting functions using table lookup
Source: http://www.snippets.org/
Changes: no major functional changes
License: May be used, modified, and re-distributed freely.
*/
#include "bitops.h" /* from Snippets */
static char bitcount_bits[256];
/*
** Count bits in each nybble
**
** Note: Only the first 16 table entries are used, the rest could be
** omitted.
*/
void
bitcount_init4(void) {
int volatile i = 0;
char bitcount_bits_tmp[256] = {
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4,
2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4,
2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6,
4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5,
3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6,
4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8};
for (i = 0; i < 256; i++)
bitcount_bits[i] = bitcount_bits_tmp[i];
}
int
bitcount_ntbl_bitcnt(unsigned long x) {
int cnt = bitcount_bits[(int) (x & 0x0000000FL)];
if (0L != (x >>= 4))
cnt += bitcount_ntbl_bitcnt(x);
return cnt;
}
/*
** Count bits in each byte
*/
int
bitcount_btbl_bitcnt(unsigned long x) {
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
int idx = sizeof(x) - 1;
#else
int idx = 0;
#endif
int cnt = bitcount_bits[((char *) &x)[idx] & 0xFF];
if (0L != (x >>= 8))
cnt += bitcount_btbl_bitcnt(x);
return cnt;
}

View File

@ -0,0 +1,150 @@
/*
This program is part of the TACLeBench benchmark suite.
Version V 1.x
Name: bitcount.c
Author: Bob Stout & Auke Reitsma
Function: test program for bit counting functions
Source: www.snippest.com
Changes: no major functional changes
License: May be used, modified, and re-distributed freely.
*/
#include "bitops.h"
// Wasm loop bounds
__attribute__((import_module("__pragma"), import_name("loopbound"))) extern void
__pragma_loopbound(unsigned int min_bound, unsigned int max_bound);
#define FUNCS 8
/*
Global variables
*/
unsigned long bitcount_randseed;
int bitcount_res;
unsigned long bitcount_seed;
unsigned long bitcount_n;
unsigned int bitcount_iterations;
/*
First declaration of the functions
*/
int bitcount_bit_shifter(long int x);
unsigned long bitcount_random(void);
__attribute__((noinline)) __attribute__((export_name("entrypoint"))) void
bitcount_main();
int bitcount_return();
void bitcount_init();
__attribute__((noinline)) __attribute__((export_name("main"))) int main(void);
int
bitcount_bit_shifter(long int x) {
int n;
unsigned int i;
__pragma_loopbound(31, 31);
for (i = n = 0; x && (i < (sizeof(long) * 8)); ++i, x >>= 1)
n += (int) (x & 1L);
return n;
}
int
bitcount_return() {
return (bitcount_n + (-1095)) != 0;
}
void
bitcount_init() {
bitcount_randseed = 1;
bitcount_n = 0;
bitcount_iterations = 10;
bitcount_init3();
bitcount_init4();
}
unsigned long
bitcount_random(void) {
long x, hi, lo, t;
/*
Compute x[n + 1] = (7^5 * x[n]) mod (2^31 - 1).
From "Random number generators: good ones are hard to find",
Park and Miller, Communications of the ACM, vol. 31, no. 10,
October 1988, p. 1195.
*/
x = bitcount_randseed;
hi = x / 127773;
lo = x % 127773;
t = 16807 * lo - 2836 * hi;
if (t <= 0)
t += 0x7fffffff;
bitcount_randseed = t;
return (t);
}
__attribute__((noinline)) __attribute__((export_name("entrypoint"))) void
bitcount_main() {
unsigned int i, j;
__pragma_loopbound(8, 8);
for (i = 0; i < FUNCS; i++) {
__pragma_loopbound(10, 10);
for (j = 0, bitcount_seed = bitcount_random(); j < bitcount_iterations;
j++, bitcount_seed += 13) {
// The original calls were done by function pointers
switch (i) {
case 0:
bitcount_res = bitcount_bit_count(bitcount_seed);
break;
case 1:
bitcount_res = bitcount_bitcount(bitcount_seed);
break;
case 2: {
_Pragma("marker call_ntbl") bitcount_res =
bitcount_ntbl_bitcnt(bitcount_seed);
break;
}
case 3: {
_Pragma("marker call_btbl") bitcount_res =
bitcount_btbl_bitcnt(bitcount_seed);
break;
}
case 4:
bitcount_res = bitcount_ntbl_bitcount(bitcount_seed);
break;
case 5:
bitcount_res = bitcount_BW_btbl_bitcount(bitcount_seed);
break;
case 6:
bitcount_res = bitcount_AR_btbl_bitcount(bitcount_seed);
break;
case 7:
bitcount_res = bitcount_bit_shifter(bitcount_seed);
break;
default:
break;
}
bitcount_n += bitcount_res;
}
}
_Pragma("flowrestriction 1*ntbl_bitcount <= 8*call_ntbl")
_Pragma("flowrestriction 1*btbl_bitcount <= 4*call_btbl")
}
__attribute__((noinline)) __attribute__((export_name("main"))) int
main(void) {
bitcount_init();
bitcount_main();
return (bitcount_return());
}

View File

@ -0,0 +1,50 @@
/*
This program is part of the TACLeBench benchmark suite.
Version V 1.x
Name: bitops.h
Author: Bob Stout & Auke Reitsma
Function: test program for bit counting functions
Source:
Changes: no major functional changes
License: May be used, modified, and re-distributed freely.
*/
#ifndef BITOPS__H
#define BITOPS__H
/*
** bitcount_1.c
*/
int bitcount_bit_count(long x);
/*
** bitcount_2.c
*/
int bitcount_bitcount(long i);
/*
** bitcount_3.c
*/
void bitcount_init3(void);
int bitcount_ntbl_bitcount(long int x);
int bitcount_BW_btbl_bitcount(long int x);
int bitcount_AR_btbl_bitcount(long int x);
/*
** bitcount_4.c
*/
void bitcount_init4(void);
int bitcount_ntbl_bitcnt(unsigned long x);
int bitcount_btbl_bitcnt(unsigned long x);
#endif /* BITOPS__H */

View File

@ -0,0 +1,41 @@
/*
This program is part of the TACLeBench benchmark suite.
Version V 1.x
Name: bitcnt_1.c
Author: Ratko Tomic
Function: Test program for bit counting functions
Source: http://www.snippets.org/.
Changes: no major functional changes
License: May be used, modified, and re-distributed freely.
*/
#include "bitops.h"
// Wasm loop bounds
__attribute__((import_module("__pragma"), import_name("loopbound"))) extern void
__pragma_loopbound(unsigned int min_bound, unsigned int max_bound);
__attribute__((always_inline)) static inline int
bitcount_bit_count(long x) {
int n = 0;
/*
** The loop will execute once for each bit of x set, this is in average
** twice as fast as the shift/test method.
*/
if (x) {
__pragma_loopbound(3, 8);
do {
n++;
} while (0 != (x = x & (x - 1)));
}
return (n);
}

View File

@ -0,0 +1,30 @@
/*
This program is part of the TACLeBench benchmark suite.
Version V 1.x
Name: bitcnt_2.c
Author: Bob Stout & Auke Reitsma
Function: Test program for bit counting functions
Source: http://www.snippets.org/
Changes: no major functional changes
License: May be used, modified, and re-distributed freely.
*/
#include "bitops.h"
__attribute__((always_inline)) static inline int
bitcount_bitcount(long i) {
i = ((i & 0xAAAAAAAAL) >> 1) + (i & 0x55555555L);
i = ((i & 0xCCCCCCCCL) >> 2) + (i & 0x33333333L);
i = ((i & 0xF0F0F0F0L) >> 4) + (i & 0x0F0F0F0FL);
i = ((i & 0xFF00FF00L) >> 8) + (i & 0x00FF00FFL);
i = ((i & 0xFFFF0000L) >> 16) + (i & 0x0000FFFFL);
return (int) i;
}

View File

@ -0,0 +1,98 @@
/*
This program is part of the TACLeBench benchmark suite.
Version V 1.x
Name: bitcnt_3.c
Author: Bob Stout & Auke Reitsma
Function: Bit counting functions using table lookup
Source: http://www.snippets.org/
Changes: no major functional changes
License: May be used, modified, and re-distributed freely.
*/
#include "bitops.h"
static char bitcount_bits[256];
/*
** Count bits in each nybble
**
** Note: Only the first 16 table entries are used, the rest could be
** omitted.
*/
__attribute__((always_inline)) static inline void
bitcount_init3(void) {
int volatile i = 0;
char bitcount_bits_tmp[256] = {
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4,
2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4,
2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6,
4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5,
3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6,
4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8};
for (i = 0; i < 256; i++)
bitcount_bits[i] = bitcount_bits_tmp[i];
}
__attribute__((always_inline)) static inline int
bitcount_ntbl_bitcount(long int x) {
return bitcount_bits[(int) (x & 0x0000000FUL)] +
bitcount_bits[(int) ((x & 0x000000F0UL) >> 4)] +
bitcount_bits[(int) ((x & 0x00000F00UL) >> 8)] +
bitcount_bits[(int) ((x & 0x0000F000UL) >> 12)] +
bitcount_bits[(int) ((x & 0x000F0000UL) >> 16)] +
bitcount_bits[(int) ((x & 0x00F00000UL) >> 20)] +
bitcount_bits[(int) ((x & 0x0F000000UL) >> 24)] +
bitcount_bits[(int) ((x & 0xF0000000UL) >> 28)];
}
/*
** Count bits in each byte
**
** by Bruce Wedding, works best on Watcom & Borland
*/
__attribute__((always_inline)) static inline int
bitcount_BW_btbl_bitcount(long int x) {
union {
unsigned char ch[4];
long y;
} U;
U.y = x;
return bitcount_bits[U.ch[0]] + bitcount_bits[U.ch[1]] +
bitcount_bits[U.ch[3]] + bitcount_bits[U.ch[2]];
}
/*
** Count bits in each byte
**
** by Auke Reitsma, works best on Microsoft, Symantec, and others
*/
__attribute__((always_inline)) static inline int
bitcount_AR_btbl_bitcount(long int x) {
unsigned char *ptr = (unsigned char *) &x;
int accu;
accu = bitcount_bits[*ptr++];
accu += bitcount_bits[*ptr++];
accu += bitcount_bits[*ptr++];
accu += bitcount_bits[*ptr];
return accu;
}

View File

@ -0,0 +1,79 @@
/*
This program is part of the TACLeBench benchmark suite.
Version V 1.x
Name: bitcnt_4.c
Author: Bob Stout
Function: Recursive bit counting functions using table lookup
Source: http://www.snippets.org/
Changes: no major functional changes
License: May be used, modified, and re-distributed freely.
*/
#include "bitops.h" /* from Snippets */
static char bitcount_bits[256];
/*
** Count bits in each nybble
**
** Note: Only the first 16 table entries are used, the rest could be
** omitted.
*/
__attribute__((always_inline)) static inline void
bitcount_init4(void) {
int volatile i = 0;
char bitcount_bits_tmp[256] = {
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4,
2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4,
2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6,
4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5,
3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6,
4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8};
for (i = 0; i < 256; i++)
bitcount_bits[i] = bitcount_bits_tmp[i];
}
__attribute__((always_inline)) static inline int
bitcount_ntbl_bitcnt(unsigned long x) {
int cnt = bitcount_bits[(int) (x & 0x0000000FL)];
if (0L != (x >>= 4))
cnt += bitcount_ntbl_bitcnt(x);
return cnt;
}
/*
** Count bits in each byte
*/
__attribute__((always_inline)) static inline int
bitcount_btbl_bitcnt(unsigned long x) {
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
int idx = sizeof(x) - 1;
#else
int idx = 0;
#endif
int cnt = bitcount_bits[((char *) &x)[idx] & 0xFF];
if (0L != (x >>= 8))
cnt += bitcount_btbl_bitcnt(x);
return cnt;
}

View File

@ -0,0 +1,164 @@
/*
This program is part of the TACLeBench benchmark suite.
Version V 1.x
Name: bitcount.c
Author: Bob Stout & Auke Reitsma
Function: test program for bit counting functions
Source: www.snippest.com
Changes: no major functional changes
License: May be used, modified, and re-distributed freely.
*/
#include "bitops.h"
// Wasm loop bounds
#include "bitcnt_1.c"
#include "bitcnt_2.c"
#include "bitcnt_3.c"
#include "bitcnt_4.c"
__attribute__((import_module("__pragma"), import_name("loopbound"))) extern void
__pragma_loopbound(unsigned int min_bound, unsigned int max_bound);
#define FUNCS 8
/*
Global variables
*/
unsigned long bitcount_randseed;
int bitcount_res;
unsigned long bitcount_seed;
unsigned long bitcount_n;
unsigned int bitcount_iterations;
/*
First declaration of the functions
*/
__attribute__((always_inline)) static inline int
bitcount_bit_shifter(long int x);
__attribute__((always_inline)) static inline unsigned long
bitcount_random(void);
__attribute__((noinline)) __attribute__((export_name("entrypoint")))
__attribute__((noinline)) __attribute__((export_name("entrypoint"))) void
bitcount_main();
__attribute__((always_inline)) static inline int bitcount_return();
__attribute__((always_inline)) static inline void bitcount_init();
__attribute__((noinline)) __attribute__((export_name("main")))
__attribute__((noinline)) __attribute__((export_name("main"))) int
main(void);
__attribute__((always_inline)) static inline int
bitcount_bit_shifter(long int x) {
int n;
unsigned int i;
__pragma_loopbound(31, 31);
for (i = n = 0; x && (i < (sizeof(long) * 8)); ++i, x >>= 1)
n += (int) (x & 1L);
return n;
}
__attribute__((always_inline)) static inline int
bitcount_return() {
return (bitcount_n + (-1095)) != 0;
}
__attribute__((always_inline)) static inline void
bitcount_init() {
bitcount_randseed = 1;
bitcount_n = 0;
bitcount_iterations = 10;
bitcount_init3();
bitcount_init4();
}
__attribute__((always_inline)) static inline unsigned long
bitcount_random(void) {
long x, hi, lo, t;
/*
Compute x[n + 1] = (7^5 * x[n]) mod (2^31 - 1).
From "Random number generators: good ones are hard to find",
Park and Miller, Communications of the ACM, vol. 31, no. 10,
October 1988, p. 1195.
*/
x = bitcount_randseed;
hi = x / 127773;
lo = x % 127773;
t = 16807 * lo - 2836 * hi;
if (t <= 0)
t += 0x7fffffff;
bitcount_randseed = t;
return (t);
}
__attribute__((noinline)) __attribute__((export_name("entrypoint")))
__attribute__((noinline)) __attribute__((export_name("entrypoint"))) void
bitcount_main() {
unsigned int i, j;
__pragma_loopbound(8, 8);
for (i = 0; i < FUNCS; i++) {
__pragma_loopbound(10, 10);
for (j = 0, bitcount_seed = bitcount_random(); j < bitcount_iterations;
j++, bitcount_seed += 13) {
// The original calls were done by function pointers
switch (i) {
case 0:
bitcount_res = bitcount_bit_count(bitcount_seed);
break;
case 1:
bitcount_res = bitcount_bitcount(bitcount_seed);
break;
case 2: {
_Pragma("marker call_ntbl") bitcount_res =
bitcount_ntbl_bitcnt(bitcount_seed);
break;
}
case 3: {
_Pragma("marker call_btbl") bitcount_res =
bitcount_btbl_bitcnt(bitcount_seed);
break;
}
case 4:
bitcount_res = bitcount_ntbl_bitcount(bitcount_seed);
break;
case 5:
bitcount_res = bitcount_BW_btbl_bitcount(bitcount_seed);
break;
case 6:
bitcount_res = bitcount_AR_btbl_bitcount(bitcount_seed);
break;
case 7:
bitcount_res = bitcount_bit_shifter(bitcount_seed);
break;
default:
break;
}
bitcount_n += bitcount_res;
}
}
_Pragma("flowrestriction 1*ntbl_bitcount <= 8*call_ntbl")
_Pragma("flowrestriction 1*btbl_bitcount <= 4*call_btbl")
}
__attribute__((noinline)) __attribute__((export_name("main")))
__attribute__((noinline)) __attribute__((export_name("main"))) int
main(void) {
bitcount_init();
bitcount_main();
return (bitcount_return());
}

View File

@ -0,0 +1,55 @@
/*
This program is part of the TACLeBench benchmark suite.
Version V 1.x
Name: bitops.h
Author: Bob Stout & Auke Reitsma
Function: test program for bit counting functions
Source:
Changes: no major functional changes
License: May be used, modified, and re-distributed freely.
*/
#ifndef BITOPS__H
#define BITOPS__H
/*
** bitcount_1.c
*/
__attribute__((always_inline)) static inline int bitcount_bit_count(long x);
/*
** bitcount_2.c
*/
__attribute__((always_inline)) static inline int bitcount_bitcount(long i);
/*
** bitcount_3.c
*/
__attribute__((always_inline)) static inline void bitcount_init3(void);
__attribute__((always_inline)) static inline int
bitcount_ntbl_bitcount(long int x);
__attribute__((always_inline)) static inline int
bitcount_BW_btbl_bitcount(long int x);
__attribute__((always_inline)) static inline int
bitcount_AR_btbl_bitcount(long int x);
/*
** bitcount_4.c
*/
__attribute__((always_inline)) static inline void bitcount_init4(void);
__attribute__((always_inline)) static inline int
bitcount_ntbl_bitcnt(unsigned long x);
__attribute__((always_inline)) static inline int
bitcount_btbl_bitcnt(unsigned long x);
#endif /* BITOPS__H */