Updated to fedora-glibc-20041124T0741
[glibc.git] / sysdeps / alpha / div_libc.h
blob62b447035510cdb236529bc5b6a4aab5a129f5c3
1 /* Copyright (C) 2004 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
19 /* Common bits for implementing software divide. */
21 #include <sysdep.h>
22 #ifdef __linux__
23 # include <asm/gentrap.h>
24 # include <asm/pal.h>
25 #else
26 # include <machine/pal.h>
27 #endif
29 /* These are not normal C functions. Argument registers are t10 and t11;
30 the result goes in t12; the return address is in t9. Only t12 and AT
31 may be clobbered. */
32 #define X t10
33 #define Y t11
34 #define RV t12
35 #define RA t9
37 /* None of these functions should use implicit anything. */
38 .set nomacro
39 .set noat
41 /* Code fragment to invoke _mcount for profiling. This should be invoked
42 directly after allocation of the stack frame. */
43 .macro CALL_MCOUNT
44 #ifdef PROF
45 stq ra, 0(sp)
46 stq pv, 8(sp)
47 stq gp, 16(sp)
48 cfi_rel_offset (ra, 0)
49 cfi_rel_offset (pv, 8)
50 cfi_rel_offset (gp, 16)
51 br AT, 1f
52 .set macro
53 1: ldgp gp, 0(AT)
54 mov RA, ra
55 lda AT, _mcount
56 jsr AT, (AT), _mcount
57 .set nomacro
58 ldq ra, 0(sp)
59 ldq pv, 8(sp)
60 ldq gp, 16(sp)
61 cfi_restore (ra)
62 cfi_restore (pv)
63 cfi_restore (gp)
64 /* Realign subsequent code with what we'd have without this
65 macro at all. This means aligned with one arithmetic insn
66 used within the bundle. */
67 .align 4
68 nop
69 #endif
70 .endm
72 /* In order to make the below work, all top-level divide routines must
73 use the same frame size. */
74 #define FRAME 64
76 /* Code fragment to generate an integer divide-by-zero fault. When
77 building libc.so, we arrange for there to be one copy of this code
78 placed late in the dso, such that all branches are forward. When
79 building libc.a, we use multiple copies to avoid having an out of
80 range branch. Users should jump to DIVBYZERO. */
82 .macro DO_DIVBYZERO
83 #ifdef PIC
84 #define DIVBYZERO __divbyzero
85 .section .gnu.linkonce.t.divbyzero, "ax", @progbits
86 .globl __divbyzero
87 .type __divbyzero, @function
88 .usepv __divbyzero, no
89 .hidden __divbyzero
90 #else
91 #define DIVBYZERO $divbyzero
92 #endif
94 .align 4
95 DIVBYZERO:
96 cfi_startproc
97 cfi_return_column (RA)
98 cfi_def_cfa_offset (FRAME)
100 mov a0, RV
101 unop
102 lda a0, GEN_INTDIV
103 call_pal PAL_gentrap
105 mov RV, a0
106 clr RV
107 lda sp, FRAME(sp)
108 cfi_def_cfa_offset (0)
109 ret $31, (RA), 1
111 cfi_endproc
112 .size DIVBYZERO, .-DIVBYZERO
113 .endm
115 /* Like the ev6 instructions, but fall back to stack use on prior machines. */
117 .arch ev6
119 .macro _ITOFS gr, fr, slot
120 #ifdef __alpha_fix__
121 itofs \gr, \fr
122 #else
123 stl \gr, \slot(sp)
124 lds \fr, \slot(sp)
125 #endif
126 .endm
128 .macro _ITOFT gr, fr, slot
129 #ifdef __alpha_fix__
130 itoft \gr, \fr
131 #else
132 stq \gr, \slot(sp)
133 ldt \fr, \slot(sp)
134 #endif
135 .endm
137 .macro _FTOIT fr, gr, slot
138 #ifdef __alpha_fix__
139 ftoit \fr, \gr
140 #else
141 stt \fr, \slot(sp)
142 ldq \gr, \slot(sp)
143 #endif
144 .endm
146 /* Similarly, but move two registers. Schedules better for pre-ev6. */
148 .macro _ITOFT2 gr1, fr1, slot1, gr2, fr2, slot2
149 #ifdef __alpha_fix__
150 itoft \gr1, \fr1
151 itoft \gr2, \fr2
152 #else
153 stq \gr1, \slot1(sp)
154 stq \gr2, \slot2(sp)
155 ldt \fr1, \slot1(sp)
156 ldt \fr2, \slot2(sp)
157 #endif
158 .endm