Skip to content

Commit

Permalink
research: update LLVM x86 compiler (#452)
Browse files Browse the repository at this point in the history
  • Loading branch information
mratsim authored Aug 3, 2024
1 parent cb48a88 commit cfe077b
Show file tree
Hide file tree
Showing 5 changed files with 342 additions and 10 deletions.
9 changes: 7 additions & 2 deletions constantine/math_compiler/ir.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms.

import
constantine/math/config/[curves, precompute],
constantine/named/algebras,
constantine/named/deriv/precompute,
constantine/math/io/io_bigints,
constantine/platforms/[primitives, bithacks],
constantine/platforms/llvm/llvm,
Expand All @@ -30,6 +31,7 @@ type

Backend* = enum
bkNvidiaPTX
bkX86_64_Linux

FnDef* = tuple[fnTy: TypeRef, fnImpl: ValueRef]
# calling getTypeOf on a ValueRef function
Expand All @@ -51,6 +53,9 @@ proc new*(T: type Assembler_LLVM, backend: Backend, moduleName: cstring): Assemb
result.module.setTarget("nvptx64-nvidia-cuda")
# Datalayout for NVVM IR 1.8 (CUDA 11.6)
result.module.setDataLayout("e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-i128:128:128-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64")
of bkX86_64_Linux:
{.warning : "The x86 LLVM backend is incomplete and for research purposes only".}
result.module.setTarget("x86_64-pc-linux-gnu")

result.builder = result.ctx.createBuilder()
result.i1_t = result.ctx.int1_t()
Expand Down Expand Up @@ -188,7 +193,7 @@ type
spareBits*: uint8

CurveMetadata* = object
curve*: Curve
curve*: Algebra
prefix*: string
wordSize*: WordSize
fp*: FieldConst
Expand Down
1 change: 0 additions & 1 deletion research/codegen/nim.cfg

This file was deleted.

6 changes: 3 additions & 3 deletions research/codegen/x86_inlineasm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import
std/[macros, strutils],
./llvm
constantine/platforms/llvm/llvm

# ############################################################
#
Expand Down Expand Up @@ -85,7 +85,7 @@ macro genInstr(body: untyped): untyped =


instrBody.add quote do:
let `asmString` = if numBits == 64: static(`instr` & "q") & static(" " & `instrParam`)
let `asmString` = if `numBits` == 64: static(`instr` & "q") & static(" " & `instrParam`)
else: static(`instr` & "l") & static(" " & `instrParam`)

instrBody.add quote do:
Expand Down Expand Up @@ -206,4 +206,4 @@ genInstr():
op adcx_rr: ("adcx", "%2, %0;", "=r,%0,r", [lhs, rhs])
op adcx_rm: ("adcx", "%2, %0;", "=r,0,m", [lhs, rhs])
op adox_rr: ("adox", "%2, %0;", "=r,%0,r", [lhs, rhs])
op adox_rm: ("adox", "%2, %0;", "=r,0,m", [lhs, rhs])
op adox_rm: ("adox", "%2, %0;", "=r,0,m", [lhs, rhs])
9 changes: 5 additions & 4 deletions research/codegen/x86.nim → research/codegen/x86_instr.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms.

import
./bindings/c_abi,
./llvm, ./ir,
./x86_inlineasm,
../primitives
constantine/platforms/llvm/bindings/c_abi,
constantine/platforms/llvm/llvm,
constantine/platforms/primitives,
constantine/math_compiler/ir,
./x86_inlineasm

export x86_inlineasm

Expand Down
Loading

0 comments on commit cfe077b

Please sign in to comment.