#ifndef _LIBM_H
#define _LIBM_H
#include <sys/isa_defs.h>
#ifdef _ASM
#if defined(__amd64)
#undef PROF
#endif
#include <sys/asm_linkage.h>
#define NAME(x) x
#define TEXT .section ".text"
#define DATA .section ".data"
#define RO_DATA .section ".rodata"
#define IDENT(x) .ident x
#if defined(__sparc)
#define LIBM_ANSI_PRAGMA_WEAK(sym,stype) \
.weak __##sym; \
.type __##sym,#stype; \
__##sym = sym
#ifndef SET_FILE
#define SET_FILE(x) \
.file x
#endif
#ifdef PIC
#define PIC_SETUP(via) \
9: call 8f; \
sethi %hi(NAME(_GLOBAL_OFFSET_TABLE_)-(9b-.)),%via; \
8: or %via,%lo(NAME(_GLOBAL_OFFSET_TABLE_)-(9b-.)),%via; \
add %via,%o7,%via
#define PIC_LEAF_SETUP(via) \
or %g0,%o7,%g1; \
9: call 8f; \
sethi %hi(NAME(_GLOBAL_OFFSET_TABLE_)-(9b-.)),%via; \
8: or %via,%lo(NAME(_GLOBAL_OFFSET_TABLE_)-(9b-.)),%via; \
add %via,%o7,%via; \
or %g0,%g1,%o7
#ifdef __sparcv9
#define PIC_SET(via,sym,dst) ldx [%via+sym],%dst
#else
#define PIC_SET(via,sym,dst) ld [%via+sym],%dst
#endif
#else
#define PIC_SETUP(via)
#define PIC_LEAF_SETUP(via)
#ifdef __sparcv9
#define PIC_SET(via,sym,dst) setx sym,%g1,%dst
#else
#define PIC_SET(via,sym,dst) set sym,%dst
#endif
#endif
#if defined(PROF) && defined(__sparcv9)
#undef MCOUNT_SIZE
#undef MCOUNT
#if !defined(PIC)
#define MCOUNT_SIZE (9*4)
#define MCOUNT(x) \
save %sp, -SA(MINFRAME), %sp; \
sethi %hh(.L_##x##1), %o0; \
sethi %lm(.L_##x##1), %o1; \
or %o0, %hm(.L_##x##1), %o0; \
or %o1, %lo(.L_##x##1), %o1; \
sllx %o0, 32, %o0; \
call _mcount; \
or %o0, %o1, %o0; \
restore; \
.common .L_##x##1, 8, 8
#elif defined(PIC32)
#define MCOUNT_SIZE (10*4)
#define MCOUNT(x) \
save %sp,-SA(MINFRAME),%sp; \
1: call .+8; \
sethi %hi(_GLOBAL_OFFSET_TABLE_-(1b-.)),%o0; \
sethi %hi(.L_##x##1),%o1; \
add %o0,%lo(_GLOBAL_OFFSET_TABLE_-(1b-.)),%o0; \
add %o1,%lo(.L_##x##1),%o1; \
add %o0,%o7,%o0; \
call _mcount; \
ldx [%o0+%o1],%o0; \
restore; \
.common .L_##x##1,8,8
#else
#define MCOUNT_SIZE (8*4)
#define MCOUNT(x) \
save %sp,-SA(MINFRAME),%sp; \
1: call .+8; \
sethi %hi(_GLOBAL_OFFSET_TABLE_-(1b-.)),%o0; \
add %o0,%lo(_GLOBAL_OFFSET_TABLE_-(1b-.)),%o0; \
add %o0,%o7,%o0; \
call _mcount; \
ldx [%o0+%lo(.L_##x##1)],%o0; \
restore; \
.common .L_##x##1,8,8
#endif
#endif
#elif defined(__x86)
#define LIBM_ANSI_PRAGMA_WEAK(sym,stype) \
.weak __##sym; \
.type __##sym,@stype; \
__##sym = sym
#ifdef PIC
#if defined(__amd64)
#define PIC_SETUP(x)
#define PIC_WRAPUP
#define PIC_F(x) x@PLT
#define PIC_G(x) x@GOTPCREL(%rip)
#define PIC_L(x) x(%rip)
#define PIC_G_LOAD(insn,sym,dst) \
movq PIC_G(sym),%dst; \
insn (%dst),%dst
#else
#define PIC_SETUP(label) \
pushl %ebx; \
call .##label; \
.##label: popl %ebx; \
addl $_GLOBAL_OFFSET_TABLE_ + [. - .##label], %ebx
#define PIC_WRAPUP popl %ebx
#define PIC_F(x) x@PLT
#define PIC_G(x) x@GOT(%ebx)
#define PIC_L(x) x@GOTOFF(%ebx)
#define PIC_G_LOAD(insn,sym,dst) \
mov PIC_G(sym),%dst; \
insn (%dst),%dst
#endif
#else
#define PIC_SETUP(x)
#define PIC_WRAPUP
#define PIC_F(x) x
#define PIC_G(x) x
#define PIC_L(x) x
#define PIC_G_LOAD(insn,sym,dst) insn sym,%dst
#endif
#else
#error Unknown architecture
#endif
#else
#include "libm_macros.h"
#include "libm_protos.h"
#include "libm_inlines.h"
#include <math.h>
#if defined(__SUNPRO_C)
#include <sunmath.h>
#endif
#endif
#endif