JDK-6850613 : Add support for saturated casts
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 7
  • Priority: P5
  • Status: Open
  • Resolution: Unresolved
  • OS: linux
  • CPU: x86
  • Submitted: 2009-06-12
  • Updated: 2011-02-16
Related Reports
Relates :  
Description
A DESCRIPTION OF THE REQUEST :
I post this as a follow up to a discussion that took place on core-libs-dev, titled "Interest in support for saturated casts?"

It would be great if when fixing "4504839 "Java libraries should provide support for unsigned integer arithmetic", saturated casts could also be provided.

JUSTIFICATION :
Modern processors seem to have support for this kind of operation, in
x86 there's packssdw in MMX/SSE2.

If the processor doesn't support saturated casts, its just a few lines simple code.

For now this behaviour has to emulated with, which is quite inefficient:

return (short) (x > Short.MAX_VALUE ? Short.MAX_VALUE : (x <
Short.MIN_VALUE ? Short.MIN_VALUE : x));