xref: /freebsd/lib/libc/powerpc64/string/bcopy_resolver.c (revision 559a218c9b257775fb249b67945fe4a05b7a6b9f)
1e16c1865SLeandro Lupori /*-
2e16c1865SLeandro Lupori  * Copyright (c) 2018 Instituto de Pesquisas Eldorado
3e16c1865SLeandro Lupori  * All rights reserved.
4e16c1865SLeandro Lupori  *
5e16c1865SLeandro Lupori  * Redistribution and use in source and binary forms, with or without
6e16c1865SLeandro Lupori  * modification, are permitted provided that the following conditions
7e16c1865SLeandro Lupori  * are met:
8e16c1865SLeandro Lupori  * 1. Redistributions of source code must retain the above copyright
9e16c1865SLeandro Lupori  *    notice, this list of conditions and the following disclaimer.
10e16c1865SLeandro Lupori  * 2. Redistributions in binary form must reproduce the above copyright
11e16c1865SLeandro Lupori  *    notice, this list of conditions and the following disclaimer in the
12e16c1865SLeandro Lupori  *    documentation and/or other materials provided with the distribution.
13e16c1865SLeandro Lupori  * 3. Neither the name of the author nor the names of its contributors may
14e16c1865SLeandro Lupori  *    be used to endorse or promote products derived from this software
15e16c1865SLeandro Lupori  *
16e16c1865SLeandro Lupori  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17e16c1865SLeandro Lupori  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18e16c1865SLeandro Lupori  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19e16c1865SLeandro Lupori  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20e16c1865SLeandro Lupori  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21e16c1865SLeandro Lupori  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22e16c1865SLeandro Lupori  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23e16c1865SLeandro Lupori  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24e16c1865SLeandro Lupori  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25e16c1865SLeandro Lupori  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26e16c1865SLeandro Lupori  * SUCH DAMAGE.
27e16c1865SLeandro Lupori  *
28e16c1865SLeandro Lupori  */
29e16c1865SLeandro Lupori 
30e16c1865SLeandro Lupori #include <machine/cpu.h>
31e16c1865SLeandro Lupori #include <machine/ifunc.h>
32e16c1865SLeandro Lupori 
33e16c1865SLeandro Lupori #define _CAT(a,b)	a##b
34e16c1865SLeandro Lupori #define CAT(a,b)	_CAT(a,b)
35e16c1865SLeandro Lupori #define CAT3(a,b,c)	CAT(CAT(a,b),c)
36e16c1865SLeandro Lupori 
37e16c1865SLeandro Lupori #ifdef MEMCOPY
38e16c1865SLeandro Lupori #define FN_NAME		memcpy
39e16c1865SLeandro Lupori #define FN_RET		void *
40e16c1865SLeandro Lupori #define FN_PARAMS	(void *dst, const void *src, size_t len)
41e16c1865SLeandro Lupori 
42e16c1865SLeandro Lupori #elif defined(MEMMOVE)
43e16c1865SLeandro Lupori #define FN_NAME		memmove
44e16c1865SLeandro Lupori #define FN_RET		void *
45e16c1865SLeandro Lupori #define FN_PARAMS	(void *dst, const void *src, size_t len)
46e16c1865SLeandro Lupori 
47e16c1865SLeandro Lupori #else
48e16c1865SLeandro Lupori #define FN_NAME		bcopy
49e16c1865SLeandro Lupori #define FN_RET		void
50e16c1865SLeandro Lupori #define FN_PARAMS	(const void *src, void *dst, size_t len)
51e16c1865SLeandro Lupori #endif
52e16c1865SLeandro Lupori 
53e16c1865SLeandro Lupori #define FN_NAME_NOVSX	CAT(__, FN_NAME)
54e16c1865SLeandro Lupori #define FN_NAME_VSX	CAT3(__, FN_NAME, _vsx)
55e16c1865SLeandro Lupori 
56e16c1865SLeandro Lupori FN_RET FN_NAME_NOVSX FN_PARAMS;
57e16c1865SLeandro Lupori FN_RET FN_NAME_VSX FN_PARAMS;
58e16c1865SLeandro Lupori 
59e16c1865SLeandro Lupori DEFINE_UIFUNC(, FN_RET, FN_NAME, FN_PARAMS)
60e16c1865SLeandro Lupori {
612b37373cSAlfredo Dal'Ava Junior 	/* VSX instructions were added in POWER ISA 2.06,
622b37373cSAlfredo Dal'Ava Junior 	 * however it requires data to be word-aligned.
632b37373cSAlfredo Dal'Ava Junior 	 * Since POWER ISA 2.07B this is solved transparently
642b37373cSAlfredo Dal'Ava Junior 	 * by the hardware
652b37373cSAlfredo Dal'Ava Junior 	 */
66*021abafaSJustin Hibbits 	if (cpu_features & PPC_FEATURE_HAS_VSX)
67e16c1865SLeandro Lupori 		return (FN_NAME_VSX);
68e16c1865SLeandro Lupori 	else
69e16c1865SLeandro Lupori 		return (FN_NAME_NOVSX);
70e16c1865SLeandro Lupori }
71