mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 13:58:04 +02:00
Bring rtasm from mesa to gallium.
This commit is contained in:
parent
e773a813cf
commit
df8ab3140c
10 changed files with 2034 additions and 1 deletions
|
|
@ -68,7 +68,7 @@ PROGRAM_DIRS = demos redbook samples glsl xdemos
|
|||
|
||||
|
||||
# Gallium directories and
|
||||
GALLIUM_AUXILIARY_DIRS = draw cso_cache pipebuffer tgsi util
|
||||
GALLIUM_AUXILIARY_DIRS = draw cso_cache pipebuffer tgsi rtasm util
|
||||
GALLIUM_AUXILIARIES = $(foreach DIR,$(GALLIUM_AUXILIARY_DIRS),$(TOP)/src/gallium/auxiliary/$(DIR)/lib$(DIR).a)
|
||||
GALLIUM_DRIVER_DIRS = softpipe i915simple i965simple failover
|
||||
GALLIUM_DRIVERS = $(foreach DIR,$(GALLIUM_DRIVER_DIRS),$(TOP)/src/gallium/drivers/$(DIR)/lib$(DIR).a)
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ Export('auxiliaries')
|
|||
SConscript([
|
||||
# NOTE: order matters!
|
||||
'auxiliary/util/SConscript',
|
||||
'auxiliary/rtasm/SConscript',
|
||||
'auxiliary/tgsi/SConscript',
|
||||
'auxiliary/cso_cache/SConscript',
|
||||
'auxiliary/draw/SConscript',
|
||||
|
|
|
|||
20
src/gallium/auxiliary/rtasm/Makefile
Normal file
20
src/gallium/auxiliary/rtasm/Makefile
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
|
||||
TOP = ../../../..
|
||||
include $(TOP)/configs/current
|
||||
|
||||
LIBNAME = rtasm
|
||||
|
||||
DRIVER_SOURCES = \
|
||||
x86sse.c \
|
||||
mm.c \
|
||||
execmem.c
|
||||
|
||||
C_SOURCES = \
|
||||
$(DRIVER_SOURCES)
|
||||
|
||||
ASM_SOURCES =
|
||||
|
||||
include ../../Makefile.template
|
||||
|
||||
symlinks:
|
||||
|
||||
11
src/gallium/auxiliary/rtasm/SConscript
Normal file
11
src/gallium/auxiliary/rtasm/SConscript
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
Import('*')
|
||||
|
||||
rtasm = env.ConvenienceLibrary(
|
||||
target = 'rtasm',
|
||||
source = [
|
||||
'x86sse.c',
|
||||
'mm.c',
|
||||
'execmem.c',
|
||||
])
|
||||
|
||||
auxiliaries.insert(0, rtasm)
|
||||
133
src/gallium/auxiliary/rtasm/execmem.c
Normal file
133
src/gallium/auxiliary/rtasm/execmem.c
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
/**************************************************************************
|
||||
*
|
||||
* Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
/**
|
||||
* \file exemem.c
|
||||
* Functions for allocating executable memory.
|
||||
*
|
||||
* \author Keith Whitwell
|
||||
*/
|
||||
|
||||
|
||||
#include "pipe/p_compiler.h"
|
||||
#include "pipe/p_thread.h"
|
||||
|
||||
#include "execmem.h"
|
||||
|
||||
|
||||
#if defined(__linux__)
|
||||
|
||||
/*
|
||||
* Allocate a large block of memory which can hold code then dole it out
|
||||
* in pieces by means of the generic memory manager code.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
#include "mm.h"
|
||||
|
||||
#define EXEC_HEAP_SIZE (10*1024*1024)
|
||||
|
||||
_glthread_DECLARE_STATIC_MUTEX(exec_mutex);
|
||||
|
||||
static struct mem_block *exec_heap = NULL;
|
||||
static unsigned char *exec_mem = NULL;
|
||||
|
||||
|
||||
static void
|
||||
init_heap(void)
|
||||
{
|
||||
if (!exec_heap)
|
||||
exec_heap = mmInit( 0, EXEC_HEAP_SIZE );
|
||||
|
||||
if (!exec_mem)
|
||||
exec_mem = (unsigned char *) mmap(0, EXEC_HEAP_SIZE,
|
||||
PROT_EXEC | PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
}
|
||||
|
||||
|
||||
void *
|
||||
_mesa_exec_malloc(size_t size)
|
||||
{
|
||||
struct mem_block *block = NULL;
|
||||
void *addr = NULL;
|
||||
|
||||
_glthread_LOCK_MUTEX(exec_mutex);
|
||||
|
||||
init_heap();
|
||||
|
||||
if (exec_heap) {
|
||||
size = (size + 31) & ~31;
|
||||
block = mmAllocMem( exec_heap, size, 32, 0 );
|
||||
}
|
||||
|
||||
if (block)
|
||||
addr = exec_mem + block->ofs;
|
||||
else
|
||||
debug_printf("_mesa_exec_malloc failed\n");
|
||||
|
||||
_glthread_UNLOCK_MUTEX(exec_mutex);
|
||||
|
||||
return addr;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
_mesa_exec_free(void *addr)
|
||||
{
|
||||
_glthread_LOCK_MUTEX(exec_mutex);
|
||||
|
||||
if (exec_heap) {
|
||||
struct mem_block *block = mmFindBlock(exec_heap, (unsigned char *)addr - exec_mem);
|
||||
|
||||
if (block)
|
||||
mmFreeMem(block);
|
||||
}
|
||||
|
||||
_glthread_UNLOCK_MUTEX(exec_mutex);
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
/*
|
||||
* Just use regular memory.
|
||||
*/
|
||||
|
||||
void *
|
||||
_mesa_exec_malloc(GLuint size)
|
||||
{
|
||||
return _mesa_malloc( size );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
_mesa_exec_free(void *addr)
|
||||
{
|
||||
_mesa_free(addr);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
45
src/gallium/auxiliary/rtasm/execmem.h
Normal file
45
src/gallium/auxiliary/rtasm/execmem.h
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/**************************************************************************
|
||||
*
|
||||
* Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
/**
|
||||
* \file exemem.c
|
||||
* Functions for allocating executable memory.
|
||||
*
|
||||
* \author Keith Whitwell
|
||||
*/
|
||||
|
||||
#ifndef _EXECMEM_H_
|
||||
#define _EXECMEM_H_
|
||||
|
||||
#include "pipe/p_compiler.h"
|
||||
|
||||
|
||||
extern void *
|
||||
_mesa_exec_malloc( size_t size );
|
||||
|
||||
|
||||
extern void
|
||||
_mesa_exec_free( void *addr );
|
||||
|
||||
|
||||
#endif
|
||||
283
src/gallium/auxiliary/rtasm/mm.c
Normal file
283
src/gallium/auxiliary/rtasm/mm.c
Normal file
|
|
@ -0,0 +1,283 @@
|
|||
/*
|
||||
* GLX Hardware Device Driver common code
|
||||
* Copyright (C) 1999 Wittawat Yamwong
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* WITTAWAT YAMWONG, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "pipe/p_compiler.h"
|
||||
#include "pipe/p_util.h"
|
||||
#include "pipe/p_debug.h"
|
||||
|
||||
#include "mm.h"
|
||||
|
||||
|
||||
void
|
||||
mmDumpMemInfo(const struct mem_block *heap)
|
||||
{
|
||||
debug_printf("Memory heap %p:\n", (void *)heap);
|
||||
if (heap == 0) {
|
||||
debug_printf(" heap == 0\n");
|
||||
} else {
|
||||
const struct mem_block *p;
|
||||
|
||||
for(p = heap->next; p != heap; p = p->next) {
|
||||
debug_printf(" Offset:%08x, Size:%08x, %c%c\n",p->ofs,p->size,
|
||||
p->free ? 'F':'.',
|
||||
p->reserved ? 'R':'.');
|
||||
}
|
||||
|
||||
debug_printf("\nFree list:\n");
|
||||
|
||||
for(p = heap->next_free; p != heap; p = p->next_free) {
|
||||
debug_printf(" FREE Offset:%08x, Size:%08x, %c%c\n",p->ofs,p->size,
|
||||
p->free ? 'F':'.',
|
||||
p->reserved ? 'R':'.');
|
||||
}
|
||||
|
||||
}
|
||||
debug_printf("End of memory blocks\n");
|
||||
}
|
||||
|
||||
struct mem_block *
|
||||
mmInit(int ofs, int size)
|
||||
{
|
||||
struct mem_block *heap, *block;
|
||||
|
||||
if (size <= 0)
|
||||
return NULL;
|
||||
|
||||
heap = CALLOC_STRUCT(mem_block);
|
||||
if (!heap)
|
||||
return NULL;
|
||||
|
||||
block = CALLOC_STRUCT(mem_block);
|
||||
if (!block) {
|
||||
FREE(heap);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
heap->next = block;
|
||||
heap->prev = block;
|
||||
heap->next_free = block;
|
||||
heap->prev_free = block;
|
||||
|
||||
block->heap = heap;
|
||||
block->next = heap;
|
||||
block->prev = heap;
|
||||
block->next_free = heap;
|
||||
block->prev_free = heap;
|
||||
|
||||
block->ofs = ofs;
|
||||
block->size = size;
|
||||
block->free = 1;
|
||||
|
||||
return heap;
|
||||
}
|
||||
|
||||
|
||||
static struct mem_block *
|
||||
SliceBlock(struct mem_block *p,
|
||||
int startofs, int size,
|
||||
int reserved, int alignment)
|
||||
{
|
||||
struct mem_block *newblock;
|
||||
|
||||
/* break left [p, newblock, p->next], then p = newblock */
|
||||
if (startofs > p->ofs) {
|
||||
newblock = CALLOC_STRUCT(mem_block);
|
||||
if (!newblock)
|
||||
return NULL;
|
||||
newblock->ofs = startofs;
|
||||
newblock->size = p->size - (startofs - p->ofs);
|
||||
newblock->free = 1;
|
||||
newblock->heap = p->heap;
|
||||
|
||||
newblock->next = p->next;
|
||||
newblock->prev = p;
|
||||
p->next->prev = newblock;
|
||||
p->next = newblock;
|
||||
|
||||
newblock->next_free = p->next_free;
|
||||
newblock->prev_free = p;
|
||||
p->next_free->prev_free = newblock;
|
||||
p->next_free = newblock;
|
||||
|
||||
p->size -= newblock->size;
|
||||
p = newblock;
|
||||
}
|
||||
|
||||
/* break right, also [p, newblock, p->next] */
|
||||
if (size < p->size) {
|
||||
newblock = CALLOC_STRUCT(mem_block);
|
||||
if (!newblock)
|
||||
return NULL;
|
||||
newblock->ofs = startofs + size;
|
||||
newblock->size = p->size - size;
|
||||
newblock->free = 1;
|
||||
newblock->heap = p->heap;
|
||||
|
||||
newblock->next = p->next;
|
||||
newblock->prev = p;
|
||||
p->next->prev = newblock;
|
||||
p->next = newblock;
|
||||
|
||||
newblock->next_free = p->next_free;
|
||||
newblock->prev_free = p;
|
||||
p->next_free->prev_free = newblock;
|
||||
p->next_free = newblock;
|
||||
|
||||
p->size = size;
|
||||
}
|
||||
|
||||
/* p = middle block */
|
||||
p->free = 0;
|
||||
|
||||
/* Remove p from the free list:
|
||||
*/
|
||||
p->next_free->prev_free = p->prev_free;
|
||||
p->prev_free->next_free = p->next_free;
|
||||
|
||||
p->next_free = 0;
|
||||
p->prev_free = 0;
|
||||
|
||||
p->reserved = reserved;
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
struct mem_block *
|
||||
mmAllocMem(struct mem_block *heap, int size, int align2, int startSearch)
|
||||
{
|
||||
struct mem_block *p;
|
||||
const int mask = (1 << align2)-1;
|
||||
int startofs = 0;
|
||||
int endofs;
|
||||
|
||||
if (!heap || align2 < 0 || size <= 0)
|
||||
return NULL;
|
||||
|
||||
for (p = heap->next_free; p != heap; p = p->next_free) {
|
||||
assert(p->free);
|
||||
|
||||
startofs = (p->ofs + mask) & ~mask;
|
||||
if ( startofs < startSearch ) {
|
||||
startofs = startSearch;
|
||||
}
|
||||
endofs = startofs+size;
|
||||
if (endofs <= (p->ofs+p->size))
|
||||
break;
|
||||
}
|
||||
|
||||
if (p == heap)
|
||||
return NULL;
|
||||
|
||||
assert(p->free);
|
||||
p = SliceBlock(p,startofs,size,0,mask+1);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
struct mem_block *
|
||||
mmFindBlock(struct mem_block *heap, int start)
|
||||
{
|
||||
struct mem_block *p;
|
||||
|
||||
for (p = heap->next; p != heap; p = p->next) {
|
||||
if (p->ofs == start)
|
||||
return p;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static INLINE int
|
||||
Join2Blocks(struct mem_block *p)
|
||||
{
|
||||
/* XXX there should be some assertions here */
|
||||
|
||||
/* NOTE: heap->free == 0 */
|
||||
|
||||
if (p->free && p->next->free) {
|
||||
struct mem_block *q = p->next;
|
||||
|
||||
assert(p->ofs + p->size == q->ofs);
|
||||
p->size += q->size;
|
||||
|
||||
p->next = q->next;
|
||||
q->next->prev = p;
|
||||
|
||||
q->next_free->prev_free = q->prev_free;
|
||||
q->prev_free->next_free = q->next_free;
|
||||
|
||||
FREE(q);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
mmFreeMem(struct mem_block *b)
|
||||
{
|
||||
if (!b)
|
||||
return 0;
|
||||
|
||||
if (b->free) {
|
||||
debug_printf("block already free\n");
|
||||
return -1;
|
||||
}
|
||||
if (b->reserved) {
|
||||
debug_printf("block is reserved\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
b->free = 1;
|
||||
b->next_free = b->heap->next_free;
|
||||
b->prev_free = b->heap;
|
||||
b->next_free->prev_free = b;
|
||||
b->prev_free->next_free = b;
|
||||
|
||||
Join2Blocks(b);
|
||||
if (b->prev != b->heap)
|
||||
Join2Blocks(b->prev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
mmDestroy(struct mem_block *heap)
|
||||
{
|
||||
struct mem_block *p;
|
||||
|
||||
if (!heap)
|
||||
return;
|
||||
|
||||
for (p = heap->next; p != heap; ) {
|
||||
struct mem_block *next = p->next;
|
||||
FREE(p);
|
||||
p = next;
|
||||
}
|
||||
|
||||
FREE(heap);
|
||||
}
|
||||
89
src/gallium/auxiliary/rtasm/mm.h
Normal file
89
src/gallium/auxiliary/rtasm/mm.h
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* GLX Hardware Device Driver common code
|
||||
* Copyright (C) 1999 Wittawat Yamwong
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* KEITH WHITWELL, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Memory manager code. Primarily used by device drivers to manage texture
|
||||
* heaps, etc.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MM_H
|
||||
#define MM_H
|
||||
|
||||
|
||||
struct mem_block {
|
||||
struct mem_block *next, *prev;
|
||||
struct mem_block *next_free, *prev_free;
|
||||
struct mem_block *heap;
|
||||
int ofs,size;
|
||||
unsigned int free:1;
|
||||
unsigned int reserved:1;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* input: total size in bytes
|
||||
* return: a heap pointer if OK, NULL if error
|
||||
*/
|
||||
extern struct mem_block *mmInit(int ofs, int size);
|
||||
|
||||
/**
|
||||
* Allocate 'size' bytes with 2^align2 bytes alignment,
|
||||
* restrict the search to free memory after 'startSearch'
|
||||
* depth and back buffers should be in different 4mb banks
|
||||
* to get better page hits if possible
|
||||
* input: size = size of block
|
||||
* align2 = 2^align2 bytes alignment
|
||||
* startSearch = linear offset from start of heap to begin search
|
||||
* return: pointer to the allocated block, 0 if error
|
||||
*/
|
||||
extern struct mem_block *mmAllocMem(struct mem_block *heap, int size, int align2,
|
||||
int startSearch);
|
||||
|
||||
/**
|
||||
* Free block starts at offset
|
||||
* input: pointer to a block
|
||||
* return: 0 if OK, -1 if error
|
||||
*/
|
||||
extern int mmFreeMem(struct mem_block *b);
|
||||
|
||||
/**
|
||||
* Free block starts at offset
|
||||
* input: pointer to a heap, start offset
|
||||
* return: pointer to a block
|
||||
*/
|
||||
extern struct mem_block *mmFindBlock(struct mem_block *heap, int start);
|
||||
|
||||
/**
|
||||
* destroy MM
|
||||
*/
|
||||
extern void mmDestroy(struct mem_block *mmInit);
|
||||
|
||||
/**
|
||||
* For debuging purpose.
|
||||
*/
|
||||
extern void mmDumpMemInfo(const struct mem_block *mmInit);
|
||||
|
||||
#endif
|
||||
1195
src/gallium/auxiliary/rtasm/x86sse.c
Normal file
1195
src/gallium/auxiliary/rtasm/x86sse.c
Normal file
File diff suppressed because it is too large
Load diff
256
src/gallium/auxiliary/rtasm/x86sse.h
Normal file
256
src/gallium/auxiliary/rtasm/x86sse.h
Normal file
|
|
@ -0,0 +1,256 @@
|
|||
|
||||
#ifndef _X86SSE_H_
|
||||
#define _X86SSE_H_
|
||||
|
||||
#if defined(__i386__) || defined(__386__)
|
||||
|
||||
/* It is up to the caller to ensure that instructions issued are
|
||||
* suitable for the host cpu. There are no checks made in this module
|
||||
* for mmx/sse/sse2 support on the cpu.
|
||||
*/
|
||||
struct x86_reg {
|
||||
unsigned file:3;
|
||||
unsigned idx:3;
|
||||
unsigned mod:2; /* mod_REG if this is just a register */
|
||||
int disp:24; /* only +/- 23bits of offset - should be enough... */
|
||||
};
|
||||
|
||||
struct x86_function {
|
||||
unsigned size;
|
||||
unsigned char *store;
|
||||
unsigned char *csr;
|
||||
unsigned stack_offset;
|
||||
int need_emms;
|
||||
const char *fn;
|
||||
};
|
||||
|
||||
enum x86_reg_file {
|
||||
file_REG32,
|
||||
file_MMX,
|
||||
file_XMM,
|
||||
file_x87
|
||||
};
|
||||
|
||||
/* Values for mod field of modr/m byte
|
||||
*/
|
||||
enum x86_reg_mod {
|
||||
mod_INDIRECT,
|
||||
mod_DISP8,
|
||||
mod_DISP32,
|
||||
mod_REG
|
||||
};
|
||||
|
||||
enum x86_reg_name {
|
||||
reg_AX,
|
||||
reg_CX,
|
||||
reg_DX,
|
||||
reg_BX,
|
||||
reg_SP,
|
||||
reg_BP,
|
||||
reg_SI,
|
||||
reg_DI
|
||||
};
|
||||
|
||||
|
||||
enum x86_cc {
|
||||
cc_O, /* overflow */
|
||||
cc_NO, /* not overflow */
|
||||
cc_NAE, /* not above or equal / carry */
|
||||
cc_AE, /* above or equal / not carry */
|
||||
cc_E, /* equal / zero */
|
||||
cc_NE /* not equal / not zero */
|
||||
};
|
||||
|
||||
enum sse_cc {
|
||||
cc_Equal,
|
||||
cc_LessThan,
|
||||
cc_LessThanEqual,
|
||||
cc_Unordered,
|
||||
cc_NotEqual,
|
||||
cc_NotLessThan,
|
||||
cc_NotLessThanEqual,
|
||||
cc_Ordered
|
||||
};
|
||||
|
||||
#define cc_Z cc_E
|
||||
#define cc_NZ cc_NE
|
||||
|
||||
/* Begin/end/retreive function creation:
|
||||
*/
|
||||
|
||||
|
||||
void x86_init_func( struct x86_function *p );
|
||||
void x86_init_func_size( struct x86_function *p, unsigned code_size );
|
||||
void x86_release_func( struct x86_function *p );
|
||||
void (*x86_get_func( struct x86_function *p ))( void );
|
||||
|
||||
|
||||
|
||||
/* Create and manipulate registers and regmem values:
|
||||
*/
|
||||
struct x86_reg x86_make_reg( enum x86_reg_file file,
|
||||
enum x86_reg_name idx );
|
||||
|
||||
struct x86_reg x86_make_disp( struct x86_reg reg,
|
||||
int disp );
|
||||
|
||||
struct x86_reg x86_deref( struct x86_reg reg );
|
||||
|
||||
struct x86_reg x86_get_base_reg( struct x86_reg reg );
|
||||
|
||||
|
||||
/* Labels, jumps and fixup:
|
||||
*/
|
||||
unsigned char *x86_get_label( struct x86_function *p );
|
||||
|
||||
void x86_jcc( struct x86_function *p,
|
||||
enum x86_cc cc,
|
||||
unsigned char *label );
|
||||
|
||||
unsigned char *x86_jcc_forward( struct x86_function *p,
|
||||
enum x86_cc cc );
|
||||
|
||||
unsigned char *x86_jmp_forward( struct x86_function *p);
|
||||
|
||||
unsigned char *x86_call_forward( struct x86_function *p);
|
||||
|
||||
void x86_fixup_fwd_jump( struct x86_function *p,
|
||||
unsigned char *fixup );
|
||||
|
||||
void x86_jmp( struct x86_function *p, unsigned char *label );
|
||||
|
||||
/* void x86_call( struct x86_function *p, void (*label)() ); */
|
||||
void x86_call( struct x86_function *p, struct x86_reg reg);
|
||||
|
||||
/* michal:
|
||||
* Temporary. As I need immediate operands, and dont want to mess with the codegen,
|
||||
* I load the immediate into general purpose register and use it.
|
||||
*/
|
||||
void x86_mov_reg_imm( struct x86_function *p, struct x86_reg dst, int imm );
|
||||
|
||||
|
||||
/* Macro for sse_shufps() and sse2_pshufd():
|
||||
*/
|
||||
#define SHUF(_x,_y,_z,_w) (((_x)<<0) | ((_y)<<2) | ((_z)<<4) | ((_w)<<6))
|
||||
#define SHUF_NOOP RSW(0,1,2,3)
|
||||
#define GET_SHUF(swz, idx) (((swz) >> ((idx)*2)) & 0x3)
|
||||
|
||||
void mmx_emms( struct x86_function *p );
|
||||
void mmx_movd( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void mmx_movq( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void mmx_packssdw( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void mmx_packuswb( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
|
||||
void sse2_cvtps2dq( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void sse2_cvttps2dq( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void sse2_movd( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void sse2_packssdw( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void sse2_packsswb( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void sse2_packuswb( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void sse2_pshufd( struct x86_function *p, struct x86_reg dest, struct x86_reg arg0,
|
||||
unsigned char shuf );
|
||||
void sse2_rcpps( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void sse2_rcpss( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
|
||||
void sse_addps( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void sse_addss( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void sse_cvtps2pi( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void sse_divss( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void sse_andnps( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void sse_andps( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void sse_cmpps( struct x86_function *p, struct x86_reg dst, struct x86_reg src,
|
||||
unsigned char cc );
|
||||
void sse_maxps( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void sse_maxss( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void sse_minps( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void sse_movaps( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void sse_movhlps( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void sse_movhps( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void sse_movlhps( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void sse_movlps( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void sse_movss( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void sse_movups( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void sse_mulps( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void sse_mulss( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void sse_orps( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void sse_xorps( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void sse_subps( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void sse_rsqrtps( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void sse_rsqrtss( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void sse_shufps( struct x86_function *p, struct x86_reg dest, struct x86_reg arg0,
|
||||
unsigned char shuf );
|
||||
void sse_pmovmskb( struct x86_function *p, struct x86_reg dest, struct x86_reg src );
|
||||
|
||||
void x86_add( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void x86_and( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void x86_cmp( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void x86_dec( struct x86_function *p, struct x86_reg reg );
|
||||
void x86_inc( struct x86_function *p, struct x86_reg reg );
|
||||
void x86_lea( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void x86_mov( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void x86_mul( struct x86_function *p, struct x86_reg src );
|
||||
void x86_or( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void x86_pop( struct x86_function *p, struct x86_reg reg );
|
||||
void x86_push( struct x86_function *p, struct x86_reg reg );
|
||||
void x86_ret( struct x86_function *p );
|
||||
void x86_sub( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void x86_test( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void x86_xor( struct x86_function *p, struct x86_reg dst, struct x86_reg src );
|
||||
void x86_sahf( struct x86_function *p );
|
||||
|
||||
void x87_f2xm1( struct x86_function *p );
|
||||
void x87_fabs( struct x86_function *p );
|
||||
void x87_fadd( struct x86_function *p, struct x86_reg dst, struct x86_reg arg );
|
||||
void x87_faddp( struct x86_function *p, struct x86_reg dst );
|
||||
void x87_fchs( struct x86_function *p );
|
||||
void x87_fclex( struct x86_function *p );
|
||||
void x87_fcom( struct x86_function *p, struct x86_reg dst );
|
||||
void x87_fcomp( struct x86_function *p, struct x86_reg dst );
|
||||
void x87_fcos( struct x86_function *p );
|
||||
void x87_fdiv( struct x86_function *p, struct x86_reg dst, struct x86_reg arg );
|
||||
void x87_fdivp( struct x86_function *p, struct x86_reg dst );
|
||||
void x87_fdivr( struct x86_function *p, struct x86_reg dst, struct x86_reg arg );
|
||||
void x87_fdivrp( struct x86_function *p, struct x86_reg dst );
|
||||
void x87_fild( struct x86_function *p, struct x86_reg arg );
|
||||
void x87_fist( struct x86_function *p, struct x86_reg dst );
|
||||
void x87_fistp( struct x86_function *p, struct x86_reg dst );
|
||||
void x87_fld( struct x86_function *p, struct x86_reg arg );
|
||||
void x87_fld1( struct x86_function *p );
|
||||
void x87_fldcw( struct x86_function *p, struct x86_reg arg );
|
||||
void x87_fldl2e( struct x86_function *p );
|
||||
void x87_fldln2( struct x86_function *p );
|
||||
void x87_fldz( struct x86_function *p );
|
||||
void x87_fmul( struct x86_function *p, struct x86_reg dst, struct x86_reg arg );
|
||||
void x87_fmulp( struct x86_function *p, struct x86_reg dst );
|
||||
void x87_fnclex( struct x86_function *p );
|
||||
void x87_fprndint( struct x86_function *p );
|
||||
void x87_fscale( struct x86_function *p );
|
||||
void x87_fsin( struct x86_function *p );
|
||||
void x87_fsincos( struct x86_function *p );
|
||||
void x87_fsqrt( struct x86_function *p );
|
||||
void x87_fst( struct x86_function *p, struct x86_reg dst );
|
||||
void x87_fstp( struct x86_function *p, struct x86_reg dst );
|
||||
void x87_fsub( struct x86_function *p, struct x86_reg dst, struct x86_reg arg );
|
||||
void x87_fsubp( struct x86_function *p, struct x86_reg dst );
|
||||
void x87_fsubr( struct x86_function *p, struct x86_reg dst, struct x86_reg arg );
|
||||
void x87_fsubrp( struct x86_function *p, struct x86_reg dst );
|
||||
void x87_fxch( struct x86_function *p, struct x86_reg dst );
|
||||
void x87_fxtract( struct x86_function *p );
|
||||
void x87_fyl2x( struct x86_function *p );
|
||||
void x87_fyl2xp1( struct x86_function *p );
|
||||
void x87_fwait( struct x86_function *p );
|
||||
void x87_fnstsw( struct x86_function *p, struct x86_reg dst );
|
||||
void x87_fucompp( struct x86_function *p );
|
||||
void x87_fucomp( struct x86_function *p, struct x86_reg arg );
|
||||
void x87_fucom( struct x86_function *p, struct x86_reg arg );
|
||||
|
||||
|
||||
|
||||
/* Retreive a reference to one of the function arguments, taking into
|
||||
* account any push/pop activity. Note - doesn't track explict
|
||||
* manipulation of ESP by other instructions.
|
||||
*/
|
||||
struct x86_reg x86_fn_arg( struct x86_function *p, unsigned arg );
|
||||
|
||||
#endif
|
||||
#endif
|
||||
Loading…
Add table
Reference in a new issue