<commit_before>/* vi: set sw=4 ts=4: */
/*
 * Wrapper functions implementing all the long double math functions
 * defined by SuSv3 by actually calling the double version of
 * each function and then casting the result back to a long double
 * to return to the user.
 *
 * Copyright (C) 2005 by <NAME> <<EMAIL>>
 *
 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
 */

#include <features.h>
/* Prevent math.h from defining colliding inlines */
#undef __USE_EXTERN_INLINES
#include "math.h"
#include <complex.h>

#define WRAPPER1(func) \
long double func##l(long double x) \
{ \
	return (long double) func((double) x); \
}
#define int_WRAPPER1(func) \
int func##l(long double x) \
{ \
	return func((double) x); \
}
#define long_WRAPPER1(func) \
long func##l(long double x) \
{ \
	return func((double) x); \
}
#define long_long_WRAPPER1(func) \
long long func##l(long double x) \
{ \
	return func((double) x); \
}

#if defined __i386__ && defined __OPTIMIZE__
# undef WRAPPER1
# undef int_WRAPPER1
# undef long_WRAPPER1
# undef long_long_WRAPPER1
/* gcc 4.3.1 generates really ugly code with redundant pair of store/load:
 *	sub	$0x10,%esp
 *	fldt	0x14(%esp)
 *	fstpl	0x8(%esp)
 *	fldl	0x8(%esp) <-- ??
 *	fstpl	(%esp)    <-- ??
 *	call	function
 *	add	$0x10,%esp
 *	ret
 * I can hope newer gcc will eliminate that. However, I don't think
 * it will be smart enough to reuse argument stack space and use
 * jump instead of call. Let's do it by hand.
 * The asm below loads long double x into st(0), then stores it back
 * to the same location, but as a double. At this point, stack looks
 * exactly as "double func(double)" expects it to be.
 * The return value is returned in st(0) per ABI in both cases (returning
 * a long double or returning a double). So we can simply jump to func.
 * Using __GI_func in jump to make optimized intra-library jump.
 * gcc will still generate a useless "ret" after asm. Oh well...
 */
# define WRAPPER1(func) \
long double func##l(long double x) \
{ \
	long double st_top; \
	__asm__ ( \
	"	fldt	%1\n" \
	"	fstpl	%1\n" \
	"	jmp	" __stringify(__GI_##func) "\n" \
	: "=t" (st_top) \
	: "m" (x) \
	); \
	return st_top; \
}
# define int_WRAPPER1(func) \
int func##l(long double x) \
{ \
	int ret; \
	__asm__ ( \
	"	fldt	%1\n" \
	"	fstpl	%1\n" \
	"	jmp	" __stringify(__GI_##func) "\n" \
	: "=a" (ret) \
	: "m" (x) \
	); \
	return ret; \
}
# define long_WRAPPER1(func) \
long func##l(long double x) \
{ \
	long ret; \
	__asm__ ( \
	"	fldt	%1\n" \
	"	fstpl	%1\n" \
	"	jmp	" __stringify(__GI_##func) "\n" \
	: "=a" (ret) \
	: "m" (x) \
	); \
	return ret; \
}
# define long_long_WRAPPER1(func) \
long long func##l(long double x) \
{ \
	long long ret; \
	__asm__ ( \
	"	fldt	%1\n" \
	"	fstpl	%1\n" \
	"	jmp	" __stringify(__GI_##func) "\n" \
	: "=A" (ret) \
	: "m" (x) \
	); \
	return ret; \
}
#endif /* __i386__ && __OPTIMIZE__ */

#if defined __NO_LONG_DOUBLE_MATH
# define int_WRAPPER_C99(func) /* not needed */
# else
# define int_WRAPPER_C99(func) \
int func##l(long double x) \
{ \
    return func((double) x); \
} \
libm_hidden_def(func##l)
#endif<commit_msg>libm/x86: use call instead of jump for wrappers<commit_after>/* vi: set sw=4 ts=4: */
/*
 * Wrapper functions implementing all the long double math functions
 * defined by SuSv3 by actually calling the double version of
 * each function and then casting the result back to a long double
 * to return to the user.
 *
 * Copyright (C) 2005 by <NAME> <<EMAIL>>
 *
 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
 */

#include <features.h>
/* Prevent math.h from defining colliding inlines */
#undef __USE_EXTERN_INLINES
#include "math.h"
#include <complex.h>

#define WRAPPER1(func) \
long double func##l(long double x) \
{ \
	return (long double) func((double) x); \
}
#define int_WRAPPER1(func) \
int func##l(long double x) \
{ \
	return func((double) x); \
}
#define long_WRAPPER1(func) \
long func##l(long double x) \
{ \
	return func((double) x); \
}
#define long_long_WRAPPER1(func) \
long long func##l(long double x) \
{ \
	return func((double) x); \
}

#if defined __i386__ && defined __OPTIMIZE__
# undef WRAPPER1
# undef int_WRAPPER1
# undef long_WRAPPER1
# undef long_long_WRAPPER1
/* gcc 4.3.1 generates really ugly code with redundant pair of store/load:
 *	sub	$0x10,%esp
 *	fldt	0x14(%esp)
 *	fstpl	0x8(%esp)
 *	fldl	0x8(%esp) <-- ??
 *	fstpl	(%esp)    <-- ??
 *	call	function
 *	add	$0x10,%esp
 *	ret
 * I can hope newer gcc will eliminate that. However, I don't think
 * it will be smart enough to reuse argument stack space and use
 * jump instead of call. Let's do it by hand.
 * The asm below loads long double x into st(0), then stores it back
 * to the same location, but as a double. At this point, stack looks
 * exactly as "double func(double)" expects it to be.
 * The return value is returned in st(0) per ABI in both cases (returning
 * a long double or returning a double). So we can simply jump to func.
 * Using __GI_func in jump to make optimized intra-library jump.
 * gcc will still generate a useless "ret" after asm. Oh well...
 *
 * Update: we do need to use call (instead of tail jump) as gcc can create
 * stack frame, and push/modify/pop ebx during PIC build.
 * TODO: add conditionals to use tail jump if possible?
 */
# define WRAPPER1(func) \
long double func##l(long double x) \
{ \
	long double st_top; \
	__asm__ ( \
	"	fldt	%1\n" \
	"	fstpl	%1\n" \
	"	call	" __stringify(__GI_##func) "\n" \
	: "=t" (st_top) \
	: "m" (x) \
	); \
	return st_top; \
}
# define int_WRAPPER1(func) \
int func##l(long double x) \
{ \
	int ret; \
	__asm__ ( \
	"	fldt	%1\n" \
	"	fstpl	%1\n" \
	"	call	" __stringify(__GI_##func) "\n" \
	: "=a" (ret) \
	: "m" (x) \
	); \
	return ret; \
}
# define long_WRAPPER1(func) \
long func##l(long double x) \
{ \
	long ret; \
	__asm__ ( \
	"	fldt	%1\n" \
	"	fstpl	%1\n" \
	"	call	" __stringify(__GI_##func) "\n" \
	: "=a" (ret) \
	: "m" (x) \
	); \
	return ret; \
}
# define long_long_WRAPPER1(func) \
long long func##l(long double x) \
{ \
	long long ret; \
	__asm__ ( \
	"	fldt	%1\n" \
	"	fstpl	%1\n" \
	"	call	" __stringify(__GI_##func) "\n" \
	: "=A" (ret) \
	: "m" (x) \
	); \
	return ret; \
}
#endif /* __i386__ && __OPTIMIZE__ */

#if defined __NO_LONG_DOUBLE_MATH
# define int_WRAPPER_C99(func) /* not needed */
# else
# define int_WRAPPER_C99(func) \
int func##l(long double x) \
{ \
    return func((double) x); \
} \
libm_hidden_def(func##l)
#endif
{'fraction_non_alphanumeric': 0.14964407304240174, 'fraction_numerical': 0.01795109873104302, 'mean_word_length': 3.153598971722365, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7425417', 'n_tokens_mistral': 2658, 'n_tokens_neox': 2590, 'n_words': 798}