Skip to content

Commit

Permalink
LoongArch: Added Loongson ASX vector directive compilation framework.
Browse files Browse the repository at this point in the history
gcc/ChangeLog:

	* config/loongarch/genopts/loongarch-strings: Added compilation framework.
	* config/loongarch/genopts/loongarch.opt.in: Ditto.
	* config/loongarch/loongarch-c.cc (loongarch_cpu_cpp_builtins): Ditto.
	* config/loongarch/loongarch-def.c: Ditto.
	* config/loongarch/loongarch-def.h (N_ISA_EXT_TYPES): Ditto.
	(ISA_EXT_SIMD_LASX): Ditto.
	(N_SWITCH_TYPES): Ditto.
	(SW_LASX): Ditto.
	* config/loongarch/loongarch-driver.cc (driver_get_normalized_m_opts): Ditto.
	* config/loongarch/loongarch-driver.h (driver_get_normalized_m_opts): Ditto.
	* config/loongarch/loongarch-opts.cc (isa_str): Ditto.
	* config/loongarch/loongarch-opts.h (ISA_HAS_LSX): Ditto.
	(ISA_HAS_LASX): Ditto.
	* config/loongarch/loongarch-str.h (OPTSTR_LASX): Ditto.
	* config/loongarch/loongarch.opt: Ditto.

Change-Id: I911fc6724d767c6d0e658591c35935bddda64478
  • Loading branch information
chenglulu326 committed Mar 21, 2023
1 parent d92c159 commit d41121b
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 6 deletions.
1 change: 1 addition & 0 deletions gcc/config/loongarch/genopts/loongarch-strings
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ OPTSTR_DOUBLE_FLOAT double-float

# SIMD extensions
OPTSTR_LSX lsx
OPTSTR_LASX lasx

# -mabi=
OPTSTR_ABI_BASE abi
Expand Down
4 changes: 4 additions & 0 deletions gcc/config/loongarch/genopts/loongarch.opt.in
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ m@@OPTSTR_LSX@@
Target RejectNegative Var(la_opt_switches) Mask(LSX) Negative(m@@OPTSTR_LSX@@)
Enable LoongArch SIMD Extension (LSX).

m@@OPTSTR_LASX@@
Target RejectNegative Var(la_opt_switches) Mask(LASX) Negative(m@@OPTSTR_LASX@@)
Enable LoongArch Advanced SIMD Extension (LASX).

;; Base target models (implies ISA & tune parameters)
Enum
Name(cpu_type) Type(int)
Expand Down
11 changes: 11 additions & 0 deletions gcc/config/loongarch/loongarch-c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,19 @@ loongarch_cpu_cpp_builtins (cpp_reader *pfile)
builtin_define ("__loongarch_simd");
builtin_define ("__loongarch_sx");
builtin_define ("__loongarch_sx_width=128");

if (!ISA_HAS_LASX)
builtin_define ("__loongarch_simd_width=128");
}

if (ISA_HAS_LASX)
{
builtin_define ("__loongarch_asx");
builtin_define ("__loongarch_asx_width=256");
builtin_define ("__loongarch_simd_width=256");
}


/* Native Data Sizes. */
builtin_define_with_int_value ("_LOONGARCH_SZINT", INT_TYPE_SIZE);
builtin_define_with_int_value ("_LOONGARCH_SZLONG", LONG_TYPE_SIZE);
Expand Down
4 changes: 3 additions & 1 deletion gcc/config/loongarch/loongarch-def.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ loongarch_cpu_default_isa[N_ARCH_TYPES] = {
[CPU_LA464] = {
.base = ISA_BASE_LA64V100,
.fpu = ISA_EXT_FPU64,
.simd = ISA_EXT_SIMD_LSX,
.simd = ISA_EXT_SIMD_LASX,
},
};

Expand Down Expand Up @@ -138,6 +138,7 @@ loongarch_isa_ext_strings[N_ISA_EXT_TYPES] = {
[ISA_EXT_FPU32] = STR_ISA_EXT_FPU32,
[ISA_EXT_NOFPU] = STR_ISA_EXT_NOFPU,
[ISA_EXT_SIMD_LSX] = OPTSTR_LSX,
[ISA_EXT_SIMD_LASX] = OPTSTR_LASX,
};

const char*
Expand Down Expand Up @@ -168,6 +169,7 @@ loongarch_switch_strings[] = {
[SW_SINGLE_FLOAT] = OPTSTR_SINGLE_FLOAT,
[SW_DOUBLE_FLOAT] = OPTSTR_DOUBLE_FLOAT,
[SW_LSX] = OPTSTR_LSX,
[SW_LASX] = OPTSTR_LASX,
};


Expand Down
6 changes: 4 additions & 2 deletions gcc/config/loongarch/loongarch-def.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ extern const char* loongarch_isa_ext_strings[];
#define ISA_EXT_FPU64 2
#define N_ISA_EXT_FPU_TYPES 3
#define ISA_EXT_SIMD_LSX 3
#define N_ISA_EXT_TYPES 4
#define ISA_EXT_SIMD_LASX 4
#define N_ISA_EXT_TYPES 5

/* enum abi_base */
extern const char* loongarch_abi_base_strings[];
Expand Down Expand Up @@ -99,7 +100,8 @@ extern const char* loongarch_switch_strings[];
#define SW_SINGLE_FLOAT 1
#define SW_DOUBLE_FLOAT 2
#define SW_LSX 3
#define N_SWITCH_TYPES 4
#define SW_LASX 4
#define N_SWITCH_TYPES 5

/* The common default value for variables whose assignments
are triggered by command-line options. */
Expand Down
2 changes: 1 addition & 1 deletion gcc/config/loongarch/loongarch-driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ driver_get_normalized_m_opts (int argc, const char **argv)

if (la_target.isa.simd)
{
APPEND_LTR (" %<m" OPTSTR_LSX " -m");
APPEND_LTR (" %<m" OPTSTR_LSX " %<m" OPTSTR_LASX " -m");
APPEND_VAL (loongarch_isa_ext_strings[la_target.isa.simd]);
}

Expand Down
1 change: 1 addition & 0 deletions gcc/config/loongarch/loongarch-driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ driver_get_normalized_m_opts (int argc, const char **argv);
LA_SET_FLAG_SPEC (SINGLE_FLOAT) \
LA_SET_FLAG_SPEC (DOUBLE_FLOAT) \
LA_SET_FLAG_SPEC (LSX) \
LA_SET_FLAG_SPEC (LASX) \
" %:get_normalized_m_opts()"

#define DRIVER_SELF_SPECS \
Expand Down
9 changes: 8 additions & 1 deletion gcc/config/loongarch/loongarch-opts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const int loongarch_switch_mask[N_SWITCH_TYPES] = {
/* SW_SINGLE_FLOAT */ M(FORCE_F32),
/* SW_DOUBLE_FLOAT */ M(FORCE_F64),
/* SW_LSX */ M(LSX),
/* SW_LASX */ M(LASX),
};
#undef M

Expand Down Expand Up @@ -254,8 +255,9 @@ loongarch_config_target (struct loongarch_target *target,
t.isa.fpu : DEFAULT_ISA_EXT_FPU);

/* LoongArch SIMD extensions. */
/* Note: LASX implies LSX, so we put "on (LASX)" first. */
int simd_switch;
if (on (LSX))
if (on (LASX) || on (LSX))
{
constrained.simd = 1;
switch (on_switch)
Expand All @@ -264,6 +266,10 @@ loongarch_config_target (struct loongarch_target *target,
t.isa.simd = ISA_EXT_SIMD_LSX;
break;

case SW_LASX:
t.isa.simd = ISA_EXT_SIMD_LASX;
break;

default:
gcc_unreachable ();
}
Expand Down Expand Up @@ -603,6 +609,7 @@ isa_str (const struct loongarch_isa *isa, char separator)
switch (isa->simd)
{
case ISA_EXT_SIMD_LSX:
case ISA_EXT_SIMD_LASX:
APPEND1 (separator);
APPEND_STRING (loongarch_isa_ext_strings[isa->simd]);
break;
Expand Down
4 changes: 3 additions & 1 deletion gcc/config/loongarch/loongarch-opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ loongarch_config_target (struct loongarch_target *target,
|| la_target.abi.base == ABI_BASE_LP64F \
|| la_target.abi.base == ABI_BASE_LP64S)

#define ISA_HAS_LSX (la_target.isa.simd == ISA_EXT_SIMD_LSX)
#define ISA_HAS_LSX (la_target.isa.simd == ISA_EXT_SIMD_LSX \
|| la_target.isa.simd == ISA_EXT_SIMD_LASX)
#define ISA_HAS_LASX (la_target.isa.simd == ISA_EXT_SIMD_LASX)
#define TARGET_ARCH_NATIVE (la_target.cpu_arch == CPU_NATIVE)
#define LARCH_ACTUAL_ARCH (TARGET_ARCH_NATIVE \
? (la_target.cpu_native < N_ARCH_TYPES \
Expand Down
1 change: 1 addition & 0 deletions gcc/config/loongarch/loongarch-str.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ along with GCC; see the file COPYING3. If not see
#define OPTSTR_DOUBLE_FLOAT "double-float"

#define OPTSTR_LSX "lsx"
#define OPTSTR_LASX "lasx"

#define OPTSTR_ABI_BASE "abi"
#define STR_ABI_BASE_LP64D "lp64d"
Expand Down
4 changes: 4 additions & 0 deletions gcc/config/loongarch/loongarch.opt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ mlsx
Target RejectNegative Var(la_opt_switches) Mask(LSX) Negative(mlsx)
Enable LoongArch SIMD Extension (LSX).

mlasx
Target RejectNegative Var(la_opt_switches) Mask(LASX) Negative(mlasx)
Enable LoongArch Advanced SIMD Extension (LASX).

;; Base target models (implies ISA & tune parameters)
Enum
Name(cpu_type) Type(int)
Expand Down

0 comments on commit d41121b

Please sign in to comment.