Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
fsaintjacques committed Dec 13, 2019
0 parents commit b7e8021
Show file tree
Hide file tree
Showing 45 changed files with 2,711 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http:https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
---
BasedOnStyle: Google
DerivePointerAlignment: false
ColumnLimit: 90
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build*
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "vendor/googletest"]
path = vendor/googletest
url = [email protected]:google/googletest.git
[submodule "vendor/benchmark"]
path = vendor/benchmark
url = [email protected]:google/benchmark.git
24 changes: 24 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
cmake_minimum_required(VERSION 3.0.0)
project(jitmap)

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/dev/cmake")

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

option(BUILD_TESTS "Builder unit tests" ON)
option(FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)." ON)

include(CompilerToolchain)
find_package(LLVM REQUIRED CONFIG)

add_subdirectory(src/jitmap)
add_subdirectory(tools)

if (BUILD_TESTS)
enable_testing()
include(GoogleTest)
include(GoogleBenchmark)
add_subdirectory(tests)
endif()
158 changes: 158 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
# jitmap: Jitted bitmaps


# Language

A tiny expression language supporting the following C binary operators:
- *!*: not
- *&*: and
- *|*: or
- *^*: xor
Supported literals are:
- *$[0-9]+*: index reference
- *[A-Za-z0-9_]+*: named reference


## Examples
```
!a
a & b
($0 & ($1 | $2) ^ !$1)
```

# Generated assembly for query

```
$ ninja && tools/jitmap-ir '($0 & ($1 & ($2 & ($3 & $4))))'
ninja: no work to do.
; ModuleID = 'query'
source_filename = "($0 & ($1 & ($2 & ($3 & $4))))"
; Function Attrs: argmemonly
define void @query(i64* nocapture readonly %in, i64* nocapture readonly %in1, i64* nocapture readonly %in2, i64* nocapture readonly %in3, i64* nocapture readonly %in4, i64* nocapture %out) #0 {
entry:
br label %loop
loop: ; preds = %loop, %entry
%i = phi i64 [ 0, %entry ], [ %next_i, %loop ]
%gep_0 = getelementptr inbounds i64, i64* %in, i64 %i
%bitcast_0 = bitcast i64* %gep_0 to <4 x i64>*
%load_0 = load <4 x i64>, <4 x i64>* %bitcast_0
%gep_1 = getelementptr inbounds i64, i64* %in1, i64 %i
%bitcast_1 = bitcast i64* %gep_1 to <4 x i64>*
%load_1 = load <4 x i64>, <4 x i64>* %bitcast_1
%gep_2 = getelementptr inbounds i64, i64* %in2, i64 %i
%bitcast_2 = bitcast i64* %gep_2 to <4 x i64>*
%load_2 = load <4 x i64>, <4 x i64>* %bitcast_2
%gep_3 = getelementptr inbounds i64, i64* %in3, i64 %i
%bitcast_3 = bitcast i64* %gep_3 to <4 x i64>*
%load_3 = load <4 x i64>, <4 x i64>* %bitcast_3
%gep_4 = getelementptr inbounds i64, i64* %in4, i64 %i
%bitcast_4 = bitcast i64* %gep_4 to <4 x i64>*
%load_4 = load <4 x i64>, <4 x i64>* %bitcast_4
%0 = and <4 x i64> %load_3, %load_4
%1 = and <4 x i64> %load_2, %0
%2 = and <4 x i64> %load_1, %1
%3 = and <4 x i64> %load_0, %2
%gep_output = getelementptr inbounds i64, i64* %out, i64 %i
%bitcast_output = bitcast i64* %gep_output to <4 x i64>*
store <4 x i64> %3, <4 x i64>* %bitcast_output
%next_i = add i64 %i, 4
%exit_cond = icmp eq i64 %next_i, 1024
br i1 %exit_cond, label %after_loop, label %loop
after_loop: ; preds = %loop
ret void
}
attributes #0 = { argmemonly }
```

Use LLVM's opt and/or llc to transform the IR into native assembly.

```
tools/jitmap-ir '($0 & ($1 & ($2 & ($3 & $4))))' | llc-8 -O3 -mcpu=core-avx2
ninja: no work to do.
.text
.file "($0 & ($1 & ($2 & ($3 & $4))))"
.globl query # -- Begin function query
.p2align 4, 0x90
.type query,@function
query: # @query
.cfi_startproc
# %bb.0: # %entry
xorl %eax, %eax
.p2align 4, 0x90
.LBB0_1: # %loop
# =>This Inner Loop Header: Depth=1
vmovaps (%rcx,%rax), %ymm0
vandps (%r8,%rax), %ymm0, %ymm0
vandps (%rdx,%rax), %ymm0, %ymm0
vandps (%rsi,%rax), %ymm0, %ymm0
vandps (%rdi,%rax), %ymm0, %ymm0
vmovaps %ymm0, (%r9,%rax)
addq $32, %rax
cmpq $8192, %rax # imm = 0x2000
jne .LBB0_1
# %bb.2: # %after_loop
vzeroupper
retq
.Lfunc_end0:
.size query, .Lfunc_end0-query
.cfi_endproc
# -- End function
.section ".note.GNU-stack","",@progbits
```

```
$ ninja && tools/jitmap-ir '$0 ^ $1' | opt-8 -S -O3 -mcpu=core-avx2 -mtriple=x86_64-pc-linux-gnu | llc-8 -O3 -mcpu=core-avx2
ninja: no work to do.
.text
.file "($0 ^ $1)"
.globl query # -- Begin function query
.p2align 4, 0x90
.type query,@function
query: # @query
# %bb.0: # %entry
xorl %eax, %eax
.p2align 4, 0x90
.LBB0_1: # %loop
# =>This Inner Loop Header: Depth=1
vmovaps (%rsi,%rax,8), %ymm0
vxorps (%rdi,%rax,8), %ymm0, %ymm0
vmovaps %ymm0, (%rdx,%rax,8)
vmovaps 32(%rsi,%rax,8), %ymm0
vxorps 32(%rdi,%rax,8), %ymm0, %ymm0
vmovaps %ymm0, 32(%rdx,%rax,8)
vmovaps 64(%rsi,%rax,8), %ymm0
vxorps 64(%rdi,%rax,8), %ymm0, %ymm0
vmovaps %ymm0, 64(%rdx,%rax,8)
vmovaps 96(%rsi,%rax,8), %ymm0
vxorps 96(%rdi,%rax,8), %ymm0, %ymm0
vmovaps %ymm0, 96(%rdx,%rax,8)
vmovaps 128(%rsi,%rax,8), %ymm0
vxorps 128(%rdi,%rax,8), %ymm0, %ymm0
vmovaps %ymm0, 128(%rdx,%rax,8)
vmovaps 160(%rsi,%rax,8), %ymm0
vxorps 160(%rdi,%rax,8), %ymm0, %ymm0
vmovaps %ymm0, 160(%rdx,%rax,8)
vmovaps 192(%rsi,%rax,8), %ymm0
vxorps 192(%rdi,%rax,8), %ymm0, %ymm0
vmovaps %ymm0, 192(%rdx,%rax,8)
vmovaps 224(%rsi,%rax,8), %ymm0
vxorps 224(%rdi,%rax,8), %ymm0, %ymm0
vmovaps %ymm0, 224(%rdx,%rax,8)
addq $32, %rax
cmpq $1024, %rax # imm = 0x400
jne .LBB0_1
# %bb.2: # %after_loop
vzeroupper
retq
.Lfunc_end0:
.size query, .Lfunc_end0-query
# -- End function
.section ".note.GNU-stack","",@progbits
```

10 changes: 10 additions & 0 deletions dev/cmake/CompilerToolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
if (${FORCE_COLORED_OUTPUT})
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compile_options (-fdiagnostics-color=always)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_compile_options (-fcolor-diagnostics)
endif ()
endif ()


set(CXX_WARNING_FLAGS -Werror -Wall)
31 changes: 31 additions & 0 deletions dev/cmake/GoogleBenchmark.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Download and unpack googlebenchmark at configure time
configure_file(tests/BenchmarkCMakeLists.txt.in googlebenchmark-download/CMakeLists.txt)

set(BENCHMARK_ENABLE_TESTING OFF)
set(BENCHMARK_ENABLE_GTEST_TESTS OFF)

execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googlebenchmark-download )
if(result)
message(FATAL_ERROR "CMake step for googlebenchmark failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googlebenchmark-download )
if(result)
message(FATAL_ERROR "Build step for googlebenchmark failed: ${result}")
endif()

# Add googlebenchmark directly to our build. This defines
# the benchmark and benchmark_main targets.
add_subdirectory(${CMAKE_SOURCE_DIR}/vendor/benchmark
${CMAKE_CURRENT_BINARY_DIR}/googlebenchmark-build
EXCLUDE_FROM_ALL)

# The gtest/gtest_main targets carry header search path
# dependencies automatically when using CMake 2.8.11 or
# later. Otherwise we have to add them here ourselves.
if (CMAKE_VERSION VERSION_LESS 2.8.11)
include_directories("${benchmark_SOURCE_DIR}/include")
endif()
31 changes: 31 additions & 0 deletions dev/cmake/GoogleTest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Download and unpack googletest at configure time
configure_file(tests/GTestCMakeLists.txt.in googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()

# Prevent overriding the parent project's compiler/linker
# settings on Windows
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory(${CMAKE_SOURCE_DIR}/vendor/googletest
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
EXCLUDE_FROM_ALL)

# The gtest/gtest_main targets carry header search path
# dependencies automatically when using CMake 2.8.11 or
# later. Otherwise we have to add them here ourselves.
if (CMAKE_VERSION VERSION_LESS 2.8.11)
include_directories("${gtest_SOURCE_DIR}/include")
endif()
Loading

0 comments on commit b7e8021

Please sign in to comment.