2016-01-25 16:56:00 +01:00
|
|
|
/****************************************************************************
|
2018-05-29 21:21:26 +02:00
|
|
|
* libs/libc/misc/lib_usub64.c
|
2016-01-25 16:56:00 +01:00
|
|
|
*
|
2021-04-02 09:22:52 +02:00
|
|
|
* 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
|
2016-01-25 16:56:00 +01:00
|
|
|
*
|
2021-04-02 09:22:52 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2016-01-25 16:56:00 +01:00
|
|
|
*
|
2021-04-02 09:22:52 +02:00
|
|
|
* 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.
|
2016-01-25 16:56:00 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-07-21 22:00:15 +02:00
|
|
|
#include <nuttx/lib/math32.h>
|
2016-01-25 16:56:00 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* 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.
|
2016-01-25 18:19:25 +01:00
|
|
|
* difference - The location to return the difference of the two values.
|
2016-01-25 16:56:00 +01:00
|
|
|
* 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:
|
2016-01-25 18:19:25 +01:00
|
|
|
*
|
2016-01-25 16:56:00 +01:00
|
|
|
* subtrahend->ls > minuend->ls
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (subtrahend->ls > minuend->ls)
|
|
|
|
{
|
|
|
|
difference->ms--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the LS part of the difference */
|
|
|
|
|
|
|
|
difference->ls = minuend->ls - subtrahend->ls;
|
|
|
|
}
|