root/trunk/helpers.h

Revision 32, 2.0 KB (checked in by mike, 5 years ago)

Broke it

Line 
1/*
2 * Copyright (C) 2007 Michael Lewis
3 * Author: Mike Lewis <mikelikespie@gmail.com>
4 *
5 * This work is provide AS IS, and has no warranty.
6 * The author is NOT responsible for anything that happens
7 * due to use of this code, either using it or running it on
8 * your system
9 */
10#ifndef _HELPERS_H_INCLUDED
11#define _HELPERS_H_INCLUDED
12#include "fakesse.h"
13
14static inline __m128i shift_pack_left127( __m128i A ) {
15    return _mm_srli_si128( _mm_srli_epi32( A, 7 ), 15 );
16}
17
18static inline __m128i shift_pack_left( __m128i A ) {
19    const __m128i endmask = _mm_set_epi8( 0xff,0x00,0x00,0x00,
20                                         0x00,0x00,0x00,0x00,
21                                         0x00,0x00,0x00,0x00,
22                                         0x00,0x00,0x00,0x00);
23
24    __m128i temp1 = _mm_and_si128( endmask, _mm_srli_epi32( _mm_slli_si128( A, 15 ), 1 ) );
25    __m128i temp2 = _mm_srli_si128( A, 1 );
26    return _mm_or_si128( temp1, temp2 );
27}
28
29static inline __m128i shift_pack_right127( __m128i A ) {
30    return _mm_slli_si128( _mm_slli_epi32( A, 7 ), 15 );
31}
32
33static inline __m128i shift_pack_right( __m128i A ) {
34    const __m128i startmask = _mm_set_epi8( 0x00,0x00,0x00,0x00,
35                                            0x00,0x00,0x00,0x00,
36                                            0x00,0x00,0x00,0x00,
37                                            0x00,0x00,0x00,0xFF);
38
39    __m128i temp1 = _mm_and_si128( startmask, _mm_slli_epi32( _mm_srli_si128( A, 15 ), 1 ) );
40    __m128i temp2 = _mm_slli_si128( A, 1 );
41    return _mm_or_si128( temp1, temp2 );
42}   
43
44
45static inline __m128i unpack( __m128i A, int row ) {
46    const __m128i onemask = _mm_set1_epi8( 0x01 );
47    __m128i shift = _mm_srli_epi32( A, row );
48    return _mm_and_si128( shift, onemask );
49}
50
51// MAKE SURE A IS IN THE FORM (0xFF) not (0x01
52// ( a | mask ) | ( ~mask & b )
53static inline __m128i pack( __m128i A, int row ) {
54    const __m128i onemask = _mm_set1_epi8( 0x01 );
55    A = _mm_and_si128( onemask, A );
56    return _mm_slli_epi32(A, row);
57}
58
59//The get and set ops are scalar and slow.
60__m128i set_bit( __m128i A, int col );
61char get_bit( __m128i A, int col );
62void print_packed_row( __m128i A );
63
64
65void print_life_block( life_block *block );
66
67void set_bit_in_block( life_block *block, int row, int column );
68
69#endif //_HELPERS_H_INCLUDED
Note: See TracBrowser for help on using the browser.