fpu_reg.h revision 330897
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2002 by Thomas Moestl <tmm@FreeBSD.org>.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
25 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 * $FreeBSD: stable/11/lib/libc/sparc64/fpu/fpu_reg.h 330897 2018-03-14 03:19:51Z eadler $
28 */
29
30#ifndef _LIBC_SPARC64_FPU_FPU_REG_H_
31#define _LIBC_SPARC64_FPU_FPU_REG_H_
32
33/*
34 * These are not really of type char[]. They are arrays of functions defined
35 * in fpu_reg.S; each array member loads/stores a certain fpu register of the
36 * given size.
37 */
38extern char __fpu_ld32[];
39extern char __fpu_st32[];
40extern char __fpu_ld64[];
41extern char __fpu_st64[];
42
43/* Size of the functions in the arrays. */
44#define	FPU_LD32_SZ	8
45#define	FPU_ST32_SZ	8
46#define	FPU_LD64_SZ	8
47#define	FPU_ST64_SZ	8
48
49/* Typedefs for convenient casts in the functions below. */
50typedef void (fp_ldst32_fn)(u_int32_t *);
51typedef void (fp_ldst64_fn)(u_int64_t *);
52
53/*
54 * These are the functions that are actually used in the fpu emulation code to
55 * access the fp registers. They are usually not used more than once, so
56 * caching needs not be done here.
57 */
58static __inline u_int32_t
59__fpu_getreg(int r)
60{
61	u_int32_t rv;
62
63	((fp_ldst32_fn *)&__fpu_st32[r * FPU_ST32_SZ])(&rv);
64	return (rv);
65}
66
67static __inline u_int64_t
68__fpu_getreg64(int r)
69{
70	u_int64_t rv;
71
72	((fp_ldst64_fn *)&__fpu_st64[(r >> 1) * FPU_ST64_SZ])(&rv);
73	return (rv);
74}
75
76static __inline void
77__fpu_setreg(int r, u_int32_t v)
78{
79
80	((fp_ldst32_fn *)&__fpu_ld32[r * FPU_LD32_SZ])(&v);
81}
82
83static __inline void
84__fpu_setreg64(int r, u_int64_t v)
85{
86
87	((fp_ldst64_fn *)&__fpu_ld64[(r >> 1) * FPU_LD64_SZ])(&v);
88}
89
90#endif /* _LIBC_SPARC64_FPU_FPU_REG_H_ */
91