Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable caches, fusion and dual issue on startup #68

Open
wants to merge 2 commits into
base: arc-2024.12
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libgloss/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ multilibtool_PROGRAMS = $(am__EXEEXT_7)
@CONFIG_RISCV_TRUE@ riscv/arcv.specs \
@CONFIG_RISCV_TRUE@ riscv/arcv-crt0.o \
@CONFIG_RISCV_TRUE@ riscv/arcv.ld \
@CONFIG_RISCV_TRUE@ riscv/arcv.o \
@CONFIG_RISCV_TRUE@ riscv/crt0.o

@CONFIG_RISCV_TRUE@am__append_102 = riscv/libgloss.a riscv/libsim.a \
Expand Down
1 change: 1 addition & 0 deletions libgloss/riscv/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ multilibtool_DATA += \
%D%/arcv.specs \
%D%/arcv-crt0.o \
%D%/arcv.ld \
%D%/arcv.o \
%D%/crt0.o

multilibtool_LIBRARIES += %D%/libgloss.a
Expand Down
5 changes: 5 additions & 0 deletions libgloss/riscv/arcv-crt0.S
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ _start:
#endif
call __libc_init_array # Run global initialization functions

#if defined (__riscv_zicsr)
# ARC-V specific initialization
call _arcv_cache_enable # Enable caches
#endif

# Get arguments from custom symbols if they are defined. Otherwise,
# get them from the stack.
.weak _argc
Expand Down
84 changes: 84 additions & 0 deletions libgloss/riscv/arcv.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
Copyright (c) 2024, Synopsys, Inc. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1) Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2) Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3) Neither the name of the Synopsys, Inc., nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/

#include "arcv.h"

void _arcv_cache_enable ()
{
#if defined (__riscv_zicsr)
unsigned long mcache = _arcv_csr_read(CSR_NUM_ARCV_MCACHE_CTRL);
mcache |=
(1 << ARCV_MCACHE_CTRL_IC_EN_OFFSET) |
(1 << ARCV_MCACHE_CTRL_DC_EN_OFFSET) |
(1 << ARCV_MCACHE_CTRL_DC_L0_EN_OFFSET) |
(1 << ARCV_MCACHE_CTRL_L2_EN_OFFSET);
_arcv_csr_write(CSR_NUM_ARCV_MCACHE_CTRL, mcache);
#endif
}

void _arcv_dual_issue_enable ()
{
#if defined (__riscv_zicsr)
unsigned long mexec, family, marchid;

marchid = _arcv_csr_read(CSR_NUM_MARCHID);
family = (marchid >> ARCV_MARCHID_FAMILY_OFFSET) & ARCV_MARCHID_FAMILY_MASK;
if (family != ARCV_MARCHID_RHX100_VALUE) {
return;
}

mexec = _arcv_csr_read(CSR_NUM_ARCV_MEXEC_CTRL);
mexec = ~mexec;
mexec |= 1 << ARCV_MEXEC_DUAL_ISSUE_OFFSET;
mexec = ~mexec;
_arcv_csr_write(CSR_NUM_ARCV_MEXEC_CTRL, mexec);
#endif
}

void _arcv_fusion_enable ()
{
#if defined (__riscv_zicsr)
unsigned long mexec, family, marchid;

marchid = _arcv_csr_read(CSR_NUM_MARCHID);
family = (marchid >> ARCV_MARCHID_FAMILY_OFFSET) & ARCV_MARCHID_FAMILY_MASK;
if (family != ARCV_MARCHID_RHX100_VALUE) {
return;
}

mexec = _arcv_csr_read(CSR_NUM_ARCV_MEXEC_CTRL);
mexec = ~mexec;
mexec |=
(1 << ARCV_MEXEC_FUSION_OFFSET) |
(ARCV_MEXEC_FUSION_CTRL_MASK << ARCV_MEXEC_FUSION_CTRL_OFFSET);
mexec = ~mexec;
_arcv_csr_write(CSR_NUM_ARCV_MEXEC_CTRL, mexec);
#endif
}
70 changes: 70 additions & 0 deletions libgloss/riscv/arcv.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
Copyright (c) 2024, Synopsys, Inc. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1) Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2) Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3) Neither the name of the Synopsys, Inc., nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef _ARCV_H
#define _ARCV_H

#define CSR_NUM_MARCHID 0xF12
#define ARCV_MARCHID_FAMILY_OFFSET 0x0
#define ARCV_MARCHID_FAMILY_MASK 0xFF
#define ARCV_MARCHID_RMX_VALUE 0x01
#define ARCV_MARCHID_RHX100_VALUE 0x02

#define CSR_NUM_ARCV_MEXEC_CTRL 0x7C5
#define ARCV_MEXEC_DUAL_ISSUE_OFFSET 0x0
#define ARCV_MEXEC_FUSION_OFFSET 0x2
#define ARCV_MEXEC_FUSION_CTRL_OFFSET 0x8
#define ARCV_MEXEC_FUSION_CTRL_MASK 0x3FFF

#define CSR_NUM_ARCV_MCACHE_CTRL 0x7C8
#define ARCV_MCACHE_CTRL_IC_EN_OFFSET 0x0
#define ARCV_MCACHE_CTRL_DC_EN_OFFSET 0x8
#define ARCV_MCACHE_CTRL_DC_L0_EN_OFFSET 0xC
#define ARCV_MCACHE_CTRL_L2_EN_OFFSET 0x10

inline unsigned long __attribute__((always_inline))
_arcv_csr_read (int csr_num)
{
unsigned long result;
__asm__ __volatile__("csrr %0, %1" : "=r"((result)) : "i"((csr_num)));
return result;
}

inline void __attribute__((always_inline))
_arcv_csr_write (int csr_num, unsigned long data)
{
__asm__ __volatile__("csrw %0, %1" :: "i"(csr_num), "r"(data));
}

void _arcv_cache_enable ();
void _arcv_fusion_enable ();
void _arcv_dual_issue_enable ();

#endif
2 changes: 1 addition & 1 deletion libgloss/riscv/arcv.specs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
*startfile:
arcv-crt0%O%s crtbegin%O%s
arcv-crt0%O%s crtbegin%O%s arcv%O%s