source: trunk/lib/bitblock128.hpp @ 1948

Last change on this file since 1948 was 1890, checked in by cameron, 7 years ago

Move count_forward_zeroes et al up to remove 128-bit dependency.

File size: 3.4 KB
Line 
1/*
2    bitblock128 - Specific 128 bit IDISA implementations.
3
4    Idealized SIMD Operations with SSE versions
5    Copyright (C) 2011, Robert D. Cameron, Kenneth S. Herdy, Hua Huang and Nigel Medforth.
6    Licensed to the public under the Open Software License 3.0.
7    Licensed to International Characters Inc.
8       under the Academic Free License version 3.0.
9
10*/
11#ifndef BITBLOCK128_HPP_
12#define BITBLOCK128_HPP_
13
14#include "idisa128.hpp"
15#include "builtins.hpp"
16
17union ubitblock {
18        bitblock128_t _128;
19        uint64_t _64[sizeof(bitblock128_t)/sizeof(uint64_t)];
20        uint32_t _32[sizeof(bitblock128_t)/sizeof(uint32_t)];
21        uint16_t _16[sizeof(bitblock128_t)/sizeof(uint16_t)];
22        uint8_t _8[sizeof(bitblock128_t)/sizeof(uint8_t)];
23};
24
25static IDISA_ALWAYS_INLINE void adc(bitblock128_t x, bitblock128_t y, bitblock128_t & carry, bitblock128_t & sum);
26static IDISA_ALWAYS_INLINE void sbb(bitblock128_t x, bitblock128_t y, bitblock128_t & borrow, bitblock128_t & difference);
27static IDISA_ALWAYS_INLINE void advance_with_carry(bitblock128_t cursor, bitblock128_t & carry, bitblock128_t & rslt);
28static IDISA_ALWAYS_INLINE bool bitblock_has_bit(bitblock128_t arg1);
29static IDISA_ALWAYS_INLINE void signbitmask(bitblock128_t & v);
30static IDISA_ALWAYS_INLINE bitblock128_t convert (uint64_t s);
31static IDISA_ALWAYS_INLINE uint64_t convert (bitblock128_t v);
32
33IDISA_ALWAYS_INLINE void adc(bitblock128_t x, bitblock128_t y, bitblock128_t & carry, bitblock128_t & sum)
34{
35        bitblock128_t gen = simd_and(x, y);
36        bitblock128_t prop = simd_or(x, y);
37        bitblock128_t partial = simd128<64>::add(simd128<64>::add(x, y), carry);
38        bitblock128_t c1 = simd128<128>::slli<64>(simd128<64>::srli<63>(simd_or(gen, simd_andc(prop, partial))));
39        sum = simd128<64>::add(c1, partial);
40        // carry = simd_and(hibitmask<bitblock128_t>(), simd_or(gen, simd_andc(prop, sum))); // TODO - set high bit carry via hibitmask
41        carry = simd128<128>::srli<127>(simd_or(gen, simd_andc(prop, sum))); // TODO -
42}
43
44IDISA_ALWAYS_INLINE void sbb(bitblock128_t x, bitblock128_t y, bitblock128_t & borrow, bitblock128_t & difference)
45{
46        bitblock128_t gen = simd_andc(y, x);
47        bitblock128_t prop = simd_not(simd_xor(x, y));
48        bitblock128_t partial = simd128<64>::sub(simd128<64>::sub(x, y), borrow);
49        bitblock128_t b1 = simd128<128>::slli<64>(simd128<64>::srli<63>(simd_or(gen, simd_and(prop, partial))));
50        difference = simd128<64>::sub(partial, b1);
51        // borrow = simd_and(hibitmask<bitblock128_t>, simd_or(gen, simd_and(prop, difference))); // TODO - set high bit carry via hibitmask
52        borrow = simd128<128>::srli<127>(simd_or(gen, simd_and(prop, difference)));
53}
54
55IDISA_ALWAYS_INLINE void advance_with_carry(bitblock128_t cursor, bitblock128_t & carry, bitblock128_t & rslt)
56{
57bitblock128_t shift_out = simd128<64>::srli<63>(cursor);
58bitblock128_t low_bits = esimd128<64>::mergel(shift_out, carry);
59// carry = simd_and(hibitmask<bitblock128_t>, cursor);
60carry = simd128<128>::srli<64>(shift_out);                                              // carry - accumlated 127 shift right locical shift of cursor
61rslt = simd_or(simd128<64>::add(cursor, cursor), low_bits);
62}
63
64IDISA_ALWAYS_INLINE void signbitmask(bitblock128_t & v)
65{
66        v =  simd128<128>::slli<127>(simd128<128>::constant<1>());
67}
68
69IDISA_ALWAYS_INLINE bitblock128_t convert(uint64_t s)
70{
71        ubitblock b = {b._128 = simd128<128>::constant<0>()}; // = {0};
72        b._64[0] = s;
73        return b._128;
74}
75
76IDISA_ALWAYS_INLINE uint64_t convert (bitblock128_t v)
77{
78        return (uint64_t) mvmd128<64>::extract<0>(v);
79}
80
81
82
83#endif /* BITBLOCK128_HPP_ */
Note: See TracBrowser for help on using the repository browser.