summaryrefslogtreecommitdiffstats
path: root/otherlibs/num/bng_sparc.c
blob: 4e46a316ae710afab80af8cb2ed34fcc68dd0fc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/***********************************************************************/
/*                                                                     */
/*                                OCaml                                */
/*                                                                     */
/*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
/*                                                                     */
/*  Copyright 2003 Institut National de Recherche en Informatique et   */
/*  en Automatique.  All rights reserved.  This file is distributed    */
/*  under the terms of the GNU Library General Public License, with    */
/*  the special exception on linking described in file ../../LICENSE.  */
/*                                                                     */
/***********************************************************************/

/* $Id$ */

/* Code specific to the SPARC (V8 and above) architecture. */

#define BngAdd2(res,carryout,arg1,arg2)                                     \
  asm("addcc %2, %3, %0 \n\t"                                               \
      "addx  %%g0, 0, %1"                                                   \
      : "=r" (res), "=r" (carryout)                                         \
      : "r" (arg1), "r" (arg2)                                              \
      : "cc")

#define BngAdd2Carry(res,carryout,arg1,arg2,carryin)                        \
  asm("subcc %%g0, %4, %%g0 \n\t"                                           \
      "addxcc %2, %3, %0 \n\t"                                              \
      "addx  %%g0, 0, %1"                                                   \
      : "=r" (res), "=r" (carryout)                                         \
      : "r" (arg1), "r" (arg2), "r" (carryin)                               \
      : "cc")

#define BngAdd3(res,carryaccu,arg1,arg2,arg3)                               \
  asm("addcc %2, %3, %0 \n\t"                                               \
      "addx %1, 0, %1 \n\t"                                                 \
      "addcc %0, %4, %0 \n\t"                                               \
      "addx %1, 0, %1"                                                      \
      : "=r" (res), "=r" (carryaccu)                                        \
      : "r" (arg1), "r" (arg2), "r" (arg3), "1" (carryaccu)                 \
      : "cc")

#define BngSub2(res,carryout,arg1,arg2)                                     \
  asm("subcc %2, %3, %0 \n\t"                                               \
      "addx  %%g0, 0, %1"                                                   \
      : "=r" (res), "=r" (carryout)                                         \
      : "r" (arg1), "r" (arg2)                                              \
      : "cc")

#define BngSub2Carry(res,carryout,arg1,arg2,carryin)                        \
  asm("subcc %%g0, %4, %%g0 \n\t"                                           \
      "subxcc %2, %3, %0 \n\t"                                              \
      "addx  %%g0, 0, %1"                                                   \
      : "=r" (res), "=r" (carryout)                                         \
      : "r" (arg1), "r" (arg2), "r" (carryin)                               \
      : "cc")

#define BngSub3(res,carryaccu,arg1,arg2,arg3)                               \
  asm("subcc %2, %3, %0 \n\t"                                               \
      "addx %1, 0, %1 \n\t"                                                 \
      "subcc %0, %4, %0 \n\t"                                               \
      "addx %1, 0, %1"                                                      \
      : "=r" (res), "=r" (carryaccu)                                        \
      : "r" (arg1), "r" (arg2), "r" (arg3), "1" (carryaccu)                 \
      : "cc")

#define BngMult(resh,resl,arg1,arg2)                                        \
  asm("umul %2, %3, %0 \n\t"                                                \
      "rd %%y, %1"                                                          \
      : "=r" (resl), "=r" (resh)                                            \
      : "r" (arg1), "r" (arg2))

#define BngDiv(quo,rem,nh,nl,d)                                             \
  asm("wr %1, %%y \n\t"                                                     \
      "udiv %2, %3, %0"                                                     \
      : "=r" (quo)                                                          \
      : "r" (nh), "r" (nl), "r" (d));                                       \
  rem = nl - d * quo