bitmask

SSE2 test xmm bitmask directly without using 'pmovmskb'

a 夏天 提交于 2021-02-11 16:41:40
问题 consider we have this: .... pxor xmm1, xmm1 movdqu xmm0, [reax] pcmpeqb xmm0, xmm1 pmovmskb eax, xmm0 test ax , ax jz .zero ... is there any way to not use 'pmovmskb' and test the bitmask directly from xmm0 (to check if it's zero) ? is there any SSE instruction for this action ? in fact, im searching for something like 'ptest xmm0, xmm0' action but in SSE2 ... not SSE4 回答1: It's generally not worth using SSE4.1 ptest xmm0,xmm0 on a pcmpeqb result, especially not if you're branching. pmovmskb

SSE2 test xmm bitmask directly without using 'pmovmskb'

蓝咒 提交于 2021-02-11 16:40:42
问题 consider we have this: .... pxor xmm1, xmm1 movdqu xmm0, [reax] pcmpeqb xmm0, xmm1 pmovmskb eax, xmm0 test ax , ax jz .zero ... is there any way to not use 'pmovmskb' and test the bitmask directly from xmm0 (to check if it's zero) ? is there any SSE instruction for this action ? in fact, im searching for something like 'ptest xmm0, xmm0' action but in SSE2 ... not SSE4 回答1: It's generally not worth using SSE4.1 ptest xmm0,xmm0 on a pcmpeqb result, especially not if you're branching. pmovmskb

Merge bit sequences a and b according to a mask

旧街凉风 提交于 2021-02-05 06:52:37
问题 According to the bit twiddling hacks website, the operation unsigned int a; // value to merge in non-masked bits unsigned int b; // value to merge in masked bits unsigned int mask; // 1 where bits from b should be selected; 0 where from a. unsigned int r; // result of (a & ~mask) | (b & mask) goes here r = a ^ ((a ^ b) & mask); allows to merge two bit sequences a and b according to a mask. I was wondering: Whether this operation had a specific/usual name? Whether specific assembly instruction

Merge bit sequences a and b according to a mask

别等时光非礼了梦想. 提交于 2021-02-05 06:52:13
问题 According to the bit twiddling hacks website, the operation unsigned int a; // value to merge in non-masked bits unsigned int b; // value to merge in masked bits unsigned int mask; // 1 where bits from b should be selected; 0 where from a. unsigned int r; // result of (a & ~mask) | (b & mask) goes here r = a ^ ((a ^ b) & mask); allows to merge two bit sequences a and b according to a mask. I was wondering: Whether this operation had a specific/usual name? Whether specific assembly instruction

Swift - Turn Int to binary representations

孤街浪徒 提交于 2020-05-15 06:31:08
问题 I receive an Int from my server which I’d like to explode in to an array of bit masks. So for example, if my server gives me the number 3, we get two values, a binary 1 and a binary 2. How do I do this in Swift? 回答1: I am not aware of any nice built-in way, but you could use this: var i = 3 let a = 0..<8 var b = a.map { Int(i & (1 << $0)) } // b = [1, 2, 0, 0, 0, 0, 0, 0] 回答2: You could use: let number = 3 //radix: 2 is binary, if you wanted hex you could do radix: 16 let str = String(number,

Need help regarding bitmask+dynamic programming [closed]

烈酒焚心 提交于 2020-03-17 03:23:25
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 days ago . found this question in geeksforgeeks related to dynamic programming with bitmasking : https://www.geeksforgeeks.org/sum-subsets-dynamic-programming/ I am trying for weeks but not able to understand how the answer is formulated. Please provide any links, that may help to understand

Given a list and a bitmask, how do I return the values at the indices that are True?

最后都变了- 提交于 2020-02-21 10:57:21
问题 I start with the following list s and bitmask b : s = ['baa', 'baa', 'black', 'sheep', 'have', 'you', 'any', 'wool'] b = [1, 0, 0, 0, 1, 1, 1, 0] # or any iterable with boolean values How do I write some function apply_bitmask(s, b) so that it returns ['baa', 'have', 'you', 'any'] 回答1: Python 3.1 itertools.compress (or Python 2.7's if you haven't upgraded yet) does exactly that (the list comprehension is a real close second): import itertools filtered = itertools.compress(s, b) Note that this

convert a two Byte bit mask into a EnumSet

久未见 提交于 2020-01-31 16:52:28
问题 I am reading a binary file that has values stored in bit masks, both 1 Byte bit masks and 2 Byte bit masks . Each bit in the masks act as a switch that indicates where an Event has transpired. Example of 1 Byte mask: 00000101 Indicates that Event one and Event 3 has transpired. Example of Enum public enum MyEnum { EventOne, EventTwo, ....; } I have created a Enum MyEnum (as per Item 32 in Effective java, Second Edition) of the events. How can the binary bit masks be read into an EnumSet

Using SQL to determine cidr value of a subnet mask

给你一囗甜甜゛ 提交于 2020-01-31 03:30:12
问题 I'd like to find a way to do a SQL query that will calculate the cidr (bit representation) of a subnet mask stored in the database. So for example, I've got either 255.255.255.0 or its decimal value (4294967040) stored in the database. I'd like to do a select and get back /24 representation via the query. I've done things like the following to determine the last IP of a subnet so I'm hoping to do something similar to determine the cidr representation of a mask. select concat(inet_ntoa(ip_addr

Convenient ways to work with large bit mask

↘锁芯ラ 提交于 2020-01-14 18:43:47
问题 I am trying to implement an algorithm within an iOS app that will make use of large bitmasks. Each bitmask can be up to 256 bits (32 bytes) in length. I will need to quickly get/set bits at arbitrary locations within the mask, etc. Are there any built-in language features of C or Objective-C that makes this kind of thing easy to do, or should I expect to write my own functions for manipulating bits within arbitrary character arrays? It doesn't seem like it would be too hard to do it myself