flat assembler
Message board for the users of flat assembler.

flat assembler > Main > shl + first bit, or shr + carry flag?

Author
Thread Post new topic Reply to topic
vivik



Joined: 29 Oct 2016
Posts: 485
I need to pack a texture into a bit array. I now have a bunch of pixels, each is either ff000000 or ffffffff. Looks like a good place to compress.

What is the better way to extract bits from a byte? Shifting left, and then doing "and 1"? Or shifting right, and then using the carry bit? What are the instructions for these?

Can I use SIMD here somehow?
Post 09 Feb 2018, 09:17
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16057
Location: 112 Ocean Avenue, Amityville
vivik wrote:
I need to pack a texture into a bit array. I now have a bunch of pixels, each is either ff000000 or ffffffff. Looks like a good place to compress.

What is the better way to extract bits from a byte? Shifting left, and then doing "and 1"? Or shifting right, and then using the carry bit? What are the instructions for these?
SHR, SHl, RCR, RCL, ROR, ROL
vivik wrote:
Can I use SIMD here somehow?
Yes, but there is no carry flag in the SIMD instructions.
Post 09 Feb 2018, 09:31
View user's profile Send private message Visit poster's website Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 485
Which SIMD instructions/intrisics?
Post 09 Feb 2018, 12:05
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16057
Location: 112 Ocean Avenue, Amityville
vivik wrote:
Which SIMD instructions/intrisics?
The x86 CPU doesn't have a carry flag for SIMD or AVX instructions. Intrisics is just C's way of encoding the SIMD instructions.
Post 09 Feb 2018, 12:54
View user's profile Send private message Visit poster's website Reply with quote
Ali.A



Joined: 08 Jan 2018
Posts: 128
vivik wrote:
What is the better way to extract bits from a byte?

if the least significant bit is '1' then shr will take off that bit and set carry flag to '1' so its not recommended to use that.
instead you can use rol and ror.

if you wanna use shr and shl without losing the least significant bit, then you need CC (condition code) like cmovpe cmovpo jpe jpo setpe setpo
pe = if parity flag is even
po = if parity flag is odd

even if you lost the LSB and carry set to '1' you can move it into a register.
there are many choices tho, depends on your need or how you wanna do your things.
Post 09 Feb 2018, 14:02
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2018, Tomasz Grysztar.

Powered by rwasa.