diff options
author | David Faust <david.faust@oracle.com> | 2020-09-22 20:31:35 +0200 |
---|---|---|
committer | Jose E. Marchesi <jose.marchesi@oracle.com> | 2020-09-22 20:31:35 +0200 |
commit | 7c8ba5da80d5d95a8521010d6731d0d83036145d (patch) | |
tree | 2e140dde7f05e626f15a17684ee603936270c145 /gcc/config/bpf | |
parent | 30bf947649e7381402637d1434d6b1ef22d031f1 (diff) | |
download | gcc-7c8ba5da80d5d95a8521010d6731d0d83036145d.zip gcc-7c8ba5da80d5d95a8521010d6731d0d83036145d.tar.gz gcc-7c8ba5da80d5d95a8521010d6731d0d83036145d.tar.bz2 |
bpf: use xBPF signed div, mod insns when available
The 'mod' and 'div' operators in eBPF are unsigned, with no signed
counterpart. xBPF adds two new ALU operations, sdiv and smod, for
signed division and modulus, respectively. Update bpf.md with
'define_insn' blocks for signed div and mod to use them when targetting
xBPF, and add new tests to ensure they are used appropriately.
2020-09-17 David Faust <david.faust@oracle.com>
gcc/
* config/bpf/bpf.md: Add defines for signed div and mod operators.
gcc/testsuite/
* gcc.target/bpf/diag-sdiv.c: New test.
* gcc.target/bpf/diag-smod.c: New test.
* gcc.target/bpf/xbpf-sdiv-1.c: New test.
* gcc.target/bpf/xbpf-smod-1.c: New test.
Diffstat (limited to 'gcc/config/bpf')
-rw-r--r-- | gcc/config/bpf/bpf.md | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/gcc/config/bpf/bpf.md b/gcc/config/bpf/bpf.md index 769d8ea..8e7cf50 100644 --- a/gcc/config/bpf/bpf.md +++ b/gcc/config/bpf/bpf.md @@ -165,6 +165,16 @@ "div<msuffix>\t%0,%2" [(set_attr "type" "<mtype>")]) +;; However, xBPF does provide a signed division operator, sdiv. + +(define_insn "div<AM:mode>3" + [(set (match_operand:AM 0 "register_operand" "=r,r") + (div:AM (match_operand:AM 1 "register_operand" " 0,0") + (match_operand:AM 2 "reg_or_imm_operand" "r,I")))] + "TARGET_XBPF" + "sdiv<msuffix>\t%0,%2" + [(set_attr "type" "<mtype>")]) + ;;; Modulus ;; Note that eBPF doesn't provide instructions for signed integer @@ -178,6 +188,16 @@ "mod<msuffix>\t%0,%2" [(set_attr "type" "<mtype>")]) +;; Again, xBPF provides a signed version, smod. + +(define_insn "mod<AM:mode>3" + [(set (match_operand:AM 0 "register_operand" "=r,r") + (mod:AM (match_operand:AM 1 "register_operand" " 0,0") + (match_operand:AM 2 "reg_or_imm_operand" "r,I")))] + "TARGET_XBPF" + "smod<msuffix>\t%0,%2" + [(set_attr "type" "<mtype>")]) + ;;; Logical AND (define_insn "and<AM:mode>3" [(set (match_operand:AM 0 "register_operand" "=r,r") |