198913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project/* Copyright (C) 2004 Jean-Marc Valin */
298913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project/**
398913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   @file fixed_arm4.h
498913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   @brief ARM4 fixed-point operations
598913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project*/
698913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project/*
798913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   Redistribution and use in source and binary forms, with or without
898913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   modification, are permitted provided that the following conditions
998913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   are met:
1098913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
1198913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   - Redistributions of source code must retain the above copyright
1298913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   notice, this list of conditions and the following disclaimer.
1398913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
1498913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   - Redistributions in binary form must reproduce the above copyright
1598913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   notice, this list of conditions and the following disclaimer in the
1698913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   documentation and/or other materials provided with the distribution.
1798913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
1898913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   - Neither the name of the Xiph.org Foundation nor the names of its
1998913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   contributors may be used to endorse or promote products derived from
2098913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   this software without specific prior written permission.
2198913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
2298913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2398913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2498913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2598913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
2698913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
2798913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2898913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
2998913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
3098913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
3198913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3298913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3398913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project*/
3498913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
3598913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project#ifndef FIXED_ARM4_H
3698913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project#define FIXED_ARM4_H
3798913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
3898913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project#undef MULT16_32_Q14
3998913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Projectstatic inline spx_word32_t MULT16_32_Q14(spx_word16_t x, spx_word32_t y) {
4098913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project  int res;
4198913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project  int dummy;
4298913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project  asm (
4398913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project        "smull  %0,%1,%2,%3 \n\t"
4498913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project        "mov %0, %0, lsr #14 \n\t"
4598913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project        "add %0, %0, %1, lsl #18 \n\t"
4698913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   : "=&r"(res), "=&r" (dummy)
4798913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   : "r"(y),"r"((int)x));
4898913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project  return(res);
4998913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project}
5098913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
5198913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project#undef MULT16_32_Q15
5298913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Projectstatic inline spx_word32_t MULT16_32_Q15(spx_word16_t x, spx_word32_t y) {
5398913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project  int res;
5498913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project  int dummy;
5598913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project  asm (
5698913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project        "smull  %0,%1,%2,%3 \n\t"
5798913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project        "mov %0, %0, lsr #15 \n\t"
5898913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project        "add %0, %0, %1, lsl #17 \n\t"
5998913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   : "=&r"(res), "=&r" (dummy)
6098913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   : "r"(y),"r"((int)x));
6198913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project  return(res);
6298913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project}
6398913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
6498913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project#undef DIV32_16
6598913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Projectstatic inline short DIV32_16(int a, int b)
6698913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project{
6798913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   int res=0;
6898913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   int dead1, dead2, dead3, dead4, dead5;
6998913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   __asm__ __volatile__ (
7098913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\teor %5, %0, %1\n"
7198913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tmovs %4, %0\n"
7298913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\trsbmi %0, %0, #0 \n"
7398913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tmovs %4, %1\n"
7498913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\trsbmi %1, %1, #0 \n"
7598913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tmov %4, #1\n"
7698913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
7798913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tsubs %3, %0, %1, asl #14 \n"
7898913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tmovpl %0, %3 \n"
7998913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\torrpl %2, %2, %4, asl #14 \n"
8098913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
8198913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tsubs %3, %0, %1, asl #13 \n"
8298913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tmovpl %0, %3 \n"
8398913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\torrpl %2, %2, %4, asl #13 \n"
8498913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
8598913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tsubs %3, %0, %1, asl #12 \n"
8698913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tmovpl %0, %3 \n"
8798913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\torrpl %2, %2, %4, asl #12 \n"
8898913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
8998913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tsubs %3, %0, %1, asl #11 \n"
9098913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tmovpl %0, %3 \n"
9198913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\torrpl %2, %2, %4, asl #11 \n"
9298913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
9398913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tsubs %3, %0, %1, asl #10 \n"
9498913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tmovpl %0, %3 \n"
9598913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\torrpl %2, %2, %4, asl #10 \n"
9698913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
9798913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tsubs %3, %0, %1, asl #9 \n"
9898913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tmovpl %0, %3 \n"
9998913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\torrpl %2, %2, %4, asl #9 \n"
10098913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
10198913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tsubs %3, %0, %1, asl #8 \n"
10298913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tmovpl %0, %3 \n"
10398913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\torrpl %2, %2, %4, asl #8 \n"
10498913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
10598913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tsubs %3, %0, %1, asl #7 \n"
10698913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tmovpl %0, %3 \n"
10798913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\torrpl %2, %2, %4, asl #7 \n"
10898913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
10998913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tsubs %3, %0, %1, asl #6 \n"
11098913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tmovpl %0, %3 \n"
11198913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\torrpl %2, %2, %4, asl #6 \n"
11298913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
11398913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tsubs %3, %0, %1, asl #5 \n"
11498913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tmovpl %0, %3 \n"
11598913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\torrpl %2, %2, %4, asl #5 \n"
11698913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
11798913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tsubs %3, %0, %1, asl #4 \n"
11898913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tmovpl %0, %3 \n"
11998913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\torrpl %2, %2, %4, asl #4 \n"
12098913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
12198913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tsubs %3, %0, %1, asl #3 \n"
12298913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tmovpl %0, %3 \n"
12398913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\torrpl %2, %2, %4, asl #3 \n"
12498913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
12598913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tsubs %3, %0, %1, asl #2 \n"
12698913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tmovpl %0, %3 \n"
12798913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\torrpl %2, %2, %4, asl #2 \n"
12898913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
12998913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tsubs %3, %0, %1, asl #1 \n"
13098913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tmovpl %0, %3 \n"
13198913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\torrpl %2, %2, %4, asl #1 \n"
13298913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
13398913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tsubs %3, %0, %1 \n"
13498913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tmovpl %0, %3 \n"
13598913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\torrpl %2, %2, %4 \n"
13698913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
13798913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\tmovs %5, %5, lsr #31 \n"
13898913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project         "\trsbne %2, %2, #0 \n"
13998913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   : "=r" (dead1), "=r" (dead2), "=r" (res),
14098913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   "=r" (dead3), "=r" (dead4), "=r" (dead5)
14198913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   : "0" (a), "1" (b), "2" (res)
14298913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   : "cc"
14398913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project                        );
14498913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project   return res;
14598913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project}
14698913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
14798913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project
14898913fed6520d8849fb2e246be943e04474aefaThe Android Open Source Project#endif
149