b7c451c5a4
Gregory Nutt has submitted the SGA and we can migrate the licenses to Apache. Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
68 lines
2.4 KiB
C
68 lines
2.4 KiB
C
/****************************************************************************
|
|
* libs/libc/misc/lib_usub64.c
|
|
*
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
* this work for additional information regarding copyright ownership. The
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
* "License"); you may not use this file except in compliance with the
|
|
* License. You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
* License for the specific language governing permissions and limitations
|
|
* under the License.
|
|
*
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
* Included Files
|
|
****************************************************************************/
|
|
|
|
#include <nuttx/lib/math32.h>
|
|
|
|
/****************************************************************************
|
|
* Public Functions
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
* Name: usub64
|
|
*
|
|
* Description:
|
|
* Subtract two 64-bit values and return the 64-bit difference.
|
|
*
|
|
* Input Parameters:
|
|
* minuend - The number from which another number (the Subtrahend) is
|
|
* to be subtracted.
|
|
* subtrahend - The number that is to be subtracted.
|
|
* difference - The location to return the difference of the two values.
|
|
* difference may the same as one of minuend or subtrahend.
|
|
*
|
|
****************************************************************************/
|
|
|
|
void usub64(FAR const struct uint64_s *minuend,
|
|
FAR const struct uint64_s *subtrahend,
|
|
FAR struct uint64_s *difference)
|
|
{
|
|
/* Get the MS part of the difference */
|
|
|
|
difference->ms = minuend->ms - subtrahend->ms;
|
|
|
|
/* Check for a borrow, i.e., that is when:
|
|
*
|
|
* subtrahend->ls > minuend->ls
|
|
*/
|
|
|
|
if (subtrahend->ls > minuend->ls)
|
|
{
|
|
difference->ms--;
|
|
}
|
|
|
|
/* Get the LS part of the difference */
|
|
|
|
difference->ls = minuend->ls - subtrahend->ls;
|
|
}
|