Showing results for

- Intel Community
- Software Development Technologies
- Intel® ISA Extensions
- absolute value of the difference between two unsigned char

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Highlighted
##

I have two 128-bit register xmm1, xmm2, each with 16 packed unsigned char, I want to get the absolute value of the difference between the corresponding unsigned chars, Is there an instruction to get it? Why isn't there the instruction to get it?

hurricanezhb

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-26-2009
10:00 AM

22 Views

absolute value of the difference between two unsigned char

6 Replies

Highlighted
##

*I have two 128-bit register xmm1, xmm2, each with 16 packed unsigned char, I want to get the absolute value of the difference between the corresponding unsigned chars, Is there an instruction to get it? Why isn't there the instruction to get it?*

PSUBB xmm1, xmm2

PABSB xmm1, xmm2

- si the easyest way...

look at:

Intel 64 and IA-32 Architectures

Software Developers Manual

Volume 2B:

Instruction Set Reference, N-Z

jancino

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-28-2009
08:28 AM

22 Views

Quoting - hurricanezhb

PSUBB xmm1, xmm2

PABSB xmm1, xmm2

- si the easyest way...

look at:

Intel 64 and IA-32 Architectures

Software Developers Manual

Volume 2B:

Instruction Set Reference, N-Z

Highlighted
##

*I have two 128-bit register xmm1, xmm2, each with 16 packed unsigned char, I want to get the absolute value of the difference between the corresponding unsigned chars, Is there an instruction to get it? Why isn't there the instruction to get it?*

Probably, both unsigned char and unsigned int instructions are not supported till date.

The Intel Reference document - Intel-64 & IA-32 Architectures Software Develope's Manual, Vol.2B 4-91, Order# 253667-025US only speaks about signed bytes/words/double intergers.

~BR

srimks

New Contributor II

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-28-2009
06:57 PM

22 Views

Quoting - hurricanezhb

Probably, both unsigned char and unsigned int instructions are not supported till date.

The Intel Reference document - Intel-64 & IA-32 Architectures Software Develope's Manual, Vol.2B 4-91, Order# 253667-025US only speaks about signed bytes/words/double intergers.

~BR

Highlighted
##

That probavly because data type char in C languages is the same as byte, I think. Both are 8 bits long and it doesn't mather whether it is signed or unsigned because in 2 complement logics it is the same...

jancino

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-29-2009
06:19 AM

22 Views

Probably, both unsigned char and unsigned int instructions are not supported till date.

The Intel Reference document - Intel-64 & IA-32 Architectures Software Develope's Manual, Vol.2B 4-91, Order# 253667-025US only speaks about signed bytes/words/double intergers.

The Intel Reference document - Intel-64 & IA-32 Architectures Software Develope's Manual, Vol.2B 4-91, Order# 253667-025US only speaks about signed bytes/words/double intergers.

That probavly because data type char in C languages is the same as byte, I think. Both are 8 bits long and it doesn't mather whether it is signed or unsigned because in 2 complement logics it is the same...

Highlighted
##

*I have two 128-bit register xmm1, xmm2, each with 16 packed unsigned char, I want to get the absolute value of the difference between the corresponding unsigned chars, Is there an instruction to get it? Why isn't there the instruction to get it?*
I am not sure psubb, pabsb will work. I'm still trying to convince myself using first principles of boolean algebra. It might depend on whether the mmx and sse vectors have associated carry/exception bits that affect subsequent operations. In other words, if psubb has an underflow that affects the subsequent pabsb operation.

Other sources say that abs value of the difference can be obtained by (a saturatedminus b) OR (b saturatedminus a). You can translate that into three vector operations using psubsb (subtraction using saturated arithmetic) and por.

bootchnc_rr_com

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-29-2009
09:18 AM

22 Views

Quoting - hurricanezhb

Other sources say that abs value of the difference can be obtained by (a saturatedminus b) OR (b saturatedminus a). You can translate that into three vector operations using psubsb (subtraction using saturated arithmetic) and por.

Highlighted
##

jancino

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-29-2009
01:04 PM

22 Views

The question is, what do you want to do, if the result overflow...

Highlighted
##

neni

New Contributor II

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-12-2009
01:52 PM

22 Views

psubb(pmaxub(a,b), pminub(a,b))

For more complete information about compiler optimizations, see our Optimization Notice.