2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1992,1997 NeXT Software, Inc. All rights reserved.
24 * File: libc/gen/ppc/abs.s
25 * Author: Derek B Clegg, NeXT Software, Inc.
28 * 24-Jan-1997 Umesh Vaishampayan (umeshv@NeXT.com)
30 * 10-Nov-92 Derek B Clegg (dclegg@next.com)
32 * 13-Jan-93 Derek B Clegg (dclegg@next.com)
39 * The `abs' function computes the absolute value of an integer `j'.
40 * If the result cannot be represented, the behavior is undefined.
42 * The `abs' function returns the absolute value.
44 #include <architecture/ppc/asm_help.h>
45 #include <architecture/ppc/pseudo_inst.h>
47 /* We calculate abs(x) as
52 * If x >= 0, then s = 0, so clearly we return x. On the other hand, if
53 * x < 0, then we may write x as ~z + 1, where z = -x. In this case,
54 * s = -1, so y = x - 1 = ~z, and hence we return -1 ^ (x - 1) = -1 ^ ~z